Skip to content

Refine a known step at a stated pressure with reactionflow band - #91

Open
Austin243 wants to merge 3 commits into
mainfrom
feat/band-command
Open

Austin243 wants to merge 3 commits into
mainfrom
feat/band-command

Conversation

@Austin243

Copy link
Copy Markdown
Owner

Summary

reactionflow band campaign.json reactant.extxyz product.extxyz --pressure 25 --out bands/25GPa

reactionflow band refines one step without MD. Until now a band could only come from an event
that run found, at that trajectory's pressure, so taking a step to other pressures needed scripts
outside the package. The command takes a reactant file and a product file, relaxes the two ends at
the stated pressure (or at fixed cell when there is none), checks their bonds, runs NEB or SSNEB
and the climbing image, and applies the saddle gate. It does this by calling refine_pathway(),
the function run calls, with the campaign's model, bond thresholds, region radius, and pathway
settings.

Refinement itself is unchanged. No tolerance, threshold, step limit, time limit, default, or
acceptance rule is added, and no result file or campaign key changes. A run writes the same files
as before.

Adds a net 143 lines in src (+179/−36). Ruff and the tests pass at each commit.

Commit What src lines
1bc669e publish_outcome is split out of ReactionRun._publish_outcome, so a run and band write results with the same code +27/−18
b4e3080 refine_band and the band command in cli.py, beside check_band, with 14 tests in tests/test_band.py. Two predicates are lifted out of _start_warnings so that both use them +152/−18
638289f A section in docs/pathway-refinement.md, and the command named in the README and the overview 0

What the command does, in order:

  • Model and pressure are named as for check: --index picks the trajectory whose model and
    pressure are used, and --pressure replaces that pressure. Zero is a pressure. With a null
    trajectory pressure and no --pressure, the cell is fixed. As with check, no option asks for a
    fixed cell when the trajectory has a pressure, and require_gpu is not enforced.
  • The two files must hold the same atoms, matched by ID when both carry IDs and by order when
    neither does. ASE's file@N picks a frame, so images.traj@0 and images.traj@-1 are the
    relaxed ends of an earlier band. A file with several frames, or with constraints, is used as run
    uses a starting structure, with the same kind of warning.
  • The candidate is made by ReactionTracker, as from two observations of a trajectory, with
    candidate_region_radius from the campaign. Each file's bonds are the pairs within their
    formation distance, the rule the detector applies to the first frame of a trajectory.
  • Refused before the model loads, with nothing written: the same bonds in both files, bond
    changes in two or more separate regions, different atoms, atom IDs in one file only.
  • Refinement is refine_pathway(candidate, ...) with reaction_run.pathway and
    reaction_run.detector. Ends whose bonds change on relaxation end as collapsed or unresolved
    with the reason, and every other status is the existing one.
  • The folder given by --out gets candidates/band/, pathways/band/ and reactions.sqlite3
    in the form of a trajectory's folder, written by OccurrenceStore and publish_outcome. check
    and export-electrace read pathways/band unchanged.
  • A rerun never overwrites a result. A folder that already holds a band is refused, and so is a
    trajectory's folder. An interrupted band has published nothing and starts over in its folder.

What to look at when merging

Most of these follow from reusing run's path as it is. Each is a place where another choice is
possible.

  • The product is not relaxed from its file. As in every refinement since Build the product from the relaxed reactant and report no barrier without a saddle #70, the product
    starts from the relaxed reactant, cell included, with only the atoms in changed bonds and the
    atoms bonded to them placed at their fractional coordinates in the product file. The rest of the
    product file is not used. On the xTB example this moved the product end by 0.02 to 0.10 Å against
    the run's own product and changed barriers by at most 1.4 meV.
  • Bonds are read by distance from each file. Relaxed structures are what the command is for.
    The two hot frames stored with an occurrence can have the changing bond between its thresholds,
    and are then read differently from the tracker's record: of the seven xTB occurrences, six ended
    unresolved this way and one gave the run's barrier to the last digit.
  • A step in two separate regions is refused, since run refines those as two events. The
    message names the pairs.
  • There is no time limit. max_hours_per_barrier is not applied: its clock lives in a
    trajectory's state.json. An unfinished band is not continued either, so a band needs a job long
    enough to finish it.
  • reactionflow status does not list a band. It reads output_root/<trajectory-id> folders
    that have a state.json, and takes each class's pressure from the trajectory. The band's folder
    has the same registry and result files, but nothing reads them into a table yet.
  • result.json has the keys a run writes and no more, so it does not say which model or
    campaign made the band. A run's result does not either, but there the trajectory's folder does.
  • check on a band needs the band's --pressure, because check takes the trajectory's.
  • A published result uses up its folder, including a failed one after a model error.
  • The tests import helpers from test_run.py and test_ssneb.py, which no test module did
    before. The alternative was to copy the scripted runtime and two calculators.
  • Add a command-line reference, a citation file, a contributing guide and a bug report form #89 adds docs/cli.md, which says there are nine commands. Whichever merges second needs the
    band entry at the end of this description.

