【发布时间】: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