5
$\begingroup$

I am processing some XYZ files using the rdkit library in python. I came across some strange/unexpected behaviour.

Consider a sample XYZ file of methanol with coordinates in Angstroms:

6
Methanol
  H      1.2001      0.0363      0.8431
  H      0.9877      0.8943     -0.7114
  H      1.0155     -0.8918     -0.6742
  C      0.7031      0.0083     -0.1305
  O     -0.6582     -0.0067      0.1730
  H     -1.1326     -0.0311     -0.6482

I am using the following code to visualise this compound. I am running the below code on Google Colab.

!pip install rdkit
from rdkit.Chem.rdmolfiles import  MolFromXYZFile

coord_filepath = '/content/drive/MyDrive/input_files/methanol.xyz'
mol = MolFromXYZFile(coord_filepath)
display(mol)

The output from the display looks like this:

enter image description here

I am a bit puzzled about the extra Hydrogens in the image. I tried to double check the atoms in the rdkit mol

for atom in mol.GetAtoms():
  print(atom.GetSymbol())

It displays as expected:

H
H
H
C
O
H

With coordinates in nanometers, the behaviour persists, with a bit better spacing between the various atoms/molecules.

enter image description here

So is this behaviour a bug or am I missing something conceptually?

$\endgroup$
4
  • 1
    $\begingroup$ I have never heard of the MolFromXYZFile function in RDKit before, if I remember correctly, rdkit wasn't able to read xyz files. So this is probably a newly implemented feature in rdkit, and maybe buggy because of that. $\endgroup$
    – S R Maiti
    Mar 11 at 10:09
  • $\begingroup$ rdkit.org/docs/source/… You can find the documentation for the function here. $\endgroup$ Mar 11 at 10:17
  • 1
    $\begingroup$ It looks RDKit thinks it read in isolated atoms and "auto-hydrogenated" them into one water, one methane and four hydrogen molecules. Maybe it was expecting nm (your coordinates look like angstroms) and thus could not auto-detect bonds between the atomic positions. $\endgroup$ Mar 12 at 9:01
  • $\begingroup$ @ShernRenTee The behaviour persists even when I use nanometers. I have updated the question with details. Please have a look. $\endgroup$ Mar 12 at 10:36

1 Answer 1

5
$\begingroup$

Here is a demo how to work with MolFromXYZ.

You can choose rdDetermineBonds.DetermineConnectivity for bonds or rdDetermineBonds.DetermineBondsfor bonds and bond orders.

from rdkit import Chem
from rdkit.Chem import rdDetermineBonds

xyz = '''6
Methanol
  H      1.2001      0.0363      0.8431
  H      0.9877      0.8943     -0.7114
  H      1.0155     -0.8918     -0.6742
  C      0.7031      0.0083     -0.1305
  O     -0.6582     -0.0067      0.1730
  H     -1.1326     -0.0311     -0.6482'''

mol = Chem.MolFromXYZBlock(xyz)

conn_mol = Chem.Mol(mol)
rdDetermineBonds.DetermineConnectivity(conn_mol)
conn_mol

mol

$\endgroup$

You must log in to answer this question.

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