Example #1
0
    def converge_scf(self):
        """
        start scf-cycle from Fleur calculation
        """
        # run a convergence worklfow
        # Comment: Here we wait, because of run,
        # maybe using a future and submit instead might be better
        #print 'ctx, before scf {} {}'.format(ctx, [a for a in self.ctx])
        inputs = self.get_inputs_scf(self.ctx)

        if self.ctx.last_calc2:
            #print 'inputs for convergnce2: {}'.format(inputs)
            res = run(fleur_scf_wc,
                      wf_parameters=inputs['wf_parameters'],
                      fleurinp=inputs['fleurinp'],
                      fleur=inputs['fleur'])
            #inputs)#
            #wf_parameters=wf_para,
            #structure=s,
            #calc_parameters=parameters,
            #inpgen = code,
            #fleur=code2)#, computer=computer)
        else:
            res = run(fleur_scf_wc,
                      wf_parameters=inputs['wf_parameters'],
                      structure=inputs['structure'],
                      calc_parameters=inputs['calc_parameters'],
                      inpgen=inputs['inpgen'],
                      fleur=inputs['fleur'])  #inputs)#
        #print 'ctx, after scf {} {}'.format(ctx, [a for a in self.ctx])

        #print 'output of convergence: {}'.format(res)
        self.ctx.last_calc2 = res  #.get('remote_folder', None)
Example #2
0
def launch(
    code, parent_calc, kpoints, max_num_machines, max_wallclock_seconds, daemon):
    """
    Run the MatdynBaseWorkChain for a previously completed Q2rCalculation
    """
    from aiida.orm.data.parameter import ParameterData
    from aiida.orm.utils import CalculationFactory, WorkflowFactory
    from aiida.work.run import run, submit
    from aiida_quantumespresso.utils.resources import get_default_options

    MatdynBaseWorkChain = WorkflowFactory('quantumespresso.matdyn.base')

    options = get_default_options(max_num_machines, max_wallclock_seconds)

    inputs = {
        'code': code,
        'kpoints': kpoints,
        'parent_folder': parent_calc.out.force_constants,
        'options': ParameterData(dict=options),
    }

    if daemon:
        workchain = submit(MatdynBaseWorkChain, **inputs)
        click.echo('Submitted {}<{}> to the daemon'.format(MatdynBaseWorkChain.__name__, workchain.pid))
    else:
        run(MatdynBaseWorkChain, **inputs)
Example #3
0
def launch(code, structure, pseudo_family, daemon, protocol):
    """
    Run the PwBandStructureWorkChain for a given input structure 
    to compute the band structure for the relaxed structure
    """
    from aiida.orm.data.base import Str
    from aiida.orm.utils import WorkflowFactory
    from aiida.work.run import run, submit

    PwBandStructureWorkChain = WorkflowFactory(
        'quantumespresso.pw.band_structure')

    inputs = {
        'code': code,
        'structure': structure,
        'pseudo_family': Str(pseudo_family),
        'protocol': Str(protocol),
    }

    if daemon:
        workchain = submit(PwBandStructureWorkChain, **inputs)
        click.echo('Submitted {}<{}> to the daemon'.format(
            PwBandStructureWorkChain.__name__, workchain.pid))
    else:
        run(PwBandStructureWorkChain, **inputs)
