Esempio n. 1
0
def test_all_calculation_inputs(vasp_code, cstdn_code, incar, kpoints, poscar,
                                with_pbe_potcars, calc_type, temporary_cwd):
    from aiida.engine import run
    from aiida_cusp.data import VaspPotcarData
    from aiida_cusp.calculators import VaspCalculation
    from aiida_cusp.utils.defaults import CustodianDefaults
    # default custodian settings and handlers
    custodian_settings = CustodianDefaults.CUSTODIAN_SETTINGS
    custodian_handlers = CustodianDefaults.ERROR_HANDLER_SETTINGS
    # define code
    vasp_code.set_attribute('input_plugin', 'cusp.vasp')
    cstdn_code.set_attribute('input_plugin', 'cusp.vasp')
    # define all possible inputs
    inputs = {
        'code': vasp_code,
        'incar': incar,
        'kpoints': kpoints,
        'potcar': VaspPotcarData.from_structure(poscar, 'pbe'),
        'custodian': {
            'settings': custodian_settings,
            'handlers': custodian_handlers,
        },
        'metadata': {
            'dry_run': True,
            'options': {'resources': {'num_machines': 1}},
        },
    }
    if calc_type == 'normal':
        inputs['poscar'] = poscar
    elif calc_type == 'neb':
        neb_path = {'node_00': poscar, 'node_01': poscar, 'node_02': poscar}
        inputs['neb_path'] = neb_path
    run(VaspCalculation, **inputs)
Esempio n. 2
0
def example_failure(cp2k_code):
    """Run failing calculation"""

    print("Testing CP2K failure...")

    # a broken CP2K input
    parameters = Dict(dict={'GLOBAL': {'FOO_BAR_QUUX': 42}})

    print("Submitted calculation...")

    # Construct process builder
    builder = Cp2kCalculation.get_builder()
    builder.parameters = parameters
    builder.code = cp2k_code
    builder.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    builder.metadata.options.max_wallclock_seconds = 1 * 2 * 60

    try:
        run(builder)
        print("ERROR!")
        print("CP2K failure was not recognized")
        sys.exit(3)
    except OutputParsingError:
        print("CP2K failure correctly recognized")
Esempio n. 3
0
def main(codelabel):
    """Example usage: verdi run thistest.py cp2k@localhost"""

    print("Testing CP2K multistage workchain on H2O")
    print(">>> Using 'singlepoint' tag, with no output structure")

    code = Code.get_from_string(codelabel)

    atoms = ase.build.molecule('H2O')
    atoms.center(vacuum=2.0)
    structure = StructureData(ase=atoms)

    options = {
        "resources": {
            "num_machines": 1,
            "num_mpiprocs_per_machine": 1,
        },
        "max_wallclock_seconds": 1 * 3 * 60,
    }
    inputs = {
        'structure': structure,
        'protocol_tag': Str('singlepoint'),
        'cp2k_base': {
            'cp2k': {
                'code': code,
                'metadata': {
                    'options': options,
                }
            }
        }
    }

    run(Cp2kMultistageWorkChain, **inputs)
def run_multistage_h2o_fail(cp2k_code):
    """Example usage: verdi run thistest.py cp2k@localhost"""

    print("Testing CP2K multistage workchain on H2O")
    print(">>> Making it fail because of an unphysical Multiplicity")

    atoms = ase.build.molecule('H2O')
    atoms.center(vacuum=2.0)
    structure = StructureData(ase=atoms)

    parameters = Dict(
        dict={'FORCE_EVAL': {
            'DFT': {
                'UKS': True,
                'MULTIPLICITY': 666,
            }
        }})

    # Construct process builder
    builder = Cp2kMultistageWorkChain.get_builder()
    builder.structure = structure
    builder.protocol_tag = Str('test')
    builder.cp2k_base.max_iterations = Int(1)
    builder.cp2k_base.cp2k.parameters = parameters
    builder.cp2k_base.cp2k.code = cp2k_code
    builder.cp2k_base.cp2k.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    builder.cp2k_base.cp2k.metadata.options.max_wallclock_seconds = 1 * 3 * 60

    run(builder)
Esempio n. 5
0
def main(code_string, datafiles, parameters):
    """Main method to setup the calculation."""

    # First, we need to fetch the AiiDA datatypes which will
    # house the inputs to our calculation
    dict_data = DataFactory('dict')

    # Then, we set the workchain we would like to call
    workchain = WorkflowFactory('logger.gc_example')

    # Set inputs for the following WorkChain execution
    inputs = AttributeDict()
    # inputs.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1},
    #                                'parser_name': 'logger',
    #                                'withmpi': False,
    #                                'output_filename': 'logger.out'}}
    # Set code
    inputs.code = Code.get_from_string(code_string)
    # Set datafiles
    inputs.datafiles = datafiles
    # Set parameters
    inputs.parameters = dict_data(dict=parameters)
    # Set workchain related inputs, in this case, give more explicit output to report
    inputs.verbose = Bool(True)
    # Submit the requested workchain with the supplied inputs
    run(workchain, **inputs)
