Filters

Filter related functions

source

Filter

 Filter (name='filter')

Filter base class

Type Default Details
name str filter filter name

source

FilterResult

 FilterResult (filter_result:bool, filter_name:str, filter_data:dict)

Container for filter results

Type Details
filter_result bool overall filter result (True or False)
filter_name str name of filter
filter_data dict filter data dict

source

SingleCompoundFilter

 SingleCompoundFilter ()

Checks if molecule is a single compound


source

ValidityFilter

 ValidityFilter ()

Checks if molecule is valid

mol1 = Molecule('CCCC')
mol2 = Molecule('CCCc')
mol3 = Molecule('CCC.CCCC')

f1 = ValidityFilter()
f2 = SingleCompoundFilter()

assert f1(mol1).filter_result
assert not f1(mol2).filter_result
assert f1(mol3).filter_result

assert f2(mol1).filter_result
assert not f2(mol3).filter_result

source

AttachmentCountFilter

 AttachmentCountFilter (num_attachments:int)

Checks number of dummy attachment atoms

mol1 = Molecule('[*:1]CC')
mol2 = Molecule('[*:1]CC[*:2]')
f = AttachmentCountFilter(1)

assert f(mol1).filter_result
assert not f(mol2).filter_result

source

DataFunctionFilter

 DataFunctionFilter
                     (func:Callable[[chem_templates.chem.Molecule],Tuple[b
                     ool,dict]], name:str)

Filter base class

Type Details
func typing.Callable[[chem_templates.chem.Molecule], typing.Tuple[bool, dict]] callable that takes a Molecule and returns (bool, dict)
name str filter name

source

BinaryFunctionFilter

 BinaryFunctionFilter (func:Callable[[chem_templates.chem.Molecule],bool],
                       name:str)

Filter base class

Type Details
func typing.Callable[[chem_templates.chem.Molecule], bool] callable function that takes a Molecule as input and returns a bool
name str filter name
from rdkit.Chem import rdMolDescriptors
mol1 = Molecule('Cc1nnc2n1-c1ccc(Cl)cc1C(c1ccccc1)=NC2')
mol2 = Molecule('CCCC')

def filter_func(molecule):
    n_rings = rdMolDescriptors.CalcNumRings(molecule.mol)
    return n_rings>1

f = BinaryFunctionFilter(filter_func, 'has_ring')

assert f(mol1).filter_result
assert not f(mol2).filter_result

source

RangeFunctionFilter

 RangeFunctionFilter
                      (func:Callable[[chem_templates.chem.Molecule],Union[
                      int,float]], name:str,
                      min_val:Union[int,float,NoneType]=None,
                      max_val:Union[int,float,NoneType]=None)

Filter base class

Type Default Details
func typing.Callable[[chem_templates.chem.Molecule], typing.Union[int, float]] callable function, takes a Molecule as input, returns a numeric value
name str filter name
min_val typing.Union[int, float, NoneType] None min acceptable range value (if None, defaults to -inf)
max_val typing.Union[int, float, NoneType] None max acceptable range value (if None, defaults to inf)
from rdkit.Chem import rdMolDescriptors

molwt = mol_func_wrapper(rdMolDescriptors.CalcExactMolWt)

f = RangeFunctionFilter(molwt, 'molwt_filter', 250, 350)


mol1 = Molecule('Cc1nnc2n1-c1ccc(Cl)cc1C(c1ccccc1)=NC2')
mol2 = Molecule('CCCC')

assert f(mol1).filter_result
assert not f(mol2).filter_result

source

SmartsFilter

 SmartsFilter (smarts:str, name:str, exclude:bool=True,
               min_val:Union[int,float,NoneType]=None,
               max_val:Union[int,float,NoneType]=None)

Filter base class

Type Default Details
smarts str SMARTS string
name str filter name
exclude bool True if filter should be exclusion or inclusion
min_val typing.Union[int, float, NoneType] None min number of occurences
max_val typing.Union[int, float, NoneType] None max number of occurences
smarts = '[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1'

f1 = SmartsFilter(smarts, 'one_phenyl', min_val=1, max_val=1)
f2 = SmartsFilter(smarts, 'two_phenyl', min_val=2)

