Example #1
0
class PDEntryTest(unittest.TestCase):
    def setUp(self):
        comp = Composition("LiFeO2")
        self.entry = PDEntry(comp, 53)
        self.gpentry = GrandPotPDEntry(self.entry, {Element("O"): 1.5})

    def test_get_energy(self):
        self.assertEqual(self.entry.energy, 53, "Wrong energy!")
        self.assertEqual(self.gpentry.energy, 50, "Wrong energy!")

    def test_get_chemical_energy(self):
        self.assertEqual(self.gpentry.chemical_energy, 3, "Wrong energy!")

    def test_get_energy_per_atom(self):
        self.assertEqual(self.entry.energy_per_atom, 53.0 / 4,
                         "Wrong energy per atom!")
        self.assertEqual(self.gpentry.energy_per_atom, 50.0 / 2,
                         "Wrong energy per atom!")

    def test_get_name(self):
        self.assertEqual(self.entry.name, "LiFeO2", "Wrong name!")
        self.assertEqual(self.gpentry.name, "LiFeO2", "Wrong name!")

    def test_get_composition(self):
        comp = self.entry.composition
        expected_comp = Composition("LiFeO2")
        self.assertEqual(comp, expected_comp, "Wrong composition!")
        comp = self.gpentry.composition
        expected_comp = Composition("LiFe")
        self.assertEqual(comp, expected_comp, "Wrong composition!")

    def test_is_element(self):
        self.assertFalse(self.entry.is_element)
        self.assertFalse(self.gpentry.is_element)

    def test_to_from_dict(self):
        d = self.entry.as_dict()
        gpd = self.gpentry.as_dict()
        entry = PDEntry.from_dict(d)

        self.assertEqual(entry.name, "LiFeO2", "Wrong name!")
        self.assertEqual(entry.energy_per_atom, 53.0 / 4)
        gpentry = GrandPotPDEntry.from_dict(gpd)
        self.assertEqual(gpentry.name, "LiFeO2", "Wrong name!")
        self.assertEqual(gpentry.energy_per_atom, 50.0 / 2)

        d_anon = d.copy()
        del d_anon["name"]
        try:
            entry = PDEntry.from_dict(d_anon)
        except KeyError:
            self.fail("Should not need to supply name!")

    def test_str(self):
        self.assertIsNotNone(str(self.entry))

    def test_read_csv(self):
        entries = EntrySet.from_csv(str(module_dir / "pdentries_test.csv"))
        self.assertEqual(entries.chemsys, {"Li", "Fe", "O"}, "Wrong elements!")
        self.assertEqual(len(entries), 490, "Wrong number of entries!")
 def gppd_mixing(self, chempots, gppd_entries=None):
     """
     This function give the phase equilibria of a pseudo-binary in a open system (GPPD).
     It will give a complete evolution profile for mixing ratio x change from 0 to 1.
     x is the ratio (both entry norm. to 1 atom/fu(w/o open element) ) or each entry
     """
     open_el = list(chempots.keys())[0]
     el_ref = VirtualEntry.get_mp_entry(open_el)
     chempots[open_el] = chempots[open_el] + el_ref.energy_per_atom
     gppd_entry1 = GrandPotPDEntry(
         self.entry1, {Element[_]: chempots[_]
                       for _ in chempots})
     gppd_entry2 = GrandPotPDEntry(
         self.entry2, {Element[_]: chempots[_]
                       for _ in chempots})
     if not gppd_entries:
         gppd_entries = self.get_gppd_entries(open_el)
     gppd = GrandPotentialPhaseDiagram(gppd_entries, chempots)
     profile = get_full_evolution_profile(gppd, gppd_entry1, gppd_entry2, 0,
                                          1)
     cleaned = clean_profile(profile)
     return cleaned
def get_mix_entry(mix_dict):
    """
    Mixing PDEntry or GrandPotEntry for the binary search algorithm.
    """
    entry1, entry2 = mix_dict.keys()
    x1, x2 = mix_dict[entry1], mix_dict[entry2]
    if type(entry1) == GrandPotPDEntry:
        mid_ori_entry = VirtualEntry.from_mixing({
            entry1.original_entry: x1,
            entry2.original_entry: x2
        })
        return GrandPotPDEntry(mid_ori_entry, entry1.chempots)
    else:
        return VirtualEntry.from_mixing({entry1: x1, entry2: x2})
Example #4
0
    def test_to_from_dict(self):
        d = self.entry.as_dict()
        gpd = self.gpentry.as_dict()
        entry = PDEntry.from_dict(d)

        self.assertEqual(entry.name, "LiFeO2", "Wrong name!")
        self.assertEqual(entry.energy_per_atom, 53.0 / 4)
        gpentry = GrandPotPDEntry.from_dict(gpd)
        self.assertEqual(gpentry.name, "LiFeO2", "Wrong name!")
        self.assertEqual(gpentry.energy_per_atom, 50.0 / 2)

        d_anon = d.copy()
        del d_anon["name"]
        try:
            entry = PDEntry.from_dict(d_anon)
        except KeyError:
            self.fail("Should not need to supply name!")
Example #5
0
 def setUp(self):
     comp = Composition("LiFeO2")
     self.entry = PDEntry(comp, 53)
     self.gpentry = GrandPotPDEntry(self.entry, {Element("O"): 1.5})