Example #1
0
def test_create_group(db_test_app):
    db_test_app.get_or_create_computer()

    with resource_context("basis_sets", "sto3g") as path:
        nfiles, nuploaded = BasisSetData.upload_basisset_family(
            path, "sto3g", "group of sto3g basis sets")

    assert (nfiles, nuploaded) == (3, 3)

    group = BasisSetData.get_basis_group("sto3g")

    assert group.description == "group of sto3g basis sets"

    groups = BasisSetData.get_basis_groups(filter_elements="O")
    # print(groups)
    assert len(groups) == 1

    # try uploading the files to a second group
    with pytest.raises(ValueError):
        with resource_context("basis_sets", "sto3g") as path:
            BasisSetData.upload_basisset_family(
                path,
                "another_sto3g",
                "another group of sto3g basis sets",
                stop_if_existing=True,
            )

    with resource_context("basis_sets", "sto3g") as path:
        nfiles, nuploaded = BasisSetData.upload_basisset_family(
            path,
            "another_sto3g",
            "another group of sto3g basis sets",
            stop_if_existing=False,
        )
    assert (nfiles, nuploaded) == (3, 0)
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)
Example #3
0
def test_basis_upload(db_test_app):

    runner = CliRunner()
    with resource_context("basis_sets", "sto3g") as path:
        result = runner.invoke(
            basisset,
            [
                "uploadfamily",
                "--path",
                str(path),
                "--name",
                "sto3g",
                "--description",
                "STO3G",
            ],
        )

    print(result.output)

    assert result.exit_code == 0

    result2 = runner.invoke(basisset, ["listfamilies", "-d"])

    print(result2.output)

    assert result2.exit_code == 0

    assert "sto3g" in result2.output
Example #4
0
def test_bases_from_struct(db_test_app):
    db_test_app.get_or_create_computer()

    with resource_context("basis_sets", "sto3g") as path:
        nfiles, nuploaded = BasisSetData.upload_basisset_family(
            path, "sto3g", "group of sto3g basis sets")

    # MgO
    import ase  # noqa: F401
    from ase.spacegroup import crystal

    atoms = crystal(
        symbols=[12, 8],
        basis=[[0, 0, 0], [0.5, 0.5, 0.5]],
        spacegroup=225,
        cellpar=[4.21, 4.21, 4.21, 90, 90, 90],
    )  # type: ase.Atoms

    # atoms[0].tag = 1
    # atoms[1].tag = 1
    atoms.set_tags([1, 1, 0, 0, 0, 0, 0, 0])

    structure_data_cls = DataFactory("structure")
    struct = structure_data_cls(ase=atoms)

    bases_dict = BasisSetData.get_basissets_by_kind(struct, "sto3g")
    # print(bases_dict)

    assert set(bases_dict.keys()) == set(["Mg", "Mg1", "O"])

    assert bases_dict["Mg"].get_basis_family_names() == ["sto3g"]
def test_calcjob_submit_mgo(db_test_app):
    # type: (AiidaTestApp, bool) -> None
    """Test submitting a calculation."""
    parameters = Dict(dict={"shrink_is": 18, "shrink_isp": 36, "npoints": 20})
    metadata = {
        "options": {
            "withmpi": False,
            "resources": {
                "num_machines": 1,
                "num_mpiprocs_per_machine": 1,
            },
            "max_wallclock_seconds": 30,
            "input_wf_name": "fort.9",
        },
        "dry_run": True,
    }

    # set up calculation
    builder = db_test_app.get_or_create_code("crystal17.ech3").get_builder()
    builder.metadata = metadata
    builder.parameters = parameters

    with resource_context("ech3", "mgo_sto3g_scf") as path:

        builder.wf_folder = RemoteData(
            remote_path=str(path),
            computer=db_test_app.get_or_create_computer())

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

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

            # Check the attributes of the returned `CalcInfo`
            assert calc_info.codes_info[0].cmdline_params == []
            assert sorted(calc_info.local_copy_list) == sorted([])
            assert sorted(calc_info.retrieve_list) == sorted(["main.out"])
            assert sorted(calc_info.retrieve_temporary_list) == sorted(
                ["DENS_CUBE.DAT", "SPIN_CUBE.DAT"])

            assert sorted(folder.get_content_list()) == sorted(
                [process_options.input_file_name])

            with folder.open(process_options.input_file_name) as f:
                input_content = f.read()

    expected_input = dedent("""\
        ECH3
        20
        END""")

    assert input_content == expected_input
Example #6
0
 def _upload(folder_name="sto3g",
             group_name="sto3g",
             stop_if_existing=True):
     with resource_context("basis_sets", folder_name) as path:
         BasisSetData.upload_basisset_family(
             path,
             group_name,
             "minimal basis sets",
             stop_if_existing=stop_if_existing,
             extension=".basis",
         )
     return BasisSetData.get_basis_group_map(group_name)
