class PDPlotterTest(unittest.TestCase): def setUp(self): entries = list(EntrySet.from_csv(os.path.join(module_dir, "pdentries_test.csv"))) self.pd_ternary = PhaseDiagram(entries) self.plotter_ternary_mpl = PDPlotter(self.pd_ternary, backend="matplotlib") self.plotter_ternary_plotly = PDPlotter(self.pd_ternary, backend="plotly") entrieslio = [e for e in entries if "Fe" not in e.composition] self.pd_binary = PhaseDiagram(entrieslio) self.plotter_binary_mpl = PDPlotter(self.pd_binary, backend="matplotlib") self.plotter_binary_plotly = PDPlotter(self.pd_binary, backend="plotly") entries.append(PDEntry("C", 0)) self.pd_quaternary = PhaseDiagram(entries) self.plotter_quaternary_mpl = PDPlotter(self.pd_quaternary, backend="matplotlib") self.plotter_quaternary_plotly = PDPlotter(self.pd_quaternary, backend="plotly") def test_pd_plot_data(self): (lines, labels, unstable_entries) = self.plotter_ternary_mpl.pd_plot_data self.assertEqual(len(lines), 22) self.assertEqual( len(labels), len(self.pd_ternary.stable_entries), "Incorrect number of lines generated!", ) self.assertEqual( len(unstable_entries), len(self.pd_ternary.all_entries) - len(self.pd_ternary.stable_entries), "Incorrect number of lines generated!", ) (lines, labels, unstable_entries) = self.plotter_quaternary_mpl.pd_plot_data self.assertEqual(len(lines), 33) self.assertEqual(len(labels), len(self.pd_quaternary.stable_entries)) self.assertEqual( len(unstable_entries), len(self.pd_quaternary.all_entries) - len(self.pd_quaternary.stable_entries), ) (lines, labels, unstable_entries) = self.plotter_binary_mpl.pd_plot_data self.assertEqual(len(lines), 3) self.assertEqual(len(labels), len(self.pd_binary.stable_entries)) def test_mpl_plots(self): # Some very basic ("non")-tests. Just to make sure the methods are callable. self.plotter_binary_mpl.get_plot().close() self.plotter_ternary_mpl.get_plot().close() self.plotter_quaternary_mpl.get_plot().close() self.plotter_ternary_mpl.get_contour_pd_plot().close() self.plotter_ternary_mpl.get_chempot_range_map_plot([Element("Li"), Element("O")]).close() self.plotter_ternary_mpl.plot_element_profile(Element("O"), Composition("Li2O")).close() def test_plotly_plots(self): # Also very basic tests. Ensures callability and 2D vs 3D properties. self.plotter_binary_plotly.get_plot() self.plotter_ternary_plotly.get_plot() self.plotter_quaternary_plotly.get_plot()
comp = Composition(phase) # getting entry for PD Object entry = PDEntry(comp, computed_phases[phase]) # building list of entries entries.append(entry) # getting PD from list of entries pd = PhaseDiagram(entries) # get distance from convex hull for cubic phase comp = Composition('NaNbO3') energy = -38.26346361 entry = PDEntry(comp, energy) cubic_instability = pd.get_e_above_hull(entry) pd_dict = pd.as_dict() # Getting Plot plt = PDPlotter(pd, show_unstable=False) # you can also try show_unstable=True #plt_data = plt.pd_plot_data # getting plot for chem potential - variables 'fontsize' for labels size and 'plotsize' for fig size have been added (not present in original pymatgen) to get_chempot_range_map_plot function chem_pot_plot = plt.get_chempot_range_map_plot( [Element("Na"), Element("Nb")], fontsize=14, plotsize=1.5) #plt.write_image("chem_pot_{}.png".format('-'.join(system)), "png") chem_pot_plot.savefig(f'chem_pot_{system_name}.png') # save figure # getting plot for PD - variables 'fontsize' for labels size and plotsize for fig size have been added (not present in original pymatgen) to get_plot function pd_plot = plt.get_plot(label_stable=True, fontsize=24, plotsize=3) pd_plot.savefig(f'PD_{system_name}.png')
pd = PDHandler(computed_phases).phase_diagram() pdplotter = PDPlotter(pd) #building set of points points_boundary = {} for res in chempots_boundary: points_boundary[res] = (chempots_boundary[res][Element('Na')], chempots_boundary[res][Element('Nb')]) points_exp = {} for res in chempots_exp: points_exp[res] = (chempots_exp[res][Element('Na')], chempots_exp[res][Element('Nb')]) pdplotter.get_chempot_range_map_plot([Element('Na'), Element('Nb')]) plotcustom = PDPlotterAdder(ca) plotcustom.add_points(points_boundary) plotcustom.add_points(points_exp) chempot_ox = {Element('O'): chempots_exp['X1'][Element('O')]} plotcustom.add_constant_chempot_line( Composition('NaNbO3'), Element('Na'), chempot_ox, label='$\Delta \mu_{O}$ = ' + '%s eV' % (np.around(chempot_ox[Element("O")], decimals=2)), color='#5782e1') plt.legend() plt.xlim(-3.5, 0.4)