Coverage for ase/io/exciting.py: 100.00%
21 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1"""This is the implementation of the exciting I/O functions.
3The main roles these functions do is write exciting ground state
4input files and read exciting ground state ouput files.
6Right now these functions all written without a class to wrap them. This
7could change in the future but was done to make things simpler.
9These functions are primarily called by the exciting caculator in
10ase/calculators/exciting/exciting.py.
12See the correpsonding test file in ase/test/io/test_exciting.py.
14Plan is to add parsing of eigenvalues in the next iteration using
15excitingtools.exciting_dict_parsers.groundstate_parser.parse_eigval
17Note: excitingtools must be installed using `pip install excitingtools` for
18the exciting io to work.
19"""
21from pathlib import Path
23import ase
26def parse_output(info_out_file_path):
27 """Parse exciting INFO.OUT output file using excitingtools.
29 Note, excitingtools works by returning a dictionary that contains
30 two high level keys. Initialization and results. Initialization
31 contains data about how the calculation was setup (e.g. structure,
32 maximum number of planewaves, etc...) and the results
33 gives SCF cycle result information (e.g. total energy).
35 Args:
36 info_out_file_path: path to an INFO.out exciting output file.
37 Returns
38 -------
39 A dictionary containing information about how the calculation was setup
40 and results from the calculations SCF cycles.
41 """
42 from excitingtools.exciting_dict_parsers.groundstate_parser import (
43 parse_info_out,
44 )
46 # Check for the file:
47 if not Path(info_out_file_path).is_file():
48 raise FileNotFoundError
49 return parse_info_out(info_out_file_path)
52def write_input_xml_file(
53 file_name,
54 atoms: ase.Atoms,
55 ground_state_input: dict,
56 species_path,
57 title=None,
58 properties_input: dict | None = None,
59):
60 """Write input xml file for exciting calculation.
62 Args:
63 file_name: where to save the input xml file.
64 atoms: ASE Atoms object.
65 ground_state_input: ground state parameters for run.
66 properties_input: optional additional parameters to run
67 after performing the ground state calculation (e.g. bandstructure
68 or DOS.)
69 """
70 from excitingtools import (
71 ExcitingGroundStateInput,
72 ExcitingInputXML,
73 ExcitingPropertiesInput,
74 ExcitingStructure,
75 )
77 # Convert ground state dictionary into expected input object.
78 ground_state = ExcitingGroundStateInput(**ground_state_input)
79 structure = ExcitingStructure(atoms, species_path=species_path)
80 # If we are running futher calculations such as bandstructure/DOS.
81 if properties_input is not None:
82 properties_input = ExcitingPropertiesInput(**properties_input)
83 else:
84 properties_input = ExcitingPropertiesInput()
85 input_xml = ExcitingInputXML(
86 structure=structure,
87 groundstate=ground_state,
88 properties=properties_input,
89 title=title,
90 )
92 input_xml.write(file_name)
95def ase_atoms_from_exciting_input_xml(input_xml_path: Path | str) -> ase.Atoms:
96 """Helper function to read structure from input.xml file.
98 Note, this function operates on the input.xml file that is the input
99 to an exciting calculation. It parses the structure data given in the file
100 and returns it in an ase Atoms object. Note this information can also be
101 taken from an INFO.out file using parse_output. This script is more
102 lightweight than parse_output since the input xml is significantly smaller
103 than an INFO.out file and is XML structured making the parsing easier.
105 Args:
106 input_xml_path: Path where input.xml file lives.
108 Returns
109 -------
110 ASE atoms object with all the relevant fields filled.
111 """
112 from excitingtools.exciting_obj_parsers.input_xml import parse_input_xml
113 from excitingtools.structure.ase_utilities import exciting_structure_to_ase
115 structure = parse_input_xml(input_xml_path).structure
116 return exciting_structure_to_ase(structure)