Example #4
0
def launch(code, structure, pseudo_family, kpoints, max_num_machines,
           max_wallclock_seconds, daemon, automatic_parallelization,
           clean_workdir, final_scf, group):
    """
    Run the PwRelaxWorkChain for a given input structure
    """
    from aiida.orm.data.base import Bool, Str
    from aiida.orm.data.parameter import ParameterData
    from aiida.orm.utils import WorkflowFactory
    from aiida.work.run import run, submit
    from aiida_quantumespresso.utils.resources import get_default_options

    PwRelaxWorkChain = WorkflowFactory('quantumespresso.pw.relax')

    parameters = {
        'SYSTEM': {
            'ecutwfc': 30.,
            'ecutrho': 240.,
        },
    }

    inputs = {
        'code': code,
        'structure': structure,
        'pseudo_family': Str(pseudo_family),
        'kpoints': kpoints,
        'parameters': ParameterData(dict=parameters),
    }

    if automatic_parallelization:
        parallelization = {
            'max_num_machines': max_num_machines,
            'target_time_seconds': 0.5 * max_wallclock_seconds,
            'max_wallclock_seconds': max_wallclock_seconds
        }
        inputs['automatic_parallelization'] = ParameterData(
            dict=parallelization)
    else:
        options = get_default_options(max_num_machines, max_wallclock_seconds)
        inputs['options'] = ParameterData(dict=options)

    if clean_workdir:
        inputs['clean_workdir'] = Bool(True)

    if final_scf:
        inputs['final_scf'] = Bool(True)

    if group:
        inputs['group'] = Str(group)

    if daemon:
        workchain = submit(PwRelaxWorkChain, **inputs)
        click.echo('Submitted {}<{}> to the daemon'.format(
            PwRelaxWorkChain.__name__, workchain.pid))
    else:
        run(PwRelaxWorkChain, **inputs)
Example #5
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)
Example #6
0
def execute(args):
    """
    The main execution of the script, which will run some preliminary checks on the command
    line arguments before passing them to the workchain and running it
    """
    try:
        code = Code.get_from_string(args.codename)
    except NotExistent as exception:
        print "Execution failed: could not retrieve the code '{}'".format(args.codename)
        print "Exception report: {}".format(exception)
        return

    try:
        parent_calc = load_node(args.parent_calc)
    except NotExistent as exception:
        print "Execution failed: failed to load the node for the given parent calculation '{}'".format(args.parent_calc)
        print "Exception report: {}".format(exception)
        return

    if not isinstance(parent_calc, PwCalculation):
        print "The provided parent calculation {} is not of type PwCalculation, aborting...".format(args.parent_calc)
        return

    qpoints = KpointsData()
    qpoints.set_kpoints_mesh(args.qpoints)

    parameters = {
        'INPUTPH': {
            'tr2_ph': 1e-10,
        }
    }
    settings = {}
    options  = {
        'resources': {
            'num_machines': 1
        },
        'max_wallclock_seconds': args.max_wallclock_seconds,
    }

    run(
        PhBaseWorkChain,
        code=code,
        parent_calc=parent_calc,
        qpoints=qpoints,
        parameters=ParameterData(dict=parameters),
        settings=ParameterData(dict=settings),
        options=ParameterData(dict=options),
        max_iterations=Int(args.max_iterations)
    )
Example #7
0
def test_changed_seedname(create_gaas_calc, configure_with_daemon,
                          assert_finished):
    from aiida.work.run import run
    process, inputs = create_gaas_calc(seedname='wannier90')
    output, pid = run(process, _return_pid=True, **inputs)
    assert all(key in output for key in ['retrieved', 'output_parameters'])
    assert_finished(pid)
Example #8
0
def run_eos(element="Si",
            code='qe-pw-6.2.1@localhost',
            pseudo_family='GBRV_lda'):
    return run(EquationOfStates,
               element=Str(element),
               code=Str(code),
               pseudo_family=Str(pseudo_family))
Example #9
0
def test_filter_symmetries(configure_with_daemon, filter_symmetries_inputs):
    from aiida.work.run import run

    builder = filter_symmetries_inputs
    output = run(builder)

    assert 'symmetries' in output
Example #10
0
    def test_same_input_node(self):
        class Wf(WorkChain):
            @classmethod
            def define(cls, spec):
                super(Wf, cls).define(spec)
                spec.input('a', valid_type=Int)
                spec.input('b', valid_type=Int)
                # Try defining an invalid outline
                spec.outline(cls.check_a_b)

            def check_a_b(self):
                assert 'a' in self.inputs
                assert 'b' in self.inputs

        x = Int(1)
        run(Wf, a=x, b=x)
