airsspy.casteptools#

CASTEP-related utility functions.

Provides tools for parsing CASTEP output files, extracting results, managing cell files, and running RASH (Random Ab initio Structure Hunting) relaxation seeds.

Module Contents#

Functions#

parse_param

Parse a CASTEP .param file and return a dictionary.

parse_dot_castep

Parse geometry convergence information from a CASTEP output file.

RASH_prepare_seed

Prepare a seed file for RASH (Random Ab initio Structure Hunting) relaxation.

extract_REM

Construct the REM lines from a CASTEP history file.

extract_result

Extract and save results as attributes from a CASTEP history file.

extract_REM_from_castep

Extract quality-affecting computational parameters from a .castep file.

extract_cell_rem_metadata

Extract REM-relevant metadata from a .cell file.

build_rem_lines

Build REM block lines for a .res file from CASTEP output.

write_converge

Write convergence information to a .gconv file.

get_rand_cell_name

Return a string for naming a randomly generated cell file.

castep_finish_ok

Check for the hint that CASTEP finished OK.

castep_geom_count

Count the number of geometry optimisation cycles in a .castep file.

push_cell

Copy the structure from one cell file to another.

gulp_relax_finish_ok

Check if a GULP relaxation finished successfully.

Data#

API#

exception airsspy.casteptools.CastepRunError[source]#

Bases: RuntimeError

Error when CASTEP produced no result

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception airsspy.casteptools.CastepSkip[source]#

Bases: RuntimeError

Skip this CASTEP run

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception airsspy.casteptools.CastepManualTimedout[source]#

Bases: RuntimeError

CASTEP was manually timed out

Initialization

Initialize self. See help(type(self)) for accurate signature.

airsspy.casteptools.parse_param(seed: str) dict[source]#

Parse a CASTEP .param file and return a dictionary.

Keys are converted to lower case. Values are left as-is.

Args: seed: Name of the seed (without extension).

Returns: Dictionary of parameter key-value pairs.

airsspy.casteptools.pattern_geom = <Multiline-String>#
airsspy.casteptools.pattern_time = <Multiline-String>#
airsspy.casteptools.parse_dot_castep(fb, aggregate=False)[source]#

Parse geometry convergence information from a CASTEP output file.

Args: fb: File handle or iterable of lines from a .castep file. aggregate: If True, aggregate timer values across continuation runs.

Returns: Dictionary with keys: H (enthalpy list), iter_num, name, unit, time (timing), save_iter, save_times.

airsspy.casteptools.RASH_prepare_seed(seed: str, relaxed: str, amp: float) io.StringIO[source]#

Prepare a seed file for RASH (Random Ab initio Structure Hunting) relaxation.

Takes the lattice from the relaxed structure and the position block, then combines with the original seed’s generation parameters.

Args: seed: Name of the ORIGINAL seed. relaxed: Name (uid) of the relaxed structure. amp: Amplitude of shape perturbation (positive float).

Returns: An StringIO object of the cell for RASH.

airsspy.casteptools.extract_REM(seed: str) dict[source]#

Construct the REM lines from a CASTEP history file.

Args: seed: Name of the seed (without extension).

Returns: A dictionary of the REM information.

airsspy.casteptools.extract_result(seed: str) dict[source]#

Extract and save results as attributes from a CASTEP history file.

Args: seed: Name of the seed (without extension).

Returns: Dictionary with P, H, V, sym, nat, chem_formula.

airsspy.casteptools.extract_REM_from_castep(seed: str) dict[source]#

Extract quality-affecting computational parameters from a .castep file.

Reads the .castep output file (not .history) to extract metadata for the REM block of a .res file. Uses tail-1 semantics (last match) for fields that repeat across cyclic CASTEP runs.

Args: seed: Name of the seed (without extension).

Returns: Dictionary with keys: functional, relativity, dispersion, cutoff, gridscale, gmax, fbsc, mpgrid, offset, nkpts, psps.

airsspy.casteptools.extract_cell_rem_metadata(seed: str) dict[source]#

Extract REM-relevant metadata from a .cell file.

Args: seed: Name of the seed (without extension).

Returns: Dictionary with keys: spacing, hubbard, md5.

airsspy.casteptools.build_rem_lines(seed: str) list[str][source]#

Build REM block lines for a .res file from CASTEP output.

Combines metadata from .castep and .cell files into a list of REM strings (without the “REM “ prefix), matching the format produced by the castep2res script.

Args: seed: Name of the seed (without extension).

Returns: List of REM line strings.

airsspy.casteptools.write_converge(seed: str, suffix: str = 'castep') None[source]#

Write convergence information to a .gconv file.

Args: seed: Name of the seed (without extension). suffix: File suffix (default: "castep").

airsspy.casteptools.get_rand_cell_name(seed_name: str) str[source]#

Return a string for naming a randomly generated cell file.

Format: <seed_name>-<YYMMDD-HHMMSS>-<uuid6>.cell

Args: seed_name: Name of the seed.

Returns: A unique cell file name.

airsspy.casteptools.castep_finish_ok(dot_castep: str) bool[source]#

Check for the hint that CASTEP finished OK.

Args: dot_castep: Path to the .castep file.

Returns: True if "Total time" appears in the last 20 lines.

airsspy.casteptools.castep_geom_count(dot_castep: str) int[source]#

Count the number of geometry optimisation cycles in a .castep file.

Args: dot_castep: Path to the .castep file.

Returns: Number of geometry cycles.

airsspy.casteptools.push_cell(cellout: str, cell: str) None[source]#

Copy the structure from one cell file to another.

Moves the LATTICE and POSITIONS blocks from cellout into cell, preserving everything else from cell.

Args: cellout: Path to the output cell file (source of new structure). cell: Path to the input cell file (to be updated).

airsspy.casteptools.gulp_relax_finish_ok(dot_castep: str) bool[source]#

Check if a GULP relaxation finished successfully.

Args: dot_castep: Path to the output file.

Returns: True if "Final Enthalpy" is found.