def run_eos_wc(self): """ Run the fleur_eos_wc """ structure = self.inputs.structure eos_wc_para = self.inputs.wf_parameters optimize_res = self.ctx.optimize_res calc_parameters = optimize_res.get('optimized_para') fleur = self.inputs.fleur inpgen = self.inputs.inpgen form = structure.get_formula() label = 'fleur_eos_wc on {}'.format(form) description = 'Fleur eos of {}'.format(form) eos_res = submit(fleur_eos_wc, wf_parameters=eos_wc_para, fleur=fleur, inpgen=inpgen, structure=structure, calc_parameters=calc_parameters, _label=label, _description=description) return ToContext(**eos_res)
def run_cp2k_charge_density(self): """Compute charge-density with CP2K""" #TODO Change to this when aiida 1.0.0 will be released # inputs = AttributeDict(self.exposed_inputs(PwBaseWorkChain, namespace='base')) # inputs.structure = self.input.structure # inputs = prepare_process_inputs(Cp2kDftBaseWorkChain, inputs) parameters = ParameterData( dict={ 'FORCE_EVAL': { 'DFT': { 'PRINT': { 'E_DENSITY_CUBE': { 'STRIDE': '1 1 1', } }, }, }, }) inputs = { 'code': self.inputs.cp2k_code, 'structure': self.inputs.structure, 'parameters': parameters, 'options': self.inputs.cp2k_options, '_guess_multiplisity': True, } running = submit(Cp2kDftBaseWorkChain, **inputs) self.report( "pk: {} | Running Cp2kDftBaseWorkChain to compute the charge-density" ) return ToContext(charge_density_calc=Outputs(running))
def run_stm(self): """ Run a STMCalculation with the relaxed_calculation parent folder """ self.report('Running stm calculation') # Get the remote folder of the last calculation in the previous workchain remote_folder = self.ctx.workchain_relax.get_outputs_dict( )['remote_folder'] stm_inputs = {} stm_inputs['code'] = self.ctx.inputs['stm_code'] stm_inputs['parent_folder'] = remote_folder # Height of image plane, in Ang stm_inputs['parameters'] = ParameterData( dict={'z': self.ctx.inputs['height']}) # Dummy dict settings_dict = {'a': 'b'} stm_inputs['settings'] = ParameterData(dict=settings_dict) # This should be just a dictionary! stm_inputs['_options'] = { 'resources': { 'num_machines': 1 }, 'max_wallclock_seconds': 600 } process = STMCalculation.process() running = submit(process, **stm_inputs) self.report('launching STMCalculation<{}>'.format(running.pid)) return ToContext(stm_calc=running)
def run_fleurinpgen(self): """ run the inpgen """ structure = self.inputs.structure self.ctx.formula = structure.get_formula() label = 'scf: inpgen' description = '{} inpgen on {}'.format(self.ctx.description_wf, self.ctx.formula) inpgencode = self.inputs.inpgen if 'calc_parameters' in self.inputs: params = self.inputs.calc_parameters else: params = None options = { "max_wallclock_seconds": self.ctx.walltime_sec, "resources": self.ctx.resources, "queue_name": self.ctx.queue } inputs = get_inputs_inpgen(structure, inpgencode, options, label, description, params=params) self.report('INFO: run inpgen') future = submit(FleurinpProcess, **inputs) return ToContext(inpgen=future, last_calc=future)
def setup(self): """ Launch the first calculation for the input structure, and a second calculation for a shifted volume (increased by 4 angstrom^3) Store the outputs of the two calcs in r0 and r1 """ print "Workchain node identifiers: {}".format(self.calc) inputs0 = generate_scf_input_params(self.inputs.structure, str(self.inputs.code), self.inputs.pseudo_family) initial_volume = self.inputs.structure.get_cell_volume() new_volume = initial_volume + 4. # In ang^3 scaled_structure = get_structure(self.inputs.structure, new_volume) inputs1 = generate_scf_input_params(scaled_structure, str(self.inputs.code), self.inputs.pseudo_family) self.ctx.last_structure = scaled_structure # Run PW future0 = submit(PwProcess, **inputs0) future1 = submit(PwProcess, **inputs1) # Wait to complete before next step return ToContext(r0=future0, r1=future1)
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 = submit(PwBandsWorkChain, **inputs) self.report('launching PwBandsWorkChain<{}>'.format(running.pid)) return ToContext(workchain_bands=running)
def run_first_gcmc(self): """This function will run RaspaConvergeWorkChain for the current pressure""" self.ctx.raspa_parameters_gcmc_0['GeneralSettings'][ 'ExternalPressure'] = self.ctx.pressure parameters = ParameterData( dict=self.ctx.raspa_parameters_gcmc_0).store() # Create the input dictionary inputs = { 'code': self.inputs.raspa_code, 'structure': self.ctx.structure, 'parameters': parameters, '_options': self.inputs._raspa_options, '_label': "run_first_loading_raspa", } # Check if there are pocket blocks to be loaded try: inputs['block_component_0'] = self.ctx.zeopp['block'] except Exception: pass if self.ctx.restart_raspa_calc is not None: inputs['retrieved_parent_folder'] = self.ctx.restart_raspa_calc # Create the calculation process and launch it running = submit(RaspaConvergeWorkChain, **inputs) self.ctx.current_run_counter += 1 self.report("pk: {} | Running RASPA for the {} time".format( running.pid, self.ctx.current_run_counter)) return ToContext(raspa_loading=Outputs(running))
def run_zeopp(self): """Main function that performs zeo++ VOLPO and block calculations.""" params = { 'ha': True, # 100 samples / Ang^3: accurate for all the structures 'block': [self.inputs.zeopp_probe_radius.value, 100], # 100k samples, may need more for structures bigger than 30x30x30 'volpo': [ self.inputs.zeopp_probe_radius.value, self.inputs.zeopp_probe_radius.value, 100000 ] } inputs = { 'code': self.inputs.zeopp_code, 'structure': self.inputs.structure, 'parameters': NetworkParameters(dict=params).store(), '_options': self.inputs._zeopp_options, '_label': "ZeoppVolpoBlock", } # Use default zeopp atomic radii only if a .rad file is not specified try: inputs['atomic_radii'] = self.inputs.zeopp_atomic_radii self.report("Zeopp will use atomic radii from the .rad file") except: self.report("Zeopp will use default atomic radii") # Create the calculation process and launch it running = submit(ZeoppCalculation.process(), **inputs) self.report( "pk: {} | Running zeo++ volpo and block calculations".format( running.pid)) return ToContext(zeopp=Outputs(running))
def run_relax_and_analyze(self): """ Run the SiestaBaseWorkChain to (relax) and analyze the input structure """ self.report('Running run_relax_and_analyze') inputs = dict(self.ctx.inputs) ldos_e = "\n {e1} {e2} eV".format(e1=self.inputs.e1, e2=self.inputs.e2) inputs['parameters']['%block local-density-of-states'] = ldos_e # Final input preparation, wrapping dictionaries in ParameterData nodes # The code and options were set above # Pseudos was set above in ctx.inputs, and so in inputs inputs['kpoints'] = self.ctx.kpoints_mesh inputs['basis'] = ParameterData(dict=inputs['basis']) inputs['structure'] = self.ctx.structure_initial_primitive inputs['parameters'] = ParameterData(dict=inputs['parameters']) inputs['settings'] = ParameterData(dict=inputs['settings']) inputs['clean_workdir'] = Bool(False) inputs['max_iterations'] = Int(20) running = submit(SiestaBaseWorkChain, **inputs) self.report( 'launched SiestaBaseWorkChain<{}> in relax+ldos mode'.format( running.pid)) return ToContext(workchain_relax=running)
def run_calculation(self): """Run cp2k calculation.""" # Create the calculation process and launch it process = Cp2kCalculation.process() running = submit(process, **self.ctx.inputs) self.report("pk: {} | Running DFT calculation with cp2k".format(running.pid)) self.ctx.nruns += 1 return ToContext(calculation=Outputs(running))
def run_ddec(self): """Compute ddec point charges from precomputed charge-density.""" # Create the calculation process and launch it running = submit(DdecCalculation.process(), **self.ctx.ddec_inputs) self.report( "pk: {} | Running ddec to compute point charges based on the charge-density" .format(running.pid)) return ToContext(ddec_calc=Outputs(running))
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 _submit_pw_calc(self, structure, label, runtype, precision, min_kpoints, wallhours=24, parent_folder=None): self.report("Running pw.x for " + label) inputs = {} inputs['_label'] = label inputs['code'] = self.inputs.pw_code inputs['structure'] = structure inputs['parameters'] = self._get_parameters(structure, runtype) inputs['pseudo'] = self._get_pseudos(structure, family_name="SSSP_modified") if parent_folder: inputs['parent_folder'] = parent_folder # kpoints cell_a = inputs['structure'].cell[0][0] precision *= self.inputs.precision.value nkpoints = max(min_kpoints, int(30 * 2.5 / cell_a * precision)) use_symmetry = runtype != "bands" kpoints = self._get_kpoints(nkpoints, use_symmetry=use_symmetry) inputs['kpoints'] = kpoints # parallelization settings ## TEMPORARY double pools in case of spin spinpools = 1 start_mag = self._get_magnetization(structure) if any([m != 0 for m in start_mag.values()]): spinpools = 2 npools = min(spinpools + nkpoints / 5, 5) natoms = len(structure.sites) nnodes = (1 + natoms / 60) * npools inputs['_options'] = { "resources": { "num_machines": nnodes }, "max_wallclock_seconds": wallhours * 60 * 60, # hours } settings = {'cmdline': ["-npools", str(npools)]} if runtype == "bands": settings['also_bands'] = True # instruction for output parser inputs['settings'] = ParameterData(dict=settings) # self.report("precision %f"%precision) # self.report("nkpoints %d"%nkpoints) # self.report("npools %d"%npools) # self.report("natoms %d"%natoms) # self.report("nnodes %d"%nnodes) future = submit(PwCalculation.process(), **inputs) return ToContext(**{label: Calc(future)})
def run_export_hartree(self): self.report("Running pp.x to export hartree potential") inputs = {} inputs['_label'] = "export_hartree" inputs['code'] = self.inputs.pp_code prev_calc = self.ctx.scf self._check_prev_calc(prev_calc) inputs['parent_folder'] = prev_calc.out.remote_folder structure = prev_calc.inp.structure cell_a = structure.cell[0][0] cell_b = structure.cell[1][1] cell_c = structure.cell[2][2] parameters = ParameterData(dict={ 'inputpp': { 'plot_num': 11, # the V_bare + V_H potential }, 'plot': { 'iflag': 2, # 2D plot # format suitable for gnuplot (2D) x, y, f(x,y) 'output_format': 7, # 3D vector, origin of the plane (in alat units) 'x0(1)': 0.0, 'x0(2)': 0.0, 'x0(3)': cell_c/cell_a, # 3D vectors which determine the plotting plane # in alat units) 'e1(1)': cell_a/cell_a, 'e1(2)': 0.0, 'e1(3)': 0.0, 'e2(1)': 0.0, 'e2(2)': cell_b/cell_a, 'e2(3)': 0.0, 'nx': 10, # Number of points in the plane 'ny': 10, 'fileout': 'vacuum_hartree.dat', }, }) inputs['parameters'] = parameters settings = ParameterData( dict={'additional_retrieve_list': ['vacuum_hartree.dat']} ) inputs['settings'] = settings inputs['_options'] = { "resources": {"num_machines": 1}, "max_wallclock_seconds": 20 * 60, # workaround for flaw in PpCalculator. # We don't want to retrive this huge intermediate file. "append_text": u"rm -v aiida.filplot\n", } future = submit(PpCalculation.process(), **inputs) return ToContext(hartree=Calc(future))
def do_submit(self): if self.should_submit(): self.report('Submitting nested workchain.') return ToContext( workchain=append_(self.submit( NestedWorkChain, inp=self.inputs.inp - 1 )) )
def contex_waits(self): """This function is in the spec.cls, and is used to resolve the `future` object and store it in a `self.ctx` variable after each iteration. This function will receive the future object stored in a ctx variable by functions that are not in the spec.cls and can not therefore resolve the `future` i.e. call `ToContext` on a `future`. These functions will store the subworkflow's future in the context and here will resolve it and wait for the result by calling ToContext, storing the result in a context variable, which is selected depending on which step the subworkflow represent. """ if self.ctx.last_step == 'step_0_1' or self.ctx.last_step == 'step_0_2': return ToContext(step0_res=self.ctx.step0_res_) elif self.ctx.last_step == 'step_1_1' or self.ctx.last_step == 'step_1_2': return ToContext(step1_res=self.ctx.step1_res_) elif self.ctx.last_step == 'step_2_1' or self.ctx.last_step == 'step_2_2': return ToContext(step2_res=self.ctx.step2_res_) elif self.ctx.last_step == 'step_3_1' or self.ctx.last_step == 'step_3_2': return ToContext(step3_res=self.ctx.step3_res_) return
def run_ape(self): self.ctx.scut=self.ctx.scales[self.ctx.si]*self.ctx.spick self.ctx.pcut=self.ctx.scales[self.ctx.pi]*self.ctx.ppick self.ctx.dcut=self.ctx.scut self.ctx.fcut=self.ctx.scut print "Run Ape with s cutoff = {0} and p cutoff = {1}".format(self.ctx.scut,self.ctx.pcut) inp=generate_ApeCalculation('apelocal',self.inputs.element,self.ctx.scut,self.ctx.pcut,self.ctx.dcut,self.ctx.fcut) futur = submit(ApeCalculation.process(), **inp) return ToContext(resul=futur)
def run_bands_calculation(self): """Run cp2k calculation.""" # Create the calculation process and launch it process = Cp2kCalculation.process() # cp2k plugin future = submit(process, **self.ctx.inputs) self.report("pk: {} | Running DFT calculation with" " cp2k".format(future.pid)) return ToContext(calculation=Outputs(future))
def fit(self): future = self.submit(FitterCalculation, code=self.inputs.fitter.code, structures=self.ctx.structures, forces=self.ctx.forces, energy=self.ctx.energy, parameters=self.inputs.fitter.parameters, force_field=self.inputs.fitter.force_field, options=self.inputs.fitter.options.get_dict()) return ToContext(run=future)
def run_relax(self): """Run the BaseVaspWf for the relaxation.""" self.ctx.inputs.structure = self.ctx.current_structure inputs = prepare_process_inputs(self.ctx.inputs) running = self.submit(VaspBaseWf, **inputs) self.ctx.iteration += 1 self.report('launching VaspBaseWf{}'.format(running)) return ToContext(workchains=append_(running))
def run_calculation(self): """Run raspa calculation.""" # Create the calculation process and launch it process = RaspaCalculation.process() future = submit(process, **self.ctx.inputs) self.report("pk: {} | Running calculation with" " RASPA".format(future.pid)) self.ctx.nruns += 1 return ToContext(calculation=Outputs(future))
def init(self): print "Workchain node identifiers: {}".format( ProcessRegistry().current_calc_node) print "Run Ape with guess radii, just to get nodes and picks" apein = generate_ApeCalculation('apelocal', self.inputs.element, 2, 2, 2, 2) self.ctx.Vo2, self.ctx.Bo2, self.ctx.Bp2 = get_reference( self.inputs.element) future = submit(ApeCalculation.process(), **apein) return ToContext(result=future)
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 create_displacement_calculations(self): print 'test2!', self.ctx structures = create_supercells_with_displacements_using_phonopy( self.inputs.structure, self.inputs.ph_settings) print 'test!' self.ctx.data_sets = structures.pop('data_sets') self.ctx.number_of_displacements = len(structures) generate_inputs = { 'quantumespresso.pw': generate_qe_params, 'vasp.vasp': generate_vasp_params } ############### FOR TESTING ############### # 1) Load data from nodes if False: #For test from aiida.orm import load_node nodes = [461200, 461205, 461210, 461215] # VASP labels = [ 'structure_1', 'structure_0', 'structure_3', 'structure_2' ] for pk, label in zip(nodes, labels): future = load_node(pk) self.ctx._content[label] = future return calcs = {} for label, structure in structures.iteritems(): print label, structure print self.inputs.es_settings.dict.code # plugin = self.inputs.code.get_attr('input_plugin') try: plugin = Code.get_from_string( self.inputs.es_settings.dict.code).get_attr('input_plugin') # plugin = self.inputs.es_settings.dict.code.get_attr('input_plugin') except: plugin = Code.get_from_string( self.inputs.es_settings.dict.code_forces).get_attr( 'input_plugin') # plugin = self.inputs.es_settings.dict.code_forces.get_attr('input_plugin') JobCalculation, calculation_input = generate_inputs[plugin]( structure, self.inputs.machine, self.inputs.es_settings) calculation_input._label = label future = submit(JobCalculation, **calculation_input) calcs[label] = future return ToContext(**calcs)
def run_relax(self): """Run the PwRelaxWorkChain to run a relax PwCalculation.""" inputs = AttributeDict( self.exposed_inputs(PwRelaxWorkChain, namespace='relax')) inputs.structure = self.ctx.current_structure running = self.submit(PwRelaxWorkChain, **inputs) self.report('launching PwRelaxWorkChain<{}>'.format(running.pk)) return ToContext(workchain_relax=running)
def run_geopt_again(self): # TODO: make this nicer. inputs_new = self.build_calc_inputs(self.inputs.structure, self.inputs.cp2k_code, self.inputs.fixed_atoms, self.inputs.num_machines, '', self.ctx.geo_opt.out.remote_folder) self.report("inputs (restart): " + str(inputs_new)) future_new = submit(Cp2kCalculation.process(), **inputs_new) return ToContext(geo_opt=Calc(future_new))
def run_geopt(self): self.report("Running CP2K geometry optimization") inputs = self.build_calc_inputs(self.inputs.structure, self.inputs.cp2k_code, self.inputs.fixed_atoms, self.inputs.num_machines, self.inputs.wavefunction, None) self.report("inputs: " + str(inputs)) future = submit(Cp2kCalculation.process(), **inputs) return ToContext(geo_opt=Calc(future))
def run_fleur(self): ''' run a fleur calculation ''' FleurProcess = FleurCalculation.process() inputs = {} inputs = self.get_inputs_fleur() #print inputs future = submit(FleurProcess, **inputs) print 'run Fleur in band workflow' return ToContext(last_calc=future)
def run_pw(self): scale = self.ctx.scales[self.ctx.i] scaled = rescale(self.inputs.structure, scale) inputs = generate_scf_input_params(scaled, self.inputs.code, self.inputs.pseudo_family) # Launch the code pid = self.submit(PwProcess, inputs).pid self.ctx.i += 1 return ToContext(result=pid)
def run_export_orbitals(self): self.report("Running pp.x to export KS orbitals") inputs = {} inputs['_label'] = "export_orbitals" inputs['code'] = self.inputs.pp_code prev_calc = self.ctx.bands_lowres self._check_prev_calc(prev_calc) inputs['parent_folder'] = prev_calc.out.remote_folder nel = prev_calc.res.number_of_electrons nkpt = prev_calc.res.number_of_k_points nbnd = prev_calc.res.number_of_bands nspin = prev_calc.res.number_of_spin_components volume = prev_calc.res.volume kband1 = max(int(nel/2) - 6, 1) kband2 = min(int(nel/2) + 7, nbnd) kpoint1 = 1 kpoint2 = nkpt * nspin nhours = 2 + min(22, 2*int(volume/1500)) parameters = ParameterData(dict={ 'inputpp': { # contribution of a selected wavefunction # to charge density 'plot_num': 7, 'kpoint(1)': kpoint1, 'kpoint(2)': kpoint2, 'kband(1)': kband1, 'kband(2)': kband2, }, 'plot': { 'iflag': 3, # 3D plot 'output_format': 6, # CUBE format 'fileout': '_orbital.cube', }, }) inputs['parameters'] = parameters inputs['_options'] = { "resources": {"num_machines": 1}, "max_wallclock_seconds": nhours * 60 * 60, # 6 hours "append_text": self._get_cube_cutter(), } settings = ParameterData( dict={'additional_retrieve_list': ['*.cube.gz']} ) inputs['settings'] = settings future = submit(PpCalculation.process(), **inputs) return ToContext(orbitals=Calc(future))