= Molecule('CCCC')
mol1 = Molecule('CCCc')
mol2 = Molecule('CCC.CCCC')
mol3
= ValidityFilter()
f1 = SingleCompoundFilter()
f2
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
Filters
Filter related functions
Filter
Filter (name='filter')
Filter base class
Type | Default | Details | |
---|---|---|---|
name | str | filter | filter name |
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 |
SingleCompoundFilter
SingleCompoundFilter ()
Checks if molecule is a single compound
ValidityFilter
ValidityFilter ()
Checks if molecule is valid
AttachmentCountFilter
AttachmentCountFilter (num_attachments:int)
Checks number of dummy attachment atoms
= Molecule('[*:1]CC')
mol1 = Molecule('[*:1]CC[*:2]')
mol2 = AttachmentCountFilter(1)
f
assert f(mol1).filter_result
assert not f(mol2).filter_result
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 |
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
= Molecule('Cc1nnc2n1-c1ccc(Cl)cc1C(c1ccccc1)=NC2')
mol1 = Molecule('CCCC')
mol2
def filter_func(molecule):
= rdMolDescriptors.CalcNumRings(molecule.mol)
n_rings return n_rings>1
= BinaryFunctionFilter(filter_func, 'has_ring')
f
assert f(mol1).filter_result
assert not f(mol2).filter_result
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
= mol_func_wrapper(rdMolDescriptors.CalcExactMolWt)
molwt
= RangeFunctionFilter(molwt, 'molwt_filter', 250, 350)
f
= Molecule('Cc1nnc2n1-c1ccc(Cl)cc1C(c1ccccc1)=NC2')
mol1 = Molecule('CCCC')
mol2
assert f(mol1).filter_result
assert not f(mol2).filter_result
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 |
= '[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1'
smarts
= SmartsFilter(smarts, 'one_phenyl', min_val=1, max_val=1)
f1 = SmartsFilter(smarts, 'two_phenyl', min_val=2)
f2
= [
smiles 'c1ccccc1',
'Cc1cc(NC)cnc1',
'Cc1cccc(NCc2ccccc2)c1'
]
= [Molecule(i) for i in smiles]
molecules
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])
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 |
= '[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1'
smarts
= SimpleSmartsFilter(smarts, 'one_phenyl', min_val=1, max_val=1)
f1 = SimpleSmartsFilter(smarts, 'two_phenyl', min_val=2)
f2 = SimpleSmartsFilter(smarts, 'zero_phenyl', max_val=0)
f3
= [
smiles 'c1ccccc1',
'Cc1cc(NC)cnc1',
'Cc1cccc(NCc2ccccc2)c1'
]
= [Molecule(i) for i in smiles]
molecules
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
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.from_params(FilterCatalogParams.FilterCatalogs.PAINS)
catalog = CatalogFilter(catalog, 'pains')
f = Molecule('c1ccccc1N=Nc1ccccc1')
molecule
assert f.has_match(molecule)
assert not f(molecule).filter_result
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 |
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 |
= mol_func_wrapper(rdMolDescriptors.CalcNumHBD)
hbd = mol_func_wrapper(rdMolDescriptors.CalcNumHBA)
hba = mol_func_wrapper(rdMolDescriptors.CalcExactMolWt)
molwt
def logp(molecule):
return rdMolDescriptors.CalcCrippenDescriptors(molecule.mol)[0]
= [
filters
ValidityFilter(),
SingleCompoundFilter(),'hydrogen_bond_donors', None, 5),
RangeFunctionFilter(hbd, 'hydrogen_bond_acceptors', None, 10),
RangeFunctionFilter(hba, 'molecular_weight', None, 150),
RangeFunctionFilter(molwt, 'CLogP', None, 5)
RangeFunctionFilter(logp,
]
= Template(filters)
template
= Molecule('c1ccccc1N=Nc1ccccc1')
molecule
= template(molecule, early_exit=True)
res assert res.result == False
assert res.filter_results == [True, True, True, True, False, False]
= template(molecule, early_exit=False)
res assert res.result == False
assert res.filter_results == [True, True, True, True, False, True]
assert template(Molecule('c1ccccc1N=N')).result