本文整理汇总了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)
示例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)