3. LJ cluster — heat capacity¶
The same 8 atoms as 4. LJ periodic — NPT, with the cell dropped. No periodic
images, no pressure, no volume/shear/stretch moves — just a cluster in
vacuum and the classic nested-sampling question: what does its heat capacity
look like? Finishes in well under a minute, even on a CPU.
The config¶
examples/tutorials/02_lj_cluster/config.yaml:
# 8-atom Lennard-Jones cluster in vacuum, NVT.
#
# The same 8 atoms as 03_lj_npt, with the cell dropped: no periodic images,
# no pressure, no volume/shear/stretch moves. What is left is the classic
# nested-sampling cluster problem, and its heat capacity -- computed with
# `jaxrens analyze` -- is the point of this tutorial.
#
# Finishes in well under a minute even on a CPU.
#
# Run it with:
# jaxrens validate -c config.yaml --full
# jaxrens run -c config.yaml
run:
n_live: 128
max_iterations: 4000
n_mcmc_steps: 10 # decorrelation per replacement walker
# Walkers MCMC-walked in parallel each iteration is 1 + n_extra, so this
# is the batch width the GPU actually sees. Left at 0 only one chain
# runs and the device idles; it does not change the population size.
n_extra: 15
seed: 42
backend:
type: lj
epsilon: 1.0
sigma: 1.0
cutoff: 2.5
periodic: false # a cluster in vacuum -- no cell, no images
ensemble:
type: nvt # no cell, so no P*V term to speak of
moves:
# One move is the whole sampler: no cell means no volume / shear /
# stretch, since there is nothing for them to act on.
- {type: gmc, n_reflect: 6, step_size: 0.1, weight: 1.0}
termination:
- type: prior_mass
threshold: 1.0e-3
adaptation:
full_auto: true
adjust_interval: 50
defaults: {min_rate: 0.3, max_rate: 0.5, adjust_factor: 1.5, step_size_max: 0.5}
init:
start_species: "18 8" # 8 argon atoms
random_initialise_pos: true
pos_randomization_mode: grid
grid_distance: 1.0
random_initialise_cell: false
initial_walk: {n_walks: 3, walklength: 20, adjust_interval: 1, emax_offset_per_atom: 1.0}
cell:
# Not sampled: it only bounds where the initial positions are drawn from.
max_volume_per_atom: 24.0
min_volume_per_atom: 16.0
min_aspect_ratio: 0.6
output:
format: extxyz
working_dir: ./output
out_file_prefix: lj8cluster
info_interval: 200
traj_interval: 1 # every dead point -- the thermodynamics need them
checkpoint_interval: 4000
Two things changed relative to 4. LJ periodic — NPT, and everything else follows from them:
backend.periodic: false means there are no periodic images and no
supercell_trafo to tune — the cell: block still exists, but only to bound
where the initial 8 atoms are drawn from. It is never sampled.
ensemble.type: nvt drops the P·V term, which is what makes volume,
shear and stretch pointless here: with no cell to act on, a single
gmc move is the whole sampler.
1. Run it¶
cd examples/tutorials/02_lj_cluster
jaxrens validate -c config.yaml --full
jaxrens run -c config.yaml
tail -f lj8cluster.log # from a second shell; `run` prints nothing
Starting NS run: 128 walkers, 8 atoms, max_iter=4000, n_mcmc=10
iter=0 Emax=7.66511 log_Z=-12.5171 dt=4.2s nE=6.42e+03 nG=6.42e+03
iter=200 Emax=-2.02892 log_Z=0.8851 dt=0.5s nE=2.14e+05 nG=2.14e+05
iter=200 T_est=9904.120 K
iter=600 Emax=-3.75971 log_Z=1.6527 dt=0.3s nE=6.10e+05 nG=6.10e+05
iter=1000 Emax=-5.45988 log_Z=1.7730 dt=0.3s nE=1.00e+06 nG=1.00e+06
iter=1600 Emax=-7.62947 log_Z=1.8001 dt=0.4s nE=1.60e+06 nG=1.60e+06
NS terminated at iter 1663: Prior mass negligible compared to evidence
NS complete: 1664 dead points, log_Z=1.8022
NS finished: 1664 iterations, log_Z=1.8022, elapsed=7s
Two differences from the NPT run worth noticing. First, this one terminates
itself at iteration 1663 instead of running to max_iterations=4000 — the
prior_mass criterion fires once the remaining prior volume is too small to
move log_Z further, and a cluster’s configuration space is small enough
that this happens quickly. Second, elapsed=7s: dropping the cell doesn’t
just remove parameters, it removes an entire class of moves (and their JIT
compilation), which is most of why this finishes faster than the NPT run
despite needing more than three times as many iterations.
2. What you get¶
ls output/
File |
What it holds |
|---|---|
|
the dead-point energy ladder — the input to every thermodynamic estimator |
|
the culled walker at each iteration, ASE-readable |
|
step-size and acceptance traces (one move here: |
|
the restart point |
|
the fully-defaulted config this run actually used |
3. Plot it¶
jaxrens plot output/lj8cluster.energies
jaxrens plot output/lj8cluster.adaptation.h5
The bottom panel is flat: jaxrens plot always draws a volume trail when one
is present in the log, and here it is — just constant, because the cell is
never sampled. That flat line is the NVT/non-periodic story: compare it to
the same panel in 4. LJ periodic — NPT.
One move, one trace: gmc’s acceptance rate settles in the 0.3–0.6 band the
adaptation.defaults block asks for, with the step size shrinking in steps
as the accessible region contracts.
4. Heat capacity: jaxrens analyze¶
Energies and acceptance rates are sampler diagnostics — they tell you the run
behaved. The heat capacity is the physics: jaxrens analyze turns the same
dead-point ladder into a thermodynamic observable by reweighting it at a
sweep of temperatures. The primary output is data, not a picture — T
against the observable, ready for a notebook or a paper plot without a
detour through a PNG. --format csv (the default) writes fixed-width,
right-aligned columns — a CSV meant to actually be read, not just parsed:
jaxrens analyze output/lj8cluster.final.checkpoint.h5 \
--t-min 0.05 --t-max 3.0
Wrote output/lj8cluster.heat_capacity.csv
T, Cv
0.05, 0.44239143
0.064824121, 0.72091224
0.079648241, 0.88485042
...
--format json is the other option — self-describing, and it nests however
many dimensions an observable actually has rather than forcing one row per
temperature, which matters the moment an observable stops being a single
scalar per T (e.g. a per-species heat capacity):
jaxrens analyze output/lj8cluster.final.checkpoint.h5 \
--t-min 0.05 --t-max 3.0 --format json
{
"observable": "heat_capacity",
"column": "Cv",
"prefix": "lj8cluster",
"k_b": 1.0,
"T": [
0.05,
0.06482412060301508,
0.07964824120603016,
...
],
"Cv": [
0.4423914311076833,
0.7209122395837029,
0.8848504158531625,
...
]
}
Add --plot to also render a PNG from the same data, the same way jaxrens plot renders one from an artefact file (works with either --format):
jaxrens analyze output/lj8cluster.final.checkpoint.h5 \
--t-min 0.05 --t-max 3.0 --plot
Wrote output/lj8cluster.heat_capacity.csv
Wrote output/lj8cluster.heat_capacity.png
Unlike jaxrens plot, analyze dispatches on a checkpoint file rather
than a single self-contained artefact: n_live and the live-walker energies
live in lj8cluster.final.checkpoint.h5, but the dead-point energies are in
the sibling lj8cluster.energies — analyze loads both from the same
directory (via Monitor.from_directory under the hood), which is why it
needs no second file argument. There is no default --t-min/--t-max: the
right temperature range depends on the backend’s energy units, so the CLI
asks rather than guesses.
The peak near T ≈ 0.5 is a structural transition — the cluster has more
than one geometrically distinct low-energy arrangement, and around that
temperature the population starts spreading across them instead of sitting
in the single deepest one. --observable also accepts partition_function
(log Z(T)) and free_energy (F(T)), the other two quantities a Monitor
computes from the same dead-point ladder.
Next¶
4. LJ periodic — NPT — the same 8 atoms, with the cell back: periodic images, pressure, and the moves that act on a cell.
Configuration — every key you can put in that YAML.
The nested-sampling loop — what the two loops are actually doing.