示例#1
0
class PhononBSPlotterTest(unittest.TestCase):
    def setUp(self):
        with open(os.path.join(test_dir, "NaCl_phonon_bandstructure.json"),
                  "r") as f:
            d = json.loads(f.read())
            self.bs = PhononBandStructureSymmLine.from_dict(d)
            self.plotter = PhononBSPlotter(self.bs)

    def test_bs_plot_data(self):
        self.assertEqual(len(self.plotter.bs_plot_data()['distances'][0]), 51,
                         "wrong number of distances in the first branch")
        self.assertEqual(len(self.plotter.bs_plot_data()['distances']), 4,
                         "wrong number of branches")
        self.assertEqual(
            sum([len(e) for e in self.plotter.bs_plot_data()['distances']]),
            204, "wrong number of distances")
        self.assertEqual(self.plotter.bs_plot_data()['ticks']['label'][4], "Y",
                         "wrong tick label")
        self.assertEqual(len(self.plotter.bs_plot_data()['ticks']['label']), 8,
                         "wrong number of tick labels")

    def test_plot(self):
        # Disabling latex for testing.
        from matplotlib import rc
        rc('text', usetex=False)
        self.plotter.get_plot(units="mev")

    def test_plot_compare(self):
        # Disabling latex for testing.
        from matplotlib import rc
        rc('text', usetex=False)
        self.plotter.plot_compare(self.plotter, units="mev")
示例#2
0
 def compare_plot(self, filename="band_comparison.eps", img_format="eps"):
     plotter = PhononBSPlotter(bs=self.bs1)
     plotter2 = PhononBSPlotter(bs=self.bs2)
     new_plotter = plotter.plot_compare(plotter2)
     new_plotter.savefig(filename, format=img_format)
     new_plotter.close()