============= UMA HCN dimer ============= This tutorial runs ``gprd``, the single-ended GP dimer, on the HCN to HNC saddle with the UMA-S-1.1 potential. A dimer needs a start near the saddle and a rough direction of the unstable mode. Both come from a band, so the page takes them from the band of :doc:`the UMA HCN band tutorial `. The page has the same three parts as that tutorial. Steps 1 and 3 need only this repository and run in the documentation test. Step 2 calls UMA and is gated on ``GPRIDGE_UMA_MODEL``; the test skips it when the variable is unset. No UMA run is part of the test, and the repository holds no recorded ``gprd`` run for HCN, so this page states no dimer call count. What you need ------------- - The UMA setup of the band tutorial: a ``gprd`` built with ``-Duse_rgpot_uma=true`` and ``-Duse_capnp=true``, the engine's libraries on ``LD_LIBRARY_PATH``, and the ``01_hcn.pt2`` package. ``build_uma.sh`` builds ``gprn`` and the engine; add ``gprd`` to the same build tree with ``ninja -C build-uma gprd``. The "What you need" section of :doc:`the band tutorial ` gives the commands and the license note. Set ``GPRIDGE_UMA_MODEL`` to the package. - A band. The page uses the band the published run wrote, which the repository keeps as ``paper/jcim/records/band/hcn/band.con``. To use your own band from the band tutorial, set ``BAND`` to its ``band.con``. Step 1: a start and a direction from the band --------------------------------------------- The dimer reads one structure (``--pos``) and one orientation file (``--orient``). The orientation file has one row of ``dx dy dz`` per atom; ``gprd`` normalises it. Without the file ``gprd`` starts from a random direction. The band's highest image has already been converged to the band tolerance. ``gprd`` measures its true force, finds it below the tolerance, and returns after that one evaluation. The block therefore starts at the image before the highest, so the dimer has a short walk to make, and takes the direction from the neighbours of that image: the difference between the next and the previous image. .. code:: bash uv run --script - "${BAND:-$GPRIDGE_ROOT/paper/jcim/records/band/hcn/band.con}" <<'PY' # /// script # requires-python = ">=3.11" # dependencies = ["numpy", "readcon-chemfiles>=0.23.2,<0.24"] # /// import sys import numpy as np import readcon band = readcon.read_con(sys.argv[1]) energy = np.array([frame.energy for frame in band]) top = int(energy.argmax()) start = top - 1 print(f"{len(band)} frames; highest frame {top}; dimer starts at frame {start}") left, here, right = band[start - 1 : start + 2] readcon.write_con("pos.con", [here], precision=12) direction = right.coords_array() - left.coords_array() np.savetxt("direction.dat", direction.reshape(-1, 3), fmt="%.8f") print(f"energy of frame {start}: {energy[start]:.6f} eV, " f"highest {energy[top]:.6f} eV") PY test -s pos.con -a -s direction.dat cat direction.dat :: 20 frames; highest frame 7; dimer starts at frame 6 energy of frame 6: -2540.622785 eV, highest -2540.400241 eV 0.03751052 0.19281265 -0.00001693 0.17733732 -0.14323088 0.00000264 -0.21484784 -0.04958178 0.00001429 ``pos.con`` is the image's structure with the cell of the band file, which is :math:`0 \times 0 \times 0` Angstrom, no cell. The three rows of ``direction.dat`` are the displacement, in Angstrom, of the carbon, nitrogen and hydrogen atoms between the images on either side. The numbers above are those of the recorded band. With your own band the frame numbers and values differ. Step 2: the dimer ----------------- - ``--pos`` and ``--orient`` name the two files of step 1. - ``--potential uma`` with ``--model``, ``--device cpu``, ``--task-name omol``, ``--uma-charge 0`` and ``--uma-spin 1`` selects UMA for neutral, closed-shell HCN, as in the band tutorial. - ``--gp-nonperiodic true`` treats the molecule as isolated and excludes rigid rotations from the dimer's search directions. - ``--converged-force 0.0514221`` ends the search when the true force norm falls below 0.0514221 eV/Angstrom, the tolerance of the band. - ``--force-stop-certificate true`` measures one Cartesian stencil at the converged midpoint and accepts it only as a first-order saddle; a higher-order point is refined or left along its extra negative mode. Without it the dimer's own stencil still refuses a force stop near a minimum or a higher-order saddle, but ends there. The stencil costs two evaluations per Cartesian coordinate plus the centre: 19 for the three atoms of HCN. ``--vibrational-stencil vibrational`` measures the four vibrations of this linear molecule, 9 calls, and can call a borderline mode resolved where the full stencil leaves it unresolved. .. code:: bash test -s "$GPRIDGE_UMA_MODEL" gprd --pos pos.con --orient direction.dat \ --potential uma --model "$GPRIDGE_UMA_MODEL" \ --device cpu --task-name omol --uma-charge 0 --uma-spin 1 \ --gp-nonperiodic true \ --converged-force 0.0514221 --force-stop-certificate true \ > gprd.log 2>&1 grep -E '^(Converged:|Saddle energy \(eV\)|Oracle calls|Cartesian saddle certificate|Final midpoint (force norm|curvature))' gprd.log ``gprd`` exits with status 0 when the search converged and 1 otherwise, so the block fails on a run that did not converge. ``--irc-certificate`` is a ``gprn`` flag and ``gprd`` does not take it. The Cartesian stencil is the saddle check of the dimer; ``--dimer-index-recovery`` (default true) controls what the search does when that check finds a higher-order point. Step 3: read the result ----------------------- The lines of the log mean: - ``Converged: yes`` says the true force norm fell below ``--converged-force``. - ``Saddle energy (eV)`` is the absolute energy of the saddle. The ``Final midpoint energy`` line is relative to the first evaluation. - ``Oracle calls (dimer total)`` counts the evaluations of the search, and ``Oracle calls (certificate)`` the stencil's. - ``Cartesian saddle certificate: first_order=1 higher_order=0`` says the stencil found one negative mode and no second one. ``negative_upper`` is an upper bound on the lowest curvature, and a value below zero fixes that mode as negative. ``positive_lower`` is a lower bound on the other curvatures, and a value above zero rules out a second negative mode. - ``Final midpoint curvature`` is the curvature along the dimer direction. A negative value says the point is a maximum along that direction. ``gprd`` prints the final geometry as ``Final midpoint coordinates``, in Angstrom, and keeps the observations it measured in ``obs-archive``, next to ``pos.con``. To start the dimer from the observations of a band instead of from an empty training set, pass that band's archive with ``--gp-seed-archive``. The published band of the repository holds the saddle that the band run found, as ``paper/jcim/records/band/hcn/saddle.con``. The block below prints its bond lengths with those of the endpoints. It also converts the ``Final midpoint coordinates`` of a ``gprd.log`` into bond lengths, which is the comparison to make with your result. .. code:: bash cat > saddle_bonds.py <<'EOF' # /// script # requires-python = ">=3.11" # dependencies = ["ase", "numpy", "readcon-chemfiles>=0.23.2,<0.24"] # /// import sys from pathlib import Path import numpy as np import readcon def bonds(atoms): labels = atoms.get_chemical_symbols() pairs = [(0, 1), (0, 2), (1, 2)] return ", ".join(f"{labels[a]}-{labels[b]} {atoms.get_distance(a, b):.3f}" for a, b in pairs) + " Angstrom" def from_log(path): atoms = readcon.read_first_frame("pos.con").to_ase() text = path.read_text() block = text.split("Final midpoint coordinates", 1)[1].split("\n", 1)[1] positions = block.split("End of final midpoint coordinates", 1)[0] atoms.positions = np.loadtxt(positions.splitlines()) return atoms for arg in sys.argv[1:]: path = Path(arg) atoms = (from_log(path) if path.suffix == ".log" else readcon.read_first_frame(str(path)).to_ase()) print(f"{path.name}: {bonds(atoms)}") EOF uv run --script saddle_bonds.py "$GPRIDGE_ROOT/paper/jcim/records/band/hcn/saddle.con" \ "$GPRIDGE_ROOT/bench_data/baker/endpoints-irc/01_hcn/reactant.con" \ "$GPRIDGE_ROOT/bench_data/baker/endpoints-irc/01_hcn/product.con" :: saddle.con: C-N 1.178, C-H 1.187, N-H 1.409 Angstrom reactant.con: C-N 1.144, C-H 1.067, N-H 2.211 Angstrom product.con: C-N 1.163, C-H 2.160, N-H 0.997 Angstrom The saddle is the structure with the hydrogen atom bridging the carbon and the nitrogen atom, 1.19 Angstrom from the carbon and 1.41 Angstrom from the nitrogen. Run the script on your result and compare: .. code:: bash uv run --script saddle_bonds.py gprd.log The saddle energy of the recorded band is -2540.400241 eV, the energy of its highest frame (step 1). A converged dimer on the same potential should land on the same stationary point, so its ``Saddle energy (eV)`` and its bond lengths should be close to these values. The two searches end at different force residuals, so they do not agree to the last digit. What to try next ---------------- - :doc:`The first gprn band <../tutorials/gprn_lj_pentamer>` explains the band side of the workflow without a model file. - :doc:`Get an IRC certificate for a saddle <../howto/irc_certificate>` shows the ``gprn`` check that connects a saddle to its endpoints, which the dimer does not run. - :doc:`The command-line reference <../reference/cli_reference>` lists the ``gprd`` flags.