Exemplo n.º 1
0
        print(
            "Pseudo or pseudo family not found. You may want to load the "
            "pseudo family, or set auto_pseudos to False.")
        raise
else:
    raw_pseudos = [
        ("Ba.pbesol-spn-rrkjus_psl.0.2.3-tot-pslib030.UPF", 'Ba', 'pbesol'),
        ("Ti.pbesol-spn-rrkjus_psl.0.2.3-tot-pslib030.UPF", 'Ti', 'pbesol'),
        ("O.pbesol-n-rrkjus_psl.0.1-tested-pslib030.UPF", 'O', 'pbesol')
    ]

    pseudos_to_use = {}
    for fname, elem, pot_type in raw_pseudos:
        absname = os.path.realpath(
            os.path.join(os.path.dirname(__file__), "data", fname))
        pseudo, created = UpfData.get_or_create(absname, use_first=True)
        if created:
            print "Created the pseudo for {}".format(elem)
        else:
            print "Using the pseudo for {} from DB: {}".format(elem, pseudo.pk)
        pseudos_to_use[elem] = pseudo

    for k, v in pseudos_to_use.iteritems():
        calc.use_pseudo(v, kind=k)

calc.use_kpoints(kpoints)

if settings is not None:
    calc.use_settings(settings)
#from aiida.orm.data.remote import RemoteData
#calc.set_outdir(remotedata)
Exemplo n.º 2
0
def create_inputs(inpath, outpath):
    """ create ``crystal17.main`` input nodes from an existing run

    NB: none of the nodes are stored, also
    existing basis will be retrieved if availiable

    :param inpath: path to .d12 file
    :param outpath: path to .out file
    :return: dictionary of inputs, with keys 'structure', 'parameters', 'settings', 'structure', 'basis'
    """
    from aiida.orm import DataFactory, CalculationFactory
    calc_cls = CalculationFactory('crystal17.main')
    basis_cls = DataFactory('crystal17.basisset')
    struct_cls = DataFactory('structure')
    structsettings_cls = DataFactory('crystal17.structsettings')

    inputs = {}

    with open(inpath) as f:
        d12content = f.read()

    output_dict, basis_sets, atom_props = extract_data(d12content)

    cryparse = CrystalOutputPlugin()
    if not os.path.exists(outpath):
        raise OutputParsingError(
            "The raw data file does not exist: {}".format(outpath))
    with open(outpath) as f:
        try:
            data = cryparse.read_file(f, log_warnings=False)
        except IOError as err:
            raise OutputParsingError(
                "Error in CRYSTAL 17 run output: {}".format(err))

    # we retrieve the initial primitive geometry and symmetry
    atoms = _create_atoms(data)

    # convert fragment (i.e. unfixed) to fixed
    if "fragment" in atom_props:
        frag = atom_props.pop("fragment")
        atom_props["fixed"] = [
            i + 1 for i in range(atoms.get_number_of_atoms())
            if i + 1 not in frag
        ]

    atoms.set_tags(_create_tags(atom_props, atoms))

    structure = struct_cls(ase=atoms)
    inputs['structure'] = structure

    settings_dict = {"kinds": {}}
    for key, vals in atom_props.items():
        settings_dict["kinds"][key] = [
            structure.sites[i - 1].kind_name for i in vals
        ]

    settings_dict["operations"] = data["initial"]["primitive_symmops"]
    # TODO retrieve centering code, crystal system and spacegroup
    settings_dict["space_group"] = 1
    settings_dict["crystal_type"] = 1
    settings_dict["centring_code"] = 1
    settings = structsettings_cls(data=settings_dict)

    parameters = calc_cls.prepare_and_validate(output_dict, structure,
                                               settings)
    inputs['parameters'] = parameters
    inputs['settings'] = settings

    inputs["basis"] = {}
    for bset in basis_sets:

        bfile = tempfile.NamedTemporaryFile(delete=False)
        try:
            with open(bfile.name, "w") as f:
                f.write(bset)
            bdata, _ = basis_cls.get_or_create(
                bfile.name, use_first=False, store_basis=False)
            # TODO report if bases created or retrieved
        finally:
            os.remove(bfile.name)

        inputs["basis"][bdata.element] = bdata

    return inputs