Esempio n. 6
0
def main(codelabel):
    """Run failing calculation"""
    try:
        code = Code.get_from_string(codelabel)
    except NotExistent:
        print("The code '{}' does not exist".format(codelabel))
        sys.exit(1)

    print("Testing CP2K failure...")

    # a broken CP2K input
    parameters = Dict(dict={'GLOBAL': {'FOO_BAR_QUUX': 42}})
    options = {
        "resources": {
            "num_machines": 1,
            "num_mpiprocs_per_machine": 1,
        },
        "max_wallclock_seconds": 1 * 2 * 60,
    }

    print("Submitted calculation...")
    inputs = {'parameters': parameters, 'code': code, 'metadata': {'options': options,}}
    try:
        run(Cp2kCalculation, **inputs)
        print("ERROR!")
        print("CP2K failure was not recognized")
        sys.exit(3)
    except OutputParsingError:
        print("CP2K failure correctly recognized")

    sys.exit(0)
Esempio n. 7
0
def run_multistage_h2o_testfile(cp2k_code):
    """Example usage: verdi run thistest.py cp2k@localhost"""

    print("Testing CP2K multistage workchain on H2O")
    print(">>> Loading a custom protocol from file testfile.yaml")

    atoms = ase.build.molecule('H2O')
    atoms.center(vacuum=2.0)
    structure = StructureData(ase=atoms)

    thisdir = os.path.dirname(os.path.abspath(__file__))

    # Construct process builder
    builder = Cp2kMultistageWorkChain.get_builder()
    builder.structure = structure
    builder.protocol_yaml = SinglefileData(file=os.path.abspath(
        os.path.join(thisdir, '..', 'data', 'test_multistage_protocol.yaml')))
    builder.cp2k_base.cp2k.code = cp2k_code
    builder.cp2k_base.cp2k.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    builder.cp2k_base.cp2k.metadata.options.max_wallclock_seconds = 1 * 3 * 60

    run(builder)
Esempio n. 8
0
def example(code, formchk_pk):

    builder = CubegenCalculation.get_builder()
    builder.parent_calc_folder = load_node(formchk_pk).outputs.remote_folder
    builder.code = code

    builder.parameters = Dict(
        dict={
            "h**o": {
                "kind": "MO=H**o",
                "npts": -2,
            },
            "density": {
                "kind": "Density=SCF",
                "npts": -2,
            },
        })

    builder.retrieve_cubes = Bool(True)

    builder.metadata.options.resources = {
        "tot_num_mpiprocs": 1,
        "num_machines": 1,
    }

    builder.metadata.options.max_wallclock_seconds = 5 * 60

    print("Submitted calculation...")
    run(builder)
Esempio n. 9
0
def main(raspa_code_label):
    """Prepare inputs and submit the work chain."""

    builder = SimAnnealingWorkChain.get_builder()
    builder.metadata.label = "test"
    builder.raspa_base.raspa.code = Code.get_from_string(raspa_code_label)
    builder.raspa_base.raspa.metadata.options = {
        "resources": {
            "num_machines": 1,
            "tot_num_mpiprocs": 1,
        },
        "max_wallclock_seconds": 1 * 60 * 60,
    }
    builder.structure = CifData(file=os.path.abspath('data/HKUST-1.cif'),
                                label="HKUST-1")
    builder.molecule = Str('co2')
    builder.parameters = Dict(
        dict={
            "ff_framework": "UFF",  # (str) Forcefield of the structure.
            "temperature_list": [
                300, 200, 100
            ],  # (list) List of decreasing temperatures for the annealing.
            "mc_steps": int(10),  # (int) Number of MC cycles.
            "number_of_molecules":
            3  # (int) Number of molecules loaded in the framework.
        })

    run(builder)
Esempio n. 10
0
def test_run_failure(new_workdir):
    """Testing CP2K failure"""

    from aiida.engine import run
    from aiida.plugins import CalculationFactory
    from aiida.orm import Dict
    from aiida.common.exceptions import OutputParsingError

    computer = get_computer(workdir=new_workdir)
    code = get_code(entry_point="cp2k", computer=computer)

    # a broken CP2K input
    parameters = Dict(dict={"GLOBAL": {"FOO_BAR_QUUX": 42}})
    options = {
        "resources": {
            "num_machines": 1,
            "num_mpiprocs_per_machine": 1
        },
        "max_wallclock_seconds": 1 * 2 * 60,
    }

    print("Submitted calculation...")
    inputs = {
        "parameters": parameters,
        "code": code,
        "metadata": {
            "options": options
        }
    }

    with pytest.raises(OutputParsingError):
        run(CalculationFactory("cp2k"), **inputs)
