kups.potential.common.graph
¶
Graph construction from atomic coordinates for potential evaluation.
This module builds molecular graphs (point clouds, hypergraphs) from
Indexed particle data for potential energy evaluation. Graphs support
periodic boundary conditions, multiple independent systems, and efficient
incremental construction for Monte Carlo via probes.
Key components:
- PointCloud: Indexed particles and systems
- HyperGraph: Point cloud with typed edges
- RadiusGraphConstructor: Builds pairwise graphs from neighbor lists
- EdgeSetGraphConstructor: Builds graphs from explicit edge lists (bonds, angles)
- PointCloudConstructor: Builds zero-order graphs (no edges)
- LocalGraphSumComposer: Incremental energy update plans
- FullGraphSumComposer: Full recomputation plans
EdgeSetGraphConstructor
¶
Bases: GraphConstructor[State, Ptch, P, S, Degree]
Constructs graphs from predefined edge lists (bonds, angles, dihedrals).
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
View[State, Table[ParticleId, P]]
|
View extracting |
systems |
View[State, Table[SystemId, S]]
|
View extracting |
edges |
View[State, Edges[Degree]]
|
View extracting |
probe |
Probe[State, Ptch, IsEdgeSetGraphProbe[P, Degree]] | None
|
Optional probe for incremental particle + edge changes. |
Source code in src/kups/potential/common/graph.py
FullGraphSumComposer
¶
Bases: SumComposer[State, GraphPotentialInput[Params, P, S, Degree], Ptch]
Composer for global potentials requiring full recomputation.
Always applies the patch (if any) to the state and then builds a single full graph.
Source code in src/kups/potential/common/graph.py
GraphConstructor
¶
Bases: Protocol
Protocol for constructing molecular graphs from simulation state.
Source code in src/kups/potential/common/graph.py
__call__(state, patch, old_graph=False)
¶
Construct a hypergraph from state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
Current simulation state. |
required |
patch
|
Ptch | None
|
Optional patch for incremental construction. |
required |
old_graph
|
bool
|
If True, return graph for the pre-update configuration. |
False
|
Returns:
| Type | Description |
|---|---|
HyperGraph[P, S, Degree]
|
HyperGraph with particles, systems, and edges. |
Source code in src/kups/potential/common/graph.py
GraphPotentialInput
¶
Bases: NamedTuple, Generic[Params, Part, Sys, Degree]
Input bundle for graph-based potential energy functions.
Source code in src/kups/potential/common/graph.py
HyperGraph
¶
Bases: PointCloud[Part, Sys], Generic[Part, Sys, Degree]
Point cloud with edges representing particle interactions.
Generic in Part (particle data), Sys (system data), and
Degree (number of particles per edge: 2=pairs, 3=triplets).
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
Table[ParticleId, Part]
|
Inherited -- indexed particle data. |
systems |
Table[SystemId, Sys]
|
Inherited -- indexed system data. |
edges |
Edges[Degree]
|
Edge connectivity with |
Source code in src/kups/potential/common/graph.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
sorted_by_system(sort_edges=False, *, return_sort_order=False)
¶
Sort particles by system index and remap edges accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sort_edges
|
bool
|
If True, also sort edges by the system of their first particle. |
False
|
return_sort_order
|
bool
|
If True, also return the sort permutation. |
False
|
Source code in src/kups/potential/common/graph.py
IsEdgeSetGraphProbe
¶
Bases: Protocol
Probe result for edge-set graph incremental updates.
Source code in src/kups/potential/common/graph.py
IsRadiusGraphProbe
¶
Bases: Protocol
Probe result for radius graph incremental updates.
Source code in src/kups/potential/common/graph.py
LocalGraphSumComposer
¶
Bases: SumComposer[State, GraphPotentialInput[Params, P, S, Degree], Ptch]
Composer for local potentials with incremental updates.
Without a patch, returns a single full-graph summand. With a patch,
returns old_graph (weight −1) + new_graph (weight +1) with
add_previous_total=True, enabling O(k) energy updates.
Source code in src/kups/potential/common/graph.py
PointCloud
¶
Bases: Generic[Part, Sys]
Indexed particles and systems, the base for all graph representations.
Generic in Part (particle data with positions and system assignment)
and Sys (system data with unit cell).
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
Table[ParticleId, Part]
|
Indexed particle data with positions and system assignment. |
systems |
Table[SystemId, Sys]
|
Indexed system data with unit cell information. |
Source code in src/kups/potential/common/graph.py
PointCloudConstructor
¶
Bases: GraphConstructor[State, Ptch, P, S, Literal[0]]
Constructs zero-order graphs (Degree=0, no edges).
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
View[State, Table[ParticleId, P]]
|
View extracting |
systems |
View[State, Table[SystemId, S]]
|
View extracting |
probe_particles |
Probe[State, Ptch, WithIndices[ParticleId, P]] | None
|
Optional probe returning |
Source code in src/kups/potential/common/graph.py
RadiusGraphConstructor
¶
Bases: GraphConstructor[State, Ptch, P, S, Literal[2]]
Constructs pairwise graphs from neighbor lists (Degree=2).
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
View[State, Table[ParticleId, P]]
|
View extracting |
systems |
View[State, Table[SystemId, S]]
|
View extracting |
cutoffs |
View[State, Table[SystemId, Array]]
|
View extracting |
neighborlist |
View[State, NearestNeighborList]
|
View extracting the |
probe |
Probe[State, Ptch, IsRadiusGraphProbe[P]] | None
|
Optional probe for incremental particle + neighbor list changes. |