Benchmark AI / Public workspace
SciCode / 10 / ewald_summation
Problem
Answer published by the source. Consult the official source to check your work against its answer.
problem background main
problem description main
Write a Python function that calculates the energy of a periodic system using Ewald summation given `latvec` of shape `(3, 3)`, `atom_charges` of shape `(natoms,)`, `atom_coords` of shape `(natoms, 3)`, and `configs` of shape `(nelectrons, 3)` using the following formula.
\begin{align}
E &= E_{\textrm{real-cross}} + E_{\textrm{real-self}} + E_{\textrm{recip}} + E_{\textrm{charged}}. \\
E_{\textrm{real-cross}} &= \sum_{\mathbf{n}} {}^{\prime} \sum_{i=1}^N \sum_{j>i}^N q_i q_j \frac{\textrm{erfc} \left( \alpha |\mathbf{r}_{ij} + \mathbf{n} L| \right)}{|\mathbf{r}_{ij} + \mathbf{n} L|}. \\
E_{\textrm{real-self}} &= - \frac{\alpha}{\sqrt{\pi}} \sum_{i=1}^N q_i^2. \\
E_{\textrm{recip}} &= \frac{4 \pi}{V} \sum_{\mathbf{k} > 0} \frac{\mathrm{e}^{-\frac{k^2}{4 \alpha^2}}}{k^2}
\left|
\sum_{i=1}^N q_i \mathrm{e}^{i \mathbf{k} \cdot \mathbf{r}_i} \sum_{j=1}^N q_j \mathrm{e}^{-i \mathbf{k} \cdot \mathbf{r}_j}
\right|. \\
E_{\textrm{charge}} &= -\frac{\pi}{2 V \alpha^2} \left|\sum_{i}^N q_i \right|^2.
\end{align}problem io
"""
Parameters:
latvec (np.ndarray): A 3x3 array representing the lattice vectors.
atom_charges (np.ndarray): An array of shape (natoms,) representing the charges of the atoms.
atom_coords (np.ndarray): An array of shape (natoms, 3) representing the coordinates of the atoms.
configs (np.ndarray): An array of shape (nelectrons, 3) representing the configurations of the electrons.
gmax (int): The maximum integer number of lattice points to include in one positive direction.
Returns:
float: The total energy from the Ewald summation.
"""problem name
ewald_summation
required dependencies
import numpy as np from scipy.special import erfc
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import