Skip to content

Commit

Permalink
XspectraCalculation+XspectraParser: Added Various Extra Features
Browse files Browse the repository at this point in the history
Adds the following features to the `XspectraCalculation` and
`XspectraParser` classes:
- A save file ('xanes.sav') is now reserved by default and is printed
at the end of each calculation run or after a designated time limit.
The file can then be used for re-starting halted calculations or
re-plotting spectra from previously-finished calculations.
- The `XspectraCalculation` class now copies the save file from a
parent calculation if the calculation type is itself an
XspectraCalculation, thus re-starts and re-plot runs are handled
automatically.
- An error code has been added (315) for calculations which safely exit
after reaching their time limit, thus enabiling a restart.
- Additional information is now included in the `output_parameters`
node (e.g. the polarisation vectors used and whether the calculation was
set to "xonly_plot").
  • Loading branch information
PNOGillespie committed Sep 2, 2022
1 parent 5f4bd99 commit 875fa58
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/aiida_quantumespresso/calculations/xspectra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Classes and methods for running xspectra.x with AiiDA."""

import os

from aiida import orm
from aiida.common import exceptions
from aiida.orm import Dict, SinglefileData, XyData
Expand All @@ -16,10 +18,13 @@ class XspectraCalculation(NamelistsCalculation):

_Plotcore_FILENAME = 'stdout'
_Spectrum_FILENAME = 'xanes.dat'
_XSPECTRA_SAVE_FILE = 'xanes.sav'
_XSPECTRA_GAMMA_FILE = 'gamma.dat'
_default_namelists = ['INPUT_XSPECTRA', 'PLOT', 'PSEUDOS', 'CUT_OCC']
_blocked_keywords = [('INPUT_XSPECTRA', 'outdir', NamelistsCalculation._OUTPUT_SUBFOLDER),
('INPUT_XSPECTRA', 'prefix', NamelistsCalculation._PREFIX),
('PSEUDOS', 'filecore', _Plotcore_FILENAME)]
('INPUT_XSPECTRA', 'x_save_file', _XSPECTRA_SAVE_FILE),
('PLOT', 'gamma_file', _XSPECTRA_GAMMA_FILE), ('PSEUDOS', 'filecore', _Plotcore_FILENAME)]
_internal_retrieve_list = [_Spectrum_FILENAME]
_retrieve_singlefile_list = []
_retrieve_temporary_list = []
Expand All @@ -31,7 +36,7 @@ def define(cls, spec):

super().define(spec)

spec.input('parent_folder', valid_type=(orm.RemoteData, orm.FolderData), required=True)
spec.input('parent_folder', valid_type=(orm.RemoteData), required=True)
spec.input(
'core_wfc_data',
valid_type=SinglefileData,
Expand All @@ -44,6 +49,14 @@ def define(cls, spec):
required=True,
help='The K-point sampling to be used for the XSpectra calculation'
)
spec.input(
'gamma_file',
valid_type=SinglefileData,
required=False,
help='An optional file containing the data for the broadening function used when'
' `gamma_mode=file`'
)

spec.output('output_parameters', valid_type=Dict)
spec.output('spectra', valid_type=XyData)
spec.default_output_node = 'output_parameters'
Expand All @@ -65,6 +78,12 @@ def define(cls, spec):
'ERROR_OUTPUT_ABSORBING_SPECIES_ZERO',
message='xiabs was either set to 0 or less, or was greater than ntyp.'
)
spec.exit_code(
315,
'ERROR_OUTPUT_TIME_LIMIT_EXCEEDED',
message='The time limit set for the calculation was exceeded, and the job wrote a save file '
'before exiting.'
)
spec.exit_code(
330,
'ERROR_READING_SPECTRUM_FILE',
Expand Down Expand Up @@ -108,4 +127,21 @@ def prepare_for_submission(self, folder):
core_file_info = (core_file.uuid, core_file.filename, core_file.filename)
calcinfo.local_copy_list.append(core_file_info)

# if included as an input, append the gamma file node to the copy list
if 'gamma_file' in self.inputs.keys():
gamma_file = self.inputs.gamma_file
gamma_file_info = (gamma_file.uuid, gamma_file.filename, gamma_file.filename)
calcinfo.local_copy_list.append(gamma_file_info)

# Check if the parent folder is an XspectraCalculation type, if so we then copy the
# save file to enable calculation restarts and re-plots.
parent_folder = self.inputs.parent_folder
parent_calcs = parent_folder.get_incoming(node_class=orm.CalcJobNode).all()
parent_calc = parent_calcs[0].node
restart_flag = parent_calc.process_type == 'aiida.calculations:quantumespresso.xspectra'
if restart_flag:
calcinfo.remote_copy_list.append((
parent_folder.computer.uuid, os.path.join(parent_folder.get_remote_path(),
self._XSPECTRA_SAVE_FILE), '.'
))
return calcinfo
12 changes: 12 additions & 0 deletions src/aiida_quantumespresso/parsers/xspectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def parse(self, **kwargs):
return self.exit(self.exit_codes.ERROR_OUTPUT_ABSORBING_SPECIES_WRONG)
if 'xiabs < 1 or xiabs > ntyp' in line:
return self.exit(self.exit_codes.ERROR_OUTPUT_ABSORBING_SPECIES_ZERO)
if 'Calculation not finished' in line:
return self.exit(self.exit_codes.ERROR_OUTPUT_TIME_LIMIT_EXCEEDED)
if 'END JOB' in line:
job_done = True
break
Expand Down Expand Up @@ -161,6 +163,16 @@ def parse_stdout_xspectra(filecontent, codename=None, message_map=None):
# Parse the necessary information for data plotting: core level energy of the
# absorbing atom and the energy zero of the spectrum (typically the Fermi level)
for line in lines:
if 'xepsilon' in line:
eps_vector_string = line.split(':')[-1].strip()
eps_vector_list = [float(i) for i in eps_vector_string.split(' ')]
parsed_data['epsilon_vector'] = eps_vector_list
if 'xonly_plot:' in line:
is_only_plot_string = line.split(':')[-1].strip()
if is_only_plot_string == 'FALSE':
parsed_data['plot_only'] = False
elif is_only_plot_string == 'TRUE':
parsed_data['plot_only'] = True
if 'From SCF save directory' in line:
if '(spin polarized work)' in line:
spin = True
Expand Down

0 comments on commit 875fa58

Please sign in to comment.