Пример #1
0
def test_open_gcube(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    with node.open_cube_file() as handle:
        line = handle.readline().strip()
    assert line == "Charge density - 3D GRID - GAUSSIAN CUBE FORMAT MgO Bulk"
Пример #2
0
def test_compute_integration_atom(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    assert [round(v, 1) for v in node.compute_integration_atom((0, 1), 2)] == [
        18.8,
        3.8,
    ]
Пример #3
0
def test_compute_integration_sphere(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    assert (round(
        node.compute_integration_sphere((0, 0, 0), 10,
                                        (False, False, False))[0], 1) == 18.6)
    assert (round(
        node.compute_integration_sphere((0, 0, 0), 1,
                                        (False, False, False))[0], 1) == 2.0)
    assert (round(
        node.compute_integration_sphere((0, 0, 0), 1, (True, True, True))[0],
        1) == 17.2)
Пример #4
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

        # parse stderr
        pbs_error = None
        sterr_file = self.node.get_option("scheduler_stderr")
        if sterr_file in output_folder.list_object_names():
            with output_folder.open(sterr_file) as fileobj:
                pbs_exit_code = parse_pbs_stderr(fileobj)
            if pbs_exit_code:
                pbs_error = self.exit_codes[pbs_exit_code]

        # parse stdout file
        stdout_error = None
        stdout_data = {}
        stdout_fname = self.node.get_option("stdout_file_name")
        if stdout_fname not in self.retrieved.list_object_names():
            stdout_error = self.exit_codes.ERROR_OUTPUT_FILE_MISSING
        else:
            with output_folder.open(stdout_fname) as handle:
                stdout_data = read_properties_stdout(handle.read())
            stdout_exit_code = stdout_data.pop("exit_code", None)
            if stdout_exit_code:
                stdout_error = self.exit_codes[stdout_exit_code]

        # parse density file(s)
        density_error = None
        charge_cube = None
        spin_cube = None

        if "retrieved_temporary_folder" not in kwargs:
            density_error = self.exit_codes.ERROR_TEMP_FOLDER_MISSING
        else:
            temporary_folder = kwargs["retrieved_temporary_folder"]
            list_of_temp_files = os.listdir(temporary_folder)
            output_charge_fname = self.node.get_option("output_charge_fname")
            output_spin_fname = self.node.get_option("output_spin_fname")

            if output_charge_fname not in list_of_temp_files:
                density_error = self.exit_codes.ERROR_DENSITY_FILE_MISSING
            else:
                try:
                    charge_cube = GaussianCube(
                        os.path.join(temporary_folder, output_charge_fname)
                    )
                except Exception:
                    traceback.print_exc()
                    density_error = self.exit_codes.ERROR_PARSING_DENSITY_FILE
            if output_spin_fname in list_of_temp_files:
                try:
                    spin_cube = GaussianCube(
                        os.path.join(temporary_folder, output_spin_fname)
                    )
                except Exception:
                    traceback.print_exc()
                    density_error = self.exit_codes.ERROR_PARSING_DENSITY_FILE

        stdout_data["parser_version"] = str(__version__)
        stdout_data["parser_class"] = str(self.__class__.__name__)

        # log errors
        errors = stdout_data.get("errors", [])
        parser_errors = stdout_data.get("parser_errors", [])
        if parser_errors:
            self.logger.warning(
                "the parser raised the following errors:\n{}".format(
                    "\n\t".join(parser_errors)
                )
            )
        if errors:
            self.logger.warning(
                "the calculation raised the following errors:\n{}".format(
                    "\n\t".join(errors)
                )
            )

        # make output nodes
        self.out("results", Dict(dict=stdout_data))
        if charge_cube:
            self.out("charge", charge_cube)
        if spin_cube:
            self.out("spin", spin_cube)

        if pbs_error is not None:
            return pbs_error

        if stdout_error is not None:
            return stdout_error

        if density_error is not None:
            return density_error

        return ExitCode()
Пример #5
0
def test_write_gcube_to_vesta(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf", "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    with db_test_app.sandbox_folder() as folder:
        write_gcube_to_vesta(node, folder.abspath, "test")
        assert sorted(folder.get_content_list()) == sorted(["test.cube", "test.vesta"])
Пример #6
0
def test_compute_integration_cell(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    assert round(node.compute_integration_cell(), 1) == 18.6
Пример #7
0
def test_get_ase(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    atoms = node.get_ase()
    assert atoms.get_chemical_symbols() == ["Mg", "O"]
Пример #8
0
def test_get_cube_data(db_test_app):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    data = node.get_cube_data()
    assert data.atoms_atomic_number == [12, 8]
Пример #9
0
def test_read_fileobj(db_test_app, data_regression):
    with open_resource_binary("ech3", "mgo_sto3g_scf",
                              "DENS_CUBE.DAT") as handle:
        node = GaussianCube(handle)
    data_regression.check(recursive_round(node.attributes, 5))
Пример #10
0
def test_read_filepath(db_test_app, data_regression):
    with resource_context("ech3", "mgo_sto3g_scf", "DENS_CUBE.DAT") as path:
        node = GaussianCube(str(path))
    data_regression.check(recursive_round(node.attributes, 5))