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


Python Chem.SDWriter方法代码示例

本文整理汇总了Python中rdkit.Chem.SDWriter方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.SDWriter方法的具体用法?Python Chem.SDWriter怎么用?Python Chem.SDWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdkit.Chem的用法示例。


在下文中一共展示了Chem.SDWriter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rotate_molecule

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def rotate_molecule(path, target_path, count=10):
    # Load dataset
    mols = Chem.SDMolSupplier(path)
    rotated_mols = []

    print("Loaded {} Molecules from {}".format(len(mols), path))

    print("Rotating Molecules...")
    for mol in mols:
        for _ in range(count):
            for atom in mol.GetAtoms():
                atom_idx = atom.GetIdx()

                pos = list(mol.GetConformer().GetAtomPosition(atom_idx))
                pos_rotated = np.matmul(random_rotation_matrix(), pos)

                mol.GetConformer().SetAtomPosition(atom_idx, pos_rotated)

            rotated_mols.append(mol)

    w = Chem.SDWriter(target_path)
    for m in rotated_mols:
        if m is not None:
            w.write(m)
    print("Saved {} Molecules to {}".format(len(rotated_mols), target_path)) 
开发者ID:blackmints,项目名称:3DGCN,代码行数:27,代码来源:converter.py

示例2: __init__

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def __init__(self, args):

        self.args = args
        self.inputs = args.input

        if args.sdf:
            rdlogger.setLevel(4)
            self.output = SDWriter(args.output)
        else:
            self.output = open(args.output, 'w')

        self.mol_map = open(args.map_mols, 'w') if args.map_mols else None
        if self.mol_map:
            self.mol_map.write('MOLECULE_ID\tSCAFFOLD_ID\n')

        self.ann_map = open(args.map_annotations, 'w') if args.map_annotations else None
        if self.ann_map:
            self.ann_map.write('SCAFFOLD_ID\tANNOTATIONS\n')

        self.current_id = 0
        self.duplicates = 0
        self.table = {} 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:24,代码来源:operations.py

示例3: write_sdf_file

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def write_sdf_file(scaffold_graph, output_file):
    """Write an SDF file from a scaffoldgraph

    Parameters
    ----------
    scaffold_graph (sg.ScaffoldGraph): graph to be converted
    output_file (str): path to output file
    """

    N = scaffold_graph.num_scaffold_nodes
    sorted_scaffolds = sorted(scaffold_graph.get_scaffold_nodes(data=True), key=lambda x: x[1]['hierarchy'])
    mapping = dict(zip([s[0] for s in sorted_scaffolds], range(0, N)))
    writer = SDWriter(output_file)
    for scaffold, data in sorted_scaffolds:
        molecule = MolFromSmiles(scaffold)
        if molecule is not None:
            subscaffolds = list(scaffold_graph.predecessors(scaffold))
            molecule.SetProp('_Name', mapping[scaffold])
            molecule.SetIntProp('HIERARCHY', scaffold_graph.nodes[scaffold]['HIERARCHY'])
            molecule.SetProp('SMILES', scaffold)
            molecule.SetProp('SUBSCAFFOLDS', ', '.join([str(mapping[s]) for s in subscaffolds]))
            writer.write(molecule)
    writer.close() 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:25,代码来源:sdf.py

示例4: __init__

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def __init__(self, format, filename, overwrite=False):
        self.format = format
        self.filename = filename
        if not overwrite and os.path.isfile(self.filename):
            raise IOError("%s already exists. Use 'overwrite=True' to overwrite it." % self.filename)
        if format == "sdf":
            self._writer = Chem.SDWriter(self.filename)
        elif format == "smi":
            self._writer = Chem.SmilesWriter(self.filename, isomericSmiles=True, includeHeader=False)
        elif format in ('inchi', 'inchikey') and Chem.INCHI_AVAILABLE:
            self._writer = open(filename, 'w')
        elif format in ('mol2', 'pdbqt'):
            self._writer = gzip.open(filename, 'w') if filename.split('.')[-1] == 'gz' else open(filename, 'w')
        elif format == "pdb":
            self._writer = Chem.PDBWriter(self.filename)
        else:
            raise ValueError("%s is not a recognised RDKit format" % format)
        self.total = 0  # The total number of molecules written to the file 
