def test_failed_optimisation(db_test_app, plugin_name, data_regression):
    """Test that if the optimisation is killed before completion, the trajectory data is still available."""
    retrieved = FolderData()
    with open_resource_binary(
        "crystal", "nio_sto3g_afm_opt_walltime", "main.out"
    ) as handle:
        retrieved.put_object_from_filelike(handle, "main.out", mode="wb")
    with open_resource_binary(
        "crystal", "nio_sto3g_afm_opt_walltime", "_scheduler-stderr.txt"
    ) as handle:
        retrieved.put_object_from_filelike(handle, "_scheduler-stderr.txt", mode="wb")

    calc_node = db_test_app.generate_calcjob_node(plugin_name, retrieved)

    with resource_context("crystal", "nio_sto3g_afm_opt_walltime") as path:
        results, calcfunction = db_test_app.parse_from_node(
            plugin_name, calc_node, retrieved_temp=str(path)
        )

    # print(get_calcjob_report(calc_node))

    assert calcfunction.is_finished, calcfunction.exception
    assert calcfunction.is_failed, calcfunction.exit_status
    assert (
        calcfunction.exit_status
        == calc_node.process_class.exit_codes.ERROR_OUT_OF_WALLTIME.status
    )

    assert "optimisation" in results, results
    data_regression.check(results["optimisation"].attributes)
def test_run_mgo_scf_folder(db_test_app, sanitise_calc_attr, data_regression):
    # type: (AiidaTestApp) -> None
    """Test running a calculation."""
    # set up calculation
    builder = db_test_app.get_or_create_code("crystal17.newk").get_builder()
    builder.metadata = get_metadata()
    builder.parameters = Dict(dict={"k_points": [18, 36]})

    wf_folder = FolderData()
    with open_resource_binary("newk", "mgo_sto3g_scf", "fort.9") as handle:
        wf_folder.put_object_from_filelike(handle, "fort.9", mode="wb")

    builder.wf_folder = wf_folder

    output = run_get_node(builder)
    calc_node = output.node

    db_test_app.check_calculation(calc_node, ["results"])

    calc_attributes = sanitise_calc_attr(calc_node.attributes)

    results = {
        k: round(i, 7) if isinstance(i, float) else i
        for k, i in calc_node.outputs.results.attributes.items()
        if k not in ["execution_time_seconds"]
    }

    data_regression.check({
        "calc": calc_attributes,
        "results": results,
    })
示例#3
0
    def _get_cif(name):
        from aiida.orm import CifData

        if name == "pyrite":
            with open_resource_binary("cif", "pyrite.cif") as handle:
                return CifData(file=handle)
        raise ValueError(name)
示例#4
0
def test_run_prop_mgo_no_scf(db_test_app, sanitise_calc_attr, data_regression):
    """Test the workchains when a folder is supplied that contains the wavefunction file."""
    clear_spec()

    wc_builder = CryPropertiesWorkChain.get_builder()

    with open_resource_binary("doss", "mgo_sto3g_scf", "fort.9") as handle:
        wc_builder.wf_folder = SinglefileData(handle)

    wc_builder.doss.code = db_test_app.get_or_create_code("crystal17.doss")
    wc_builder.doss.parameters = get_parameters()["doss"]
    wc_builder.doss.metadata = db_test_app.get_default_metadata()

    wc_builder.ech3.code = db_test_app.get_or_create_code("crystal17.ech3")
    wc_builder.ech3.parameters = get_parameters()["ech3"]
    wc_builder.ech3.metadata = db_test_app.get_default_metadata()

    outputs, wc_node = run_get_node(wc_builder)
    sys.stderr.write(get_workchain_report(wc_node, "REPORT"))

    wk_attributes = sanitise_calc_attr(wc_node.attributes)

    data_regression.check({
        "calc_node":
        wk_attributes,
        "incoming":
        sorted(wc_node.get_incoming().all_link_labels()),
        "outgoing":
        sorted(wc_node.get_outgoing().all_link_labels()),
        # "results": outputs["results"].attributes
    })
示例#5
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"
示例#6
0
def test_calcjob_submission(db_test_app, data_regression):
    # type: (AiidaTestApp) -> None
    """Test submitting a calculation."""
    from aiida.orm import SinglefileData

    # Prepare input parameters
    code = db_test_app.get_or_create_code("crystal17.basic")
    with open_resource_binary("crystal", "mgo_sto3g_scf", "INPUT") as handle:
        infile = SinglefileData(file=handle)
    infile.store()

    # set up calculation
    builder = code.get_builder()
    builder.metadata.options.withmpi = False
    builder.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    builder.input_file = infile

    with db_test_app.sandbox_folder() as folder:
        calc_info = db_test_app.generate_calcinfo("crystal17.basic", folder,
                                                  builder)

    data_regression.check(sanitize_calc_info(calc_info))
