mooonpy.molspace.remap module

Atom-ID remapping primitives for Molspace.

A single primitive remap_ids(mol, old2new) handles three use cases:

  1. Pure renumbering: when old2new covers every atom id in mol.

  2. Slicing: when old2new covers only a subset; the missing ids and any bond/angle/dihedral/improper entry referencing them are dropped.

  3. Combined slice + renumber: any subset, mapped to any new ids.

The Python identities of mol.atoms, mol.bonds, mol.angles, mol.dihedrals, mol.impropers, and each surviving Atom/Bond/… object are preserved. Only the dict keys (and obj.id / obj.ordered) change.

The helper build_old2new constructs the mapping for the common cases (contiguous renumber, fixed offset, identity-with-keep-set).

Bond-graph reachability lives in mooonpy.molspace.graph_theory.interface (find_reachable_neighbors, find_reachable_neighbors_all, steps_from_initiator).

mooonpy.molspace.remap.build_old2new(mol, mode='contiguous', offset=0, start=1, keep=None)[source]

Build an old2new mapping (and its inverse) for use with remap_ids.

Parameters

mol : Molspace mode : {‘contiguous’, ‘offset’, ‘identity’}

  • 'contiguous': assign start, start+1, ... in current atom insertion order. With keep set, only the kept ids are renumbered (so calling remap_ids with this map slices to those ids).

  • 'offset': new = old + offset for every atom (or each id in keep if given).

  • 'identity': each id maps to itself. Most useful with keep to slice without renumbering.

offsetint

Used by 'offset' mode.

startint

Used by 'contiguous' mode.

keepiterable[int] or None

If given, restricts the mapping to these atom ids. Missing ids will be dropped if this map is passed to remap_ids.

Returns

(old2new, new2old) : tuple[dict[int, int], dict[int, int]]

mooonpy.molspace.remap.contiguous(mol, start=1)[source]

Renumber atoms 1..N (or start..start+N-1) in current insertion order.

Returns

old2new : dict[int, int]

mooonpy.molspace.remap.remap_ids(mol, old2new)[source]

Renumber and/or slice mol in place.

Parameters

mol : Molspace old2new : dict[int, int]

Map from current atom id to new atom id. Any current atom whose id is not in this dict is dropped, and any topology entry referencing a dropped id is also dropped.

Notes

Container Python identities (mol.atoms, mol.bonds, etc.) and surviving per-atom/per-bond object identities are preserved. Clusters are recomputed from scratch.

mooonpy.molspace.remap.slice_mol(mol, keep_ids, renumber=True)[source]

In-place slice mol to retain only keep_ids.

Parameters

keep_ids : iterable[int] renumber : bool

If True, surviving atoms are renumbered contiguously from 1. If False, original ids are kept (‘identity’ mode).

Returns

old2new : dict[int, int]