kups.potential.classical.ewald
¶
Ewald summation for long-range electrostatics in periodic systems.
Splits the Coulomb potential into short-range (real-space), long-range (reciprocal-space), and self-interaction terms. Supports incremental updates via cached structure factors for efficient Monte Carlo.
TO_STANDARD_UNITS = HARTREE * BOHR
module-attribute
¶
Conversion factor from atomic units to standard energy units.
EwaldSelfInput = GraphPotentialInput[EwaldParameters, IsEwaldPointData, HasUnitCell, Any]
¶
Input type for the Ewald self-interaction correction.
EwaldShortRangeInput = GraphPotentialInput[EwaldParameters, IsEwaldPointData, HasUnitCell, Literal[2]]
¶
Input type for the real-space short-range Ewald energy.
EwaldCache
¶
Cached structure factors and per-component outputs for incremental updates.
Attributes:
| Name | Type | Description |
|---|---|---|
structure_factor |
Array
|
Complex structure factors, shape |
short_range |
PotentialOut[Gradient, Hessian]
|
Cached real-space short-range output. |
long_range |
PotentialOut[Gradient, Hessian]
|
Cached reciprocal-space long-range output. |
self_interaction |
PotentialOut[Gradient, Hessian]
|
Cached self-interaction correction output. |
exclusion |
PotentialOut[Gradient, Hessian]
|
Cached bonded-pair exclusion correction output. |
Source code in src/kups/potential/classical/ewald.py
EwaldCachePatch
¶
Bases: Patch[State]
Patch for updating Ewald structure factors on Monte Carlo accept/reject.
Attributes:
| Name | Type | Description |
|---|---|---|
new_structure_factor |
Array
|
Updated structure factors to apply on acceptance. |
lens |
Lens[State, EwaldCache[Gradient, Hessian]]
|
Lens to the |
Source code in src/kups/potential/classical/ewald.py
EwaldLongRangeComposer
¶
Composer for the long-range Ewald potential.
Without a patch, builds a single full point cloud for the structure factor computation. With a patch, builds a point cloud containing the proposed changes and stores previous particle data for incremental structure factor updates.
Source code in src/kups/potential/classical/ewald.py
EwaldLongRangeInput
¶
Input for the reciprocal-space (long-range) Ewald energy.
Attributes:
| Name | Type | Description |
|---|---|---|
point_cloud |
PointCloud[IsEwaldPointData, HasUnitCell]
|
Particle and system data. |
parameters |
EwaldParameters
|
Ewald convergence parameters and k-vectors. |
cache |
EwaldCache | None
|
Cached structure factors for incremental updates; |
cache_lens |
Lens[State, EwaldCache[Any, Any]] | None
|
Lens to the |
changes_from_prev |
WithIndices[ParticleId, IsEwaldPointData] | None
|
Changed particles for incremental structure factor updates. |
Source code in src/kups/potential/classical/ewald.py
EwaldParameterEstimates
¶
Estimated optimal Ewald parameters for given accuracy.
Source code in src/kups/potential/classical/ewald.py
EwaldParameters
¶
Ewald summation parameters: convergence settings and reciprocal lattice vectors.
Attributes:
| Name | Type | Description |
|---|---|---|
alpha |
Table[SystemId, Array]
|
Ewald screening parameter [1/Ang], shape |
cutoff |
Table[SystemId, Array]
|
Real-space cutoff radius [Ang], shape |
reciprocal_lattice_shifts |
Table[SystemId, Array]
|
Integer k-vector coefficients,
shape |
Source code in src/kups/potential/classical/ewald.py
make(charges, unitcell, epsilon_total=1e-08, real_cutoff=None)
classmethod
¶
Estimate Ewald parameters from indexed particles and systems.
Splits particles by system index, estimates per-system parameters, and zero-pads k-vectors to the maximum count across systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charges
|
Table[ParticleId, IsEwaldPointData]
|
Indexed particles with charges and system assignment. |
required |
unitcell
|
Table[SystemId, HasUnitCell]
|
Indexed systems with unit cells. |
required |
epsilon_total
|
float
|
Target total accuracy for the Ewald sum. |
1e-08
|
real_cutoff
|
float | None
|
Optional real-space cutoff override; estimated if not given. |
None
|
Returns:
| Type | Description |
|---|---|
EwaldParameters
|
|
Source code in src/kups/potential/classical/ewald.py
EwaldPotential
¶
Bases: SummedPotential[State, Gradients, Hessians, P]
Complete Ewald potential with named access to each component term.
Source code in src/kups/potential/classical/ewald.py
exclusion_correction
property
¶
Exclusion correction: subtracts vacuum Coulomb energy for bonded/excluded pairs.
long_range
property
¶
Reciprocal-space long-range potential component.
self_interaction
property
¶
Self-interaction correction term.
short_range
property
¶
Real-space short-range potential component.
IsEwaldPointData
¶
Bases: HasCharges, IsRadiusGraphPoints, Protocol
Particle data required by Ewald: charges, positions, system/inclusion/exclusion indices.
Source code in src/kups/potential/classical/ewald.py
IsEwaldState
¶
Bases: Protocol
Protocol for states providing all inputs for the Ewald potential.
Source code in src/kups/potential/classical/ewald.py
estimate_ewald_parameters(charges, unitcell, /, real_cutoff=None, alpha=None, epsilon_total=1e-08)
¶
Estimate optimal Ewald parameters for target accuracy.
Not JAX-compatible (uses scipy); call before JIT compilation. Only works on single systems, not batched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charges
|
Array
|
Particle charges [e], shape |
required |
unitcell
|
UnitCell
|
Unit cell parameters. |
required |
real_cutoff
|
float | None
|
Real-space cutoff [Ang]; optimized if |
None
|
alpha
|
float | None
|
Screening parameter [1/Ang]; optimized if |
None
|
epsilon_total
|
float
|
Target total error (split equally between real/reciprocal). |
1e-08
|
Returns:
| Type | Description |
|---|---|
EwaldParameterEstimates
|
Optimized Ewald summation parameters. |
Source code in src/kups/potential/classical/ewald.py
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 | |
ewald_long_range_energy(inp)
¶
Reciprocal-space (long-range) Ewald energy.
Math: E_lr = TO_STANDARD_UNITS * sum_k P(k) * |S(k)|^2.
Wraps structure_factor + long_range and returns a cache patch
for structure factor updates on MC accept/reject.
Source code in src/kups/potential/classical/ewald.py
ewald_self_interaction_energy(inp)
¶
Self-interaction correction for Ewald summation.
Removes the artificial interaction of each charge with its own Gaussian cloud introduced by the Ewald splitting.
Math: E_self = -alpha / sqrt(pi) * sum_i q_i^2 * TO_STANDARD_UNITS.
Summed per system via segment_sum. Positions in Ang, charges in e, energy in eV.
Source code in src/kups/potential/classical/ewald.py
ewald_short_range_energy(inp)
¶
Real-space (short-range) screened Coulomb energy.
Math: E_sr = 1/2 * TO_STANDARD_UNITS * sum_{i<j} q_i*q_j * erfc(alpha*r_ij) / r_ij.
The erfc(alpha*r) damping ensures convergence within the cutoff.
Factor ½ corrects for double-counted pairs from the radius graph edges.
Positions in Ang, charges in e, energy in eV.
Source code in src/kups/potential/classical/ewald.py
exclusion_correction_energy(inp)
¶
Correction for excluded pairs (e.g., bonded atoms).
Math: E_excl = E_sr(excluded) - E_vacuum(excluded).
Subtracts the vacuum Coulomb energy from the short-range Ewald energy for excluded pairs, ensuring they have zero net Coulomb interaction in the total Ewald sum.
Source code in src/kups/potential/classical/ewald.py
kvecs_from_kmax(unitcell, kmax)
¶
Generate integer k-vector coefficients within a sphere of radius kmax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unitcell
|
UnitCell
|
Unit cell defining the reciprocal lattice. |
required |
kmax
|
float
|
Maximum k-vector magnitude cutoff. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Integer k-vector coefficients, shape |
Source code in src/kups/potential/classical/ewald.py
long_range(inp, structure_factor)
¶
Reciprocal-space energy from structure factors.
Math: E_lr = sum_k P(k) * |S(k)|^2 where P(k) is the prefactor
and S(k) the structure factor.
Source code in src/kups/potential/classical/ewald.py
make_ewald_from_state(state, probe=None, *, compute_position_and_unitcell_gradients=False, include_exclusion_mask=False)
¶
make_ewald_from_state(
state: Lens[
State,
IsEwaldState[MaybeCached[EwaldParameters, Any]],
],
probe: None = None,
*,
compute_position_and_unitcell_gradients: Literal[
False
] = ...,
include_exclusion_mask: bool = False,
) -> EwaldPotential[State, EmptyType, EmptyType, Patch]
make_ewald_from_state(
state: Lens[
State,
IsEwaldState[MaybeCached[EwaldParameters, Any]],
],
probe: None = None,
*,
compute_position_and_unitcell_gradients: Literal[True],
include_exclusion_mask: bool = False,
) -> EwaldPotential[
State, PositionAndUnitCell, EmptyType, Patch
]
make_ewald_from_state(
state: Lens[
State,
IsEwaldState[
HasCache[
EwaldParameters,
EwaldCache[EmptyType, EmptyType],
]
],
],
probe: Probe[
State, P, IsRadiusGraphProbe[IsEwaldPointData]
],
*,
compute_position_and_unitcell_gradients: Literal[
False
] = ...,
include_exclusion_mask: bool = False,
) -> EwaldPotential[State, EmptyType, EmptyType, P]
make_ewald_from_state(
state: Lens[
State,
IsEwaldState[
HasCache[
EwaldParameters,
EwaldCache[PositionAndUnitCell, EmptyType],
]
],
],
probe: Probe[
State, P, IsRadiusGraphProbe[IsEwaldPointData]
],
*,
compute_position_and_unitcell_gradients: Literal[True],
include_exclusion_mask: bool = False,
) -> EwaldPotential[
State, PositionAndUnitCell, EmptyType, P
]
Create an Ewald potential from a typed state, optionally with incremental updates.
When probe is None, builds a static potential by extracting
components directly from the state. When a probe is provided, the
potential supports incremental (cached) evaluation via the probe's
patch mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Any
|
Lens focusing on the Ewald state (particles, systems, neighborlist, and ewald_parameters). |
required |
probe
|
Any
|
Probe for incremental updates. |
None
|
compute_position_and_unitcell_gradients
|
bool
|
When |
False
|
include_exclusion_mask
|
bool
|
Whether to include the exclusion correction term in the returned potential. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
An |
Any
|
self-energy, and (optionally) exclusion-correction terms. |
Any
|
Gradient type is |
Any
|
requested, |
Source code in src/kups/potential/classical/ewald.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 | |
make_ewald_long_range_potential(particles_view, systems_view, parameter_lens, cache_lens, probe=None, gradient_lens=EMPTY_LENS, hessian_lens=EMPTY_LENS, hessian_idx_view=EMPTY_LENS, patch_idx_view=None)
¶
Create the Ewald reciprocal-space (long-range) potential.
Source code in src/kups/potential/classical/ewald.py
make_ewald_potential(particles_view, systems_view, neighborlist_view, parameter_lens, cache_lens, probe, gradient_lens, hessian_lens, hessian_idx_view, patch_idx_view=None, include_exclusion_mask=False)
¶
Create the complete Ewald potential combining all component terms.
Implements the Ewald decomposition:
E_total = E_sr + E_lr - E_self - E_excl
where each term is computed independently and cached for incremental
MC updates. Short-range and exclusion use radius graphs (real-space
pairs), long-range uses point clouds (reciprocal space), and
self-interaction is per-particle.
Internally converts _ParticleData adding inclusion and
exclusion fields for the neighbor list:
- sr/lr/self:
inclusion=system(all particles in same system interact),exclusion=particle_id(self-exclusion). - exclusion correction:
inclusion=group(only same-molecule pairs),exclusion=particle_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles_view
|
View[State, Table[ParticleId, IsEwaldPointData]]
|
Indexed particle data (positions, charges, system index). |
required |
systems_view
|
View[State, Table[SystemId, HasUnitCell]]
|
Indexed system data (unit cell). |
required |
neighborlist_view
|
View[State, NearestNeighborList]
|
Full neighbor list. |
required |
parameter_lens
|
Lens[State, EwaldParameters]
|
Lens to EwaldParameters. |
required |
cache_lens
|
Lens[State, EwaldCache] | None
|
Lens to EwaldCache, or |
required |
probe
|
Probe[State, Ptch, IsRadiusGraphProbe[IsEwaldPointData]] | None
|
Probe for incremental updates, or |
required |
gradient_lens
|
Lens[PointCloud[IsEwaldPointData, HasUnitCell], 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 (optional). |
None
|
include_exclusion_mask
|
bool
|
Whether to include the exclusion correction. |
False
|
Returns:
| Type | Description |
|---|---|
EwaldPotential[State, Gradients, Hessians, Ptch]
|
Complete Ewald potential (sum of three or four components). |
Source code in src/kups/potential/classical/ewald.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 | |
make_ewald_self_interaction_potential(particles_view, systems_view, parameter_view, probe=None, gradient_lens=EMPTY_LENS, hessian_lens=EMPTY_LENS, hessian_idx_view=EMPTY_LENS, patch_idx_view=None, cache_lens=None)
¶
Create the Ewald self-interaction correction potential.
Source code in src/kups/potential/classical/ewald.py
make_ewald_short_range_potential(particles_view, systems_view, neighborlist_view, parameter_view, probe, gradient_lens, hessian_lens, hessian_idx_view, patch_idx_view=None, cache_lens=None)
¶
Create the Ewald real-space (short-range) potential.
Source code in src/kups/potential/classical/ewald.py
prefactor(inp)
¶
Reciprocal-space prefactor for each k-vector.
Math: P(k) = 2*pi/V * exp(-k^2 / (4*alpha^2)) / k^2 for k != 0,
zero for k = 0. The (2 - leading_zero) factor accounts for the
Hermitian symmetry optimization: only half the k-vectors are stored
(k and -k give conjugate contributions).
Returns:
| Type | Description |
|---|---|
Array
|
Prefactor array, shape |
Source code in src/kups/potential/classical/ewald.py
structure_factor(inp)
¶
Compute the structure factor, dispatching between full and incremental.
Uses _structure_factor_full when no changes_from_prev is available,
otherwise _structure_factor_update for incremental MC updates.
Returns:
| Type | Description |
|---|---|
tuple[Array, Patch[State]]
|
Tuple of structure factor array and a cache patch. |