def test_create_builder(db_test_app, data_regression):

    with SandboxFolder() as folder:
        with open_resource_binary("crystal", "nio_sto3g_afm_scf", "INPUT") as handle:
            folder.create_file_from_filelike(handle, "INPUT", mode="wb")
        with open_resource_binary("crystal", "nio_sto3g_afm_scf", "main.out") as handle:
            folder.create_file_from_filelike(handle, "main.out", mode="wb")

        remote = RemoteData(
            remote_path=folder.abspath, computer=db_test_app.get_or_create_computer()
        )

        builder = populate_builder(remote)

    assert set(builder["basissets"].keys()) == set(["Ni", "O"])

    data_regression.check(builder.parameters.attributes, "test_create_builder_params")

    expected_settings = {
        "kinds": {
            "spin_alpha": ["Ni"],
            "spin_beta": ["Ni1"],
        },
        "operations": [
            [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
            [-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0],
            [0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
            [0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0],
            [-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0],
            [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
            [0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0],
            [0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
            [-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0],
            [0.0, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
            [0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0],
            [-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0],
            [1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
            [0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0],
            [0.0, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
        ],
        "space_group": 1,
        "crystal_type": 1,
        "centring_code": 1,
    }

    assert builder.symmetry.compare_operations(expected_settings["operations"]) == {}
示例#8
0
def test_calcjob_run(db_test_app, infolder, external_geom, data_regression):
    # type: (AiidaTestApp, str, str) -> None
    """Test running an optimisation calculation."""
    from aiida.engine import run_get_node
    from aiida.orm import SinglefileData

    code = db_test_app.get_or_create_code("crystal17.basic")

    # set up calculation
    builder = code.get_builder()
    builder.metadata = {
        "options": {
            "withmpi": False,
            "resources": {
                "num_machines": 1,
                "num_mpiprocs_per_machine": 1,
            },
            "max_wallclock_seconds": 60,
        }
    }
    # .crystal.ingui # .crystal.d12
    # Prepare input parameters
    with open_resource_binary("crystal", infolder, "INPUT") as handle:
        infile = SinglefileData(file=handle)
    builder.input_file = infile
    if external_geom:
        with open_resource_binary("crystal", infolder, "fort.34") as handle:
            ingui = SinglefileData(file=handle)
        builder.input_external = ingui

    outcome = run_get_node(builder)
    # result = outcome.result
    calc_node = outcome.node

    db_test_app.check_calculation(calc_node,
                                  ["results", "structure", "symmetry"])

    results_attributes = calc_node.outputs.results.attributes
    results_attributes.pop("execution_time_seconds")
    results_attributes.pop("parser_version")
    results_attributes = recursive_round(results_attributes, 9)
    data_regression.check(results_attributes)

    data_regression.check(
        recursive_round(calc_node.outputs.structure.attributes, 9),
        "test_calcjob_run_{}_{}_struct".format(infolder, external_geom),
    )
示例#9
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,
    ]
示例#10
0
def test_builder_populated(db_test_app):
    clear_spec()
    wc_builder = CryPropertiesWorkChain.get_builder()
    with open_resource_binary("doss", "mgo_sto3g_scf", "fort.9") as handle:
        wc_builder.wf_folder = SinglefileData(handle)
    wc_builder.doss.code = db_test_app.get_or_create_code("crystal17.doss")
    wc_builder.doss.parameters = get_parameters()["doss"]
    wc_builder.doss.metadata = db_test_app.get_default_metadata()
    db_test_app.generate_context(CryPropertiesWorkChain, wc_builder, [])
def test_full_nio_afm(db_test_app, data_regression):

    code = db_test_app.get_or_create_code("crystal17.main")

    metadata = get_default_metadata()
    metadata["options"].update(
        {"input_file_name": "other.d12", "output_main_file_name": "other2.out"}
    )

    with SandboxFolder() as folder:
        with open_resource_binary("crystal", "nio_sto3g_afm_scf", "INPUT") as handle:
            folder.create_file_from_filelike(handle, "other.d12", mode="wb")
        with open_resource_binary("crystal", "nio_sto3g_afm_scf", "main.out") as handle:
            folder.create_file_from_filelike(handle, "other2.out", mode="wb")

        remote = RemoteData(
            remote_path=folder.abspath, computer=db_test_app.get_or_create_computer()
        )

        builder = populate_builder(remote, code=code, metadata=metadata)

        node = immigrate_existing(builder, remote)

    attributes = node.attributes
    attributes["remote_workdir"] = "path/to/remote"
    attributes["version"] = None

    data_regression.check(attributes)

    assert set(node.inputs) == set(
        [
            "basissets__Ni",
            "basissets__O",
            "parameters",
            "structure",
            "symmetry",
            "kinds",
            "code",
        ]
    )

    assert set(node.outputs) == set(["results", "remote_folder", "retrieved"])
示例#12
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)
示例#13
0
def test_missing_isofile(db_test_app, plugin_name):

    retrieved = FolderData()
    with open_resource_binary("doss", "cubic_rocksalt_orbitals",
                              "cubic-rocksalt_2x1_pdos.doss.out") as handle:
        retrieved.put_object_from_filelike(handle, "main.out", mode="wb")

    calc_node = db_test_app.generate_calcjob_node(plugin_name, retrieved)
    results, calcfunction = db_test_app.parse_from_node(plugin_name, calc_node)

    assert calcfunction.is_finished, calcfunction.exception
    assert calcfunction.is_failed, calcfunction.exit_status
    assert (calcfunction.exit_status == calc_node.process_class.exit_codes.
            ERROR_ISOVALUE_FILE_MISSING.status)
示例#14
0
def test_failed_scf_convergence(db_test_app, plugin_name):

    retrieved = FolderData()
    with open_resource_binary("crystal", "failed", "FAILED_SCF_bcc_iron.out") as handle:
        retrieved.put_object_from_filelike(handle, "main.out", mode="wb")

    calc_node = db_test_app.generate_calcjob_node(plugin_name, retrieved)
    results, calcfunction = db_test_app.parse_from_node(plugin_name, calc_node)

    assert calcfunction.is_finished, calcfunction.exception
    assert calcfunction.is_failed, calcfunction.exit_status
    assert (
        calcfunction.exit_status
        == calc_node.process_class.exit_codes.UNCONVERGED_SCF.status
    )
示例#15
0
def test_success(db_test_app, plugin_name, data_regression):

    retrieved = FolderData()
    with open_resource_binary("doss", "cubic_rocksalt_orbitals",
                              "cubic-rocksalt_2x1_pdos.doss.out") as handle:
        retrieved.put_object_from_filelike(handle, "main.out", mode="wb")
    with open_resource_binary("doss", "cubic_rocksalt_orbitals",
                              "cubic-rocksalt_2x1_pdos.doss.f25") as handle:
        retrieved.put_object_from_filelike(handle, "fort.25", mode="wb")

    calc_node = db_test_app.generate_calcjob_node(plugin_name, retrieved)
    results, calcfunction = db_test_app.parse_from_node(plugin_name, calc_node)

    assert calcfunction.is_finished_ok, calcfunction.exception
    assert "results" in results
    assert "arrays" in results
    results_attr = {
        k: round(i, 7) if isinstance(i, float) else i
        for k, i in results["results"].attributes.items()
    }
    data_regression.check({
        "results": results_attr,
        "arrays": results["arrays"].attributes
    })
示例#16
0
def test_missing_density(db_test_app, plugin_name):

    retrieved = FolderData()
    with open_resource_binary("ech3", "mgo_sto3g_scf", "main.out") as handle:
        retrieved.put_object_from_filelike(handle, "main.out", mode="wb")

    calc_node = db_test_app.generate_calcjob_node(plugin_name, retrieved)
    with db_test_app.sandbox_folder() as temp_folder:
        results, calcfunction = db_test_app.parse_from_node(
            plugin_name, calc_node, retrieved_temp=temp_folder.abspath)

    assert calcfunction.is_finished, calcfunction.exception
    assert calcfunction.is_failed, calcfunction.exit_status
    assert (calcfunction.exit_status == calc_node.process_class.exit_codes.
            ERROR_DENSITY_FILE_MISSING.status)
示例#17
0
def test_calcjob_submit_mgo_singlefile(db_test_app):
    # type: (AiidaTestApp, bool) -> None
    """Test submitting a calculation, using a singlefile input for wf_input."""
    builder = db_test_app.get_or_create_code("crystal17.newk").get_builder()
    builder.metadata = get_metadata()
    builder.parameters = Dict(dict={"k_points": [18, 36]})

    with open_resource_binary("newk", "mgo_sto3g_scf", "fort.9") as handle:
        builder.wf_folder = SinglefileData(handle)

    process_options = builder.process_class(inputs=builder).metadata.options

    with db_test_app.sandbox_folder() as folder:
        db_test_app.generate_calcinfo("crystal17.newk", folder, builder)
        assert folder.get_content_list() == [process_options.input_file_name]
示例#18
0
def test_init_steps(db_test_app, data_regression):
    clear_spec()
    wc_builder = CryPropertiesWorkChain.get_builder()
    with open_resource_binary("doss", "mgo_sto3g_scf", "fort.9") as handle:
        wc_builder.wf_folder = SinglefileData(handle)
    wc_builder.doss.code = db_test_app.get_or_create_code("crystal17.doss")
    wc_builder.doss.parameters = get_parameters()["doss"]
    wc_builder.doss.metadata = db_test_app.get_default_metadata()
    wc_builder.test_run = True
    steps = ["check_inputs", "check_wf_folder"]
    wkchain, step_outcomes, context = db_test_app.generate_context(
        CryPropertiesWorkChain, wc_builder, steps)

    data_regression.check(context)
    try:
        assert step_outcomes[0] is None
        assert step_outcomes[1] is False
    except Exception:
        sys.stderr.write(get_workchain_report(wkchain, "REPORT"))
        raise
示例#19
0
def test_success(db_test_app, plugin_name, data_regression):

    retrieved = FolderData()
    with open_resource_binary("ech3", "mgo_sto3g_scf", "main.out") as handle:
        retrieved.put_object_from_filelike(handle, "main.out", mode="wb")

    calc_node = db_test_app.generate_calcjob_node(plugin_name, retrieved)
    with resource_context("ech3", "mgo_sto3g_scf") as path:
        results, calcfunction = db_test_app.parse_from_node(
            plugin_name, calc_node, retrieved_temp=str(path))

    assert calcfunction.is_finished_ok, calcfunction.exception
    assert "results" in results
    assert "charge" in results
    data_regression.check({
        "results":
        recursive_round(results["results"].attributes, 7),
        "charge":
        recursive_round(results["charge"].attributes, 7),
    })
示例#20
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]
示例#21
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))
def test_full_mgo_opt(db_test_app, data_regression):

    code = db_test_app.get_or_create_code("crystal17.main")

    with SandboxFolder() as folder:
        with open_resource_binary("crystal", "mgo_sto3g_opt", "INPUT") as handle:
            folder.create_file_from_filelike(handle, "INPUT", mode="wb")
        with open_resource_binary("crystal", "mgo_sto3g_opt", "main.out") as handle:
            folder.create_file_from_filelike(handle, "main.out", mode="wb")

        remote = RemoteData(
            remote_path=folder.abspath, computer=db_test_app.get_or_create_computer()
        )

        builder = populate_builder(remote, code=code, metadata=get_default_metadata())

        node = immigrate_existing(builder, remote)

    attributes = node.attributes
    attributes["remote_workdir"] = "path/to/remote"
    attributes["version"] = None

    data_regression.check(attributes)

    assert set(node.inputs) == set(
        ["basissets__Mg", "basissets__O", "parameters", "structure", "symmetry", "code"]
    )

    assert set(node.outputs) == set(
        ["results", "retrieved", "structure", "remote_folder"]
    )

    expected_instruct_attrs = {
        "cell": [[0.0, 2.105, 2.105], [2.105, 0.0, 2.105], [2.105, 2.105, 0.0]],
        "kinds": [
            {"mass": 24.305, "name": "Mg", "symbols": ["Mg"], "weights": [1.0]},
            {"mass": 15.9994, "name": "O", "symbols": ["O"], "weights": [1.0]},
        ],
        "pbc1": True,
        "pbc2": True,
        "pbc3": True,
        "sites": [
            {"kind_name": "Mg", "position": [0.0, 0.0, 0.0]},
            {"kind_name": "O", "position": [2.105, 2.105, 2.105]},
        ],
    }

    assert (
        edict.diff(
            dict(node.inputs.structure.attributes),
            expected_instruct_attrs,
            np_allclose=True,
            atol=1e-3,
        )
        == {}
    )

    expected_outstruct_attrs = {
        "cell": [
            [0.0, 1.94218061274, 1.94218061274],
            [1.94218061274, 0.0, 1.94218061274],
            [1.94218061274, 1.94218061274, 0.0],
        ],
        "kinds": [
            {"mass": 24.305, "name": "Mg", "symbols": ["Mg"], "weights": [1.0]},
            {"mass": 15.9994, "name": "O", "symbols": ["O"], "weights": [1.0]},
        ],
        "pbc1": True,
        "pbc2": True,
        "pbc3": True,
        "sites": [
            {"kind_name": "Mg", "position": [0.0, 0.0, 0.0]},
            {
                "kind_name": "O",
                "position": [1.94218061274, 1.94218061274, 1.94218061274],
            },
        ],
    }

    assert (
        edict.diff(
            dict(node.outputs.structure.attributes),
            expected_outstruct_attrs,
            np_allclose=True,
            atol=1e-3,
        )
        == {}
    )
示例#23
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"]
示例#24
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
def test_parse_fort9(data_regression):
    with open_resource_binary("ech3", "mgo_sto3g_scf", "fort.9") as handle:
        results = parse_fort9(handle)

    data_regression.check(recursive_round(results._asdict(), 7))
示例#26
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"])