chemparseplot.parse.trajectory.band_h5#

NEB bands from gpridge’s readcon output and from HDF5 band files.

Added in version 1.15.0.

gpridge (gprn) writes its band as readcon files: --write-con band.con (one frame per image with energy and forces, the run summary on the first frame under neb_summary), the same frames in the corpus band.con.corpus, and every oracle evaluation in the observation archive (obs-archive, the active training set in obs-archive/training).

func:

read_band and :func:read_observations read those first.

The HDF5 readers here are for files that hold the band in HDF5: ChemGP’s files, gpridge’s optional --full-h5 output (schema neb-band/1, the ChemGP layout plus 2-D /training, /summary and /trace), and band.h5 files of older gpridge runs. The default gpridge band.h5 (schema gprn-gp-trace/1) holds only the GP trace, not the band.

Two programs wrote a NEB band to HDF5 with different groups.

ChemGP (neb_result.h5, neb_history.h5) /path/{images, gradients} of shape (n_images, 3N), /path/{energies, f_para, rxn_coord} of shape (n_images,), /metadata/{atomic_numbers, cell, converged, oracle_calls,     max_energy_image}, /convergence/<series>, and in a history file /steps/<NNN>/ groups shaped like /path.

gpridge (gprn band.h5) /converged/<i>/{positions, gradient} of shape (3N,) and /converged/<i>/energy of shape (1,), /summary/<name> scalars of shape (1,), and /training/{n_rows, dof, positions, gradients,     energies}: the training set of the run, row-major. Older gpridge runs only; the file stores no atomic numbers and no cell.

func:

read_band reads either layout into a :class:NebBand and

func:

read_observations reads the gpridge training set into

class:

Observations. Both convert to readcon.ConFrame objects (:func:band_frames, :func:observation_frames) and the observations go into a readcon-db observation archive with :func:write_observation_archive, the same store gpridge writes during a run. :func:convert_layout writes one layout from the other.

When a gpridge file is read without atomic_numbers,

func:

discover_structure looks beside it for the observation archive (obs-archive) and then for a CON file with the same stem (band.con). Units are those of the file: angstrom and eV.

Module Contents#

Classes#

NebBand

One band: positions, energies and gradients of every image.

Observations

Oracle evaluations: one row per evaluated configuration.

Functions#

_h5py

_schema

_layout_of

_is_readcon_path

detect_layout

Return :data:READCON, :data:CHEMGP or :data:GPRIDGE.

_cell_from_lengths_angles

_lengths_angles

_structure_from_frame

Atomic numbers in the writer’s order (atom ids) and the cell of a frame.

discover_structure

Atomic numbers and cell for a band file from the files beside it.

_resolve_structure

_scalar

_read_chemgp_band

_read_gpridge_band

read_band

Read the final band from gpridge’s readcon output or an HDF5 file.

read_observations

Read oracle evaluations: an observation archive or an HDF5 /training.

_file_order

Stored row of each atom in the writer’s order (atom ids), or identity.

_read_readcon_band

_read_archive_observations

write_band_con

Write a band as gpridge’s --write-con file.

_frame

_readcon

band_frames

One readcon.ConFrame per image, with energy and forces.

observation_frames

One readcon.ConFrame per oracle evaluation, in evaluation order.

write_observation_archive

Append the observations to a readcon-db observation archive.

path_coordinates

Cumulative distance and parallel force (improved tangent) of a band.

_write_chemgp

_write_training

_write_gpridge

convert_layout

Write the band (and the gpridge training set) of src in layout to.

Data#

API#

chemparseplot.parse.trajectory.band_h5.log#

‘getLogger(…)’

chemparseplot.parse.trajectory.band_h5.__all__#

