def test_from_structure_NPT(self): from pymatgen import Lattice, Structure coords1 = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) coords2 = np.array([[0.0, 0.0, 0.0], [0.6, 0.6, 0.6]]) coords3 = np.array([[0.0, 0.0, 0.0], [0.7, 0.7, 0.7]]) lattice1 = Lattice.from_parameters( a=2.0, b=2.0, c=2.0, alpha=90, beta=90, gamma=90 ) lattice2 = Lattice.from_parameters( a=2.1, b=2.1, c=2.1, alpha=90, beta=90, gamma=90 ) lattice3 = Lattice.from_parameters( a=2.0, b=2.0, c=2.0, alpha=90, beta=90, gamma=90 ) s1 = Structure(coords=coords1, lattice=lattice1, species=["F", "Li"]) s2 = Structure(coords=coords2, lattice=lattice2, species=["F", "Li"]) s3 = Structure(coords=coords3, lattice=lattice3, species=["F", "Li"]) structures = [s1, s2, s3] d = DiffusionAnalyzer.from_structures( structures, specie="Li", temperature=500.0, time_step=2.0, step_skip=1, smoothed=None, ) self.assertArrayAlmostEqual( d.disp[1], np.array([[0.0, 0.0, 0.0], [0.21, 0.21, 0.21], [0.40, 0.40, 0.40]]), )
def setUp(self): ## simple toy structure for preliminary testing self.a0 = 3.0 self.c = 20.0 self.structure = Structure( Lattice.from_parameters(a=self.a0, b=self.a0, c=self.c, alpha=90, beta=90, gamma=90), ["O","O"], [[0.0, 0.0, 0.1], [0.5, 0.5, 0.3]]) self.structure_rot = Structure( Lattice.from_parameters(a=self.a0, b=self.c, c=self.a0, alpha=90, beta=90, gamma=90), ["O","O"], [[0.0, 0.1, 0.0], [0.5, 0.3, 0.5]]) self.zaxis = 'b' self.structure_bulk = Structure( Lattice.from_parameters(a=self.a0, b=self.a0, c=self.c, alpha=90, beta=90, gamma=90), ["O","O","O","O"], [[0.0, 0.0, 0.15], [0.5, 0.5, 0.35], [0.0, 0.0, 0.65], [0.5, 0.5, 0.85]]) self.slabmin = 0.0 self.slabmax = 0.5
def test_aqueous_compat(self): el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) lioh_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '65e83282d1707ec078c1012afbd05be8'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7a25bc5b9a5393f46600a4939d357982'}, {"titel": 'PAW_PBE H 15Jun2001', 'hash': "bb43c666e3d36577264afe07669e9582"}]}) lioh_entry_compat = self.compat.process_entry(lioh_entry) lioh_entry_compat_aqcorr = self.aqcorr.correct_entry(lioh_entry_compat) lioh_entry_aqcompat = self.aqcompat.process_entry(lioh_entry) self.assertAlmostEqual(lioh_entry_compat_aqcorr.energy, lioh_entry_aqcompat.energy, 4)
def test___dr_ij(self): coords = np.array([[0.5, 0.5, 0.5], [0.0, 0.0, 0.0]]) atom_list = ['Na', 'Cl'] lattice = Lattice.from_parameters(a=4.0, b=4.0, c=4.0, alpha=90, beta=90, gamma=90) structure = Structure(lattice, atom_list, coords) mock_structures = [Mock(spec=Structure)] for s in mock_structures: s.lattice = Mock(spec=Lattice) s.lattice.volume = 1.0 indices_i = [0, 1] with patch( 'vasppy.rdf.RadialDistributionFunction._RadialDistributionFunction__dr_ij' ) as mock_dr_ij: rdf = RadialDistributionFunction(structures=mock_structures, indices_i=indices_i) rdf.self_reference = True np.testing.assert_array_almost_equal( rdf._RadialDistributionFunction__dr_ij(structure), np.array([3.46410162, 3.46410162])) rdf.self_reference = False np.testing.assert_array_almost_equal( np.sort(rdf._RadialDistributionFunction__dr_ij(structure)), np.array([0.0, 0.0, 3.46410162, 3.46410162])) rdf.indices_i = [0] rdf.indices_j = [1] np.testing.assert_array_almost_equal( rdf._RadialDistributionFunction__dr_ij(structure), np.array([3.46410162]))
def test_peroxide_energy_corr(self): latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510) el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o] coords = [[0.666656, 0.666705, 0.750001], [0.333342, 0.333378, 0.250001], [0.000001, 0.000041, 0.500001], [0.000001, 0.000021, 0.000001], [0.333347, 0.333332, 0.649191], [0.333322, 0.333353, 0.850803], [0.666666, 0.666686, 0.350813], [0.666665, 0.666684, 0.149189]] struct = Structure(latt, elts, coords) li2o2_entry = ComputedStructureEntry( struct, -3, parameters={ 'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Fe 06Sep2000', 'PAW_PBE O 08Apr2002'] }) li2o2_entry_corrected = self.compat.process_entry(li2o2_entry) self.assertRaises(AssertionError, self.assertAlmostEqual, *(li2o2_entry_corrected.energy, -3 - 0.44317 * 4, 4)) self.assertAlmostEqual(li2o2_entry_corrected.energy, -3 - 0.66975 * 4, 4)
def test_from_structure_NPT( self ): from pymatgen import Structure, Lattice coords1 = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]] ) coords2 = np.array([[0.0, 0.0, 0.0], [0.6, 0.6, 0.6]] ) coords3 = np.array([[0.0, 0.0, 0.0], [0.7, 0.7, 0.7]] ) lattice1 = Lattice.from_parameters(a=2.0, b=2.0, c=2.0, alpha=90, beta=90, gamma=90) lattice2 = Lattice.from_parameters(a=2.1, b=2.1, c=2.1, alpha=90, beta=90, gamma=90) lattice3 = Lattice.from_parameters(a=2.0, b=2.0, c=2.0, alpha=90, beta=90, gamma=90) s1 = Structure(coords=coords1, lattice=lattice1, species=['F', 'Li']) s2 = Structure(coords=coords2, lattice=lattice2, species=['F', 'Li']) s3 = Structure(coords=coords3, lattice=lattice3, species=['F', 'Li']) structures = [s1, s2, s3] d = DiffusionAnalyzer.from_structures( structures, specie='Li', temperature=500.0, time_step=2.0, step_skip=1, smoothed=None ) self.assertArrayAlmostEqual(d.disp[1], np.array([[0., 0., 0. ], [0.21, 0.21, 0.21], [0.40, 0.40, 0.40]]))
def test_aqueous_compat(self): el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) lioh_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '9658a0ffb28da97ee7b36709966a0d1c'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7af704ddff29da5354831c4609f1cbc5'}, {"titel": 'PAW_PBE H 15Jun2001', 'hash': "57732e53d8a424e5b3721d0277f14ef0"}]}) lioh_entry_compat = self.compat.process_entry(lioh_entry) lioh_entry_compat_aqcorr = self.aqcorr.correct_entry(lioh_entry_compat) lioh_entry_aqcompat = self.aqcompat.process_entry(lioh_entry) self.assertAlmostEqual(lioh_entry_compat_aqcorr.energy, lioh_entry_aqcompat.energy, 4)
def make_supercell(self, scaling_matrix): """ Create a supercell. Very similar to pymatgen's Structure.make_supercell However, we need to make sure that all fractional coordinates that equal to 1 will become 0 and the lattice are redefined so that x_c = [0, 0, c] Args: scaling_matrix (3x3 matrix): The scaling matrix to make supercell. """ s = self * scaling_matrix for i, site in enumerate(s): f_coords = np.mod(site.frac_coords, 1) # The following for loop is probably not necessary. But I will leave # it here for now. for j, v in enumerate(f_coords): if abs(v - 1) < 1e-6: f_coords[j] = 0 s[i] = PeriodicSite(site.specie, f_coords, site.lattice, properties=site.properties) self._sites = s.sites self._lattice = s.lattice new_lat = Lattice.from_parameters(*s.lattice.parameters) self.lattice = new_lat
def test_process_entry_peroxide(self): latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510) el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o] coords = [[0.666656, 0.666705, 0.750001], [0.333342, 0.333378, 0.250001], [0.000001, 0.000041, 0.500001], [0.000001, 0.000021, 0.000001], [0.333347, 0.333332, 0.649191], [0.333322, 0.333353, 0.850803], [0.666666, 0.666686, 0.350813], [0.666665, 0.666684, 0.149189]] struct = Structure(latt, elts, coords) li2o2_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '9658a0ffb28da97ee7b36709966a0d1c'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7af704ddff29da5354831c4609f1cbc5'}]}) li2o2_entry_corrected = self.compat.process_entry(li2o2_entry) self.assertAlmostEqual(li2o2_entry_corrected.energy, -3 - 0.44317 * 4, 4)
def test_aqueous_compat(self): el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) lioh_entry = ComputedStructureEntry(struct, -3, parameters={ 'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': [ 'PAW_PBE Fe 17Jan2003', 'PAW_PBE O 08Apr2002', 'PAW_PBE H 15Jun2001' ] }) lioh_entry_compat = self.compat.process_entry(lioh_entry) lioh_entry_compat_aqcorr = self.aqcorr.correct_entry(lioh_entry_compat) lioh_entry_aqcompat = self.aqcompat.process_entry(lioh_entry) self.assertAlmostEqual(lioh_entry_compat_aqcorr.energy, lioh_entry_aqcompat.energy, 4)
def supercell_matrix_from_structure(self, structure): if self.sm_type == 'pmg_sm': sc_matrix = self.sm.get_supercell_matrix(structure, self.structure) elif self.sm_type == 'an_frame': prim_an_sites = [site for site in self.structure if Is_Anion_Site(site)] prim_an = Structure.from_sites(prim_an_sites) s_an_fracs = [] s_an_sps = [] latt = structure.lattice for site in structure: if Is_Anion_Site(site): s_an_fracs.append(site.frac_coords) s_an_sps.append(site.specie) scaling = ((len(s_an_sps)/len(prim_an))/(structure.volume/self.structure.volume))**(1/3.0) s_an_latt = Lattice.from_parameters(latt.a * scaling, latt.b * scaling, latt.c * scaling, \ latt.alpha, latt.beta, latt.gamma) structure_an = Structure(s_an_latt,s_an_sps,s_an_fracs,to_unit_cell =False, coords_are_cartesian=False) #print('Structure:',structure) #print('Structure_an:',structure_an) #print('Prim_an:',prim_an) sc_matrix = self.sm.get_supercell_matrix(structure_an, prim_an) else: raise ValueError("Structure Matcher type not implemented!") if sc_matrix is None: raise ValueError("Supercell couldn't be found") if np.linalg.det(sc_matrix) < 0: sc_matrix *= -1 return sc_matrix
def test_peroxide_energy_corr(self): latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510) el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o] coords = [[0.666656, 0.666705, 0.750001], [0.333342, 0.333378, 0.250001], [0.000001, 0.000041, 0.500001], [0.000001, 0.000021, 0.000001], [0.333347, 0.333332, 0.649191], [0.333322, 0.333353, 0.850803], [0.666666, 0.666686, 0.350813], [0.666665, 0.666684, 0.149189]] struct = Structure(latt, elts, coords) li2o2_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '65e83282d1707ec078c1012afbd05be8'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7a25bc5b9a5393f46600a4939d357982'}]}) li2o2_entry_corrected = self.compat.process_entry(li2o2_entry) self.assertRaises(AssertionError, self.assertAlmostEqual, *(li2o2_entry_corrected.energy, -3 - 0.44317 * 4, 4)) self.assertAlmostEqual(li2o2_entry_corrected.energy, -3 - 0.66975 * 4, 4)
def test_unique_structure_substitutions_in_two_steps_gives_full_degeneracies( self ): # integration test # Create a pymatgen structure with 16 sites in a 4x4 square grid coords = np.array( [ [ 0.0, 0.0, 0.0 ], [ 0.25, 0.0, 0.0 ], [ 0.5, 0., 0.0 ], [ 0.75, 0.0, 0.0 ], [ 0.0, 0.25, 0.0 ], [ 0.25, 0.25, 0.0 ], [ 0.5, 0.25, 0.0 ], [ 0.75, 0.25, 0.0 ], [ 0.0, 0.5, 0.0 ], [ 0.25, 0.5, 0.0 ], [ 0.5, 0.5, 0.0 ], [ 0.75, 0.5, 0.0 ], [ 0.0, 0.75, 0.0 ], [ 0.25, 0.75, 0.0 ], [ 0.5, 0.75, 0.0 ], [ 0.75, 0.75, 0.0 ] ] ) atom_list = [ 'Li' ] * len( coords ) lattice = Lattice.from_parameters( a = 3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90 ) parent_structure = Structure( lattice, atom_list, coords ) us = unique_structure_substitutions( parent_structure, 'Li', { 'Na':1, 'Li':15 } ) ns = unique_structure_substitutions( us[0], 'Li', { 'Mg':1, 'Li':14 } ) self.assertEqual( len( ns ), 5 ) distances = np.array( sorted( [ s.get_distance( s.indices_from_symbol('Mg')[0], s.indices_from_symbol('Na')[0] ) for s in ns ] ) ) np.testing.assert_array_almost_equal( distances, np.array( [ 0.75 , 1.06066 , 1.5 , 1.677051, 2.12132 ] ) ) np.testing.assert_array_equal( np.array( sorted( [ s.number_of_equivalent_configurations for s in ns ] ) ), np.array( [ 1, 2, 4, 4, 4 ] ) ) np.testing.assert_array_equal( np.array( sorted( [ s.full_configuration_degeneracy for s in ns ] ) ), np.array( [ 16, 32, 64, 64, 64 ] ) )
def get_matched_structure_mapping(base: Structure, inserted: Structure, sm: StructureMatcher): """ Get the mapping from the inserted structure onto the base structure, assuming that the inserted structure sans the working ion is some kind of SC of the base. Args: base: host structure, smaller cell inserted: bigger cell sm: StructureMatcher instance Returns: sc_m : supercell matrix to apply to s1 to get s2 total-t : translation to apply on s1 * sc_m to get s2 """ s1, s2 = sm._process_species([base, inserted]) fu, _ = sm._get_supercell_size(s1, s2) try: val, dist, sc_m, total_t, mapping = sm._strict_match(s1, s2, fu=fu, s1_supercell=True) except TypeError: return None sc = s1 * sc_m sc.lattice = Lattice.from_parameters(*sc.lattice.abc, *sc.lattice.angles, vesta=True) return sc_m, total_t
def build_gb(self, vacuum=0.0, add_if_dist=0.0, to_primitive=True, delete_layer="0b0t0b0t", tol=0.25): """ Build the GB based on the given crystal, uc of grain A and B, if_model, vacuum thickness, distance between two grains and tolerance factor. Args: vacuum (float), Angstrom: Vacuum thickness for GB. Default to 0.0 add_if_dist (float), Angstrom: Add extra distance at the interface between two grains. Default to 0.0 to_primitive (bool): Whether to get primitive structure of GB. Default to true. delete_layer (str): Delete interface layers on both sides of each grain. 8 characters in total. The first 4 characters is for grain A and the other 4 is for grain B. "b" means bottom layer and "t" means top layer. Integer represents the number of layers to be deleted. Default to "0b0t0b0t", which means no deletion of layers. The direction of top and bottom layers is based on gb_direction. tol (float), Angstrom: Tolerance factor to determine whether two atoms are at the same plane. Default to 0.25 Returns: GB structure (Grain) """ ind = self.gb_direction delete_layer = delete_layer.lower() delete = re.findall('(\d+)(\w)', delete_layer) if len(delete) != 4: raise ValueError("'%s' is not supported. Please make sure the format " "is 0b0t0b0t.") for i, v in enumerate(delete): for j in range(int(v[0])): if i <= 1: self.grain_a.delete_bt_layer(v[1], tol, ind) else: self.grain_b.delete_bt_layer(v[1], tol, ind) abc_a = list(self.grain_a.lattice.abc) abc_b, angles = np.reshape(self.grain_b.lattice.parameters, (2, 3)) if ind == 1: l = (abc_a[ind] + add_if_dist) * sin(radians(angles[2])) else: l = abc_a[ind] + add_if_dist abc_a[ind] += abc_b[ind] + 2 * add_if_dist + vacuum new_lat = Lattice.from_parameters(*abc_a, *angles) a_fcoords = new_lat.get_fractional_coords(self.grain_a.cart_coords) grain_a = Grain(new_lat, self.grain_a.species, a_fcoords) l_vector = [0, 0] l_vector.insert(ind, l) b_fcoords = new_lat.get_fractional_coords( self.grain_b.cart_coords + l_vector) grain_b = Grain(new_lat, self.grain_b.species, b_fcoords) gb = Grain.from_sites(grain_a[:] + grain_b[:]) gb = gb.get_sorted_structure() if to_primitive: gb = gb.get_primitive_structure() return gb
def from_string(header_str): """ Reads Header string and returns Header object if header was generated by pymatgen. Note: Checks to see if generated by pymatgen, if not it is impossible to generate structure object so it is not possible to generate header object and routine ends Args: header_str: pymatgen generated feff.inp header Returns: Structure object. """ lines = tuple(clean_lines(header_str.split("\n"), False)) comment1 = lines[0] feffpmg = comment1.find("pymatgen") if feffpmg == -1: feffpmg = False if feffpmg: comment2 = ' '.join(lines[1].split()[2:]) source = ' '.join(lines[2].split()[2:]) basis_vec = lines[6].split(":")[-1].split() # a, b, c a = float(basis_vec[0]) b = float(basis_vec[1]) c = float(basis_vec[2]) lengths = [a, b, c] # alpha, beta, gamma basis_ang = lines[7].split(":")[-1].split() alpha = float(basis_ang[0]) beta = float(basis_ang[1]) gamma = float(basis_ang[2]) angles = [alpha, beta, gamma] lattice = Lattice.from_parameters(*lengths, *angles) natoms = int(lines[8].split(":")[-1].split()[0]) atomic_symbols = [] for i in range(9, 9 + natoms): atomic_symbols.append(lines[i].split()[2]) # read the atomic coordinates coords = [] for i in range(natoms): toks = lines[i + 9].split() coords.append([float(s) for s in toks[3:]]) struct = Structure(lattice, atomic_symbols, coords, False, False, False) h = Header(struct, source, comment2) return h raise ValueError( "Header not generated by pymatgen, cannot return header object")
def setUp(self): coords = np.array([[0.5, 0.5, 0.5]]) atom_list = ['S'] lattice = Lattice.from_parameters(a=1.0, b=1.0, c=1.0, alpha=90, beta=90, gamma=90) self.structure = Structure(lattice, atom_list, coords)
def test_rdf_coordination_number(self): # create a simple cubic lattice coords = np.array([[0.5, 0.5, 0.5]]) atom_list = ['S'] lattice = Lattice.from_parameters(a=1.0, b=1.0, c=1.0, alpha=90, beta=90, gamma=90) structure = Structure(lattice, atom_list, coords) rdf = RadialDistributionFunction.from_species( structures=[structure], species=['S'], rmax=5.0, sigma=0.1, ngrid=500) self.assertEqual(rdf.coordination_number[100], 6.0)
def setUp(self): ## SnS unitcell self.a0 = 4.442511 self.a1 = 4.023972 self.c = 11.432652 self.structure = Structure( Lattice.from_parameters(a=self.a0, b=self.a1, c=self.c, alpha=90, beta=90, gamma=90), ["Sn","Sn","S","S"], [[0.873976, 0.250000, 0.121238], [0.373976, 0.750000, 0.378762], [0.480133, 0.750000, 0.150170], [0.980133, 0.250000, 0.349830]]) self.structure_rot = Structure( Lattice.from_parameters(a=self.c, b=self.a1, c=self.a0, alpha=90, beta=90, gamma=90), ["Sn","Sn","S","S"], [[0.121238, 0.250000, 0.126024], [0.378762, 0.750000, 0.626024], [0.150170, 0.750000, 0.519867], [0.349830, 0.250000, 0.019867]]) self.zaxis = 'a' self.structure_bulk = Structure( Lattice.from_parameters(a=self.a0, b=self.a1, c=self.c, alpha=90, beta=90, gamma=90), ["Sn","Sn","Sn","Sn","S","S","S","S"], [[0.873976, 0.250000, 0.121238], [0.126024, 0.750000, 0.878762], [0.373976, 0.750000, 0.378762], [0.626024, 0.250000, 0.621238], [0.480133, 0.750000, 0.150170], [0.519867, 0.250000, 0.849830], [0.980133, 0.250000, 0.349830], [0.019867, 0.750000, 0.650170]]) self.slabmin = 0.0 self.slabmax = 0.5
def test_unique_symmetry_operations_as_vectors_from_structure_hex( self ): # integration test coords = np.array( [ [ 0.666667, 0.333334, 0.498928 ], [ 0.333334, 0.666667, 0.998928 ], [ 0.666667, 0.333334, 0.876081 ], [ 0.333334, 0.666667, 0.376081 ] ] ) atom_list = [ 'Zn' ] * 2 + [ 'O' ] * 2 lattice = Lattice.from_parameters( a=2.0, b=2.0, c=3.265986324, alpha=90, beta=90, gamma=120 ) structure = Structure( lattice, atom_list, coords ) mappings = unique_symmetry_operations_as_vectors_from_structure( structure, verbose=False ) self.assertEqual( len( mappings ), 2 ) for l in [ [ 1, 2, 3, 4 ], [ 2, 1, 4, 3 ] ]: self.assertEqual( l in mappings, True )
def setUp(self): ## hexagonal WSe2 unitcell self.a0 = 3.325612 self.c = 17.527085 self.structure = Structure( Lattice.from_parameters(a=self.a0, b=self.a0, c=self.c, alpha=90, beta=90, gamma=120), ["W","Se","Se"], [[0.0, 0.0, 0.0], [0.333333, 0.666667, 0.095876], [0.333333, 0.666667, 0.904124]]) self.structure_rot = Structure( Lattice.from_parameters(a=self.c, b=self.a0, c=self.a0, alpha=60, beta=90, gamma=90), ["W","Se","Se"], [[0.0, 0.0, 0.0], [0.095876, 0.666667, -0.333333], [0.904124, 0.666667, -0.333333]]) self.zaxis = 'a' self.structure_bulk = Structure( Lattice.from_parameters(a=self.a0, b=self.a0, c=self.c, alpha=90, beta=90, gamma=120), ["W","W","Se","Se","Se","Se"], [[0.0, 0.0, 0.75], [0.333333, 0.666667, 0.25], [0.0, 0.0, 0.345876], [0.333333, 0.666667, 0.845876], [0.333333, 0.666667, 0.654124], [0.0, 0.0, 0.154124]]) self.slabmin = 0.5 self.slabmax = 1.0
def test_matching_sites_with_species( self ): # construct a pymatgen Structure instance using the site fractional coordinates # face-centered cubic lattice coords = np.array( [ [ 0.0, 0.0, 0.0 ], [ 0.5, 0.5, 0.0 ], [ 0.0, 0.5, 0.5 ], [ 0.5, 0.0, 0.5 ] ] ) atom_list = [ 'Li', 'Mg', 'Mg', 'Mg' ] lattice = Lattice.from_parameters( a=3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90 ) structure = Structure( lattice, atom_list, coords ) ref_coords = np.array( [ [ 0.1, 0.1, 0.1 ], [ 0.0, 0.4, 0.5 ] ] ) ref_atom_list = [ 'Na' ] * len( ref_coords ) ref_structure = Structure( lattice, ref_atom_list, ref_coords ) matched_sites = matching_sites( structure, ref_structure, species=['Li'] ) self.assertEqual( len( matched_sites ), 1 ) self.assertEqual( matched_sites[0], [ structure[0], 0 ] )
def test_oxide_energy_corr(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_o] latt = Lattice.from_parameters(3.278, 3.278, 3.278, 60, 60, 60) coords = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75], [0.0, 0.0, 0.0]] struct = Structure(latt, elts, coords) li2o_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Fe 06Sep2000', 'PAW_PBE O 08Apr2002']}) li2o_entry_corrected = self.compat.process_entry(li2o_entry) self.assertAlmostEqual(li2o_entry_corrected.energy, -3.0 -0.66975, 4)
def test_oxide_energy_corr(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_o] latt = Lattice.from_parameters(3.278, 3.278, 3.278, 60, 60, 60) coords = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75], [0.0, 0.0, 0.0]] struct = Structure(latt, elts, coords) li2o_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Li 06Sep2000', 'PAW_PBE O 08Apr2002']}) li2o_entry_corrected = self.compat.process_entry(li2o_entry) self.assertAlmostEqual(li2o_entry_corrected.energy, -3.0 -0.66975, 4)
def test_unique_symmetry_operations_as_vectors_from_structure_hex(self): # integration test coords = np.array([[0.666667, 0.333334, 0.498928], [0.333334, 0.666667, 0.998928], [0.666667, 0.333334, 0.876081], [0.333334, 0.666667, 0.376081]]) atom_list = ['Zn'] * 2 + ['O'] * 2 lattice = Lattice.from_parameters(a=2.0, b=2.0, c=3.265986324, alpha=90, beta=90, gamma=120) structure = Structure(lattice, atom_list, coords) mappings = unique_symmetry_operations_as_vectors_from_structure( structure, verbose=False) self.assertEqual(len(mappings), 2) for l in [[1, 2, 3, 4], [2, 1, 4, 3]]: self.assertEqual(l in mappings, True)
def test_ozonide(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_o, el_o, el_o] latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342) coords = [[0.513004, 0.513004, 1.000000], [0.017616, 0.017616, 0.000000], [0.649993, 0.874790, 0.775203], [0.099587, 0.874790, 0.224797]] struct = Structure(latt, elts, coords) lio3_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Li 06Sep2000', 'PAW_PBE O 08Apr2002']}) lio3_entry_corrected = self.compat.process_entry(lio3_entry) self.assertAlmostEqual(lio3_entry_corrected.energy, -3.0 - 3 * 0.66975)
def setUp( self ): # construct a pymatgen Structure instance using the site fractional coordinates # face-centered cubic lattice coords = np.array( [ [ 0.0, 0.0, 0.0 ], [ 0.5, 0.5, 0.0 ], [ 0.0, 0.5, 0.5 ], [ 0.5, 0.0, 0.5 ] ] ) atom_list = [ 'Li' ] * len( coords ) lattice = Lattice.from_parameters( a=3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90 ) self.structure = Structure( lattice, atom_list, coords ) # construct a pymatgen Molecule instance # square molecule (D4h) m_coords = np.array( [ [ 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 1.0, 1.0, 0.0 ] ] ) molecule = Molecule( atom_list, m_coords ) molecule = Molecule( molecule.species, molecule.cart_coords - molecule.center_of_mass ) self.molecule = molecule
def test_ozonide(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_o, el_o, el_o] latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342) coords = [[0.513004, 0.513004, 1.000000], [0.017616, 0.017616, 0.000000], [0.649993, 0.874790, 0.775203], [0.099587, 0.874790, 0.224797]] struct = Structure(latt, elts, coords) lio3_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Fe 06Sep2000', 'PAW_PBE O 08Apr2002']}) lio3_entry_corrected = self.compat.process_entry(lio3_entry) self.assertAlmostEqual(lio3_entry_corrected.energy, -3.0 - 3 * 0.66975)
def test_rdf_two_species_coordination_number(self): # create a structure with interpenetrating simple cubic lattice coords = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) atom_list = ["S", "Zn"] lattice = Lattice.from_parameters(a=1.0, b=1.0, c=1.0, alpha=90, beta=90, gamma=90) structure = Structure(lattice, atom_list, coords) rdf = RadialDistributionFunction.from_species( structures=[structure], species=["S"], reference_species=["Zn"], rmax=5.0, sigma=0.1, ngrid=500, ) self.assertEqual(rdf.coordination_number[100], 8.0)
def getSuperCell(): from pymatgen import Lattice, Structure, Molecule la = 1 lb = 1 lc = 1 coords = [[0, 0, 0], [0.5, 0, 0.5]] lattice = Lattice.from_parameters(a=la, b=lb, c=lc, alpha=90, beta=90, gamma=90) struct = Structure(lattice, ["Co", "Co"], coords) # saving the primitive cell into a POSCAR (it'll have DIRECT/FRACTION coordinates) new_structure.to(fmt='poscar', filename='POSCAR_Li22Sn5_primitive') return atomPositions
def test_unique_structure_substitutions_in_two_steps_gives_full_degeneracies( self): # integration test # Create a pymatgen structure with 16 sites in a 4x4 square grid coords = np.array([[0.0, 0.0, 0.0], [0.25, 0.0, 0.0], [0.5, 0., 0.0], [0.75, 0.0, 0.0], [0.0, 0.25, 0.0], [0.25, 0.25, 0.0], [0.5, 0.25, 0.0], [0.75, 0.25, 0.0], [0.0, 0.5, 0.0], [0.25, 0.5, 0.0], [0.5, 0.5, 0.0], [0.75, 0.5, 0.0], [0.0, 0.75, 0.0], [0.25, 0.75, 0.0], [0.5, 0.75, 0.0], [0.75, 0.75, 0.0]]) atom_list = ['Li'] * len(coords) lattice = Lattice.from_parameters(a=3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90) parent_structure = Structure(lattice, atom_list, coords) us = unique_structure_substitutions(parent_structure, 'Li', { 'Na': 1, 'Li': 15 }) ns = unique_structure_substitutions(us[0], 'Li', {'Mg': 1, 'Li': 14}) self.assertEqual(len(ns), 5) distances = np.array( sorted([ s.get_distance( s.indices_from_symbol('Mg')[0], s.indices_from_symbol('Na')[0]) for s in ns ])) np.testing.assert_array_almost_equal( distances, np.array([0.75, 1.06066, 1.5, 1.677051, 2.12132])) np.testing.assert_array_equal( np.array( sorted([s.number_of_equivalent_configurations for s in ns])), np.array([1, 2, 4, 4, 4])) np.testing.assert_array_equal( np.array(sorted([s.full_configuration_degeneracy for s in ns])), np.array([16, 32, 64, 64, 64]))
def test_oxide_energy_corr(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_o] latt = Lattice.from_parameters(3.278, 3.278, 3.278, 60, 60, 60) coords = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75], [0.0, 0.0, 0.0]] struct = Structure(latt, elts, coords) li2o_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '65e83282d1707ec078c1012afbd05be8'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7a25bc5b9a5393f46600a4939d357982'}]}) li2o_entry_corrected = self.compat.process_entry(li2o_entry) self.assertAlmostEqual(li2o_entry_corrected.energy, -3.0 -0.66975, 4)
def setUp(self): # construct a pymatgen Structure instance using the site fractional coordinates # face-centered cubic lattice coords = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5]]) atom_list = ['Li'] * len(coords) lattice = Lattice.from_parameters(a=3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90) self.structure = Structure(lattice, atom_list, coords) # construct a pymatgen Molecule instance # square molecule (D4h) m_coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0]]) molecule = Molecule(atom_list, m_coords) molecule = Molecule(molecule.species, molecule.cart_coords - molecule.center_of_mass) self.molecule = molecule
def test_oxide_energy_corr(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_o] latt = Lattice.from_parameters(3.278, 3.278, 3.278, 60, 60, 60) coords = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75], [0.0, 0.0, 0.0]] struct = Structure(latt, elts, coords) li2o_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '9658a0ffb28da97ee7b36709966a0d1c'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7af704ddff29da5354831c4609f1cbc5'}]}) li2o_entry_corrected = self.compat.process_entry(li2o_entry) self.assertAlmostEqual(li2o_entry_corrected.energy, -3.0 -0.66975, 4)
def test_potcar_doenst_match_structure(self): el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) lioh_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Fe 17Jan2003', 'PAW_PBE O 08Apr2002', 'PAW_PBE H 15Jun2001']}) self.assertIsNone(self.compat.process_entry(lioh_entry))
def test_ozonide(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_o, el_o, el_o] latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342) coords = [[0.513004, 0.513004, 1.000000], [0.017616, 0.017616, 0.000000], [0.649993, 0.874790, 0.775203], [0.099587, 0.874790, 0.224797]] struct = Structure(latt, elts, coords) lio3_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '65e83282d1707ec078c1012afbd05be8'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7a25bc5b9a5393f46600a4939d357982'}]}) lio3_entry_corrected = self.compat.process_entry(lio3_entry) self.assertAlmostEqual(lio3_entry_corrected.energy, -3.0 - 3 * 0.66975)
def test_process_entry_peroxide(self): latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510) el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o] coords = [[0.666656, 0.666705, 0.750001], [0.333342, 0.333378, 0.250001], [0.000001, 0.000041, 0.500001], [0.000001, 0.000021, 0.000001], [0.333347, 0.333332, 0.649191], [0.333322, 0.333353, 0.850803], [0.666666, 0.666686, 0.350813], [0.666665, 0.666684, 0.149189]] struct = Structure(latt, elts, coords) li2o2_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Li 06Sep2000', 'PAW_PBE O 08Apr2002']}) li2o2_entry_corrected = self.compat.process_entry(li2o2_entry) self.assertAlmostEqual(li2o2_entry_corrected.energy, -3 - 0.44317 * 4, 4)
def test_ozonide(self): el_li = Element("Li") el_o = Element("O") elts = [el_li, el_o, el_o, el_o] latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342) coords = [[0.513004, 0.513004, 1.000000], [0.017616, 0.017616, 0.000000], [0.649993, 0.874790, 0.775203], [0.099587, 0.874790, 0.224797]] struct = Structure(latt, elts, coords) lio3_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_spec': [{'titel':'PAW_PBE Li 17Jan2003', 'hash': '9658a0ffb28da97ee7b36709966a0d1c'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7af704ddff29da5354831c4609f1cbc5'}]}) lio3_entry_corrected = self.compat.process_entry(lio3_entry) self.assertAlmostEqual(lio3_entry_corrected.energy, -3.0 - 3 * 0.66975)
def test_potcar_doenst_match_structure(self): compat = MITCompatibility() el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) lioh_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Fe 17Jan2003', 'PAW_PBE O 08Apr2002', 'PAW_PBE H 15Jun2001']}) self.assertIsNone(compat.process_entry(lioh_entry))
def test_aqueous_compat(self): el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) lioh_entry = ComputedStructureEntry(struct, -3, parameters={'is_hubbard': False, 'hubbards': None, 'run_type': 'GGA', 'potcar_symbols': ['PAW_PBE Li 17Jan2003', 'PAW_PBE O 08Apr2002', 'PAW_PBE H 15Jun2001']}) lioh_entry_compat = self.compat.process_entry(lioh_entry) lioh_entry_compat_aqcorr = self.aqcorr.correct_entry(lioh_entry_compat) lioh_entry_aqcompat = self.aqcompat.process_entry(lioh_entry) self.assertAlmostEqual(lioh_entry_compat_aqcorr.energy, lioh_entry_aqcompat.energy, 4)
from pymatgen import Lattice, Structure from bsym.pymatgen_interface import spacegroup_from_structure from bsym import bsym as sym if __name__ == '__main__': # construct a pymatgen Structure instance using the site fractional coordinates coords = np.array( [ [ 0.0, 0.0, 0.0 ], [ 0.5, 0.0, 0.0 ], [ 0.0, 0.5, 0.0 ], [ 0.0, 0.0, 0.5 ], [ 0.5, 0.5, 0.0 ], [ 0.0, 0.5, 0.5 ], [ 0.5, 0.0, 0.5 ], [ 0.5, 0.5, 0.5 ] ] ) atom_list = [ 'Li' ] * len( coords ) lattice = Lattice.from_parameters( a = 3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90 ) parent_structure = Structure( lattice, atom_list, coords ) # generate a SpaceGroup instance with the symmetry operations for this structure sg = spacegroup_from_structure( parent_structure ) # define the site occupations site_dist = { 1 : 2, 0 : 6 } # find the unique configurations unique_configurations = sym.process.unique_configurations_from_sites( site_dist, sg, verbose=True ) # output [ config.pprint() for config in unique_configurations ] sitelist = sym.SiteList( coords )
def test_oxide_type(self): el_li = Element("Li") el_o = Element("O") latt = Lattice([[3.985034, 0.0, 0.0], [0.0, 4.881506, 0.0], [0.0, 0.0, 2.959824]]) elts = [el_li, el_li, el_o, el_o, el_o, el_o] coords = list() coords.append([0.500000, 0.500000, 0.500000]) coords.append([0.0, 0.0, 0.0]) coords.append([0.632568, 0.085090, 0.500000]) coords.append([0.367432, 0.914910, 0.500000]) coords.append([0.132568, 0.414910, 0.000000]) coords.append([0.867432, 0.585090, 0.000000]) struct = Structure(latt, elts, coords) self.assertEqual(oxide_type(struct, 1.1), "superoxide") el_li = Element("Li") el_o = Element("O") elts = [el_li, el_o, el_o, el_o] latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342) coords = [[0.513004, 0.513004, 1.000000], [0.017616, 0.017616, 0.000000], [0.649993, 0.874790, 0.775203], [0.099587, 0.874790, 0.224797]] struct = Structure(latt, elts, coords) self.assertEqual(oxide_type(struct, 1.1), "ozonide") latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510) el_li = Element("Li") el_o = Element("O") elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o] coords = [[0.666656, 0.666705, 0.750001], [0.333342, 0.333378, 0.250001], [0.000001, 0.000041, 0.500001], [0.000001, 0.000021, 0.000001], [0.333347, 0.333332, 0.649191], [0.333322, 0.333353, 0.850803], [0.666666, 0.666686, 0.350813], [0.666665, 0.666684, 0.149189]] struct = Structure(latt, elts, coords) self.assertEqual(oxide_type(struct, 1.1), "peroxide") el_li = Element("Li") el_o = Element("O") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_o, el_o] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) self.assertEqual(oxide_type(struct, 1.1), "hydroxide") el_li = Element("Li") el_n = Element("N") el_h = Element("H") latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000) elts = [el_h, el_h, el_li, el_li, el_n, el_n] coords = [[0.000000, 0.500000, 0.413969], [0.500000, 0.000000, 0.586031], [0.000000, 0.000000, 0.000000], [0.500000, 0.500000, 0.000000], [0.000000, 0.500000, 0.192672], [0.500000, 0.000000, 0.807328]] struct = Structure(latt, elts, coords) self.assertEqual(oxide_type(struct, 1.1), "None") el_o = Element("O") latt = Lattice.from_parameters(4.389828, 5.369789, 5.369789, 70.786622, 69.244828, 69.244828) elts = [el_o, el_o, el_o, el_o, el_o, el_o, el_o, el_o] coords = [[0.844609, 0.273459, 0.786089], [0.155391, 0.213911, 0.726541], [0.155391, 0.726541, 0.213911], [0.844609, 0.786089, 0.273459], [0.821680, 0.207748, 0.207748], [0.178320, 0.792252, 0.792252], [0.132641, 0.148222, 0.148222], [0.867359, 0.851778, 0.851778]] struct = Structure(latt, elts, coords) self.assertEqual(oxide_type(struct, 1.1), "None")
fws.append( Firework([VaspToDBTaskEx()], spec, name=get_name(structure, spec['task_type']), fw_id=2)) connections[1] = [2] # 3rd Firework - static run. # VaspCopyTask - copy output from previous run to this directory # SetupStaticRunTask - override old parameters for static run # CustodianTaskEx - run VASP within a custodian spec = {'task_type': 'GGA static example'} copytask = VaspCopyTask({'use_CONTCAR': True, 'skip_CHGCAR': True}) setuptask = SetupStaticRunTask() custodiantask = VaspCustodianTaskEx({'jobs': [VaspJob('', auto_npar=False).as_dict()], 'handlers': [h.as_dict() for h in handlers], 'max_errors': 5}) fws.append(Firework([copytask, setuptask, custodiantask], spec, name=get_name(structure, spec['task_type']), fw_id=3)) connections[2] = [3] # 4th Firework - insert previous run into DB spec = {'task_type': 'VASP db insertion example'} fws.append( Firework([VaspToDBTaskEx()], spec, name=get_name(structure, spec['task_type']), fw_id=4)) connections[3] = [4] return Workflow(fws, connections, name=get_slug(structure.formula)) if __name__ == '__main__': l = Lattice.from_parameters(3.866, 3.866, 3.866, 60, 60, 60) s = Structure(l, ['Si', 'Si'], [[0.125,0.125,0.125], [0.875,0.875,0.875]]) my_wf = structure_to_wf(s) pprint(my_wf.to_dict(), indent=2) my_wf.to_file("Si_wf.json")
def structure_from_string(data): """ Parses a rndstr.in or lat.in file into pymatgen's Structure format. :param data: contents of a rndstr.in or lat.in file :return: Structure object """ data = data.splitlines() data = [x.split() for x in data if x] # remove empty lines # following specification/terminology given in manual if len(data[0]) == 6: # lattice parameters a, b, c, alpha, beta, gamma = map(float, data[0]) coord_system = Lattice.from_parameters(a, b, c, alpha, beta, gamma).matrix lattice_vecs = np.array([ [data[1][0], data[1][1], data[1][2]], [data[2][0], data[2][1], data[2][2]], [data[3][0], data[3][1], data[3][2]] ], dtype=float) first_species_line = 4 else: coord_system = np.array([ [data[0][0], data[0][1], data[0][2]], [data[1][0], data[1][1], data[1][2]], [data[2][0], data[2][1], data[2][2]] ], dtype=float) lattice_vecs = np.array([ [data[3][0], data[3][1], data[3][2]], [data[4][0], data[4][1], data[4][2]], [data[5][0], data[5][1], data[5][2]] ], dtype=float) first_species_line = 6 scaled_matrix = np.matmul(coord_system, lattice_vecs) lattice = Lattice(scaled_matrix) all_coords = [] all_species = [] for l in data[first_species_line:]: all_coords.append(np.array([l[0], l[1], l[2]], dtype=float)) species_strs = "".join(l[3:]) # join multiple strings back together species_strs = species_strs.replace(" ", "") # trim any white space species_strs = species_strs.split(",") # comma-delimited species = {} for species_str in species_strs: species_str = species_str.split('=') if len(species_str) == 1: # assume occupancy is 1.0 species_str = [species_str[0], 1.0] try: species[Specie(species_str[0])] = float(species_str[1]) except Exception: species[DummySpecie(species_str[0])] = float(species_str[1]) all_species.append(species) return Structure(lattice, all_species, all_coords)
# dir(site.specie) # type(site.specie) # site.specie # + print("type(struct):", "\n", type(struct)) print("type(struct[-1]):", "\n", type(struct[-1])) print("type(struct[-1].specie):", "\n", type(struct[-1].specie)) # - # + from pymatgen import Lattice, Structure, Molecule coords = [[0, 0, 0], [0.75,0.5,0.75]] lattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84, alpha=120, beta=90, gamma=60) struct = Structure(lattice, ["Si", "Si"], coords) coords = [[0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], [1.026719, 0.000000, -0.363000], [-0.513360, -0.889165, -0.363000], [-0.513360, 0.889165, -0.363000]] methane = Molecule(["C", "H", "H", "H", "H"], coords)
def structure_from_string(data): """ Parses a rndstr.in or lat.in file into pymatgen's Structure format. :param data: contents of a rndstr.in or lat.in file :return: Structure object """ data = data.splitlines() data = [x.split() for x in data if x] # remove empty lines # following specification/terminology given in manual if len(data[0]) == 6: # lattice parameters a, b, c, alpha, beta, gamma = map(float, data[0]) coord_system = Lattice.from_parameters(a, b, c, alpha, beta, gamma).matrix lattice_vecs = np.array([ [data[1][0], data[1][1], data[1][2]], [data[2][0], data[2][1], data[2][2]], [data[3][0], data[3][1], data[3][2]] ], dtype=float) first_species_line = 4 else: coord_system = np.array([ [data[0][0], data[0][1], data[0][2]], [data[1][0], data[1][1], data[1][2]], [data[2][0], data[2][1], data[2][2]] ], dtype=float) lattice_vecs = np.array([ [data[3][0], data[3][1], data[3][2]], [data[4][0], data[4][1], data[4][2]], [data[5][0], data[5][1], data[5][2]] ], dtype=float) first_species_line = 6 scaled_matrix = np.matmul(coord_system, lattice_vecs) lattice = Lattice(scaled_matrix) all_coords = [] all_species = [] for l in data[first_species_line:]: all_coords.append(np.array([l[0], l[1], l[2]], dtype=float)) species_strs = "".join(l[3:]) # join multiple strings back together species_strs = species_strs.replace(" ", "") # trim any white space species_strs = species_strs.split(",") # comma-delimited species = {} for species_str in species_strs: species_str = species_str.split('=') if len(species_str) == 1: # assume occupancy is 1.0 species_str = [species_str[0], 1.0] try: species[Specie(species_str[0])] = float(species_str[1]) except: species[DummySpecie(species_str[0])] = float(species_str[1]) all_species.append(species) return Structure(lattice, all_species, all_coords)