4
$\begingroup$

I'm trying to find the Euclidean distance between two atoms in the molecule with SMILES representation O=CC1OC12CC1OC12 using the rdkit package. Looking online, I have converged to the following code.

import numpy as np
from rdkit import Chem

mol = Chem.MolFromSmiles('O=CC1OC12CC1OC12')

conf = mol.GetConformer()
at1Coords = np.array(conf.GetAtomPosition(bond_i.GetBeginAtomIdx()))
at2Coords = np.array(conf.GetAtomPosition(bond_i.GetEndAtomIdx()))
print(np.linalg.norm(at2Coords - at1Coords))

But I get the error

conf = mol.GetConformer()  
ValueError: Bad Conformer Id

I was wondering how to fix the issue. Thanks!

$\endgroup$
0

1 Answer 1

2
$\begingroup$

The issue was that I had to embed the molecule to have a 3D conformation. So I added following line:

AllChem.EmbedMolecule(mol)

Feel free to answer with better suggestions and alternatives.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.