Example #1
0
 def setUp(self):
     module_dir = os.path.dirname(os.path.abspath(__file__))
     (self.elements, self.entries) = PDEntryIO.from_csv(
         os.path.join(module_dir, "pdentries_test.csv"))
     self.pd = CompoundPhaseDiagram(
         self.entries,
         [Composition("Li2O"), Composition("Fe2O3")])
Example #2
0
class CompoundPhaseDiagramTest(unittest.TestCase):
    def setUp(self):
        module_dir = os.path.dirname(os.path.abspath(__file__))
        (self.elements, self.entries) = PDEntryIO.from_csv(
            os.path.join(module_dir, "pdentries_test.csv"))
        self.pd = CompoundPhaseDiagram(
            self.entries,
            [Composition("Li2O"), Composition("Fe2O3")])

    def test_stable_entries(self):
        stable_formulas = [ent.name for ent in self.pd.stable_entries]
        expected_stable = ["Fe2O3", "Li5FeO4", "LiFeO2", "Li2O"]
        for formula in expected_stable:
            self.assertTrue(formula in stable_formulas)

    def test_get_formation_energy(self):
        stable_formation_energies = {
            ent.name: self.pd.get_form_energy(ent)
            for ent in self.pd.stable_entries
        }
        expected_formation_energies = {
            'Li5FeO4': -7.0773284399999739,
            'Fe2O3': 0,
            'LiFeO2': -0.47455929750000081,
            'Li2O': 0
        }
        for formula, energy in expected_formation_energies.items():
            self.assertAlmostEqual(energy, stable_formation_energies[formula],
                                   7)

    def test_str(self):
        self.assertIsNotNone(str(self.pd))
Example #3
0
class CompoundPhaseDiagramTest(unittest.TestCase):

    def setUp(self):
        module_dir = os.path.dirname(os.path.abspath(__file__))
        (self.elements, self.entries) = PDEntryIO.from_csv(
            os.path.join(module_dir, "pdentries_test.csv"))
        self.pd = CompoundPhaseDiagram(self.entries, [Composition("Li2O"),
                                                      Composition("Fe2O3")])

    def test_stable_entries(self):
        stable_formulas = [ent.name for ent in self.pd.stable_entries]
        expected_stable = ["Fe2O3", "Li5FeO4", "LiFeO2", "Li2O"]
        for formula in expected_stable:
            self.assertTrue(formula in stable_formulas)

    def test_get_formation_energy(self):
        stable_formation_energies = {ent.name:
                                     self.pd.get_form_energy(ent)
                                     for ent in self.pd.stable_entries}
        expected_formation_energies = {'Li5FeO4': -7.0773284399999739,
                                       'Fe2O3': 0,
                                       'LiFeO2': -0.47455929750000081,
                                       'Li2O': 0}
        for formula, energy in expected_formation_energies.items():
            self.assertAlmostEqual(energy, stable_formation_energies[formula],
                                   7)

    def test_str(self):
        self.assertIsNotNone(str(self.pd))
Example #4
0
    def get_phase_diagram_plot(self):
        """
        Returns a phase diagram plot, as a matplotlib plot object.
        """

        # set the font to Times, rendered with Latex
        plt.rc('font', **{'family': 'serif', 'serif': ['Times']})
        plt.rc('text', usetex=True)

        # parse the composition space endpoints
        endpoints_line = self.lines[0].split()
        endpoints = []
        for word in endpoints_line[::-1]:
            if word == 'endpoints:':
                break
            else:
                endpoints.append(Composition(word))

        if len(endpoints) < 2:
            print('There must be at least 2 endpoint compositions to make a '
                  'phase diagram.')
            quit()

        # parse the compositions and total energies of all the structures
        compositions = []
        total_energies = []
        for i in range(4, len(self.lines)):
            line = self.lines[i].split()
            compositions.append(Composition(line[1]))
            total_energies.append(float(line[2]))

        # make a list of PDEntries
        pdentries = []
        for i in range(len(compositions)):
            pdentries.append(PDEntry(compositions[i], total_energies[i]))

        # make a CompoundPhaseDiagram
        compound_pd = CompoundPhaseDiagram(pdentries, endpoints)

        # make a PhaseDiagramPlotter
        pd_plotter = PDPlotter(compound_pd, show_unstable=100)
        return pd_plotter.get_plot(label_unstable=False)
Example #5
0
 def setUp(self):
     module_dir = os.path.dirname(os.path.abspath(__file__))
     (self.elements, self.entries) = PDEntryIO.from_csv(
         os.path.join(module_dir, "pdentries_test.csv"))
     self.pd = CompoundPhaseDiagram(self.entries, [Composition("Li2O"),
                                                   Composition("Fe2O3")])
Example #6
0
term_comp = [
    Composition(names[7]),
    Composition(names[11]),
    Composition(names[32])
]

# creating entries from for the LDA phase diagram
entries_lda = []
for i in range(len(names)):
    #    entries_lda.append(PDEntry(names[i],enlda[i], names[i], "LDA"))
    entries_lda.append(PDEntry(names[i], enlda[i], " ", "LDA"))

# creating the phase diagram for LDA
pd_lda = PhaseDiagram(entries_lda)
cpd_lda = CompoundPhaseDiagram(entries_lda,
                               term_comp,
                               normalize_terminal_compositions=True)
a_lda = PDAnalyzer(pd_lda)

# creating entries from for the PBE phase diagram
entries_pbe = []
for i in range(len(names)):
    #    entries_pbe.append(PDEntry(names[i],enpbe[i], names[i], "PBE"))
    entries_pbe.append(PDEntry(names[i], enpbe[i], " ", "PBE"))

# creating the phase diagram for PBE
pd_pbe = PhaseDiagram(entries_pbe)
cpd_pbe = CompoundPhaseDiagram(entries_pbe,
                               term_comp,
                               normalize_terminal_compositions=True)
a_pbe = PDAnalyzer(pd_pbe)