【问题标题】:TypeError: 'NoneType' object is not an iterator Rdkit VS codeTypeError:“NoneType”对象不是迭代器 Rdkit VS 代码
【发布时间】:2021-02-23 01:55:28
【问题描述】:

我正在尝试通过 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)

【问题讨论】:

    标签: visual-studio-code jupyter-notebook rdkit


    【解决方案1】:

    我假设您使用的是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...
    

    【讨论】:

    • 谢谢,帮了大忙!
    • 没问题。如果解决了您的问题,请将其标记为已接受的答案,谢谢。
    猜你喜欢
    • 2012-08-25
    • 1970-01-01
    • 2017-08-29
    • 2016-08-30
    • 2014-11-21
    • 1970-01-01
    相关资源
    最近更新 更多