本文整理汇总了Python中rdkit.Chem.Mol方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.Mol方法的具体用法?Python Chem.Mol怎么用?Python Chem.Mol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.Mol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MolToQPixmap
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def MolToQPixmap(mol, size=(300, 300), kekulize=True, wedgeBonds=True, fitImage=False, options=None,
**kwargs):
""" Generates a drawing of a molecule on a Qt QPixmap
"""
if not mol:
raise ValueError('Null molecule provided')
from rdkit.Chem.Draw.qtCanvas import Canvas
canvas = Canvas(size)
if options is None:
options = DrawingOptions()
options.bgColor = None
if fitImage:
options.dotsPerAngstrom = int(min(size) / 10)
options.wedgeDashedBonds = wedgeBonds
if kekulize:
from rdkit import Chem
mol = Chem.Mol(mol.ToBinary())
Chem.Kekulize(mol)
if not mol.GetNumConformers():
from rdkit.Chem import AllChem
AllChem.Compute2DCoords(mol)
drawer = MolDrawing(canvas=canvas, drawingOptions=options)
drawer.AddMol(mol, **kwargs)
canvas.flush()
return canvas.pixmap
示例2: get_conformer_rmsd
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def get_conformer_rmsd(mol):
"""
Calculate conformer-conformer RMSD.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
from rdkit.Chem import AllChem
rmsd = np.zeros(
(mol.GetNumConformers(), mol.GetNumConformers()), dtype=float)
for i, ref_conf in enumerate(mol.GetConformers()):
for j, fit_conf in enumerate(mol.GetConformers()):
if i >= j:
continue
rmsd[i, j] = AllChem.GetBestRMS(mol, mol, ref_conf.GetId(),
fit_conf.GetId())
rmsd[j, i] = rmsd[i, j]
return rmsd
示例3: sanitizeMol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def sanitizeMol(self, kekulize=False, drawkekulize=False):
self.computeNewCoords()
self._drawmol = Chem.Mol(self._mol.ToBinary()) #Is this necessary?
try:
Chem.SanitizeMol(self._drawmol)
self.sanitizeSignal.emit("Sanitizable")
except:
self.sanitizeSignal.emit("UNSANITIZABLE")
self.logger.warning("Unsanitizable")
try:
self._drawmol.UpdatePropertyCache(strict=False)
except:
self.sanitizeSignal.emit("UpdatePropertyCache FAIL")
self.logger.error("Update Property Cache failed")
#Kekulize
if kekulize:
try:
Chem.Kekulize(self._drawmol)
except:
self.logger.warning("Unkekulizable")
try:
self._drawmol = rdMolDraw2D.PrepareMolForDrawing(self._drawmol, kekulize=drawkekulize)
except ValueError: # <- can happen on a kekulization failure
self._drawmol = rdMolDraw2D.PrepareMolForDrawing(self._drawmol, kekulize=False)
示例4: to_rdkit_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def to_rdkit_mol(self):
"""
Convert the graph to an RDKit molecule with atom map numbers set
by the indices of the atoms.
"""
assert all(atom.idx is not None for atom in self)
rd_mol = Chem.rdchem.EditableMol(Chem.rdchem.Mol())
for atom in self:
rd_atom = Chem.rdchem.Atom(atom.symbol)
rd_atom.SetAtomMapNum(atom.idx)
rd_mol.AddAtom(rd_atom)
for atom1 in self:
for atom2 in atom1.connections.keys():
idx1 = self.atoms.index(atom1) # This is the index in the atoms list
idx2 = self.atoms.index(atom2)
if idx1 < idx2:
rd_mol.AddBond(idx1, idx2, Chem.rdchem.BondType.SINGLE)
rd_mol = rd_mol.GetMol()
return rd_mol
示例5: add_atom
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [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
示例6: write
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def write(self, molecule):
"""Write a molecule to the output file.
Required parameters:
molecule
"""
if not self.filename:
raise IOError("Outputfile instance is closed.")
if self.format in ('inchi', 'inchikey', 'mol2'):
self._writer.write(molecule.write(self.format) + '\n')
if self.format == 'pdbqt':
self._writer.write('MODEL %i\n' % (self.total + 1) +
molecule.write(self.format) + '\nENDMDL\n')
else:
self._writer.write(molecule.Mol)
self.total += 1
示例7: calcdesc
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def calcdesc(self, descnames=None):
"""Calculate descriptor values.
Optional parameter:
descnames -- a list of names of descriptors
If descnames is not specified, all available descriptors are
calculated. See the descs variable for a list of available
descriptors.
"""
descnames = descnames or descs
ans = {}
for descname in descnames:
try:
desc = _descDict[descname]
except KeyError:
raise ValueError("%s is not a recognised RDKit descriptor type" % descname)
ans[descname] = desc(self.Mol)
return ans
示例8: make3D
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def make3D(self, forcefield="mmff94", steps=50):
"""Generate 3D coordinates.
Optional parameters:
forcefield -- default is "uff". See the forcefields variable
for a list of available forcefields.
steps -- default is 50
Once coordinates are generated, a quick
local optimization is carried out with 50 steps and the
UFF forcefield. Call localopt() if you want
to improve the coordinates further.
"""
forcefield = forcefield.lower()
success = AllChem.EmbedMolecule(self.Mol,
useExpTorsionAnglePrefs=True,
useBasicKnowledge=True,
enforceChirality=True,
)
if success == -1:
raise Exception("Embedding failed!")
self.localopt(forcefield, steps)
self._clear_cache()
示例9: __getstate__
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def __getstate__(self):
if self._source is None:
state = {'Mol': self.Mol,
'source': None,
'protein': self.protein,
'data': dict([(k, self.Mol.GetProp(k))
for k in self.Mol.GetPropNames(includePrivate=True)]),
'dicts': {'atom_dict': self._atom_dict,
'ring_dict': self._ring_dict,
'res_dict': self._res_dict,
}
}
else:
state = {'Mol': None,
'source': self._source,
'data': {},
'protein': self.protein,
'dicts': {'atom_dict': None,
'ring_dict': None,
'res_dict': None,
}
}
return state
示例10: get_anchor_smiles
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def get_anchor_smiles(mol, anchor, idxfunc=idxfunc):
copy_mol = Chem.Mol(mol)
for a in copy_mol.GetAtoms():
idx = idxfunc(a)
if idx == anchor: a.SetAtomMapNum(1)
else: a.SetAtomMapNum(0)
return get_smiles(copy_mol)
示例11: MolToFile
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def MolToFile(mol, fileName, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None,
fitImage=False, options=None, **kwargs):
""" Generates a drawing of a molecule and writes it to a file
"""
# original contribution from Uwe Hoffmann
if not fileName:
raise ValueError('no fileName provided')
if not mol:
raise ValueError('Null molecule provided')
if imageType is None:
imageType = os.path.splitext(fileName)[1][1:]
if options is None:
options = DrawingOptions()
useAGG, useCairo, Canvas = _getCanvas()
if fitImage:
options.dotsPerAngstrom = int(min(size) / 10)
options.wedgeDashedBonds = wedgeBonds
if useCairo or useAGG:
canvas = Canvas(size=size, imageType=imageType, fileName=fileName)
else:
options.radicalSymbol = '.' # <- the sping canvas doesn't support unicode well
canvas = Canvas(size=size, name=fileName, imageType=imageType)
drawer = MolDrawing(canvas=canvas, drawingOptions=options)
if kekulize:
from rdkit import Chem
mol = Chem.Mol(mol.ToBinary())
Chem.Kekulize(mol)
if not mol.GetNumConformers():
from rdkit.Chem import AllChem
AllChem.Compute2DCoords(mol)
drawer.AddMol(mol, **kwargs)
if useCairo or useAGG:
canvas.flush()
else:
canvas.save()
示例12: MolToMPL
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def MolToMPL(mol, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None, fitImage=False,
options=None, **kwargs):
""" Generates a drawing of a molecule on a matplotlib canvas
"""
if not mol:
raise ValueError('Null molecule provided')
from experiment.figure.Draw.mplCanvas import Canvas
canvas = Canvas(size)
if options is None:
options = DrawingOptions()
options.bgColor = None
if fitImage:
options.dotsPerAngstrom = int(min(size) / 10)
options.wedgeDashedBonds = wedgeBonds
drawer = MolDrawing(canvas=canvas, drawingOptions=options)
omol = mol
if kekulize:
from rdkit import Chem
mol = Chem.Mol(mol.ToBinary())
Chem.Kekulize(mol)
if not mol.GetNumConformers():
from rdkit.Chem import AllChem
AllChem.Compute2DCoords(mol)
drawer.AddMol(mol, **kwargs)
omol._atomPs = drawer.atomPs[mol]
for k, v in iteritems(omol._atomPs):
omol._atomPs[k] = canvas.rescalePt(v)
canvas._figure.set_size_inches(float(size[0]) / 100, float(size[1]) / 100)
return canvas._figure
示例13: __call__
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def __call__(self, mol):
"""
Generate conformers for a molecule.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
return self.generate_conformers(mol)
示例14: generate_conformers
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def generate_conformers(self, mol):
"""
Generate conformers for a molecule.
This function returns a copy of the original molecule with embedded
conformers.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
# initial embedding
mol = self.embed_molecule(mol)
if not mol.GetNumConformers():
msg = 'No conformers generated for molecule'
if mol.HasProp('_Name'):
name = mol.GetProp('_Name')
msg += ' "{}".'.format(name)
else:
msg += '.'
raise RuntimeError(msg)
# minimization and pruning
self.minimize_conformers(mol)
mol = self.prune_conformers(mol)
return mol
示例15: embed_molecule
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Mol [as 别名]
def embed_molecule(self, mol):
"""
Generate conformers, possibly with pruning.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
from rdkit import Chem
from rdkit.Chem import AllChem
mol = Chem.AddHs(mol) # add hydrogens
n_confs = self.max_conformers * self.pool_multiplier
AllChem.EmbedMultipleConfs(mol, numConfs=n_confs, pruneRmsThresh=-1.)
return mol