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.launch 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.pk)) else: run(PwBandStructureWorkChain, **inputs)
def test_create(self): a = Float() # Check that initial value is zero self.assertEqual(a.value, 0.0) f = Float(6.0) self.assertEqual(f.value, 6.) self.assertEqual(f, Float(6.0)) i = Int() self.assertEqual(i.value, 0) i = Int(6) self.assertEqual(i.value, 6) self.assertEqual(f, i) b = Bool() self.assertEqual(b.value, False) b = Bool(False) self.assertEqual(b.value, False) self.assertEqual(b.value, get_false_node()) b = Bool(True) self.assertEqual(b.value, True) self.assertEqual(b.value, get_true_node()) s = Str() self.assertEqual(s.value, "") s = Str('Hello') self.assertEqual(s.value, 'Hello')
def test_context(self): A = Str("a") B = Str("b") @workfunction def a(): return A @workfunction def b(): return B class Wf(WorkChain): @classmethod def define(cls, spec): super(Wf, cls).define(spec) spec.outline(cls.s1, cls.s2, cls.s3) def s1(self): return ToContext(r1=Outputs(async (a)), r2=Outputs(async (b))) def s2(self): assert self.ctx.r1['_return'] == A assert self.ctx.r2['_return'] == B # Try overwriting r1 return ToContext(r1=Outputs(async (b))) def s3(self): assert self.ctx.r1['_return'] == B assert self.ctx.r2['_return'] == B Wf.run()
def test_run(self): A = Str('A') B = Str('B') C = Str('C') three = Int(3) # Try the if(..) part Wf.run(value=A, n=three) # Check the steps that should have been run for step, finished in Wf.finished_steps.iteritems(): if step not in ['s3', 's4', 'isB']: self.assertTrue( finished, "Step {} was not called by workflow".format(step)) # Try the elif(..) part finished_steps = Wf.run(value=B, n=three) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['isA', 's2', 's4']: self.assertTrue( finished, "Step {} was not called by workflow".format(step)) # Try the else... part finished_steps = Wf.run(value=C, n=three) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['isA', 's2', 'isB', 's3']: self.assertTrue( finished, "Step {} was not called by workflow".format(step))
def test_context(self): A = Str("a") B = Str("b") @workfunction def a(): return A @workfunction def b(): return B class Wf(WorkChain): @classmethod def define(cls, spec): super(Wf, cls).define(spec) spec.outline(cls.s1, cls.s2, cls.s3) def s1(self): self.ctx.r1 = run(a) self.ctx.r2 = run(b) def s2(self): assert self.ctx.r1 == A assert self.ctx.r2 == B # Try overwriting r1 self.ctx.r1 = run(b) def s3(self): assert self.ctx.r1 == B assert self.ctx.r2 == B Wf.run()
def test_checkpointing(self): A = Str('A') B = Str('B') C = Str('C') three = Int(3) # Try the if(..) part finished_steps = \ self._run_with_checkpoints(Wf, inputs={'value': A, 'n': three}) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['s3', 's4', 'isB']: self.assertTrue( finished, "Step {} was not called by workflow".format(step)) # Try the elif(..) part finished_steps = \ self._run_with_checkpoints(Wf, inputs={'value': B, 'n': three}) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['isA', 's2', 's4']: self.assertTrue( finished, "Step {} was not called by workflow".format(step)) # Try the else... part finished_steps = \ self._run_with_checkpoints(Wf, inputs={'value': C, 'n': three}) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['isA', 's2', 'isB', 's3']: self.assertTrue( finished, "Step {} was not called by workflow".format(step))
def run(structure_pk, code, atomic_files, group, partition, ranks_per_node, ranks_kp, ranks_diag, kmesh): # load code from label@computer c = Code.get_from_string(code) if not atomic_files: if c.get_input_plugin_name() == 'quantumespresso.pw': atomic_files = 'SSSP_acc_PBE' if c.get_input_plugin_name() == 'exciting.exciting': atomic_files = 'high_quality_lapw_species' # create k-point mesh k = List() k.extend(kmesh) for spk in structure_pk: # load structure from PK structure = load_node(spk) # create stress tensor workflow stress_tensor = Stress_Tensor() stress_tensor.run(structure=structure, code=c, atomic_files=Str(atomic_files), group=Str(group), kmesh=k, partition=Str(partition), ranks_per_node=Int(ranks_per_node), ranks_kp=Int(ranks_kp), ranks_diag=Int(ranks_diag))
def run_eos_wf(codename, pseudo_family, element): print "Workfunction node identifiers: {}".format(Process.current().calc) s0 = create_diamond_fcc(Str(element)) calcs = {} for label, factor in zip(labels, scale_facs): s = rescale(s0, Float(factor)) inputs = generate_scf_input_params(s, str(codename), Str(pseudo_family)) print "Running a scf for {} with scale factor {}".format( element, factor) result = run(PwCalculation, **inputs) print "RESULT: {}".format(result) calcs[label] = get_info(result) eos = [] for label in labels: eos.append(calcs[label]) # Return information to plot the EOS ParameterData = DataFactory('parameter') retdict = { 'initial_structure': s0, 'result': ParameterData(dict={'eos_data': eos}) } return retdict
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))
def run_sub3(self): print('run_sub3') inputs_sub = Str('This is wonderful 3.1') inputs_sub2 = Str('This is wonderful 3.2') res = async (sub_dummy_wc, str_display=inputs_sub) res2 = async (sub_dummy_wc, str_display=inputs_sub2) return ToContext(sub31=res, sub32=res2)
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))
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)
def define(cls, spec): super(FTGeoOptWorkChain, cls).define(spec) spec.input("cp2k_code", valid_type=Code) spec.input("structure", valid_type=StructureData) spec.input("num_machines", valid_type=Int, default=Int(1)) spec.input("wavefunction", valid_type=Str, default=Str('')) spec.input("fixed_atoms", valid_type=Str, default=Str('')) spec.outline( cls.run_geopt, while_(cls.not_converged)(cls.run_geopt_again), ) spec.dynamic_output()
def run_bands(self): """ Run the PwBandsWorkChain to compute the band structure """ inputs = dict(self.ctx.inputs) options = inputs['options'] settings = inputs['settings'] parameters = inputs['parameters'] # Final input preparation, wrapping dictionaries in ParameterData nodes inputs['kpoints_mesh'] = self.ctx.kpoints_mesh inputs['parameters'] = ParameterData(dict=parameters) inputs['settings'] = ParameterData(dict=settings) inputs['options'] = ParameterData(dict=options) inputs['relax'] = { 'kpoints_distance': Float(self.ctx.protocol['kpoints_mesh_density']), 'parameters': ParameterData(dict=parameters), 'settings': ParameterData(dict=settings), 'options': ParameterData(dict=options), 'meta_convergence': Bool(False), 'relaxation_scheme': Str('vc-relax'), 'volume_convergence': Float(0.01) } running = self.submit(PwBandsWorkChain, **inputs) self.report('launching PwBandsWorkChain<{}>'.format(running.pk)) return ToContext(workchain_bands=running)
def define(cls, spec): super(GollumSiestaWorkChain, cls).define(spec) spec.input('siesta_code', valid_type=Code) spec.input('gollum_code', valid_type=Code) spec.input('structure_le', valid_type=StructureData) spec.input('structure_em', valid_type=StructureData) spec.input('protocol', valid_type=Str, default=Str('standard')) spec.input('kpoints_le', valid_type=KpointsData) spec.input('kpoints_em', valid_type=KpointsData) spec.input('parameters', valid_type=ParameterData) spec.outline( cls.setup_siesta_inputs, cls.setup_protocol, cls.setup_structures, cls.setup_pseudo_potentials, cls.setup_siesta_parameters, cls.setup_basis, cls.setup_kpoints, cls.run_leads, cls.run_extmol, cls.setup_gollum_inputs, cls.setup_gollum_settings, cls.setup_gollum_parameters, cls.run_gollum, cls.run_results, ) spec.dynamic_output()
def return_out(self): time.sleep(65) message = 'generating output nodes sub_dummy' self.report(message) outdict = {'out_sub_dummy_wc' : Str('wonderful sub_dummy_wc')} for link_name, node in outdict.iteritems(): self.out(link_name, node)
def return_out(self): message = 'generating output nodes' self.report(message) subout = '{} | {} | {}, {}'.format(self.ctx.sub1, self.ctx.sub2, self.ctx.sub31, self.ctx.sub32) self.report(subout) outdict = {'out_dummy_wc' : Str('wonderful dummy_wc')} for link_name, node in outdict.iteritems(): self.out(link_name, node)
def define(cls, spec): super(SlabGeoOptWorkChain, cls).define(spec) spec.input("cp2k_code", valid_type=Code) spec.input("structure", valid_type=StructureData) spec.input("max_force", valid_type=Float, default=Float(0.001)) spec.input("calc_type", valid_type=Str, default=Str('Mixed DFTB')) spec.input("vdw_switch", valid_type=Bool, default=Bool(False)) spec.input("mgrid_cutoff", valid_type=Int, default=Int(600)) spec.input("fixed_atoms", valid_type=Str, default=Str('')) spec.input("center_switch", valid_type=Bool, default=Bool(False)) spec.input("num_machines", valid_type=Int, default=Int(1)) spec.outline( cls.run_geopt, while_(cls.not_converged)(cls.run_geopt_again), ) spec.dynamic_output()
def runEos(self): inputs = dict = {'element' : self.inputs.element} inputs['code']=Str('QEmodule@parsons') pseu=self.ctx.resul.out.pseupf inputs['pseudo']=pseu inputs['_label']="{0} {1} {2} {3}".format(self.ctx.scut,self.ctx.pcut,self.ctx.dcut,self.ctx.fcut) inputs['_description']="T1" print "Runnin eos" fut = submit(EquationOfStates, **inputs) return ToContext(res=fut) #Here it waits
def test_db_flushed(configure): from aiida.orm.data.base import Str test_string = 'this string should not be present when the test run starts' tag = 'Test string tag' from aiida.orm.querybuilder import QueryBuilder qb = QueryBuilder() qb.append(Str, filters={'label': {'==': tag}}) assert not qb.all() str_obj = Str(test_string) str_obj.label = tag str_obj.store()
def test_queue_up(self): inputs = {'a': Int(2), 'b': Str('test')} # Queue up the process pid = queue_up(DummyProcess, inputs, self.storage) # Then load the checkpoint and instantiate the class cp = self.storage.load_checkpoint(pid) dp = DummyProcess.create_from(cp) self.assertIsInstance(dp, DummyProcess) self.assertEqual(dp.raw_inputs, inputs) dp.run_until_complete()
def to_db_type(value): if isinstance(value, Data): return value elif isinstance(value, bool): return Bool(value) elif isinstance(value, (int, long)): return Int(value) elif isinstance(value, float): return Float(value) elif isinstance(value, basestring): return Str(value) else: raise ValueError("Cannot convert value to database type")
def define(cls, spec): super(EnergyWorkChain, cls).define(spec) spec.input("cp2k_code", valid_type=Code) spec.input("structure", valid_type=StructureData) spec.input("num_machines", valid_type=Int, default=Int(1)) spec.input("wavefunction", valid_type=Str, default=Str('')) spec.input("gasphase", valid_type=Bool, default=Bool(False)) spec.outline( cls.run_ene, while_(cls.not_converged)(cls.run_ene_again), ) spec.dynamic_output()
def define(cls, spec): super(ReplicaWorkchain, cls).define(spec) spec.input("cp2k_code", valid_type=Code) spec.input("structure", valid_type=StructureData) spec.input("num_machines", valid_type=Int, default=Int(54)) spec.input("replica_name", valid_type=Str) spec.input("cell", valid_type=Str, default=Str('')) spec.input("fixed_atoms", valid_type=Str, default=Str('')) spec.input("colvar_targets", valid_type=Str) spec.input("target_unit", valid_type=Str) spec.input("spring", valid_type=Float, default=Float(75.0)) spec.input("spring_unit", valid_type=Str) spec.input("subsys_colvar", valid_type=ParameterData) spec.input("calc_type", valid_type=Str) spec.outline( cls.init, while_(cls.next_replica)(cls.generate_replica, while_(cls.not_converged)( cls.generate_replica), cls.store_replica)) spec.dynamic_output()
def calc_energies(codename, pseudo_family): print("Calculating energies, my pk is '{}'".format( ProcessStack.get_active_process_id())) futures = {} for element, scale in [("Si", 5.41)]: structure = create_diamond_fcc(Str(element), Float(1.)) structure = rescale(structure, Float(scale)) print("Running {} scf calculation.".format(element)) futures[element] = async(run_scf, structure, codename, pseudo_family) print("Waiting for calculations to finish.") outs = {element: Float(future.result()['output_parameters'].dict.energy) for element, future in futures.iteritems()} print("Calculations finished.") return outs
def run_sub1(self): """ Submiting this subwork chain is still buggy somehow... """ print('run_sub1') n = 3 allres = {} time.sleep(35) for i in range(0,n): inputs_sub = Str('This is wonderful 1.{}'.format(i)) res = submit(sub_dummy_wc, str_display=inputs_sub) label = 'sub1_run{}'.format(i) allres[label] = res time.sleep(65) self.get_input() return ToContext(**allres)
def define(cls, spec): super(PdosWorkChain, cls).define(spec) spec.input("cp2k_code", valid_type=Code) spec.input("slabsys_structure", valid_type=StructureData) spec.input("mol_structure", valid_type=StructureData) spec.input("pdos_lists", valid_type=List) spec.input("mgrid_cutoff", valid_type=Int, default=Int(600)) spec.input("wfn_file_path", valid_type=Str, default=Str("")) spec.input("elpa_switch", valid_type=Bool, default=Bool(True)) spec.input("overlap_code", valid_type=Code) spec.input("overlap_params", valid_type=ParameterData) spec.outline(cls.run_scfs, cls.run_overlap) spec.dynamic_output()
def define(cls, spec): super(SiestaBandsWorkChain, cls).define(spec) spec.input('code', valid_type=Code) spec.input('structure', valid_type=StructureData) spec.input('protocol', valid_type=Str, default=Str('standard')) spec.outline( cls.setup_protocol, cls.setup_structure, cls.setup_kpoints, cls.setup_pseudo_potentials, cls.setup_parameters, cls.setup_basis, cls.run_relax, cls.run_bands, # We can run this directly, a combined scf+bands cls.run_results, ) spec.dynamic_output()
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 define(cls, spec): super(OrbitalWorkChain, cls).define(spec) spec.input("cp2k_code", valid_type=Code) spec.input("structure", valid_type=StructureData) spec.input("wfn_file_path", valid_type=Str, default=Str("")) spec.input("dft_params", valid_type=ParameterData) spec.input("stm_code", valid_type=Code) spec.input("stm_params", valid_type=ParameterData) spec.outline( cls.run_scf_diag, cls.run_stm, ) spec.dynamic_output()