vp.liquids.diffusion
Time correlation functions of a trajectory and the diffusion coefficient they give: the velocity autocorrelation function <v(0) . v(t)>, the mean-square displacement <|r(t) - r(0)|^2> and the cross-correlation <v(0) . (r(t) - r(0))>, each averaged over atoms and over time origins spaced along the trajectory. Positions are unfolded across the periodic boundaries frame by frame.
Part of the distribution vipyr-liquids; it runs from a checkout of the
repository. Planned on PyPI as pip install vipyr-liquids.
Signature
vp.liquids.diffusion(*, n=2, box=4.0, delta=0.05, frames_r=..., frames_v=..., nt=20, origin_interval=5) Parameters
- n : int, default
2 - The atoms in each frame. Range: >= 1, <= 1000000.
- box : float, default
4.0 - The box side, in sigma. Range: > 0.
- delta : float, default
0.05 - The time between frames. Range: > 0.
- frames_r : ndarray[float64], default
ballistic_frames(41, 0.05, 4.0) - The positions of every frame one after another, (frames x n, 3), in sigma, each inside the box; by default two atoms crossing the box at constant velocity for 41 frames. Range: rank 2.
- frames_v : ndarray[float64], default
ballistic_frames(41, 0.05, 4.0) - The velocities of every frame, the same shape. Range: rank 2.
- nt : int, default
20 - The functions run over 0 to nt frames apart. Range: >= 1, <= 1000000.
- origin_interval : int, default
5 - A time origin every this many frames. Range: >= 1, <= 1000000.
Returns
A frozen DiffusionResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- vacf : ndarray[float64]
- <v(0) . v(t)> per atom at 0 to nt frames apart.
- rvcf : ndarray[float64]
- <v(0) . (r(t) - r(0))> per atom.
- msd : ndarray[float64]
- <|r(t) - r(0)|^2> per atom.
- time : ndarray[float64]
- The times, 0 to nt delta.
- d_vacf : float
- D as one third of the integral of the VACF over the range (trapezoids).
- d_msd : float
- D as one sixth of the slope of the MSD over the second half of the range (least squares).
Raises
- vipyr.ParameterError
- A ValueError: an argument outside its range, choices, rank or shape, or one of a group given without the rest; its .param names the argument.
- TypeError
- An argument of the wrong type, or an unknown keyword.
- vipyr.VivBuildError
- An ImportError: no C compiler, or the program's C does not build.
- RuntimeError
- The program stops with its own message (a combination it rejects, or no convergence where the program treats that as an error).
Examples
import vipyr as vp
r = vp.liquids.diffusion() # two atoms moving at constant velocity
print(r.vacf[:3], r.msd[:3])
assert r.check() [0.625 0.625 0.625] [0. 0.0015625 0.00625 ]Each example ran as written when these pages were generated, and the output shown is what it printed.
Checked against
- Tests
- ports/liquids/test_liquids.py: every tolerance is stated beside its check
- Upstream
- diffusion of https://github.com/Allen-Tildesley/examples at 4818bc82, built with gfortran -O2 by ports/liquids/oracle/build.py; same bits from the same start and random numbers
Credits
- A port of the examples of Allen and Tildesley's Computer Simulation of Liquids, which are CC0-1.0.
Source
- Manifest: ports/liquids/diffusion.export.toml
- Viv: ports/liquids/diffusion.viv
- The defs it reaches and the calls between them: map of the code