|
8 | 8 |
|
9 | 9 | from __future__ import annotations |
10 | 10 |
|
| 11 | +import math |
11 | 12 | from typing import TYPE_CHECKING |
12 | 13 |
|
13 | 14 | import torch |
@@ -169,7 +170,8 @@ class EwaldModel(ModelInterface): |
169 | 170 |
|
170 | 171 | Args: |
171 | 172 | cutoff: Real-space cutoff in Angstrom. |
172 | | - accuracy: Target accuracy for auto-estimated Ewald parameters. |
| 173 | + accuracy: Target accuracy, which sets the Ewald splitting parameter and the |
| 174 | + reciprocal-space cutoff together with ``cutoff``. |
173 | 175 | device: Compute device. Defaults to CUDA if available, else CPU. |
174 | 176 | dtype: Floating-point dtype. Defaults to ``torch.float64``. |
175 | 177 | compute_forces: Whether to return forces. Defaults to True. |
@@ -237,10 +239,14 @@ def forward(self, state: SimState, **_kwargs: object) -> dict[str, torch.Tensor] |
237 | 239 | state.positions.shape[0], |
238 | 240 | ) |
239 | 241 | cell = state.row_vector_cell.contiguous() |
| 242 | + # The real-space cutoff is fixed, so alpha and k_cutoff follow from accuracy |
| 243 | + log_accuracy = math.log(self.accuracy) |
240 | 244 | out = ewald_summation( |
241 | 245 | positions=state.positions, |
242 | 246 | charges=charges, |
243 | 247 | cell=cell, |
| 248 | + alpha=math.sqrt(-log_accuracy) / self.cutoff, |
| 249 | + k_cutoff=-2.0 * log_accuracy / self.cutoff, |
244 | 250 | neighbor_list=edge_index, |
245 | 251 | neighbor_ptr=neighbor_ptr, |
246 | 252 | neighbor_shifts=unit_shifts, |
@@ -294,7 +300,8 @@ class PMEModel(ModelInterface): |
294 | 300 |
|
295 | 301 | Args: |
296 | 302 | cutoff: Real-space cutoff in Angstrom. |
297 | | - accuracy: Target accuracy for auto-estimated parameters. |
| 303 | + accuracy: Target accuracy, which sets the Ewald splitting parameter and the |
| 304 | + default mesh together with ``cutoff``. |
298 | 305 | mesh_spacing: Optional mesh spacing (Angstrom) for automatic mesh sizing. |
299 | 306 | mesh_dimensions: Explicit FFT mesh dimensions ``(nx, ny, nz)``. |
300 | 307 | spline_order: B-spline interpolation order. Defaults to 4. |
@@ -376,6 +383,8 @@ def forward(self, state: SimState, **_kwargs: object) -> dict[str, torch.Tensor] |
376 | 383 | positions=state.positions, |
377 | 384 | charges=charges, |
378 | 385 | cell=cell, |
| 386 | + # The real-space cutoff is fixed, so alpha follows from accuracy |
| 387 | + alpha=math.sqrt(-math.log(self.accuracy)) / self.cutoff, |
379 | 388 | neighbor_list=edge_index, |
380 | 389 | neighbor_ptr=neighbor_ptr, |
381 | 390 | neighbor_shifts=unit_shifts, |
|
0 commit comments