polymerist.rdutils.chemlabel

For reading, writing, and clearing labels from RDKit Atoms, Bonds, and Mols

Functions

has_fully_mapped_atoms(→ bool)

Check whether an RDKit Mol has a map number explicitly assigned to each member Atom

has_uniquely_mapped_atoms(→ bool)

Check whether an RDKit Mol has distinct atom map numbers for each member Atom

map_numbers_by_atom_idxs(→ Generator[Optional[int], ...)

Get assigned atom map numbers for a collection of atom ids, in the same order as the internal RDKit Mol atom IDs

atom_idxs_by_map_numbers(→ Generator[Optional[int], ...)

Returns the first occurences of the atom IDs of any number of atoms, indexed by atom map number

get_bond_by_map_num_pair(→ Optional[Union[int, ...)

Get the bond spanning a pair of atoms with given pair of atom map numbers

assign_atom_map_nums_by_ids(→ None)

Assigns atom map numbers to Atoms in a Mol as identified by a mapping of atom indices to map numbers

assign_ordered_atom_map_nums(→ None)

Assigns atom's index as its atom map number for all atoms in an RDmol

relabel_map_nums(→ None)

Applies a relabelling of atom map numbers to a subset of mapped atoms (described by a dict of old_map_num : new_map_num)

mol_to_smiles_and_atom_permutation(→ tuple[str, list[int]])

Convert RDKit Mol to SMILES string (with any SMILES writer parameters passed to as args/kwargs)

assign_contiguous_atom_map_nums(...)

Assign sequential numbering to a collection of molecules such that their map numbers span a contiguous range of integers

clear_atom_map_nums(→ None)

Removes atom map numbers from all atoms in an RDKit Mol

clear_atom_isotopes(→ None)

Removes isotope numbers from all atoms in an RDKit Mol

Module Contents

polymerist.rdutils.chemlabel.has_fully_mapped_atoms(rdmol: rdkit.Chem.rdchem.Mol) bool[source]

Check whether an RDKit Mol has a map number explicitly assigned to each member Atom

polymerist.rdutils.chemlabel.has_uniquely_mapped_atoms(rdmol: rdkit.Chem.rdchem.Mol, skip_unmapped: bool = False) bool[source]

Check whether an RDKit Mol has distinct atom map numbers for each member Atom If skip_unmapped=False (default), will check map numbers on ALL atoms; If skip_unmapped=True, however, will only check uniqueness of NONZERO map number (i.e. explicitly-mapped) atoms

polymerist.rdutils.chemlabel.map_numbers_by_atom_idxs(rdmol: rdkit.Chem.rdchem.Mol, *atom_idxs: list[int]) Generator[int | None, None, None][source]

Get assigned atom map numbers for a collection of atom ids, in the same order as the internal RDKit Mol atom IDs

polymerist.rdutils.chemlabel.atom_idxs_by_map_numbers(rdmol: rdkit.Chem.rdchem.Mol, *map_numbers: list[int]) Generator[int | None, None, None][source]

Returns the first occurences of the atom IDs of any number of atoms, indexed by atom map number

polymerist.rdutils.chemlabel.get_bond_by_map_num_pair(rdmol: rdkit.Chem.rdchem.Mol, map_num_pair: tuple[int, int], as_bond: bool = True) int | rdkit.Chem.rdchem.Bond | None[source]

Get the bond spanning a pair of atoms with given pair of atom map numbers Returns the RDkit.Bond object if as_bond=True, and the index of the bond if as_bond=False

If no bond exists between the atoms, will return None regardless of the value of “as_bond”

polymerist.rdutils.chemlabel.assign_atom_map_nums_by_ids(rdmol: rdkit.Chem.rdchem.Mol, map_nums_by_ids: dict[int, int]) None[source]

Assigns atom map numbers to Atoms in a Mol as identified by a mapping of atom indices to map numbers

Parameters:
  • rdmol (Chem.Mol) – An RDKit molecule to assign labels to

  • map_nums_by_ids (dict[int, int]) – A dict keyed by atom index and mapping to the corresponding desired atom map numbers

polymerist.rdutils.chemlabel.assign_ordered_atom_map_nums(rdmol: rdkit.Chem.rdchem.Mol, start_from: int = 1) None[source]

Assigns atom’s index as its atom map number for all atoms in an RDmol Can optionally specify what value to begin counting from (by default 1)

polymerist.rdutils.chemlabel.relabel_map_nums(rdmol: rdkit.Chem.rdchem.Mol, relabeling: dict[int, int]) None[source]

Applies a relabelling of atom map numbers to a subset of mapped atoms (described by a dict of old_map_num : new_map_num)

polymerist.rdutils.chemlabel.mol_to_smiles_and_atom_permutation(mol: rdkit.Chem.rdchem.Mol, *args, **kwargs) tuple[str, list[int]][source]

Convert RDKit Mol to SMILES string (with any SMILES writer parameters passed to as args/kwargs) AND return permutation list which maps atoms in the written SMILES to their order in the passed Mol

Useful when preserving Mol atom order in SMILES is necessary (not true in general)

Parameters:
  • mol (Chem.Mol) – The RDKit Mol object

  • *args, **kwargs – Additional arguments passed to the SMILES writer

Returns:

  • smiles (str) – The resulting SMILES string

  • atom_perm_inv (list[int]) – List representation of the permutation that restores atom order

    E.g. the following call, using “smiles” returned above, will in general scramble atom order: >>> from rdkit.Chem.rdmolfiles import MolToSmiles >>> mol = MolFromSmiles(smiles) # atom order doesn’t match that of exporting Mol

    However, atom order can easily be restored by calling: >>> from rdkit.Chem.rdmolops import RenumberAtoms >>> mol = RenumberAtoms(mol, atom_perm_inv)

  • tuple[str, list[int]] – A tuple containing the SMILES string and the atom permutation list.

polymerist.rdutils.chemlabel.assign_contiguous_atom_map_nums(*rdmols: Iterable[rdkit.Chem.rdchem.Mol], start_from: int = 1, in_place: bool = False) list[rdkit.Chem.rdchem.Mol] | None[source]

Assign sequential numbering to a collection of molecules such that their map numbers span a contiguous range of integers Can optionally specify what value to begin counting from (by default 1)

polymerist.rdutils.chemlabel.clear_atom_map_nums(rdmol: rdkit.Chem.rdchem.Mol) None[source]

Removes atom map numbers from all atoms in an RDKit Mol

polymerist.rdutils.chemlabel.clear_atom_isotopes(rdmol: rdkit.Chem.rdchem.Mol) None[source]

Removes isotope numbers from all atoms in an RDKit Mol