================================================================
First NEB band: Berry pseudorotation of a Lennard-Jones pentamer
================================================================
Run a Gaussian-process nudged elastic band (GP-NEB) for five atoms bound by a Lennard-Jones potential.
The trigonal bipyramid exchanges its two axial atoms with two equatorial ones through a square-pyramidal saddle, a Berry pseudorotation.
You write the two endpoints, run one GP-accelerated band and one band on the oracle alone, compare the barrier and the number of oracle calls, and check the energies against the potential.
.. figure:: ../../orgmode/_static/gprn_lj5_profile.png
Energy along the band that gprn returns for the pentamer. The endpoints and the climbing image carry oracle energies, the other images the surrogate's.
Oracle call counts and timings can vary with the build and machine.
What you need
-------------
Set ``GPRIDGE_ROOT`` to the path of your source checkout.
- A built ``gprn``.
The documentation CI builds it with ``bash scripts/install_cbindgen_pixi.sh``, then ``meson setup builddir -Dwith_tests=true -Duse_readcon=true -Duse_anneal=enabled --buildtype=release`` and ``meson compile -C builddir gprn gprd`` (``.github/workflows/docbuilder.yml``, job ``examples``).
The :doc:`Installation page <../getting-started/installation>` lists the other routes.
The commands below call the program as ``gprn``; put ``builddir`` on your ``PATH`` or write ``./builddir/gprn``.
- A build with readcon-db (``-Duse_readcon_db``, default ``auto``, on when the wrap resolves).
The commands below keep the default ``--gp-observation-archive auto``.
Without readcon-db, ``gprn`` prints ``--gp-observation-archive requested but this build has no readcon-db`` and exits with status 2.
Add ``--gp-observation-archive off`` to every command if your build lacks it.
- `uv `_ for the Python binding example and the plots.
The scripts declare their dependencies inline.
- Some familiarity with ``gprn``.
The :doc:`quickstart <../getting-started/quickstart>` explains the log lines using the same cluster and prepared endpoint files.
Work in a fresh directory:
.. code:: bash
mkdir -p lj-pentamer
cd lj-pentamer
Step 1: check the build
-----------------------
.. code:: bash
gprn --list-potentials | grep -E '^lj[[:space:]]'
The command prints one row, ``lj`` with the backend ``compiled``, when this binary has the Lennard-Jones oracle built in.
If the shell reports that ``gprn`` is not found, put the build directory on ``PATH``.
Step 2: use the two supplied endpoints
--------------------------------------
The reactant is the relaxed bipyramid with its axis along :math:`z`; the product is the same bipyramid with its axis along :math:`y`, after atoms 0 and 1 have moved into the equatorial plane and atoms 3 and 4 onto the axis.
Atom 2 is the pivot and stays put.
The oracle is a 12-6 Lennard-Jones potential with :math:`\epsilon = 1` eV and :math:`\sigma = 1` Angstrom for every pair, shifted to zero at a 15 Angstrom cutoff (the defaults in ``subprojects/rgpot/CppCore/rgpot/LennardJones/LJPot.hpp``).
The element label is therefore arbitrary for the oracle.
The files use Ne.
The label does reach ``gprn``'s element-dependent settings, so the call counts below belong to Ne labels.
Labelling the same atoms Ar also converges (``ArgonPentamerAcquiresAndConverges`` in ``tests/gpr/GprnLennardJonesTest.cpp`` asserts it).
In the run that checked this page, Ar labels gave a barrier of 0.623209 eV and took 28 oracle calls instead of 17.
The repository includes both endpoints as CON files.
GPRidge reads them through ReadCon.
The 30 Å cell gives the cluster room on every side, and all five atoms can move.
.. code:: bash
examples="$GPRIDGE_ROOT/examples/lj-pentamer"
cp "$examples/reactant.con" "$examples/product.con" .
Step 3: run the GP-accelerated band
-----------------------------------
``--potential lj`` selects the Lennard-Jones oracle.
``--nimages 7`` puts seven movable images between the endpoints, a band of nine.
``--gp-model-profile gprd_zbl`` selects the GP model profile that the published UMA Baker runs use; the default is ``extended``.
``--output gp/neb.h5`` names the HDF5 result, and because ``--gp-observation-archive`` defaults to ``auto``, the archive of every oracle evaluation goes to ``gp/obs-archive``, next to it.
``--write-con`` stores the final band, one frame per image with its energy in the frame header.
.. code:: bash
mkdir -p gp
gprn --reactant reactant.con --product product.con \
--potential lj --nimages 7 --gp-model-profile gprd_zbl \
--output gp/neb.h5 --write-con gp/band.con > gp/gprn.log 2>&1
grep -E '^(Oracle calls:|Barrier energy|Converged:|Certified:|Outer relaxation iterations)' gp/gprn.log
awk '/^Barrier energy/ { b = $4 } END { exit !(b > 0.622 && b < 0.625) }' gp/gprn.log
The run on the machine that produced this page took 11 to 14 s and printed
::
Outer relaxation iterations: across 1 attempt(s)
Oracle calls: (neb=, dimer=0, certificate=0, transition=0)
Barrier energy (eV): (forward: E_saddle - E_reactant)
Converged: yes
Certified: yes
The IRC certificate file is written by the rgmin connectivity walk.
.. code:: bash
test -f gp/obs-archive/irc_certificate.txt
The ``awk`` line asserts the barrier to 1e-3 eV around 0.6232 eV, the tolerance that ``tests/gpr/GprnLennardJonesTest.cpp`` uses for this system.
The lines mean:
- ``Oracle calls`` counts evaluations of the Lennard-Jones potential: 2 for the endpoints and 15 chosen by the search.
This count is the cost the surrogate tries to minimise.
- ``Barrier energy`` is the energy of the highest image above the reactant, evaluated on the oracle.
- ``Converged: yes`` says that the true force on the climbing image fell below ``--converged-force`` (0.05 eV/Angstrom by default).
- ``Certified: yes`` says that the IRC certificate (``--irc-certificate``, on by default) walked downhill from the saddle in both directions and reached the reactant and the product.
The record is in ``gp/obs-archive/irc_certificate.txt``, and the log line ``IRC certificate record:`` prints its path.
See :doc:`Saddle-point certificates <../explanation/irc_certificate>` for what the check tests.
The exit status follows the same rule: ``gprn`` exits with 0 when the search converged (or when ``--max-iterations 0`` requested band setup only, which builds the initial band without relaxing it, skips the IRC walk and logs ``setup only (max-iterations 0): band built, not relaxed``) and the oracle stencil check, if requested, passed, with 2 when it did not (also when the observation archive is misconfigured), and with 1 on an error such as an unreadable input file or a negative ``--max-iterations``.
A job script can branch on it.
Wall time says little here.
The log's ``Oracle time`` line reports the oracle's share of the run, which is far below a millisecond for 17 Lennard-Jones evaluations, so almost all of the 11 to 14 s is the surrogate.
The saving appears with an oracle that costs seconds per call.
The log also carries a line ``Band discretization certificate: FAILS`` with a leak and a residual.
It compares the chord-discretisation leak and the chord-perpendicular residual at the climbing image's neighbours with the force tolerance.
The run above printed ``FAILS`` and still ended ``Converged: yes`` and ``Certified: yes``, because the leak is only a requirement with ``--band-leak-bound true`` (default false).
Step 4: compare with a true-force band
--------------------------------------
``--nebmode standard`` runs the same band with the oracle alone, no surrogate.
It gets its own directory.
A run adopts the rows that are already in the observation archive next to its ``--output`` file, so a second run in ``gp/`` would start from the first run's points and its call count would no longer be a cost.
In the run that checked this page, the standard band took 86 calls in ``gp/`` and 93 in a fresh directory.
.. code:: bash
mkdir -p standard
gprn --reactant reactant.con --product product.con \
--potential lj --nimages 7 --nebmode standard \
--output standard/neb.h5 --write-con standard/band.con \
> standard/gprn.log 2>&1
grep -E '^(Oracle calls:|Barrier energy|Converged:)' standard/gprn.log
gp=$(sed -n 's/^Oracle calls: \([0-9]*\) .*/\1/p' gp/gprn.log)
std=$(sed -n 's/^Oracle calls: \([0-9]*\) .*/\1/p' standard/gprn.log)
test "$gp" -lt "$std"
awk '/^Barrier energy/ { b = $4 } END { exit !(b > 0.622 && b < 0.625) }' standard/gprn.log
::
Oracle calls: 93 (neb=93, dimer=0, certificate=0, transition=0)
Barrier energy (eV): 0.623232 (forward: E_saddle - E_reactant)
Converged: yes
The two barriers differ by 5e-6 eV.
The GP band asked the oracle 17 times, the true-force band 93 times.
The block asserts that the GP band used fewer calls and that both barriers lie within 1e-3 eV of 0.6232 eV.
The ``Search time:`` line of ``standard/gprn.log`` reads under 0.01 s against 12 s for the GP band: a Lennard-Jones call costs microseconds, so the surrogate is overhead here and the saving is in calls only.
Run the same reaction through a binding
---------------------------------------
Choose Python, C++, C or Fortran.
Each program runs both bands with the same endpoints and force tolerance, keeps all nine images, checks a forward barrier of 0.6232 eV within 1 meV, and verifies that the GP band uses fewer oracle calls.
The bindings use the analytical Lennard-Jones function, with gradients converted to forces at the oracle boundary.
The CLI uses a cutoff with a constant energy shift.
All ten pairs stay within that cutoff, so the shift cancels in the barrier.
The Python tab opens both CON files with ReadCon.
For the native examples, use the same ReadCon reader to prepare a coordinate stream.
Each output line contains one atom's coordinate triplet in Å.
.. code:: bash
uv run --script - "$GPRIDGE_ROOT/examples/lj-pentamer" > endpoints.dat <<'PY'
# /// script
# requires-python = ">=3.11"
# dependencies = ["numpy", "readcon-chemfiles>=0.23.2,<0.24"]
# ///
import sys
from pathlib import Path
import numpy as np
import readcon
examples = Path(sys.argv[1])
for name in ("reactant.con", "product.con"):
frame = readcon.read_first_frame(str(examples / name))
np.savetxt(sys.stdout, frame.coords_array().reshape(-1, 3))
PY
The Python tab uses ``uv`` to install the Python package for the script.
The native tabs use the installed shared library and its ``pkg-config`` file.
The C and C++ programs check ``GPR_ABI_CHECK()`` against ``GPR_SUCCESS``.
Fortran makes the same check through ``gpr_check_abi``.
See :doc:`Installation <../getting-started/installation>` for both.
The source files are in `examples/lj-pentamer `_.
.. tab-set::
:sync-group: gpridge-language
.. tab-item:: Python
:sync: python
.. code-block:: bash
sample="$GPRIDGE_ROOT/examples/lj-pentamer"
uv run --script "$sample/band.py" "$sample/reactant.con" "$sample/product.con"
.. literalinclude:: ../../../examples/lj-pentamer/band.py
:language: python
.. tab-item:: C++
:sync: cpp
.. code-block:: bash
c++ -std=c++20 "$GPRIDGE_ROOT/examples/lj-pentamer/band.cpp" \
$(pkg-config --cflags --libs gpridge) -o band
./band < endpoints.dat
.. literalinclude:: ../../../examples/lj-pentamer/band.cpp
:language: cpp
.. tab-item:: C
:sync: c
.. code-block:: bash
cc -std=c11 "$GPRIDGE_ROOT/examples/lj-pentamer/band.c" \
$(pkg-config --cflags --libs gpridge) -o band
./band < endpoints.dat
.. literalinclude:: ../../../examples/lj-pentamer/band.c
:language: c
.. tab-item:: Fortran
:sync: fortran
.. code-block:: bash
gfortran "$GPRIDGE_ROOT/fortran/gpridge.f90" \
"$GPRIDGE_ROOT/examples/lj-pentamer/band.f90" \
$(pkg-config --libs gpridge) -o band
./band < endpoints.dat
.. literalinclude:: ../../../examples/lj-pentamer/band.f90
:language: fortran
All four programs write ``gp.dat`` and ``standard.dat``.
Each row holds an image's energy in eV followed by its 15 Cartesian coordinates in Å.
Run one tab per working directory to retain the results from multiple languages.
In one run all four bindings reported 0.6232 eV and 93 oracle calls for the standard band and 0.6227 eV and 13 calls for the GP band.
Step 5: plot the band
---------------------
ChemParsePlot draws the 1D energy profile and colors the 2D trajectory by energy.
RgPyCrumbs computes the two interatomic distances used in the 2D view.
At the reactant, atoms 0 and 1 occupy the axial sites.
At the product, atoms 3 and 4 occupy them.
Using those two distances keeps the atom identities visible as the pairs exchange roles.
The 2D panel shows the sampled band in these coordinates.
The plot script declares its dependencies inline.
``uv`` resolves them when the script runs, including the ``readcon`` import supplied by ``readcon-chemfiles``.
.. code:: bash
MPLBACKEND=Agg uv run --script "$GPRIDGE_ROOT/examples/lj-pentamer/plot_band.py" gp/band.con --output figures
From any of the four binding examples, pass ``gp.dat`` in place of ``gp/band.con``.
To plot the standard band, pass ``standard.dat`` or ``standard/band.con`` and give it a different output directory.
The script writes ``profile.png`` and ``path-2d.png``.
.. figure:: ../../orgmode/_static/gprn_lj5_path_2d.png
The first and last points are the equivalent trigonal bipyramids. The distance between each numbered pair shows how the two pairs exchange axial sites through the saddle.
The endpoints and climbing image carry oracle energies in the GP band.
The other six are the surrogate's estimates.
ReadCon supplies the geometries to ASE, which independently evaluates the three oracle energies with the same shifted Lennard-Jones potential.
.. code:: python
import readcon
from ase.calculators.lj import LennardJones
calculator = LennardJones(epsilon=1.0, sigma=1.0, rc=15.0)
for frame in readcon.read_con("lj-pentamer/gp/band.con"):
role = frame.metadata["role"]
if role in ("reactant", "climbing", "product"):
atoms = frame.to_ase()
atoms.pbc = False
atoms.calc = calculator
direct = atoms.get_potential_energy()
print(f"{role:9s} stored {frame.energy:.6f} direct {direct:.6f} eV")
assert abs(frame.energy - direct) < 1e-6
The reactant energy of −9.1038 eV is the bipyramid's.
The climbing image at −8.4806 eV is the square pyramid, 0.6232 eV above it.
What to try next
----------------
- :doc:`Use GPRidge with the SciMap tools <../howto/scimap>` follows the band from the oracle to analysis and plotting.
- :doc:`Run a GP-NEB band <../howto/gpneb>` covers the acquisition and trust options that decide which image the oracle evaluates next.
- :doc:`The command-line reference <../reference/cli_reference>` lists every ``gprn`` flag, and :doc:`the TOML keys <../reference/config_keys>` give the same settings in a file.
- :doc:`The first GP dimer search ` refines a saddle from Python.
- :doc:`The UMA HCN band ` runs the same driver with a machine-learned potential.