def test_multi_entry(self): # TODO: More robust multientry test m_entry = MultiEntry([self.PxSol, self.PxIon]) for attr in ['energy', 'composition', 'nPhi']: self.assertEqual(getattr(m_entry, attr), getattr(self.PxSol, attr) + getattr(self.PxIon, attr)) # As dict, from dict m_entry_dict = m_entry.as_dict() m_entry_new = MultiEntry.from_dict(m_entry_dict) self.assertEqual(m_entry_new.energy, m_entry.energy)
def test_multicomponent(self): # Assure no ions get filtered at high concentration ag_n = [e for e in self.test_data["Ag-Te-N"] if "Te" not in e.composition] highconc = PourbaixDiagram( ag_n, filter_solids=True, conc_dict={"Ag": 1e-5, "N": 1} ) entry_sets = [set(e.entry_id) for e in highconc.stable_entries] self.assertIn({"mp-124", "ion-17"}, entry_sets) # Binary system pd_binary = PourbaixDiagram( self.test_data["Ag-Te"], filter_solids=True, comp_dict={"Ag": 0.5, "Te": 0.5}, conc_dict={"Ag": 1e-8, "Te": 1e-8}, ) self.assertEqual(len(pd_binary.stable_entries), 30) test_entry = pd_binary.find_stable_entry(8, 2) self.assertTrue("mp-499" in test_entry.entry_id) # Find a specific multientry to test self.assertEqual(pd_binary.get_decomposition_energy(test_entry, 8, 2), 0) pd_ternary = PourbaixDiagram(self.test_data["Ag-Te-N"], filter_solids=True) self.assertEqual(len(pd_ternary.stable_entries), 49) # Fetch a solid entry and a ground state entry mixture ag_te_n = self.test_data["Ag-Te-N"][-1] ground_state_ag_with_ions = MultiEntry( [self.test_data["Ag-Te-N"][i] for i in [4, 18, 30]], weights=[1 / 3, 1 / 3, 1 / 3], ) self.assertAlmostEqual( pd_ternary.get_decomposition_energy(ag_te_n, 2, -1), 2.767822855765 ) self.assertAlmostEqual( pd_ternary.get_decomposition_energy(ag_te_n, 10, -2), 3.756840056890625 ) self.assertAlmostEqual( pd_ternary.get_decomposition_energy(ground_state_ag_with_ions, 2, -1), 0 ) # Test invocation of pourbaix diagram from ternary data new_ternary = PourbaixDiagram(pd_ternary.all_entries) self.assertEqual(len(new_ternary.stable_entries), 49) self.assertAlmostEqual( new_ternary.get_decomposition_energy(ag_te_n, 2, -1), 2.767822855765 ) self.assertAlmostEqual( new_ternary.get_decomposition_energy(ag_te_n, 10, -2), 3.756840056890625 ) self.assertAlmostEqual( new_ternary.get_decomposition_energy(ground_state_ag_with_ions, 2, -1), 0 )