当前位置: 首页>>代码示例>>Python>>正文


Python Draw.MolToFile方法代码示例

本文整理汇总了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 
开发者ID:deepchem,项目名称:deepchem,代码行数:10,代码来源:utils.py

示例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 
开发者ID:danielegrattarola,项目名称:spektral,代码行数:15,代码来源:chem.py

示例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) 
开发者ID:simonfqy,项目名称:PADME,代码行数:32,代码来源:preprocess.py

示例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) 
开发者ID:ATOMconsortium,项目名称:AMPL,代码行数:13,代码来源:struct_utils.py

示例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) 
开发者ID:microsoft,项目名称:constrained-graph-variational-autoencoder,代码行数:6,代码来源:utils.py

示例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) 
开发者ID:pfnet-research,项目名称:graph-nvp,代码行数:4,代码来源:utils.py

示例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 
开发者ID:hachmannlab,项目名称:chemml,代码行数:37,代码来源:molecule.py


注:本文中的rdkit.Chem.Draw.MolToFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。