rdkit / rdkit

The official sources for the RDKit library
BSD 3-Clause "New" or "Revised" License
2.63k stars 874 forks source link

FindAtomEnvironmentOfRadiusN error for small molecules #6587

Open Arch4ngel21 opened 1 year ago

Arch4ngel21 commented 1 year ago

When using rdkit.Chem.rdmolops.FindAtomEnvironmentOfRadiusN with small molecules like LiF or LiCl, this function returns ValueError for atom index 0. Found it while reimplementing MAP4 fingerprint.

Code to reproduce:

from rdkit.Chem.rdmolops import FindAtomEnvironmentOfRadiusN
from rdkit.Chem import MolFromSmiles

radius = 2
mol = MolFromSmiles("[Li]F")

assert mol is not None

for atom in mol.GetAtoms():
    idx = atom.GetIdx()
    for r in range(1, radius + 1):
        env = FindAtomEnvironmentOfRadiusN(mol, idx, r)

Returns:

ValueError: bad atom index

Configuration:

j-adamczyk commented 7 months ago

Root cause: this error happens because there is no radius N for atoms in a molecule with diameter lower than N. This function returns an environment of radius exactly N, not up to N. This is not stated anywhere in the docs, which should be fixed.

greglandrum commented 6 months ago

This should definitely have a better error message

github-actions[bot] commented 9 hours ago

This issue was marked as stale because it has been open for 90 days with no activity.