Beispiel #1
0
    def test_get_energy(self):
        coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5],
                  [0.25, 0.25, 0.25]]
        lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0.00],
                           [0.00, -2.0, 3.0]])
        s = Structure(lattice, [{
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }, {
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }, {
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }, {
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }], coords)

        m = EwaldElectrostaticModel()
        # large tolerance because scipy constants changed between 0.16.1 and 0.17
        self.assertAlmostEqual(m.get_energy(s), -264.66364858,
                               2)  # Result from GULP
        s2 = Structure.from_file(os.path.join(test_dir, "Li2O.cif"))
        self.assertAlmostEqual(m.get_energy(s2), -145.39050015844839, 4)
Beispiel #2
0
    def test_get_energy(self):
        coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5],
                  [0.25, 0.25, 0.25]]
        lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0.00],
                           [0.00, -2.0, 3.0]])
        s = Structure(lattice, [{
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }, {
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }, {
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }, {
            "Si4+": 0.5,
            "O2-": 0.25,
            "P5+": 0.25
        }], coords)

        m = EwaldElectrostaticModel()
        self.assertAlmostEqual(m.get_energy(s), 44.1070954178)
        s2 = Structure.from_file(os.path.join(test_dir, "Li2O.cif"))
        self.assertAlmostEqual(m.get_energy(s2), -145.39049924661001)
Beispiel #3
0
    def Find_Lowest_Energy_Structure_Electrostatics(self):
        """
        Find oxidized/reduced combination with lowest electrostatic energy
        """
        n_Na = self.structure.composition['Na']
        n_S = self.structure.composition['S']
        n_O = self.structure.composition['O']
        n_N = self.structure.composition['N']
        n_Fe = self.structure.composition['Fe']

        n_Fe_reduced = self.variable_magnetization_dict['Fe']['n_reduced']
        n_Fe_oxidized = n_Fe-n_Fe_reduced 

        N_charge = ( 2.*n_O-6.*n_S-n_Na-3.*n_Fe_oxidized-2.*n_Fe_reduced )/n_N

        oxidation_states = {'Na':+1, 'Fe':+3, 'O':-2,'S':+6,'N':N_charge}
        Fe_2plus = pymatgen.Specie('Fe',oxidation_state=+2)

        structure_with_charges = self.structure.copy()
        structure_with_charges.add_oxidation_state_by_element(oxidation_states)                                           

        # identify  Fe sites
        list_Fe_indices = []
        for i,site in enumerate(structure_with_charges):
            if site.specie.symbol == 'Fe':
                list_Fe_indices.append(i)

        # Generate all possible permutation  of sites and compute 
        # Ewald energy
        ewald_model = EwaldElectrostaticModel(acc_factor=6)
        list_reduced_sets = []
        list_ewald_energy = []
        for reduced_set in itertools.combinations(list_Fe_indices,n_Fe_reduced):
            list_reduced_sets.append(reduced_set) 

            struct = structure_with_charges.copy()
            for i in reduced_set:
                struct.replace(i, Fe_2plus)

            list_ewald_energy.append(ewald_model.get_energy(struct))

        if len(list_ewald_energy) == 0:
            # all sites are oxidized. No sorting involved                
            list_reduced_site_indices = []
            list_oxidized_site_indices = list_Fe_indices
        else:
            # some reduction takes place. Identify best electrostatic choice

            imin = np.argmin(list_ewald_energy)

            list_reduced_site_indices = list_reduced_sets[imin] 
            list_oxidized_site_indices = []
            for i in list_Fe_indices:
                if i not in list_reduced_site_indices: 
                    list_oxidized_site_indices.append(i) 


        return list_reduced_site_indices, list_oxidized_site_indices 
    def test_get_energy(self):
        coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5],
                  [0.25, 0.25, 0.25]]
        lattice = Lattice([[3.0, 0.0, 0.0],
                           [1.0, 3.0, 0.00],
                           [0.00, -2.0, 3.0]])
        s = Structure(lattice,
                      [{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                       {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                       {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                       {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25}], coords)

        m = EwaldElectrostaticModel()
        self.assertAlmostEqual(m.get_energy(s), 44.1070954178)
        s2 = read_structure(os.path.join(test_dir, "Li2O.cif"))
        self.assertAlmostEqual(m.get_energy(s2), -36.3476248117)
Beispiel #5
0
    def test_get_energy(self):
        coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5],
                  [0.25, 0.25, 0.25]]
        lattice = Lattice([[3.0, 0.0, 0.0],
                           [1.0, 3.0, 0.00],
                           [0.00, -2.0, 3.0]])
        s = Structure(lattice,
                      [{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                       {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                       {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                       {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25}], coords)

        m = EwaldElectrostaticModel()
        # large tolerance because scipy constants changed between 0.16.1 and 0.17
        self.assertAlmostEqual(m.get_energy(s), -264.66364858, 2)  # Result from GULP
        s2 = Structure.from_file(os.path.join(test_dir, "Li2O.cif"))
        self.assertAlmostEqual(m.get_energy(s2), -145.39050015844839, 4)
Beispiel #6
0
    def test_get_energy(self):
        coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]]
        lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0.00], [0.00, -2.0, 3.0]])
        s = Structure(
            lattice,
            [
                {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
                {"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
            ],
            coords,
        )

        m = EwaldElectrostaticModel()
        self.assertAlmostEqual(m.get_energy(s), -40.655658979571228)
        s2 = Structure.from_file(os.path.join(test_dir, "Li2O.cif"))
        self.assertAlmostEqual(m.get_energy(s2), -145.39050015844839)
Beispiel #7
0
 def test_to_from_dict(self):
     m = EwaldElectrostaticModel()
     d = m.as_dict()
     self.assertIsInstance(EwaldElectrostaticModel.from_dict(d), EwaldElectrostaticModel)
 def test_to_from_dict(self):
     m = EwaldElectrostaticModel()
     d = m.as_dict()
     self.assertIsInstance(
         EwaldElectrostaticModel.from_dict(d), EwaldElectrostaticModel
     )
structure[2] = {"Fe2+": 1 / 3, "Li+": 2 / 3}
structure[3] = {"S2-": 1}
structure[4] = {"O2-": 1}
structure

structure.make_supercell([2, 2, 2])
structure

enum = EnumerateStructureTransformation()
enumerated = enum.apply_transformation(
    structure, return_ranked_list=100)  # return no more than 100 structures
structures = [d["structure"] for d in enumerated]
print("%d structures returned." % len(structures))

from pymatgen.analysis.energy_models import EwaldElectrostaticModel
ed = EwaldElectrostaticModel()
#ed.get_energy(structures[1])

structures20 = structures[:20]
batch_write_input(elect_stru, vasp_input_set=MPRelaxSet)

# elect_stru=structures20=structures[::10]

# for st in elect_stru:
# print(ed.get_energy(st))

# from pymatgen.transformations.standard_transformations import PartialRemoveSpecieTransformation
# vac_list=[]

# for ii in range (1,11):
# strut=structures[ii]