def test_caching(create_gaas_calc, configure_with_daemon, assert_finished):
    from aiida.work.run import run
    from aiida.orm import load_node
    from aiida.common.hashing import make_hash
    try:
        from aiida.common import caching
    except ImportError:
        pytest.skip("The used version of aiida-core does not support caching.")
    process, inputs = create_gaas_calc()
    output, pid = run(process, _return_pid=True, **inputs)
    output2, pid2 = run(process, _use_cache=True, _return_pid=True, **inputs)
    assert '_aiida_cached_from' in load_node(pid2).extras()
    assert all(key in output for key in ['retrieved', 'output_parameters'])
    assert all(key in output2 for key in ['retrieved', 'output_parameters'])
    assert_finished(pid)
    assert_finished(pid2)
Example #12
0
def test_changed_seedname_no_settings(create_gaas_calc, configure_with_daemon,
                                      assert_state):
    from aiida.work.run import run
    from aiida.common.datastructures import calc_states
    process, inputs = create_gaas_calc(seedname='wannier90')
    del inputs.settings
    output, pid = run(process, _return_pid=True, **inputs)
    assert_state(pid, calc_states.SUBMISSIONFAILED)
Example #13
0
def test_empty_settings(create_gaas_calc, configure_with_daemon, assert_state):
    from aiida.work.run import run
    from aiida.orm import DataFactory
    from aiida.common.datastructures import calc_states
    process, inputs = create_gaas_calc()
    inputs.settings = DataFactory('parameter')()
    output, pid = run(process, _return_pid=True, **inputs)
    assert_state(pid, calc_states.FINISHED)
Example #14
0
def test_plot(configure_with_daemon, plot_process_inputs):
    from aiida.work.run import run
    from aiida.orm import DataFactory

    process, inputs = plot_process_inputs
    output = run(process, _use_cache=False, **inputs)
    assert 'plot' in output
    assert isinstance(output['plot'], DataFactory('singlefile'))
def execute(args):
    """
    The main execution of the script, which will run some preliminary checks on the command
    line arguments before passing them to the workchain and running it
    """
    try:
        code = Code.get_from_string(args.codename)
    except NotExistent as exception:
        print "Execution failed: could not retrieve the code '{}'".format(args.codename)
        print "Exception report: {}".format(exception)
        return

    try:
        structure = load_node(args.structure)
    except NotExistent as exception:
        print "Execution failed: failed to load the node for the given structure pk '{}'".format(args.structure)
        print "Exception report: {}".format(exception)
        return

    if not isinstance(structure, StructureData):
        print "The provided pk {} for the structure does not correspond to StructureData, aborting...".format(args.parent_calc)
        return

    kpoints = KpointsData()
    kpoints.set_kpoints_mesh(args.kpoints)

    parameters = load_property_json('parameters.json')
    basis = load_property_json('basis.json')
    settings = load_property_json('settings.json')
    options = load_property_json('options.json')

    options['max_wallclock_seconds'] = args.max_wallclock_seconds

    run(
        SiestaWorkChain,
        code=code,
        structure=structure,
        pseudo_family=Str(args.pseudo_family),
        kpoints=kpoints,
        parameters=ParameterData(dict=parameters),
        settings=ParameterData(dict=settings),
        options=ParameterData(dict=options),
        basis=ParameterData(dict=basis),
        max_iterations=Int(args.max_iterations),
    )
def run_eos(structure,
            element="Si",
            code='qe-pw-6.2.1@localhost',
            pseudo_family='GBRV_lda'):
    return run(PressureConvergence,
               structure=structure,
               code=Str(code),
               pseudo_family=Str(pseudo_family),
               volume_tolerance=Float(0.1))
Example #17
0
def eos(structure, codename, pseudo_family):
    Proc = PwCalculation.process()
    results = {}
    for s in (0.98, 0.99, 1.0, 1.02, 1.04):
        rescaled = rescale(structure, Float(s))
        inputs = generate_scf_input_params(rescaled, codename, pseudo_family)
        outputs = run(Proc, **inputs)
        res = outputs['output_parameters'].dict
        results[str(s)] = res

    return results
