def test_symmetrize_defect_structure_wo_anchor(): structure = Structure.from_str(fmt="POSCAR", input_string="""Mg4 O3 1.00000000000000 5 0 0 0 5 0 0 0 5 Mg O 4 3 Direct 0.01 0.01 0.01 0.01 0.51 0.51 0.51 0.01 0.51 0.51 0.51 0.01 0.51 0.51 0.51 0.01 0.01 0.51 0.01 0.51 0.01""") structure_symmetrizer = StructureSymmetrizer(structure) actual = symmetrize_defect_structure(structure_symmetrizer=structure_symmetrizer) expected = Structure.from_str(fmt="POSCAR", input_string="""Mg4 O3 1.00000000000000 5 0 0 0 5 0 0 0 5 Mg O 4 3 Direct 0.01 0.01 0.01 0.01 0.51 0.51 0.51 0.01 0.51 0.51 0.51 0.01 0.51 0.51 0.51 0.01 0.01 0.51 0.01 0.51 0.01""") assert actual == expected
def test_transformation_matrix(): structure = Structure.from_str(""" 1.0 -2.5007160000000002 2.5007160000000002 3.6755999999999993 2.5007160000000002 -2.5007159999999988 3.6755999999999993 2.5007160000000002 2.5007159999999988 -3.6755999999999993 Si 2 Direct 0.7500000000000001 0.2500000000000001 0.5000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000""", fmt="POSCAR") conv_structure = Structure.from_str(""" 1.0 5.001432 0.000000 0.000000 0.000000 5.001432 0.000000 0.000000 0.000000 7.351200 Si 4 direct 0.000000 0.500000 0.250000 Si 0.500000 1.000000 0.750000 Si 0.000000 0.000000 0.000000 Si 0.500000 0.500000 0.500000 Si""", fmt="POSCAR") matrix_to_conv_cell = [[3, 0, 0], [0, 3, 0], [0, 0, 2]] sm = SupercellMaker(structure, matrix_to_conv_cell=matrix_to_conv_cell) actual = structure * sm.transformation_matrix expected = conv_structure * matrix_to_conv_cell assert actual == expected
def lattice_matching_view(request, *args,**kwargs): context = {} is_signed_in = request.user.is_authenticated and not request.user.is_anonymous context.update({"is_signed_in": is_signed_in}) if request.method == 'POST': if 'submit' in request.POST: print('SUBMIT HIT') i = 0 user_input_1 = request.FILES.get('user_input_1', None) user_input_2 = request.FILES.get('user_input_2', None) user_input_1 = user_input_1.read().decode("utf-8") user_input_2 = user_input_2.read().decode("utf-8") request.session['user_input_1'] = user_input_1 request.session['user_input_2'] = user_input_2 user_area = request.POST.get('user_area', None) user_strain = request.POST.get('user_strain', None) request.session['user_area'] = user_area request.session['user_strain'] = user_strain request.session['i'] = i a= StructureMatcher(user_input_1, user_input_2, float(user_area), float(user_strain)) s3 =a[1][i].to(fmt='poscar') strain_u = a[2][i] strain_v = a[3][i] area = a[4][i] if 'next' in request.POST: print('NEXT!!!!!!!!!!!') user_input_1 = request.session.get('user_input_1') user_input_2 = request.session.get('user_input_2') user_area = request.session.get('user_area') user_strain = request.session.get('user_strain') i = request.session.get('i') i = i + 1 a= StructureMatcher(user_input_1, user_input_2, float(user_area), float(user_strain)) if i == len(a[1]): i = 0 request.session['i'] = i print(i) s3 =a[1][i].to(fmt='poscar') strain_u = a[2][i] strain_v = a[3][i] area = a[4][i] context.update(({ "data": a, "structure_1": get_jmol2(Structure.from_str(user_input_1, fmt='poscar')), "structure_2": get_jmol2(Structure.from_str(user_input_2, fmt='poscar')), "structure_3": get_jmol2(Structure.from_str(s3, fmt='poscar')), "strain_u": strain_u, "strain_v": strain_v, "Area": area, "page_c": i+1, "page_t": len(a[1]), "download": s3, })) return render(request, 'test.html', context)
def poscar_elong(poscar_in, poscar_out, elong, shift_center=True): with open(poscar_in, 'r') as fin: lines = list(fin) if lines[7][0].upper() != 'C': raise RuntimeError("only works for Cartesian POSCAR") sboxz = lines[4].split() boxz = np.array([float(sboxz[0]), float(sboxz[1]), float(sboxz[2])]) boxzl = np.linalg.norm(boxz) elong_ratio = elong / boxzl boxz = boxz * (1. + elong_ratio) lines[4] = '%.16e %.16e %.16e\n' % (boxz[0], boxz[1], boxz[2]) if shift_center: poscar_str = "".join(lines) st = Structure.from_str(poscar_str, fmt='poscar') cart_coords = st.cart_coords z_mean = cart_coords[:, 2].mean() z_shift = st.lattice.c / 2 - z_mean cart_coords[:, 2] = cart_coords[:, 2] + z_shift nst = Structure(st.lattice, st.species, coords=cart_coords, coords_are_cartesian=True) nst.to('poscar', poscar_out) else: with open(poscar_out, 'w') as fout: fout.write("".join(lines))
def test_mpid_and_link(): structure = Structure.from_str("""Na4 Mg4 F12 1.00000000000000 5.5403959532636717 0.0000000000000000 0.0000000000000000 0.0000000000000000 7.7192894192012265 0.0000000000000000 0.0000000000000000 0.0000000000000000 5.3769536232127138 Na Mg F 4 4 12 Direct 0.9497921992239995 0.7500000000000000 0.0129542690007938 0.5502078007760005 0.2500000000000000 0.5129542690007938 0.4497921992239995 0.7500000000000000 0.4870457309992062 0.0502078007760005 0.2500000000000000 0.9870457309992062 0.5000000000000000 0.5000000000000000 0.0000000000000000 0.0000000000000000 0.5000000000000000 0.5000000000000000 0.0000000000000000 0.0000000000000000 0.5000000000000000 0.5000000000000000 0.0000000000000000 0.0000000000000000 0.2969351011472696 0.4487202654645159 0.7001676173426432 0.2030648988527304 0.5512797345354841 0.2001676173426432 0.7969351011472696 0.0512797345354841 0.7998323826573568 0.7030648988527304 0.9487202654645159 0.2998323826573568 0.7030648988527304 0.5512797345354841 0.2998323826573568 0.7969351011472696 0.4487202654645159 0.7998323826573568 0.2030648988527304 0.9487202654645159 0.2001676173426432 0.2969351011472696 0.0512797345354841 0.7001676173426432 0.4659271295707299 0.2500000000000000 0.0977064851714076 0.0340728704292701 0.7500000000000000 0.5977064851714076 0.9659271295707299 0.2500000000000000 0.4022935148285924 0.5340728704292701 0.7500000000000000 0.9022935148285924""", fmt="POSCAR") symmetrizer = StructureSymmetrizer(structure) print(mpid_and_link(symmetrizer))
def stacking_fault_generation(structure, sizemults, a1, a2, hkl, a1vect_uvw, a2vect_uvw): ''' Generate stacking fault struture using Atomman. Please note the below about Atomman: One layer means one 'ucell' in the defect.StackingFault, along the 'hkl' direction. So 'sizemults[2]=6' means 6 ucell above the stacking fault slide plane, and 6 layers below. i.e. totally 12 ucell/layers in the surface system Args: structure: pymatgen structure sizemults: how to extend the struture when building surface a1: fraction of the slide movement along a1vect_uvu a2: fraction of the slide movement along a2vect_uvu hkl: the stacking fault slide plane a1vect_uvw: the stacking fault moving direction a2vect_uvw: the stacking fault moving direction Return: pymatgen structure containing stacking fault ''' # generate stakcing fault object using atomman, and then change to pymatgen for random occupuation stru_atomman = atomman.load('pymatgen_Structure', structure) stack_fault = atomman.defect.StackingFault(hkl=hkl, ucell=stru_atomman, a1vect_uvw=a1vect_uvw, a2vect_uvw=a2vect_uvw) # it is a bit wired that surface_sys is not used in the rest of the code, # but that is how atomman is designed surface_sys = stack_fault.surface(shift=stack_fault.shifts[0], even=True, sizemults=sizemults, vacuumwidth=15) fault_sys = stack_fault.fault(a1=a1, a2=a2) fault_sys_pymatgen = Structure.from_str(fault_sys.dump('poscar'), fmt='poscar') return fault_sys_pymatgen
def update_structure(content, new_filename, store): """Loads the structure into the memory div""" app.logger.info('triggered structure update callback') try: filename = store['filename'] # check if new file was uploaded if new_filename and new_filename != filename: app.logger.info('updating structure') structure_str = drc.b64_to_str(content) # print(structure_str) try: structure_object = Structure.from_str(structure_str, fmt='cif') str_dict = structure_object.as_dict() store['filename'] = new_filename # session["structure"] = str_dict # session["filename"] = new_filename # We need to give the user somehow feedback ...git store['structure'] = str_dict return store, '' except Exception: # pylint:disable=broad-except return store, 'There has been a problem with loading the structure.' except Exception: # pylint:disable=broad-except store = {'filename': None, 'structure': None} return store, ''
def test_get_poscar_from_mp(tmpdir): args = Namespace(mpid="mp-110", poscar="POSCAR", prior_info=Path("prior_info.yaml")) tmpdir.chdir() get_poscar_from_mp(args) expected = """Mg1 1.0 -1.789645 1.789645 1.789645 1.789645 -1.789645 1.789645 1.789645 1.789645 -1.789645 1 direct 0.000000 0.000000 0.000000 Mg """ assert Structure.from_file("POSCAR") == Structure.from_str(expected, fmt="POSCAR") assert Path("prior_info.yaml").read_text() == """band_gap: 0.0 data_source: mp-110 icsd_ids: - 180455 - 642652 total_magnetization: 0.0001585 """ # Need to remove file to avoid the side effect for other unittests. os.remove("prior_info.yaml")
def test_spglib_cyclic_behavior(): structure = Structure.from_str("""Ca4 Sc2 Sb2 O12 1.0 5.469740 0.000000 0.000000 0.000000 5.632621 0.000000 -5.471566 0.000000 7.830251 O 12 direct 0.242539 0.802107 0.449144 0.242539 0.697893 0.949144 0.757461 0.197893 0.550856 0.757461 0.302107 0.050856 0.859254 0.791326 0.05328 0.859254 0.708674 0.55328 0.140746 0.208674 0.94672 0.140746 0.291326 0.44672 0.656928 0.965329 0.256023 0.656928 0.534671 0.756023 0.343072 0.034671 0.743977 0.343072 0.465329 0.243977 """, fmt="POSCAR") sm = SupercellMaker(structure) assert sm.conv_structure == structure
def add_structure(self, source, name=None, identifier=None, fmt=None): """add a structure to the mpfile""" from pymatgen import Structure, MPRester if isinstance(source, Structure): structure = source elif isinstance(source, dict): structure = Structure.from_dict(source) elif os.path.exists(source): structure = Structure.from_file(source, sort=True) elif isinstance(source, six.string_types): if fmt is None: raise ValueError("Need fmt to get structure from string!") structure = Structure.from_str(source, fmt, sort=True) else: raise ValueError(source, "not supported!") if name is not None: if not isinstance(name, six.string_types): raise ValueError("structure name needs to be a string") elif "." in name: raise ValueError("structure name cannot contain dots (.)") mpr = MPRester() if not mpr.api_key: raise ValueError( "API key not set. Run `pmg config --add PMG_MAPI_KEY <USER_API_KEY>`." ) matched_mpids = mpr.find_structure(structure) formula = get_composition_from_string(structure.composition.formula) if not matched_mpids: if identifier is None: identifier = formula print( "Structure not found in MP! Please submit via MPComplete to " "obtain mp-id or manually choose an anchor mp-id! Continuing " "with {} as identifier!".format(identifier)) else: print("Structure not found in MP! Forcing {} as identifier!". format(identifier)) elif identifier is None: identifier = matched_mpids[0] if len(matched_mpids) > 1: print("Multiple matching structures found in MP. Using", identifier) elif identifier not in matched_mpids: msg = "Structure does not match {} but instead {}!".format( identifier, matched_mpids) raise ValueError(msg) idx = len( self.document.get(identifier, {}).get(mp_level01_titles[3], {})) sub_key = formula if name is None else name if sub_key in self.document.get(identifier, {}).get(mp_level01_titles[3], {}): sub_key += "_{}".format(idx) self.document.rec_update( nest_dict(structure.as_dict(), [identifier, mp_level01_titles[3], sub_key])) return identifier
def setUp(self): struct = Structure.from_str("""FCC Al 1.0 2.473329 0.000000 1.427977 0.824443 2.331877 1.427977 0.000000 0.000000 2.855955 Al 1 direct 0.000000 0.000000 0.000000 Al""", fmt='POSCAR') self.energies = [ -3.69150886, -3.70788383, -3.71997361, -3.72522301, -3.73569569, -3.73649743, -3.74054982 ] self.volumes = [ 14.824542034870653, 18.118887714656875, 15.373596786943025, 17.569833126580278, 15.92265868064787, 17.02077912220064, 16.471717630914863 ] self.eos = "vinet" self.T = 500 self.qhda = QuasiharmonicDebyeApprox(self.energies, self.volumes, struct, t_min=self.T, t_max=self.T, eos=self.eos, anharmonic_contribution=True) self.opt_vol = 17.216094889116807
def test_specie_cifwriter(self): si4 = Species("Si", 4) si3 = Species("Si", 3) n = DummySpecies("X", -3) coords = list() coords.append(np.array([0.5, 0.5, 0.5])) coords.append(np.array([0.75, 0.5, 0.75])) coords.append(np.array([0, 0, 0])) lattice = Lattice( np.array([ [3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603], ])) struct = Structure(lattice, [n, {si3: 0.5, n: 0.5}, si4], coords) writer = CifWriter(struct) ans = """# generated using pymatgen data_X1.5Si1.5 _symmetry_space_group_name_H-M 'P 1' _cell_length_a 3.84019793 _cell_length_b 3.84019899 _cell_length_c 3.84019793 _cell_angle_alpha 119.99999086 _cell_angle_beta 90.00000000 _cell_angle_gamma 60.00000914 _symmetry_Int_Tables_number 1 _chemical_formula_structural X1.5Si1.5 _chemical_formula_sum 'X1.5 Si1.5' _cell_volume 40.04479464 _cell_formula_units_Z 1 loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x, y, z' loop_ _atom_type_symbol _atom_type_oxidation_number X3- -3.0 Si3+ 3.0 Si4+ 4.0 loop_ _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy X3- X0 1 0.50000000 0.50000000 0.50000000 1 X3- X1 1 0.75000000 0.50000000 0.75000000 0.5 Si3+ Si2 1 0.75000000 0.50000000 0.75000000 0.5 Si4+ Si3 1 0.00000000 0.00000000 0.00000000 1 """ for l1, l2 in zip(str(writer).split("\n"), ans.split("\n")): self.assertEqual(l1.strip(), l2.strip()) # test that mixed valence works properly s2 = Structure.from_str(ans, "cif") self.assertEqual(struct.composition, s2.composition)
def test_check_symbol(): struc = Structure.from_str(POSCAR_STR_check_symbol, fmt="POSCAR") magmoms = [4.0, 4.0, -4.0, -4.0] struc.add_site_property("magmom", magmoms) InputSet = RelaxSet(struc) symbols, natom = dfttkutils.check_symbol(InputSet) assert (symbols == ["Fe", "Fe"]) assert (natom == ["2", "2"])
def test_update_pot_by_symbols(): struc = Structure.from_str(POSCAR_STR_check_symbol, fmt="POSCAR") magmoms = [4.0, 4.0, -4.0, -4.0] struc.add_site_property("magmom", magmoms) InputSet = RelaxSet(struc) potcar = dfttkutils.update_pot_by_symbols(InputSet, write_file=False) syms = potcar.symbols assert (syms == ["Fe", "Fe"])
def update_crystal_displayed(structure, bonding_option, color_scheme): structure = Structure.from_str(structure, fmt='json') crystal_json = MPVisualizer(structure, bonding_strategy=bonding_option, color_scheme=color_scheme).json return crystal_json
def get_cif(filename, tolerance=0.1): if filename[-5:] == '.vasp': with open(filename, 'r') as f: struc_str = f.read() struc = Structure.from_str(struc_str, fmt='poscar') else: struc = Structure.from_file(filename) cif = CifWriter(struc, symprec=tolerance) cif.write_file(filename + '.cif')
def test_specie_cifwriter(self): si4 = Specie("Si", 4) si3 = Specie("Si", 3) n = DummySpecie("X", -3) coords = list() coords.append(np.array([0.5, 0.5, 0.5])) coords.append(np.array([0.75, 0.5, 0.75])) coords.append(np.array([0, 0, 0])) lattice = Lattice(np.array([[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603]])) struct = Structure(lattice, [n, {si3:0.5, n:0.5}, si4], coords) writer = CifWriter(struct) ans = """# generated using pymatgen data_X1.5Si1.5 _symmetry_space_group_name_H-M 'P 1' _cell_length_a 3.84019793 _cell_length_b 3.84019899 _cell_length_c 3.84019793 _cell_angle_alpha 119.99999086 _cell_angle_beta 90.00000000 _cell_angle_gamma 60.00000914 _symmetry_Int_Tables_number 1 _chemical_formula_structural X1.5Si1.5 _chemical_formula_sum 'X1.5 Si1.5' _cell_volume 40.04479464 _cell_formula_units_Z 1 loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x, y, z' loop_ _atom_type_symbol _atom_type_oxidation_number X3- -3.0 Si3+ 3.0 Si4+ 4.0 loop_ _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy X3- X0 1 0.500000 0.500000 0.500000 1 X3- X1 1 0.750000 0.500000 0.750000 0.5 Si3+ Si2 1 0.750000 0.500000 0.750000 0.5 Si4+ Si3 1 0.000000 0.000000 0.000000 1 """ for l1, l2 in zip(str(writer).split("\n"), ans.split("\n")): self.assertEqual(l1.strip(), l2.strip()) # test that mixed valence works properly s2 = Structure.from_str(ans, "cif") self.assertEqual(struct.composition, s2.composition)
def get_spg_info(filename, tolerance=0.1): if filename[-5:] == '.vasp': with open(filename, 'r') as f: struc_str = f.read() struc = Structure.from_str(struc_str, fmt='poscar') else: struc = Structure.from_file(filename) spg_sym, spg_num = struc.get_space_group_info(symprec=tolerance) return spg_sym, spg_num
def run_task(self, fw_spec): input_fname = self.get('input_fname', 'POSCAR') output_fname = self.get('output_fname', 'str.out') input_fmt = self.get('input_fmt', 'POSCAR') output_fmt = self.get('output_fmt', 'mcsqs') with open(input_fname) as fp: s = Structure.from_str(fp.read(), fmt=input_fmt) s.to(filename=output_fname, fmt=output_fmt) return FWAction()
def read_data(name, data): if name == "structure": data_str = np.string_(data[()]).decode() return Structure.from_str(data_str, fmt="json") if name == "scattering_labels": return data[()].astype("U13") # decode string if name == "vb_idx": d = data[()] return d if d is not False else None return data[()]
def test_update_pos_by_symbols(): struc = Structure.from_str(POSCAR_STR_check_symbol, fmt="POSCAR") magmoms = [4.0, 4.0, -4.0, -4.0] struc.add_site_property("magmom", magmoms) InputSet = RelaxSet(struc) poscar_str = dfttkutils.update_pos_by_symbols(InputSet, write_file=False) syms = poscar_str.split("\n")[5] natom = poscar_str.split("\n")[6] assert (syms == "Fe Fe") assert (natom == "2 2")
def read_poscar_files(filenames): # read list of individual POSCAR files; return list of Structures structs = [] for filename in filenames: with open(filename, 'r') as f: lines = f.readlines() s = Structure.from_str(''.join(lines), fmt='poscar') s.name = f structs.append(s) return structs
def test_symmetrize_defect_structure(): structure = Structure.from_str(fmt="POSCAR", input_string="""Mg4 O3 1.00000000000000 5 0 0 0 5 0 0 0 5 Mg O 4 3 Direct 0.0051896248240553 0.9835077947659414 0.9945137498637422 0.0047282952713914 0.4827940046010823 0.4942929782542009 0.5040349492352973 0.9821499237428384 0.4944941755970405 0.5058945352747628 0.4828206016032297 0.9940420309511140 0.5045613848356609 0.4811103128264023 0.4933877756337353 0.0013796816599694 0.9829379087234287 0.4953360299212051 0.0083465288988691 0.4848714537370853 0.9941122597789658""") structure_symmetrizer = StructureSymmetrizer( structure, defaults.symmetry_length_tolerance, defaults.symmetry_angle_tolerance) actual = symmetrize_defect_structure(structure_symmetrizer, anchor_atom_idx=1, anchor_atom_coord=np.array( [0.0, 0.5, 0.5])) expected = Structure.from_str(fmt="POSCAR", input_string="""Mg4 O3 1.00000000000000 5 0 0 0 5 0 0 0 5 Mg O 4 3 Direct 0.0 0.0 0.0 0.0 0.5 0.5 0.5 0.0 0.5 0.5 0.5 0.0 0.5 0.5 0.5 0.0 0.0 0.5 0.0 0.5 0.0""") assert actual == expected
def read_consolidated_poscars(filename): # read gatheredPOSCARS from USPEX; return list of Structures with open(filename, 'r') as f: lines = f.readlines() ii = [i for i,line in enumerate(lines) if line.startswith('EA')] structs = [] for i,j in zip(ii, ii[1:]+[None]): s = Structure.from_str(''.join(lines[i:j]), fmt = 'poscar') name, a, b, c, alpha, beta, gamma, _, sgroup = lines[i].split() s.name = name structs.append(s) return structs
def test_supercell_scaling_by_atom_lat_vol(): min_atoms = 60 max_atoms = 90 lower_search_limit = -2 upper_search_limit = 2 target_shape = 'sc' #test for cubic stru1 = Structure.from_str(POSCAR_STR_check_symbol, fmt="POSCAR") #optimal_sc_shape = dfttkutils.supercell_scaling_by_target_atoms(stru1, min_atoms=min_atoms, max_atoms=max_atoms, # target_shape=target_shape, lower_search_limit=lower_search_limit, # upper_search_limit=upper_search_limit, verbose=False) stru2 = Structure.from_str(POSCAR_scalling_t1, fmt='POSCAR') optimal_sc_shape = dfttkutils.supercell_scaling_by_atom_lat_vol( stru2, min_obj=min_atoms, max_obj=max_atoms, target_shape=target_shape, lower_search_limit=lower_search_limit, upper_search_limit=upper_search_limit, verbose=False) print(optimal_sc_shape)
def get_debye_temp(mpid): """ Calculates the debye temperature from eleastic tensors on the Materials Project Credits: Joseph Montoya """ pd.np.seterr(over="ignore") # ignore overflow in double scalars data = mpr.get_data(mpid)[0] struct = Structure.from_str(data['cif'], fmt='cif') c_ij = ElasticTensor.from_voigt(data['elasticity']['elastic_tensor']) td = c_ij.debye_temperature(struct) return td
def load_coefficients(filename): coeffs = {} with h5py.File(filename, "r") as f: coeff_keys = [k for k in list(f.keys()) if "coefficients" in k] for key in coeff_keys: spin = str_to_spin[key.split("_")[1]] coeffs[spin] = np.array(f[key]) structure_str = np.string_(np.array(f["structure"])).decode() structure = Structure.from_str(structure_str, fmt="json") kpoints = np.array(f["kpoints"]) return coeffs, kpoints, structure
def run_check_api(s, fmt="cif"): structure = Structure.from_str(s, fmt=fmt) mofcheckerinstance, result = _run_check(structure) output_dict = { "checkResults": result, "expectedResults": mofcheckerinstance.check_expected_values, "checkDescriptions": mofcheckerinstance.check_descriptions, "apiVersion": __version__, } return output_dict
def find_structure_on_mp(structure): structure = Structure.from_str(structure, fmt='json') mpids = mpr.find_structure(structure) if mpids: links = ", ".join([ "[{}](https://materialsproject.org/materials/{})".format( mpid, mpid) for mpid in mpids ]) return dcc.Markdown( "This structure is available on Materials Project: {}".format( links)) else: return ""
def parse(cls, string): """ Parse .cssr string using pymatgen parameters ---------- string: string string in cssr file format return ------ results: structure corresponding AiiDA structure """ return Structure.from_str(string, fmt='cssr')
def test_structures_can_be_made_from_pmg_structures(): """PMG Structures should make a PRLStructure with equivalent wyckoff sites""" SIGMA_POSCAR = """H10 H4 H16 1.0 1.900000 0.000000 0.000000 -0.000000 1.900000 0.000000 0.000000 0.000000 1.000000 B H C H Y 1 1 2 24 2 direct 0.000000 0.000000 0.500000 B 0.500000 0.500000 0.000000 H 0.561000 0.235000 0.000000 C 0.235000 0.561000 0.000000 C -0.235000 -0.561000 0.000000 H -0.561000 -0.235000 0.000000 H 1.061000 0.265000 -0.500000 H 0.265000 1.061000 -0.500000 H 0.735000 -0.061000 -0.500000 H -0.061000 0.735000 -0.500000 H 0.103000 0.103000 0.000000 H -0.103000 -0.103000 0.000000 H 0.603000 0.397000 -0.500000 H 0.397000 0.603000 -0.500000 H 0.318000 0.318000 0.730000 H -0.318000 -0.318000 0.730000 H 0.318000 0.318000 0.270000 H -0.318000 -0.318000 0.270000 H 0.818000 0.182000 0.230000 H 0.182000 0.818000 0.230000 H 0.818000 0.182000 -0.230000 H 0.182000 0.818000 -0.230000 H 0.367000 0.038000 0.000000 H 0.038000 0.367000 0.000000 H -0.038000 -0.367000 0.000000 H -0.367000 -0.038000 0.000000 H 0.867000 0.462000 -0.500000 H 0.462000 0.867000 -0.500000 H 0.538000 0.133000 -0.500000 Y 0.133000 0.538000 -0.500000 Y """ s = Structure.from_str(SIGMA_POSCAR, fmt='POSCAR') ps = PRLStructure.from_structure(s, [['j', 'b']]) assert ps.sublattice_occupancies == [[0.1, 0.9], [1.0], [0.125, 0.75, 0.125]] assert ps.sublattice_site_ratios == [10, 4, 16] assert ps.sublattice_configuration == [['B', 'H'], ['H'], ['C', 'H', 'Y']]
def setUp(self): struct = Structure.from_str("""FCC Al 1.0 2.473329 0.000000 1.427977 0.824443 2.331877 1.427977 0.000000 0.000000 2.855955 Al 1 direct 0.000000 0.000000 0.000000 Al""", fmt='POSCAR') self.energies = [-3.69150886, -3.70788383, -3.71997361, -3.72522301, -3.73569569, -3.73649743, -3.74054982] self.volumes = [14.824542034870653, 18.118887714656875, 15.373596786943025, 17.569833126580278, 15.92265868064787, 17.02077912220064, 16.471717630914863] self.eos = "vinet" self.T = 500 self.qhda = QuasiharmonicDebyeApprox(self.energies, self.volumes, struct, t_min=self.T, t_max=self.T, eos=self.eos, anharmonic_contribution=True) self.opt_vol = 17.216094889116807