[‘CHEMGP’, ‘GPRIDGE’, ‘READCON’, ‘NebBand’, ‘Observations’, ‘band_frames’, ‘convert_layout’, ‘detect…

chemparseplot.parse.trajectory.band_h5.CHEMGP#

‘chemgp’

chemparseplot.parse.trajectory.band_h5.GPRIDGE#

‘gpridge’

chemparseplot.parse.trajectory.band_h5.READCON#

‘readcon’

chemparseplot.parse.trajectory.band_h5.NEB_BAND_SCHEMA#

‘neb-band/1’

chemparseplot.parse.trajectory.band_h5.GP_TRACE_SCHEMA#

‘gprn-gp-trace/1’

chemparseplot.parse.trajectory.band_h5.Layout#

None

chemparseplot.parse.trajectory.band_h5._FREE_PADDING#

10.0

chemparseplot.parse.trajectory.band_h5._ORTHO_TOL#

1e-08

chemparseplot.parse.trajectory.band_h5._MATRIX_NDIM#

2

class chemparseplot.parse.trajectory.band_h5.NebBand#

One band: positions, energies and gradients of every image.

positions and gradients have shape (n_images, natoms, 3). cell is a (3, 3) matrix of lattice vectors (rows), or None for a free molecule. atomic_numbers is None when neither the file nor the caller gave them. summary holds the scalar results the file records (barrier, oracle calls, convergence).

layout: str#

None

positions: numpy.ndarray#

None

energies: numpy.ndarray#

None

gradients: numpy.ndarray | None#

None

atomic_numbers: numpy.ndarray | None#

None

cell: numpy.ndarray | None#

None

summary: dict[str, Any]#

‘field(…)’

moving: numpy.ndarray | None#

None

property n_images: int#
property natoms: int#
property forces: numpy.ndarray | None#

-gradients, or None when the file has no gradients.

class chemparseplot.parse.trajectory.band_h5.Observations#

Oracle evaluations: one row per evaluated configuration.

positions and gradients have shape (n_rows, natoms, 3) and energies shape (n_rows,). A row whose energy the writer did not record holds NaN.

positions: numpy.ndarray#

None

energies: numpy.ndarray#

None

gradients: numpy.ndarray#

None

atomic_numbers: numpy.ndarray | None#

None

cell: numpy.ndarray | None#

None

__len__() → int#
property forces: numpy.ndarray#
chemparseplot.parse.trajectory.band_h5._h5py()#
chemparseplot.parse.trajectory.band_h5._schema(f) → str#
chemparseplot.parse.trajectory.band_h5._layout_of(f) → str#
chemparseplot.parse.trajectory.band_h5._is_readcon_path(path: str | pathlib.Path) → bool#
chemparseplot.parse.trajectory.band_h5.detect_layout(path: str | pathlib.Path) → str#

Return :data:READCON, :data:CHEMGP or :data:GPRIDGE.

A CON file or a readcon-db corpus directory is :data:READCON. An HDF5 file is :data:CHEMGP (also gpridge --full-h5, schema neb-band/1) or :data:GPRIDGE (older gpridge band.h5) from the groups present.

Raises:

ValueError – when the HDF5 file has neither layout’s groups, or holds only the gpridge GP trace.

chemparseplot.parse.trajectory.band_h5._cell_from_lengths_angles(lengths, angles) → numpy.ndarray#
chemparseplot.parse.trajectory.band_h5._lengths_angles(cell: numpy.ndarray) → tuple[list[float], list[float]]#
chemparseplot.parse.trajectory.band_h5._structure_from_frame(frame) → tuple[numpy.ndarray, numpy.ndarray]#

Atomic numbers in the writer’s order (atom ids) and the cell of a frame.

chemparseplot.parse.trajectory.band_h5.discover_structure(h5_file: str | pathlib.Path) → tuple[numpy.ndarray, numpy.ndarray] | None#

Atomic numbers and cell for a band file from the files beside it.

Looks for the observation archive gpridge writes next to the band (obs-archive, or any directory holding observations.rdb), then a CON file with the band’s stem (band.con). Atomic numbers follow the stored atom ids, which are the writer’s atom order. Returns None when nothing is found or readcon / readcon-db is not installed.

chemparseplot.parse.trajectory.band_h5._resolve_structure(h5_file, natoms, *, atomic_numbers, cell, file_z, file_cell)#
chemparseplot.parse.trajectory.band_h5._scalar(ds) → Any#
chemparseplot.parse.trajectory.band_h5._read_chemgp_band(f) → tuple[dict, numpy.ndarray | None, numpy.ndarray | None]#
chemparseplot.parse.trajectory.band_h5._read_gpridge_band(f) → dict#
chemparseplot.parse.trajectory.band_h5.read_band(h5_file: str | pathlib.Path, *, atomic_numbers=None, cell=None) → chemparseplot.parse.trajectory.band_h5.NebBand#

Read the final band from gpridge’s readcon output or an HDF5 file.

h5_file may be a CON file (band.con), a readcon-db corpus (band.con.corpus), or an HDF5 file in the ChemGP, neb-band/1 or older gpridge layout. A ChemGP history file without /path gives its last step. atomic_numbers and cell ((3, 3), or three orthorhombic lengths) take precedence over the file’s metadata and over

Func:

discover_structure.

chemparseplot.parse.trajectory.band_h5.read_observations(h5_file: str | pathlib.Path, *, atomic_numbers=None, cell=None) → chemparseplot.parse.trajectory.band_h5.Observations#

Read oracle evaluations: an observation archive or an HDF5 /training.

h5_file may be a readcon-db observation archive (gpridge’s obs-archive holds every evaluation, obs-archive/training the final training set), or an HDF5 file with /training (gpridge --full-h5 as 2-D rows, older gpridge band.h5 as flat rows).

Raises:

ValueError – for an HDF5 file without /training.

chemparseplot.parse.trajectory.band_h5._file_order(frame) → numpy.ndarray#

Stored row of each atom in the writer’s order (atom ids), or identity.

chemparseplot.parse.trajectory.band_h5._read_readcon_band(path, *, atomic_numbers=None, cell=None) → chemparseplot.parse.trajectory.band_h5.NebBand#
chemparseplot.parse.trajectory.band_h5._read_archive_observations(path, *, atomic_numbers=None, cell=None) → chemparseplot.parse.trajectory.band_h5.Observations#
chemparseplot.parse.trajectory.band_h5.write_band_con(band: chemparseplot.parse.trajectory.band_h5.NebBand, path: str | pathlib.Path) → pathlib.Path#

Write a band as gpridge’s --write-con file.

One frame per image with energy, forces, neb_band / neb_bead and role (reactant, intermediate, climbing, product; the climbing image is summary["max_energy_image"] when the summary has it), and the band summary on the first frame under neb_summary. Converts an older gpridge band.h5 (whose band holds only the moving atoms) into the readcon output a current run writes.

chemparseplot.parse.trajectory.band_h5._frame(readcon, positions, forces, *, energy, z, cell, metadata, moving=None)#
chemparseplot.parse.trajectory.band_h5._readcon()#
chemparseplot.parse.trajectory.band_h5.band_frames(band: chemparseplot.parse.trajectory.band_h5.NebBand) → list[Any]#

One readcon.ConFrame per image, with energy and forces.

Atoms keep the file’s order as their atom_id. The metadata carries neb_bead (the image index) and neb_band 0. A band without a cell is written in a box with 10 angstrom padding and pbc all false.

chemparseplot.parse.trajectory.band_h5.observation_frames(obs: chemparseplot.parse.trajectory.band_h5.Observations) → list[Any]#

One readcon.ConFrame per oracle evaluation, in evaluation order.

chemparseplot.parse.trajectory.band_h5.write_observation_archive(obs: chemparseplot.parse.trajectory.band_h5.Observations, directory: str | pathlib.Path) → int#

Append the observations to a readcon-db observation archive.

directory is the archive directory (observations.rdb is created inside it), as gpridge’s --gp-observation-archive writes it, so readcon_db.ArchiveReader(directory) reads the rows back in caller atom order. Rows without an energy are skipped. The archive stores an orthorhombic box: a non-orthorhombic cell raises ValueError and a free molecule gets a box around every row with 10 angstrom padding.

Returns:

the number of rows written.

chemparseplot.parse.trajectory.band_h5.path_coordinates(band: chemparseplot.parse.trajectory.band_h5.NebBand) → tuple[numpy.ndarray, numpy.ndarray]#

Cumulative distance and parallel force (improved tangent) of a band.

chemparseplot.parse.trajectory.band_h5._write_chemgp(f, band: chemparseplot.parse.trajectory.band_h5.NebBand, obs: chemparseplot.parse.trajectory.band_h5.Observations | None) → None#
chemparseplot.parse.trajectory.band_h5._write_training(f, obs: chemparseplot.parse.trajectory.band_h5.Observations) → None#
chemparseplot.parse.trajectory.band_h5._write_gpridge(f, band: chemparseplot.parse.trajectory.band_h5.NebBand, obs: chemparseplot.parse.trajectory.band_h5.Observations | None) → None#
chemparseplot.parse.trajectory.band_h5.convert_layout(src: str | pathlib.Path, dst: str | pathlib.Path, to: chemparseplot.parse.trajectory.band_h5.Layout, *, atomic_numbers=None, cell=None) → pathlib.Path#

Write the band (and the gpridge training set) of src in layout to.

gpridge to ChemGP computes rxn_coord (cumulative distance) and f_para (force on the improved tangent) and stores the atomic numbers and cell found by :func:read_band. The /training group is copied as it is, so the ChemGP file keeps the oracle evaluations. ChemGP to gpridge writes /converged and the /summary scalars it can derive. dst must not exist.