Skip to content

Commit

Permalink
Set default outputs (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 authored Sep 13, 2024
1 parent 3174c11 commit 49b7fe2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/ase_quantumespresso/espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ def read_results(self, directory):

results = parser.results
results["exit_code"] = exit_code
results.setdefault("energy", results["output_parameters"].get("energy", None))
results["atoms"] = results.get("output_structure", None)
for key in ["kpoints", "band", "trajectory", "structure", "atomic_occupations"]:
results.setdefault(key, None)
results["atoms"] = results.pop("structure", None)
results.setdefault("parameters", {})
results.setdefault("energy", results["parameters"].get("energy", None))
return results


Expand Down
2 changes: 1 addition & 1 deletion src/ase_quantumespresso/parsers/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def parse(self, **kwargs):
if base_exit_code:
return self.exit(base_exit_code, logs)

self.out("output_parameters", parsed_stdout)
self.out("parameters", parsed_stdout)

if "ERROR_OUTPUT_STDOUT_INCOMPLETE" in logs.error:
return self.exit(self.exit_codes.ERROR_OUTPUT_STDOUT_INCOMPLETE, logs)
Expand Down
16 changes: 16 additions & 0 deletions src/ase_quantumespresso/parsers/exit_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ class PwExitCodes:
ERROR_NO_RETRIEVED_TEMPORARY_FOLDER: ExitCode = ExitCode(
301, "The retrieved temporary folder could not be accessed."
)
ERROR_OUTPUT_STDOUT_MISSING: ExitCode = ExitCode(
302, "The retrieved folder did not contain the required stdout output file."
)
ERROR_OUTPUT_STDOUT_READ: ExitCode = ExitCode(
310, "The stdout output file could not be read."
)
ERROR_OUTPUT_STDOUT_PARSE: ExitCode = ExitCode(
311, "The stdout output file could not be parsed."
)
ERROR_OUTPUT_STDOUT_INCOMPLETE: ExitCode = ExitCode(
312,
"The stdout output file was incomplete probably because the calculation got interrupted.",
)
ERROR_OUT_OF_WALLTIME: ExitCode = ExitCode(
400, "The calculation stopped prematurely because it ran out of walltime."
)
ERROR_OUTPUT_XML_MISSING: ExitCode = ExitCode(
303, "The folder did not contain the required XML file."
)
Expand Down
2 changes: 1 addition & 1 deletion src/ase_quantumespresso/parsers/ld1.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def parse(self, **kwargs):
if base_exit_code:
return self.exit(base_exit_code, logs)

self.out("output_parameters", parsed_stdout)
self.out("parameters", parsed_stdout)

if "ERROR_OUTPUT_STDOUT_INCOMPLETE" in logs.error:
return self.exit(self.exit_codes.ERROR_OUTPUT_STDOUT_INCOMPLETE, logs)
Expand Down
2 changes: 1 addition & 1 deletion src/ase_quantumespresso/parsers/projwfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def parse(self, **kwargs):
if base_exit_code:
return self.exit(base_exit_code, logs)

self.out("output_parameters", parsed_data)
self.out("parameters", parsed_data)

if "ERROR_OUTPUT_STDOUT_INCOMPLETE" in logs.error:
return self.exit(self.exit_codes.ERROR_OUTPUT_STDOUT_INCOMPLETE, logs)
Expand Down
27 changes: 12 additions & 15 deletions src/ase_quantumespresso/parsers/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,22 @@ def parse(self, **kwargs):

# Only attach the `KpointsData` as output if there will be no `BandsData` output and inputs were defined as mesh
if kpoints and not bands and not input_kpoints_explicit:
self.out("output_kpoints", kpoints)
else:
self.out("output_kpoints", None)
self.out("kpoints", kpoints)

if bands:
self.out("output_band", bands)
else:
self.out("output_band", None)
self.out("band", bands)

if trajectory:
self.out("output_trajectory", trajectory)
else:
self.out("output_trajectory", None)
self.out("trajectory", trajectory)

self.out("output_structure", structure)
self.out("structure", structure)

# Separate the atomic_occupations dictionary in its own node if it is present
atomic_occupations = parsed_parameters.pop("atomic_occupations", None)
if atomic_occupations:
self.out("output_atomic_occupations", atomic_occupations)
else:
self.out("output_atomic_occupations", None)
self.out("atomic_occupations", atomic_occupations)

self.out("output_parameters", parsed_parameters)
self.out("parameters", parsed_parameters)

# Emit the logs returned by the XML and stdout parsing through the logger
# If the calculation was an initialization run, reset the XML logs because they will contain a lot of verbose
Expand Down Expand Up @@ -413,7 +405,12 @@ def parse_xml(self, dir_with_bands=None, parser_options=None):
return parsed_data, logs

try:
with open(self.directory / "pwscf.save" / xml_files[0]) as xml_file:
ourdir = (
self.parameters["input_data"].get("CONTROL", {}).get("outdir", "./")
)
with open(
self.directory / ourdir / "pwscf.save" / xml_files[0]
) as xml_file:
parsed_data, logs = parse_xml(xml_file, dir_with_bands)
except IOError:
self.exit_code_xml = self.exit_codes.ERROR_OUTPUT_XML_READ
Expand Down

0 comments on commit 49b7fe2

Please sign in to comment.