本文整理汇总了Python中rdkit.Chem.AllChem.ReactionFromSmarts方法的典型用法代码示例。如果您正苦于以下问题:Python AllChem.ReactionFromSmarts方法的具体用法?Python AllChem.ReactionFromSmarts怎么用?Python AllChem.ReactionFromSmarts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem.AllChem
的用法示例。
在下文中一共展示了AllChem.ReactionFromSmarts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crossover_non_ring
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def crossover_non_ring(parent_A, parent_B):
for i in range(10):
fragments_A = cut(parent_A)
fragments_B = cut(parent_B)
if fragments_A is None or fragments_B is None:
return None
rxn = AllChem.ReactionFromSmarts('[*:1]-[1*].[1*]-[*:2]>>[*:1]-[*:2]')
new_mol_trial = []
for fa in fragments_A:
for fb in fragments_B:
new_mol_trial.append(rxn.RunReactants((fa, fb))[0])
new_mols = []
for mol in new_mol_trial:
mol = mol[0]
if mol_ok(mol):
new_mols.append(mol)
if len(new_mols) > 0:
return random.choice(new_mols)
return None
示例2: TransformStringToImage
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def TransformStringToImage(transform, retro=True, options=None,**kwargs):
'''Wrapper function meant to take a SMARTS transform and return a PIL image
of that transform.
TODO: Need to improve generalization visually! Right now it still shows'''
if not options:
options = defaultDrawOptions()
options.dotsPerAngstrom = 40
# To generalize un-mapped atoms in transform, need to identify square brackets
# without colon in the middle (e.g., [C]) and replace with dummy label [C:0] so
# generalization display works
old_tags = re.findall('\[[^:]+\]', transform)
for old_tag in old_tags:
new_tag = old_tag.replace(']', ':0]')
transform = transform.replace(old_tag, new_tag)
rxn = AllChem.ReactionFromSmarts(transform)
return ReactionToImage(rxn, dummyAtoms=True, options=options, retro=retro, **kwargs)
示例3: initialize_rxn_from_smarts
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def initialize_rxn_from_smarts(reaction_smarts):
# Initialize reaction
rxn = AllChem.ReactionFromSmarts(reaction_smarts)
rxn.Initialize()
if rxn.Validate()[1] != 0:
raise ValueError('validation failed')
if PLEVEL >= 2: print('Validated rxn without errors')
unmapped = 700
for rct in rxn.GetReactants():
rct.UpdatePropertyCache()
Chem.AssignStereochemistry(rct)
# Fill in atom map numbers
for a in rct.GetAtoms():
if not a.HasProp('molAtomMapNumber'):
a.SetIntProp('molAtomMapNumber', unmapped)
unmapped += 1
if PLEVEL >= 2: print('Added {} map nums to unmapped reactants'.format(unmapped-700))
if unmapped > 800:
raise ValueError('Why do you have so many unmapped atoms in the template reactants?')
return rxn
示例4: crossover_non_ring
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def crossover_non_ring(parent_A,parent_B):
for i in range(10):
fragments_A = cut(parent_A)
fragments_B = cut(parent_B)
if fragments_A == None or fragments_B == None:
return None
rxn = AllChem.ReactionFromSmarts('[*:1]-[1*].[1*]-[*:2]>>[*:1]-[*:2]')
new_mol_trial = []
for fa in fragments_A:
for fb in fragments_B:
new_mol_trial.append(rxn.RunReactants((fa,fb))[0])
new_mols = []
for mol in new_mol_trial:
mol = mol[0]
if mol_OK(mol):
new_mols.append(mol)
if len(new_mols) > 0:
return random.choice(new_mols)
return None
示例5: __init__
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def __init__(self):
self.rxns = [
# Double bonds on aromatic rings (dist 1)
AllChem.ReactionFromSmarts('[NH0:1]=[a:2][nH:3]>>[NH:1][a:2][nH0:3]'),
AllChem.ReactionFromSmarts('[NH1:1]=[a:2][nH:3]>>[NH2:1][a:2][nH0:3]'),
AllChem.ReactionFromSmarts('[OH0:1]=[a:2][nH:3]>>[OH:1][a:2][nH0:3]'),
# Double bonds on aromatic rings (dist 2)
AllChem.ReactionFromSmarts('[NH0:1]=[a:2][a:4][nH:3]>>[NH:1][a:2][a:4][nH0:3]'),
AllChem.ReactionFromSmarts('[NH1:1]=[a:2][a:4][nH:3]>>[NH2:1][a:2][a:4][nH0:3]'),
AllChem.ReactionFromSmarts('[OH0:1]=[a:2][a:4][nH:3]>>[OH:1][a:2][a:4][nH0:3]'),
# Double bonds on aromatic rings (dist 2)
AllChem.ReactionFromSmarts('[NH0:1]=[a:2][a:4][a:5][nH:3]>>[NH:1][a:2][a:4][a:5][nH0:3]'),
AllChem.ReactionFromSmarts('[NH1:1]=[a:2][a:4][a:5][nH:3]>>[NH2:1][a:2][a:4][a:5][nH0:3]'),
AllChem.ReactionFromSmarts('[OH0:1]=[a:2][a:4][a:5][nH:3]>>[OH:1][a:2][a:4][a:5][nH0:3]'),
# Iminol / amide
AllChem.ReactionFromSmarts('[NH0:1]=[C:2]-[OH:3]>>[NH1:1]-[C:2]=[OH0:3]'),
AllChem.ReactionFromSmarts('[NH1:1]=[C:2]-[OH:3]>>[NH2:1]-[C:2]=[OH0:3]'),
# Thiourea
AllChem.ReactionFromSmarts('[NH0:1]=[C:2]-[SH:3]>>[NH1:1]-[C:2]=[SH0:3]'),
AllChem.ReactionFromSmarts('[NH1:1]=[C:2]-[SH:3]>>[NH2:1]-[C:2]=[SH0:3]'),
# Azide
AllChem.ReactionFromSmarts('[NH0:1][NH0:2]=[NH0;-:3]>>[NH0;-:1]=[NH0;+:2]=[NH0;-:3]'),
# Cyanide salts
AllChem.ReactionFromSmarts('([K,Na;H1:1].[C;X1;H0:2]#[N:3])>>[*;H0:1][*:2]#[N:3]'),
AllChem.ReactionFromSmarts('([Cu:1].[C;X1;H0:2]#[N:3])>>[*:1][*:2]#[N:3]'),
# Grinards
AllChem.ReactionFromSmarts('([MgH+:1].[C;v3:2][*:3])>>[Mg+:1][*:2][*:3]'),
# Coordinated tin
AllChem.ReactionFromSmarts('([SnH4:1].[C;v3:2].[C;v3:3].[C;v3:4].[C;v3:5])>>[Sn:1]([*:2])([*:3])([*:4])[*:5]'),
AllChem.ReactionFromSmarts('([SnH3:1].[C;v3:2].[C;v3:3].[C;v3:4])>>[Sn:1]([*:2])([*:3])[*:4]'),
AllChem.ReactionFromSmarts('([SnH2:1].[C;v3:2].[C;v3:3])>>[Sn:1]([*:2])[*:3]'),
AllChem.ReactionFromSmarts('([SnH1:1].[C;v3:2])>>[Sn:1][*:2]'),
]
示例6: initialize_rxn_from_smarts
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def initialize_rxn_from_smarts(reaction_smarts):
# Initialize reaction
rxn = AllChem.ReactionFromSmarts(reaction_smarts)
rxn.Initialize()
if rxn.Validate()[1] != 0:
raise ValueError('validation failed')
if PLEVEL >= 2: print('Validated rxn without errors')
# Figure out if there are unnecessary atom map numbers (that are not balanced)
# e.g., leaving groups for retrosynthetic templates. This is because additional
# atom map numbers in the input SMARTS template may conflict with the atom map
# numbers of the molecules themselves
prd_maps = [a.GetAtomMapNum() for prd in rxn.GetProducts() for a in prd.GetAtoms() if a.GetAtomMapNum()]
unmapped = 700
for rct in rxn.GetReactants():
rct.UpdatePropertyCache()
Chem.AssignStereochemistry(rct)
# Fill in atom map numbers
for a in rct.GetAtoms():
if not a.GetAtomMapNum() or a.GetAtomMapNum() not in prd_maps:
a.SetAtomMapNum(unmapped)
unmapped += 1
if PLEVEL >= 2: print('Added {} map nums to unmapped reactants'.format(unmapped-700))
if unmapped > 800:
raise ValueError('Why do you have so many unmapped atoms in the template reactants?')
return rxn
示例7: setUp
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def setUp(self):
for smiles in REACTION_SMILES_SAMPLE:
ReactionModel.objects.create(rxn=smiles)
for smarts in REACTION_SMARTS_SAMPLE:
ReactionModel.objects.create(
rxn=Chem.ReactionFromSmarts(str(smarts)))
示例8: from_db_value
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def from_db_value(self, value, expression, connection):
if value is None:
return value
return Chem.ReactionFromSmarts(value, useSmiles=True)
示例9: to_python
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def to_python(self, value):
if value is None or isinstance(value, Chem.ChemicalReaction):
return value
elif isinstance(value, str):
# The string case. A reaction SMILES is expected.
return Chem.ReactionFromSmarts(str(value), useSmiles=True)
else:
raise ValidationError("Invalid input for a ChemicalReaction instance")
示例10: crossover_ring
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def crossover_ring(parent_A, parent_B):
ring_smarts = Chem.MolFromSmarts('[R]')
if not parent_A.HasSubstructMatch(ring_smarts) and not parent_B.HasSubstructMatch(ring_smarts):
return None
rxn_smarts1 = ['[*:1]~[1*].[1*]~[*:2]>>[*:1]-[*:2]', '[*:1]~[1*].[1*]~[*:2]>>[*:1]=[*:2]']
rxn_smarts2 = ['([*:1]~[1*].[1*]~[*:2])>>[*:1]-[*:2]', '([*:1]~[1*].[1*]~[*:2])>>[*:1]=[*:2]']
for i in range(10):
fragments_A = cut_ring(parent_A)
fragments_B = cut_ring(parent_B)
if fragments_A is None or fragments_B is None:
return None
new_mol_trial = []
for rs in rxn_smarts1:
rxn1 = AllChem.ReactionFromSmarts(rs)
new_mol_trial = []
for fa in fragments_A:
for fb in fragments_B:
new_mol_trial.append(rxn1.RunReactants((fa, fb))[0])
new_mols = []
for rs in rxn_smarts2:
rxn2 = AllChem.ReactionFromSmarts(rs)
for m in new_mol_trial:
m = m[0]
if mol_ok(m):
new_mols += list(rxn2.RunReactants((m,)))
new_mols2 = []
for m in new_mols:
m = m[0]
if mol_ok(m) and ring_OK(m):
new_mols2.append(m)
if len(new_mols2) > 0:
return random.choice(new_mols2)
return None
示例11: mutate
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def mutate(mol, mutation_rate):
if random.random() > mutation_rate:
return mol
try:
Chem.Kekulize(mol, clearAromaticFlags=True)
except ValueError:
return mol
p = [0.15, 0.14, 0.14, 0.14, 0.14, 0.14, 0.15]
for i in range(10):
rxn_smarts_list = 7 * ['']
rxn_smarts_list[0] = insert_atom()
rxn_smarts_list[1] = change_bond_order()
rxn_smarts_list[2] = delete_cyclic_bond()
rxn_smarts_list[3] = add_ring()
rxn_smarts_list[4] = delete_atom()
rxn_smarts_list[5] = change_atom(mol)
rxn_smarts_list[6] = append_atom()
rxn_smarts = np.random.choice(rxn_smarts_list, p=p)
# print 'mutation',rxn_smarts
rxn = AllChem.ReactionFromSmarts(rxn_smarts)
new_mol_trial = rxn.RunReactants((mol,))
new_mols = []
for m in new_mol_trial:
m = m[0]
# print Chem.MolToSmiles(mol),mol_ok(mol)
if co.mol_ok(m) and co.ring_OK(m):
new_mols.append(m)
if len(new_mols) > 0:
return random.choice(new_mols)
return None
示例12: run_rxn
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def run_rxn(rxn_smarts, mol):
new_mol_list = []
patt = rxn_smarts.split('>>')[0]
# work on a copy so an un-kekulized version is returned
# if the molecule is not changed
mol_copy = Chem.Mol(mol)
try:
Chem.Kekulize(mol_copy)
except ValueError:
pass
if mol_copy.HasSubstructMatch(Chem.MolFromSmarts(patt)):
rxn = AllChem.ReactionFromSmarts(rxn_smarts)
new_mols = rxn.RunReactants((mol_copy,))
for new_mol in new_mols:
try:
Chem.SanitizeMol(new_mol[0])
new_mol_list.append(new_mol[0])
except ValueError:
pass
if len(new_mol_list) > 0:
new_mol = random.choice(new_mol_list)
return new_mol
else:
return mol
else:
return mol
示例13: transform
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def transform(self):
log.debug('Loading Normalization transform: %s', self.name)
return AllChem.ReactionFromSmarts(str(self.transform_str))
示例14: fingerprint_reactions
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def fingerprint_reactions(reactions, fp_dim):
fps = []
for r in reactions:
rxn = AllChem.ReactionFromSmarts(r)
# fp = AllChem.CreateDifferenceFingerprintForReaction(rxn)
fp = AllChem.CreateStructuralFingerprintForReaction(rxn)
fold_factor = fp.GetNumBits()//fp_dim
fp = DataStructs.FoldFingerprint(fp, fold_factor)
fps.append(fp)
return fps
示例15: transform
# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import ReactionFromSmarts [as 别名]
def transform(mol, rule):
"""Apply transformation rule to a molecule to get reactants"""
rxn = AllChem.ReactionFromSmarts(rule)
results = rxn.RunReactants([mol])
# Only look at first set of results (TODO any reason not to?)
results = results[0]
reactants = [Chem.MolToSmiles(smi) for smi in results]
return reactants