import py3Dmol
import copy
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import AllChem
from rdkit.Chem import rdBase
from rdkit.Chem import rdMolAlign
from rdkit.Chem import rdMolDescriptors
import numpy as np
print(rdBase.rdkitVersion)
2018.03.4
p = AllChem.ETKDGv2()
p.verbose = True
mols = [m for m in Chem.SDMolSupplier('cdk2.sdf') if m != None][:6]
for mol in mols:
mol.RemoveAllConformers()
hmols_1 = [Chem.AddHs(m) for m in mols]
hmols_2 = copy.deepcopy(hmols_1)
# Generate 100 conformers per each molecule
for mol in hmols_1:
# AllChem.EmbedMolecule(mol, p, )
AllChem.EmbedMultipleConfs(mol, 100, p)
for mol in hmols_2:
# AllChem.EmbedMolecule(mol, p, )
AllChem.EmbedMultipleConfs(mol, 100, p)
Draw.MolsToGridImage(mols)
crippen_contribs = [rdMolDescriptors._CalcCrippenContribs(mol) for mol in hmols_1]
crippen_ref_contrib = crippen_contribs[0]
crippen_prob_contribs = crippen_contribs[1:]
ref_mol1 = hmols_1[0]
prob_mols_1 = hmols_1[1:]
mmff_params = [AllChem.MMFFGetMoleculeProperties(mol) for mol in hmols_2]
mmff_ref_param = mmff_params[0]
mmff_prob_params = mmff_params[1:]
ref_mol2 = hmols_2[0]
prob_mols_2 = hmols_2[1:]
print(ref_mol1.GetNumConformers())
100
p_crippen = py3Dmol.view(width=600, height=400)
p_crippen.addModel(Chem.MolToMolBlock(ref_mol1), 'sdf')
crippen_score = []
for idx, mol in enumerate(prob_mols_1):
tempscore = []
for cid in range(100):
crippenO3A = rdMolAlign.GetCrippenO3A(mol, ref_mol1, crippen_prob_contribs[idx], crippen_ref_contrib, cid, 0)
crippenO3A.Align()
tempscore.append(crippenO3A.Score())
best = np.argmax(tempscore)
p_crippen.addModel(Chem.MolToMolBlock(mol, confId=int(best)), 'sdf')
crippen_score.append(tempscore[best])
p_crippen.setStyle({'stick':{}})
p_crippen.render()
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
<py3Dmol.view at 0x11dbd59e8>
print(crippen_score)
[103.29763690511137, 103.21589800584982, 103.29460070292699, 102.31579609125176, 92.70130850563217]
p_O3A = py3Dmol.view(width=600, height=400)
p_O3A.addModel(Chem.MolToMolBlock(ref_mol2), 'sdf')
pyO3A_score = []
for idx, mol in enumerate(prob_mols_2):
tempscore = []
for cid in range(100):
pyO3A = rdMolAlign.GetO3A(mol, ref_mol2, mmff_prob_params[idx], mmff_ref_param, cid, 0)
pyO3A.Align()
tempscore.append(pyO3A.Score())
best = np.argmax(tempscore)
p_O3A.addModel(Chem.MolToMolBlock(mol, confId=int(best)), 'sdf')
pyO3A_score.append(tempscore[best])
p_O3A.setStyle({'stick':{'colorscheme':'cyanCarbon'}})
p_O3A.render()
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
<py3Dmol.view at 0x11dbd5cc0>
print(pyO3A_score)
[148.0083215883, 147.8413237002005, 144.5908949595946, 145.01694989896706, 135.53700531243712]