Example #18
0
def launch(code, structure, pseudo_family, kpoints, max_num_machines,
           max_wallclock_seconds, daemon, mode):
    """
    Run a PwCalculation for a given input structure
    """
    from aiida.orm import load_node
    from aiida.orm.data.parameter import ParameterData
    from aiida.orm.data.upf import get_pseudos_from_structure
    from aiida.orm.utils import CalculationFactory
    from aiida.work.run import run, submit
    from aiida_quantumespresso.utils.resources import get_default_options

    PwCalculation = CalculationFactory('quantumespresso.pw')

    parameters = {
        'CONTROL': {
            'calculation': mode,
        },
        'SYSTEM': {
            'ecutwfc': 30.,
            'ecutrho': 240.,
        },
    }

    inputs = {
        'code': code,
        'structure': structure,
        'pseudo': get_pseudos_from_structure(structure, pseudo_family),
        'kpoints': kpoints,
        'parameters': ParameterData(dict=parameters),
        'settings': ParameterData(dict={}),
        '_options': get_default_options(max_num_machines,
                                        max_wallclock_seconds),
    }

    process = PwCalculation.process()

    if daemon:
        calculation = submit(process, **inputs)
        click.echo('Submitted {}<{}> to the daemon'.format(
            PwCalculation.__name__, calculation.pid))
    else:
        click.echo('Running a PwCalculation in the {} mode... '.format(mode))
        results, pk = run(process, _return_pid=True, **inputs)
        calculation = load_node(pk)

        click.echo('PwCalculation<{}> terminated with state: {}'.format(
            pk, calculation.get_state()))
        click.echo('\n{link:25s} {node}'.format(link='Output link',
                                                node='Node pk and type'))
        click.echo('{s}'.format(s='-' * 60))
        for link, node in sorted(calculation.get_outputs(also_labels=True)):
            click.echo('{:25s} <{}> {}'.format(link, node.pk,
                                               node.__class__.__name__))
Example #19
0
def test_vasp2w90(
        configure_with_daemon,  # pylint: disable=unused-argument
        sample,
        get_gaas_process_inputs,  # pylint: disable=redefined-outer-name
        assert_finished):
    """Vasp2w90 unit test"""
    from aiida.work.run import run
    from aiida.orm import DataFactory
    from aiida.orm.data.base import List

    process, inputs = get_gaas_process_inputs(
        calculation_string='vasp.vasp2w90',
        parameters={
            'ncore': 1,
            'isym': -1,
            'icharg': 11,
            'lwave': False
        })
    charge_density = DataFactory('vasp.chargedensity')()
    charge_density.set_file(sample('GaAs/CHGCAR'))
    inputs.charge_density = charge_density

    wannier_input_parameters = dict(
        dis_num_iter=1000,
        num_bands=24,
        num_iter=0,
        num_wann=14,
        spinors=True,
    )
    inputs.wannier_parameters = DataFactory('parameter')(
        dict=wannier_input_parameters)

    wannier_projections = List()
    wannier_projections.extend(['Ga : s; px; py; pz', 'As : px; py; pz'])
    inputs.wannier_projections = wannier_projections

    output, pid = run(process, _return_pid=True, **inputs)
    assert all(key in output for key in [
        'retrieved', 'kpoints', 'wannier_parameters', 'wannier_kpoints',
        'wannier_projections'
    ])
    # check that the input parameters are preserved
    wannier_output_parameters = output['wannier_parameters'].get_dict()
    for key, value in wannier_input_parameters.items():
        assert key in wannier_output_parameters
        out_value = eval(
            wannier_output_parameters[key].strip('.').capitalize())  # pylint: disable=eval-used
        assert value == out_value
    # check that the projections block is preserved
    assert wannier_projections.get_attr(
        'list') == output['wannier_projections'].get_attr('list')

    assert_finished(pid)
