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.assertEqual( str(self.entry), "PDEntry : Li1 Fe1 O2 (mp-757614) with energy = 53.0000") pde = self.entry.as_dict() del pde["name"] pde = PDEntry.from_dict(pde) self.assertEqual(str(pde), "PDEntry : Li1 Fe1 O2 with energy = 53.0000")
def from_dict(cls, d): """ Invokes """ entry_type = d["entry_type"] if entry_type == "Ion": entry = IonEntry.from_dict(d["entry"]) else: entry = PDEntry.from_dict(d["entry"]) entry_id = d["entry_id"] concentration = d["concentration"] return PourbaixEntry(entry, entry_id, concentration)
def from_dict(cls, d): """ Invokes """ entry_type = d["entry_type"] if entry_type == "Ion": entry = IonEntry.from_dict(d["entry"]) else: entry = PDEntry.from_dict(d["entry"]) entry_id = d["entry_id"] concentration = d["concentration"] return PourbaixEntry(entry, entry_id, concentration)
def from_dict(cls, d): """ Returns a PourbaixEntry by reading in an Ion """ entry_type = d["entry type"] if entry_type == "Ion": entry = IonEntry.from_dict(d["entry"]) else: entry = PDEntry.from_dict(d["entry"]) correction = d["correction"] entry_id = d["entry_id"] return PourbaixEntry(entry, correction, entry_id)
def from_dict(cls, d): """ Returns a PourbaixEntry by reading in an Ion """ entry_type = d["entry type"] if entry_type == "Ion": entry = IonEntry.from_dict(d["entry"]) else: entry = PDEntry.from_dict(d["entry"]) correction = d["correction"] entry_id = d["entry_id"] return PourbaixEntry(entry, correction, entry_id)