def __init__(self, entries, chempots, elements=None): """ Standard constructor for grand potential phase diagram. Args: entries ([PDEntry]): A list of PDEntry-like objects having an energy, energy_per_atom and composition. chempots {Element: float}: Specify the chemical potentials of the open elements. elements ([Element]): Optional list of elements in the phase diagram. If set to None, the elements are determined from the the entries themselves. """ if elements is None: elements = set() map(elements.update, [entry.composition.elements for entry in entries]) self.chempots = {get_el_sp(el): u for el, u in chempots.items()} elements = set(elements).difference(self.chempots.keys()) all_entries = [ GrandPotPDEntry(e, self.chempots) for e in entries if (not e.is_element) or e.composition.elements[0] in elements ] super(GrandPotentialPhaseDiagram, self).__init__(all_entries, elements)
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)
class PDEntryTest(unittest.TestCase): ''' Test all functions using a ficitious entry ''' 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_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_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_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 setUp(self): comp = Composition("LiFeO2") self.entry = PDEntry(comp, 53) self.gpentry = GrandPotPDEntry(self.entry, {Element('O'): 1.5})
def main(comp="La0.5Sr0.5MnO3", energy=-43.3610, ostart="", oend="", ostep=""): """Get energy above hull for a composition Args: comp <str>: Composition in string form energy <float>: Energy PER FORMULA UNIT of composition given (Leave the following arguments blank for a non-grand potential phase diagram.) ostart <float>: Starting oxygen chemical potential. oend <float>: Ending oxygen chemical potential. ostep <float>: Step for oxygen chemical potential Returns: Prints to screen """ #a = MPRester("<YOUR_MPREST_API_KEY_HERE>") a = MPRester("wfmUu5VSsDCvIrhz") mycomp = Composition(comp) print "Composition: ", mycomp myenergy = energy print "Energy: ", myenergy myPDEntry = PDEntry(mycomp, myenergy) elements = mycomp.elements ellist = map(str, elements) chemsys_entries = a.get_entries_in_chemsys(ellist) #For reference: other ways of getting entries #entries = a.mpquery(criteria={'elements':{'$in':['La','Mn'],'$all':['O']},'nelements':3}) #entries = a.mpquery(criteria={'elements':{'$in':['La','Mn','O'],'$all':['O']}},properties=['pretty_formula']) #entries = a.get_entries_in_chemsys(['La', 'Mn', 'O', 'Sr']) if ostart == "": #Regular phase diagram entries = list(chemsys_entries) entries.append(myPDEntry) pd = PhaseDiagram(entries) #plotter = PDPlotter(gppd) #plotter.show() ppda = PDAnalyzer(pd) eabove = ppda.get_decomp_and_e_above_hull(myPDEntry) print "Energy above hull: ", eabove[1] print "Decomposition: ", eabove[0] return eabove else: #Grand potential phase diagram orange = np.arange( ostart, oend + ostep, ostep) #add ostep because otherwise the range ends before oend for o_chem_pot in orange: entries = list(chemsys_entries) myGrandPDEntry = GrandPotPDEntry( myPDEntry, {Element('O'): float(o_chem_pot) }) #need grand pot pd entry for GPPD entries.append(myGrandPDEntry) gppd = GrandPotentialPhaseDiagram( entries, {Element('O'): float(o_chem_pot)}) gppda = PDAnalyzer(gppd) geabove = gppda.get_decomp_and_e_above_hull(myGrandPDEntry, True) print "******** Decomposition for mu_O = %s eV ********" % o_chem_pot print "%30s%1.4f" % ("mu_O: ", o_chem_pot) print "%30s%1.4f" % ("Energy above hull (eV): ", geabove[1]) decomp = geabove[0] #print "Decomp: ", decomp print "%30s" % "Decomposition: " for dkey in decomp.keys(): print "%30s:%1.4f" % (dkey.composition, decomp[dkey]) return