开发者ID:oddt,项目名称:oddt,代码行数:20,代码来源:rdk.py

示例5: save_dataset

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def save_dataset(self, path, pred=None, target="test", filename=None):
        mols = []
        for idx, (x, c, y) in enumerate(zip(self.x[target], self.c[target], self.y[target])):
            x.SetProp("true", str(y * self.std + self.mean))
            if pred is not None:
                x.SetProp("pred", str(pred[idx][0] * self.std + self.mean))
            mols.append(x)

        if filename is not None:
            w = Chem.SDWriter(path + filename + ".sdf")
        else:
            w = Chem.SDWriter(path + target + ".sdf")
        for mol in mols:
            if mol is not None:
                w.write(mol) 
开发者ID:blackmints,项目名称:3DGCN,代码行数:17,代码来源:dataset.py

示例6: find_confusion

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def find_confusion(dataset, base_path):
    for i in range(1, 11):
        path = base_path + "trial_{}/".format(i)

        # Load true, pred value
        true_y, pred_y, diff_y = [], [], []

        mols = Chem.SDMolSupplier(path + "test.sdf")
        for mol in mols:
            diff_y.append(float(mol.GetProp("true")) - float(mol.GetProp("pred")))

        diff_y = np.array(diff_y, dtype=float)

        # Find largest, smallest error molecules
        idx = np.argsort(diff_y)
        top_1 = mols[int(idx[-1])]
        top_2 = mols[int(idx[-2])]
        btm_1 = mols[int(idx[0])]
        btm_2 = mols[int(idx[1])]

        best_idx = np.argsort(np.abs(diff_y))
        best = mols[int(best_idx[0])]

        # Save example molecules
        writer = Chem.SDWriter(path + "confusion_examples_" + dataset + "_trial" + str(i) + ".sdf")
        for mol in [top_1, top_2, btm_1, btm_2, best]:
            writer.write(mol) 
开发者ID:blackmints,项目名称:3DGCN,代码行数:29,代码来源:scatter_plot.py

示例7: mock_sdf

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def mock_sdf(tmp_path):
    d = tmp_path / "test_data"
    d.mkdir()
    p = d / "test.sdf"
    writer = Chem.SDWriter(str(p))
    writer.write(Chem.MolFromSmiles('CN1C(=O)CN=C(C2=C1C=CC(=C2)Cl)C3=CC=CC=C3'))
    writer.write(Chem.MolFromSmiles('CCC1=CC2=C(S1)N(C(=O)CN=C2C3=CC=CC=C3Cl)C'))
    writer.close()
    return str(p) 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:11,代码来源:__init__.py

示例8: mock_sdf_2

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def mock_sdf_2(tmp_path):
    d = tmp_path / "test_data"
    try:
        d.mkdir()
    except FileExistsError:
        pass
    p = d / "test_2.sdf"
    writer = Chem.SDWriter(str(p))
    writer.write(Chem.MolFromSmiles('C1C(=O)NC2=C(C=C(C=C2)Br)C(=N1)C3=CC=CC=N3'))
    writer.write(Chem.MolFromSmiles('CC1=NN(C2=C1C(=NCC(=O)N2C)C3=CC=CC=C3F)C'))
    writer.close()
    return str(p) 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:14,代码来源:__init__.py

示例9: sdf_file

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def sdf_file(tmpdir, mols):
    # Chem.AllChem.Compute2DCoords(mol1)
    fname = os.path.join(str(tmpdir), 'test.sdf')
    writer = Chem.SDWriter(fname)
    for mol in mols:
        writer.write(mol)
    return fname 