Esempio n. 11
0
    def test_kkr_from_kkr(self):
        """
        continue KKR calculation after a previous KKR calculation instead of starting from voronoi
        """
        from aiida.orm import Code, load_node
        from aiida.plugins import DataFactory
        from masci_tools.io.kkr_params import kkrparams
        from aiida_kkr.calculations.kkr import KkrCalculation
        Dict = DataFactory('dict')

        # load necessary files from db_dump files
        from aiida.tools.importexport import import_data
        import_data('files/db_dump_kkrcalc.tar.gz')
        kkr_calc = load_node('3058bd6c-de0b-400e-aff5-2331a5f5d566')

        # prepare computer and code (needed so that
        prepare_code(kkr_codename, codelocation, computername, workdir)

        # extract KKR parameter (add missing values)
        params_node = kkr_calc.inputs.parameters

        # load code from database and create new voronoi calculation
        code = Code.get_from_string(kkr_codename+'@'+computername)
        options = {'resources': {'num_machines':1, 'tot_num_mpiprocs':1}, 'queue_name': queuename}
        builder = KkrCalculation.get_builder()
        builder.code = code
        builder.metadata.options = options
        builder.parameters = params_node
        builder.parent_folder = kkr_calc.outputs.remote_folder
        builder.metadata.dry_run = True
        from aiida.engine import run
        run(builder)
Esempio n. 12
0
def launch():
    """Launch the relax work chain for a basic silicon crystal structure at a range of scaling factors."""

    print(f'Running {STRUCTURE} with {CODE}')

    pymatgen_structure = Structure.from_file(
        f'../../../common/data/{STRUCTURE}.cif')
    structure = orm.StructureData(pymatgen=pymatgen_structure)

    parameters_dict = {
        'structure': structure,
        'sub_process_class': 'common_workflows.relax.abinit',
        'generator_inputs': {
            'protocol': 'precise',
            'relax_type': RelaxType.ATOMS,
            'threshold_forces': 0.001,
            'calc_engines': {
                'relax': {
                    'code': CODE,
                    'options': {
                        'withmpi': True,
                        'max_wallclock_seconds': 24 * 60**2,
                        'resources': {
                            'num_machines': 1,
                            'num_mpiprocs_per_machine': 4
                        }
                    }
                }
            },
            **KWARGS
        }
    }

    run(EquationOfStateWorkChain, **parameters_dict)
Esempio n. 13
0
def example_relax(code, pseudo_family):
    """Run simple silicon DFT calculation."""

    print("Testing the AbinitBaseWorkChain relaxation on Silicon")

    thisdir = os.path.dirname(os.path.realpath(__file__))
    structure = StructureData(pymatgen=mg.Structure.from_file(
        os.path.join(thisdir, "files", 'Si.cif')))
    pseudo_family = Group.objects.get(label=pseudo_family)
    pseudos = pseudo_family.get_pseudos(structure=structure)

    base_parameters_dict = {
        'kpoints_distance': Float(0.6),  # 1 / Angstrom
        'abinit': {
            'code':
            code,
            'structure':
            structure,
            'pseudos':
            pseudos,
            'parameters':
            Dict(
                dict={
                    'optcell':
                    2,  # Cell optimization
                    'ionmov':
                    22,  # Atoms relaxation
                    'tolmxf':
                    5.0e-5,  # Tolerence on the maximal force
                    'ecutsm':
                    0.5,  # Energy cutoff smearing, in Hartree
                    'ecut':
                    20.0,  # Maximal kinetic energy cut-off, in Hartree
                    'nshiftk':
                    4,  # of the reciprocal space (that form a BCC lattice !)
                    'shiftk': [[0.5, 0.5, 0.5], [0.5, 0.0, 0.0],
                               [0.0, 0.5, 0.0], [0.0, 0.0, 0.5]],
                    'nstep':
                    20,  # Maximal number of SCF cycles
                    'toldfe':
                    1.0e-6,  # Will stop when, twice in a row, the difference 
                    # between two consecutive evaluations of total energy
                    # differ by less than toldfe (in Hartree)
                }),
            'metadata': {
                'options': {
                    'withmpi': True,
                    'max_wallclock_seconds': 10 * 60,
                    'resources': {
                        'num_machines': 1,
                        'num_mpiprocs_per_machine': 4,
                    }
                }
            }
        }
    }

    print("Running work chain...")
    run(AbinitBaseWorkChain, **base_parameters_dict)
Esempio n. 14
0
    def test_save_load(self):
        process = DummyProcess()
        saved_state = plumpy.Bundle(process)
        process.close()

        loaded_process = saved_state.unbundle()
        run(loaded_process)

        self.assertEqual(loaded_process.state, plumpy.ProcessState.FINISHED)
