Esempio n. 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)
Esempio n. 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)
Esempio n. 3
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 = read_structure(os.path.join(test_dir, "Li2O.cif"))
        self.assertAlmostEqual(m.get_energy(s2), -36.3476248117)
Esempio n. 4
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)
Esempio n. 5
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 
Esempio n. 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)