Exemplo n.º 3
0
def test_submit_mgo(new_database, new_workdir):
    """Test submitting a calculation"""
    from aiida.orm import DataFactory
    ParameterData = DataFactory('parameter')
    StructureData = DataFactory('structure')
    BasisSetData = DataFactory('crystal17.basisset')
    from aiida.common.folders import SandboxFolder

    # get code
    code = get_main_code(new_workdir)

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

    # MgO
    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])
    instruct = StructureData(ase=atoms)

    from aiida_crystal17.workflows.symmetrise_3d_struct import (
        run_symmetrise_3d_structure)
    instruct, settings = run_symmetrise_3d_structure(instruct)

    mg_basis, _ = BasisSetData.get_or_create(
        os.path.join(TEST_DIR, "input_files", "sto3g", 'sto3g_Mg.basis'))
    o_basis, _ = BasisSetData.get_or_create(
        os.path.join(TEST_DIR, "input_files", "sto3g", 'sto3g_O.basis'))

    # set up calculation
    calc = code.new_calc()
    # calc.label = "aiida_crystal17 test"
    # calc.description = "Test job submission with the aiida_crystal17 plugin"
    # calc.set_max_wallclock_seconds(30)
    calc.set_withmpi(False)
    calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})

    calc.use_parameters(inparams)
    calc.use_structure(instruct)
    calc.use_settings(settings)
    calc.use_basisset(mg_basis, "Mg")
    calc.use_basisset(o_basis, "O")

    calc.store_all()

    # output input files and scripts to temporary folder
    with SandboxFolder() as folder:
        subfolder, script_filename = calc.submit_test(folder=folder)
        print("inputs created successfully at {}".format(subfolder.abspath))
        print([
            os.path.basename(p)
            for p in glob.glob(os.path.join(subfolder.abspath, "*"))
        ])
        with open(os.path.join(subfolder.abspath,
                               calc._DEFAULT_INPUT_FILE)) as f:
            input_content = f.read()
        with open(os.path.join(subfolder.abspath,
                               calc._DEFAULT_EXTERNAL_FILE)) as f:
            gui_content = f.read()

    expected_input = """MgO Bulk
EXTERNAL
END
12 3
1 0 3  2.  0.
1 1 3  8.  0.
1 1 3  2.  0.
8 2
1 0 3  2.  0.
1 1 3  6.  0.
99 0
END
SHRINK
8 8
END
"""

    assert input_content == expected_input

    expected_gui = [
        '3 5 6', '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        ' -2.105000000E+00  -2.105000000E+00   0.000000000E+00',
        ' -2.105000000E+00   0.000000000E+00  -2.105000000E+00', '48',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -2.105000000E+00   0.000000000E+00  -2.105000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        ' -2.105000000E+00  -4.210000000E+00  -2.105000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -2.105000000E+00   0.000000000E+00  -2.105000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -2.105000000E+00  -4.210000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00   0.000000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -4.210000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00   0.000000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -4.210000000E+00  -2.105000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00   0.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        ' -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        '  1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00   1.000000000E+00',
        '  0.000000000E+00  -1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00',
        ' -1.000000000E+00   0.000000000E+00   0.000000000E+00',
        '  0.000000000E+00   0.000000000E+00  -1.000000000E+00',
        '  0.000000000E+00   1.000000000E+00   0.000000000E+00',
        '  0.000000000E+00  -2.105000000E+00  -2.105000000E+00', '2',
        ' 12  -2.105000000E+00  -2.105000000E+00  -4.210000000E+00',
        '  8  -2.105000000E+00  -2.105000000E+00  -2.105000000E+00', '225 48'
    ]

    gui_content_lines = gui_content.splitlines()

    # print(gui_content_lines)

    # difflib is too slow if there are a lot of differences
    assert len(gui_content_lines) == len(expected_gui)
    assert gui_content_lines[0:10] == expected_gui[0:10]
    assert gui_content_lines[-1] == expected_gui[-1]
Exemplo n.º 4
0
def test_bands(siesta_develop):
    """Test workfunction runs and outputs results in serial mode."""
    from aiida.orm import Code, DataFactory, CalculationFactory
    from aiida.orm.data.base import Float, Str

    SiestaCalculation = CalculationFactory('siesta.siesta')
    PsfData = DataFactory('siesta.psf')
    StructureData = DataFactory('structure')
    ParameterData = DataFactory('parameter')
    KpointsData = DataFactory('array.kpoints')

    codename = 'siesta@develop'
    code = Code.get_from_string(codename)

    inputs = SiestaCalculation.process().get_inputs_template()
    inputs.code = code
    inputs._options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    inputs._options.max_wallclock_seconds = 30 * 60

    # Define MgO structure
    alat = 4.117  # MgO lattice constant, Angstroms
    cell = create_FCC_structure(alat)  # Creating MgO FCC-cell
    structure = StructureData(cell=cell)  # Creating structure from cell
    # Placing basis atoms
    structure.append_atom(position=(0.000 * alat, 0.000 * alat, 0.000 * alat),
                          symbols=['Mg'])
    structure.append_atom(position=(0.500 * alat, 0.500 * alat, 0.500 * alat),
                          symbols=['O'])
    inputs.structure = structure

    # Pseudopotentials
    # from aiida_siesta.data.psf import get_pseudos_from_structure
    # inputs.pseudo = get_pseudos_from_structure(structure, "test_psf_family")
    raw_pseudos = [
        ("Mg.psf", 'Mg'),
        ("O.psf", 'O'),
    ]
    pseudo_dict = {}
    for fname, kind in raw_pseudos:
        absname = os.path.realpath(
            os.path.join(os.path.dirname(__file__), '..', 'pseudos', fname))
        pseudo, created = PsfData.get_or_create(absname, use_first=True)

        if created:
            print "Created the pseudo for {}".format(kind)
        else:
            print "Using the pseudo for {} from DB: {}".format(kind, pseudo.pk)
        # Attach pseudo node to the calculation
        pseudo_dict[kind] = pseudo

    inputs.pseudo = pseudo_dict

    # K-points mesh
    kpoints_mesh = KpointsData()
    kpoints_mesh.set_kpoints_mesh([6, 6, 6], [0.5, 0.5, 0.5])
    inputs.kpoints = kpoints_mesh

    # Bands' k-points
    bandskpoints = KpointsData()
    bandskpoints.set_cell(structure.cell, structure.pbc)
    bandskpoints.set_kpoints_path([
        ('K', 'G', 39),
        ('G', 'X', 37),
        ('X', 'W', 19),
        ('W', 'L', 27),
        ('L', 'G', 32),
    ])
    inputs.bandskpoints = bandskpoints

    # Calculation parameters
    parameters = ParameterData(
        dict={
            'xc-functional': 'LDA',
            'xc-authors': 'CA',
            'spin-polarized': False,
            'meshcutoff': '200 Ry',
            'max-scfiterations': 50,
            'xml-write': True,
        })
    inputs.parameters = parameters

    # Create and run Siesta calculation process
    from aiida.work.run import run

    JobCalc = SiestaCalculation.process()
    result = run(JobCalc, **inputs)

    assert result['bands_array'] is not None
Exemplo n.º 5
0
def test_simple_submission(siesta_develop):
    """Test that single calculation is submitted."""
    from aiida.orm import DataFactory
    from aiida.common.example_helpers import test_and_get_code

    PsfData = DataFactory('siesta.psf')
    StructureData = DataFactory('structure')
    ParameterData = DataFactory('parameter')
    KpointsData = DataFactory('array.kpoints')

    code = test_and_get_code('siesta', expected_code_type='siesta.siesta')
    assert code is not None

    # Si diamond structure
    alat = 5.430  # angstrom
    cell = [
        [
            0.5 * alat,
            0.5 * alat,
            0.,
        ],
        [
            0.,
            0.5 * alat,
            0.5 * alat,
        ],
        [
            0.5 * alat,
            0.,
            0.5 * alat,
        ],
    ]

    # Si
    # This was originally given in the "ScaledCartesian" format
    #
    s = StructureData(cell=cell)
    s.append_atom(position=(0.000 * alat, 0.000 * alat, 0.000 * alat),
                  symbols=['Si'])
    s.append_atom(position=(0.250 * alat, 0.250 * alat, 0.250 * alat),
                  symbols=['Si'])

    parameters = ParameterData(
        dict={
            'xc-functional': 'LDA',
            'xc-authors': 'CA',
            'max-scfiterations': 50,
            'dm-numberpulay': 4,
            'dm-mixingweight': 0.3,
            'dm-tolerance': 1.e-3,
            'Solution-method': 'diagon',
            'electronic-temperature': '25 meV',
            'md-typeofrun': 'cg',
            'md-numcgsteps': 3,
            'md-maxcgdispl': '0.1 Ang',
            'md-maxforcetol': '0.04 eV/Ang',
            'xml-write': True
        })

    basis = ParameterData(dict={
        'pao-energy-shift': '300 meV',
        '%block pao-basis-sizes': 'Si DZP',
    })

    kpoints = KpointsData()
    kpoints.set_kpoints_mesh([4, 4, 4])

    calc = code.new_calc(max_wallclock_seconds=3600,
                         resources={
                             "num_machines": 1,
                             "num_mpiprocs_per_machine": 1,
                         })

    calc.label = "Si bulk"
    calc.description = "Test calculation with the Siesta code. Si bulk"

    # Use raw pseudos for this example:
    raw_pseudos = [("Si.psf", 'Si')]

    calc.use_structure(s)
    calc.use_code(code)
    calc.use_parameters(parameters)
    calc.use_basis(basis)
    calc.use_kpoints(kpoints)

    # Pseudo business
    #
    # TODO: understand how to work with pseudo families
    # calc.use_pseudos_from_family(pseudo_family)
    #
    for fname, kind in raw_pseudos:
        absname = op.realpath(
            op.join(op.dirname(__file__), "..", "pseudos", fname))
        pseudo, created = PsfData.get_or_create(absname, use_first=True)

        if created:
            print "\nCreated the pseudo for {}".format(kind)
        else:
            print "\nUsing the pseudo for {} from DB: {}".format(
                kind, pseudo.pk)

    # Attach pseudo node to the calculation
    calc.use_pseudo(pseudo, kind=kind)

    calc.store_all()
    print "created calculation with PK={}".format(calc.pk)
    subfolder, script_filename = calc.submit_test()
    print "Test_submit for calculation (uuid='{}')".format(calc.uuid)

    assert op.isfile(op.join(op.relpath(subfolder.abspath), script_filename))
    print "Submit file in {}".format(
        op.join(op.relpath(subfolder.abspath), script_filename))

    assert op.isfile(op.join(op.relpath(subfolder.abspath), 'aiida.fdf'))
    assert op.isfile(op.join(op.relpath(subfolder.abspath), 'Si.psf'))