Coverage for /builds/kinetik161/ase/ase/io/exciting.py: 100.00%

22 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

1"""This is the implementation of the exciting I/O functions. 

2 

3The main roles these functions do is write exciting ground state 

4input files and read exciting ground state ouput files. 

5 

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. 

8 

9These functions are primarily called by the exciting caculator in 

10ase/calculators/exciting/exciting.py. 

11 

12See the correpsonding test file in ase/test/io/test_exciting.py. 

13 

14Plan is to add parsing of eigenvalues in the next iteration using 

15excitingtools.exciting_dict_parsers.groundstate_parser.parse_eigval 

16 

17Note: excitingtools must be installed using `pip install excitingtools` for 

18the exciting io to work. 

19""" 

20from pathlib import Path 

21from typing import Dict, Optional, Union 

22 

23import ase 

24 

25 

26def parse_output(info_out_file_path): 

27 """Parse exciting INFO.OUT output file using excitingtools. 

28 

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). 

34 

35 Args: 

36 info_out_file_path: path to an INFO.out exciting output file. 

37 Returns: 

38 A dictionary containing information about how the calculation was setup 

39 and results from the calculations SCF cycles. 

40 """ 

41 from excitingtools.exciting_dict_parsers.groundstate_parser import \ 

42 parse_info_out 

43 

44 # Check for the file: 

45 if not Path(info_out_file_path).is_file(): 

46 raise FileNotFoundError 

47 return parse_info_out(info_out_file_path) 

48 

49 

50def write_input_xml_file( 

51 file_name, atoms: ase.Atoms, ground_state_input: Dict, 

52 species_path, title=None, 

53 properties_input: Optional[Dict] = None): 

54 """Write input xml file for exciting calculation. 

55 

56 Args: 

57 file_name: where to save the input xml file. 

58 atoms: ASE Atoms object. 

59 ground_state_input: ground state parameters for run. 

60 properties_input: optional additional parameters to run 

61 after performing the ground state calculation (e.g. bandstructure 

62 or DOS.) 

63 """ 

64 from excitingtools import (ExcitingGroundStateInput, ExcitingInputXML, 

65 ExcitingPropertiesInput, ExcitingStructure) 

66 

67 # Convert ground state dictionary into expected input object. 

68 ground_state = ExcitingGroundStateInput(**ground_state_input) 

69 structure = ExcitingStructure(atoms, species_path=species_path) 

70 # If we are running futher calculations such as bandstructure/DOS. 

71 if properties_input is not None: 

72 properties_input = ExcitingPropertiesInput(**properties_input) 

73 else: 

74 properties_input = ExcitingPropertiesInput() 

75 input_xml = ExcitingInputXML(structure=structure, 

76 groundstate=ground_state, 

77 properties=properties_input, 

78 title=title) 

79 

80 input_xml.write(file_name) 

81 

82 

83def ase_atoms_from_exciting_input_xml( 

84 input_xml_path: Union[Path, str]) -> ase.Atoms: 

85 """Helper function to read structure from input.xml file. 

86 

87 Note, this function operates on the input.xml file that is the input 

88 to an exciting calculation. It parses the structure data given in the file 

89 and returns it in an ase Atoms object. Note this information can also be 

90 taken from an INFO.out file using parse_output. This script is more 

91 lightweight than parse_output since the input xml is significantly smaller 

92 than an INFO.out file and is XML structured making the parsing easier. 

93 

94 Args: 

95 input_xml_path: Path where input.xml file lives. 

96 

97 Returns: 

98 ASE atoms object with all the relevant fields filled. 

99 """ 

100 from excitingtools.exciting_obj_parsers.input_xml import parse_input_xml 

101 from excitingtools.structure.ase_utilities import exciting_structure_to_ase 

102 structure = parse_input_xml(input_xml_path).structure 

103 return exciting_structure_to_ase(structure)