【问题标题】:How to export my results from visual studio code to file on my computer如何将我的结果从 Visual Studio 代码导出到我的计算机上的文件
【发布时间】:2021-02-25 17:29:06
【问题描述】:

过滤 sdf 数据库后,我得到了只打印在屏幕上的结果。

如何将结果导出到计算机上的单独 sdf 文件中?

下面是我的过滤代码。

我想我需要使用 SDWriter Rdkit 模块,但在互联网上找不到特定代码来实现我的过滤分子的脚本。

感谢任何帮助!

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】:

    目前尚不清楚您要达到的具体目标。如果您只想将通过所有三个过滤器的分子保存到新的 SDF,那么这很容易。您应该能够将代码改编为其他用途。

    rdkit documentation 也有 SDWriter 的代码示例

    molecules = Chem.SDMolSupplier('path/to/mols.sdf')
    results_sdf = Chem.SDWriter('results.sdf')
    
    for mol in molecules:
        
        # Calculate descriptors here
        # Get the boolean result of each filter
        
        if lipinski and ghose_filter and rule_of_3:
            results_sdf.write(mol)
    
    results_sdf.close()
    

    您也可以将每个过滤器的结果作为属性存储在结果 SDF 中。为此,您只需向分子添加一个属性。这将自动写入 SDF。

    molecules = Chem.SDMolSupplier('path/to/mols.sdf')
    results_sdf = Chem.SDWriter('results.sdf')
    
    for mol in molecules:
        
        # Calculate descriptors here
        # Get the boolean result of each filter
        
        mol.SetBoolProp('lipinski', lipinksi)
        mol.SetBoolProp('ghose', ghose_gilter)
        mol.SetBoolProp('ro3', rule_of_3)
    
        results_sdf.write(mol)
    
    results_sdf.close()
    

    这是一个假的输出示例来说明这一点:

         RDKit          2D
    
      6  6  0  0  0  0  0  0  0  0999 V2000
        1.5000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.7500   -1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
       -0.7500   -1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
       -1.5000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
       -0.7500    1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.7500    1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
      1  2  2  0
      2  3  1  0
      3  4  2  0
      4  5  1  0
      5  6  2  0
      6  1  1  0
    M  END
    >  <lipinski>  (1) 
    1
    
    >  <ghose>  (1) 
    1
    
    >  <ro3>  (1) 
    0
    
    $$$$
    

    【讨论】:

      猜你喜欢
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多