Esempio n. 15
0
def example_ev(julia_code, submit=True):
    """
    Example to prepare and run a Sinlge Component
    """

    pwd = os.path.dirname(os.path.realpath(__file__))
    framework = CifData(file=os.path.join(pwd, 'files', 'HKUST1.cif')).store()
    acc_voronoi_nodes = SinglefileData(
        file=os.path.join(pwd, 'files', 'HKUST1.voro_accessible')).store()
    data_path = os.path.join(pwd, 'data')
    print(data_path)
    parameters = Dict(
        dict={
            'data_path': data_path,
            'ff': 'UFF.csv',
            'cutoff': 12.5,
            'mixing': 'Lorentz-Berthelot',
            'framework': framework.filename,
            'frameworkname': framework.filename[:-4],
            'adsorbate': "Xe",
            'temperature': 298.0,
            'output_filename': "Ev_" + framework.filename[:-4] + ".csv",
            'input_template': 'ev_vdw_kh_1comp_template',
            'ev_setting': [99, 95, 90, 80, 50
                           ],  # if not defined the default is [90,80,50]
        })

    builder = PorousMaterialsCalculation.get_builder()
    builder.structure = {framework.filename[:-4]: framework}
    builder.parameters = parameters
    builder.acc_voronoi_nodes = {framework.filename[:-4]: acc_voronoi_nodes}
    builder.code = julia_code
    builder.metadata.options.resources = { #pylint: disable = no-member
        'num_machines': 1,
        'num_mpiprocs_per_machine': 1,
    }
    builder.metadata.options.max_wallclock_seconds = 1 * 30 * 60  #pylint: disable = no-member
    builder.metadata.options.withmpi = False  #pylint: disable = no-member

    if submit:
        print('Testing PorousMaterials Ev for single component...')
        res, pk = run_get_pk(builder)
        print('Voronoi Energy is: ',
              res['output_parameters'].dict.HKUST1['Ev_probe']['Ev_minimum'])
        print('calculation pk: ', pk)
        print('OK, calculation has completed successfully')
        pytest.base_calc_pk = pk
    else:
        print('Generating test input ...')
        builder.metadata.dry_run = True  #pylint: disable = no-member
        builder.metadata.store_provenance = False  #pylint: disable = no-member
        run(builder)
        print('submission test successful')
        print("In order to actually submit, add '--submit'")
    print('-----------')
Esempio n. 16
0
def example_dft(code, pseudo_family):
    """Run simple silicon DFT calculation."""

    print('Testing Abinit Total energy on Silicon using AbinitCalculation')

    thisdir = os.path.dirname(os.path.realpath(__file__))
    structure = StructureData(pymatgen=mg.core.Structure.from_file(
        os.path.join(thisdir, 'files', 'Si.cif')))
    pseudo_family = Group.objects.get(label=pseudo_family)
    pseudos = pseudo_family.get_pseudos(structure=structure)

    kpoints = KpointsData()
    kpoints.set_cell_from_structure(structure)
    kpoints.set_kpoints_mesh([2, 2, 2])
    # kpoints.set_kpoints_mesh_from_density(2.0)

    parameters_dict = {
        'code':
        code,
        'structure':
        structure,
        'pseudos':
        pseudos,
        'kpoints':
        kpoints,
        'parameters':
        Dict(
            dict={
                'ecut':
                8.0,  # Maximal kinetic energy cut-off, in Hartree
                'nshiftk':
                4,  # of the reciprocal space (that form a BCC lattice !)
                'shiftk': [[0.5, 0.5, 0.5], [0.5, 0.0, 0.0], [0.0, 0.5, 0.0],
                           [0.0, 0.0, 0.5]],
                'nstep':
                20,  # Maximal number of SCF cycles
                'toldfe':
                1.0e-6,  # Will stop when, twice in a row, the difference
                # between two consecutive evaluations of total energy
                # differ by less than toldfe (in Hartree)
            }),
        'metadata': {
            'options': {
                'withmpi': True,
                'max_wallclock_seconds': 2 * 60,
                'resources': {
                    'num_machines': 1,
                    'num_mpiprocs_per_machine': 4,
                }
            }
        }
    }

    print('Running calculation...')
    run(AbinitCalculation, **parameters_dict)
