TypeError: 'NoneType' object is not an iterator Rdkit VS code
TypeError: 'NoneType' object is not an iterator Rdkit VS code
我正在尝试通过 Lipinski、Ghose 和 RUle of 3 过滤器从数据库 'part1' 中过滤分子,但我不断收到错误。
因此,在我 运行 这个脚本之后,我在 'progressbar' 被提及两次的那一行得到一个错误 'object is not an iterator' 。我是新手,希望得到帮助。
下面是我过滤分子数据库的脚本。
from rdkit import Chem
from rdkit.Chem import Descriptors
import progressbar
if __name__ == '__main__':
molecules = Chem.SDMolSupplier('chemspidersdf/part1.sdf')
results = {
"Lipinski Rule of 5": 0,
"Ghose Filter": 0,
"Rule of 3 Filter": 0,
}
print ("Molecule Database Length: " + str(len(molecules)))
for i in progressbar.ProgressBar(range(len(molecules))):
molecule = molecules[i]
if molecule:
lipinski = False
rule_of_3 = False
ghose_filter = False
molecular_weight = Descriptors.ExactMolWt(molecule)
logp = Descriptors.MolLogP(molecule)
h_bond_donor = Descriptors.NumHDonors(molecule)
h_bond_acceptors = Descriptors.NumHAcceptors(molecule)
rotatable_bonds = Descriptors.NumRotatableBonds(molecule)
number_of_atoms = Chem.rdchem.Mol.GetNumAtoms(molecule)
molar_refractivity = Chem.Crippen.MolMR(molecule)
# Lipinski
if molecular_weight <= 500 and logp <= 5 and h_bond_donor <= 5 and h_bond_acceptors <= 5 and rotatable_bonds <= 5:
lipinski = True
results["Lipinski Rule of 5"] += 1
# Ghose Filter
if molecular_weight >= 160 and molecular_weight <= 480 and logp >= 0.4 and logp <= 5.6 and number_of_atoms >= 20 and number_of_atoms <= 70 and molar_refractivity >= 40 and molar_refractivity <= 130:
ghose_filter = True
results["Ghose Filter"] += 1
# Rule of 3
if molecular_weight <= 300 and logp <= 3 and h_bond_donor <= 3 and h_bond_acceptors <= 3 and rotatable_bonds <= 3:
rule_of_3 = True
results["Rule of 3 Filter"] += 1
print (results)
我假设您正在使用 progressbar2。看起来 progressbar
应该是小写的:
mols = Chem.SDMolSupplier('path/to/my/mols.sdf')
n_mols = len(mols)
for x in progressbar.progressbar(range(n_mols)):
# do stuff...
它也可以这样工作:
mols = Chem.SDMolSupplier('path/to/my/mols.sdf')
for mol in progressbar.progressbar(mols):
if mol is None:
continue
# do stuff...
我正在尝试通过 Lipinski、Ghose 和 RUle of 3 过滤器从数据库 'part1' 中过滤分子,但我不断收到错误。 因此,在我 运行 这个脚本之后,我在 'progressbar' 被提及两次的那一行得到一个错误 'object is not an iterator' 。我是新手,希望得到帮助。
下面是我过滤分子数据库的脚本。
from rdkit import Chem
from rdkit.Chem import Descriptors
import progressbar
if __name__ == '__main__':
molecules = Chem.SDMolSupplier('chemspidersdf/part1.sdf')
results = {
"Lipinski Rule of 5": 0,
"Ghose Filter": 0,
"Rule of 3 Filter": 0,
}
print ("Molecule Database Length: " + str(len(molecules)))
for i in progressbar.ProgressBar(range(len(molecules))):
molecule = molecules[i]
if molecule:
lipinski = False
rule_of_3 = False
ghose_filter = False
molecular_weight = Descriptors.ExactMolWt(molecule)
logp = Descriptors.MolLogP(molecule)
h_bond_donor = Descriptors.NumHDonors(molecule)
h_bond_acceptors = Descriptors.NumHAcceptors(molecule)
rotatable_bonds = Descriptors.NumRotatableBonds(molecule)
number_of_atoms = Chem.rdchem.Mol.GetNumAtoms(molecule)
molar_refractivity = Chem.Crippen.MolMR(molecule)
# Lipinski
if molecular_weight <= 500 and logp <= 5 and h_bond_donor <= 5 and h_bond_acceptors <= 5 and rotatable_bonds <= 5:
lipinski = True
results["Lipinski Rule of 5"] += 1
# Ghose Filter
if molecular_weight >= 160 and molecular_weight <= 480 and logp >= 0.4 and logp <= 5.6 and number_of_atoms >= 20 and number_of_atoms <= 70 and molar_refractivity >= 40 and molar_refractivity <= 130:
ghose_filter = True
results["Ghose Filter"] += 1
# Rule of 3
if molecular_weight <= 300 and logp <= 3 and h_bond_donor <= 3 and h_bond_acceptors <= 3 and rotatable_bonds <= 3:
rule_of_3 = True
results["Rule of 3 Filter"] += 1
print (results)
我假设您正在使用 progressbar2。看起来 progressbar
应该是小写的:
mols = Chem.SDMolSupplier('path/to/my/mols.sdf')
n_mols = len(mols)
for x in progressbar.progressbar(range(n_mols)):
# do stuff...
它也可以这样工作:
mols = Chem.SDMolSupplier('path/to/my/mols.sdf')
for mol in progressbar.progressbar(mols):
if mol is None:
continue
# do stuff...