vp.liquids.mc_npt
Metropolis Monte Carlo of Lennard-Jones atoms at constant N, P and T, the potential cut (not shifted) at r_cut. Each step is a sweep of trial displacements, one per atom, then one trial change of the box: its side is scaled by exp(zeta db_max), zeta uniform in (-1, 1), every position with it, and the change is accepted with probability min(1, exp(-(dU + P dV) / T + (N + 1) ln(V_new / V))). A run returns the block and run averages of the density, energy and pressure (for the cut potential, and corrected for the full potential), the configurational temperature, the heat capacity at constant pressure from the enthalpy's fluctuations, the volume's fluctuation, the acceptance ratios, the final configuration and box.
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.mc_npt(*, n=256, density=0.75, temperature=1.0, r_cut=2.5, pressure=0.69, dr_max=0.15, db_max=0.025, nblock=10, nstep=1000, seed=1, r_start=zeros(0, DIM), box_start=0.0) Parameters
- n : int, default
256 - The number of atoms, 4 nc^3 for the fcc start (32, 108, 256, 500, 864, ...); ignored when r_start is given. Range: >= 32, <= 100000.
- density : float, default
0.75 - The number density N / V; sets the box side when r_start is not given. Range: > 0.
- temperature : float, default
1.0 - The temperature. Range: > 0.
- r_cut : float, default
2.5 - The potential's cutoff, in sigma; at most half the box. Range: > 0.
- pressure : float, default
0.69 - The pressure.
- dr_max : float, default
0.15 - The largest trial displacement along each axis, in sigma. Range: > 0.
- db_max : float, default
0.025 - The largest trial change of ln(box side). Range: > 0.
- nblock : int, default
10 - The number of blocks the run is averaged in. Range: >= 1, <= 100000.
- nstep : int, default
1000 - The steps per block, each a sweep and a box move (upstream's default is 10000). Range: >= 0, <= 100000000.
- seed : int, default
1 - The seed of the random numbers. Range: >= 0, <= 2147483646.
- r_start : ndarray[float64], default
zeros(0, DIM) - A starting configuration (N, 3), in sigma, instead of the fcc lattice; box_start must come with it. Range: rank 2.
- box_start : float, default
0.0 - The box side of r_start, in sigma. Range: >= 0.
Returns
A frozen MCResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- box : float
- The box side, in sigma.
- move_ratio : float
- The fraction of trial displacements accepted.
- volume_ratio : float
- The fraction of trial box changes accepted.
- density_avg : float
- The mean number density.
- density_err : float
- Its standard error from the block averages.
- e_cut : float
- The energy per atom of the cut (not shifted) potential, with the ideal gas's 3T/2.
- e_cut_err : float
- Its standard error.
- p_cut : float
- The virial pressure of the cut potential with the delta correction; it should come out near the pressure imposed.
- p_cut_err : float
- Its standard error.
- e_full : float
- The energy per atom with the long-range correction: an estimate for the full potential.
- e_full_err : float
- Its standard error.
- p_full : float
- The pressure with the long-range correction.
- p_full_err : float
- Its standard error.
- t_config : float
- The configurational temperature, |F|^2 / lap U.
- t_config_err : float
- Its standard error.
- cp_cut : float
- The heat capacity per atom at constant pressure from the enthalpy's fluctuations, plus 3/2.
- cp_cut_err : float
- Its standard error.
- cp_full : float
- The same with the long-range correction in the enthalpy.
- cp_full_err : float
- Its standard error.
- volume_msd : float
- The mean-square deviation of the volume within a block, averaged over blocks.
- box_final : float
- The final box side, in sigma.
- blocks : ndarray[float64]
- The block averages, one row per block, columns move_ratio, volume_ratio, density, e_cut, p_cut, e_full, p_full, t_config, cp_cut, cp_full, volume_msd (rank 2).
- initial : ndarray[float64]
- The same eleven variables at the start (the first two are 0).
- energy_series : ndarray[float64]
- E_cut after every step.
- box_series : ndarray[float64]
- The box side after every step.
- r_final : ndarray[float64]
- The final positions (N, 3), in sigma, in the box centered on the origin (rank 2).
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.mc_npt(n=256, pressure=0.69, nblock=2, nstep=10)
print(r.density_avg, r.e_cut, r.volume_ratio, r.box_final)
assert r.check() 0.8302591070630576 -4.179699033503689 0.30000000000000004 6.680945057071963Each 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
- mc_npt_lj 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/mc_npt.export.toml
- Viv: ports/liquids/mc_npt.viv
- The defs it reaches and the calls between them: map of the code