本文整理汇总了Python中rdkit.Chem.MolFromSmarts方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.MolFromSmarts方法的具体用法?Python Chem.MolFromSmarts怎么用?Python Chem.MolFromSmarts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.MolFromSmarts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def new_mol(self, name):
if self.sanitized:
mol = Chem.MolFromSmiles(name)
else:
mol = Chem.MolFromSmarts(name)
if mol is None:
return None
else:
mg = MolGraph(name, self.sanitized, mol=mol)
if self.fp_degree > 0:
bi = {} if self.fp_info else None
feat = AllChem.GetMorganFingerprint(mol, self.fp_degree, bitInfo=bi, invariants=self._get_inv(mol))
on_bits = list(feat.GetNonzeroElements().keys())
mg.fingerprints = on_bits
mg.fp_info = bi
return mg
示例2: cut
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def cut(mol):
if not mol.HasSubstructMatch(Chem.MolFromSmarts('[*]-;!@[*]')):
return None
bis = random.choice(mol.GetSubstructMatches(Chem.MolFromSmarts('[*]-;!@[*]'))) # single bond not in ring
bs = [mol.GetBondBetweenAtoms(bis[0], bis[1]).GetIdx()]
fragments_mol = Chem.FragmentOnBonds(mol, bs, addDummies=True, dummyLabels=[(1, 1)])
try:
return Chem.GetMolFrags(fragments_mol, asMols=True, sanitizeFrags=True)
except ValueError:
return None
return None
示例3: ring_OK
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def ring_OK(mol):
if not mol.HasSubstructMatch(Chem.MolFromSmarts('[R]')):
return True
ring_allene = mol.HasSubstructMatch(Chem.MolFromSmarts('[R]=[R]=[R]'))
cycle_list = mol.GetRingInfo().AtomRings()
max_cycle_length = max([len(j) for j in cycle_list])
macro_cycle = max_cycle_length > 6
double_bond_in_small_ring = mol.HasSubstructMatch(Chem.MolFromSmarts('[r3,r4]=[r3,r4]'))
return not ring_allene and not macro_cycle and not double_bond_in_small_ring
# TODO: set from main? calculate for dataset?
示例4: add_atom
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def add_atom(rdkit_mol, stats: Stats):
old_mol = Chem.Mol(rdkit_mol)
if np.random.random() < 0.63: # probability of adding ring atom
rxn_smarts = np.random.choice(stats.rxn_smarts_ring_list, p=stats.p_ring)
if not rdkit_mol.HasSubstructMatch(Chem.MolFromSmarts('[r3,r4,r5]')) \
or AllChem.CalcNumAliphaticRings(rdkit_mol) == 0:
rxn_smarts = np.random.choice(stats.rxn_smarts_make_ring, p=stats.p_ring)
if np.random.random() < 0.036: # probability of starting a fused ring
rxn_smarts = rxn_smarts.replace("!", "")
else:
if rdkit_mol.HasSubstructMatch(Chem.MolFromSmarts('[*]1=[*]-[*]=[*]-1')):
rxn_smarts = '[r4:1][r4:2]>>[*:1]C[*:2]'
else:
rxn_smarts = np.random.choice(stats.rxn_smarts_list, p=stats.p)
rdkit_mol = run_rxn(rxn_smarts, rdkit_mol)
if valences_not_too_large(rdkit_mol):
return rdkit_mol
else:
return old_mol
示例5: BuildPatts
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def BuildPatts(rawV=None):
""" Internal Use Only
"""
global esPatterns, _rawD
if rawV is None:
rawV = _rawD
esPatterns = [None] * len(rawV)
for i, (name, sma) in enumerate(rawV):
try:
patt = Chem.MolFromSmarts(sma)
except:
sys.stderr.write(
"WARNING: problems with pattern %s (name: %s), skipped.\n" % (sma, name)
)
else:
esPatterns[i] = name, patt
示例6: __init__
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def __init__(self):
log.debug("Initializing MetalDisconnector")
# Initialize SMARTS to identify relevant substructures
# TODO: Use atomic numbers instead of element symbols in SMARTS to allow for isotopes?
self._metal_nof = Chem.MolFromSmarts(
"[Li,Na,K,Rb,Cs,F,Be,Mg,Ca,Sr,Ba,Ra,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Al,Ga,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi]~[N,O,F]".encode(
"utf8"
)
)
self._metal_non = Chem.MolFromSmarts(
"[Al,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,Hf,Ta,W,Re,Os,Ir,Pt,Au]~[B,C,Si,P,As,Sb,S,Se,Te,Cl,Br,I,At]".encode(
"utf8"
)
)
self._free_metal = Chem.MolFromSmarts("[Li,Na,K,Mg,CaX0+0]".encode("utf8"))
self._carboxylic = Chem.MolFromSmarts("[CX3](=O)[OX2H1]".encode("utf8"))
示例7: initialise_neutralisation_reactions
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def initialise_neutralisation_reactions():
patts = (
# Imidazoles
('[n+;H]', 'n'),
# Amines
('[N+;!H0]', 'N'),
# Carboxylic acids and alcohols
('[$([O-]);!$([O-][#7])]', 'O'),
# Thiols
('[S-;X1]', 'S'),
# Sulfonamides
('[$([N-;X2]S(=O)=O)]', 'N'),
# Enamines
('[$([N-;X2][C,N]=C)]', 'N'),
# Tetrazoles
('[n-]', '[nH]'),
# Sulfoxides
('[$([S-]=O)]', 'S'),
# Amides
('[$([N-]C=O)]', 'N'),
)
return [(Chem.MolFromSmarts(x), Chem.MolFromSmiles(y, False)) for x, y in patts]
示例8: __init__
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def __init__(self, x_set, c_set, y_set, batch, task="binary", num_atoms=0,
use_degree=True, use_hybridization=True, use_implicit_valence=True, use_partial_charge=False,
use_formal_charge=True, use_ring_size=True, use_hydrogen_bonding=True, use_acid_base=True,
use_aromaticity=True, use_chirality=True, use_num_hydrogen=True, use_atom_symbol=True):
self.x, self.c, self.y = x_set, c_set, y_set
self.batch = batch
self.task = task
self.num_atoms = num_atoms
self.use_atom_symbol = use_atom_symbol
self.use_degree = use_degree
self.use_hybridization = use_hybridization
self.use_implicit_valence = use_implicit_valence
self.use_partial_charge = use_partial_charge
self.use_formal_charge = use_formal_charge
self.use_ring_size = use_ring_size
self.use_hydrogen_bonding = use_hydrogen_bonding
self.use_acid_base = use_acid_base
self.use_aromaticity = use_aromaticity
self.use_chirality = use_chirality
self.use_num_hydrogen = use_num_hydrogen
self.hydrogen_donor = Chem.MolFromSmarts("[$([N;!H0;v3,v4&+1]),$([O,S;H1;+0]),n&H1&+0]")
self.hydrogen_acceptor = Chem.MolFromSmarts(
"[$([O,S;H1;v2;!$(*-*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N;v3;!$(N-*=[O,N,P,S])]),n&H0&+0,$([o,s;+0;!$([o,s]:n);!$([o,s]:c:n)])]")
self.acidic = Chem.MolFromSmarts("[$([C,S](=[O,S,P])-[O;H1,-1])]")
self.basic = Chem.MolFromSmarts(
"[#7;+,$([N;H2&+0][$([C,a]);!$([C,a](=O))]),$([N;H1&+0]([$([C,a]);!$([C,a](=O))])[$([C,a]);!$([C,a](=O))]),$([N;H0&+0]([C;!$(C(=O))])([C;!$(C(=O))])[C;!$(C(=O))])]")
示例9: get_rotatable_bonds
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def get_rotatable_bonds(mol):
"""
https://github.com/rdkit/rdkit/blob/f4529c910e546af590c56eba01f96e9015c269a6/Code/GraphMol/Descriptors/Lipinski.cpp#L107
Taken from rdkit source to find which bonds are rotatable store
rotatable bonds in (from_atom, to_atom)
Parameters
----------
mol: rdkit Mol
Ligand molecule
Returns
-------
rotatable_bonds: list
List of rotatable bonds in molecule
"""
from rdkit import Chem
from rdkit.Chem import rdmolops
pattern = Chem.MolFromSmarts(
"[!$(*#*)&!D1&!$(C(F)(F)F)&!$(C(Cl)(Cl)Cl)&!$(C(Br)(Br)Br)&!$(C([CH3])("
"[CH3])[CH3])&!$([CD3](=[N,O,S])-!@[#7,O,S!D1])&!$([#7,O,S!D1]-!@[CD3]="
"[N,O,S])&!$([CD3](=[N+])-!@[#7!D1])&!$([#7!D1]-!@[CD3]=[N+])]-!@[!$(*#"
"*)&!D1&!$(C(F)(F)F)&!$(C(Cl)(Cl)Cl)&!$(C(Br)(Br)Br)&!$(C([CH3])([CH3])"
"[CH3])]")
rdmolops.FastFindRings(mol)
rotatable_bonds = mol.GetSubstructMatches(pattern)
return rotatable_bonds
示例10: cano_smarts
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def cano_smarts(smarts):
tmp = Chem.MolFromSmarts(smarts)
if tmp is None:
return None, smarts
[a.ClearProp('molAtomMapNumber') for a in tmp.GetAtoms()]
cano = Chem.MolToSmarts(tmp)
if '[[se]]' in cano: # strange parse error
cano = smarts
return tmp, cano
示例11: cut_ring
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def cut_ring(mol):
for i in range(10):
if random.random() < 0.5:
if not mol.HasSubstructMatch(Chem.MolFromSmarts('[R]@[R]@[R]@[R]')):
return None
bis = random.choice(mol.GetSubstructMatches(Chem.MolFromSmarts('[R]@[R]@[R]@[R]')))
bis = ((bis[0], bis[1]), (bis[2], bis[3]),)
else:
if not mol.HasSubstructMatch(Chem.MolFromSmarts('[R]@[R;!D2]@[R]')):
return None
bis = random.choice(mol.GetSubstructMatches(Chem.MolFromSmarts('[R]@[R;!D2]@[R]')))
bis = ((bis[0], bis[1]), (bis[1], bis[2]),)
bs = [mol.GetBondBetweenAtoms(x, y).GetIdx() for x, y in bis]
fragments_mol = Chem.FragmentOnBonds(mol, bs, addDummies=True, dummyLabels=[(1, 1), (1, 1)])
try:
fragments = Chem.GetMolFrags(fragments_mol, asMols=True, sanitizeFrags=True)
if len(fragments) == 2:
return fragments
except ValueError:
return None
return None
示例12: crossover_ring
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [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
示例13: change_atom
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def change_atom(mol):
choices = ['#6', '#7', '#8', '#9', '#16', '#17', '#35']
p = [0.15, 0.15, 0.14, 0.14, 0.14, 0.14, 0.14]
X = np.random.choice(choices, p=p)
while not mol.HasSubstructMatch(Chem.MolFromSmarts('[' + X + ']')):
X = np.random.choice(choices, p=p)
Y = np.random.choice(choices, p=p)
while Y == X:
Y = np.random.choice(choices, p=p)
return '[X:1]>>[Y:1]'.replace('X', X).replace('Y', Y)
示例14: count_macro_cycles
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [as 别名]
def count_macro_cycles(smiles_list, smarts_list, tot, probs):
"""
Args:
smiles_list: list of SMILES
smarts_list: list of SMARTS
tot: counter of ... TODO: why is this passed?
probs: OrderedDict of {SMARTS: counts}
Returns:
"""
# probs = collections.OrderedDict()
for smarts in smarts_list:
probs[smarts] = 0
for smiles in smiles_list:
for smarts in smarts_list:
mol = Chem.MolFromSmiles(smiles)
Chem.Kekulize(mol)
matches = mol.GetSubstructMatches(Chem.MolFromSmarts(smarts), uniquify=True)
if len(matches) > 0:
probs[smarts] += 1
tot += 1
return tot, probs
示例15: run_rxn
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmarts [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