RdKit Coordinates for atoms in a molecule

5.9k Views Asked by At

Hey everyone I need some help formatting coordinates for atoms in a molecule and I'm coding with Python. What I am needing is along the lines of:

(atom) x y z coordinates

For every atom in the molecule. So far my code is:

for molecule in mol_list:
    molecule = Chem.AddHs(molecule)
    print(molecule.GetNumAtoms())
    AllChem.EmbedMolecule(molecule)
    AllChem.UFFOptimizeMolecule(molecule)
    molecule.GetConformer()

    print()

    for atom in molecule.GetAtoms():
        # positions = molecule.GetConformer().GetAtomPosition(0)
        positions = molecule.GetConformer().GetPositions()
        print(atom.GetSymbol(), positions)
    
        print()

But this gives me the output of:

(Atom) x y z coordinates for every atom

This repeats so that every atom in the molecule has the entire molecule's x, y, and z coordinates. mol_list in the for loop is a list of strings that I converted to the object: rdkit.Chem.rdchem.Mol. I've tried the geometry.xyz function in Chemml, but ran into issues with the Molecule object. Also, I've tried using the RdKit function getAtomPos() with no luck. Any help with this would be awesome!

1

There are 1 best solutions below

1
On

You have to pass the atom number to get its coordinates. The following code snippet should do what you're looking for

for molecule in mol_list:
    molecule = Chem.AddHs(molecule)
    print(molecule.GetNumAtoms())
    AllChem.EmbedMolecule(molecule)
    AllChem.UFFOptimizeMolecule(molecule)
    molecule.GetConformer()
    print()

    for i, atom in enumerate(molecule.GetAtoms()):
        positions = molecule.GetConformer().GetAtomPosition(i)
        print(atom.GetSymbol(), positions.x, positions.y, positions.z)