mooonpy.molspace.remap module
Atom-ID remapping primitives for Molspace.
A single primitive remap_ids(mol, old2new) handles three use cases:
Pure renumbering: when
old2newcovers every atom id inmol.Slicing: when
old2newcovers only a subset; the missing ids and any bond/angle/dihedral/improper entry referencing them are dropped.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
old2newmapping (and its inverse) for use withremap_ids.Parameters
mol : Molspace mode : {‘contiguous’, ‘offset’, ‘identity’}
'contiguous': assignstart, start+1, ...in current atom insertion order. Withkeepset, only the kept ids are renumbered (so callingremap_idswith this map slices to those ids).'offset':new = old + offsetfor every atom (or each id inkeepif given).'identity': each id maps to itself. Most useful withkeepto 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
molin 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
molto retain onlykeep_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]