Tools#
get_generated_files#
get_generated_files is a function which can predict the files that will be produced by a CASTEP
run. It can accept either parsed (via parse_cell_param_file) .cell / .param files or
paths or a seedname.
from pathlib import Path
from castep_outputs.tools.get_generated_files import get_generated_files
example_path = Path.cwd() / "example_data" / "pair-pot-lj"
cell_path = example_path.with_suffix(".cell")
param_path = example_path.with_suffix(".param")
# Automatically picks up cell/param files if present.
get_generated_files(seedname=example_path)
['pair-pot-lj.*.drhom',
'pair-pot-lj.*.wfm',
'pair-pot-lj.castep',
'pair-pot-lj.md']
# Allows you to override cell/param files for a given output seedname.
get_generated_files(cell_file=cell_path, param_file=param_path)
['seedname.*.drhom', 'seedname.*.wfm', 'seedname.castep', 'seedname.md']
from castep_outputs import parse_cell_param_file
param = parse_cell_param_file(param_path)[0]
cell = parse_cell_param_file(cell_path)[0]
get_generated_files(param_data=param, cell_data=cell)
['seedname.*.drhom', 'seedname.*.wfm', 'seedname.castep', 'seedname.md']
md_geom_parser#
The MDGeomParser is a class which provides an iterative interface for loading md/geom data
without loading the whole file simultaneously. It supports efficient Sequence
style access to the data, returning parsed frame data or lists thereof.
from pathlib import Path
from castep_outputs.tools.md_geom_parser import MDGeomParser
example_path = Path.cwd() / "example_data" / "pair-pot-lj.md"
parser = MDGeomParser(example_path)
print(parser)
WARNING:root:[/home/runner/work/castep_outputs/castep_outputs/docs/source/example_data/pair-pot-lj.md:26] Number of frames estimate is non-integral (2).
This may have been caused by manually modifying the file.
While iteration should work, extracting particular frames may not.
File: /home/runner/work/castep_outputs/castep_outputs/docs/source/example_data/pair-pot-lj.md
Frames: 2
Next frame: 0
print(f"There are {len(parser)} frames in the file.")
There are 2 frames in the file.
for i, frame in enumerate(parser):
print(f"Frame {i} temperature: {frame['temperature']}.")
Frame 0 temperature: [[0.00031668115668705653]].
Frame 1 temperature: [[0.00028945201776119263]].
print(f"First temperature: {parser[0]['temperature']}")
First temperature: [[0.00031668115668705653]]
print(f"Last temperature: {parser[-1]['temperature']}")
Last temperature: [[0.00028945201776119263]]