Ejemplo n.º 1
0
    def parse(self, **kwargs):
        """Parses the datafolder, stores results."""
        resources = self.get_parsing_resources(kwargs, traj_in_temp=True)
        if resources.exit_code is not None:
            return resources.exit_code

        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                trajectory_data = LammpsTrajectory(
                    resources.traj_paths[0],
                    aliases={
                        'stresses': [f'c_stpa[{i+1}]' for i in range(6)],
                        'forces': ['fx', 'fy', 'fz'],
                    },
                )
                self.out('trajectory_data', trajectory_data)
                self.out(
                    'structure',
                    trajectory_data.get_step_structure(
                        -1, original_structure=self.node.inputs.structure),
                )
            except Exception as err:  # pylint: disable=broad-except
                traceback.print_exc()
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data['data']
        if 'units_style' in output_data:
            output_data.update(
                get_units_dict(
                    output_data['units_style'],
                    ['energy', 'force', 'distance', 'pressure'],
                ))
            output_data['stress_units'] = output_data.pop('pressure_units')
        else:
            self.logger.warning('units missing in log')
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        parameters_data = Dict(dict=output_data)
        self.out('results', parameters_data)

        if output_data['errors']:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if not log_data.get('found_end', False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE
        return None
Ejemplo n.º 2
0
    def parse(self, **kwargs):
        """Parses the datafolder, stores results."""
        resources = self.get_parsing_resources(kwargs, traj_in_temp=True)
        if resources.exit_code is not None:
            return resources.exit_code

        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                trajectory_data = LammpsTrajectory(
                    resources.traj_paths[0],
                    aliases={
                        "stresses":
                        ["c_stpa[{}]".format(i + 1) for i in range(6)],
                        "forces": ["fx", "fy", "fz"],
                    },
                )
                self.out("trajectory_data", trajectory_data)
                self.out(
                    "structure",
                    trajectory_data.get_step_structure(
                        -1, original_structure=self.node.inputs.structure),
                )
            except Exception as err:
                traceback.print_exc()
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data["data"]
        if "units_style" in output_data:
            output_data.update(
                get_units_dict(
                    output_data["units_style"],
                    ["energy", "force", "distance", "pressure"],
                ))
            output_data["stress_units"] = output_data.pop("pressure_units")
        else:
            self.logger.warning("units missing in log")
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        parameters_data = Dict(dict=output_data)
        self.out("results", parameters_data)

        if output_data["errors"]:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if not log_data.get("found_end", False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE
Ejemplo n.º 3
0
    def parse(self, **kwargs):
        """Parse the retrieved files and store results."""
        # retrieve resources
        resources = self.get_parsing_resources(kwargs)
        if resources.exit_code is not None:
            return resources.exit_code

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                array_data = self.parse_traj_file(resources.traj_paths[0])
                self.out("arrays", array_data)
            except IOError as err:
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data["data"]
        if "units_style" in output_data:
            output_data.update(
                get_units_dict(
                    output_data["units_style"], ["energy", "force", "distance"]
                )
            )
        else:
            self.logger.warning("units missing in log")
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        parameters_data = Dict(dict=output_data)
        self.out("results", parameters_data)

        if output_data["errors"]:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if not log_data.get("found_end", False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE
Ejemplo n.º 4
0
    def parse(self, **kwargs):
        """
        Parses the datafolder, stores results.
        """
        # retrieve resources
        resources, exit_code = self.get_parsing_resources(kwargs)
        if exit_code is not None:
            return exit_code
        trajectory_filename, trajectory_filepath, info_filepath = resources

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        # parse trajectory file
        trajectory_txt = self.retrieved.get_object_content(trajectory_filename)
        if not trajectory_txt:
            self.logger.error("trajectory file empty")
            return self.exit_codes.ERROR_TRAJ_PARSING
        positions, forces, charges, symbols, cell2 = read_lammps_positions_and_forces_txt(
            trajectory_txt)

        # save forces and stresses into node
        array_data = ArrayData()
        array_data.set_array('forces', forces)
        if charges is not None:
            array_data.set_array('charges', charges)
        self.out('arrays', array_data)

        # save results into node
        output_data = log_data["data"]
        if 'units_style' in output_data:
            output_data.update(get_units_dict(output_data['units_style'],
                                              ["energy", "force", "distance"]))
        else:
            self.logger.warning("units missing in log")
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        parameters_data = Dict(dict=output_data)
        self.out('results', parameters_data)

        if output_data["errors"]:
            return self.exit_codes.ERROR_LAMMPS_RUN
Ejemplo n.º 5
0
    def parse(self, **kwargs):
        """Parse the retrieved folder and store results."""
        # pylint: disable=too-many-locals, too-many-branches, too-many-return-statements
        # retrieve resources
        resources = self.get_parsing_resources(kwargs, traj_in_temp=True)
        if resources.exit_code is not None:
            return resources.exit_code

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                trajectory_data = LammpsTrajectory(resources.traj_paths[0])
                self.out('trajectory_data', trajectory_data)
            except Exception as err:  # pylint: disable=broad-except
                traceback.print_exc()
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data['data']
        if 'units_style' in output_data:
            output_data.update(
                get_units_dict(output_data['units_style'],
                               ['distance', 'time', 'energy']))
        else:
            self.logger.warning('units missing in log')
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        if 'parameters' in self.node.get_incoming().all_link_labels():
            output_data['timestep_picoseconds'] = convert_units(
                self.node.inputs.parameters.dict.timestep,
                output_data['units_style'],
                'time',
                'picoseconds',
            )
        parameters_data = Dict(dict=output_data)
        self.out('results', parameters_data)

        # parse the system data file
        sys_data_error = None
        if resources.sys_paths:
            sys_data = ArrayData()
            try:
                with open(resources.sys_paths[0]) as handle:
                    names = handle.readline().strip().split()
                for i, col in enumerate(
                        np.loadtxt(resources.sys_paths[0],
                                   skiprows=1,
                                   unpack=True,
                                   ndmin=2)):
                    sys_data.set_array(names[i], col)
            except Exception:  # pylint: disable=broad-except
                traceback.print_exc()
                sys_data_error = self.exit_codes.ERROR_INFO_PARSING
            sys_data.set_attribute('units_style',
                                   output_data.get('units_style', None))
            self.out('system_data', sys_data)

        if output_data['errors']:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if sys_data_error:
            return sys_data_error

        if not log_data.get('found_end', False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE
        return None
Ejemplo n.º 6
0
    def parse(self, **kwargs):
        """Parse the retrieved folder and store results."""
        # pylint: disable= too-many-locals, too-many-branches, too-many-statements, too-many-return-statements
        # retrieve resources
        resources = self.get_parsing_resources(kwargs, traj_in_temp=True)
        if resources.exit_code is not None:
            return resources.exit_code

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                trajectories = {
                    os.path.basename(traj_path).split('-')[0]:
                    LammpsTrajectory(traj_path)
                    for traj_path in resources.traj_paths
                }
                self.out('trajectory', trajectories)
            except Exception as err:  # pylint: disable=broad-except
                traceback.print_exc()
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data['data']
        if 'units_style' in output_data:
            output_data.update(
                get_units_dict(output_data['units_style'],
                               ['distance', 'time', 'energy']))
        else:
            self.logger.warning('units missing in log')
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        if 'parameters' in self.node.get_incoming().all_link_labels():
            output_data['timestep_picoseconds'] = convert_units(
                self.node.inputs.parameters.dict.timestep,
                output_data['units_style'],
                'time',
                'picoseconds',
            )
            output_data['stage_names'] = [
                s['name'] for s in self.node.inputs.parameters.dict.stages
            ]
        parameters_data = Dict(dict=output_data)
        self.out('results', parameters_data)

        # parse the system data file
        sys_data_error = None
        arrays = {}
        for sys_path in resources.sys_paths:
            stage_name = os.path.basename(sys_path).split('-')[0]
            sys_data = ArrayData()
            sys_data.set_attribute('units_style',
                                   output_data.get('units_style', None))
            try:
                with open(sys_path) as handle:
                    names = handle.readline().strip().split()
                for i, col in enumerate(
                        np.loadtxt(sys_path, skiprows=1, unpack=True,
                                   ndmin=2)):
                    sys_data.set_array(names[i], col)
                arrays[stage_name] = sys_data
            except Exception:  # pylint: disable=broad-except
                traceback.print_exc()
                sys_data_error = self.exit_codes.ERROR_INFO_PARSING
        if arrays:
            self.out('system', arrays)

        # retrieve the last restart file, per stage
        restart_map = {}
        for rpath in resources.restart_paths:
            rpath_base = os.path.basename(rpath)
            match = re.match(r'([^\-]*)\-.*\.([\d]+)', rpath_base)
            if match:
                stage, step = match.groups()
                if int(step) > restart_map.get(stage, (-1, None))[0]:
                    restart_map[stage] = (int(step), rpath)

        for stage, (step, rpath) in restart_map.items():
            with io.open(rpath, 'rb') as handle:
                self.retrieved.put_object_from_filelike(
                    handle, os.path.basename(rpath), 'wb', force=True)

        if output_data['errors']:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if sys_data_error:
            return sys_data_error

        if not log_data.get('found_end', False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE
        return None
Ejemplo n.º 7
0
    def parse(self, **kwargs):
        """
        Parses the datafolder, stores results.
        """
        # retrieve resources
        resources, exit_code = self.get_parsing_resources(
            kwargs, traj_in_temp=True, sys_info=True)
        if exit_code is not None:
            return exit_code
        trajectory_filename, trajectory_filepath, info_filepath = resources

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        # parse trajectory file
        try:
            timestep = self.node.inputs.parameters.dict.timestep
            positions, charges, step_ids, cells, symbols, time = read_lammps_trajectory(
                trajectory_filepath, timestep=timestep,
                log_warning_func=self.logger.warning)
        except Exception:
            traceback.print_exc()
            return self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data["data"]
        if 'units_style' in output_data:
            output_data.update(get_units_dict(output_data['units_style'],
                                              ["distance", "time", "energy"]))
        else:
            self.logger.warning("units missing in log")
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        parameters_data = Dict(dict=output_data)
        self.out('results', parameters_data)

        # save trajectories into node
        trajectory_data = TrajectoryData()
        trajectory_data.set_trajectory(
            symbols, positions, stepids=step_ids, cells=cells, times=time)
        if charges is not None:
            trajectory_data.set_array('charges', charges)       
        self.out('trajectory_data', trajectory_data)

        # parse the system data file
        if info_filepath:
            sys_data = ArrayData()
            try:
                with open(info_filepath) as handle:
                    names = handle.readline().strip().split()
                for i, col in enumerate(np.loadtxt(info_filepath, skiprows=1, unpack=True)):
                    sys_data.set_array(names[i], col)
            except Exception:
                traceback.print_exc()
                return self.exit_codes.ERROR_INFO_PARSING
            sys_data.set_attribute('units_style', output_data.get('units_style', None))
            self.out('system_data', sys_data)

        if output_data["errors"]:
            return self.exit_codes.ERROR_LAMMPS_RUN
Ejemplo n.º 8
0
    def parse(self, **kwargs):
        """Parse the retrieved folder and store results."""
        # retrieve resources
        resources = self.get_parsing_resources(kwargs, traj_in_temp=True)
        if resources.exit_code is not None:
            return resources.exit_code

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                trajectory_data = LammpsTrajectory(resources.traj_paths[0])
                self.out("trajectory_data", trajectory_data)
            except Exception as err:
                traceback.print_exc()
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data["data"]
        if "units_style" in output_data:
            output_data.update(
                get_units_dict(output_data["units_style"],
                               ["distance", "time", "energy"]))
        else:
            self.logger.warning("units missing in log")
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        if "parameters" in self.node.get_incoming().all_link_labels():
            output_data["timestep_picoseconds"] = convert_units(
                self.node.inputs.parameters.dict.timestep,
                output_data["units_style"],
                "time",
                "picoseconds",
            )
        parameters_data = Dict(dict=output_data)
        self.out("results", parameters_data)

        # parse the system data file
        sys_data_error = None
        if resources.sys_paths:
            sys_data = ArrayData()
            try:
                with open(resources.sys_paths[0]) as handle:
                    names = handle.readline().strip().split()
                for i, col in enumerate(
                        np.loadtxt(resources.sys_paths[0],
                                   skiprows=1,
                                   unpack=True,
                                   ndmin=2)):
                    sys_data.set_array(names[i], col)
            except Exception:
                traceback.print_exc()
                sys_data_error = self.exit_codes.ERROR_INFO_PARSING
            sys_data.set_attribute("units_style",
                                   output_data.get("units_style", None))
            self.out("system_data", sys_data)

        if output_data["errors"]:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if sys_data_error:
            return sys_data_error

        if not log_data.get("found_end", False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE
Ejemplo n.º 9
0
    def parse(self, **kwargs):
        """Parse the retrieved folder and store results."""
        # retrieve resources
        resources = self.get_parsing_resources(kwargs, traj_in_temp=True)
        if resources.exit_code is not None:
            return resources.exit_code

        # parse log file
        log_data, exit_code = self.parse_log_file()
        if exit_code is not None:
            return exit_code

        traj_error = None
        if not resources.traj_paths:
            traj_error = self.exit_codes.ERROR_TRAJ_FILE_MISSING
        else:
            try:
                trajectories = {
                    os.path.basename(traj_path).split("-")[0]:
                    LammpsTrajectory(traj_path)
                    for traj_path in resources.traj_paths
                }
                self.out("trajectory", trajectories)
            except Exception as err:
                traceback.print_exc()
                self.logger.error(str(err))
                traj_error = self.exit_codes.ERROR_TRAJ_PARSING

        # save results into node
        output_data = log_data["data"]
        if "units_style" in output_data:
            output_data.update(
                get_units_dict(output_data["units_style"],
                               ["distance", "time", "energy"]))
        else:
            self.logger.warning("units missing in log")
        self.add_warnings_and_errors(output_data)
        self.add_standard_info(output_data)
        if "parameters" in self.node.get_incoming().all_link_labels():
            output_data["timestep_picoseconds"] = convert_units(
                self.node.inputs.parameters.dict.timestep,
                output_data["units_style"],
                "time",
                "picoseconds",
            )
            output_data["stage_names"] = [
                s["name"] for s in self.node.inputs.parameters.dict.stages
            ]
        parameters_data = Dict(dict=output_data)
        self.out("results", parameters_data)

        # parse the system data file
        sys_data_error = None
        arrays = {}
        for sys_path in resources.sys_paths:
            stage_name = os.path.basename(sys_path).split("-")[0]
            sys_data = ArrayData()
            sys_data.set_attribute("units_style",
                                   output_data.get("units_style", None))
            try:
                with open(sys_path) as handle:
                    names = handle.readline().strip().split()
                for i, col in enumerate(
                        np.loadtxt(sys_path, skiprows=1, unpack=True,
                                   ndmin=2)):
                    sys_data.set_array(names[i], col)
                arrays[stage_name] = sys_data
            except Exception:
                traceback.print_exc()
                sys_data_error = self.exit_codes.ERROR_INFO_PARSING
        if arrays:
            self.out("system", arrays)

        # retrieve the last restart file, per stage
        restart_map = {}
        for rpath in resources.restart_paths:
            rpath_base = os.path.basename(rpath)
            match = re.match(r"([^\-]*)\-.*\.([\d]+)", rpath_base)
            if match:
                stage, step = match.groups()
                if int(step) > restart_map.get(stage, (-1, None))[0]:
                    restart_map[stage] = (int(step), rpath)

        for stage, (step, rpath) in restart_map.items():
            with io.open(rpath, "rb") as handle:
                self.retrieved.put_object_from_filelike(
                    handle, os.path.basename(rpath), "wb", force=True)

        if output_data["errors"]:
            return self.exit_codes.ERROR_LAMMPS_RUN

        if traj_error:
            return traj_error

        if sys_data_error:
            return sys_data_error

        if not log_data.get("found_end", False):
            return self.exit_codes.ERROR_RUN_INCOMPLETE