schrodinger.application.transforms.ligfilter module

class schrodinger.application.transforms.ligfilter.LigFilterResult(*, ID: str, structure: Structure, passed_filter: bool, no_match_reason: str | None = None)

Bases: BaseModel

Result of applying LigFilter criteria to a single structure.

Parameters:
  • ID – Identifier of the structure.

  • structure – The structure object.

  • passed_filter – Whether the structure passed the filter.

  • no_match_reason – Reason for not matching, if applicable.

ID: str
structure: Structure
passed_filter: bool
no_match_reason: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class schrodinger.application.transforms.ligfilter.LigFilterConfig(*, match_any: bool = False, invert_criteria: bool = False, criteria: list[schrodinger.utils.ligfilter.Criterion] = <factory>, add_props: bool = False, legacy_arg_string: str | None = None)

Bases: BaseModel

Configuration for LigFilter transforms.

There are two ways to configure this:

  1. Use named fields directly (preferred for new code):

    config = LigFilterConfig(
        criteria=["Num_atoms > 5", "Num_rings == 1"],
        match_any=True
    )
    

    The criteria field also accepts a path to a criteria file:

    config = LigFilterConfig(criteria=Path("my_criteria.lff"))
    config = LigFilterConfig(criteria="/path/to/my_criteria.lff")
    
  2. Use legacy_arg_string for backwards compatibility with CLI args:

    config = LigFilterConfig(legacy_arg_string="-e 'Num_atoms > 5' -any")
    

These modes are mutually exclusive - you cannot specify both legacy_arg_string and other configuration fields (criteria, match_any, invert_criteria).

Parameters:
  • match_any – Match any criteria instead of all.

  • invert_criteria – Invert the filter (remove matching structures).

  • criteria – List of compiled filter criteria, or Path to a criteria file.

  • add_props – Whether to add properties to structures (not supported).

  • legacy_arg_string – Legacy command line argument string.

match_any: bool
invert_criteria: bool
criteria: list[Criterion]
add_props: bool
legacy_arg_string: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod validate_criteria(v: Any) List[Criterion]

Custom validator to allow criteria to be passed as: - A Path to a criteria file (reads and parses file contents) - A string path to a criteria file (reads and parses file contents) - A single string (e.g. “Num_atoms > 5”) - A list of strings - A single Criterion object - A list of Criterion objects - A mixed list of strings and Criterion objects

Parameters:

v – The input value for criteria.

Returns:

A list of Criterion objects.

Raises:
  • ValueError – If any string cannot be parsed into a Criterion.

  • FileNotFoundError – If a Path is provided but the file doesn’t exist.

classmethod parse_legacy_arg_string(data: Any) Any

Parse legacy_arg_string into the other config fields.

If legacy_arg_string is provided, it is parsed and the resulting values are used to populate match_any, invert_criteria, and criteria. This is mutually exclusive with specifying those fields directly.

Parameters:

data – The input data dictionary.

Returns:

The modified data dictionary with parsed values.

Raises:

ValueError – If legacy_arg_string is used with other config fields.

schrodinger.application.transforms.ligfilter.mol_to_structure(mol: Mol) Iterable[Structure]

Converts an RDKit Mol to a Schrodinger Structure. Yields a single Structure or nothing if conversion fails.

Parameters:

mol – The input RDKit Mol.

Returns:

Yields the converted Structure.

class schrodinger.application.transforms.ligfilter.RunLigFilterDoFn(config: LigFilterConfig)

Bases: DoFn

A DoFn that applies LigFilter criteria and yields results for all structures.

Parameters:

config – An instance of LigFilterConfig containing filter settings.

__init__(config: LigFilterConfig)
class schrodinger.application.transforms.ligfilter.RunLigFilter(**kwargs)

Bases: PTransformWithConfig

A PTransform that applies LigFilter criteria and returns results for all structures.

Unlike LigFilter which only yields passing structures, this transform yields a LigFilterResult for every input structure, indicating whether it passed and the reason for not matching if applicable.

Example usage:

>>> from schrodinger import adapter
>>> st1 = adapter.to_structure('c1ccccc1')
>>> st1.title = "benzene"
>>> st2 = adapter.to_structure('CCO')
>>> st2.title = "ethanol"
>>> with beam.Pipeline() as p:
...     results = (p
...         | beam.Create([st1, st2])
...         | RunLigFilter(criteria=['Num_heavy_atoms==3'])
...         | beam.Map(lambda r: (r.ID, r.passed_filter))
...         | beam.LogElements())
('benzene', False)
('ethanol', True)
Parameters:
  • match_any – If True, matches any of the criteria instead of all.

  • invert_criteria – If True, inverts the filter (removes matching structures).

  • criteria – A list of compiled LigFilter criteria.

  • add_props – If True, adds properties to structures (not currently supported).

config_class

alias of LigFilterConfig

class schrodinger.application.transforms.ligfilter.FilterLigands(**kwargs)

Bases: PTransformWithConfig

A PTransform that filters molecules based on LigFilter criteria.

This is a wrapper transform that uses RunLigFilter internally and returns only the structures that pass the filter.

Example usage with standard args:

>>> from schrodinger import adapter
>>> st1 = adapter.to_structure('c1ccccc1')
>>> st1.title = "benzene_fail"
>>> st2 = adapter.to_structure('CCO')
>>> st2.title = "ethanol_pass"
>>> with beam.Pipeline() as p:
...     filtered_structures = (p
...         | beam.Create([st1, st2])
...         | FilterLigands(criteria=['Num_heavy_atoms==3'])
...         | beam.Map(lambda st: st.title)
...         | beam.LogElements())
ethanol_pass

Example usage with legacy arg string:

>>> from schrodinger import adapter
>>> st1 = adapter.to_structure('c1ccccc1')
>>> st1.title = "benzene_pass"
>>> st2 = adapter.to_structure('CCO')
>>> st2.title = "ethanol_fail"
>>> with beam.Pipeline() as p:
...     filtered_structures = (p
...         | beam.Create([st1, st2])
...         | FilterLigands(legacy_arg_string='-e Num_heavy_atoms>3')
...         | beam.Map(lambda st: st.title)
...         | beam.LogElements())
Filtering criteria:
  Num_heavy_atoms>3
benzene_pass
Parameters:
  • match_any – If True, matches any of the criteria instead of all.

  • invert_criteria – If True, inverts the filter (removes matching structures).

  • criteria – A list of compiled LigFilter criteria.

  • add_props – If True, adds properties to structures (not currently supported).

  • legacy_arg_string – Legacy CLI argument string (mutually exclusive with other fields).

config_class

alias of LigFilterConfig