def example_multistage_al(cp2k_code):
    """Example usage: verdi run thistest.py cp2k@localhost"""

    print("Testing CP2K multistage workchain on Al (RKS, needs smearing)...")
    print(
        "EXPECTED: the OT (settings_0) will converge to a negative bandgap, then we switch to SMEARING (settings_1)"
    )

    thisdir = os.path.dirname(os.path.abspath(__file__))
    structure = StructureData(
        ase=ase.io.read(os.path.join(thisdir, '../data/Al.cif')))

    # testing user change of parameters and protocol
    parameters = Dict(
        dict={'FORCE_EVAL': {
            'DFT': {
                'MGRID': {
                    'CUTOFF': 250,
                }
            }
        }})
    protocol_mod = Dict(
        dict={
            'initial_magnetization': {
                'Al': 0
            },
            'settings_0': {
                'FORCE_EVAL': {
                    'DFT': {
                        'SCF': {
                            'OUTER_SCF': {
                                'MAX_SCF': 5,
                            }
                        }
                    }
                }
            }
        })

    # Construct process builder
    builder = Cp2kMultistageWorkChain.get_builder()
    builder.structure = structure
    builder.protocol_tag = Str('test')
    builder.starting_settings_idx = Int(0)
    builder.protocol_modify = protocol_mod
    builder.cp2k_base.cp2k.parameters = parameters
    builder.cp2k_base.cp2k.code = cp2k_code
    builder.cp2k_base.cp2k.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    builder.cp2k_base.cp2k.metadata.options.max_wallclock_seconds = 1 * 3 * 60

    run(builder)
Esempio n. 18
0
def main(zeopp_code_label, raspa_code_label):
    """
    Prepare inputs and submit the Isotherm workchain.
    Usage: verdi run run_HTSMultiTWorkChain_HKUST-1_2comp.py zeopp@teslin raspa37@teslin
    """

    builder = HTSMultiTempWorkChain.get_builder()

    builder.metadata.label = "test"

    builder.raspa_base.raspa.code = Code.get_from_string(raspa_code_label)
    builder.zeopp.code = Code.get_from_string(zeopp_code_label)
    builder.zeopp.atomic_radii = SinglefileData(file=os.path.abspath('../aiida_matdis/data/UFF.rad'))

    options = {
        "resources": {
            "num_machines": 1,
            "tot_num_mpiprocs": 1,
        },
        "max_wallclock_seconds": 1 * 60 * 60,
        "withmpi": False,
    }
    builder.raspa_base.raspa.metadata.options = options
    builder.zeopp.metadata.options = options
    builder.structure = CifData(file=os.path.abspath('../aiida_matdis/data/HKUST-1.cif'), label="hkust1")

    builder.mixture = Dict(dict={
        'comp1': {
            'name': 'xenon',
            'molfraction': 0.20
        },
        'comp2': {
            'name': 'krypton',
            'molfraction': 0.80
        },
    })

    builder.parameters = Dict(
        dict={
            'ff_framework': 'UFF',  # Default: UFF
            'temperature_list': [273, 298],  # (K) Note: higher temperature will have less adsorbate and it is faster
            'zeopp_volpo_samples': 100,  # Default: 1e5 *NOTE: default is good for standard real-case!
            'zeopp_sa_samples': 100,  # Default: 1e5 *NOTE: default is good for standard real-case!
            'zeopp_block_samples': 100,  # Default: 100
            'raspa_widom_cycles': 500,  # Default: 1e5
            'raspa_gcmc_init_cycles': 500,  # Default: 1e3
            'raspa_gcmc_prod_cycles': 500,  # Default: 1e4
            'pressure_list': [0.1, 1.0],
            'lcd_max': 15.0,
            'pld_min': 3.5,
            'probe_based': False,
        })

    run(builder)
Esempio n. 19
0
def main(codelabel):
    """Example usage: verdi run thistest.py cp2k@localhost"""

    print("Testing CP2K multistage workchain on Al (RKS, needs smearing)...")
    print("EXPECTED: the OT (settings_0) will converge to a negative bandgap, then we switch to SMEARING (settings_1)")

    code = Code.get_from_string(codelabel)

    thisdir = os.path.dirname(os.path.abspath(__file__))
    structure = StructureData(ase=ase.io.read(os.path.join(thisdir, '../data/Al.cif')))

    # testing user change of parameters and protocol
    parameters = Dict(dict={'FORCE_EVAL': {'DFT': {'MGRID': {'CUTOFF': 250,}}}})
    protocol_mod = Dict(dict={
        'initial_magnetization': {
            'Al': 0
        },
        'settings_0': {
            'FORCE_EVAL': {
                'DFT': {
                    'SCF': {
                        'OUTER_SCF': {
                            'MAX_SCF': 5,
                        }
                    }
                }
            }
        }
    })
    options = {
        "resources": {
            "num_machines": 1,
            "num_mpiprocs_per_machine": 1,
        },
        "max_wallclock_seconds": 1 * 3 * 60,
    }
    inputs = {
        'structure': structure,
        'protocol_tag': Str('test'),
        'starting_settings_idx': Int(0),
        'protocol_modify': protocol_mod,
        'cp2k_base': {
            'cp2k': {
                'parameters': parameters,
                'code': code,
                'metadata': {
                    'options': options,
                }
            }
        }
    }

    run(Cp2kMultistageWorkChain, **inputs)
Esempio n. 20
0
    def test_startpot_Cu_simple(self):
        """
        simple Cu noSOC, FP, lmax2 full example
        """
        from aiida.orm import Code
        from aiida.plugins import DataFactory
        from masci_tools.io.kkr_params import kkrparams
        from aiida_kkr.calculations.voro import VoronoiCalculation

        Dict = DataFactory('dict')
        StructureData = DataFactory('structure')

        # create StructureData instance for Cu
        alat = 3.61  # lattice constant in Angstroem
        bravais = [[0.5 * alat, 0.5 * alat, 0], [0.5 * alat, 0, 0.5 * alat],
                   [0, 0.5 * alat, 0.5 * alat]]  # Bravais matrix in Ang. units
        Cu = StructureData(cell=bravais)
        Cu.append_atom(position=[0, 0, 0], symbols='Cu')

        # create Dict input node using kkrparams class from masci-tools
        params = kkrparams(params_type='voronoi')
        params.set_multiple_values(LMAX=2, NSPIN=1, RCLUSTZ=2.3)
        Dict = DataFactory(
            'dict')  # use DataFactory to get ParamerterData class
        ParaNode = Dict(dict=params.get_dict())

        # import computer etc from database dump
        from aiida.tools.importexport import import_data
        import_data('files/db_dump_vorocalc.tar.gz')

        # prepare computer and code (needed so that
        prepare_code(voro_codename, codelocation, computername, workdir)

        # load code from database and create new voronoi calculation
        #code = Code.get_from_string(codename)
        code = Code.get_from_string(voro_codename + '@' + computername)

        #code = Code.get_from_string('voronoi@localhost_new')
        options = {
            'resources': {
                'num_machines': 1,
                'tot_num_mpiprocs': 1
            },
            'queue_name': queuename
        }
        builder = VoronoiCalculation.get_builder()
        builder.code = code
        builder.metadata.options = options
        builder.parameters = ParaNode
        builder.structure = Cu
        builder.metadata.dry_run = True
        from aiida.engine import run
        run(builder)
Esempio n. 21
0
def main(raspa_code_label, cp2k_code_label):
    """Prepare inputs and submit the work chain."""

    print("Testing BindingSite work chain (FF + DFT) for CO2 in Zn-MOF-74 ...")
    print("[NOTE: this test will run on 4 cpus and take ca. 10 minutes]")

    builder = BindingSiteWorkChain.get_builder()
    builder.metadata.label = "test"
    builder.raspa_base.raspa.code = Code.get_from_string(raspa_code_label)
    builder.cp2k_base.cp2k.code = Code.get_from_string(cp2k_code_label)
    builder.raspa_base.raspa.metadata.options = {
        "resources": {
            "num_machines": 1,
            "tot_num_mpiprocs": 1,
        },
        "max_wallclock_seconds": 1 * 10 * 60,
    }
    builder.cp2k_base.cp2k.metadata.options = {
        "resources": {
            "num_machines": 1,
            "tot_num_mpiprocs": 4,
        },
        "max_wallclock_seconds": 1 * 10 * 60,
    }
    builder.structure = CifData(file=os.path.abspath('data/Zn-MOF-74.cif'), label="Zn-MOF-74")
    builder.molecule = Str('co2')
    builder.parameters = Dict(
        dict={
            "ff_framework": "UFF",  # (str) Forcefield of the structure.
            "mc_steps": int(10),  # (int) Number of MC cycles.
            "temperature_list": [300, 150],
        })
    builder.protocol_tag = Str('test')
    builder.cp2k_base.cp2k.parameters = Dict(dict={ # Lowering CP2K default setting for a faster test calculation
        'FORCE_EVAL': {
            'DFT': {
                'SCF': {
                    'EPS_SCF': 1.0E-4,
                    'OUTER_SCF': {
                        'EPS_SCF': 1.0E-4,
                    },
                },
            },
        },
        'MOTION': {
            'GEO_OPT': {
                'MAX_ITER': 5
            }
        },
    })

    run(builder)
Esempio n. 22
0
def run_multistage_h2om(cp2k_code):
    """Example usage: verdi run thistest.py cp2k@localhost"""

    print(
        "Testing CP2K multistage workchain on 2xH2O- (UKS, no need for smearing)..."
    )
    print("This is checking:")
    print(" > unit cell resizing")
    print(" > protocol modification")
    print(" > cp2k calc modification")

    atoms = ase.build.molecule('H2O')
    atoms.center(vacuum=2.0)
    structure = StructureData(ase=atoms)

    protocol_mod = Dict(dict={
        'settings_0': {
            'FORCE_EVAL': {
                'DFT': {
                    'MGRID': {
                        'CUTOFF': 300,
                    }
                }
            }
        }
    })
    parameters = Dict(dict={
        'FORCE_EVAL': {
            'DFT': {
                'UKS': True,
                'MULTIPLICITY': 3,
                'CHARGE': -2,
            }
        }
    })

    # Construct process builder
    builder = Cp2kMultistageWorkChain.get_builder()
    builder.structure = structure
    builder.min_cell_size = Float(4.1)
    builder.protocol_tag = Str('test')
    builder.protocol_modify = protocol_mod

    builder.cp2k_base.cp2k.parameters = parameters
    builder.cp2k_base.cp2k.code = cp2k_code
    builder.cp2k_base.cp2k.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 1,
    }
    builder.cp2k_base.cp2k.metadata.options.max_wallclock_seconds = 1 * 3 * 60

    run(builder)
Esempio n. 23
0
def example_dft(g_code):
    """Run simple DFT calculation"""

    print("Testing Gaussian Input Creation")

    pwd = os.path.dirname(os.path.realpath(__file__))

    # structure
    structure = StructureData(
        pymatgen_molecule=mg.Molecule.from_file('./ch4.xyz'))

    # parameters
    parameters = Dict(
        dict={
            'functional': 'PBE1PBE',
            'basis_set': '6-31g',
            'route_parameters': {
                'nosymm': None,
                'Output': 'WFX'
            },
            'input_parameters': {
                'output.wfx': None
            },
            'link0_parameters': {
                '%chk': 'mychk.chk',
                '%mem': '100000kb',
                '%nprocshared': '2'
            },
        })

    # Construct process builder

    builder = GaussianCalculation.get_builder()

    builder.structure = structure
    builder.parameters = parameters
    builder.code = g_code

    builder.metadata.options.resources = {
        "num_machines": 1,
        "num_mpiprocs_per_machine": 2,
        "tot_num_mpiprocs": parameters['link0_parameters']['%nprocshared']
    }
    builder.metadata.options.max_memory_kb = int(
        parameters['link0_parameters']['%mem'][:-2])

    builder.metadata.options.max_wallclock_seconds = 3 * 60
    builder.metadata.dry_run = True
    builder.metadata.store_provenance = False

    print("Submitted calculation...")
    run(builder)
Esempio n. 24
0
def main():
    inputs = {
        'a': Float(3.14),
        'b': Int(4),
        'c': Int(6)
    }

    results = run(SumWorkChain, **inputs)
    print('Result of SumWorkChain: {}'.format(results))

    results = run(ProductWorkChain, **inputs)
    print('Result of ProductWorkChain: {}'.format(results))

    results = run(SumProductWorkChain, **inputs)
    print('Result of SumProductWorkChain: {}'.format(results))
Esempio n. 25
0
    def test_calculation_future_broadcasts(self):
        """Test calculation future broadcasts."""
        manager = get_manager()
        runner = manager.get_runner()
        process = test_processes.DummyProcess()

        # No polling
        future = processes.futures.ProcessFuture(
            pk=process.pid, loop=runner.loop, communicator=manager.get_communicator()
        )

        run(process)
        calc_node = runner.run_until_complete(asyncio.wait_for(future, self.TIMEOUT))

        self.assertEqual(process.node.pk, calc_node.pk)
def test_process(rhino_zfs_code):
    """Test running a calculation
    note this does not test that the expected outputs are created of output parsing"""
    from aiida.plugins import DataFactory, CalculationFactory
    from aiida.engine import run

    # Prepare input parameters
    DiffParameters = DataFactory('rhino_zfs')
    parameters = DiffParameters({'ignore-case': True})

    from aiida.orm import SinglefileData
    file1 = SinglefileData(
        file=os.path.join(TEST_DIR, "input_files", 'file1.txt'))
    file2 = SinglefileData(
        file=os.path.join(TEST_DIR, "input_files", 'file2.txt'))

    # set up calculation
    inputs = {
        'code': rhino_zfs_code,
        'parameters': parameters,
        'file1': file1,
        'file2': file2,
        'metadata': {
            'options': {
                'max_wallclock_seconds': 30
            },
        },
    }

    result = run(CalculationFactory('rhino_zfs'), **inputs)
    computed_diff = result['rhino_zfs'].get_content()

    assert 'content1' in computed_diff
    assert 'content2' in computed_diff
