[Rdkit-discuss] distance matrix for non-bonded atoms
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=84349351iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] distance matrix for non-bonded atoms
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('C') 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 distminimum: minimum=dist print(minimum) On 3 December 2013 16:17, Nicholas Firth nicholas.fi...@icr.ac.uk 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('C') 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 nicholas.fi...@icr.ac.uk | 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 michal.kromp...@gmail.com 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=84349351iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net 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. -- 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=84349351iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] distance matrix for non-bonded atoms
hmm, I think this way is probably faster. And, once you grok the numpy bits, it's arguably simpler: from rdkit import Chem from rdkit.Chem import AllChem mol = Chem.MolFromSmiles('C') AllChem.EmbedMolecule(mol) AllChem.UFFOptimizeMolecule(mol) dm=numpy.multiply(Chem.Get3DDistanceMatrix(mol),numpy.logical_not(Chem.GetAdjacencyMatrix(mol))) dm[dm==0.0]=1000.0 minDist = numpy.min(dm) # get the closest atoms: mv=numpy.argmin(dm) a1,a2 = mv // dm.shape[0],mv%dm.shape[0] -greg On Tue, Dec 3, 2013 at 6:00 PM, Michal Krompiec michal.kromp...@gmail.comwrote: 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('C') 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 distminimum: minimum=dist print(minimum) On 3 December 2013 16:17, Nicholas Firth nicholas.fi...@icr.ac.uk 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('C') 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 nicholas.fi...@icr.ac.uk | 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 michal.kromp...@gmail.com 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=84349351iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net 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. -- 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=84349351iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss -- 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
Re: [Rdkit-discuss] distance matrix for non-bonded atoms
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('C') 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 distminimum: minimum=dist print(minimum) On 3 December 2013 17:00, Michal Krompiec michal.kromp...@gmail.com 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('C') 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 distminimum: minimum=dist print(minimum) On 3 December 2013 16:17, Nicholas Firth nicholas.fi...@icr.ac.uk 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('C') 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 nicholas.fi...@icr.ac.uk | 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 michal.kromp...@gmail.com 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=84349351iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net 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=111408631iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] distance matrix for non-bonded atoms
Sorry for spamming the list. This is the correct version: from rdkit import Chem from rdkit.Chem import AllChem mol = Chem.MolFromSmiles('') mol=Chem.AddHs(mol) AllChem.EmbedMolecule(mol) AllChem.UFFOptimizeMolecule(mol) conf = mol.GetConformer() natom=mol.GetNumAtoms() conf=mol.GetConformer() 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 distminimum: minimum=dist print(minimum) Best wishes, Michal -- 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=111408631iu=/4140/ostg.clktrk ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss