def test_lammpstraj_get_step_struct(db_test_app, data_regression):
    path = os.path.join(TEST_DIR, "input_files", "trajectory.lammpstrj")
    data = LammpsTrajectory(path)
    data_regression.check(
        recursive_round(data.get_step_structure(-1).attributes,
                        2,
                        apply_lists=True))
Beispiel #2
0
def test_lammpstraj_get_step_struct(db_test_app, data_regression):  # pylint: disable=unused-argument
    """Get the structure data for a given trajectory step"""
    path = os.path.join(TEST_DIR, 'input_files', 'trajectory.lammpstrj')
    data = LammpsTrajectory(path)
    data_regression.check(
        recursive_round(data.get_step_structure(-1).attributes,
                        2,
                        apply_lists=True))
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
    def parse(self, **kwargs):
        """
        Parse the files produced by lammps.

        It takes care of parsing the log.lammps file, the trajectory file and the
        yaml file with the final value of the variables printed in the
        ``thermo_style``.
        """
        # pylint: disable=too-many-return-statements

        try:
            out_folder = self.retrieved
        except exceptions.NotExistent:
            return self.exit_codes.ERROR_NO_RETRIEVED_FOLDER

        list_of_files = out_folder.list_object_names()

        # check log file
        if self.node.get_option('logfile_filename') not in list_of_files:
            return self.exit_codes.ERROR_LOG_FILE_MISSING
        filename = self.node.get_option('logfile_filename')
        parsed_data = parse_logfile(file_contents=self.node.outputs.retrieved.
                                    get_object_content(filename))
        if parsed_data is None:
            return self.exit_codes.ERROR_PARSING_LOGFILE
        global_data = parsed_data['global']
        arrays = parsed_data['time_dependent']

        # check final variable file
        if self.node.get_option('variables_filename') not in list_of_files:
            return self.exit_codes.ERROR_FINAL_VARIABLE_FILE_MISSING

        filename = self.node.get_option('variables_filename')
        final_variables = parse_final_data(
            file_contents=self.node.outputs.retrieved.get_object_content(
                filename))
        if final_variables is None:
            return self.exit_codes.ERROR_PARSING_FINAL_VARIABLES

        results = orm.Dict(dict={
            **final_variables, 'compute_variables': global_data
        })

        # Expose the results from the log.lammps outputs
        self.out('results', results)

        # Get the time-dependent outputs exposed as a dictionary
        time_dependent_computes = orm.Dict(dict=arrays)
        self.out('time_dependent_computes', time_dependent_computes)

        # check trajectory file
        if self.node.get_option('trajectory_filename') not in list_of_files:
            return self.exit_codes.ERROR_TRAJECTORY_FILE_MISSING
        # Gather the lammps trajectory data
        filename = self.node.get_option('trajectory_filename')
        with self.node.outputs.retrieved.open(filename) as handle:
            lammps_trajectory = LammpsTrajectory(handle)
        self.out('trajectories', lammps_trajectory)

        self.out('structure', lammps_trajectory.get_step_structure(-1))

        # check stdout
        if self.node.get_option('scheduler_stdout') not in list_of_files:
            return self.exit_codes.ERROR_STDOUT_FILE_MISSING

        # check stderr
        if self.node.get_option('scheduler_stderr') not in list_of_files:
            return self.exit_codes.ERROR_STDERR_FILE_MISSING

        return None