[docs]classMDParser(BaseParser):""" Parser class for parsing output of molecular dynamics simulation. Inherits from SPParser. Parameters ---------- node : aiida.orm.nodes.process.process.ProcessNode ProcessNode of calculation. Methods ------- 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 `MD`. """
[docs]def__init__(self,node:ProcessNode):""" Check that the ProcessNode being passed was produced by a `MD`. Parameters ---------- node : aiida.orm.nodes.process.process.ProcessNode ProcessNode of calculation. """super().__init__(node)ifnotissubclass(node.process_class,MDCalculation):raiseexceptions.ParsingError("Can only parse `MD` calculations")
[docs]defparse(self,**kwargs)->ExitCode:""" Parse outputs, store results in the database. Parameters ---------- **kwargs : Any Any keyword arguments. Returns ------- int An exit code. """# Call the parent parse method to handle common parsing logicexit_code=super().parse(**kwargs)ifexit_code!=ExitCode(0):returnexit_codemd_dictionary=self.node.inputs.md_kwargs.get_dict()# Process trajectory file saving both the file and trajectory as aiida datatraj_filepath=md_dictionary.get("traj-file",MD.DEFAULT_TRAJ_FILE)withself.retrieved.open(traj_filepath,"rb")ashandle:self.out("traj_file",SinglefileData(file=handle,filename=traj_filepath))final_str,traj_output=xyz_to_aiida_traj(Path(self.node.get_remote_workdir(),traj_filepath))self.out("traj_output",traj_output)self.out("final_structure",final_str)# Process stats file as singlefiledatastats_filepath=md_dictionary.get("stats-file",MD.DEFAULT_STATS_FILE)withself.retrieved.open(stats_filepath,"rb")ashandle:self.out("stats_file",SinglefileData(file=handle,filename=stats_filepath))# Process summary as both singlefiledata and results dictionarysummary_filepath=md_dictionary.get("summary",MD.DEFAULT_SUMMARY_FILE)print(self.node.get_remote_workdir(),summary_filepath)withself.retrieved.open(summary_filepath,"rb")ashandle:self.out("summary",SinglefileData(file=handle,filename=summary_filepath))withself.retrieved.open(summary_filepath,"r")ashandle:try:res_dict=yaml.safe_load(handle.read())exceptyaml.YAMLErrorasexc:print("Error loading YAML:",exc)ifres_dictisNone:self.logger.error("Results dictionary empty")returnself.exit_codes.ERROR_MISSING_OUTPUT_FILESresults_node=Dict(res_dict)self.out("results_dict",results_node)returnExitCode(0)