Example #7
0
def test_run_mgo_scf(db_test_app, sanitise_calc_attr, data_regression):
    # type: (AiidaTestApp) -> None
    """Test running a calculation."""
    parameters = Dict(
        dict={
            "k_points": [18, 36],
            "npoints": 100,
            "band_minimum": -10,
            "band_maximum": 10,
            "band_units": "eV",
        })
    metadata = {
        "options": {
            "withmpi": False,
            "resources": {
                "num_machines": 1,
                "num_mpiprocs_per_machine": 1,
            },
            "max_wallclock_seconds": 30,
            "input_wf_name": "fort.9",
        }
    }

    # set up calculation
    builder = db_test_app.get_or_create_code("crystal17.doss").get_builder()
    builder.metadata = metadata
    builder.parameters = parameters

    with resource_context("doss", "mgo_sto3g_scf") as path:
        builder.wf_folder = RemoteData(
            remote_path=str(path),
            computer=db_test_app.get_or_create_computer())
        output = run_get_node(builder)
        calc_node = output.node

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

    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,
        "arrays": calc_node.outputs.arrays.attributes,
    })
def test_run_mgo_scf(db_test_app, sanitise_calc_attr, data_regression):
    # type: (AiidaTestApp) -> None
    """Test running a calculation."""
    parameters = Dict(dict={
        "npoints": 20,
    })
    metadata = {
        "options": {
            "withmpi": False,
            "resources": {
                "num_machines": 1,
                "num_mpiprocs_per_machine": 1,
            },
            "max_wallclock_seconds": 30,
            "input_wf_name": "fort.9",
        }
    }

    # set up calculation
    builder = db_test_app.get_or_create_code("crystal17.ech3").get_builder()
    builder.metadata = metadata
    builder.parameters = parameters

    with resource_context("ech3", "mgo_sto3g_scf") as path:
        builder.wf_folder = RemoteData(
            remote_path=str(path),
            computer=db_test_app.get_or_create_computer())
        output = run_get_node(builder)
        calc_node = output.node

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

    calc_attributes = sanitise_calc_attr(calc_node.attributes)

    results = recursive_round(calc_node.outputs.results.attributes, 5)
    results.pop("execution_time_seconds", None)
    results.pop("parser_version", None)

    data_regression.check({
        "calc":
        calc_attributes,
        "results":
        results,
        "charge":
        recursive_round(calc_node.outputs.charge.attributes, 5),
    })
Example #9
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),
    })
def test_calcjob_submit_mgo_remote(db_test_app):
    # type: (AiidaTestApp, bool) -> None
    """Test submitting a calculation, using a remote folder 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 resource_context("newk", "mgo_sto3g_scf", "fort.9") as path:

        builder.wf_folder = RemoteData(
            remote_path=str(path),
            computer=db_test_app.get_or_create_computer())

        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
            ]
Example #11
0
def test_restart_wf_submit(
    db_test_app,
    get_structure,
    upload_basis_set_family,
    file_regression,
    data_regression,
):
    """Test restarting from a previous fort.9 file."""
    code = db_test_app.get_or_create_code("crystal17.main")

    # Prepare input parameters
    params = {
        "title": "NiO Bulk with AFM spin",
        "scf.single": "UHF",
        "scf.k_points": (8, 8),
        "scf.spinlock.SPINLOCK": (0, 15),
        "scf.numerical.FMIXING": 30,
        "scf.post_scf": ["PPAN"],
    }

    instruct = get_structure("NiO_afm")

    kind_data = KindData(
        data={
            "kind_names": ["Ni1", "Ni2", "O"],
            "spin_alpha": [True, False, False],
            "spin_beta": [False, True, False],
        })

    sym_calc = run_get_node(
        WorkflowFactory("crystal17.sym3d"),
        structure=instruct,
        settings=DataFactory("dict")(dict={
            "symprec": 0.01,
            "compute_primitive": True
        }),
    ).node
    instruct = sym_calc.get_outgoing().get_node_by_label("structure")
    symmetry = sym_calc.get_outgoing().get_node_by_label("symmetry")

    upload_basis_set_family()

    # set up calculation
    process_class = code.get_builder().process_class
    builder = process_class.create_builder(
        params,
        instruct,
        "sto3g",
        symmetry=symmetry,
        kinds=kind_data,
        code=code,
        metadata=db_test_app.get_default_metadata(with_mpi=True),
        unflatten=True,
    )

    with resource_context("crystal", "nio_sto3g_afm_scf_maxcyc") as path:
        builder.wf_folder = orm.RemoteData(computer=code.computer,
                                           remote_path=str(path))

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

        with db_test_app.sandbox_folder() as folder:
            calc_info = db_test_app.generate_calcinfo("crystal17.main", folder,
                                                      builder)
            with folder.open(process_options.input_file_name) as f:
                input_content = f.read()

    file_regression.check(input_content)
    data_regression.check(sanitize_calc_info(calc_info))
Example #12
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))
Example #13
0
def test_parse_doss_f25():
    """Test parsing good fort.25 file."""
    runner = CliRunner()
    with resource_context("doss", "mgo_sto3g_scf", "fort.25") as path:
        result = runner.invoke(doss_f25, [str(path)])
    assert result.exit_code == 0, result.stdout
Example #14
0
def test_parse_stdout():
    """Test parsing good stdout file."""
    runner = CliRunner()
    with resource_context("crystal", "mgo_sto3g_scf", "main.out") as path:
        result = runner.invoke(stdout, [str(path)])
    assert result.exit_code == 0, result.stdout