def run_wf(pwscf_code, pw2wannier90_code, wannier_code):
    """Run a simple workflow running Quantum ESPRESSO+wannier90 for GaAs."""
    static_inputs = get_static_inputs()

    pseudo_family_name = get_or_create_pseudo_family()

    # Run the workflow
    run(
        MinimalW90WorkChain,
        pw_code=pwscf_code,  #load_code('pw-6.4-release@localhost'),
        pseudo_family=Str(
            pseudo_family_name),  #Str('SSSP_efficiency_pseudos'),
        wannier_code=wannier_code,  #load_code('wannier90-3-desktop@localhost'),
        pw2wannier90_code=
        pw2wannier90_code,  #load_code('pw2wannier90-6.4-release@localhost'),
        **static_inputs)
Esempio n. 28
0
def test_workchain_run(test_crystal_code, crystal_calc_parameters,
                       test_properties_code, properties_calc_parameters,
                       test_basis):
    from mpds_aiida.workflows.crystal import MPDSCrystalWorkchain
    from aiida.plugins import DataFactory
    from aiida.engine import run
    inputs = MPDSCrystalWorkchain.get_builder()
    inputs.crystal_code = test_crystal_code
    inputs.properties_code = test_properties_code
    inputs.crystal_parameters = crystal_calc_parameters
    inputs.properties_parameters = properties_calc_parameters
    inputs.basis_family = test_basis
    inputs.mpds_query = DataFactory('dict')(dict={
        "classes": "binary",
        "formulae": "MgO",
        "sgs": 225
    })  # MgO 225
    inputs.options = DataFactory('dict')(dict={
        'label': 'MgO/225/PS',
        'resources': {
            'num_machines': 1,
            'num_mpiprocs_per_machine': 1
        }
    })
    results = run(MPDSCrystalWorkchain, **inputs)
    assert 'output_parameters' in results
    assert 'frequency_parameters' in results
    assert 'elastic_parameters' in results
    assert 'output_dos' in results
    assert 'output_bands' in results
def test_strained_fp_tb(
        configure_with_daemon,  # pylint: disable=unused-argument
        get_optimize_fp_tb_input,  # pylint: disable=redefined-outer-name
):
    """
    Run the DFT tight-binding optimization workflow with strain on an InSb sample for three strain values.
    """
    from aiida.engine import run
    from aiida.orm import Code
    from aiida.orm import Str, List
    from aiida_tbextraction.optimize_strained_fp_tb import OptimizeStrainedFirstPrinciplesTightBinding
    inputs = get_optimize_fp_tb_input

    inputs['strain_kind'] = Str('three_five.Biaxial001')
    inputs['strain_parameters'] = Str('InSb')

    strain_strengths = List()
    strain_list = [-0.1, 0., 0.1]
    strain_strengths.extend(strain_list)
    inputs['strain_strengths'] = strain_strengths

    inputs['symmetry_repr_code'] = Code.get_from_string('symmetry_repr')

    result = run(OptimizeStrainedFirstPrinciplesTightBinding, **inputs)
    print(result)
    for value in strain_list:
        suffix = '_{}'.format(value).replace('.', '_dot_')
        assert all(key + suffix in result
                   for key in ['cost_value', 'tb_model', 'window'])
Esempio n. 30
0
def test_process(logger_code):
    """
    Test running a calculation.

    Also checks its outputs.
    """
    from aiida.plugins import DataFactory, CalculationFactory
    from aiida.engine import run
    from aiida.common.extendeddicts import AttributeDict

    from aiida_logger.tests import TEST_DIR  # pylint: disable=wrong-import-position

    # Prepare input parameters
    parameters = AttributeDict()
    parameters.comment_string = '#'
    parameters.labels = True

    # Define input files to use
    SinglefileData = DataFactory('singlefile')
    datafile = SinglefileData(
        file=os.path.join(TEST_DIR, 'input_files', 'datafile'))

    # Set up calculation
    inputs = {
        'code': logger_code,
        'parameters': DataFactory('dict')(dict=parameters),
        'datafiles': {
            'datafile': datafile
        },
        'metadata': {
            'options': {
                'resources': {
                    'num_machines': 1,
                    'num_mpiprocs_per_machine': 1
                },
                'parser_name': 'logger',
                'withmpi': False,
                'output_filename': 'logger.out'
            },
            'description': 'Test job submission with the aiida_logger plugin'
        },
    }

    result = run(CalculationFactory('logger'), **inputs)

    assert 'data' in result
    assert 'metadata' in result

    data = result['data']
    metadata = result['metadata']
    metadata = metadata.get_dict()

    assert 'labels' in metadata
    assert 'comments' in metadata
    assert metadata['labels'] == ['time', 'param1', 'param2', 'param3']
    assert metadata['comments'][0] == '# This is an example file'
    test_array = np.array([[1.0e+00, 3.0e+00, 4.0e+00, 5.0e+00],
                           [2.0e+00, 4.0e+00, 5.7e+00, -1.0e-01],
                           [3.0e+00, 1.0e-03, 1.0e+03, 8.0e-01]])
    np.testing.assert_allclose(data.get_array('content'), test_array)