This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

vp.liquids.mc_nvt

Metropolis Monte Carlo of Lennard-Jones atoms at constant N, V and T, the potential cut (not shifted) at r_cut. Each step is a sweep: every atom in turn is moved by a random displacement in a cube and the move is accepted with probability min(1, exp(-dU / T)). A run returns the block and run averages of the energy and pressure (for the cut potential, and corrected for the full potential), the configurational temperature, the heat capacity from the energy's fluctuations, the acceptance ratio, the final configuration and, when it samples, g(r).

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_nvt(*, n=256, density=0.75, temperature=1.0, r_cut=2.5, dr_max=0.15, nblock=10, nstep=1000, seed=1, r_start=zeros(0, DIM), box_start=0.0, sample=0, gr_dr=0.02)

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.
dr_max : float, default 0.15
The largest trial displacement along each axis, in sigma. Range: > 0.
nblock : int, default 10
The number of blocks the run is averaged in. Range: >= 1, <= 100000.
nstep : int, default 1000
The sweeps per block (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.
sample : int, default 0
Every this many sweeps, the configuration goes into g(r); 0: none. Range: >= 0, <= 100000000.
gr_dr : float, default 0.02
The bin width of g(r), 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.
rho : float
The number density N / V.
move_ratio : float
The fraction of trial moves accepted.
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 from the block averages.
p_cut : float
The pressure of the cut potential, with the delta correction for the step at r_cut.
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, which should come out at T.
t_config_err : float
Its standard error.
cv_full : float
The heat capacity per atom from the energy's fluctuations, plus 3/2 (the same for the cut and the full potential).
cv_full_err : float
Its standard error.
blocks : ndarray[float64]
The block averages, one row per block, columns move_ratio, e_cut, p_cut, e_full, p_full, t_config, cv_full (rank 2).
initial : ndarray[float64]
The same seven variables at the start (the first is 0).
energy_series : ndarray[float64]
E_cut after every sweep.
r_final : ndarray[float64]
The final positions (N, 3), in sigma, in the box centered on the origin (rank 2).
gr_r : ndarray[float64]
The midpoints of the g(r) bins, in sigma (empty without sample).
gr : ndarray[float64]
G(r) at those midpoints.

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_nvt(n=108, temperature=1.0, nblock=2, nstep=20)
print(r.e_cut, r.e_cut_err, r.p_cut, r.move_ratio)
assert r.check()
-3.602077766485601 0.07702054409382009 -0.9085332607154094 0.4481481481481482

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
mc_nvt_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