#!/usr/bin/env python # coding: utf-8 # In[1]: from rdkit import Chem from rdkit.Chem import AllChem from rdkit.Chem import rdFMCS from rdkit.Chem.Draw import IPythonConsole # In[2]: mol1 = Chem.MolFromSmiles('CCc1ccccc1') mol2 = Chem.MolFromSmiles('CCc1nnccc1') # In[3]: AllChem.EmbedMolecule(mol1) # In[4]: IPythonConsole.drawMol3D(mol1, size=(200,200)) # In[5]: mcs = rdFMCS.FindMCS([mol1, mol2]) mcs_mol = Chem.MolFromSmarts(mcs.smartsString) # In[6]: ref_match = mol1.GetSubstructMatch(mcs_mol) target_match = mol2.GetSubstructMatch(mcs_mol) # In[7]: print(ref_match, target_match) # In[8]: rwmol = Chem.RWMol(mcs_mol) # In[9]: rwconf = Chem.Conformer(rwmol.GetNumAtoms()) matches = rwmol.GetSubstructMatch(mcs_mol) # In[10]: ref_conf = mol1.GetConformer() for i, match in enumerate(matches): print(ref_conf.GetAtomPosition(ref_match[i]).x) rwconf.SetAtomPosition(match, ref_conf.GetAtomPosition(ref_match[i])) # In[18]: for i in matches: pos=rwconf.GetAtomPosition(i) print(pos.x, pos.y, pos.z) # In[12]: rwmol.AddConformer(rwconf) # In[13]: IPythonConsole.drawMol3D(rwmol) # In[14]: AllChem.ConstrainedEmbed(mol2, rwmol) # In[15]: IPythonConsole.drawMol3D(mol2) # In[ ]: print(Chem.MolToMolBlock(mol1)) print(Chem.MolToMolBlock(mol1))