Example #20
0
def registry_tester():
    # Call a wf
    result, pid = run(nested_tester, _return_pid=True)
    assert pid == result['pid']
    assert pid == result['node_pk']

    # Call a Process
    StackTester.run()

    return {
        'pid': Int(ProcessStack.get_active_process_id()),
        'node_pk': Int(ProcessStack.get_active_process_calc_node().pk)
    }
Example #21
0
    def test_calculation_input(self):
        @workfunction
        def simple_wf():
            return {'a': Int(6), 'b': Int(7)}

        outputs, pid = run(simple_wf, _return_pid=True)
        calc = load_node(pid)
        dp = DummyProcess.new_instance(inputs={'calc': calc})
        dp.run_until_complete()

        input_calc = dp.calc.get_inputs_dict()['calc']
        self.assertTrue(isinstance(input_calc, FrozenDict))
        self.assertEqual(input_calc['a'], outputs['a'])
Example #22
0
    def test_seal(self):
        rinfo = run(DummyProcess, _return_pid=True)[1]
        self.assertTrue(load_node(pk=rinfo).is_sealed)

        storedir = tempfile.mkdtemp()
        storage = Persistence.create_from_basedir(storedir)

        rinfo = submit(DummyProcess, _jobs_store=storage)
        n = load_node(pk=rinfo.pid)
        self.assertFalse(n.is_sealed)

        dp = DummyProcess.create_from(storage.load_checkpoint(rinfo.pid))
        dp.run_until_complete()
        self.assertTrue(n.is_sealed)
        shutil.rmtree(storedir)
Example #23
0
    def test_tocontext_async_workchain(self):
        class MainWorkChain(WorkChain):
            @classmethod
            def define(cls, spec):
                super(MainWorkChain, cls).define(spec)
                spec.outline(cls.run, cls.check)
                spec.dynamic_output()

            def run(self):
                return ToContext(subwc=async (SubWorkChain))

            def check(self):
                assert self.ctx.subwc.out.value == Int(5)

        class SubWorkChain(WorkChain):
            @classmethod
            def define(cls, spec):
                super(SubWorkChain, cls).define(spec)
                spec.outline(cls.run)

            def run(self):
                self.out("value", Int(5))

        run(MainWorkChain)
Example #24
0
def test_vasp(configure_with_daemon, get_gaas_process_inputs, assert_finished):  # pylint: disable=unused-argument,redefined-outer-name
    """Vasp calculation integration test"""

    from aiida.work.run import run
    from aiida.orm import DataFactory

    process, inputs = get_gaas_process_inputs(calculation_string='vasp.vasp',
                                              parameters={'ncore': 4})
    inputs.settings = DataFactory('parameter')(dict={
        'ADDITIONAL_RETRIEVE_LIST': ['CHGCAR']
    })
    output, pid = run(process, _return_pid=True, **inputs)
    assert_finished(pid)
    assert all(filename in output['retrieved'].get_folder_list() for filename
               in ['OUTCAR', 'EIGENVAL', 'DOSCAR', 'CHGCAR', 'vasprun.xml'])
Example #25
0
def test_duplicate_exclude_bands(create_gaas_calc, configure_with_daemon,
                                 assert_state):
    from aiida.work.run import run
    from aiida.orm import DataFactory
    from aiida.common.datastructures import calc_states
    process, inputs = create_gaas_calc(projections_dict={
        'kind_name': 'As',
        'ang_mtm_name': 's'
    })
    inputs.parameters = DataFactory('parameter')(
        dict=dict(num_wann=1,
                  num_iter=12,
                  wvfn_formatted=True,
                  exclude_bands=[1] * 2 + [2, 3]))
    output, pid = run(process, _return_pid=True, **inputs)
    assert all(key in output for key in ['retrieved', 'output_parameters'])
    assert_state(pid, calc_states.FAILED)
