airsspy.fullrelax#

Self-consistent CASTEP relaxation driver.

Replicates the behaviour of castep_relax.pl, performing iterative fixed-NPW geometry optimisations with restart capability and optional alternating cell constraints.

Module Contents#

Classes#

FullRelax

Self-consistent CASTEP relaxation with restart and state tracking.

Functions#

check_relax_status

Check whether the last geometry optimisation completed.

parse_geom_text_output

Parse a CASTEP .geom file and return trajectory data.

geom_to_cell

Convert the last configuration in a .geom file to cell blocks.

Data#

API#

airsspy.fullrelax.logger#

‘getLogger(…)’

class airsspy.fullrelax.FullRelax(exe: str, struct_name: str, maxit: int, initial_cycle: int = 4, initial_length: int = 4, alter_cell_cons: bool = False)[source]#

Self-consistent CASTEP relaxation with restart and state tracking.

Performs iterative fixed-NPW geometry optimisations. Initial cycles use a short iteration count, then full-length cycles until two consecutive successful runs confirm convergence.

Initialization

Initialise a FullRelax instance.

Args: exe: CASTEP executable name/path. struct_name: Name of the structure to relax (without extension). maxit: Maximum geometry iterations (0 for single-point). initial_cycle: Number of initial short cycles. initial_length: Number of iterations in initial short cycles. alter_cell_cons: Alternate cell constraints on/off between cycles.

property dot_castep: str#
property dot_param: str#
property dot_cell: str#
property dot_cell_out: str#
check_param() None[source]#

Ensure write_cell_structure is set in the PARAM file.

save_state() None[source]#

Save the relaxation state to a JSON file.

load_state() None[source]#

Load state from an unfinished run if present.

fixed_cell_off() None[source]#

Remove fixed cell constraints and uncomment CELL_CONSTRAINTS block.

fixed_cell_on() None[source]#

Comment out CELL_CONSTRAINTS block and add FIX_ALL_CELL.

run(timeout: Optional[float] = None) str[source]#

Run the full relaxation procedure.

Args: timeout: Walltime limit in seconds.

Returns: "success" if converged, "limit reached" if maxit exceeded.

__repr__() str[source]#
airsspy.fullrelax.check_relax_status(dot_castep: str) tuple[bool, int][source]#

Check whether the last geometry optimisation completed.

Args: dot_castep: Path to the .castep file.

Returns: Tuple of (relaxation_succeeded, total_iterations).

airsspy.fullrelax.parse_geom_text_output(out_lines: list[str]) dict[str, numpy.ndarray][source]#

Parse a CASTEP .geom file and return trajectory data.

Args: out_lines: Lines from the .geom file.

Returns: Dictionary with keys cells, positions, forces, geom_energy, symbols, and optionally velocities. All arrays are in CASTEP atomic units, converted to Angstrom/eV.

airsspy.fullrelax.geom_to_cell(geom_file: str) tuple[str, str][source]#

Convert the last configuration in a .geom file to cell blocks.

Args: geom_file: Path to the .geom file.

Returns: Tuple of (cell_block_string, position_block_string) including %BLOCK/%ENDBLOCK enclosures.