kups.potential.common.pair
¶
Composable pair energies with independent features, cutoffs, and masks.
HasPairTerms
¶
Bases: Protocol
Flat terms exposed by a single pair energy or a sum for composition.
Source code in src/kups/potential/common/pair.py
PairBatch
¶
Bases: NamedTuple
Geometry and independent masks for a batch of candidate pairs.
valid checks active endpoints and matching systems. Inclusion and
exclusion policies are kept separate so several consumers can share the
same candidates. Vectors point from query to key. Invalid geometry is
sanitized before a consumer evaluates singular pair kernels.
Source code in src/kups/potential/common/pair.py
from_candidates(batch, ctx, *, query_lanes=None)
classmethod
¶
Prepare pair geometry and masks from any selector's candidate batch.
query_lanes declares a regular block of candidates for each query, in
query-table order. This shares one cell matrix across a whole lane block
and broadcasts query coordinates so their gradients reduce along lanes.
Source code in src/kups/potential/common/pair.py
PairEnergy
¶
A pair kernel with feature, cutoff, and neighbor-mask policies.
with_parameters(view) binds a term to a field of shared parameters.
For example, lj.with_parameters(lambda p: p.lj) +
coulomb.with_parameters(lambda p: p.ewald) uses one neighbor traversal
at the maximum cutoff, retaining each term's individual cutoff.
Terms use a shared particle type; with_particles(view) adapts each
feature selector to that type before adding them.
Set inclusion=False to interact across inclusion groups within a
system, and exclusion=False to include same-group pairs. Exclusions
apply to the closest image; other periodic copies remain eligible.
Zero-shift self pairs and inactive particles are always excluded.
Source code in src/kups/potential/common/pair.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
terms
property
¶
Expose this energy as one term for flat composition.
with_parameters(view)
¶
Read this term's parameters from a shared parameter bundle.
Source code in src/kups/potential/common/pair.py
with_particles(view)
¶
Select this term's particle interface from a shared particle type.
Source code in src/kups/potential/common/pair.py
PairEnergySum
¶
A flat sum of pair terms evaluated on the same candidate batch.
Use + to combine terms with distinct feature types. Each entry in the
feature tuple comes from, and is passed back to, the term at the same
position. Feat retains the union of the terms' concrete feature types.
from_term starts a sum from any implementation of PairTerm.
Source code in src/kups/potential/common/pair.py
PairKernel
¶
Bases: Protocol
Numerical energy formula evaluated on already selected pairs.
A kernel takes parameters, the two endpoints' features and their geometry, and returns one energy per pair. For example, the Lennard-Jones kernel uses species labels to look up mixing parameters and evaluates the 12-6 formula. It leaves neighbor selection, cutoffs, masks and summation to its callers. In particular, it does not halve energies to account for directed edges.
Use JAX-compatible array operations and support broadcasting over the pair
axes: the same kernel handles flat graph edges and rectangular query/key
blocks. PairEnergy replaces masked pairs' geometry with finite, nonzero
values before calling the kernel, then sets their returned energies to zero.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
Params
|
The term's parameter bundle, such as mixing tables or screening constants. |
required | |
Feat
|
Per-particle feature pytree selected by |
required |
Source code in src/kups/potential/common/pair.py
__call__(parameters, features_i, features_j, rij, r2, system)
¶
Evaluate the interaction without reducing its pair axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Params
|
Parameters for this interaction. |
required |
features_i
|
Feat
|
Left-endpoint features, broadcastable over the pair axes. |
required |
features_j
|
Feat
|
Right-endpoint features, with the same pytree structure. |
required |
rij
|
Array
|
Displacement from left to right, including the periodic shift,
with shape |
required |
r2
|
Array
|
Squared distances, with shape |
required |
system
|
Index[SystemId]
|
System ids for selecting per-system parameters. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Energies with shape |
Source code in src/kups/potential/common/pair.py
PairTerm
¶
Bases: Protocol
Complete pair interaction interface consumed by neighbor evaluators.
A term selects particle features, declares the search cutoff, and evaluates
candidate pairs with its own cutoff and mask policy. PairEnergy implements
this interface for one PairKernel. PairEnergySum combines terms: its
search cutoff is their maximum, while evaluation retains each term's cutoff.
Its inclusion/exclusion flags describe masks required by every contribution,
allowing neighbor selection to apply those shared masks before compaction.
The evaluator constructs neighbors and periodic geometry, gathers endpoint
features, and reduces the returned pair energies into system totals.
GraphPairEnergy derives a graph evaluator from a PairEnergy;
FusedNeighborEnergy accepts any PairTerm for shared full/local evaluation.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
Params
|
Parameters supplied to the term's cutoff and energy functions. |
required | |
Part
|
Particle data presented to the feature selector. |
required | |
Feat
|
Selected per-particle feature pytree. Feature arrays preserve the
leading particle axis; |
required |
Source code in src/kups/potential/common/pair.py
cutoffs
property
¶
Select per-system search radii; a singleton table applies to all systems.
exclusion
property
¶
Whether every contribution excludes same-group closest images.
features
property
¶
Select the payload needed by the kernel, e.g. labels or charges.
Evaluators may cache these per-particle features in their cell table.
inclusion
property
¶
Whether every contribution requires matching inclusion groups.
evaluate(parameters, left, right, pairs)
¶
Return pair energies after applying this term's cutoff and masks.
left and right contain endpoint features broadcastable over
pairs.r2.shape. The result has that shape, with zero contributions
for invalid or filtered pairs. Geometry and candidate masks come from
PairBatch; the term decides which inclusion/exclusion masks apply.
Summation and directed-edge counting remain the evaluator's responsibility.