Getting Started#
seamm_md_analysis is the shared library behind SEAMM’s analysis of molecular
dynamics: the Diffusivity, Thermal Conductivity and Viscosity steps now, and
Structure and the Dielectric constant later. The steps run the MD (or read an
earlier run), and this library does the numerical work.
Installing#
pip install seamm-md-analysis
It needs numpy, scipy and pymbar.
What is in it#
seamm_md_analysis.statsmean_and_stderrover replicas,block_average,statistical_inefficiencyanddetect_equilibration(pymbar, imported quietly when first used),mean_and_stderr_correlated, andfmt_errto print a value with its error.seamm_md_analysis.correlateccovf, the cross-covariance of two series by FFT (the definition ofstatsmodels), the errors of correlation functions, andtensor_correlation_functionsfor the six components of a vector flux with their running integrals (the Green–Kubo input), andautocorrelation_functionsfor independent series such as the components of the shear stress.seamm_md_analysis.transportcollective_helfand_momentsfor a flux such as the heat flux;shear_stress_components, the five independent shear components of a pressure tensor, andcomponent_helfand_momentsfor each of them, for the viscosity;species_helfand_momentsandmsd_by_speciesfor single-molecule diffusion;fit_green_kubo_integral,fit_helfand_moment,helfand_slopeandfit_slope; andyeh_hummer_correction.The Helfand moments and MSDs are computed with FFTs. They equal the direct sums over time origins to rounding, but take O(n log n) rather than O(n m) time.
seamm_md_analysis.electricThe static dielectric constant and the ionic conductivity from the trajectory and fixed charges:
classify_molecules(neutral molecules, ions, and molecules with a non-integer charge),cell_dipole,dielectric_constant(the fluctuation formula for Ewald or PPPM electrostatics with conducting boundaries, with errors from blocks and the running estimate) anddipole_correlation;collective_msdandconductivity_from_msd(Einstein–Helfand, from the collective displacement of the ions’ charges) andnernst_einstein. For an electrolyte the dielectric constant uses the dipole of the neutral molecules: the ions carry a current, not a bounded dipole.seamm_md_analysis.plotsPlots of correlation functions, Green–Kubo integrals, Helfand moments and MSDs, for
seamm_utilfigures.seamm_md_analysis.legacyReaders for the files the LAMMPS step writes today:
!MolSSI trajectorytime series (read_trajectory), per-moleculevector_trajectoryfiles (read_vector_trajectory) and dump files (read_dump_trajectory).
Example#
The thermal conductivity from a heat flux sampled every dt:
import numpy as np
from seamm_md_analysis import (
collective_helfand_moments,
fit_green_kubo_integral,
read_trajectory,
tensor_correlation_functions,
)
metadata, columns = read_trajectory("heat_flux.trj")
J = np.stack((columns["Jx"], columns["Jy"], columns["Jz"]))
m = min(J.shape[1] // 10, 10000)
# Correlation functions and their integrals, per sampling interval
ccf, integral = tensor_correlation_functions(J, m=m)
# Helfand moments, per sampling interval squared
M = collective_helfand_moments(J, m=m)
Multiply by V / (k_B T²) and the sampling interval (Green–Kubo), or V dt² / (2 k_B T²) (Helfand), to get W/m/K.
The shear viscosity from a pressure tensor P (n × 3 × 3) works the same way,
averaging the five components:
from seamm_md_analysis import (
autocorrelation_functions,
component_helfand_moments,
shear_stress_components,
)
X = shear_stress_components(P) # Pxy, Pxz, Pyz, (Pxx-Pyy)/2, (Pyy-Pzz)/2
acf, integral = autocorrelation_functions(X, m=m)
M = component_helfand_moments(X, m=m)
Multiply by V / (k_B T) and the sampling interval (Green–Kubo), or V dt² / (2 k_B T) (Helfand), to get the viscosity.