Differences from the campaign scripts

The package's rules are kept in every row. "Setting" says whether an existing campaign setting
expresses the scripts' choice. No setting was added.

Campaign scripts reactionflow band Setting
Images 11 with both ends images, 7 by default reaction_run.pathway.images
Spring constant 5 eV/Ų ASE's default, 0.1 eV/Ų none
Band convergence Euclidean norm of the whole band's generalized NEB force ≤ 0.05 eV/Å FIRE's fmax: the largest force on any atom or cell row of any image ≤ neb_fmax, 0.05 eV/Å the value only, neb_fmax; the norm is not a setting
Band steps one budget for both phases, raised per case neb_steps 2000, then ci_neb_steps 2000 both exist
Band optimizer FIRE, or plain L-BFGS for continuation across pressure FIRE none
Endpoint relaxation own L-BFGS with a line search, up to 6000 steps FIRE on atoms and six cell components, relax_steps 2000 relax_steps
Endpoint tolerance force ≤ 0.05 eV/Å and every residual stress component ≤ 0.1 GPa relax_fmax 0.05 eV/Å on the combined atomic and cell gradient, with no stress tolerance. For the 192-atom example cell this is about 0.17 GPa on one stress component (0.05·J/V with J = N^(1/6)·V^(1/3); an estimate from the filter's scaling, not measured) relax_fmax; no stress setting
Where the product starts each end relaxed from its own file the reactant from its file, the product from the relaxed reactant with the reacting atoms placed none
Bond graph one cutoff per element pair, C–C 1.75, C–N 1.70, C–H and H–N 1.25, N–N 1.65, H–H 0.95 Å formation and break distances with a gap between them reaction_run.detector.pair_thresholds, which needs two distances per pair
Endpoint check each end keeps its whole-cell graph the reacting region matches the files and has no pair in the gap, and the two relaxed ends agree everywhere else. A change far from the reaction that both ends share passes none
Excluded chemistry stops when H2 or other excluded species appear no such rule none
Saddle check the same Hessian, cutoff and 0.1 Å displacement, as a separate diagnostic the gate that #72 took from it. Sides relax with the package's endpoint settings, and a side that does not converge, takes no step, or leaves a pair in the gap makes the check inconclusive exists
Interior images could be seeded from another pressure's band, with arc-length redistribution interpolated between the two relaxed ends none
Interrupted band resumes from a checkpoint of the band and its optimizer starts over none
Pressure fixed by the code directory --pressure, or the trajectory's exists

Left out on purpose

  • Carrying a band's interior images to another pressure. The first version builds its band
    from the two relaxed ends, the way run does. The transport and redistribution that the campaign
    needed are a separate piece of work.
  • Continuing an unfinished band. The existing refinement cannot: an interrupted one starts
    over. band does the same.
  • Starting from a stored occurrence. Its two frames can already be given as files, but they are
    hot frames (see above). Doing it properly means refining the stored candidate with the run's saved
    frames, which needs ReactionRun._saved_frames moved out of the class and a second way to call
    the command. That is not small.
  • Seeding the band through a supplied image, such as an EON saddle. It changes how
    _refine_step builds every band, and needs a rule for where the image sits and how the others
    are spread.
  • A time limit, a listing in status, a model record in result.json, a whole-cell graph check
    against the input files, and settings for the spring constant, a stress tolerance, or L-BFGS.

    Each is a default, an acceptance rule, or a file format.

Testing

  • Failure modes first. Seventeen ways the command could fail were written down before any
    code, then the 14 tests, which all failed on the missing command, then the code. Two cases were
    added later, each as a failing test first: a file name that picks several frames, and the folder
    of a trajectory that has not started. The pressure test was then widened to take its ends from
    another pressure, and passed as it stood. One assertion was wrong and was narrowed: it compared
    the volumes of images that the springs leave loose, where the SSNEB test compares only the first,
    highest, and last.
  • Same band as run, fixed cell. From the two ends of a refinement that run made on the pair
    double well, band gives saddle_validated and the barrier to 1e-6 eV. By hand, on six more
    cases of the pathway tests against refine_pathway called as those tests call it (atom IDs in
    another order with a cell 1% larger, a spectator on a ridge at fixed cell and at zero pressure,
    a reactant taken from an earlier frame), status and barrier agree to 4e-7 eV.
  • Same enthalpy barrier as run, at a pressure. On the SSNEB test system, ends from a
    refinement at 0 GPa give at 0.8 GPa the enthalpy barrier that a refinement inside run gives
    there, and the reverse, both to 1e-4 eV (0.0952 and 0.0625 eV). By hand, for 15 pairs of
    pressures from 0 to 2.4 GPa the highest point of the profile agrees to 3e-6 eV. Both end
    no_saddle, as the existing SSNEB test explains.
  • Refusals. Ends that collapse or stay inside the gap on relaxation are published collapsed
    and unresolved with the reason and the two relaxed ends. Structures that are not one step are
    refused before the model loads, with a model that cannot be imported.
  • Readers. check gives the band's own status and enthalpies, and export-electrace writes
    its frames, pressure, and focus atoms. A step that splits exports from its step-2 folder.
  • GFN2-xTB. The example ran 7 proton transfers in 96 s. band from the two ends of each
    refinement gave saddle_validated 7 of 7, barriers within 0.04 to 1.4 meV of the run's 0.122 to
    0.186 eV, and the same imaginary mode within 6 cm⁻¹. The reactant end did not move.
  • Whole suite: 370 passed, 25 skipped (356 before), ruff check, ruff format --check, and
    python -m build, on Python 3.12.3, ASE 3.29.0, NumPy 2.5.5, macOS.
  • Not run: a GPU, a cluster or Slurm, a machine-learned potential, an acetonitrile band or any
    band of a real crystal under pressure, Python 3.14, and Linux. The only pressure tests use the
    analytic volume-coupled double well. The xTB example is a cluster at fixed cell.

One thing seen and not touched: on the SSNEB test system at 1.6 GPa, with the product's H–H pair
also shifted as a whole, the band of run's own refinement steps over the saddle and ends
no_saddle with "an endpoint is the highest point". band gives the same.

Entry for docs/cli.md once #89 is in

The command table gets one row, and "nine commands" becomes ten.

| [`band`](#band) | Refine the step from a reactant to a product, as `run` refines an event |
## band

```text
reactionflow band [--index INDEX] [--pressure PRESSURE] --out OUT campaign reactant product
```

`band` refines one known step without MD, through the same endpoint relaxation, band, and saddle
check as an event of `run`, and prints a one-line JSON summary
([refining a known step](pathway-refinement.md#refining-a-known-step)).

| Argument | Meaning |
| --- | --- |
| `campaign` | An MD campaign, which supplies the model, the bond thresholds, the region radius, and the pathway settings |
| `reactant` | A structure file ASE can read; `file@N` picks one frame |
| `product` | The same atoms after the step |
| `--index INDEX` | The trajectory whose model and pressure to use; a campaign with several needs it |
| `--pressure PRESSURE` | A pressure in GPa, in place of the trajectory's |
| `--out OUT` | A folder for this band alone; required |

`band` refuses an EON campaign.

publish_outcome writes pathways/<occurrence>/ with result.json, images.traj and
a step-N folder for each step, under a temporary name until complete, as
ReactionRun._publish_outcome did. The method now looks up the occurrence's class
and calls it. No file a run writes changes.

This is for reactionflow band, which refines a step that no run found and
writes the same result files.
reactionflow band CAMPAIGN REACTANT PRODUCT --out FOLDER takes a step that is
already known and refines it without MD. It relaxes the two ends at the
trajectory's pressure or at --pressure, or at fixed cell when there is none,
and runs the band, the climb and the saddle check through refine_pathway with
the campaign's model, bond thresholds, region radius and pathway settings. The
model and the pressure are named as for reactionflow check.

The tracker makes the candidate from the two files, as from two observations,
with each file's bonds read as in the first frame of a trajectory. Files with
the same bonds, with changes in several separate regions, with different atoms,
or with atom IDs in one of them only are refused before the model is loaded. A
file with several frames or with constraints is used as run uses a starting
structure, and says so in the same way.

The folder gets candidates/band, pathways/band and reactions.sqlite3 in the form
of a trajectory's folder, written by the store and the publishing function a
run uses, so reactionflow check and reactionflow export-electrace read it
unchanged. A folder that already holds a band, or a trajectory's own folder, is
refused, and an interrupted band starts over in its folder.

Refinement itself is unchanged: no tolerance, threshold, time limit or
acceptance rule is added, and max_hours_per_barrier is not applied.
The pathway guide gains a section on refining a known step: what the two files
must hold, how the step becomes a candidate, that the product starts from the
relaxed reactant as in every refinement, what the folder holds, and what a
rerun does. It states what band does not do: it takes no images from another
band, continues no unfinished band, applies no time limit, and is not listed by
reactionflow status. The README and the overview name the command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant