EspressoSq is a high-performance library for structure factor calculations, implemented in C++ with SIMD optimizations and physics-based improvements. It includes a setup script to generate a Python wrapper using Cython, making it accessible for both C++ and Python users.
- Fast Calculations: Optimized with SIMD instructions for superior speed.
- Physics-Based Optimizations:
Choose how many wavevectors to use for sampling and how many
qs to calculate. The library automatically distributes them uniformly on a logarithmic scale. - Cross-Platform: C++ core with a Python wrapper for ease of use in Python environments.
- Minimal Dependencies: I suggest using GCC for compilation, but otherwise the library is dependency-free.
- A working GCC compiler
- Python with Cython installed
-
Clone the repository
-
Create a build directory and compile the library
mkdir build cd build cmake .. make -
(Optional) Build Python wrapper To make the package importable in Python:
python3 setup.py build_ext --inplace
ℹ️ You may need to install
setuptools:pip3 install setuptools
Include the header file and link against the compiled library:
#include "sq_avx.hpp"
int main() {
const unsigned int num_particles = 9999;
const unsigned int order = 100;
const double box_len = 10.0;
const unsigned int orientations_per_wavevector = 100;
const unsigned int subsample_wavevectors = 100;
// Create random particle positions
std::vector<std::vector<double>> particle_positions(num_particles, std::vector<double>(3));
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(0.0, box_len);
for (auto &pos : particle_positions) {
pos[0] = dis(gen);
pos[1] = dis(gen);
pos[2] = dis(gen);
}
auto result = calculate_structure_factor(particle_positions, order, box_len, orientations_per_wavevector, subsample_wavevectors);
return 0;
}After building the Python extension, you can use it like this:
import sq_avx
# particle_positions should be a list of 3D positions
result = sq_avx.calculate_structure_factor(
particle_positions,
order,
box_len,
orientations_per_wavevector,
subsample_wavevectors,
)Contributions are welcome! Please open an issue or submit a pull request on GitHub.