mooonpy.template.fragment module

Fragment — a reactive sub-region of a Molspace with an initiator atom, a set of edge atoms, the NTAs of each edge’s severed (external) neighbors, and an optional set of atom ids excluded from charge remapping.

For LAMMPS fix bond/react template matching, edge atoms must each have exactly one bond into the fragment interior; the constructor warns if any edge violates this. The fragment mol carries the original atom ids so the caller’s breaks / makes / changed_typ lists keep referring to the ids they already know.

Construction modes (each accepts a Molspace or another Fragment as the source — when a Fragment is passed, its stored edge_external_ntas are inherited for any edge that survives into the new fragment):

  • Fragment.from_initiator_and_edges() — caller supplies an initiator and a list of edge ids; BFS walks outward from the initiator and stops at the edges.

  • Fragment.from_interior() — caller supplies the interior atom set; edges are derived as the boundary atoms.

  • Fragment.from_initiator_steps() — caller supplies an initiator and an integer n_steps; BFS walks exactly n_steps outward.

  • Fragment.assembled() — wrap an already-built Molspace (e.g. a combined reaction template) without slicing; edges and external NTAs are supplied explicitly. initiator is None for this whole-template form.

class mooonpy.template.fragment.Fragment(mol, initiator, interior_ids, edges, charge_edge_depth=-1, inherited_edge_ntas=None, edge_external_ntas=None, no_remap_ids=None)[source]

Bases: object

Reactive sub-region of a Molspace.

Parameters:
  • mol (Molspace) – Molspace containing the fragment. Sliced (on a copy) down to interior_ids without renumbering, so original atom ids survive.

  • initiator (int or None) – Atom id of the initiator inside the fragment, or None for an assembled whole-template Fragment.

  • interior_ids (iterable[int]) – Atom ids that belong to the fragment.

  • edges (iterable[int]) – Atom ids that bound the fragment.

  • charge_edge_depth (int) – If >= 0, atoms within this many bonds of any edge are added to no_remap_ids. -1 disables.

  • inherited_edge_ntas (dict[int, list[str]] or None) – When constructing from another Fragment, the parent’s edge_external_ntas. Used to keep the severed-neighbor NTA list for any edge whose external neighbors were already pruned from the immediate mol.

  • edge_external_ntas (dict[int, list[str]] or None) – Explicit {edge_id: [nta, ...]} override (used by assembled()). When given, the parent-graph computation is skipped entirely.

  • no_remap_ids (set[int] or None) – Explicit set of charge-preserved ids (used by assembled()). When given, charge_edge_depth is ignored.

Attributes

molMolspace

Sliced Molspace with original atom ids.

initiator : int or None edges : set[int] edge_external_ntas : dict[int, list[str]]

{edge_id: [nta_of_severed_neighbor, ...]}.

no_remap_idsset[int]

Atom ids whose charges should not be remapped during the reaction.

charge_edge_depth : int

classmethod assembled(mol, edges, edge_external_ntas, no_remap_ids=None)[source]

Wrap an already-built Molspace (e.g. a combined reaction template) as a Fragment without slicing. initiator is None.

Parameters:
  • mol – The whole-template Molspace.

  • edges – Edge atom ids (in mol’s numbering).

  • edge_external_ntas{edge_id: [nta, ...]} severed-neighbor NTAs, already in mol’s numbering.

  • no_remap_ids – Charge-preserved ids, or None.

classmethod from_initiator_and_edges(src, initiator, edges, max_steps=10, charge_edge_depth=-1)[source]

BFS outward from initiator; stop at any atom in edges.

Parameters:
  • src – Molspace or Fragment to walk.

  • initiator – Atom id to start from.

  • edges – Atom ids that bound the fragment.

  • max_steps – Safety cutoff on BFS depth. A warning is emitted if BFS hits this limit before fully enclosing the fragment (caller probably forgot an edge id).

  • charge_edge_depth – See Fragment.

classmethod from_initiator_steps(src, initiator, n_steps, charge_edge_depth=-1)[source]

Walk exactly n_steps bonds outward from initiator. The outermost shell becomes the edge set.

classmethod from_interior(src, initiator, interior_ids, charge_edge_depth=-1)[source]

Use interior_ids as-is; derive edges as the boundary atoms (interior atoms with at least one neighbor outside).