简体   繁体   中英

RdKit Coordinates for atoms in a molecule

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM