本文整理汇总了Python中rdkit.Chem.GetMolFrags方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.GetMolFrags方法的具体用法?Python Chem.GetMolFrags怎么用?Python Chem.GetMolFrags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.GetMolFrags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_rdkit_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def validate_rdkit_mol(mol):
"""
Sanitizes an RDKit molecules and returns True if the molecule is chemically
valid.
:param mol: an RDKit molecule
:return: True if the molecule is chemically valid, False otherwise
"""
if rdc is None:
raise ImportError('`validate_rdkit_mol` requires RDkit.')
if len(rdc.GetMolFrags(mol)) > 1:
return False
try:
rdc.SanitizeMol(mol)
return True
except ValueError:
return False
示例2: cut
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [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: remove
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def remove(self, mol):
"""Return the molecule with specified fragments removed.
:param mol: The molecule to remove fragments from.
:type mol: rdkit.Chem.rdchem.Mol
:return: The molecule with fragments removed.
:rtype: rdkit.Chem.rdchem.Mol
"""
log.debug('Running FragmentRemover')
# Iterate FragmentPatterns and remove matching fragments
for frag in self.fragments:
# If nothing is left or leave_last and only one fragment, end here
if mol.GetNumAtoms() == 0 or (self.leave_last and len(Chem.GetMolFrags(mol)) <= 1):
break
# Apply removal for this FragmentPattern
removed = Chem.DeleteSubstructs(mol, frag.smarts, onlyFrags=True)
if not mol.GetNumAtoms() == removed.GetNumAtoms():
log.info('Removed fragment: %s', frag.name)
if self.leave_last and removed.GetNumAtoms() == 0:
# All the remaining fragments match this pattern - leave them all
break
mol = removed
return mol
示例4: normalize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def normalize(self, mol):
"""Apply a series of Normalization transforms to correct functional groups and recombine charges.
A series of transforms are applied to the molecule. For each Normalization, the transform is applied repeatedly
until no further changes occur. If any changes occurred, we go back and start from the first Normalization
again, in case the changes mean an earlier transform is now applicable. The molecule is returned once the entire
series of Normalizations cause no further changes or if max_restarts (default 200) is reached.
:param mol: The molecule to normalize.
:type mol: rdkit.Chem.rdchem.Mol
:return: The normalized fragment.
:rtype: rdkit.Chem.rdchem.Mol
"""
log.debug('Running Normalizer')
# Normalize each fragment separately to get around quirky RunReactants behaviour
fragments = []
for fragment in Chem.GetMolFrags(mol, asMols=True):
fragments.append(self._normalize_fragment(fragment))
# Join normalized fragments into a single molecule again
outmol = fragments.pop()
for fragment in fragments:
outmol = Chem.CombineMols(outmol, fragment)
Chem.SanitizeMol(outmol)
return outmol
示例5: keep_largest_fragment
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def keep_largest_fragment(sml):
"""Function that returns the SMILES sequence of the largest fragment for a input
SMILES sequnce.
Args:
sml: SMILES sequence.
Returns:
canonical SMILES sequnce of the largest fragment.
"""
mol_frags = Chem.GetMolFrags(Chem.MolFromSmiles(sml), asMols=True)
largest_mol = None
largest_mol_size = 0
for mol in mol_frags:
size = mol.GetNumAtoms()
if size > largest_mol_size:
largest_mol = mol
largest_mol_size = size
return Chem.MolToSmiles(largest_mol)
示例6: remove
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def remove(self, mol):
"""Return the molecule with specified fragments removed.
:param mol: The molecule to remove fragments from.
:type mol: :rdkit:`Mol <Chem.rdchem.Mol-class.html>`
:return: The molecule with fragments removed.
:rtype: :rdkit:`Mol <Chem.rdchem.Mol-class.html>`
"""
log.debug("Running FragmentRemover")
# Iterate FragmentPatterns and remove matching fragments
for frag in self.fragments:
# If nothing is left or leave_last and only one fragment, end here
if mol.GetNumAtoms() == 0 or (
self.leave_last and len(Chem.GetMolFrags(mol)) <= 1
):
break
# Apply removal for this FragmentPattern
removed = Chem.DeleteSubstructs(mol, frag.smarts, onlyFrags=True)
if not mol.GetNumAtoms() == removed.GetNumAtoms():
log.info("Removed fragment: %s", frag.name)
if self.leave_last and removed.GetNumAtoms() == 0:
# All the remaining fragments match this pattern - leave them all
break
mol = removed
return mol
示例7: normalize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def normalize(self, mol):
"""Apply a series of Normalization transforms to correct functional groups and recombine charges.
A series of transforms are applied to the molecule. For each Normalization, the transform is applied repeatedly
until no further changes occur. If any changes occurred, we go back and start from the first Normalization
again, in case the changes mean an earlier transform is now applicable. The molecule is returned once the entire
series of Normalizations cause no further changes or if max_restarts (default 200) is reached.
:param mol: The molecule to normalize.
:type mol: :rdkit:`Mol <Chem.rdchem.Mol-class.html>`
:return: The normalized fragment.
:rtype: :rdkit:`Mol <Chem.rdchem.Mol-class.html>`
"""
log.debug("Running Normalizer")
# Normalize each fragment separately to get around quirky RunReactants behaviour
fragments = []
for fragment in Chem.GetMolFrags(mol, asMols=True):
fragments.append(self._normalize_fragment(fragment))
# Join normalized fragments into a single molecule again
outmol = fragments.pop()
for fragment in fragments:
outmol = Chem.CombineMols(outmol, fragment)
Chem.SanitizeMol(outmol)
return outmol
示例8: cut_ring
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [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
示例9: _check_matches_fragment
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def _check_matches_fragment(self, mol):
matches = frozenset(frozenset(match) for match in mol.GetSubstructMatches(self._smarts))
fragments = frozenset(frozenset(frag) for frag in Chem.GetMolFrags(mol))
if matches & fragments:
self.log.log(self.level, self.message, {'smarts': self.smarts})
示例10: run
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def run(self, mol):
for fp in self.fragments:
matches = frozenset(frozenset(match) for match in mol.GetSubstructMatches(fp.smarts))
fragments = frozenset(frozenset(frag) for frag in Chem.GetMolFrags(mol))
if matches & fragments:
self.log.info('%s is present', fp.name)
示例11: clean_charges
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def clean_charges(mol):
"""
This hack should not be needed anymore, but is kept just in case
"""
Chem.SanitizeMol(mol)
#rxn_smarts = ['[N+:1]=[*:2]-[C-:3]>>[N+0:1]-[*:2]=[C-0:3]',
# '[N+:1]=[*:2]-[O-:3]>>[N+0:1]-[*:2]=[O-0:3]',
# '[N+:1]=[*:2]-[*:3]=[*:4]-[O-:5]>>[N+0:1]-[*:2]=[*:3]-[*:4]=[O-0:5]',
# '[#8:1]=[#6:2]([!-:6])[*:3]=[*:4][#6-:5]>>[*-:1][*:2]([*:6])=[*:3][*:4]=[*+0:5]',
# '[O:1]=[c:2][c-:3]>>[*-:1][*:2][*+0:3]',
# '[O:1]=[C:2][C-:3]>>[*-:1][*:2]=[*+0:3]']
rxn_smarts = ['[#6,#7:1]1=[#6,#7:2][#6,#7:3]=[#6,#7:4][CX3-,NX3-:5][#6,#7:6]1=[#6,#7:7]>>'
'[#6,#7:1]1=[#6,#7:2][#6,#7:3]=[#6,#7:4][-0,-0:5]=[#6,#7:6]1[#6-,#7-:7]',
'[#6,#7:1]1=[#6,#7:2][#6,#7:3](=[#6,#7:4])[#6,#7:5]=[#6,#7:6][CX3-,NX3-:7]1>>'
'[#6,#7:1]1=[#6,#7:2][#6,#7:3]([#6-,#7-:4])=[#6,#7:5][#6,#7:6]=[-0,-0:7]1']
fragments = Chem.GetMolFrags(mol,asMols=True,sanitizeFrags=False)
for i, fragment in enumerate(fragments):
for smarts in rxn_smarts:
patt = Chem.MolFromSmarts(smarts.split(">>")[0])
while fragment.HasSubstructMatch(patt):
rxn = AllChem.ReactionFromSmarts(smarts)
ps = rxn.RunReactants((fragment,))
fragment = ps[0][0]
Chem.SanitizeMol(fragment)
if i == 0:
mol = fragment
else:
mol = Chem.CombineMols(mol, fragment)
return mol
示例12: _check_matches_fragment
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def _check_matches_fragment(self, mol):
matches = frozenset(
frozenset(match) for match in mol.GetSubstructMatches(self._smarts)
)
fragments = frozenset(frozenset(frag) for frag in Chem.GetMolFrags(mol))
if matches & fragments:
self.log.log(self.level, self.message, {"smarts": self.smarts})
示例13: run
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def run(self, mol):
for fp in self.fragments:
matches = frozenset(
frozenset(match) for match in mol.GetSubstructMatches(fp.smarts)
)
fragments = frozenset(frozenset(frag) for frag in Chem.GetMolFrags(mol))
if matches & fragments:
self.log.info("%s is present", fp.name)
示例14: cut
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [as 别名]
def cut(mol):
if not mol.HasSubstructMatch(Chem.MolFromSmarts('[*]-;!@[*]')):
return None
bis = random.choice(mol.GetSubstructMatches(Chem.MolFromSmarts('[*]-;!@[*]'))) #single bond not in ring
#print bis,bis[0],bis[1]
bs = [mol.GetBondBetweenAtoms(bis[0],bis[1]).GetIdx()]
fragments_mol = Chem.FragmentOnBonds(mol,bs,addDummies=True,dummyLabels=[(1, 1)])
try:
fragments = Chem.GetMolFrags(fragments_mol,asMols=True)
return fragments
except:
return None
示例15: cut_ring
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetMolFrags [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]),)
#print bis
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)
except:
return None
if len(fragments) == 2:
return fragments
return None