A periodic Pt(111) Morse band¶
This tutorial relaxes a band for a seven-atom platinum island (a heptamer) on a Pt(111) slab, with GPLocalBand.
The cell is periodic, the lower layers are fixed, and the oracle is the Morse pair potential with platinum parameters, evaluated through ASE.
The result is a barrier in eV and the number of oracle calls it took, which the page checks against the recorded campaign for the same endpoints.
The search runs in a few seconds.
What you need¶
The Python bindings of
gpridge, ASE 3.23 or newer and thereadconpackage. See Installation.GPLocalBand.from_conreads the CON files withreadcon.A clone of the repository. The endpoints are the files in
paper/jcim/records/periodic/inputs/heptamer/. The first block reads the environment variableGPRIDGE_ROOTfor the clone and falls back to the current directory, so run the page from the repository root or set the variable.
The system¶
The endpoints are reactant.con and product.con.
The block reads them with readcon and checks what the rest of the page assumes: 343 Pt atoms in a periodic cell, the three lowest layers fixed, and a hop of a few atoms between the endpoints.
import os
from pathlib import Path
import numpy as np
import readcon
root = Path(os.environ.get("GPRIDGE_ROOT", Path.cwd()))
campaign = root / "paper" / "jcim" / "records" / "periodic"
inputs = campaign / "inputs" / "heptamer"
assert inputs.is_dir(), "run from the repository root or set GPRIDGE_ROOT"
reactant = readcon.read_first_frame(str(inputs / "reactant.con")).to_ase()
product = readcon.read_first_frame(str(inputs / "product.con")).to_ase()
fixed = reactant.constraints[0].index
moved = np.linalg.norm(product.positions - reactant.positions, axis=1) > 0.1
print(len(reactant), reactant.cell.cellpar()[:3], len(fixed), moved.sum())
assert set(reactant.get_chemical_symbols()) == {"Pt"}
assert len(reactant) == 343 and reactant.pbc.all()
assert len(fixed) == 168 and not np.isin(np.flatnonzero(moved), fixed).any()
assert moved.sum() == 11
343 [19.2088 19.0118 30. ] 168 11
The cell is 19.2088 x 19.0118 x 30 Å.
168 atoms are fixed and 175 are free, and 11 atoms move by more than 0.1 Å between the two endpoints.
The CON files carry the cell, the periodicity and the fixed-atom flags, which from_con passes on to the band.
The oracle¶
from ase.calculators.morse import MorsePotential
depth, range_per_a, minimum, cutoff = 0.7102, 1.6047, 2.897, 9.5
oracle = MorsePotential(
epsilon=depth,
rho0=range_per_a * minimum,
r0=minimum,
rcut1=(cutoff - 0.5) / minimum,
rcut2=cutoff / minimum,
)
The numbers are the platinum parameters of the Morse potential in rgpot, the potential behind gprn --potential morse: well depth 0.7102 eV, range 1.6047 1/Å, minimum at 2.897 Å and cutoff 9.5 Å (subprojects/rgpot/CppCore/rgpot/Morse/MorsePot.hpp).
ASE writes the same Morse function with the range as rho0 = a * r0, so rho0 is the range times the minimum distance.
It takes the two cutoff radii as multiples of r0.
ASE smooths the pair term to zero between rcut1 and rcut2.
The rgpot potential instead truncates at 9.5 Å with an energy shift, so the two implementations give slightly different energies and barriers.
The band¶
GPLocalBand keeps the atoms that both endpoints fix and moves the rest.
n_images is the number of images between the endpoints, so the band has 10 geometries.
norm”l2”= makes fmax bound the Euclidean norm of the band force on the moving atoms.
from gpridge import GPLocalBand
band = GPLocalBand.from_con(
inputs / "reactant.con",
inputs / "product.con",
oracle,
n_images=8,
)
converged = band.run(fmax=0.01, steps=400, norm="l2")
relative = band.energies - band.energies[0]
print(converged, band.oracle_calls, f"{band.barrier:.4f} eV")
print(np.round(relative, 3))
assert converged
assert len(band.energies) == 10 and band.max_energy_image == 4
assert abs(relative.max() - band.barrier) < 1e-9
assert abs(relative[band.max_energy_image] - band.barrier) < 1e-9
True 20 0.5897 eV
[ 0. 0.088 0.296 0.504 0.59 0.534 0.384 0.198 0.047 -0.012]
band.oracle_calls counts every true energy and force evaluation of the run: the two endpoints, the outer iterations and the final validation of the band.
band.energies holds the energy of every geometry in eV, so subtracting the first gives the profile above.
band.barrier is the highest energy minus the reactant energy, and band.max_energy_image is the index of that geometry (counting the reactant as 0).
The product lies 0.012 eV below the reactant.
Check against the campaign record¶
The repository holds the result of the same search for these endpoints, run with gprn.
heptamer/band.con is the converged band from that run, one frame per geometry with its energy.
rerun/pt_rerun_raw.csv lists the calls and the barrier of the gp_local search and of a true-force climbing-image NEB (ci_neb) for the same start, which the table names min01.
The block compares the two.
import csv
energies = [frame.energy for frame in
readcon.ConTrajectory(str(campaign / "heptamer" / "band.con"),
write_index=False)]
recorded_barrier = max(energies) - energies[0]
with open(campaign / "rerun" / "pt_rerun_raw.csv") as handle:
rows = {row["method"]: row for row in csv.DictReader(handle)
if row["set"] == "heptamer" and row["start"] == "min01"}
gp_local, ci_neb = rows["gp_local"], rows["ci_neb"]
print(f"recorded gp_local: {gp_local['calls']} calls, "
f"{float(gp_local['barrier_eV']):.4f} eV; band.con: {recorded_barrier:.4f} eV")
print(f"recorded ci_neb: {ci_neb['calls']} calls, "
f"{float(ci_neb['barrier_eV']):.4f} eV")
print(f"this run: {band.oracle_calls} calls, {band.barrier:.4f} eV, "
f"difference {abs(band.barrier - recorded_barrier):.4f} eV")
assert abs(recorded_barrier - float(gp_local["barrier_eV"])) < 1e-5
assert abs(band.oracle_calls - int(gp_local["calls"])) <= 5
assert abs(band.barrier - recorded_barrier) < 0.005
assert int(ci_neb["calls"]) > 10 * band.oracle_calls
recorded gp_local: 20 calls, 0.5887 eV; band.con: 0.5887 eV
recorded ci_neb: 442 calls, 0.5887 eV
this run: 20 calls, 0.5897 eV, difference 0.0011 eV
The Python run uses 20 calls, as the recorded gprn run does, against 442 for the true-force CI-NEB.
The barrier from the Python run is 0.0011 eV above the recorded one, small next to the barrier itself.
The two runs use different Morse implementations (see above) and are separate entry points (GPLocalBand and gprn), so the page does not claim an exact match.
The assertions allow 5 calls and 0.005 eV to absorb differences between builds.
The same search from the command line¶
gprn reads the Morse parameters from a TOML file passed with --config.
The file below is the one the OptBench Pt(111) runs write, as quoted in tests/gpr/potentials/PtMorseTomlTest.cpp.
The keys of [oracle.parameters] are the fields of the rgpot PotentialConfig schema; see TOML configuration keys.
[oracle]
potential = "morse"
[oracle.parameters.morse]
de = 0.7102
a = 1.6047
re = 2.897
cutoff = 9.5
The command-line flags are in the gprn reference, and the GP-NEB how-to and the local-band explanation describe the gp_local mode this band uses.
Limits of this example¶
band.certifiedisFalseafter this run. The first-order-saddle index certificate of the band is off by default inGPLocalBand. Passingforce_stop_certificate=Trueto the constructor turns it on. The certificate measures a finite-difference stencil at the highest image, and those evaluations are counted inband.n_certificate_callsand are included inband.oracle_calls. When this page was written, the same run with the certificate on made 1070 oracle calls, 1050 of them for the certificate, and setband.certifiedtoTruewithband.indexequal to 1. That is too slow for a page that runs in the documentation build.GPLocalBandreadsFixAtomsconstraints only and raisesValueErrorfor any other constraint.