4
$\begingroup$

I have written this code using RdKit to find topographic distance

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import rdDistGeom as molDG
dm=AllChem.Get3DDistanceMatrix('example.mol')
print(dm)

I'm not quite sure if the general form of the code is correct, but it also leads to an error message I don't know how to fix.

AllChem.Get3DDistanceMatrix('example.mol')
ArgumentError: Python argument types in
    rdkit.Chem.rdmolops.Get3DDistanceMatrix(str)
did not match C++ signature:
    Get3DDistanceMatrix(class RDKit::ROMol {lvalue} mol, int confId=-1, bool useAtomWts=False, bool force=False, char const * __ptr64 prefix='')

I would like some help either correcting this error or just getting an example of computing topographic distance with rdkit.

$\endgroup$

1 Answer 1

5
$\begingroup$

First off, it's important to know that some (most?) mol files do not include 3D coordinates. So you'd need to generate them (e.g., from rdDistGeom or ETKDG).

Your problem is that you're supplying a filename string to a method that requires a molecule object.

Let's assume your example.mol file has 3D coordinates already.

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import rdDistGeom as molDG
 
mol = Chem.MolFromMolFile('example.mol')
# either of these should work
bm = molDG.GetMoleculeBoundsMatrix(mol)
# .. or what you asked
dm = AllChem.Get3DDistanceMatrix(mol)

If (more likely) you need to generate 3D coordinates, you'll want something like this:

mol = Chem.MolFromMolFile('example.mol')
# always add hydrogens before generating 3D coordinates
m2 = Chem.AddHs(mol)
AllChem.EmbedMolecule(m2)
# if you don't want to consider the hydrogens you can remove them
# before calculating the distance matrix
dm = AllChem.Get3DDistanceMatrix(mol)
$\endgroup$
4
  • $\begingroup$ Can the above code rewritten to use for SDF files or XYZ files. As it will have the 3D coordinates I feel sir. $\endgroup$
    – sriram
    Jan 1, 2023 at 3:07
  • $\begingroup$ A SDF and Mol are essentially the same. They do not necessarily have 3D coordinates. If you know your particular files have 3D coordinates, great. But most don't. At the moment, I do not believe XYZ is natively supported by RDKit, although the next release should. $\endgroup$ Jan 1, 2023 at 3:25
  • $\begingroup$ Kindly advice me on which type of file is useful for 3D for now $\endgroup$
    – sriram
    Jan 1, 2023 at 15:04
  • $\begingroup$ @sriram - that seems like another question, rather than something to discuss in the comments, thanks. $\endgroup$ Jan 1, 2023 at 19:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .