"""Parsers provided by aiida_gromacs.This parser adds the ability to parse the outputs of the 'gmx pdb2gmx' executable."""importosfrompathlibimportPathfromaiida.commonimportexceptionsfromaiida.engineimportExitCodefromaiida.ormimportSinglefileDatafromaiida.parsers.parserimportParserfromaiida.pluginsimportCalculationFactoryPdb2gmxCalculation=CalculationFactory("gromacs.pdb2gmx")
[docs]classPdb2gmxParser(Parser):""" Parser class for parsing output of calculation. """
[docs]def__init__(self,node):""" Initialize Parser instance Checks that the ProcessNode being passed was produced by a Pdb2gmxCalculation. :param node: ProcessNode of calculation :param type node: :class:`aiida.orm.nodes.process.process.ProcessNode` """super().__init__(node)ifnotissubclass(node.process_class,Pdb2gmxCalculation):raiseexceptions.ParsingError("Can only parse Pdb2gmxCalculation")
[docs]defparse(self,**kwargs):""" Parse outputs, store results in database. :returns: an exit code, if parsing fails (or nothing if parsing succeeds) """# the directory for storing parsed output filesoutput_dir=Path(self.node.get_option("output_dir"))# Map output files to how they are named.outputs=["stdout"]output_template={"o":"grofile","p":"topfile","i":"itpfile","n":"n_file","q":"q_file",}foriteminoutput_template:ifiteminself.node.inputs.parameters.keys():outputs.append(output_template[item])# Grab list of retrieved files.files_retrieved=self.retrieved.base.repository.list_object_names()# Grab list of files expected and remove the scheduler stdout and stderr files.files_expected=[filesforfilesinself.node.get_option("retrieve_list")iffilesnotin["_scheduler-stdout.txt","_scheduler-stderr.txt"]]# Check if the expected files are a subset of retrieved.ifnotset(files_expected)<=set(files_retrieved):self.logger.error(f"Found files '{files_retrieved}', expected to find '{files_expected}'")returnself.exit_codes.ERROR_MISSING_OUTPUT_FILES# Map retrieved files to data nodes.fori,finenumerate(files_expected):self.logger.info(f"Parsing '{f}'")withself.retrieved.base.repository.open(f,"rb")ashandle:output_node=SinglefileData(filename=f,file=handle)self.out(outputs[i],output_node)# If not in testing mode, then copy back the files.if"PYTEST_CURRENT_TEST"notinos.environ:self.retrieved.copy_tree(output_dir)returnExitCode(0)