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 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 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)
checkStructure(st_or_mol)

Return True if st_or_mol passes the filters; False otherwise.

Return type

bool

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 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)
checkStructure(mol)

Return True if st_or_mol passes the filters; False otherwise.

Return type

bool

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.

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