本文整理匯總了Python中rdkit.Chem.AllChem.Compute2DCoords方法的典型用法代碼示例。如果您正苦於以下問題:Python AllChem.Compute2DCoords方法的具體用法?Python AllChem.Compute2DCoords怎麽用?Python AllChem.Compute2DCoords使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rdkit.Chem.AllChem
的用法示例。
在下文中一共展示了AllChem.Compute2DCoords方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MolToQPixmap
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [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: MolToFile
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [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()
示例3: MolToMPL
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [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
示例4: draw_structure
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [as 別名]
def draw_structure(smiles_str, image_path, image_size=500):
"""
Draw structure for the compound with the given SMILES string, in a PNG file
with the given path.
"""
mol = Chem.MolFromSmiles(smiles_str)
if mol is None:
print(("Unable to read original SMILES for %s" % cmpd_num))
else:
_discard = AllChem.Compute2DCoords(mol)
Draw.MolToFile(mol, image_path, size=(image_size,image_size), fitImage=False)
示例5: visualize_mol
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [as 別名]
def visualize_mol(path, new_mol):
AllChem.Compute2DCoords(new_mol)
print(path)
Draw.MolToFile(new_mol,path)
示例6: mols2grid_image
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [as 別名]
def mols2grid_image(mols, molsPerRow):
mols = [e if e is not None else Chem.RWMol() for e in mols]
for mol in mols:
AllChem.Compute2DCoords(mol)
return Draw.MolsToGridImage(mols, molsPerRow=molsPerRow, subImgSize=(150, 150))
示例7: make2D
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [as 別名]
def make2D(self):
"""Generate 2D coordinates for molecule"""
AllChem.Compute2DCoords(self.Mol)
self._clear_cache()
示例8: load_data_from_smiles
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import Compute2DCoords [as 別名]
def load_data_from_smiles(x_smiles, labels, add_dummy_node=True, one_hot_formal_charge=False):
"""Load and featurize data from lists of SMILES strings and labels.
Args:
x_smiles (list[str]): A list of SMILES strings.
labels (list[float]): A list of the corresponding labels.
add_dummy_node (bool): If True, a dummy node will be added to the molecular graph. Defaults to True.
one_hot_formal_charge (bool): If True, formal charges on atoms are one-hot encoded. Defaults to False.
Returns:
A tuple (X, y) in which X is a list of graph descriptors (node features, adjacency matrices, distance matrices),
and y is a list of the corresponding labels.
"""
x_all, y_all = [], []
for smiles, label in zip(x_smiles, labels):
try:
mol = MolFromSmiles(smiles)
try:
mol = Chem.AddHs(mol)
AllChem.EmbedMolecule(mol, maxAttempts=5000)
AllChem.UFFOptimizeMolecule(mol)
mol = Chem.RemoveHs(mol)
except:
AllChem.Compute2DCoords(mol)
afm, adj, dist = featurize_mol(mol, add_dummy_node, one_hot_formal_charge)
x_all.append([afm, adj, dist])
y_all.append([label])
except ValueError as e:
logging.warning('the SMILES ({}) can not be converted to a graph.\nREASON: {}'.format(smiles, e))
return x_all, y_all