moleculekit.tools.atomnames module#

moleculekit.tools.atomnames.canonicalizeAtomNames(mol, sel='all', _logger=True)#

Give atoms unique <Element><index> names (C1, C2, N1, …) within each residue.

Only residues whose atom names are not already unique (or contain an empty name) are renamed; residues that already have unique names are left untouched. Canonical protein/nucleic residues therefore pass through unchanged, since their atom names (N, CA, CB, …) are already unique and are force-field-meaningful, which makes this safe to run on a whole system. The naming counter restarts per residue, so identical residues (e.g. multiple copies of the same ligand) receive the same names.

This is typically needed after loading a molecule whose atoms are named only by element symbol (as an SDF produces), where every carbon is called C, every nitrogen N and so on, since non-unique names break topology generation.

Parameters:
  • mol (Molecule) – The molecule whose atom names to canonicalize. Not modified in place.

  • sel (str | ndarray) – An atom selection string, a boolean mask, or an integer index array (see Molecule.atomselect). Only residues with at least one selected atom are considered; the rest are left untouched. Default is “all”.

Returns:

newmol – A copy of the input molecule with canonicalized atom names.

Return type:

Molecule

Examples

>>> mol = Molecule("ligand.sdf")
>>> mol = canonicalizeAtomNames(mol)