schrodinger.structutils.filter module¶
Functions and classes for filtering structure files based on properties or SMARTS patterns. Supports filter files in the formats used by propfilter and canvasSearch, respectively. The filter classes support both Structure and Mol objects.
Simple example:
prop_filter = PropFilter(filename='filters.txt')
reader = StructureReader('structs.maegz'):
for st in prop_filter.filter(reader):
# st matches; do something with it
smarts_filter = SmartsFilter(filename='filters.cflt')
for st in smarts_filter.filter(reader):
# st matches; do something with it
Copyright Schrodinger, LLC. All rights reserved.
-
class
schrodinger.structutils.filter.
SingleFilter
¶ Bases:
object
Base class for single filters. Derived classes must implement checkStructure.
-
checkStructure
(st_or_mol)¶ Return True if st_or_mol passes the filters; False otherwise. Not implemented in the base class.
Return type: bool
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'schrodinger.structutils.filter', '__doc__': '\n Base class for single filters. Derived classes must implement\n checkStructure.\n ', 'checkStructure': <function SingleFilter.checkStructure>, '__dict__': <attribute '__dict__' of 'SingleFilter' objects>, '__weakref__': <attribute '__weakref__' of 'SingleFilter' objects>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'schrodinger.structutils.filter'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
schrodinger.structutils.filter.
Filter
(filters=None, filename=None, **kwds)¶ Bases:
object
Base class for filtering structures. The specific filters to use are determined by the SingleFilter objects passed to .append(), or by the file read with readFile().
-
__init__
(filters=None, filename=None, **kwds)¶ Create a filter object, optionally with a source for the filter conditions.
Parameters: kwds – additional keywords to pass to readFile or readFileName
-
readFileName
(filename, **kwds)¶ Add filter conditions given a filename.
Parameters: kwds – additional keywords to pass to readFile
-
readFile
(fh)¶ Add filter conditions given a file-like object. Not implemented in the base class.
-
append
(filter)¶ Add a filter the PropFilter object.
-
checkStructure
(st_or_mol, max_violations=0)¶ Return True if st_or_mol passes the filters; False otherwise.
Return type: bool
-
filter
(structures, **kwds)¶ A generator that returns only the structures from ‘structures’ that pass the filter conditions.
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'schrodinger.structutils.filter', '__doc__': '\n Base class for filtering structures. The specific filters to use are\n determined by the SingleFilter objects passed to .append(), or by\n the file read with readFile().\n ', '__init__': <function Filter.__init__>, 'readFileName': <function Filter.readFileName>, 'readFile': <function Filter.readFile>, 'append': <function Filter.append>, 'checkStructure': <function Filter.checkStructure>, 'filter': <function Filter.filter>, '_mol_adapter': None, '_mol_class': None, '_adaptStructure': <function Filter._adaptStructure>, '__dict__': <attribute '__dict__' of 'Filter' objects>, '__weakref__': <attribute '__weakref__' of 'Filter' objects>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'schrodinger.structutils.filter'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
schrodinger.structutils.filter.
SinglePropFilter
(expr)¶ Bases:
schrodinger.structutils.filter.SingleFilter
Check if a structure satisfies an expression testing a single property. The expression uses the syntax supported by $SCHRODINGER/utilities/propfilter. For example, “r_i_glide_gscore < -5 > -6”.
This class and associated functions support both Structure objects and RDKit Mol objects.
-
__init__
(expr)¶ Initialize self. See help(type(self)) for accurate signature.
-
checkStructure
(st_or_mol)¶ Return True if st_or_mol passes the filters; False otherwise.
Return type: bool
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'schrodinger.structutils.filter', '__doc__': '\n Check if a structure satisfies an expression testing a single property. The\n expression uses the syntax supported by $SCHRODINGER/utilities/propfilter.\n For example, "r_i_glide_gscore < -5 > -6".\n\n This class and associated functions support both Structure objects and\n RDKit Mol objects.\n ', '__init__': <function SinglePropFilter.__init__>, 'checkStructure': <function SinglePropFilter.checkStructure>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'schrodinger.structutils.filter'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
schrodinger.structutils.filter.
PropFilter
(filters=None, filename=None, **kwds)¶ Bases:
schrodinger.structutils.filter.Filter
Check if a structure satisfies a given list of conditions. Each condition is expressed using the syntax supported by $SCHRODINGER/utilities/propfilter. For example, “r_i_glide_gscore < -5 > -6”.
This class and associated functions support both Structure objects and RDKit Mol objects.
-
readFile
(fh)¶ Add the filter conditions given a file-like object.
-
getPropertyNames
()¶ Return the set of properties used by all the filters in this object.
Return type: set of str
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'schrodinger.structutils.filter', '__doc__': '\n Check if a structure satisfies a given list of conditions. Each condition is\n expressed using the syntax supported by $SCHRODINGER/utilities/propfilter.\n For example, "r_i_glide_gscore < -5 > -6".\n\n This class and associated functions support both Structure objects and\n RDKit Mol objects.\n ', 'readFile': <function PropFilter.readFile>, 'getPropertyNames': <function PropFilter.getPropertyNames>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(filters=None, filename=None, **kwds)¶ Create a filter object, optionally with a source for the filter conditions.
Parameters: kwds – additional keywords to pass to readFile or readFileName
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'schrodinger.structutils.filter'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
append
(filter)¶ Add a filter the PropFilter object.
-
checkStructure
(st_or_mol, max_violations=0)¶ Return True if st_or_mol passes the filters; False otherwise.
Return type: bool
-
filter
(structures, **kwds)¶ A generator that returns only the structures from ‘structures’ that pass the filter conditions.
-
readFileName
(filename, **kwds)¶ Add filter conditions given a filename.
Parameters: kwds – additional keywords to pass to readFile
-
-
class
schrodinger.structutils.filter.
SingleSmartsFilter
(smarts, name, min_matches, max_matches)¶ Bases:
schrodinger.structutils.filter.SingleFilter
Check if a structure matches a SMARTS pattern a given number of times.
-
__init__
(smarts, name, min_matches, max_matches)¶ Initialize self. See help(type(self)) for accurate signature.
-
checkStructure
(mol)¶ Return True if st_or_mol passes the filters; False otherwise.
Return type: bool
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'schrodinger.structutils.filter', '__doc__': '\n Check if a structure matches a SMARTS pattern a given number of times.\n ', '__init__': <function SingleSmartsFilter.__init__>, 'checkStructure': <function SingleSmartsFilter.checkStructure>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'schrodinger.structutils.filter'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
schrodinger.structutils.filter.
SmartsFilter
(filters=None, filename=None, **kwds)¶ Bases:
schrodinger.structutils.filter.Filter
Check if a structure satisfies a given list of SMARTS filters. Supports reading canvasSearch rule files.
-
readFile
(fh, delimiter='\t')¶ Add filter conditions given a file-like object. Not implemented in the base class.
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'schrodinger.structutils.filter', '__doc__': '\n Check if a structure satisfies a given list of SMARTS filters. Supports\n reading canvasSearch rule files.\n ', '_mol_adapter': functools.partial(<function to_rdkit>, include_properties=False, include_coordinates=False), '_mol_class': <class 'rdkit.Chem.rdchem.Mol'>, 'readFile': <function SmartsFilter.readFile>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(filters=None, filename=None, **kwds)¶ Create a filter object, optionally with a source for the filter conditions.
Parameters: kwds – additional keywords to pass to readFile or readFileName
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'schrodinger.structutils.filter'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
append
(filter)¶ Add a filter the PropFilter object.
-
checkStructure
(st_or_mol, max_violations=0)¶ Return True if st_or_mol passes the filters; False otherwise.
Return type: bool
-
filter
(structures, **kwds)¶ A generator that returns only the structures from ‘structures’ that pass the filter conditions.
-
readFileName
(filename, **kwds)¶ Add filter conditions given a filename.
Parameters: kwds – additional keywords to pass to readFile
-
-
schrodinger.structutils.filter.
parse_filter_expression
(s, verbose=False)¶ Given a filter expression, return a list of instructions for a stack-based machine.
The first instruction is a property name. The others are tuples of an operator optionally followed by a value to be compared against the property value. When the tuple only has an operator, it is applied to two values popped from the result stack. For example, “r_i_glide_gscore < -5 > -6’ produces [‘r_i_glide_gscore’, (‘<’, ‘-5’), (‘>’, ‘-6’), (‘AND’,)].
Return type: list