--- myst: html_meta: "description": "Guide to using the external potential (ext_pot) interface in eOn for wrapping arbitrary calculators via file-based communication." "keywords": "eOn external potential, ext_pot, MLIP, DeePMD, wrapper script, file interface" --- # External Potential ```{admonition} conda-forge availability :class: tip Included in the `conda-forge` package. Always compiled in; no build flags required. ``` The external potential (`ext_pot`) interface allows eOn to use **any** energy and force calculator by communicating through files and a system call. Because it requires no compile-time dependencies, `ext_pot` is always available in every eOn build, including the `conda-forge` package. ```{tip} If you installed eOn from `conda-forge` and want to use an MLIP (DeePMD, MACE, etc.) that is not available through the [Metatomic](project:metatomic_pot.md) interface, `ext_pot` or [LAMMPS](project:lammps_pot.md) is the recommended path. The [ASE](project:ase_pot.md) potentials require additional compile-time flags that are **not** enabled in the `conda-forge` build. ``` ## Start with a complete working example This example needs Python and the eOn client only. It evaluates a harmonic potential, so it needs no electronic-structure executable, model download or pseudopotentials. The commands below target Linux, including Ubuntu under WSL. Run calculations inside your site's compute allocation, not on its login node. Install [Pixi](https://pixi.sh), then create a separate workspace: ```bash curl -fsSL https://pixi.sh/install.sh | sh export PATH="$HOME/.pixi/bin:$PATH" mkdir eon-external-demo cd eon-external-demo pixi init --channel conda-forge pixi add eon python pixi run eonclient --version ``` `pixi add` installs the client and Python and records their resolved packages in `pixi.lock`. Keep `pixi.toml` and `pixi.lock` together; a recipient can recreate the environment with `pixi install --locked`. No compiler or MPI installation is needed for this file-interface example. Save the following executable as `harmonic_extpot.py`: ```python #!/usr/bin/env python3 """Harmonic energy in eV and its negative derivative in eV/Angstrom.""" import math from pathlib import Path rows = [line.split() for line in Path("from_eon_to_extpot").read_text().splitlines() if line.strip()] if len(rows) < 4 or any(len(row) != 3 for row in rows[:3]): raise ValueError("Expected three box rows followed by at least one atom") positions = [] for row in rows[3:]: if len(row) != 4: raise ValueError("Expected atomic_number x y z") int(row[0]) xyz = [float(value) for value in row[1:]] if not all(math.isfinite(value) for value in xyz): raise ValueError("Non-finite coordinate") positions.append(xyz) k = 1.0 # eV/Angstrom squared energy = 0.5 * k * sum(x*x for xyz in positions for x in xyz) forces = [[-k*x for x in xyz] for xyz in positions] with Path("from_extpot_to_eon").open("w") as output: output.write(f"{energy:.15g}\n") for force in forces: output.write(" ".join(f"{value:.15g}" for value in force) + "\n") ``` Create `pos.con`, with one silicon atom at (1, 0, 0) Angstrom in a 20 Angstrom cube. The two blank lines between the cell angles and component count are part of this structure format: ```text One atom harmonic example 0.0 20.0 20.0 20.0 90.0 90.0 90.0 1 1 28.0855 Si Coordinates of Component 1 1.0 0.0 0.0 0 0 ``` Make the wrapper executable, create the configuration and evaluate the point: ```bash chmod +x harmonic_extpot.py cat > config.ini < eon.log 2>&1 cat results.dat ``` The `potential_energy` result is **0.5 eV**. The wrapper returns one force, **(-1, 0, 0) eV/Angstrom**. This potential is a protocol demonstration: its origin is fixed and it does not model periodic interatomic interactions. The exact result-file formatting depends on the installed eOn release. For example, the point check prints these result entries: ```text GOOD termination_reason_text EXT_POT potential_type 1 total_force_calls 5.000000000000e-01 potential_energy 1.000000000000e+00 Max_Force ``` To check the wrapper independently, run it from a separate directory containing this `from_eon_to_extpot` file: ```text 20 0 0 0 20 0 0 0 20 14 1 0 0 ``` Its `from_extpot_to_eon` must contain: ```text 0.5 -1 -0 -0 ``` Signed zero is equivalent to zero. A successful wrapper-only check tests the file protocol; the client run also tests the structure, configuration and executable lookup. ## Run CPMD through eOn Use the runnable example in `examples/ext_pot_cpmd` on the **develop** branch. It evaluates a geometry with your existing CPMD executable and pseudopotentials. Pixi supplies eOn, Python and uv; no cpmdc library or eOn source compilation is needed for this external route. The example contains: | File | Purpose | | --- | --- | | `pixi.toml` | Installs eOn, Python and uv; defines `run` and `neb` tasks. | | `.env.example` | Executable, pseudopotential, MPI and physical-method settings; copy it to `.env`. | | `config.ini` | A point job with `ext_pot_path = ./ext_pot`. | | `ext_pot` | Loads `.env` and invokes the CPMD file-interface wrapper. | | `cpmd_extpot.py` | Renders a single-point deck, runs CPMD and converts its results. | | `cpmd_launch.sh` | Starts CPMD with the compatible MPI runtime. | | `run.sh` | Converts an input if needed and preserves a separate point-job record. | | `con_to_input.py` | Reads a CON frame and removes cached evaluations while preserving its geometry and constraints. | ### Install the example environment Use a Linux terminal, including Ubuntu under WSL. Install [Pixi](https://pixi.sh), clone the public repository, then install the example's environment: ```bash curl -fsSL https://pixi.sh/install.sh | sh export PATH="$HOME/.pixi/bin:$PATH" git clone --branch develop https://github.com/TheochemUI/eOn.git cd eOn/examples/ext_pot_cpmd pixi install pixi run eonclient --version cp .env.example .env ``` Git is needed for the initial clone. Pixi installs the scientific environment without administrator rights. Keep its generated `pixi.lock` with `pixi.toml` when sharing a resolved environment; another account can recreate it using `pixi install --locked`. On an HPC system, run calculations inside a compute allocation according to the site policy. A workstation does not require Slurm. ### Set the existing CPMD paths Edit `.env`. For an existing Intel oneAPI CPMD installation, the essential settings look like: ```bash EON_CLIENT=eonclient CPMD_BIN=$HOME/myCPMD/bin/cpmd4.3-oneAPI-2022-AMD.x PP_LIBRARY_PATH=$HOME/pseudo CPMD_PP='14:Si_MT_BLYP.psp:LMAX=D LOC=D,7:N_MT_BLYP.psp:LMAX=P LOC=P' CPMD_MPI_LAUNCH='mpirun -np 4' CPMD_MODULES='intel/oneAPI-2022 intelmpi/oneAPI-2022' CPMD_FUNCTIONAL=BLYP CPMD_CUTOFF=70 CPMD_CONVERGENCE=1e-6 ``` Replace the paths, module names, pseudopotential mapping and ranks with the actual CPMD installation. The executable and licensed pseudopotentials are supplied by your group, not downloaded by Pixi. Every element in the structure needs a mapping in `CPMD_PP`. Its third field is CPMD's angular-momentum/options line; the wrapper uses Kleinman–Bylander pseudopotentials. Leave `CPMD_MODULES=''` on a workstation where the compatible runtime is already available. A binary linked with Intel MPI needs the matching Intel MPI launcher; another environment's Open MPI is not a substitute. When modules are requested, only the CPMD child clears inherited library overrides and loads them. The parent eOn client keeps its Pixi libraries. `.env` is sourced by Bash: values set there take precedence over the environment inherited by the launcher. Keep account paths in `.env`, which is ignored by Git. ### Evaluate a geometry From `examples/ext_pot_cpmd`, use the same command for XYZ or CON input: ```bash pixi run run /absolute/path/input.xyz pixi run run /absolute/path/pos.con ``` The CON route uses `uv run --script con_to_input.py` with pinned readcon. It preserves coordinates, cell, atom IDs, masses and fixed flags, and clears stored energy and forces so your configured CPMD calculation is evaluated. Set `CON_FRAME=0` in `.env` for the first frame, or `CON_FRAME=-1` for the last. `pos.source.json` records the frame, input hash and cache removal. Each invocation prints `Record: .../runs/point-...`, evaluates one geometry, and prints a finite energy in eV when successful. The record retains `pos.con`, `config.ini`, `eon.log` and `results.dat`. CPMD input, output and `GEOMETRY` remain in its external-potential exchange directory. A failed client or a non-finite energy causes a nonzero exit; inspect the preserved logs rather than using a partial result. For the supplied CON example, the static configuration can also be run directly from this directory after editing `.env`: ```bash pixi run eonclient > eon.log 2>&1 cat results.dat ``` This direct command uses the existing `pos.con` and `config.ini` in place; `pixi run run` creates a separate record and handles an arbitrary input. Use the launcher for a CON containing stored energies and forces: an installed client can otherwise reuse that stored evaluation. For a file route using four CPMD ranks, reserve four ranks for each concurrent calculator. The eOn client itself stays one process. ### XYZ frames, units and the periodic cell The XYZ launcher uses `uv run --script xyz_to_con.py` with the pinned `readcon-chemfiles==0.17.1` dependency to read XYZ and write CON. The first conversion needs network access unless the wheel is cached. Prepare that cache with an actual input on a host where dependency installation is permitted: ```bash pixi run uv run --script xyz_to_con.py /absolute/path/input.xyz /tmp/input.con ``` Set `XYZ_FRAME=-1` for the last frame, or a zero-based nonnegative frame index. `XYZ_UNITS=angstrom` is the default; `XYZ_UNITS=bohr` converts coordinates and a metadata cell to Angstrom. An explicit `CELL_ANGSTROM='9.984 19.968 14.976'` is always in Angstrom. Edit these values in `.env` before launching. A positive cell in extended XYZ metadata is preserved unless `CELL_ANGSTROM` overrides it. This wrapper requires an orthorhombic box. For plain XYZ with no cell, conversion prints a **LOUD WARNING** and infers a box from the coordinate bounds with `VACUUM_ANGSTROM=10` on each side. It translates the coordinates into that artificial box; **this does not recover the original bulk cell**. Supply the actual periodic cell for a material calculation. `pos.source.json` records the frame, input units, cell source, translation, atom IDs and the mapping between CON and original XYZ order. ### Run a nudged elastic band Use two endpoints with the same atoms, atom correspondence and periodic cell, relaxed on the same physical Hamiltonian: ```bash pixi run neb /absolute/path/reactant.xyz /absolute/path/product.xyz ``` The `neb` task uses `run_neb.sh` and `config-neb.ini`; XYZ endpoints use the same conversion and cell settings. Confirm endpoint identities and the real cell before launching. Reserve resources for the number of concurrent images times the CPMD rank count, and inspect the band's termination and force convergence before treating its peak as a barrier. ## CPMD method requirements The distributed settings use a neutral BLYP single-point calculation. A charged, spin-polarized, dispersion-corrected or constrained system needs a deck/wrapper that explicitly retains those settings. Replacing its geometry alone does not reproduce that Hamiltonian. Check charge, occupations, functional, dispersion, pseudopotentials, cell, cutoff and SCF convergence against the actual source calculation. The [RGPOT route](project:rgpot_pot.md) loads cpmdc in process and uses a separate serialized CPMD method message. This external executable route reads its own settings from `.env`; the two configurations are distinct inputs. A wrapper of your own can instead read the one job TOML that the [rgpot page](project:rgpot_pot.md) compiles to a CPMDParams message. The file route then renders that message and keeps no second cutoff. ## Protocol When the client needs an energy/force evaluation it: 1. Creates a private exchange directory named `extpot__` inside the directory eOn runs in, where `` is the client's process id and `` counts the potentials it built. 2. Writes the file `from_eon_to_extpot` in that directory. 3. Calls the executable (or script) specified by `ext_pot_path` via `system()`, with the exchange directory as the command's working directory. 4. Reads the file `from_extpot_to_eon` that the script must create there. The two filenames do not change, so a wrapper that opens them by relative name, as every example below does, needs no edit. The exchange directory is what keeps two clients started in one directory from reading each other's numbers. The directory lives as long as the potential: each call reuses it, so a wrapper can keep state there between calls (the CPMD wrapper below keeps its wavefunction). When the potential is destroyed the client removes the two exchange files and then the directory, if nothing else is left in it. A failed call leaves everything in place for inspection. ## One directory per image `[Main] parallel` defaults to true. A dimer, and the two product minimizations in a process search, then build a second potential when the potential asks for one instance per image. `ext_pot` does. Each instance takes the next `extpot__`, so the two calls do not share `from_eon_to_extpot`. An error on the second thread is stored, the first thread is joined, and the stored error is raised. `parallel = false` runs both images on the one instance, one after the other. ```{important} `ext_pot_path` is resolved against the directory eOn runs in when it names an existing file, so `./ext_pot` and an absolute path both work. A command line with arguments (`python wrapper.py`) or a name looked up on `PATH` is passed to the shell unchanged and therefore has to be written so it resolves from the exchange directory: give the script an absolute path. On Windows, `cmd.exe` does not honor a shebang: a resolved script whose first line names python, or whose name ends in `.py`, is invoked as `python