kups.potential.classical.harmonic
¶
Harmonic potentials for bonded interactions.
This module provides harmonic bond and angle potentials commonly used in molecular mechanics force fields. These terms maintain molecular geometry and are typically applied to explicitly defined bonds and angles.
Bond potential: \(U(r) = k(r - r_0)^2\) Angle potential: \(U(\theta) = k(\theta - \theta_0)^2\)
HarmonicAngleParameters
¶
Harmonic angle potential parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
labels |
tuple[Label, ...]
|
Species labels, shape |
theta0 |
Array
|
Equilibrium angles [degrees], shape |
k |
Array
|
Force constants [energy/degree²], shape |
Source code in src/kups/potential/classical/harmonic.py
HarmonicBondParameters
¶
Harmonic bond potential parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
labels |
tuple[Label, ...]
|
Species labels, shape |
x0 |
Array
|
Equilibrium bond lengths [Ã…], shape |
k |
Array
|
Force constants [energy/Ų], shape |
Source code in src/kups/potential/classical/harmonic.py
HasBondedParticlesAndSystems
¶
Bases: Protocol
Protocol for states with indexed particles and systems containing a unit cell.
Source code in src/kups/potential/classical/harmonic.py
IsBondedParticles
¶
Bases: HasPositionsAndLabels, HasSystemIndex, Protocol
Particle data with positions, labels, and system index.
Source code in src/kups/potential/classical/harmonic.py
IsHarmonicAngleState
¶
Bases: HasBondedParticlesAndSystems, Protocol
Protocol for states providing all inputs for the harmonic angle potential.
Source code in src/kups/potential/classical/harmonic.py
IsHarmonicBondState
¶
Bases: HasBondedParticlesAndSystems, Protocol
Protocol for states providing all inputs for the harmonic bond potential.
Source code in src/kups/potential/classical/harmonic.py
harmonic_angle_energy(inp)
¶
Compute harmonic angle energy for all angles.
Calculates energy as k(θ - θ₀)² for each angle triplet and sums over all systems. Angles are computed in degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inp
|
HarmonicAngleInput
|
Graph potential input with harmonic angle parameters |
required |
Returns:
| Type | Description |
|---|---|
WithPatch[Table[SystemId, Energy], IdPatch]
|
Total angle energy per system |
Source code in src/kups/potential/classical/harmonic.py
harmonic_bond_energy(inp)
¶
Compute harmonic bond energy for all bonds.
Calculates energy as k(r - r₀)² for each bond and sums over all systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inp
|
HarmonicBondInput
|
Graph potential input with harmonic bond parameters |
required |
Returns:
| Type | Description |
|---|---|
WithPatch[Table[SystemId, Energy], IdPatch]
|
Total bond energy per system |
Source code in src/kups/potential/classical/harmonic.py
make_harmonic_angle_from_state(state, probe=None, *, compute_position_and_unitcell_gradients=False)
¶
make_harmonic_angle_from_state(
state: Lens[
State,
IsHarmonicAngleState[
MaybeCached[HarmonicAngleParameters, Any]
],
],
probe: None = None,
*,
compute_position_and_unitcell_gradients: Literal[
False
] = ...,
) -> Potential[State, EmptyType, EmptyType, Patch]
make_harmonic_angle_from_state(
state: Lens[
State,
IsHarmonicAngleState[
MaybeCached[HarmonicAngleParameters, Any]
],
],
probe: None = None,
*,
compute_position_and_unitcell_gradients: Literal[True],
) -> Potential[
State, PositionAndUnitCell, EmptyType, Patch
]
make_harmonic_angle_from_state(
state: Lens[
State,
IsHarmonicAngleState[
HasCache[
HarmonicAngleParameters,
PotentialOut[EmptyType, EmptyType],
]
],
],
probe: Probe[
State,
P,
IsEdgeSetGraphProbe[IsBondedParticles, Literal[3]],
],
*,
compute_position_and_unitcell_gradients: Literal[
False
] = ...,
) -> Potential[State, EmptyType, EmptyType, P]
make_harmonic_angle_from_state(
state: Lens[
State,
IsHarmonicAngleState[
HasCache[
HarmonicAngleParameters,
PotentialOut[
PositionAndUnitCell, EmptyType
],
]
],
],
probe: Probe[
State,
P,
IsEdgeSetGraphProbe[IsBondedParticles, Literal[3]],
],
*,
compute_position_and_unitcell_gradients: Literal[True],
) -> Potential[State, PositionAndUnitCell, EmptyType, P]
Create a harmonic angle potential, optionally with incremental updates.
Convenience wrapper around
make_harmonic_angle_potential.
When probe is None, builds a plain potential from
IsHarmonicAngleState.
When a probe is provided, builds an incrementally-updated potential from
a state with HasCache-wrapped parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Any
|
Lens into the sub-state providing particles, unit cell, edges, and harmonic angle parameters. |
required |
probe
|
Any
|
If provided, detects which particles and edges changed since the last step for incremental updates. |
None
|
compute_position_and_unitcell_gradients
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Configured harmonic angle Potential. |
Source code in src/kups/potential/classical/harmonic.py
make_harmonic_angle_potential(particles_view, edges_view, systems_view, parameter_view, probe, gradient_lens, hessian_lens, hessian_idx_view, patch_idx_view=None, out_cache_lens=None)
¶
Create harmonic angle potential for explicitly defined angles.
Applies harmonic restraints to specified atom triplets (angles). Angles must be explicitly provided via the input_view edge set as triplets (i-j-k).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles_view
|
View[State, Table[ParticleId, IsBondedParticles]]
|
Extracts particle data (positions, species) with system index |
required |
edges_view
|
View[State, Edges[Literal[3]]]
|
Extracts angle connectivity (triplets) |
required |
systems_view
|
View[State, Table[SystemId, HasUnitCell]]
|
Extracts indexed system data (unit cell) |
required |
parameter_view
|
View[State, HarmonicAngleParameters]
|
Extracts HarmonicAngleParameters |
required |
probe
|
Probe[State, P, IsEdgeSetGraphProbe[IsBondedParticles, Literal[3]]] | None
|
Grouped probe for incremental updates (particles, edges, capacity) |
required |
gradient_lens
|
Lens[HarmonicAngleInput, Gradients]
|
Specifies gradients to compute |
required |
hessian_lens
|
Lens[Gradients, Hessians]
|
Specifies Hessians to compute |
required |
hessian_idx_view
|
View[State, Hessians]
|
Hessian index structure |
required |
patch_idx_view
|
View[State, PotentialOut[Gradients, Hessians]] | None
|
Cached output index structure |
None
|
out_cache_lens
|
Lens[State, PotentialOut[Gradients, Hessians]] | None
|
Cache location lens |
None
|
Returns:
| Type | Description |
|---|---|
Potential[State, Gradients, Hessians, P]
|
Harmonic angle Potential |
Source code in src/kups/potential/classical/harmonic.py
make_harmonic_bond_from_state(state, probe=None, *, compute_position_and_unitcell_gradients=False)
¶
make_harmonic_bond_from_state(
state: Lens[
State,
IsHarmonicBondState[
MaybeCached[HarmonicBondParameters, Any]
],
],
probe: None = None,
*,
compute_position_and_unitcell_gradients: Literal[
False
] = ...,
) -> Potential[State, EmptyType, EmptyType, Patch]
make_harmonic_bond_from_state(
state: Lens[
State,
IsHarmonicBondState[
MaybeCached[HarmonicBondParameters, Any]
],
],
probe: None = None,
*,
compute_position_and_unitcell_gradients: Literal[True],
) -> Potential[
State, PositionAndUnitCell, EmptyType, Patch
]
make_harmonic_bond_from_state(
state: Lens[
State,
IsHarmonicBondState[
HasCache[
HarmonicBondParameters,
PotentialOut[EmptyType, EmptyType],
]
],
],
probe: Probe[
State,
P,
IsEdgeSetGraphProbe[IsBondedParticles, Literal[2]],
],
*,
compute_position_and_unitcell_gradients: Literal[
False
] = ...,
) -> Potential[State, EmptyType, EmptyType, P]
make_harmonic_bond_from_state(
state: Lens[
State,
IsHarmonicBondState[
HasCache[
HarmonicBondParameters,
PotentialOut[
PositionAndUnitCell, EmptyType
],
]
],
],
probe: Probe[
State,
P,
IsEdgeSetGraphProbe[IsBondedParticles, Literal[2]],
],
*,
compute_position_and_unitcell_gradients: Literal[True],
) -> Potential[State, PositionAndUnitCell, EmptyType, P]
Create a harmonic bond potential, optionally with incremental updates.
Convenience wrapper around
make_harmonic_bond_potential.
When probe is None, builds a plain potential from
IsHarmonicBondState.
When a probe is provided, builds an incrementally-updated potential from
a state with HasCache-wrapped parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Any
|
Lens into the sub-state providing particles, unit cell, edges, and harmonic bond parameters. |
required |
probe
|
Any
|
If provided, detects which particles and edges changed since the last step for incremental updates. |
None
|
compute_position_and_unitcell_gradients
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Configured harmonic bond Potential. |
Source code in src/kups/potential/classical/harmonic.py
make_harmonic_bond_potential(particles_view, edges_view, systems_view, parameter_view, probe, gradient_lens, hessian_lens, hessian_idx_view, patch_idx_view=None, out_cache_lens=None)
¶
Create harmonic bond potential for explicitly defined bonds.
Applies harmonic restraints to specified atom pairs (bonds). Bonds must be explicitly provided via the input_view edge set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles_view
|
View[State, Table[ParticleId, IsBondedParticles]]
|
Extracts particle data (positions, species) with system index |
required |
edges_view
|
View[State, Edges[Literal[2]]]
|
Extracts bond connectivity |
required |
systems_view
|
View[State, Table[SystemId, HasUnitCell]]
|
Extracts indexed system data (unit cell) |
required |
parameter_view
|
View[State, HarmonicBondParameters]
|
Extracts HarmonicBondParameters |
required |
probe
|
Probe[State, P, IsEdgeSetGraphProbe[IsBondedParticles, Literal[2]]] | None
|
Grouped probe for incremental updates (particles, edges, capacity) |
required |
gradient_lens
|
Lens[HarmonicBondInput, Gradients]
|
Specifies gradients to compute |
required |
hessian_lens
|
Lens[Gradients, Hessians]
|
Specifies Hessians to compute |
required |
hessian_idx_view
|
View[State, Hessians]
|
Hessian index structure |
required |
patch_idx_view
|
View[State, PotentialOut[Gradients, Hessians]] | None
|
Cached output index structure |
None
|
out_cache_lens
|
Lens[State, PotentialOut[Gradients, Hessians]] | None
|
Cache location lens |
None
|
Returns:
| Type | Description |
|---|---|
Potential[State, Gradients, Hessians, P]
|
Harmonic bond Potential |