smiles = [
    'c1ccccc1',
    'Cc1cc(NC)cnc1',
    'Cc1cccc(NCc2ccccc2)c1'
]

molecules = [Molecule(i) for i in smiles]

assert f1.has_match(molecules[0])
assert not f1.has_match(molecules[1])
assert not f1.has_match(molecules[2])

assert not f2.has_match(molecules[0])
assert not f2.has_match(molecules[1])
assert f2.has_match(molecules[2])

source

SimpleSmartsFilter

 SimpleSmartsFilter (smarts:str, name:str,
                     min_val:Union[int,float,NoneType]=None,
                     max_val:Union[int,float,NoneType]=None)

Filter base class

Type Default Details
smarts str SMARTS string
name str filter name
min_val typing.Union[int, float, NoneType] None min number of occurences
max_val typing.Union[int, float, NoneType] None max number of occurences
smarts = '[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1'

f1 = SimpleSmartsFilter(smarts, 'one_phenyl', min_val=1, max_val=1)
f2 = SimpleSmartsFilter(smarts, 'two_phenyl', min_val=2)
f3 = SimpleSmartsFilter(smarts, 'zero_phenyl', max_val=0)

smiles = [
    'c1ccccc1',
    'Cc1cc(NC)cnc1',
    'Cc1cccc(NCc2ccccc2)c1'
]

molecules = [Molecule(i) for i in smiles]

assert f1(molecules[0]).filter_result
assert not f2(molecules[0]).filter_result
assert not f3(molecules[0]).filter_result

assert not f1(molecules[1]).filter_result
assert not f2(molecules[1]).filter_result
assert f3(molecules[1]).filter_result

assert not f1(molecules[2]).filter_result
assert f2(molecules[2]).filter_result
assert not f3(molecules[2]).filter_result

source

CatalogFilter

 CatalogFilter (catalog:chem_templates.chem.Catalog, name:str,
                exclude:bool=True)

Filter base class

Type Default Details
catalog Catalog SMARTS catalog
name str filter name
exclude bool True if filter should be exclusion or inclusion
from rdkit.Chem.FilterCatalog import FilterCatalogParams

catalog = Catalog.from_params(FilterCatalogParams.FilterCatalogs.PAINS)
f = CatalogFilter(catalog, 'pains')
molecule = Molecule('c1ccccc1N=Nc1ccccc1')

assert f.has_match(molecule)
assert not f(molecule).filter_result

source

Template

 Template (filters:list[__main__.Filter])

Template holds a list of filters and screens a molecule against all of them

Type Details
filters list list of filters

source

TemplateResult

 TemplateResult (result:bool, filter_results:list[bool],
                 filter_data:list[typing.Optional[__main__.FilterResult]])

Container for template results

Type Details
result bool overall pass/fail result
filter_results list pass/fail from individual filters
filter_data list filter data from individual filters
hbd = mol_func_wrapper(rdMolDescriptors.CalcNumHBD)
hba = mol_func_wrapper(rdMolDescriptors.CalcNumHBA)
molwt = mol_func_wrapper(rdMolDescriptors.CalcExactMolWt)

def logp(molecule):
    return rdMolDescriptors.CalcCrippenDescriptors(molecule.mol)[0]

filters = [
    ValidityFilter(),
    SingleCompoundFilter(),
    RangeFunctionFilter(hbd, 'hydrogen_bond_donors', None, 5),
    RangeFunctionFilter(hba, 'hydrogen_bond_acceptors', None, 10),
    RangeFunctionFilter(molwt, 'molecular_weight', None, 150),
    RangeFunctionFilter(logp, 'CLogP', None, 5)
]

template = Template(filters)

molecule = Molecule('c1ccccc1N=Nc1ccccc1')

res = template(molecule, early_exit=True)
assert res.result == False
assert res.filter_results == [True, True, True, True, False, False]

res = template(molecule, early_exit=False)
assert res.result == False
assert res.filter_results == [True, True, True, True, False, True]

assert template(Molecule('c1ccccc1N=N')).result