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.
pointcloud_geometry = lens(lambda pc: Geometry(pc.particles.map_data(lambda p: PositionsAndSystemIndex(p.positions, p.system)), pc.systems.map_data(lambda s: s.cell)))
module-attribute
¶
Adapter bridging the Ewald PointCloud sub-input to Geometry.
EwaldSelfInput = GraphPotentialInput[EwaldParameters, IsEwaldPointData, HasCell[Periodic3D], Literal[0]]
¶
Input type for the Ewald self-interaction correction.
EwaldShortRangeInput = GraphPotentialInput[EwaldParameters, IsEwaldPointData, HasCell[Periodic3D], 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, HasCell[Periodic3D]]
|
Particle and system data. |
parameters |
EwaldParameters
|
Ewald convergence parameters and k-vectors. |
cache |
EwaldCache[Any, Any] | 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, cell, 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 |
cell
|
Table[SystemId, HasCell[Periodic3D]]
|
Indexed systems with 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
estimate_ewald_parameters(charges, cell, /, 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 |
cell
|
Cell[AnyPeriodicity]
|
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
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 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 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 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 | |
ewald_long_range_energy(inp)
¶
Reciprocal-space (long-range) Ewald energy.
Math: E_lr = TO_STANDARD_UNITS * sum_k P(k) * |S(k)|^2 + E_net.
Wraps structure_factor + long_range, adds the neutralizing-background
correction (ewald_net_charge_energy) for nonzero net charge, and returns a
cache patch for structure factor updates on MC accept/reject.
Source code in src/kups/potential/classical/ewald.py
ewald_net_charge_energy(inp)
¶
Neutralizing-background correction for systems with nonzero net charge.
Math: E_net = -(pi / (2 * V * alpha^2)) * Q^2 * TO_STANDARD_UNITS where
Q = sum_i q_i is the per-system net charge and V the cell volume.
Replaces the omitted (divergent) k = 0 term of the reciprocal sum with a
uniform neutralizing background, restoring independence of the total energy
from alpha. Vanishes for charge-neutral systems. Position-independent (no
forces) but volume-dependent, so it contributes to the virial/pressure.
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
kvecs_from_kmax(cell, kmax)
¶
Generate integer k-vector coefficients within a sphere of radius kmax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
Cell[AnyPeriodicity]
|
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_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, HasCell[Periodic3D]]]
|
Indexed system data (cell). |
required |
neighborlist_view
|
View[State, NeighborList[Literal[2]]]
|
Cutoff-bound neighbor list. |
required |
parameter_lens
|
Lens[State, EwaldParameters]
|
Lens to EwaldParameters. |
required |
cache_lens
|
Lens[State, EwaldCache[Gradients, Hessians]] | None
|
Lens to EwaldCache, or |
required |
probe
|
Probe[State, Ptch, IsGraphProbe[IsEwaldPointData, Literal[2]]] | None
|
Probe for incremental updates, or |
required |
gradient_lens
|
Lens[PointCloud[IsEwaldPointData, HasCell[Periodic3D]], 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
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 1024 1025 1026 | |
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. |