Projected Velocity-Velocity Autocorrelation Function Analysis Library
A high-performance, MPI-parallelized Python library for computing velocity-velocity autocorrelation functions (VACF) and spectral properties from molecular dynamics (MD) simulations. Designed for extracting phonon dispersion relations and dynamical structure factors from atomistic trajectory data.
- MPI Parallelization — Efficiently scales across multiple cores for large trajectory processing
- Multiple Lattice Types — Built-in support for FCC, BCC, SC, and HCP crystal structures
- Custom Q-Grids — Load arbitrary wavevector grids from HDF5 files
- Partial Contributions — Compute per-species contributions in multi-component systems
- Current Projections — Longitudinal (L), transverse (T), and total current correlations
- Normal Mode Projections — Project velocities onto phonon eigenvectors (TDEP integration)
- Memory-Aware Processing — Automatic memory management for large datasets
- C Extension Core — Optimized C routines for computing density and current in reciprocal space
Ensure you have the following installed:
- Python 3.7+
- C compiler (gcc, clang, or compatible)
- MPI implementation (OpenMPI, MPICH, etc.)
git clone https://github.com/username/VVCORElib.git
cd VVCORElib
pip install .Or install in development mode:
pip install -e .| Package | Purpose |
|---|---|
numpy |
Numerical array operations |
scipy |
Signal correlation functions |
h5py |
HDF5 file I/O for trajectories and results |
mpi4py |
MPI parallelization |
psutil |
Memory management |
mpirun -np 16 VVCORE_mpi \
-path ./trajectory \
-i trajectory.h5 \
-N_frames 10000 \
-N_auto 1000 \
-lattice fcc \
-a 4.05 \
-Nq_path 50 \
-Nq 150 \
-M "26.98" \
-opt "dens cur_L cur_T" \
-ts 25 \
-wmax 40 \
-dw 0.05For more control, run each stage separately:
1. Compute Signal (density/current in reciprocal space):
mpirun -np 16 VVCORE_mpi_reduce \
-path ./trajectory \
-i trajectory.h5 \
-N_frames 10000 \
-lattice fcc \
-a 4.05 \
-Nq_path 50 \
-Nq 150 \
-M "26.98" \
-opt "dens cur_L cur_T"2. Compute Autocorrelation:
mpirun -np 16 VVCORE_mpi_auto \
-path ./trajectory \
-N_frames 10000 \
-N_auto 1000 \
-Nq 150 \
-opt "dens cur_L cur_T"3. Compute Spectrum (Inverse Fourier Transform):
mpirun -np 16 VVCORE_mpi_ift \
-path ./trajectory \
-N_auto 1000 \
-Nq 150 \
-opt "dens cur_L cur_T" \
-ts 25 \
-wmax 40 \
-dw 0.054. Collect/Average Multiple Trajectories:
mpirun -np 16 VVCORE_mpi_collect \
-path ./data \
-folders "traj1 traj2 traj3 traj4" \
-Nq 150 \
-opt "dens cur_L cur_T"Full analysis pipeline: signal → autocorrelation → spectrum.
| Argument | Default | Description |
|---|---|---|
-path |
./ |
Path to trajectory folder |
-i |
data.dat |
Input trajectory file (HDF5 format) |
-opt |
dens cur_T cur_L |
Quantities to compute (space-separated) |
-N_frames |
10000 |
Number of frames to process |
-N_auto |
1000 |
Correlation window length |
-lattice |
fcc |
Lattice type: fcc, bcc, sc, hcp, file |
-Nq_path |
50 |
Points per high-symmetry segment |
-Nq |
50 |
Total number of q-points |
-a |
— | Lattice constant (Å) |
-c |
— | c-axis lattice constant (HCP only) |
-M |
— | Atomic masses (space-separated string) |
-ts |
25 |
Timestep (fs) |
-wmax |
40 |
Maximum frequency (THz) |
-dw |
0.05 |
Frequency resolution (THz) |
--partial |
False |
Compute partial (per-species) contributions |
--normal_modes |
False |
Project onto phonon normal modes |
--phase_noise |
False |
Add velocity noise for testing |
-noise_ind |
0 |
Species index for noise injection |
-noise_ratio |
0.0 |
Fraction of atoms with flipped velocities |
| Option | Description |
|---|---|
dens |
Density correlation function S(q,t) |
cur_L |
Longitudinal current correlation C_L(q,t) |
cur_T |
Transverse current correlation C_T(q,t) |
cur |
Total current (before projection) |
v_k |
Normal mode projected velocities (requires TDEP) |
The library expects trajectories in H5MD format:
trajectory.h5
├── particles/
│ └── all/
│ ├── position/
│ │ └── value [N_frames × N_atoms × 3]
│ └── velocity/
│ └── value [N_frames × N_atoms × 3]
Required file specifying atom type indices:
ind.h5
├── 1 [indices of type 1 atoms]
├── 2 [indices of type 2 atoms]
└── ...
For arbitrary wavevector grids (use -lattice file):
qgrid.h5
├── qx [N_q array of q_x components]
├── qy [N_q array of q_y components]
└── qz [N_q array of q_z components]
For normal mode projections (--normal_modes):
outfile.dispersion_relations.hdf5
├── eigenvectors_re [N_q × N_modes × N_atoms×3]
└── eigenvectors_im [N_q × N_modes × N_atoms×3]
| File | Description |
|---|---|
dens.h5 |
Density signal ρ(q,t) |
cur_L.h5 |
Longitudinal current j_L(q,t) |
cur_T.h5 |
Transverse current j_T(q,t) |
auto_dens.h5 |
Density autocorrelation ⟨ρ(q,t)ρ*(q,0)⟩ |
auto_cur_L.h5 |
Longitudinal current autocorrelation |
auto_cur_T.h5 |
Transverse current autocorrelation |
spec_dens.h5 |
Dynamic structure factor S(q,ω) |
spec_cur_L.h5 |
Longitudinal current spectrum |
spec_cur_T.h5 |
Transverse current spectrum |
from VVCORElib_mpi import (
compute_signal, # Compute density/current in reciprocal space
compute_signal_normal_modes, # Project onto phonon eigenvectors
compute_auto, # Compute autocorrelation functions
compute_ift, # Inverse Fourier transform to frequency domain
collect_auto, # Average autocorrelations across trajectories
save_signal, # Save results to HDF5
stack, # Stack distributed results
grids, # Q-grid generators
)from mpi4py import MPI
import numpy as np
from VVCORElib_mpi import compute_signal, compute_auto, compute_ift
from VVCORElib_mpi import save_signal, stack
comm = MPI.COMM_WORLD
# Parameters
traj_file = "trajectory.h5"
N_frames = 10000
N_auto = 1000
Nq_path = 50
Nq = 150
a = 4.05 # Lattice constant
M = {'1': np.float64(26.98)} # Aluminum
opts = ['dens', 'cur_L', 'cur_T']
# 1. Compute signals
res, _, _ = compute_signal(
traj_file, N_frames, Nq_path, Nq,
lattice='fcc', a=a, c=None, M=M,
opts=opts, partial=False,
phase_noise=False, noise_ind=0, noise_ratio=0.0,
comm=comm
)
# Gather and save
for opt in opts:
gathered = comm.gather(res[opt], root=0)
if comm.rank == 0:
stacked = stack(gathered)
save_signal(stacked, f"{opt}.h5")
# 2. Compute autocorrelation
auto_res = compute_auto('./', N_frames, Nq, N_auto, opts, comm)
# 3. Compute spectrum
spec_res = compute_ift('./', N_auto, Nq, ts=25, wmax=40, dw=0.05, opts=opts, comm=comm)from VVCORElib_mpi import grids
# FCC high-symmetry path: Γ-X-Γ-L
Q, Qn = grids['fcc'](Nq=50, a=4.05)
# BCC high-symmetry path: Γ-H-Γ-N
Q, Qn = grids['bcc'](Nq=50, a=2.87)
# Simple cubic: Γ-X-M-Γ-R-M
Q, Qn = grids['sc'](Nq=50, a=3.0)
# HCP: Γ-M-Γ-A-L
Q, Qn = grids['hcp'](Nq=50, a=3.2, c=5.2)
# Load from file
Q, Qn = grids['file']() # Reads qgrid.h5Γ → X → Γ → L
(0,0,0) → (0,2π/a,0) → (2π/a,2π/a,0) → (π/a,π/a,π/a)
Γ → H → Γ → N
(0,0,0) → (0,0,2π/a) → (2π/a,2π/a,2π/a) → (0,π/a,π/a)
Γ → X → M → Γ → R → M
(0,0,0) → (0,π/a,0) → (π/a,π/a,0) → (0,0,0) → (π/a,π/a,π/a) → (π/a,π/a,0)
Γ → M → Γ → A → L
The instantaneous density in reciprocal space:
The mass current density:
Longitudinal projection:
Transverse projection:
The autocorrelation function:
The dynamic spectrum via Fourier transform:
- Optimal MPI Ranks: Use
N_ranks ≈ N_qfor best load balancing - Memory: The library auto-partitions based on available RAM
- Chunk Size: Set
-N_autoto divide evenly into-N_frames - I/O: HDF5 trajectories significantly outperform ASCII formats
- Large Systems: Increase ranks rather than per-rank memory
Reduce MPI ranks or increase workload (more q-points or frames).
The library attempts automatic memory management. For very large systems:
- Reduce
-Nqand run in batches - Increase available RAM per process
- Use fewer MPI ranks with more memory each
Create an index file mapping atom types:
import h5py
import numpy as np
with h5py.File('ind.h5', 'w') as f:
f.create_dataset('1', data=np.arange(0, 500)) # Type 1: atoms 0-499
f.create_dataset('2', data=np.arange(500, 1000)) # Type 2: atoms 500-999If you use VVCORElib in your research, please cite:
@software{vvcorelib,
title = {VVCORElib: Projected Velocity-Velocity Autocorrelation Analysis},
author = {Author Name},
year = {2025},
url = {https://github.com/username/VVCORElib}
}[Add license information here]
Contributions are welcome! Please open an issue or submit a pull request.