Dear all,
bugfixed version of my solution: (the previous one listed the shortest bond)
from rdkit import Chem
from rdkit.Chem import AllChem
mol = Chem.MolFromSmiles('CCCCC')
AllChem.EmbedMolecule(mol)
AllChem.UFFOptimizeMolecule(mol)
conf = mol.GetConformer()
natom=mol.GetNumAtoms()
minimum=1e100
for i in range(0, natom-1):
for j in range(i+1,natom):if mol.GetBondBetweenAtoms(i,j)==None: dist=rdMolTransforms.GetBondLength(conf,i,j) if dist<minimum: minimum=dist print(minimum) On 3 December 2013 17:00, Michal Krompiec <[email protected]> wrote: > Dear Nick, > Thanks. I need it for the whole molecule. But indeed it seems to be > faster this way - loop over pairs of atoms: > > from rdkit import Chem > from rdkit.Chem import AllChem > mol = Chem.MolFromSmiles('CCCCC') > AllChem.EmbedMolecule(mol) > AllChem.UFFOptimizeMolecule(mol) > conf=mol.GetConformer() > natom=mol.GetNumAtoms() > minimum=1e100 > for i in range(0, natom): > for j in range(i+1,natom): > if mol.GetBondBetweenAtoms(i,j)!=None: > dist=rdMolTransforms.GetBondLength(conf,i,j) > if dist<minimum: > minimum=dist > print(minimum) > > > > > > > > On 3 December 2013 16:17, Nicholas Firth <[email protected]> wrote: >> >> I'm not sure whether you want to get these distances for the entire molecule >> or just certain atom pairs. But I guess the simplest way to get the distance >> between two atoms would be… >> >> >>> from rdkit import Chem >> >>> import numpy as np >> >>> from rdkit.Chem import AllChem >> >>> mol = Chem.MolFromSmiles('CCCCC') >> >>> AllChem.EmbedMolecule(mol) >> >>> AllChem.UFFOptimizeMolecule(mol) >> >>> conf = mol.GetConformer() >> >>> at1Coords = np.array(conf.GetAtomPosition(1)) >> >>> at2Coords = np.array(conf.GetAtomPosition(2)) >> >>> print np.linalg.norm(at1Coords-at2Coords) >> 1.52139356317 >> >> This can be optimised by not using numpy, I've not looked but there must be >> some sort of euclidean distance using the Point3D class in RDKit. >> >> Best, >> Nick >> >> Nicholas C. Firth | PhD Student | Cancer Therapeutics >> The Institute of Cancer Research | 15 Cotswold Road | Belmont | Sutton | >> Surrey | SM2 5NG >> >> T 020 8722 4033 | E [email protected] | W www.icr.ac.uk | Twitter >> @ICRnews >> >> Facebook www.facebook.com/theinstituteofcancerresearch >> >> Making the discoveries that defeat cancer >> >> >> >> On 3 Dec 2013, at 15:56, Michal Krompiec <[email protected]> wrote: >> >> Hello, >> Is there any simpler (=faster) way of calculating the shortest >> distance between non-bonded atoms in a molecule? >> >> from rdkit import Chem >> from rdkit.Chem import AllChem >> from rdkit.Chem import rdMolTransforms >> import numpy >> mol=Chem.MolFromSmiles("Cc2ccsc2c1sccc1C") >> mol=Chem.AddHs(mol) >> AllChem.EmbedMolecule(mol) >> AllChem.MMFFOptimizeMolecule(mol) >> dm=numpy.multiply(Chem.Get3DDistanceMatrix(mol),numpy.logical_not(Chem.GetAdjacencyMatrix(mol))) >> print("minimum non-bonded atom-atom distance: >> {}".format(numpy.min(dm[numpy.nonzero(dm)]))) >> >> Best wishes, >> >> Michal >> >> ------------------------------------------------------------------------------ >> Rapidly troubleshoot problems before they affect your business. Most IT >> organizations don't have a clear picture of how application performance >> affects their revenue. With AppDynamics, you get 100% visibility into your >> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics >> Pro! >> http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk >> _______________________________________________ >> Rdkit-discuss mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >> >> >> The Institute of Cancer Research: Royal Cancer Hospital, a charitable >> Company Limited by Guarantee, Registered in England under Company No. 534147 >> with its Registered Office at 123 Old Brompton Road, London SW7 3RP. >> >> This e-mail message is confidential and for use by the addressee only. If >> the message is received by anyone other than the addressee, please return >> the message to the sender by replying to it and then delete the message from >> your computer and network. ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Rdkit-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

