Exemplo n.º 1
0
def test_calcjob_submit_mgo(db_test_app, input_symmetry, get_structure,
                            data_regression, file_regression):
    """Test submitting a calculation."""
    code = db_test_app.get_or_create_code("crystal17.main")

    # Prepare input parameters
    inparams = CryInputParamsData(data={
        "title": "MgO Bulk",
        "scf": {
            "k_points": (8, 8)
        }
    })

    instruct = get_structure("MgO")

    sym_calc = run_get_node(
        WorkflowFactory("crystal17.sym3d"),
        structure=instruct,
        settings=orm.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")

    with open_resource_text("basis_sets", "sto3g", "sto3g_Mg.basis") as handle:
        mg_basis, _ = BasisSetData.get_or_create(handle)
    with open_resource_text("basis_sets", "sto3g", "sto3g_O.basis") as handle:
        o_basis, _ = BasisSetData.get_or_create(handle)

    # set up calculation
    builder = code.get_builder()
    builder.metadata = db_test_app.get_default_metadata(dry_run=True)
    builder.parameters = inparams
    builder.structure = instruct
    builder.basissets = {"Mg": mg_basis, "O": o_basis}
    if input_symmetry:
        builder.symmetry = symmetry

    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()
        with folder.open("fort.34") as f:
            gui_content = f.read()  # noqa: F841
            # TODO test fort.34 (but rounded)

    file_regression.check(input_content)
    data_regression.check(sanitize_calc_info(calc_info))
Exemplo n.º 2
0
def test_basis_show(db_test_app):

    with open_resource_text("basis_sets", "sto3g", "sto3g_O.basis") as handle:
        node, created = BasisSetData.get_or_create(handle)

    runner = CliRunner()
    result = runner.invoke(basisset, ["show", str(node.pk)])

    assert result.exit_code == 0

    expected = """\
        atomic_number: 8
        author:        John Smith
        basis_type:    all-electron
        class:         sto3g
        element:       O
        filename:      sto3g_O.basis
        md5:           1ca6e23f7f1b1f5517117bec1d581ca2
        num_shells:    2
        orbital_types: [S, SP]
        year:          1999
        """

    assert dedent(expected) == str(result.output)

    result2 = runner.invoke(basisset, ["show", "-c", str(node.pk)])

    assert result2.exit_code == 0
def test_read_crystal_fort25(data_regression):
    with open_resource_text(
        "doss", "cubic_rocksalt_orbitals", "cubic-rocksalt_2x1_pdos.doss.f25"
    ) as handle:
        data, arrays = parse_crystal_fort25_aiida(handle)

    data_regression.check(
        {"results": recursive_round(data, 9), "arrays": recursive_round(arrays, 9)}
    )
Exemplo n.º 4
0
def test_create_builder(db_test_app, get_structure):
    """Test preparation of inputs."""
    db_test_app.get_or_create_code("crystal17.main")

    inparams = {"scf.k_points": (8, 8)}

    instruct = get_structure("MgO")
    with open_resource_text("basis_sets", "sto3g", "sto3g_Mg.basis") as handle:
        mg_basis, _ = BasisSetData.get_or_create(handle)
    with open_resource_text("basis_sets", "sto3g", "sto3g_O.basis") as handle:
        o_basis, _ = BasisSetData.get_or_create(handle)

    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")

    calc_cls = CalculationFactory("crystal17.main")
    builder = calc_cls.create_builder(
        inparams,
        instruct,
        {
            "O": o_basis,
            "Mg": mg_basis
        },
        symmetry=symmetry,
        unflatten=True,
    )

    assert isinstance(builder.structure, orm.StructureData)
    builder.parameters
Exemplo n.º 5
0
def test_create_single_from_file(db_test_app):
    db_test_app.get_or_create_computer()

    with open_resource_text("basis_sets", "sto3g", "sto3g_Mg.basis") as handle:
        basis = BasisSetData(filepath=handle)

    print(basis.filename)

    expected_meta = {
        "num_shells": 3,
        "author": "John Smith",
        "atomic_number": 12,
        "filename": "sto3g_Mg.basis",
        "element": "Mg",
        "year": 1999,
        "basis_type": "all-electron",
        "class": "sto3g",
        "md5": "0731ecc3339d2b8736e61add113d0c6f",
        "orbital_types": ["S", "SP", "SP"],
    }

    assert basis.metadata == expected_meta

    expected_content = """\
12 3
1 0 3  2.  0.
1 1 3  8.  0.
1 1 3  2.  0."""
    assert basis.content == expected_content

    basis.store()

    # try retrieving a pre-existing (stored) basis
    with open_resource_text("basis_sets", "sto3g", "sto3g_Mg.basis") as handle:
        basis, created = BasisSetData.get_or_create(basis_file=handle)
    assert not created
Exemplo n.º 6
0
def test_create_vesta_input(file_regression):

    with open_resource_text("ech3", "mgo_sto3g_scf", "DENS_CUBE.DAT") as handle:
        cube_data = read_gaussian_cube(handle, return_density=False)

    atoms = ase.Atoms(
        cell=cube_data.cell,
        positions=cube_data.atoms_positions,
        numbers=cube_data.atoms_atomic_number,
        pbc=True,
    )

    content = create_vesta_input(
        atoms,
        "input.cube",
        settings={
            "show_compass": False,
            "bonds": {"compute": [["Mg", "O", 0, 3, 0, 0, True, False]]},
        },
    )
    file_regression.check(content, extension=".vesta")
def test_read_density_cube(data_regression):

    with open_resource_text("ech3", "mgo_sto3g_scf", "DENS_CUBE.DAT") as handle:
        data = read_gaussian_cube(handle, return_density=True)._asdict()
    data.pop("density")
    data_regression.check(recursive_round(data, 2))