def create_kpoints_from_distance(structure, distance, force_parity): """Generate a uniformly spaced kpoint mesh for a given structure. The spacing between kpoints in reciprocal space is guaranteed to be at least the defined distance. :param structure: the StructureData to which the mesh should apply :param distance: a Float with the desired distance between kpoints in reciprocal space :param force_parity: a Bool to specify whether the generated mesh should maintain parity :returns: a KpointsData with the generated mesh """ from numpy import linalg from aiida.orm import KpointsData epsilon = 1E-5 kpoints = KpointsData() kpoints.set_cell_from_structure(structure) kpoints.set_kpoints_mesh_from_density(distance.value, force_parity=force_parity.value) lengths_vector = [linalg.norm(vector) for vector in structure.cell] lengths_kpoint = kpoints.get_kpoints_mesh()[0] is_symmetric_cell = all(abs(length - lengths_vector[0]) < epsilon for length in lengths_vector) is_symmetric_mesh = all(length == lengths_kpoint[0] for length in lengths_kpoint) # If the vectors of the cell all have the same length, the kpoint mesh should be isotropic as well if is_symmetric_cell and not is_symmetric_mesh: nkpoints = max(lengths_kpoint) kpoints.set_kpoints_mesh([nkpoints, nkpoints, nkpoints]) return kpoints
def validate_kpoints_mesh(ctx, param, value): """ Command line option validator for a kpoints mesh tuple. The value should be a tuple of three positive integers out of which a KpointsData object will be created with a mesh equal to the tuple. :param ctx: internal context of the click.command :param param: the click Parameter, i.e. either the Option or Argument to which the validator is hooked up :param value: a tuple of three positive integers :returns: a KpointsData instance """ # pylint: disable=unused-argument from aiida.orm import KpointsData if not value: return None if any([not isinstance(integer, int) for integer in value]) or any([int(i) <= 0 for i in value]): raise click.BadParameter( 'all values of the tuple should be positive greater than zero integers' ) try: kpoints = KpointsData() kpoints.set_kpoints_mesh(value) except ValueError as exception: raise click.BadParameter( 'failed to create a KpointsData mesh out of {}\n{}'.format( value, exception)) return kpoints
def get_shear_relax_builder(self, shear_strain_ratio: float, additional_relax_pks: list = None): """ Get relax builder for shear introduced relax twinboundary structure. Args: shear_strain_ratio (float): shear strain ratio """ twinboundary_analyzer = self.get_twinboundary_analyzer( additional_relax_pks=additional_relax_pks) cell = twinboundary_analyzer.get_shear_cell( shear_strain_ratio=shear_strain_ratio, is_standardize=False) # in order to get rotation matrix std = StandardizeCell(cell=cell) std_cell = std.get_standardized_cell(to_primitive=True, no_idealize=False, no_sort=True) if additional_relax_pks is None: rlx_pk = self.get_pks()['relax_pk'] else: rlx_pk = additional_relax_pks[-1] rlx_node = load_node(rlx_pk) builder = rlx_node.get_builder_restart() # fix kpoints mesh, offset = map(np.array, builder.kpoints.get_kpoints_mesh()) orig_mesh = np.abs( np.dot(np.linalg.inv(self._standardize.transformation_matrix), mesh).astype(int)) orig_offset = np.round(np.abs( np.dot(np.linalg.inv(std.transformation_matrix), offset)), decimals=2) std_mesh = np.abs( np.dot(std.transformation_matrix, orig_mesh).astype(int)) std_offset = np.round(np.abs( np.dot(std.transformation_matrix, orig_offset)), decimals=2) kpt = KpointsData() kpt.set_kpoints_mesh(std_mesh, offset=std_offset) builder.kpoints = kpt # fix structure builder.structure = get_aiida_structure(cell=std_cell) # fix relax conf builder.relax.convergence_max_iterations = Int(100) builder.relax.positions = Bool(True) builder.relax.shape = Bool(False) builder.relax.volume = Bool(False) builder.relax.convergence_positions = Float(1e-4) builder.relax.force_cutoff = \ Float(AiidaRelaxWorkChain(node=rlx_node).get_max_force()) builder.metadata.label = "tbr:{} rlx:{} shr:{} std:{}".format( self._pk, rlx_node.pk, shear_strain_ratio, True) builder.metadata.description = \ "twinboundary_relax_pk:{} relax_pk:{} " \ "shear_strain_ratio:{} standardize:{}".format( self._pk, rlx_node.pk, shear_strain_ratio, True) return builder
def reuse_kpoints_grid(grid, lowest_pk=False): """ Retrieve previously stored kpoints mesh data node. If there is no such ``KpointsData``, a new node will be created. Will return the one with highest pk :param grid: Grid to be retrieved :param bool lowest_pk: If set to True will return the node with lowest pk :returns: A KpointsData node representing the grid requested """ from aiida.orm import QueryBuilder from aiida.orm import KpointsData qbd = QueryBuilder() qbd.append(KpointsData, tag="kpoints", filters={ "attributes.mesh.0": grid[0], "attributes.mesh.1": grid[1], "attributes.mesh.2": grid[2] }) if lowest_pk: order = "asc" else: order = "desc" qbd.order_by({"kpoints": [{"id": {"order": order}}]}) if qbd.count() >= 1: return qbd.first()[0] kpoints = KpointsData() kpoints.set_kpoints_mesh(grid) return kpoints
def _generate_kpoints_mesh(npoints): """Return a `KpointsData` with a mesh of npoints in each direction.""" from aiida.orm import KpointsData kpoints = KpointsData() kpoints.set_kpoints_mesh([npoints] * 3) return kpoints
def example_dft(code, pseudo_family): """Run simple silicon DFT calculation.""" print('Testing Abinit Total energy on Silicon using AbinitCalculation') thisdir = os.path.dirname(os.path.realpath(__file__)) structure = StructureData(pymatgen=mg.core.Structure.from_file( os.path.join(thisdir, 'files', 'Si.cif'))) pseudo_family = Group.objects.get(label=pseudo_family) pseudos = pseudo_family.get_pseudos(structure=structure) kpoints = KpointsData() kpoints.set_cell_from_structure(structure) kpoints.set_kpoints_mesh([2, 2, 2]) # kpoints.set_kpoints_mesh_from_density(2.0) parameters_dict = { 'code': code, 'structure': structure, 'pseudos': pseudos, 'kpoints': kpoints, 'parameters': Dict( dict={ 'ecut': 8.0, # Maximal kinetic energy cut-off, in Hartree 'nshiftk': 4, # of the reciprocal space (that form a BCC lattice !) 'shiftk': [[0.5, 0.5, 0.5], [0.5, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5]], 'nstep': 20, # Maximal number of SCF cycles 'toldfe': 1.0e-6, # Will stop when, twice in a row, the difference # between two consecutive evaluations of total energy # differ by less than toldfe (in Hartree) }), 'metadata': { 'options': { 'withmpi': True, 'max_wallclock_seconds': 2 * 60, 'resources': { 'num_machines': 1, 'num_mpiprocs_per_machine': 4, } } } } print('Running calculation...') run(AbinitCalculation, **parameters_dict)
def wf_getkpoints(aiida_structure, kptper_recipang): from aiida.orm import KpointsData def get_kmeshfrom_kptper_recipang(aiida_structure, kptper_recipang): import numpy as np kptper_recipang = kptper_recipang.value ase_structure = aiida_structure.get_ase() reci_cell = ase_structure.get_reciprocal_cell() kmesh = [np.ceil(kptper_recipang * np.linalg.norm(reci_cell[i])) for i in range(len(reci_cell))] return kmesh kpoints_mesh = get_kmeshfrom_kptper_recipang(aiida_structure, kptper_recipang) kpoints = KpointsData() kpoints.set_kpoints_mesh(kpoints_mesh) return kpoints
def _get_kpoints(self, key, structure, previous_workchain): from aiida.orm import KpointsData if previous_workchain: kpoints_mesh = KpointsData() kpoints_mesh.set_cell_from_structure(structure) previous_wc_kp = previous_workchain.inputs.kpoints kpoints_mesh.set_kpoints_mesh( previous_wc_kp.get_attribute('mesh'), previous_wc_kp.get_attribute('offset')) return kpoints_mesh if 'kpoints' in self._protocols[key]: kpoints_mesh = KpointsData() kpoints_mesh.set_cell_from_structure(structure) kp_dict = self._protocols[key]['kpoints'] if 'offset' in kp_dict: kpoints_mesh.set_kpoints_mesh_from_density( distance=kp_dict['distance'], offset=kp_dict['offset']) else: kpoints_mesh.set_kpoints_mesh_from_density( distance=kp_dict['distance']) return kpoints_mesh return None
wannier_code = load_code( "<CODE LABEL>") # Replace with the Wannier90 wannier.x code label pw2wannier90_code = load_code( "<CODE LABEL>") # Replace with the QE pw2wannier90.x code label pseudo_family_name = "<UPF FAMILY NAME>" # Replace with the name of the pseudopotential family for SSSP efficiency # GaAs structure a = 5.68018817933178 # angstrom structure = StructureData( cell=[[-a / 2., 0, a / 2.], [0, a / 2., a / 2.], [-a / 2., a / 2., 0]]) structure.append_atom(symbols=['Ga'], position=(0., 0., 0.)) structure.append_atom(symbols=['As'], position=(-a / 4., a / 4., a / 4.)) # 4x4x4 k-points mesh for the SCF kpoints_scf = KpointsData() kpoints_scf.set_kpoints_mesh([4, 4, 4]) # 10x10x10 k-points mesh for the NSCF/Wannier90 calculations kpoints_nscf = KpointsData() kpoints_nscf.set_kpoints_mesh([10, 10, 10]) # k-points path for the band structure kpoint_path = Dict( dict={ 'point_coords': { 'GAMMA': [0.0, 0.0, 0.0], 'K': [0.375, 0.375, 0.75], 'L': [0.5, 0.5, 0.5], 'U': [0.625, 0.25, 0.625], 'W': [0.5, 0.25, 0.75], 'X': [0.5, 0.0, 0.5]
def test_inp_gen_cell(gen_instance, sto_calc_inputs): """ Test generation of the inputs """ gen_instance.inputs = sto_calc_inputs gen_instance.prepare_inputs() assert 'symmetry_generate' in gen_instance.cell_file assert "POSITIONS_ABS" in gen_instance.cell_file assert "LATTICE_CART" in gen_instance.cell_file assert isinstance(gen_instance.cell_file["cell_constraints"], list) assert 'C9' in gen_instance.cell_file['SPECIES_POT'][0] # Test extra-kpoints from aiida.orm import KpointsData kpn1 = KpointsData() kpn1.set_kpoints_mesh((4, 4, 4)) gen_instance._include_extra_kpoints(kpn1, 'phonon', { 'task': ('phonon', ), 'need_weights': False }) assert 'phonon_kpoint_mp_grid' in gen_instance.cell_file kpn1.set_kpoints_mesh(( 4, 4, 4, ), (0.25, 0.25, 0.25)) gen_instance._include_extra_kpoints(kpn1, 'phonon', { 'task': ('phonon', ), 'need_weights': False }) assert 'phonon_kpoint_mp_offset' in gen_instance.cell_file # Explicit kpoints, with/without the weights kpn2 = KpointsData() kpn_points = [[0, 0, 0], [0.5, 0.5, 0.5]] kpn_weights = [0.3, 0.6] kpn2.set_kpoints(kpn_points, weights=kpn_weights) gen_instance._include_extra_kpoints(kpn2, 'bs', { 'task': ('bandstructure', ), 'need_weights': True }) assert len(gen_instance.cell_file['BS_KPOINT_LIST'][0].split()) == 4 kpn2 = KpointsData() kpn_points = [[0, 0, 0], [0.5, 0.5, 0.5]] kpn2.set_kpoints(kpn_points) gen_instance._include_extra_kpoints(kpn2, 'bs', { 'task': ('bandstructure', ), 'need_weights': True }) assert len(gen_instance.cell_file['BS_KPOINT_LIST'][0].split()) == 4 assert float(gen_instance.cell_file['BS_KPOINT_LIST'][0].split()[3]) == 0.5 # No weights gen_instance._include_extra_kpoints(kpn2, 'bs', { 'task': ('bandstructure', ), 'need_weights': False }) assert len(gen_instance.cell_file['BS_KPOINT_LIST'][0].split()) == 3 assert 'BS_KPOINT_LIST' in gen_instance.cell_file
}) # Extra parameters that also go to the fdf file, but are related # to the basis. basis = Dict( dict={ 'pao-energy-shift': '300 meV', '%block pao-basis-sizes': """ Si DZP %endblock pao-basis-sizes""", }) # Define the kpoints for the simulations. Note that this is not passed as # a normal fdf parameter, it has "its own input" kpoints = KpointsData() kpoints.set_kpoints_mesh([14, 14, 14]) # Get the appropiate pseudos (in "real life", one could have a pseudos family defined # in aiida database with `verdi data psf uploadfamily <path to folder> <family name>`) # and then pass it as a simple string, Aiida will know which pseudos to use. # See the pseudo_family in the aiida_siesta docs (link on top of the file) pseudos_dict = {} raw_pseudos = [("Si.psf", ['Si'])] for fname, kinds in raw_pseudos: absname = op.realpath( op.join(op.dirname(__file__), "../fixtures/sample_psf", fname)) pseudo = PsfData.get_or_create(absname) if not pseudo.is_stored: print("\nCreated the pseudo for {}".format(kinds)) else: print("\nUsing the pseudo for {} from DB: {}".format(kinds, pseudo.pk))
def phOriginalSubmit(uuid, codename, natlist, qpoints=[[0.0, 0.0, 0.0]], add_parameters={}, del_parameters={}, metadata={}, cluster_options={}): """ :code:`phOriginalSubmit` can submit a ph.x simulation to get the PDOS. It must follow a scf simulation. :param uuid: (mandatory) The uuid of previous calculation. We will start our calculation from there. Because uuid is the unique identification number for each CalcJobNode :type uuid: python string object :param codename: (mandatory) Represent the code for pw.x that you want to use. If you want to use the same as previous calculation, then you need to use Str('') :type codename: python string object :param natlist: (mandatory) Assign the atoms which we want to do the vibrational frequency analysis. :type natlist: python list object :param qpoints: (optional, default = [[0.0, 0.0, 0.0]] It is like k-points, but useful when calculating vibrational frequencies. :type qpoints: python list object :param add_parameters: (optional, default = {}) The desired parameters that you want to state, it can be incomplete, because inside the function there is a default setting for parameters which can be used in most cases, but if you have specific need, you can put that in parameters, the format is similar as pw.x input file. e.g. :code:`{'PROJWFC':{}}` :type add_parameters: python dictionary object :param del_parameters: (optional, default = {}) The tags that we would like to delete, for example if we do not want to use spin-polarized simulation, then 'nspin' needs to be deleted. Same structure as add_parameters. e.g. :code:`{'PROJWFC': [key1, key2, key3]}` :type del_parameters: python dictionary object :param metadata: (optional, default = {}) The dictionary that contains information about metadata. For example: label and description. label and description are mendatory. :type metadata: python dictionary object :param cluster_options: (optional, default = {}) The detailed option for the cluster. Different cluster may have different settings. Only the following 3 keys can have effects: (1) resources (2) account (3) queue_name :type cluster_options: python dictionary object :returns: uuid of the CalcJobNode object of the newest calculation. """ node = load_node(uuid=uuid) # check whether it is nscf simulation if node.inputs.parameters.get_dict()['CONTROL']['calculation'] != 'nscf': return ValueError( "You need to provide a nscf simulation with higher k-points.") computer = codename.split('@')[1] code = Code.get_from_string(codename) ph_builder = code.get_builder() # parameters ph_parameter = Dict(dict=phParameter) # add parameters in add_parameters for key, value in add_parameters.items(): for key2, value2 in value.items(): ph_parameter[key][key2] = value2 # delete parameters in del_parameters for key, value in del_parameters.items(): tmp = ph_parameter[key] for key2 in value: if key2 in tmp.keys(): tmp.pop(key2) # set kpoints qpts = KpointsData() if len(qpoints) == 1: qpts.set_kpoints_mesh(mesh=qpoints[0]) else: qpts.set_kpoints_mesh(mesh=qpoints[0], offset=qpoints[1]) # set default options for slurm # set first, then modify ph_builder.metadata.options['resources'] = slurm_options[computer]['ph'][ 'resources'] # in here machine = # node ph_builder.metadata.options['max_wallclock_seconds'] = slurm_options[ computer]['projwfc']['max_wallclock_seconds'] # in here machine = node ph_builder.metadata.options['account'] = slurm_options[computer]['ph'][ 'account'] # in here machine = node ph_builder.metadata.options['scheduler_stderr'] = slurm_options[computer][ 'ph']['scheduler_stderr'] ph_builder.metadata.options['scheduler_stderr'] = slurm_options[computer][ 'ph']['scheduler_stderr'] ph_builder.metadata.options['queue_name'] = slurm_options[computer]['ph'][ 'queue_name'] # reset cluster_options: if len(cluster_options) > 0: if 'resources' in cluster_options.keys(): ph_builder.metadata.options['resources'] = cluster_options[ 'resources'] if 'account' in cluster_options.keys(): ph_builder.metadata.options['account'] = cluster_options['account'] if 'queue_name' in cluster_options.keys(): ph_builder.metadata.options['queue_name'] = cluster_options[ 'queue_name'] ph_builder.parameters = Dict(dict=ph_parameter) ph_builder.parent_folder = node.outputs.remote_folder ph_builder.metadata.label = metadata['label'] ph_builder.metadata.description = metadata['description'] ph_builder.qpoints = qpts calc = submit(ph_builder) return calc.uuid
def qePwContinueSubmit(uuid, pseudo_family, pseudo_dict={}, codename='', parent_folder=True, add_parameters={}, del_parameters={}, kpoints=[], cluster_options={}, metadata={}, settings_dict={}): """ `qePwContinueSubmit` will continue a simulation with similar or modified input parameters. All the parameters are listed in the kwargs. :param uuid: (mandatory) The uuid of previous calculation. We will start our calculation from there. Because uuid is the unique identification number for each CalcJobNode **Notice**: The uuid must be in the results dictionary, if not the program will shout KeyError. And if you are testing, you could use assignValue to quickly create a dictionary that contains the uuid that you want to continue. :type uuid: python string object :param pseudo_family: (mandatory) The pseudopotential family that you want to use. Make sure that you already have that configured, otherwise an error will occur. This is mendatory. :type pseudo_family: python string object :param pseudo_dict: (optional, default = {}) Which contains the pseudopotential files that we want to use in the simulation. :type pseudo_dict: python dictionary object :param codename: (optional, default = '') Represent the code for pw.x that you want to use. If you want to use the same as previous calculation, then you need to use Str('') :type codename: python string object :param parent_folder: (optional, default = True) If parent_folder is True, then the calculation will start with the output files from previous calculations. :type parent_folder: python boolean object :param add_parameters: (optional, default = {}) The desired parameters that you want to state, it can be incomplete, because inside the function there is a default setting for parameters which can be used in most cases, but if you have specific need, you can put that in parameters, the format is similar as pw.x input file. If you want to assign DFT+U and spin-polarization, you need to specify it on your own. e.g. :code:`{'CONTROL':{}, 'SYSTEM':{}}` **Notice**: more options in qePwOriginalSubmit function. In qePwContinueSubmit, we assume that the user wants to restart from previous converged wave functions and charge density, so we set ['CONTROL']['restart_mode']='restart', ['ELECTRON'][ 'startingwfc']='file and ['ELECTRON']['startingpot']='file'. :type add_parameters: python dictionary object :param del_parameters: (optional, default = {})The tags that we would like to delete, for example if we do not want to use spin-polarized simulation, then 'nspin' needs to be deleted. Same structure as add_parameters. e.g. :code:`{'CONTROL': [key1, key2, key3], 'SYSTEM': [key1, key2, key3]}` :type del_parameters: python dictionary object :param kpoints: (optional, default = []), if you want to keep the k-points for previous calculation, just use an empty list :code:`[]`. The kpoints that you want to use, if the kpoints has only 1 list, then it is the kpoint mesh, but if two lists are detected, then the first will be k-point mesh, the second one will be the origin of k-point mesh.e.g. [[3, 3, 1]] or [[3, 3, 1],[0.5, 0.5, 0.5]] :type kpoints: python list object :param cluster_options: (optional, default = {}) The detailed option for the cluster. Different cluster may have different settings. Only the following 3 keys can have effects: (1) resources (2) account (3) queue_name. If value is :code:`{}`, then it means we will use previous settings :type cluster_options: python dictionary object :param metadata: (optional, default = {}) The dictionary that contains information about metadata. For example: label and description.label and description are mendatory. If value is :code:`{}`, then it means we will use previous settings. :type metadata: python dictionary object :param settings_dict: (optional, default = {}) which contains the additional information for the pw.x calculation. e.g. Fixed atom, retrieving more files, parser options, etc. And the command-line options. If value is :code:`{}`, then it means we will use previous settings. :type settings_dict: python dictionary object :returns: uuid of the CalcJobNode of the newest calculation. """ node = load_node(uuid=uuid) if len(codename) == 0: # not going to change cluster computer = node.computer.label restart_builder = node.get_builder_restart() # get the restart_builder else: computer = codename.split('@')[1] code = Code.get_from_string(codename) restart_builder = code.get_builder() parameters_tmp = deepcopy(node.inputs.parameters) parameters_dict = parameters_tmp.get_dict() calc_type = parameters_dict['CONTROL']['calculation'] # change the parameters (since this is the continuation of the previous calculation) parameters_tmp['CONTROL']['restart_mode'] = 'restart' parameters_tmp['ELECTRONS'][ 'startingwfc'] = 'file' # from wave function in aiida.save parameters_tmp['ELECTRONS'][ 'startingpot'] = 'file' # from charge density in aiida.save if calc_type == 'relax' or calc_type == 'vc-relax': structure = node.outputs.output_structure elif calc_type == 'scf' or calc_type == 'nscf': structure = node.inputs.structure # assign parameters in add_parameters for key, value in add_parameters.items(): for key2, value2 in value.items(): parameters_tmp[key][key2] = value2 # delete parameters in del_parameters for key, value in del_parameters.items(): tmp = parameters_tmp[key] for key2 in value: if key2 in tmp.keys(): tmp.pop(key2) parameters_default = parameters_tmp # reset the kpoints if len(kpoints) > 0: kpts = KpointsData() if len(kpoints) == 1: kpts.set_kpoints_mesh(mesh=kpoints[0]) else: kpts.set_kpoints_mesh(mesh=kpoints[0], offset=kpoints[1]) else: kpts = node.inputs.kpoints # pseudopotential # check whether pseudo_family and pseudo_dict are set at the same time, if true, then break if len(pseudo_family) > 0 and len(pseudo_dict) > 0: return ValueError( "You cannot set pseudo_family and pseudo_dict at the same time") if len(pseudo_family) == 0 and len(pseudo_dict) == 0: return ValueError( "You need to specify at least one in pseudo_family or pseudo_dict." ) if len(pseudo_family) != 0: restart_builder.pseudos = get_pseudos_from_structure( structure, family_name=pseudo_family) if len(pseudo_dict) != 0: restart_builder.pseudos = pseudo_dict # set default options for slurm restart_builder.metadata.options['resources'] = slurm_options[computer][ 'qe']['resources'] # in here machine = node restart_builder.metadata.options['max_wallclock_seconds'] = slurm_options[ computer]['qe']['max_wallclock_seconds'] # in here machine = node restart_builder.metadata.options['account'] = slurm_options[computer][ 'qe']['account'] # in here machine = node restart_builder.metadata.options['scheduler_stderr'] = slurm_options[ computer]['qe']['scheduler_stderr'] restart_builder.metadata.options['scheduler_stderr'] = slurm_options[ computer]['qe']['scheduler_stderr'] restart_builder.metadata.options['queue_name'] = slurm_options[computer][ 'qe']['queue_name'] # reset cluster_options: if len(cluster_options) > 0: if 'resources' in cluster_options.keys(): restart_builder.metadata.options['resources'] = cluster_options[ 'resources'] if 'account' in cluster_options.keys(): restart_builder.metadata.options['account'] = cluster_options[ 'account'] if 'queue_name' in cluster_options.keys(): restart_builder.metadata.options['queue_name'] = cluster_options[ 'queue_name'] # reset metadata if len(metadata) > 0: if 'label' in metadata.keys(): restart_builder.metadata.label = metadata['label'] else: restart_builder.metadata.label = node.label if 'description' in metadata.keys(): restart_builder.metadata.description = metadata['description'] else: restart_builder.metadata.description = node.description else: restart_builder.metadata.label = node.label restart_builder.metadata.description = node.description # assign the parent_folder if parent_folder: restart_builder.parent_folder = node.outputs.remote_folder # set settings_dict if len(settings_dict) > 0: pass else: settings_dict = node.inputs.settings.get_dict() # submit the calculation restart_builder.structure = structure restart_builder.kpoints = kpts restart_builder.parameters = parameters_default restart_builder.settings = Dict(dict=settings_dict) calc = submit(restart_builder) return calc.uuid
def qePwOriginalSubmit(codename, structure, kpoints, pseudo_family, metadata, pseudo_dict={}, add_parameters={}, del_parameters={}, cluster_options={}, settings_dict={}): """ :code:`qePwOriginalSubmit` will submit an original computational task to the desired computer by using certain code. :param codename: (mandatory) A string represents the code for pw.x that you want to use. :type codename: python string object :param structure: (mandatory) The structure of your system. :type structure: aiida.orm.StructureData object :param add_parameters: (optional, default = {}) The desired parameters that you want to state, it can be incomplete, because inside the function there is a default setting for parameters which can be used in most cases, but if you have specific need, you can put that in parameters, the format is similar as pw.x input file. If you want to assign DFT+U and spin-polarization, you need to specify it on your own. In Aiida, there is a very efficient way to specify the :code:`hubbard_u`, :code:`starting_magnetization` and :code:`starting_ns_eigenvalue`. I give some examples in below: .. code-block:: python # hubbard_u 'SYSTEM': { 'hubbard_u': { 'Fe': 5.0, 'Fe3': 5.0 # if you have different spins of same atom, then you should use newStructure function to create the structure }, 'starting_magnetization': { 'Fe': 0.1, 'Fe3': 0.1, }, 'starting_ns_eigenvalue': [ [1, 1, 'Fe', 1.0] # represent: starting_ns_eigenvalue(1, 1, 1)=1.0 # others are the same, if you want to assign to Fe3, just replace Fe with Fe3. ] } :type add_parameters: python dictionary :param del_parameters: (optional, default = {}) The tags that we would like to delete, for example if we do not want to use spin-polarized simulation, then 'nspin' needs to be deleted. Same structure as add_parameters. e.g. :code:`{'CONTROL': [key1, key2, key3], 'SYSTEM': [key1, key2, key3]}` :type del_parameters: python dictionary object :param kpoints: (mandatory) The kpoints that you want to use, if the kpoints has only 1 list, then it is the kpoint mesh, but if two lists are detected, then the first will be k-point mesh, the second one will be the origin of k-point mesh.e.g. [[3, 3, 1]] or [[3, 3, 1],[0.5, 0.5, 0.5]] :type kpoints: python list object :param pseudo_family: (mandatory) The pseudopotential family that you want to use. Make sure that you already have that configured, otherwise an error will occur. :type pseudo_family: python string object. :param pseudo_dict: (optional, default = {}) which contains the pseudopotential files that we want to use in the simulation. In here it is very important to note that the path of the pseudopotential file has to be in the absolute path. e.g. .. code-block:: python pseudo_dict = { 'Fe': UpfData(absolute_path), 'Fe3': UpfData(absolute_path) } :type pseudo_dict: python dictionary object. :param cluster_options: (optional, default = {}) The detailed option for the cluster. Different cluster may have different settings. Only the following 3 keys can have effects: (1) resources (2) account (3) queue_name :type cluster_options: python dictionary object :param metadata: (mandatory) The dictionary that contains information about metadata. For example: label and description. label and description are mendatory. e.g. :code:`{'label':{}, 'description':{}}` :type metadata: python dictionary object :param settings_dict: (optional, default = {}) which contains the additional information for the pw.x calculation. e.g. Fixed atom, retrieving more files, parser options, etc. And the command-line options. :type settings_dict: python dictionary object :returns: uuid of the new CalcJobNode """ code = Code.get_from_string(codename) computer = codename.split('@')[1] # get the name of the cluster pw_builder = code.get_builder() # pseudopotential # check whether pseudo_family and pseudo_dict are set at the same time, if true, then break if len(pseudo_family) > 0 and len(pseudo_dict) > 0: return ValueError( "You cannot set pseudo_family and pseudo_dict at the same time") if len(pseudo_family) == 0 and len(pseudo_dict) == 0: return ValueError( "You need to specify at least one in pseudo_family or pseudo_dict." ) if len(pseudo_family) != 0: pw_builder.pseudos = get_pseudos_from_structure( structure, family_name=pseudo_family) if len(pseudo_dict) != 0: pw_builder.pseudos = pseudo_dict # set kpoints kpts = KpointsData() if len(kpoints) == 1: kpts.set_kpoints_mesh(mesh=kpoints[0]) else: kpts.set_kpoints_mesh(mesh=kpoints[0], offset=kpoints[1]) # parameters parameters_default = Dict(dict=pwParameter) # add parameters in add_parameters parameters_tmp = deepcopy(parameters_default) for key, value in add_parameters.items(): for key2, value2 in value.items(): parameters_tmp[key][key2] = value2 # delete parameters in del_parameters for key, value in del_parameters.items(): tmp = parameters_tmp[key] for key2 in value: if key2 in tmp.keys(): tmp.pop(key2) else: pass parameters_default = parameters_tmp # set labels and description pw_builder.metadata.label = metadata['label'] pw_builder.metadata.description = metadata['description'] # set default options for slurm pw_builder.metadata.options['resources'] = slurm_options[computer]['qe'][ 'resources'] # in here machine = node pw_builder.metadata.options['max_wallclock_seconds'] = slurm_options[ computer]['qe']['max_wallclock_seconds'] #in here machine = node pw_builder.metadata.options['account'] = slurm_options[computer]['qe'][ 'account'] # in here machine = node pw_builder.metadata.options['scheduler_stderr'] = slurm_options[computer][ 'qe']['scheduler_stderr'] pw_builder.metadata.options['scheduler_stderr'] = slurm_options[computer][ 'qe']['scheduler_stderr'] pw_builder.metadata.options['queue_name'] = slurm_options[computer]['qe'][ 'queue_name'] # revised by cluster_options if len(cluster_options) > 0: if 'resources' in cluster_options.keys(): pw_builder.metadata.options['resources'] = cluster_options[ 'resources'] if 'account' in cluster_options.keys(): pw_builder.metadata.options['account'] = cluster_options['account'] if 'queue_name' in cluster_options.keys(): pw_builder.metadata.options['queue_name'] = cluster_options[ 'queue_name'] # initialize the settings_dict if len(settings_dict) == 0: settings_dict['cmdline'] = ['-nk', '4'] else: pass # do nothing # get atomic occupations if 'lda_plus_u' in parameters_default['SYSTEM']: if parameters_default['SYSTEM']['lda_plus_u']: settings_dict['parser_options'] = { 'parse_atomic_occupations': True } # launch the simulation pw_builder.structure = structure pw_builder.kpoints = kpts pw_builder.parameters = parameters_default pw_builder.settings = Dict(dict=settings_dict) calc = submit(pw_builder) return calc.uuid
def get_kpoints_mesh(self, mesh): """Factory for kpoints with mesh""" kpoints_data = KpointsData() kpoints_data.set_kpoints_mesh(mesh) return kpoints_data
'electronic-temperature': '25 meV', 'write-forces': True, }) #The basis set basis = Dict( dict={ 'pao-energy-shift': '300 meV', '%block pao-basis-sizes': """ Si DZP %endblock pao-basis-sizes""", }) #The kpoints kpoints = KpointsData() kpoints.set_kpoints_mesh([4, 4, 4]) #The pseudopotentials pseudos_dict = {} raw_pseudos = [("Si.psf", ['Si'])] for fname, kinds in raw_pseudos: absname = op.realpath(op.join(op.dirname(__file__), "../fixtures/sample_psf", fname)) pseudo = PsfData.get_or_create(absname) if not pseudo.is_stored: print("\nCreated the pseudo for {}".format(kinds)) else: print("\nUsing the pseudo for {} from DB: {}".format(kinds, pseudo.pk)) for j in kinds: pseudos_dict[j]=pseudo
'electronic-temperature': '25 meV', 'write-forces': True, 'mesh-cutoff': "200 Ry" }) #The basis basis = Dict(dict={ 'pao-energy-shift': '100 meV', '%block pao-basis-sizes': """ Si DZP %endblock pao-basis-sizes""", }) #The kpoints mesh kpoints = KpointsData() kpoints.set_kpoints_mesh([11, 11, 11]) ##-------------------K-points for bands -------------------- bandskpoints = KpointsData() bandskpoints = result['explicit_kpoints'] #The pseudopotentials pseudos_dict = get_pseudos_from_structure(structure, 'nc-sr-04_pbe_standard-psf') #Resources options = { "max_wallclock_seconds": 600, # "withmpi" : True, "resources": { "num_machines": 1, "num_mpiprocs_per_machine": 1,