开发者ID:chainer,项目名称:chainer-chemistry,代码行数:9,代码来源:test_sdf_file_parser.py

示例10: sdf_file_long

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def sdf_file_long(tmpdir):
    """SDFFile with long smiles (ccc...)"""
    fname = os.path.join(str(tmpdir), 'test_long.sdf')
    writer = Chem.SDWriter(fname)
    for smiles in ['CCCCCCCCCCCC', 'CN=C=O', 'CCCCCCCCCCCCCCCC',
                   'Cc1ccccc1', 'CC1=CC2CC(CC1)O2']:
        mol = Chem.MolFromSmiles(smiles)
        writer.write(mol)
    return fname 
开发者ID:chainer,项目名称:chainer-chemistry,代码行数:11,代码来源:test_sdf_file_parser.py

示例11: converter

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def converter(path, target_path, name, target_name, process=20):
    # Load dataset
    print("Loading Dataset...")
    if ".csv" in path:
        x, y = load_csv(path, name, target_name)
        mols, props = [], []
        for smi, prop in zip(x, y):
            mol = Chem.MolFromSmiles(smi)
            if mol is not None:
                mols.append(mol)
                props.append(prop)
        mol_idx = list(range(len(mols)))

    elif ".sdf" in path:
        mols = Chem.SDMolSupplier(path)

        props = []
        for mol in mols:
            props.append(mol.GetProp(target_name))
        mol_idx = list(range(len(mols)))

    else:
        raise ValueError("Unsupported file type.")
    print("Loaded {} Molecules from {}".format(len(mols), path))

    # Optimize coordinate using multiprocessing
    print("Optimizing Conformers...")
    pool = mp.Pool(process)
    results = pool.starmap(optimize_conformer, zip(mol_idx, mols, props))

    # Collect results
    mol_list, prop_list = [], []
    for mol, prop in results:
        mol_list.append(mol)
        prop_list.append(prop)

    # Remove None and add properties
    mol_list_filtered = []
    for mol, prop in zip(mol_list, prop_list):
        if mol is not None:
            mol.SetProp("target", str(prop))
            mol_list_filtered.append(mol)
    print("{} Molecules Optimized".format(len(mol_list_filtered)))

    # Save molecules
    print("Saving File...")
    w = Chem.SDWriter(target_path)
    for m in mol_list_filtered:
        w.write(m)
    print("Saved {} Molecules to {}".format(len(mol_list_filtered), target_path)) 
开发者ID:blackmints,项目名称:3DGCN,代码行数:52,代码来源:converter.py

示例12: write_molecule

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import SDWriter [as 别名]
def write_molecule(mol, outfile, is_protein=False):
  """Write molecule to a file

  This function writes a representation of the provided molecule to
  the specified `outfile`. Doesn't return anything.

  Parameters
  ----------
  mol: rdkit Mol
    Molecule to write
  outfile: str
    Filename to write mol to
  is_protein: bool, optional
    Is this molecule a protein?

  Note
  ----
  This function requires RDKit to be installed.

  Raises
  ------
  ValueError: if `outfile` isn't of a supported format.
  """
  from rdkit import Chem
  if ".pdbqt" in outfile:
    writer = Chem.PDBWriter(outfile)
    writer.write(mol)
    writer.close()
    if is_protein:
      pdbqt_utils.convert_protein_to_pdbqt(mol, outfile)
    else:
      pdbqt_utils.convert_mol_to_pdbqt(mol, outfile)
  elif ".pdb" in outfile:
    writer = Chem.PDBWriter(outfile)
    writer.write(mol)
    writer.close()
  elif ".sdf" in outfile:
    writer = Chem.SDWriter(outfile)
    writer.write(mol)
    writer.close()
  else:
    raise ValueError("Unsupported Format") 
开发者ID:deepchem,项目名称:deepchem,代码行数:44,代码来源:rdkit_util.py


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