"""Parsers provided by aiida_mlip."""fromaiida.engineimportExitCodefromaiida.ormimportSinglefileDatafromaiida.orm.nodes.process.processimportProcessNodefromaiida.parsers.parserimportParser
[docs]classBaseParser(Parser):""" Parser class for parsing output of calculation. Parameters ---------- node : aiida.orm.nodes.process.process.ProcessNode ProcessNode of calculation. Methods ------- __init__(node: aiida.orm.nodes.process.process.ProcessNode) Initialize the BaseParser instance. parse(**kwargs: Any) -> int: Parse outputs, store results in the database. Returns ------- int An exit code. Raises ------ exceptions.ParsingError If the ProcessNode being passed was not produced by a `Base` Calcjob. """
[docs]def__init__(self,node:ProcessNode):""" Check that the ProcessNode being passed was produced by a `Base` Calcjob. Parameters ---------- node : aiida.orm.nodes.process.process.ProcessNode ProcessNode of calculation. """super().__init__(node)
[docs]defparse(self,**kwargs)->int:""" Parse outputs, store results in the database. Parameters ---------- **kwargs : Any Any keyword arguments. Returns ------- int An exit code. """output_filename=self.node.get_option("output_filename")log_output=(self.node.inputs.log_filename).value# Check that folder content is as expectedfiles_retrieved=self.retrieved.list_object_names()files_expected={output_filename,log_output}ifnotfiles_expected.issubset(files_retrieved):self.logger.error(f"Found files '{files_retrieved}', expected to find '{files_expected}'")returnself.exit_codes.ERROR_MISSING_OUTPUT_FILES# Add output file to the outputswith(self.retrieved.open(log_output,"rb")aslog,self.retrieved.open(output_filename,"rb")asoutput,):self.out("log_output",SinglefileData(file=log,filename=log_output))self.out("std_output",SinglefileData(file=output,filename=output_filename))returnExitCode(0)