def test_parse_failed_optimize(data_regression):
    # type: (AiidaTestApp) -> None
    with open_resource_text("gulp", "failed", "opt_step_limit.gout") as handle:
        data, exit_code = parse_file(handle, "test_class")

    result = recursive_round(data, 6)
    result.pop("parser_version")
    data_regression.check(result)

    assert exit_code == "ERROR_OPTIMISE_MAX_ATTEMPTS"
def test_parse_polymer_opt(data_regression):
    # type: (AiidaTestApp) -> None
    """ this is a surface calculation """
    with open_resource_text("gulp", "s2_polymer_opt", "main.gout") as handle:
        data, exit_code = parse_file(handle, "test_class")

    result = recursive_round(data, 6)
    result.pop("parser_version")
    data_regression.check(result)

    assert exit_code is None
def test_parse_non_primitive_opt(data_regression):
    # type: (AiidaTestApp) -> None
    with open_resource_text("gulp", "non_primitive_opt",
                            "main.gout") as handle:
        data, exit_code = parse_file(handle, "test_class")

    result = recursive_round(data, 6)
    result.pop("parser_version")
    data_regression.check(result)

    assert exit_code is None
def test_parse_single_lj_pyrite(data_regression):
    # type: (AiidaTestApp) -> None
    with open_resource_text("gulp", "single_lj_pyrite", "main.gout") as handle:
        data, exit_code = parse_file(handle,
                                     "test_class",
                                     single_point_only=True)

    result = recursive_round(data, 6)
    result.pop("parser_version")
    data_regression.check(result)

    assert exit_code is None
Exemplo n.º 5
0
    def parse(self, **kwargs):
        """
        Parse outputs, store results in database.
        """
        try:
            output_folder = self.retrieved
        except exceptions.NotExistent:
            return self.exit_codes.ERROR_NO_RETRIEVED_FOLDER

        mainout_file = self.node.get_option("output_main_file_name")
        if mainout_file not in output_folder.list_object_names():
            return self.exit_codes.ERROR_OUTPUT_FILE_MISSING

        # parse the main output file and add nodes
        self.logger.info("parsing main out file")
        with output_folder.open(mainout_file) as handle:
            try:
                result_dict, exit_code = parse_file(
                    handle,
                    parser_class=self.__class__.__name__,
                    single_point_only=True)
            except Exception:
                traceback.print_exc()
                return self.exit_codes.ERROR_PARSING_STDOUT

        if result_dict["parser_errors"]:
            self.logger.warning(
                "the parser raised the following errors:\n{}".format(
                    "\n\t".join(result_dict["parser_errors"])))
        if result_dict["errors"]:
            self.logger.warning(
                "the calculation raised the following errors:\n{}".format(
                    "\n\t".join(result_dict["errors"])))

        # look a stderr for fortran warnings, etc,
        # e.g. IEEE_INVALID_FLAG IEEE_OVERFLOW_FLAG IEEE_UNDERFLOW_FLAG
        stderr_file = self.node.get_option("output_stderr_file_name")
        if stderr_file in output_folder.list_object_names():
            with output_folder.open(stderr_file) as handle:
                stderr_content = handle.read()
                if stderr_content:
                    self.logger.warning(
                        "the calculation stderr file was not empty:")
                    self.logger.warning(stderr_content)
                    result_dict["warnings"].append(stderr_content.strip())

        self.out("results", Dict(dict=result_dict))

        if exit_code is not None:
            return self.exit_codes[exit_code]
        return ExitCode()
def test_parse_failed():
    # type: (AiidaTestApp) -> None
    with open_resource_text("gulp", "failed", "empty_error.gout") as handle:
        data, exit_code = parse_file(handle, "test_class")

    assert exit_code == "ERROR_GULP_UNHANDLED"

    expected = {
        "parser_errors": ["Reached end of file before finding output section"],
        "parser_warnings": [],
        "parser_version": __version__,
        "gulp_version": "4.5.3",
        "errors": ["!! ERROR : input file is empty"],
        "warnings": [],
        "energy_units": "eV",
        "parser_class": "test_class",
    }

    assert data == expected