當前位置: 首頁>>代碼示例>>Python>>正文


Python Chem.SmilesMolSupplier方法代碼示例

本文整理匯總了Python中rdkit.Chem.SmilesMolSupplier方法的典型用法代碼示例。如果您正苦於以下問題:Python Chem.SmilesMolSupplier方法的具體用法?Python Chem.SmilesMolSupplier怎麽用?Python Chem.SmilesMolSupplier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rdkit.Chem的用法示例。


在下文中一共展示了Chem.SmilesMolSupplier方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_smiles_file

# 需要導入模塊: from rdkit import Chem [as 別名]
# 或者: from rdkit.Chem import SmilesMolSupplier [as 別名]
def read_smiles_file(smiles_file, delimiter=' ', smiles_column=0,
                     name_column=1, header=False, requires_length=False):
    """Read a SMILES file.

    Parameters
    ----------
    smiles_file: path to a SMILES file
    requires_length: If True returns an enumerated Mol
        supplier, i.e. when monitoring progress

    Returns
    -------
    either a MolSupplier or an EnumeratedSupplier
    depending on whether a length is required
    """

    if requires_length is False:
        return MolSupplier(
            SmilesMolSupplier(
                smiles_file,
                delimiter,
                smiles_column,
                name_column,
                header,
                True))

    count = smiles_count(smiles_file)
    if header is True:
        count -= 1

    supplier = SmilesMolSupplier(smiles_file, delimiter, smiles_column, name_column, header, True)

    return EnumeratedMolSupplier(supplier, count) 
開發者ID:UCLCheminformatics,項目名稱:ScaffoldGraph,代碼行數:35,代碼來源:smiles.py

示例2: readfile

# 需要導入模塊: from rdkit import Chem [as 別名]
# 或者: from rdkit.Chem import SmilesMolSupplier [as 別名]
def readfile(format, filename, lazy=False, opt=None, **kwargs):
    """Iterate over the molecules in a file.

    Required parameters:
       format - see the informats variable for a list of available
                input formats
       filename

    You can access the first molecule in a file using the next() method
    of the iterator:
        mol = next(readfile("smi", "myfile.smi"))

    You can make a list of the molecules in a file using:
        mols = list(readfile("smi", "myfile.smi"))

    You can iterate over the molecules in a file as shown in the
    following code snippet:
    >>> atomtotal = 0
    >>> for mol in readfile("sdf", "head.sdf"):
    ...     atomtotal += len(mol.atoms)
    ...
    >>> print(atomtotal)
    43
    """
    if not os.path.isfile(filename):
        raise IOError("No such file: '%s'" % filename)
    format = format.lower()
    # Eagerly evaluate the supplier functions in order to report
    # errors in the format and errors in opening the file.
    # Then switch to an iterator...
    if format in ["sdf", "mol"]:
        return _filereader_sdf(filename, lazy=lazy)
    elif format == "pdb":
        return _filereader_pdb(filename, lazy=lazy)
    elif format == "pdbqt":
        return _filereader_pdbqt(filename, lazy=lazy)
    elif format == "mol2":
        return _filereader_mol2(filename, lazy=lazy)
    elif format == "smi":
        iterator = Chem.SmilesMolSupplier(filename, delimiter=" \t",
                                          titleLine=False, **kwargs)

        def smi_reader():
            for mol in iterator:
                yield Molecule(mol)
        return smi_reader()
    elif format == 'inchi' and Chem.INCHI_AVAILABLE:
        def inchi_reader():
            for line in open(filename):
                mol = Chem.inchi.MolFromInchi(line.strip(), **kwargs)
                yield Molecule(mol)
        return inchi_reader()
    else:
        raise ValueError("%s is not a recognised RDKit format" % format) 
開發者ID:oddt,項目名稱:oddt,代碼行數:56,代碼來源:rdk.py


注:本文中的rdkit.Chem.SmilesMolSupplier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。