Example #26
0
    def test_run_workchain(self):
        """Test running the WorkChain"""
        from aiida.work.run import run
        from aiida.orm.data.cif import CifData
        from aiida_phtools.workflows.dmatrix import DistanceMatrixWorkChain

        structure = CifData(file=os.path.join(pt.TEST_DIR, 'HKUST-1.cif'),
                            parse_policy='lazy')

        outputs = run(
            DistanceMatrixWorkChain,
            structure=structure,
            zeopp_code=self.zeopp_code,
            pore_surface_code=self.pore_surface_code,
            distance_matrix_code=self.distance_matrix_code,
            rips_code=self.rips_code,
        )

        print(outputs)
Example #27
0
    def setUpClass(cls):
        """
        Create a simple workchain and run it.
        """
        super(TestVerdiWorkCommands, cls).setUpClass()
        from aiida.work.run import run
        from aiida.work.workchain import WorkChain
        TEST_STRING = 'Test report.'
        cls.test_string = TEST_STRING

        class Wf(WorkChain):
            @classmethod
            def define(cls, spec):
                super(Wf, cls).define(spec)
                spec.outline(cls.create_logs)

            def create_logs(self):
                self.report(TEST_STRING)

        _, cls.workchain_pid = run(Wf, _return_pid=True)
Example #28
0
def test_vasp2w90(
        configure_with_daemon,  # pylint: disable=unused-argument
        sample,
        get_gaas_process_inputs,  # pylint: disable=redefined-outer-name
        assert_finished):
    """Vasp2W90 unit test"""
    from aiida.work.run import run
    from aiida.orm import DataFactory
    from aiida.orm.data.base import List

    process, inputs = get_gaas_process_inputs(
        calculation_string='vasp.vasp2w90',
        parameters={
            'ncore': 1,
            'isym': -1,
            'icharg': 11,
            'lwave': False
        })
    charge_density = DataFactory('vasp.chargedensity')()
    charge_density.set_file(sample('GaAs/CHGCAR'))
    inputs.charge_density = charge_density

    wannier_parameters = DataFactory('parameter')(dict=dict(
        dis_num_iter=1000,
        num_bands=24,
        num_iter=0,
        num_wann=14,
        spinors=True,
    ))
    inputs.wannier_parameters = wannier_parameters

    wannier_projections = List()
    wannier_projections.extend(['Ga : s; px; py; pz', 'As : px; py; pz'])
    inputs.wannier_projections = wannier_projections

    output, pid = run(process, _return_pid=True, **inputs)
    assert all(key in output for key in [
        'retrieved', 'kpoints', 'wannier_parameters', 'wannier_kpoints',
        'wannier_projections'
    ])
    assert_finished(pid)
    def run_wf():
        # print "Workfunction node identifiers: {}".format(ProcessRegistry().current_calc_node)
        wcalc_uuid = ProcessRegistry().current_calc_node.uuid
        print "Workfunction node: {}".format(wcalc_uuid)
        #Instantiate a JobCalc process and create basic structure
        JobCalc = SiestaCalculation.process()
        s0 = create_structure()
        calcs = {}
        for label, factor in zip(labels, scale_facs):
            s = rescale(s0, Float(factor))
            inputs = geninputs(s)
            print "Running a scf for Si with scale factor {}".format(factor)
            result = run(JobCalc, **inputs)
            calcs[label] = get_info(result, s)

        eos = []
        for label in labels:
            eos.append(calcs[label])

        retdict = {'result': ParameterData(dict={'eos_data': eos})}

        return retdict
Example #30
0
    def setUpClass(cls, *args, **kwargs):
        """
        Create a simple workchain and run it.
        """
        super(TestVerdiWorkCommands, cls).setUpClass()
        from aiida.work.run import run
        from aiida.work.workchain import WorkChain
        TEST_STRING = 'Test report.'
        cls.test_string = TEST_STRING

        # pylint: disable=abstract-method
        class Wf(WorkChain):
            @classmethod
            def define(cls, spec):
                super(Wf, cls).define(spec)
                spec.outline(cls.create_logs)

            def create_logs(self):
                self.report(TEST_STRING)

            # Note: Method 'get_exec_engine' is abstract in class 'Process'
            # but is not overridden.

        _, cls.workchain_pid = run(Wf, _return_pid=True)