本文整理汇总了Python中rdkit.Chem.Draw.MolToFile方法的典型用法代码示例。如果您正苦于以下问题:Python Draw.MolToFile方法的具体用法?Python Draw.MolToFile怎么用?Python Draw.MolToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem.Draw
的用法示例。
在下文中一共展示了Draw.MolToFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mols_to_pngs
# 需要导入模块: from rdkit.Chem import Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [as 别名]
def mols_to_pngs(mols, basename="test"):
"""Helper to write RDKit mols to png files."""
filenames = []
for i, mol in enumerate(mols):
filename = "%s%d.png" % (basename, i)
Draw.MolToFile(mol, filename)
filenames.append(filename)
return filenames
示例2: plot_rdkit
# 需要导入模块: from rdkit.Chem import Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [as 别名]
def plot_rdkit(mol, filename=None):
"""
Plots an RDKit molecule in Matplotlib
:param mol: an RDKit molecule
:param filename: save the image with the given filename
:return: the image as np.array
"""
if rdc is None:
raise ImportError('`draw_rdkit_mol` requires RDkit.')
if filename is not None:
Draw.MolToFile(mol, filename)
img = Draw.MolToImage(mol)
return img
示例3: filter_similarity
# 需要导入模块: from rdkit.Chem import Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [as 别名]
def filter_similarity(input_file, output_file, image_folder='./mol_images', threshold=0.85,
draw_2d_image=True, limit=False, limit_lines=120):
# Both input_file and output_file should be csv files.
df_sim = pd.read_csv(input_file, header=0, index_col=False)
smiles_array = df_sim['smiles']
scores_array = df_sim['avg_score']
similarity_array = df_sim['max_similarity']
selected_indices_list = []
for i, sim in enumerate(similarity_array):
if sim >= threshold:
continue
selected_indices_list.append(i)
if draw_2d_image:
source_line_num = i + 2
target_line_num = len(selected_indices_list) + 1
mol = Chem.MolFromSmiles(smiles_array[i])
Draw.MolToFile(mol,
image_folder + '/' + str(source_line_num) + '_' + str(target_line_num) + '.png',
size=(700,700))
with open(output_file, 'w', newline='') as csvfile:
fieldnames = ['smiles', 'avg_score', 'max_similarity']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for i, ind in enumerate(selected_indices_list):
if limit and i + 1 > limit_lines:
break
out_line = {'smiles': smiles_array[ind], 'avg_score': scores_array[ind],
'max_similarity': similarity_array[ind]}
writer.writerow(out_line)
示例4: draw_structure
# 需要导入模块: from rdkit.Chem import Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [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 Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [as 别名]
def visualize_mol(path, new_mol):
AllChem.Compute2DCoords(new_mol)
print(path)
Draw.MolToFile(new_mol,path)
示例6: save_mol_png
# 需要导入模块: from rdkit.Chem import Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [as 别名]
def save_mol_png(mol, filepath, size=(600, 600)):
Draw.MolToFile(mol, filepath, size=size)
示例7: visualize
# 需要导入模块: from rdkit.Chem import Draw [as 别名]
# 或者: from rdkit.Chem.Draw import MolToFile [as 别名]
def visualize(self, filename=None, **kwargs):
"""
This function visualizes the molecule. If both rdkit and pybel objects are avaialble, the rdkit object
will be used for visualization.
Parameters
----------
filename: str, optional (default = None)
This is the path to the file that you want write the image in it.
Tkinter and Python Imaging Library are required for writing the image.
kwargs:
any extra parameter that you want to pass to the rdkit or pybel draw tool.
Additional information at:
- https://www.rdkit.org/docs/source/rdkit.Chem.Draw.html
- http://openbabel.org/docs/dev/UseTheLibrary/Python_PybelAPI.html#pybel.Molecule.draw
Returns
-------
object
You will be able to display this object, e.g., inside the Jupyter Notebook.
"""
engine = self._check_original_molecule()
if engine == 'rdkit':
from rdkit.Chem import Draw
if filename is not None:
Draw.MolToFile(self.rdkit_molecule, filename, **kwargs)
else:
return Draw.MolToImage(self.rdkit_molecule, **kwargs)
elif engine == 'pybel':
if filename is not None:
self.pybel_molecule.draw(show=False, filename=filename, **kwargs)
else:
return self.pybel_molecule # it seems that the object alone is displayable