def create_structure_bands(): """Create bands structure object.""" alat = 4. # angstrom cell = [ [ alat, 0., 0., ], [ 0., alat, 0., ], [ 0., 0., alat, ], ] strct = StructureData(cell=cell) strct.append_atom(position=(0., 0., 0.), symbols='Fe') strct.append_atom(position=(alat / 2., alat / 2., alat / 2.), symbols='O') strct.store() @calcfunction def connect_structure_bands(strct): # pylint: disable=unused-argument alat = 4. cell = np.array([ [alat, 0., 0.], [0., alat, 0.], [0., 0., alat], ]) kpnts = KpointsData() kpnts.set_cell(cell) kpnts.set_kpoints([[0., 0., 0.], [0.1, 0.1, 0.1]]) bands = BandsData() bands.set_kpointsdata(kpnts) bands.set_bands([[1.0, 2.0], [3.0, 4.0]]) return bands bands = connect_structure_bands(strct) # Create 2 groups and add the data to one of them g_ne = Group(label='non_empty_group') g_ne.store() g_ne.add_nodes(bands) g_e = Group(label='empty_group') g_e.store() return { DummyVerdiDataListable.NODE_ID_STR: bands.id, DummyVerdiDataListable.NON_EMPTY_GROUP_ID_STR: g_ne.id, DummyVerdiDataListable.EMPTY_GROUP_ID_STR: g_e.id }
def create_structure_bands(): alat = 4. # angstrom cell = [ [ alat, 0., 0., ], [ 0., alat, 0., ], [ 0., 0., alat, ], ] s = StructureData(cell=cell) s.append_atom(position=(0., 0., 0.), symbols='Fe') s.append_atom(position=(alat / 2., alat / 2., alat / 2.), symbols='O') s.store() @calcfunction def connect_structure_bands(structure): alat = 4. cell = np.array([ [alat, 0., 0.], [0., alat, 0.], [0., 0., alat], ]) k = KpointsData() k.set_cell(cell) k.set_kpoints([[0., 0., 0.], [0.1, 0.1, 0.1]]) b = BandsData() b.set_kpointsdata(k) b.set_bands([[1.0, 2.0], [3.0, 4.0]]) return b b = connect_structure_bands(s) # Create 2 groups and add the data to one of them g_ne = Group(label='non_empty_group') g_ne.store() g_ne.add_nodes(b) g_e = Group(label='empty_group') g_e.store() return { TestVerdiDataListable.NODE_ID_STR: b.id, TestVerdiDataListable.NON_EMPTY_GROUP_ID_STR: g_ne.id, TestVerdiDataListable.EMPTY_GROUP_ID_STR: g_e.id }
def create_structure_data(): """Create StructureData object.""" alat = 4. # angstrom cell = [ [ alat, 0., 0., ], [ 0., alat, 0., ], [ 0., 0., alat, ], ] # BaTiO3 cubic structure struc = StructureData(cell=cell) struc.append_atom(position=(0., 0., 0.), symbols='Ba') struc.append_atom(position=(alat / 2., alat / 2., alat / 2.), symbols='Ti') struc.append_atom(position=(alat / 2., alat / 2., 0.), symbols='O') struc.append_atom(position=(alat / 2., 0., alat / 2.), symbols='O') struc.append_atom(position=(0., alat / 2., alat / 2.), symbols='O') struc.store() # Create 2 groups and add the data to one of them g_ne = Group(label='non_empty_group') g_ne.store() g_ne.add_nodes(struc) g_e = Group(label='empty_group') g_e.store() return { DummyVerdiDataListable.NODE_ID_STR: struc.id, DummyVerdiDataListable.NON_EMPTY_GROUP_ID_STR: g_ne.id, DummyVerdiDataListable.EMPTY_GROUP_ID_STR: g_e.id }
def get_structure(): """Return a `StructureData` representing bulk silicon. The database will first be queried for the existence of a bulk silicon crystal. If this is not the case, one is created and stored. This function should be used as a default for CLI options that require a `StructureData` node. This way new users can launch the command without having to construct or import a structure first. This is the reason that we hardcode a bulk silicon crystal to be returned. More flexibility is not required for this purpose. :return: a `StructureData` representing bulk silicon """ from ase.spacegroup import crystal from aiida.orm import QueryBuilder, StructureData # Filters that will match any elemental Silicon structure with 2 or less sites in total filters = { 'attributes.sites': { 'of_length': 2 }, 'attributes.kinds': { 'of_length': 1 }, 'attributes.kinds.0.symbols.0': 'Si' } builder = QueryBuilder().append(StructureData, filters=filters) results = builder.first() if not results: alat = 5.43 ase_structure = crystal( 'Si', [(0, 0, 0)], spacegroup=227, cellpar=[alat, alat, alat, 90, 90, 90], primitive_cell=True, ) structure = StructureData(ase=ase_structure) structure.store() else: structure = results[0] return structure.uuid
def launch(dataset_path, group_name, group_description, parse_comments_path, parse_comments_structure): print("loading dataset: {} to group: {}".format(dataset_path, group_name)) # Setup/Retrieve the Group g = Group.objects.get_or_create(name=group_name, description=group_description)[0] # Loop over structures in the dataset_path, storing the nodes then adding them to the group i = 0 while True: try: ase_structure = ase.io.read(dataset_path, index=i, format="runner") except StopIteration: break # setup and store the ase structure as an aiida StructureData node aiida_structure = StructureData() aiida_structure.set_ase(ase_structure) aiida_structure_stored = aiida_structure.store() # add in the dataset_path line if possible if parse_comments_path: try: structure_path = ase_structure.comment.strip().split()[-1][3:] aiida_structure_stored.set_extra("structure_path", structure_path) except AttributeError: print( "could not set structure_path on {}".format(ase_structure)) pass # Add in details of parent structure uuid if parse_comments_structure: try: parent_uuid = ase_structure.comment.strip().split()[-1] aiida_structure_stored.set_extra("parent_uuid", parent_uuid) add_parentstructure_extras(aiida_structure_stored, parent_uuid) except AttributeError: print("could not set parent_uuid on {}".format(ase_structure)) pass # add in the chemical formula and number of atoms if possible try: aiida_structure_stored.set_extra("num_atoms", len(ase_structure)) aiida_structure_stored.set_extra( "chem_formula", ase_structure.get_chemical_formula()) except AttributeError: print("could not set either num_atoms or chemical_formula " \ " on {}".format(ase_structure)) pass # add the structure to the group g.add_nodes(aiida_structure_stored) g.store() i += 1
def store_asestructure(ase_structure, extras, structure_group, dryrun): ase_structure = sort(ase_structure) ase_structure.set_tags( [0] * len(ase_structure)) #force AiiDA to use the same kind for each element # convert any instances of vacancy internal symbol use back to user symbol use for key in extras: if extras[key] == VACANCY_INTERNAL_SYMBOL: extras[key] = VACANCY_USER_SYMBOL if key == 'matrix_elements': extras[key] = [ (lambda x: x if x != VACANCY_INTERNAL_SYMBOL else VACANCY_USER_SYMBOL)(x) for x in extras[key] ] # delete all the vacancy sites prior to storage del ase_structure[[ x.index for x in ase_structure if x.symbol == VACANCY_INTERNAL_SYMBOL or x.symbol == VACANCY_USER_SYMBOL ]] alreadyin_group = checkif_structure_alreadyin_group( ase_structure, structure_group) if alreadyin_group: print(("skiping structure, already stored in group: {}".format( ase_structure))) return if dryrun: print(("structure: {}".format(ase_structure))) print(("extras: {}".format(extras))) else: print(("storing structure: {}".format(ase_structure))) aiida_structure = StructureData() aiida_structure.set_ase(ase_structure) aiida_structure_stored = aiida_structure.store() for key in extras: aiida_structure_stored.set_extra(key, extras[key]) aiida_structure_stored.set_extra("num_atoms", len(ase_structure)) aiida_structure_stored.set_extra("chem_formula", ase_structure.get_chemical_formula()) structure_group.add_nodes(aiida_structure_stored) print(("{} stored".format(aiida_structure_stored))) return
cell = [[a, 0, 0], [0, a, 0], [0, 0, a]] symbols = ['Si'] * 8 scaled_positions = [(0.875, 0.875, 0.875), (0.875, 0.375, 0.375), (0.375, 0.875, 0.375), (0.375, 0.375, 0.875), (0.125, 0.125, 0.125), (0.125, 0.625, 0.625), (0.625, 0.125, 0.625), (0.625, 0.625, 0.125)] structure = StructureData(cell=cell) positions = np.dot(scaled_positions, cell) for i, scaled_position in enumerate(scaled_positions): structure.append_atom(position=np.dot(scaled_position, cell).tolist(), symbols=symbols[i]) structure.store() dynaphopy_parameters = { 'supercell': [[2, 0, 0], [0, 2, 0], [0, 0, 2]], 'primitive': [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], 'mesh': [40, 40, 40], 'md_commensurate': True, 'temperature': 300 } # Temperature can be omitted (If ommited calculated from Max.-Boltz.) dynaphopy_machine = { 'num_machines': 1, 'parallel_env': 'mpi*', 'tot_num_mpiprocs': 16 }
def test_fleur_eos_structure_Si(self, run_with_cache, fleur_local_code, inpgen_local_code, generate_structure2, clear_spec): """ full example using scf workflow with just a fleurinp data as input. Several fleur runs needed till convergence """ from aiida.orm import Code, load_node, Dict, StructureData options = { 'resources': { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 }, 'max_wallclock_seconds': 10 * 60, 'withmpi': False, 'custom_scheduler_commands': '' } wf_param = {'points': 7, 'step': 0.002, 'guess': 1.00} calc_parameters = { 'atom': { 'element': 'Si', 'rmt': 2.1, 'jri': 981, 'lmax': 8, 'lnonsph': 6 }, 'comp': { 'kmax': 3.4 }, 'kpt': { 'div1': 10, 'div2': 10, 'div3': 10, 'tkb': 0.0005 } } # Fe fcc structure bohr_a_0 = 0.52917721092 # A a = 3.4100000000 * 2**(0.5) cell = [[a, 0, 0], [0, a, 0], [0, 0, a]] structure = StructureData(cell=cell) structure.append_atom(position=(0., 0., 0.), symbols='Fe', name='Fe1') structure.append_atom(position=(0.5 * a, 0.5 * a, 0.0 * a), symbols='Fe', name='Fe2') structure.append_atom(position=(0.5 * a, 0.0 * a, 0.5 * a), symbols='Fe', name='Fe31') structure.append_atom(position=(0.0 * a, 0.5 * a, 0.5 * a), symbols='Fe', name='Fe43') calc_parameters = { 'comp': { 'kmax': 3.4, }, 'atom': { 'element': 'Fe', 'bmu': 2.5, 'rmt': 2.15 }, 'kpt': { 'div1': 4, 'div2': 4, 'div3': 4 } } wf_para_scf = { 'fleur_runmax': 2, 'itmax_per_run': 120, 'density_converged': 0.2, 'serial': True, 'mode': 'density' } FleurCode = fleur_local_code InpgenCode = inpgen_local_code # create process builder to set parameters builder = FleurEosWorkChain.get_builder() builder.metadata.description = 'Simple Fleur FleurEosWorkChain test for Si bulk' builder.metadata.label = 'FleurEosWorkChain_test_Si_bulk' builder.structure = structure.store() #generate_structure2().store() builder.wf_parameters = Dict(dict=wf_param).store() builder.scf = { 'fleur': FleurCode, 'inpgen': InpgenCode, 'options': Dict(dict=options).store(), 'wf_parameters': Dict(dict=wf_para_scf).store(), 'calc_parameters': Dict(dict=calc_parameters).store() } print(builder) # now run calculation out, node = run_with_cache(builder) print(out) print(node) outpara = out.get('output_eos_wc_para', None) assert outpara is not None outpara = outpara.get_dict() print(outpara) outstruc = out.get('output_eos_wc_structure', None) assert outstruc is not None assert node.is_finished_ok # check output #distance, bulk modulus, optimal structure, opt scaling assert abs(outpara.get('scaling_gs') - 0.99268546558578) < 10**14 assert outpara.get('warnings') == [ 'Groundstate volume was not in the scaling range.' ] assert outpara.get('info') == [ 'Consider rerunning around point 0.9926854655857787' ]
def test_fleur_corehole_W( self, #run_with_cache, inpgen_local_code, fleur_local_code, generate_structure_W): #, clear_spec): """ full example using FleurCoreholeWorkChain on W. Several fleur runs needed, calculation of all only certain coreholes """ from aiida.engine import run_get_node options = Dict( dict={ 'resources': { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 }, 'max_wallclock_seconds': 60 * 60, 'queue_name': '' }) #'withmpi': False, 'custom_scheduler_commands': ''} options.store() parameters = Dict( dict={ 'atom': { 'element': 'W', 'jri': 833, 'rmt': 2.3, 'dx': 0.015, 'lmax': 8, 'lo': '5p', 'econfig': '[Kr] 5s2 4d10 4f14| 5p6 5d4 6s2', }, 'comp': { 'kmax': 3.0, }, 'kpt': { 'nkpt': 100, } }) parameters.store() #structure = generate_structure_W() # W bcc structure bohr_a_0 = 0.52917721092 # A a = 3.013812049196 * bohr_a_0 cell = [[-a, a, a], [a, -a, a], [a, a, -a]] structure = StructureData(cell=cell) structure.append_atom(position=(0., 0., 0.), symbols='W') structure.store() wf_para = Dict( dict={ 'method': 'valence', 'hole_charge': 0.5, 'atoms': ['all'], 'corelevel': ['W,4f', 'W,4p'], #['W,all'],# 'supercell_size': [2, 1, 1], 'magnetic': True }) FleurCode = fleur_local_code InpgenCode = inpgen_local_code # create process builder to set parameters inputs = { #'metadata' : { # 'description' : 'Simple FleurCoreholeWorkChain test with W bulk', # 'label' : 'FleurCoreholeWorkChain_test_W_bulk'}, 'options': options, 'fleur': FleurCode, 'inpgen': InpgenCode, 'wf_parameters': wf_para, 'calc_parameters': parameters, 'structure': structure } # now run calculation #out, node = run_with_cache(inputs, process_class=FleurCoreholeWorkChain) out, node = run_get_node(FleurCoreholeWorkChain, **inputs) # check general run assert node.is_finished_ok # check output # corelevel shift should be zero outn = out.get('output_corehole_wc_para', None) assert outn is not None outd = outn.get_dict() assert outd.get('successful') assert outd.get('warnings') == [] assert outd.get('weighted_binding_energy') == [ 470.54883993999, 402.52235778002, 32.112260220107, 29.829247920075 ] assert outd.get('binding_energy') == [ 235.27441997, 201.26117889001, 16.056130110053, 14.914623960038 ]