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 integern_steps; BFS walks exactlyn_stepsoutward.Fragment.assembled()— wrap an already-built Molspace (e.g. a combined reaction template) without slicing; edges and external NTAs are supplied explicitly.initiatorisNonefor 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:
objectReactive sub-region of a Molspace.
- Parameters:
mol (Molspace) – Molspace containing the fragment. Sliced (on a copy) down to
interior_idswithout renumbering, so original atom ids survive.initiator (int or None) – Atom id of the initiator inside the fragment, or
Nonefor 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 tono_remap_ids.-1disables.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 immediatemol.edge_external_ntas (dict[int, list[str]] or None) – Explicit
{edge_id: [nta, ...]}override (used byassembled()). 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_depthis 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.
initiatorisNone.- Parameters:
mol – The whole-template Molspace.
edges – Edge atom ids (in
mol’s numbering).edge_external_ntas –
{edge_id: [nta, ...]}severed-neighbor NTAs, already inmol’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 inedges.- 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.