def run_cp2k_charge_density(self): """ Compute the charge-density of a structure that can be later used for extracting ddec point charges. """ options = { "resources": { "num_machines": 4, "num_mpiprocs_per_machine": 12, }, "max_wallclock_seconds": 3 * 60 * 60, } inputs = { 'code' : Code.get_from_string(self.inputs.cp2k_codename.value), 'structure' : from_cif_to_structuredata(self.ctx.processed_structure), 'parameters' : self.inputs.cp2k_parameters, '_options' : options, '_label' : "run_chargedensity_cp2k", } # Create the calculation process and launch it process = Cp2kCalculation.process() future = submit(process, **inputs) self.report("pk: {} | Running cp2k to compute the charge-density") self.ctx.cp2k_pid=future.pid return ToContext(cp2k=Outputs(future))
def generate_scf_input_params(structure, codename, pseudo_family): # The inputs inputs = PwCalculation.process().get_inputs_template() # The structure inputs.structure = structure inputs.code = Code.get_from_string(codename.value) inputs._options.resources = {"num_machines": 1} inputs._options.max_wallclock_seconds = 30 * 60 # Kpoints KpointsData = DataFactory("array.kpoints") kpoints = KpointsData() kpoints_mesh = 2 kpoints.set_kpoints_mesh([kpoints_mesh, kpoints_mesh, kpoints_mesh]) inputs.kpoints = kpoints # Calculation parameters parameters_dict = { "CONTROL": {"calculation": "scf", "tstress": True, # Important that this stays to get stress "tprnfor": True,}, "SYSTEM": {"ecutwfc": 30., "ecutrho": 200.,}, "ELECTRONS": {"conv_thr": 1.e-6,} } ParameterData = DataFactory("parameter") inputs.parameters = ParameterData(dict=parameters_dict) # Pseudopotentials inputs.pseudo = get_pseudos(structure, str(pseudo_family)) return inputs
def run_block_zeopp(self): """ This is the main function that will perform a raspa calculation for the current pressure """ NetworkParameters = DataFactory('zeopp.parameters') # Create the input dictionary sigma = self.inputs.probe_molecule.get_dict()['sigma'] params = { 'ha':True, 'block': [sigma, 200], } inputs = { 'code' : Code.get_from_string(self.inputs.zeopp_codename.value), 'structure' : self.ctx.processed_structure, 'parameters' : NetworkParameters(dict=params), '_options' : self.inputs._options, '_label' : "run_block_zeopp", } # Create the calculation process and launch it process = ZeoppCalculation.process() future = submit(process, **inputs) self.report("pk: {} | Running zeo++ block volume calculation".format(future.pid)) self.ctx.block_pk = future.pid return ToContext(zeopp=Outputs(future))
def run_loading_raspa(self): """ This is the main function that will perform a raspa calculation for the current pressure """ pressure = self.ctx.pressures[self.ctx.p] self.ctx.raspa_parameters['GeneralSettings']['ExternalPressure'] = pressure if self.ctx.prev_pk is not None: self.ctx.raspa_parameters['GeneralSettings']['RestartFile'] = True self.ctx.raspa_parameters['GeneralSettings']['RestartFilePk'] = self.ctx.prev_pk # Create the input dictionary inputs = { 'code' : Code.get_from_string(self.inputs.raspa_codename.value), 'structure' : self.ctx.processed_structure, 'parameters' : ParameterData(dict=self.ctx.raspa_parameters), '_options' : self.inputs._options, '_label' : "run_loading_raspa", } # Create the calculation process and launch it process = RaspaCalculation.process() future = submit(process, **inputs) self.report("pk: {} | Running raspa for the pressure {} [bar]".format(future.pid, pressure/1e5)) self.ctx.p += 1 self.ctx.prev_pk = future.pid return ToContext(raspa=Outputs(future))
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_henry_raspa(self): """ This is the main function that will perform a raspa calculation for the current pressure """ raspa_parameters = self.inputs.raspa_parameters.get_dict() raspa_parameters['GeneralSettings'].pop('ExternalPressure') for i, comp in enumerate(raspa_parameters['Component']): name = comp['MoleculeName'] raspa_parameters['Component'][0] = { "MoleculeName" : name, "MoleculeDefinition" : "TraPPE", "WidomProbability" : 1.0, "CreateNumberOfMolecules" : 0, } # Create the input dictionary inputs = { 'code' : Code.get_from_string(self.inputs.raspa_codename.value), 'structure' : self.ctx.processed_structure, 'parameters' : ParameterData(dict=raspa_parameters), '_options' : self.inputs._options, '_label' : "run_henry_raspa", } # Create the calculation process and launch it process = RaspaCalculation.process() future = submit(process, **inputs) self.report("pk: {} | Running raspa for the Henry coefficients".format(future.pid)) return
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 main(): DifferenceCalculation = CalculationFactory('wait.wait') builder = DifferenceCalculation.get_builder() builder.code = Code.get_from_string('wait') builder.options = {'resources': {'num_machines': 1}, 'withmpi': False} node = submit(builder) print(node.pk)
def generate_scf_input_params(structure, codename, pseudo, element): # The inputs inputs = PwCalculation.process().get_inputs_template() # The structure inputs.structure = structure inputs.code = Code.get_from_string(codename) # calc.label = "PW test" # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO" inputs._options.resources = {"num_machines": 1} inputs._options.max_wallclock_seconds = 23*30*60 queue="compute" if queue is not None: inputs._options.queue_name=queue # Kpoints KpointsData = DataFactory("array.kpoints") kpoints = KpointsData() # kpoints_mesh = 2 kp=[0,0,0] f=open('/home/bosonie/AIMS/LDARESULTS/NonRelBirchLDAref', 'r') for line in f: a=line.split() if a[0]==element: kp[0]=int(a[1]) kp[1]=int(a[3]) kp[2]=int(a[5]) vol=a[7] kpoints.set_kpoints_mesh([1,1,1])#[kp[0], kp[1], kp[2]]) inputs.kpoints = kpoints # Calculation parameters parameters_dict = { "CONTROL": {"calculation": "scf", "tstress": True, # Important that this stays to get stress "tprnfor": True, "disk_io": "none"}, "SYSTEM": {"ecutwfc": 100., "ecutrho": 200., "smearing": "gauss", "degauss": 0.000734986}, "ELECTRONS": {"conv_thr": 1.e-6} } ParameterData = DataFactory("parameter") inputs.parameters = ParameterData(dict=parameters_dict) pseudos = {} pseudos[element] = pseudo inputs.pseudo = pseudos return inputs
def run_si_scf(codename, pseudo_family): JobCalc = PwCalculation.process() inputs = JobCalc.get_inputs_template() inputs.code = Code.get_from_string(codename) # calc.label = "PW test" # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO" inputs._options.resources = {"num_machines": 1} inputs._options.max_wallclock_seconds = 30 * 60 # The structure alat = 5.4 the_cell = [[alat / 2., alat / 2., 0], [alat / 2., 0, alat / 2.], [0, alat / 2., alat / 2.]] StructureData = DataFactory("structure") structure = StructureData(cell=the_cell) structure.append_atom(position=(0., 0., 0.), symbols="Si") structure.append_atom(position=(alat / 4., alat / 4., alat / 4.), symbols="Si") inputs.structure = structure # Kpoints KpointsData = DataFactory("array.kpoints") kpoints = KpointsData() kpoints_mesh = 2 kpoints.set_kpoints_mesh([kpoints_mesh, kpoints_mesh, kpoints_mesh]) inputs.kpoints = kpoints # Calculation parameters parameters_dict = { "CONTROL": { "calculation": "scf", "tstress": True, "tprnfor": True, }, "SYSTEM": { "ecutwfc": 30., "ecutrho": 200., }, "ELECTRONS": { "conv_thr": 1.e-6, } } ParameterData = DataFactory("parameter") inputs.parameters = ParameterData(dict=parameters_dict) # Pseudopotentials inputs.pseudo = get_pseudos(structure, pseudo_family) # calc.set_extra("element", "Si") # calc.submit() asyncd(JobCalc, **inputs)
def generate_pw_input_params(structure, codename, pseudo_family,parameters, calculation_set, kpoints,gamma,settings,parent_folder): """Generate PW input._* from given params """ inputs = {} inputs['structure'] = structure inputs['code'] = Code.get_from_string(codename.value) calculation_set = calculation_set.get_dict() inputs['options'] = ParameterData(dict=calculation_set) if parent_folder: inputs['parent_folder'] = parent_folder inputs['kpoints']=kpoints inputs['parameters'] = parameters inputs['pseudo_family'] = pseudo_family inputs['settings'] = settings return inputs
def generate_ApeCalculation(codename, element, s, p, d, f): inp = ApeCalculation.process().get_inputs_template() inp.code = Code.get_from_string(codename) inp._options.computer = Computer.get('localhost') inp._options.resources = {"num_machines": 1} check = False for ele in ELEMENTS: if element == ele.symbol: nc = int(ele.number) check = True print check, nc if not check: sys.exit("element is not valid") corpar = 1 if nc <= 2: corpar = 0 parameters = ParameterData( dict={ 'Title': '{}'.format(element), 'CalculationMode': 'ae + pp', 'Verbose': '40', 'WaveEquation': 'schrodinger', 'XCFunctional': 'lda_x + lda_c_pz', 'NuclearCharge': '{}'.format(nc), 'PPCalculationTolerance': '1.e-6', 'PPOutputFileFormat': 'upf + siesta', 'CoreCorrection': '{}'.format(corpar), 'EigenSolverTolerance': '1.e-8', 'ODEIntTolerance': '1.e-12' }) orbitals, PPComponents = get_orb_and_PPcomp(nc, s, p, d, f) inp.parameters = parameters inp.orbitals = orbitals inp.PPComponents = PPComponents inp._label = "{0} {1} {2} {3}".format(s, p, d, f) inp._description = "{} pseudo generation with cut of radii in label".format( element) return inp
def generate_scf_input_params(structure, codename, pseudo_family): # The inputs inputs = PwCalculation.get_builder() # The structure inputs.structure = structure inputs.code = Code.get_from_string(codename) # calc.label = "PW test" # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO" inputs.options.resources = {"num_machines": 1} inputs.options.max_wallclock_seconds = 30 * 60 # Kpoints KpointsData = DataFactory("array.kpoints") kpoints = KpointsData() kpoints_mesh = 2 kpoints.set_kpoints_mesh([kpoints_mesh, kpoints_mesh, kpoints_mesh]) inputs.kpoints = kpoints # Calculation parameters parameters_dict = { "CONTROL": { "calculation": "scf", "tstress": True, # Important that this stays to get stress "tprnfor": True, }, "SYSTEM": { "ecutwfc": 30., "ecutrho": 200., }, "ELECTRONS": { "conv_thr": 1.e-6, } } ParameterData = DataFactory("parameter") inputs.parameters = ParameterData(dict=parameters_dict) # Pseudopotentials inputs.pseudo = validate_and_prepare_pseudos_inputs( structure, pseudo_family=pseudo_family) return inputs
def code_rename(self, *args): import argparse from aiida.common.exceptions import NotExistent from aiida.orm.code import Code parser = argparse.ArgumentParser( prog=self.get_full_command_name(), description='Rename a code (change its label).') # The default states are those that are shown if no option is given parser.add_argument('old_name', help="The old name of the code") parser.add_argument('new_name', help="The new name of the code") parsed_args = parser.parse_args(args) new_name = parsed_args.new_name old_name = parsed_args.old_name try: code = Code.get_from_string(old_name) except NotExistent: print "ERROR! A code with name {} could not be found".format( old_name) sys.exit(1) suffix = '@{}'.format(code.get_computer().name) if new_name.endswith(suffix): new_name = new_name[:-len(suffix)] if '@' in new_name: print >> sys.stderr, "ERROR! Do not put '@' symbols in the code name" sys.exit(1) retrieved_old_name = '{}@{}'.format(code.label, code.get_computer().name) # CHANGE HERE code.label = new_name retrieved_new_name = '{}@{}'.format(code.label, code.get_computer().name) print "Renamed code with ID={} from '{}' to '{}'".format( code.pk, retrieved_old_name, retrieved_new_name)
def run_ddec_point_charges(self): """ Compute ddec point charges from precomputed charge-density. """ cp2k_calc = load_node(self.ctx.cp2k_pid) options = self.inputs._options #options['prepend_text'] = "export OMP_NUM_THREADS=12" inputs = { 'code' : Code.get_from_string(self.inputs.ddec_codename.value), 'parameters' : self.inputs.ddec_parameters, 'electronic_calc_folder' : cp2k_calc.out.remote_folder, '_options' : options, '_label' : "run_pointcharges_ddec", } # Create the calculation process and launch it process = DdecCalculation.process() future = submit(process, **inputs) self.report("pk: {} | Running ddec to compute point charges based on the charge-density") self.ctx.ddec_pid=future.pid return ToContext(ddec=Outputs(future))
def get_pw_calculation(wf_params, only_initialization=False, parent_calc=None, parent_remote_folder=None): """ Returns a stored calculation """ # default max number of seconds for a calculation with only_initialization=True # (should be largely sufficient) default_max_seconds_only_init = 1800 from aiida.orm.code import Code calculation = wf_params['input']['relaxation_scheme'] if only_initialization: wf_params['calculation_set'] = update_nested_dict( wf_params.get('calculation_set',{}), {'max_wallclock_seconds': default_max_seconds_only_init, 'resources': {'num_machines': 1}}) if parent_calc is None: code = Code.get_from_string(wf_params["codename"]) calc = code.new_calc() calc.use_structure(wf_params["structure"]) calc.use_pseudos_from_family(wf_params["pseudo_family"]) if parent_remote_folder is None: pw_parameters = get_pwparameterdata_from_wfparams(wf_params, calculation=calculation) else: # restart from a remote folder (typically, with charge density) pw_parameters = get_pwparameterdata_from_wfparams(wf_params, restart_mode='restart', calculation=calculation) calc._set_parent_remotedata(parent_remote_folder) else: if calculation in ['bands']: calc = parent_calc.create_restart(force_restart=True,use_output_structure=True) else: calc = parent_calc.create_restart(force_restart=True) pw_parameters = get_pwparameterdata_from_wfparams(wf_params, restart_mode='restart', calculation=calculation) if 'vdw_table' in wf_params: calc.use_vdw_table(wf_params['vdw_table']) calc.use_parameters(pw_parameters) calc.use_kpoints(wf_params['kpoints']) calc = set_the_set(calc,wf_params.get('calculation_set',{})) # set the settings if present try: settings_dict = wf_params['settings'] except KeyError: try: settings_dict = parent_calc.inp.settings.get_dict() if calc.inp.parameters.get_dict()['CONTROL']['calculation'] == 'bands': # for bands calculation we take out the npools specification # from the parent settings as the number of kpoints will # be different cmdline = settings_dict.get('cmdline',[]) the_cmdline = take_out_npools_from_cmdline(cmdline) if the_cmdline: settings_dict['cmdline'] = the_cmdline except AttributeError: settings_dict = {} if calc.inp.parameters.get_dict()['CONTROL']['calculation'] == 'bands': settings_dict['also_bands'] = True if only_initialization: settings_dict['ONLY_INITIALIZATION'] = only_initialization _ = settings_dict.pop('also_bands',None) if settings_dict: settings = ParameterData(dict=settings_dict) calc.use_settings(settings) calc.store_all() return calc
def deposit(what, type, author_name=None, author_email=None, url=None, title=None, username=None, password=False, user_email=None, code_label=default_options['code'], computer_name=None, replace=None, message=None, **kwargs): """ Launches a :py:class:`aiida.orm.implementation.general.calculation.job.AbstractJobCalculation` to deposit data node to \*COD-type database. :return: launched :py:class:`aiida.orm.implementation.general.calculation.job.AbstractJobCalculation` instance. :raises ValueError: if any of the required parameters are not given. """ from aiida.common.setup import get_property parameters = {} if not what: raise ValueError("Node to be deposited is not supplied") if not type: raise ValueError("Deposition type is not supplied. Should be " "one of the following: 'published', " "'prepublication' or 'personal'") if not username: username = get_property('tcod.depositor_username') if not username: raise ValueError("Depositor username is not supplied") if not password: parameters['password'] = get_property('tcod.depositor_password') if not parameters['password']: raise ValueError("Depositor password is not supplied") if not user_email: user_email = get_property('tcod.depositor_email') if not user_email: raise ValueError("Depositor email is not supplied") parameters['deposition-type'] = type parameters['username'] = username parameters['user_email'] = user_email if type == 'published': pass elif type in ['prepublication', 'personal']: if not author_name: author_name = get_property('tcod.depositor_author_name') if not author_name: raise ValueError("Author name is not supplied") if not author_email: author_email = get_property('tcod.depositor_author_email') if not author_email: raise ValueError("Author email is not supplied") if not title: raise ValueError("Publication title is not supplied") else: raise ValueError("Unknown deposition type '{}' -- should be " "one of the following: 'published', " "'prepublication' or 'personal'".format(type)) if replace: if str(int(replace)) != replace or int(replace) < 10000000 \ or int(replace) > 99999999: raise ValueError("ID of the replaced structure ({}) does not " "seem to be valid TCOD ID: must be in " "range [10000000,99999999]".format(replace)) elif message: raise ValueError("Message is given while the structure is not " "redeposited -- log message is relevant to " "redeposition only") kwargs['additional_tags'] = {} if title: kwargs['additional_tags']['_publ_section_title'] = title if author_name: kwargs['additional_tags']['_publ_author_name'] = author_name if replace: kwargs['additional_tags']['_tcod_database_code'] = replace kwargs['datablock_names'] = [replace] cif = export_cifnode(what, store=True, **kwargs) from aiida.orm.code import Code from aiida.orm.computer import Computer from aiida.orm.data.parameter import ParameterData from aiida.common.exceptions import NotExistent code = Code.get_from_string(code_label) computer = None if computer_name: computer = Computer.get(computer_name) calc = code.new_calc(computer=computer) calc.set_resources({'num_machines': 1, 'num_mpiprocs_per_machine': 1}) if password: import getpass parameters['password'] = getpass.getpass("Password: ") if author_name: parameters['author_name'] = author_name if author_email: parameters['author_email'] = author_email if url: parameters['url'] = url if replace: parameters['replace'] = True if message: parameters['log-message'] = str(message) pd = ParameterData(dict=parameters) calc.use_cif(cif) calc.use_parameters(pd) calc.store_all() calc.submit() return calc
def siesta_develop(): sd = {} from aiida.orm.code import Code sd["code"] = Code.get_from_string('siesta@develop') return sd
def inner(inputs, code_string): from aiida.orm.code import Code inputs.code = Code.get_from_string(code_string)
def generate_yambo_input_params(precodename, yambocodename, parent_folder, parameters, calculation_set, settings): inputs = YamboCalculation.process().get_inputs_template() inputs.preprocessing_code = Code.get_from_string(precodename.value) inputs.code = Code.get_from_string(yambocodename.value) calculation_set = calculation_set.get_dict() resource = calculation_set.pop('resources', {}) if resource: inputs._options.resources = resource inputs._options.max_wallclock_seconds = calculation_set.pop( 'max_wallclock_seconds', 86400) max_memory_kb = calculation_set.pop('max_memory_kb', None) if max_memory_kb: inputs._options.max_memory_kb = max_memory_kb queue_name = calculation_set.pop('queue_name', None) if queue_name: inputs._options.queue_name = queue_name custom_scheduler_commands = calculation_set.pop( 'custom_scheduler_commands', None) if custom_scheduler_commands: inputs._options.custom_scheduler_commands = custom_scheduler_commands environment_variables = calculation_set.pop("environment_variables", None) if environment_variables: inputs._options.environment_variables = environment_variables label = calculation_set.pop('label', None) if label: inputs._label = label inputs.parent_folder = parent_folder inputs.settings = settings # Get defaults: edit_parameters = parameters.get_dict() try: calc = parent_folder.get_inputs_dict(link_type=LinkType.CREATE)['remote_folder'].inp.parent_calc_folder.get_inputs_dict()\ ['remote_folder'].inp.parent_calc_folder.get_inputs_dict()['remote_folder'] except AttributeError: calc = None is_pw = False if isinstance(calc, PwCalculation): is_pw = True nelec = calc.out.output_parameters.get_dict()['number_of_electrons'] nocc = None if calc.out.output_parameters.get_dict()['lsda']== True or\ calc.out.output_parameters.get_dict()['non_colinear_calculation'] == True: nocc = nelec / 2 else: nocc = nelec / 2 bndsrnxp = gbndrnge = nocc ngsblxpp = int(calc.out.output_parameters.get_dict()['wfc_cutoff'] * 0.073498645 / 4 * 0.25) # ev to ry then 1/4 #ngsblxpp = 2 nkpts = calc.out.output_parameters.get_dict()['number_of_k_points'] if not resource: resource = { "num_mpiprocs_per_machine": 8, "num_machines": 1 } # safe trivial defaults tot_mpi = resource[u'num_mpiprocs_per_machine'] * resource[ u'num_machines'] if 'FFTGvecs' not in edit_parameters.keys(): edit_parameters['FFTGvecs'] = 2 edit_parameters['FFTGvecs_units'] = 'Ry' if 'BndsRnXp' not in edit_parameters.keys(): edit_parameters['BndsRnXp'] = (bndsrnxp / 2, bndsrnxp / 2 + 1) if 'GbndRnge' not in edit_parameters.keys(): edit_parameters['GbndRnge'] = (1.0, gbndrnge / 2) if 'NGsBlkXp' not in edit_parameters.keys(): edit_parameters['NGsBlkXp'] = ngsblxpp edit_parameters['NGsBlkXp_units'] = 'RL' if 'QPkrange' not in edit_parameters.keys(): edit_parameters['QPkrange'] = [(1, 1, int(nocc), int(nocc) + 1) ] # To revisit if 'SE_CPU' not in edit_parameters.keys(): b, qp = split_incom(tot_mpi) edit_parameters['SE_CPU'] = "1 {qp} {b}".format(qp=qp, b=b) edit_parameters['SE_ROLEs'] = "q qp b" if 'X_all_q_CPU' not in edit_parameters.keys(): c, v = split_incom(tot_mpi) edit_parameters['X_all_q_CPU'] = "1 1 {c} {v}".format(c=c, v=v) edit_parameters['X_all_q_ROLEs'] = "q k c v" inputs.parameters = ParameterData(dict=edit_parameters) return inputs
def inner(builder, code_string): from aiida.orm.code import Code builder.code = Code.get_from_string(code_string)