def validate_pseudos(self): """Validate the inputs related to pseudopotentials. Either the pseudo potentials should be defined explicitly in the `pseudos` namespace, or alternatively, a family can be defined in `pseudo_family` that will be used together with the input `StructureData` to generate the required mapping. """ structure = self.ctx.inputs.structure pseudos = self.ctx.inputs.get('pseudos', None) pseudo_family = self.inputs.get('pseudo_family', None) try: self.ctx.inputs.pseudos = validate_and_prepare_pseudos_inputs(structure, pseudos, pseudo_family) except ValueError as exception: self.report('{}'.format(exception)) return self.exit_codes.ERROR_INVALID_INPUT_PSEUDO_POTENTIALS
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 generate_scf_input_params(structure, code, pseudo_family): """Construct a builder for the `PwCalculation` class and populate its inputs. :return: `ProcessBuilder` instance for `PwCalculation` with preset inputs """ parameters = { '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, } } kpoints = KpointsData() kpoints.set_kpoints_mesh([2, 2, 2]) builder = PwCalculation.get_builder() builder.code = code builder.structure = structure builder.kpoints = kpoints builder.parameters = Dict(dict=parameters) builder.pseudos = validate_and_prepare_pseudos_inputs( structure, pseudo_family=pseudo_family) builder.metadata.label = "PW test" builder.metadata.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO" builder.metadata.options.resources = {'num_machines': 1} builder.metadata.options.max_wallclock_seconds = 30 * 60 return builder
def validate_inputs(self): """ Validate inputs that depend might depend on each other and cannot be validated by the spec. Also define dictionary `inputs` in the context, that will contain the inputs for the calculation that will be launched in the `run_calculation` step. """ self.ctx.inputs = AttributeDict({ 'code': self.inputs.code, 'structure': self.inputs.structure, 'kpoints': self.inputs.kpoints, 'parameters': self.inputs.parameters.get_dict() }) if 'CONTROL'not in self.ctx.inputs.parameters: self.ctx.inputs.parameters['CONTROL'] = {} if 'calculation' not in self.ctx.inputs.parameters['CONTROL']: self.ctx.inputs.parameters['CONTROL']['calculation'] = 'scf' if 'parent_folder' in self.inputs: self.ctx.inputs.parent_folder = self.inputs.parent_folder self.ctx.inputs.parameters['CONTROL']['restart_mode'] = 'restart' else: self.ctx.inputs.parent_folder = None self.ctx.inputs.parameters['CONTROL']['restart_mode'] = 'from_scratch' if 'settings' in self.inputs: self.ctx.inputs.settings = self.inputs.settings.get_dict() else: self.ctx.inputs.settings = {} if 'options' in self.inputs: self.ctx.inputs._options = self.inputs.options.get_dict() else: self.ctx.inputs._options = {} if 'vdw_table' in self.inputs: self.ctx.inputs.vdw_table = self.inputs.vdw_table # Either automatic_parallelization or options has to be specified if not any([key in self.inputs for key in ['options', 'automatic_parallelization']]): self.abort_nowait('you have to specify either the options or automatic_parallelization input') return # If automatic parallelization is not enabled, we better make sure that the options satisfy minimum requirements if 'automatic_parallelization' not in self.inputs: num_machines = self.ctx.inputs['_options'].get('resources', {}).get('num_machines', None) max_wallclock_seconds = self.ctx.inputs['_options'].get('max_wallclock_seconds', None) if num_machines is None or max_wallclock_seconds is None: self.abort_nowait("no automatic_parallelization requested, but the options do not specify both '{}' and '{}'" .format('num_machines', 'max_wallclock_seconds')) # Validate the inputs related to pseudopotentials structure = self.inputs.structure pseudos = self.inputs.get('pseudos', None) pseudo_family = self.inputs.get('pseudo_family', None) try: self.ctx.inputs.pseudo = validate_and_prepare_pseudos_inputs(structure, pseudos, pseudo_family) except ValueError as exception: self.abort_nowait('{}'.format(exception))
def validate_inputs(self): """ Validate inputs that depend might depend on each other and cannot be validated by the spec. Also define dictionary `inputs` in the context, that will contain the inputs for the calculation that will be launched in the `run_calculation` step. """ self.ctx.inputs = AttributeDict({ 'code': self.inputs.code, 'structure': self.inputs.structure, 'parameters': self.inputs.parameters.get_dict() }) if 'CONTROL' not in self.ctx.inputs.parameters: self.ctx.inputs.parameters['CONTROL'] = {} if 'calculation' not in self.ctx.inputs.parameters['CONTROL']: self.ctx.inputs.parameters['CONTROL']['calculation'] = 'scf' if 'parent_folder' in self.inputs: self.ctx.inputs.parent_folder = self.inputs.parent_folder self.ctx.inputs.parameters['CONTROL']['restart_mode'] = 'restart' else: self.ctx.inputs.parameters['CONTROL'][ 'restart_mode'] = 'from_scratch' if 'settings' in self.inputs: self.ctx.inputs.settings = self.inputs.settings.get_dict() else: self.ctx.inputs.settings = {} if 'options' in self.inputs: self.ctx.inputs.options = self.inputs.options.get_dict() else: self.ctx.inputs.options = {} if 'vdw_table' in self.inputs: self.ctx.inputs.vdw_table = self.inputs.vdw_table # Either automatic_parallelization or options has to be specified if not any([ key in self.inputs for key in ['options', 'automatic_parallelization'] ]): return self.exit_codes.ERROR_INVALID_INPUT_RESOURCES # If automatic parallelization is not enabled, we better make sure that the options satisfy minimum requirements if 'automatic_parallelization' not in self.inputs: num_machines = self.ctx.inputs.options.get('resources', {}).get( 'num_machines', None) max_wallclock_seconds = self.ctx.inputs.options.get( 'max_wallclock_seconds', None) if num_machines is None or max_wallclock_seconds is None: return self.exit_codes.ERROR_INVALID_INPUT_RESOURCES_UNDERSPECIFIED # Either a KpointsData with given mesh/path, or a desired distance between k-points should be specified if all([ key not in self.inputs for key in ['kpoints', 'kpoints_distance'] ]): return self.exit_codes.ERROR_INVALID_INPUT_KPOINTS try: self.ctx.inputs.kpoints = self.inputs.kpoints except AttributeError: structure = self.inputs.structure distance = self.inputs.kpoints_distance force_parity = self.inputs.get('kpoints_force_parity', Bool(False)) self.ctx.inputs.kpoints = create_kpoints_from_distance( structure, distance, force_parity) # Validate the inputs related to pseudopotentials structure = self.inputs.structure pseudos = self.inputs.get('pseudos', None) pseudo_family = self.inputs.get('pseudo_family', None) try: self.ctx.inputs.pseudo = validate_and_prepare_pseudos_inputs( structure, pseudos, pseudo_family) except ValueError as exception: self.report('{}'.format(exception)) return self.exit_codes.ERROR_INVALID_INPUT_PSEUDO_POTENTIALS
def main(options): ###### setting the lattice structure ###### alat = 2.4955987320 # Angstrom the_cell = [[1.000000 * alat, 0.000000, 0.000000], [-0.500000 * alat, 0.866025 * alat, 0.000000], [0.000000, 0.000000, 6.4436359260]] atoms = Atoms('BNNB', [(1.2477994910, 0.7204172280, 0.0000000000), (-0.0000001250, 1.4408346720, 0.0000000000), (1.2477994910, 0.7204172280, 3.2218179630), (-0.0000001250, 1.4408346720, 3.2218179630)], cell=[1, 1, 1]) atoms.set_cell(the_cell, scale_atoms=False) atoms.set_pbc([True, True, True]) StructureData = DataFactory('structure') structure = StructureData(ase=atoms) ###### setting the kpoints mesh ###### KpointsData = DataFactory('array.kpoints') kpoints = KpointsData() kpoints.set_kpoints_mesh([6, 6, 2]) ###### setting the scf parameters ###### Dict = DataFactory('dict') params_scf = { 'CONTROL': { 'calculation': 'scf', 'verbosity': 'high', 'wf_collect': True }, 'SYSTEM': { 'ecutwfc': 130., 'force_symmorphic': True, 'nbnd': 20 }, 'ELECTRONS': { 'mixing_mode': 'plain', 'mixing_beta': 0.7, 'conv_thr': 1.e-8, 'diago_thr_init': 5.0e-6, 'diago_full_acc': True }, } parameter_scf = Dict(dict=params_scf) params_nscf = { 'CONTROL': { 'calculation': 'nscf', 'verbosity': 'high', 'wf_collect': True }, 'SYSTEM': { 'ecutwfc': 130., 'force_symmorphic': True, 'nbnd': 500 }, 'ELECTRONS': { 'mixing_mode': 'plain', 'mixing_beta': 0.6, 'conv_thr': 1.e-8, 'diagonalization': 'david', 'diago_thr_init': 5.0e-6, 'diago_full_acc': True }, } parameter_nscf = Dict(dict=params_nscf) KpointsData = DataFactory('array.kpoints') kpoints = KpointsData() kpoints.set_kpoints_mesh([6, 6, 2]) alat = 2.4955987320 # Angstrom the_cell = [[1.000000 * alat, 0.000000, 0.000000], [-0.500000 * alat, 0.866025 * alat, 0.000000], [0.000000, 0.000000, 6.4436359260]] atoms = Atoms('BNNB', [(1.2477994910, 0.7204172280, 0.0000000000), (-0.0000001250, 1.4408346720, 0.0000000000), (1.2477994910, 0.7204172280, 3.2218179630), (-0.0000001250, 1.4408346720, 3.2218179630)], cell=[1, 1, 1]) atoms.set_cell(the_cell, scale_atoms=False) atoms.set_pbc([True, True, True]) StructureData = DataFactory('structure') structure = StructureData(ase=atoms) params_gw = { 'HF_and_locXC': True, 'dipoles': True, 'ppa': True, 'gw0': True, 'em1d': True, 'Chimod': 'hartree', #'EXXRLvcs': 40, #'EXXRLvcs_units': 'Ry', 'BndsRnXp': [1, 10], 'NGsBlkXp': 2, 'NGsBlkXp_units': 'Ry', 'GbndRnge': [1, 10], 'DysSolver': "n", 'QPkrange': [[1, 1, 8, 9]], 'DIP_CPU': "1 1 1", 'DIP_ROLEs': "k c v", 'X_CPU': "1 1 1 1", 'X_ROLEs': "q k c v", 'SE_CPU': "1 1 1", 'SE_ROLEs': "q qp b", } params_gw = Dict(dict=params_gw) builder = YamboWorkflow.get_builder() ##################scf+nscf part of the builder builder.scf.pw.structure = structure builder.scf.pw.parameters = parameter_scf builder.scf.kpoints = kpoints builder.scf.pw.metadata.options.max_wallclock_seconds = \ options['max_wallclock_seconds'] builder.scf.pw.metadata.options.resources = \ dict = options['resources'] if 'queue_name' in options: builder.scf.pw.metadata.options.queue_name = options['queue_name'] if 'qos' in options: builder.scf.pw.metadata.options.qos = options['qos'] if 'account' in options: builder.scf.pw.metadata.options.account = options['account'] builder.scf.pw.metadata.options.prepend_text = options['prepend_text'] builder.nscf.pw.structure = builder.scf.pw.structure builder.nscf.pw.parameters = parameter_nscf builder.nscf.kpoints = builder.scf.kpoints builder.nscf.pw.metadata = builder.scf.pw.metadata builder.scf.pw.code = load_code(options['pwcode_id']) builder.nscf.pw.code = load_code(options['pwcode_id']) builder.scf.pw.pseudos = validate_and_prepare_pseudos_inputs( builder.scf.pw.structure, pseudo_family=Str(options['pseudo_family'])) builder.nscf.pw.pseudos = builder.scf.pw.pseudos ##################yambo part of the builder builder.yres.yambo.metadata.options.max_wallclock_seconds = \ options['max_wallclock_seconds'] builder.yres.yambo.metadata.options.resources = \ dict = options['resources'] if 'queue_name' in options: builder.yres.yambo.metadata.options.queue_name = options['queue_name'] if 'qos' in options: builder.yres.yambo.metadata.options.qos = options['qos'] if 'account' in options: builder.yres.yambo.metadata.options.account = options['account'] builder.yres.yambo.parameters = params_gw builder.yres.yambo.precode_parameters = Dict(dict={}) builder.yres.yambo.settings = Dict(dict={ 'INITIALISE': False, 'COPY_DBS': False }) builder.yres.max_iterations = Int(5) builder.yres.yambo.preprocessing_code = load_code( options['yamboprecode_id']) builder.yres.yambo.code = load_code(options['yambocode_id']) try: builder.parent_folder = load_node( options['parent_pk']).outputs.remote_folder except: pass return builder
def main(options): ###### setting the lattice structure ###### alat = 2.4955987320 # Angstrom the_cell = [[1.000000 * alat, 0.000000, 0.000000], [-0.500000 * alat, 0.866025 * alat, 0.000000], [0.000000, 0.000000, 6.4436359260]] atoms = Atoms('BNNB', [(1.2477994910, 0.7204172280, 0.0000000000), (-0.0000001250, 1.4408346720, 0.0000000000), (1.2477994910, 0.7204172280, 3.2218179630), (-0.0000001250, 1.4408346720, 3.2218179630)], cell=[1, 1, 1]) atoms.set_cell(the_cell, scale_atoms=False) atoms.set_pbc([True, True, True]) StructureData = DataFactory('structure') structure = StructureData(ase=atoms) ###### setting the kpoints mesh ###### KpointsData = DataFactory('array.kpoints') kpoints = KpointsData() kpoints.set_kpoints_mesh([6, 6, 2]) ###### setting the scf parameters ###### Dict = DataFactory('dict') params_scf = { 'CONTROL': { 'calculation': 'scf', 'verbosity': 'high', 'wf_collect': True }, 'SYSTEM': { 'ecutwfc': 130., 'force_symmorphic': True, 'nbnd': 20 }, 'ELECTRONS': { 'mixing_mode': 'plain', 'mixing_beta': 0.7, 'conv_thr': 1.e-8, 'diago_thr_init': 5.0e-6, 'diago_full_acc': True }, } parameter_scf = Dict(dict=params_scf) ###### creation of the workchain ###### builder = PwBaseWorkChain.get_builder() builder.pw.structure = structure builder.pw.parameters = parameter_scf builder.kpoints = kpoints builder.pw.metadata.options.max_wallclock_seconds = \ options['max_wallclock_seconds'] builder.pw.metadata.options.resources = \ dict = options['resources'] if 'queue_name' in options: builder.pw.metadata.options.queue_name = options['queue_name'] if 'qos' in options: builder.pw.metadata.options.qos = options['qos'] if 'account' in options: builder.metadata.options.account = options['account'] builder.pw.metadata.options.prepend_text = options['prepend_text'] builder.pw.code = load_code(options['code_id']) builder.pw.pseudos = validate_and_prepare_pseudos_inputs( builder.pw.structure, pseudo_family=Str(options['pseudo_family'])) return builder