def setUp(self): with open(os.path.join(test_dir, "cohp.json"), "r") as f: self.cohp = Cohp.from_dict(json.load(f)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) with open(os.path.join(test_dir, "coop.json"), "r") as f: self.coop = Cohp.from_dict(json.load(f))
class CohpTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "cohp.json"), "r") as f: self.cohp = Cohp.from_dict(json.load(f)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) with open(os.path.join(test_dir, "coop.json"), "r") as f: self.coop = Cohp.from_dict(json.load(f)) def test_as_from_dict(self): with open(os.path.join(test_dir, "cohp.json"), "r") as f: cohp_dict = json.load(f) self.assertEqual(self.cohp.as_dict(), cohp_dict) def test_attributes(self): self.assertEqual(len(self.cohp.energies), 301) self.assertEqual(self.cohp.efermi, 9.75576) self.assertEqual(self.coop.efermi, 5.90043) self.assertFalse(self.cohp.are_coops) self.assertTrue(self.coop.are_coops) def test_get_icohp(self): self.assertEqual(self.cohp.get_icohp(), self.cohp.get_cohp(integrated=True)) self.assertEqual(None, self.cohp_only.get_icohp()) def test_get_interpolated_value(self): # icohp_ef are the ICHOP(Ef) values taken from # the ICOHPLIST.lobster file. icohp_ef_dict = {Spin.up: -0.10218, Spin.down: -0.19701} icoop_ef_dict = {Spin.up: 0.24714} icohp_ef = self.cohp.get_interpolated_value(self.cohp.efermi, integrated=True) icoop_ef = self.coop.get_interpolated_value(self.coop.efermi, integrated=True) self.assertAlmostEqual(icohp_ef_dict, icohp_ef) self.assertAlmostEqual(icoop_ef_dict, icoop_ef) with self.assertRaises(ValueError): self.cohp_only.get_interpolated_value(5.0, integrated=True) def test_str(self): with open(os.path.join(test_dir, "cohp.str"), "rt") as f: str_cohp = f.read() with open(os.path.join(test_dir, "coop.str"), "rt") as f: str_coop = f.read() self.assertEqual(self.cohp.__str__(), str_cohp) self.assertEqual(self.coop.__str__(), str_coop) def test_antibnd_states_below_efermi(self): self.assertDictEqual( self.cohp.has_antibnd_states_below_efermi(spin=None), {Spin.up: True, Spin.down: True}, ) self.assertDictEqual( self.cohp.has_antibnd_states_below_efermi(spin=None, limit=0.5), {Spin.up: False, Spin.down: False}, ) self.assertDictEqual( self.cohp.has_antibnd_states_below_efermi(spin=Spin.up, limit=0.5), {Spin.up: False}, )
class CohpTest(unittest.TestCase): def setUp(self): with open(os.path.join(test_dir, "cohp.json"), "r") as f: self.cohp = Cohp.from_dict(json.load(f)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) with open(os.path.join(test_dir, "coop.json"), "r") as f: self.coop = Cohp.from_dict(json.load(f)) def test_as_from_dict(self): with open(os.path.join(test_dir, "cohp.json"), "r") as f: cohp_dict = json.load(f) self.assertEqual(self.cohp.as_dict(), cohp_dict) def test_attributes(self): self.assertEqual(len(self.cohp.energies), 301) self.assertEqual(self.cohp.efermi, 9.75576) self.assertEqual(self.coop.efermi, 5.90043) self.assertFalse(self.cohp.are_coops) self.assertTrue(self.coop.are_coops) def test_get_icohp(self): self.assertEqual(self.cohp.get_icohp(), self.cohp.get_cohp(integrated=True)) self.assertEqual(None, self.cohp_only.get_icohp()) def test_get_interpolated_value(self): # icohp_ef are the ICHOP(Ef) values taken from # the ICOHPLIST.lobster file. icohp_ef_dict = {Spin.up: -0.10218, Spin.down: -0.19701} icoop_ef_dict = {Spin.up: 0.24714} icohp_ef = self.cohp.get_interpolated_value(self.cohp.efermi, integrated=True) icoop_ef = self.coop.get_interpolated_value(self.coop.efermi, integrated=True) self.assertAlmostEqual(icohp_ef_dict, icohp_ef) self.assertAlmostEqual(icoop_ef_dict, icoop_ef) with self.assertRaises(ValueError): self.cohp_only.get_interpolated_value(5.0, integrated=True) def test_str(self): with open(os.path.join(test_dir, "cohp.str"), "rt") as f: str_cohp = f.read() with open(os.path.join(test_dir, "coop.str"), "rt") as f: str_coop = f.read() self.assertEqual(self.cohp.__str__(), str_cohp) self.assertEqual(self.coop.__str__(), str_coop) def test_antibnd_states_below_efermi(self): self.assertDictEqual(self.cohp.has_antibnd_states_below_efermi(spin=None), {Spin.up: True, Spin.down: True}) self.assertDictEqual(self.cohp.has_antibnd_states_below_efermi(spin=None, limit=0.5), {Spin.up: False, Spin.down: False}) self.assertDictEqual(self.cohp.has_antibnd_states_below_efermi(spin=Spin.up, limit=0.5), {Spin.up: False})
from pymatgen.electronic_structure.cohp import Cohp from pymatgen.electronic_structure.plotter import CohpPlotter from pymatgen.io.lobster import Cohpcar COHPCAR_path = "E:/Python/pymatgen-master/test_files/cohp/COHPCAR.lobster" cohpcar = Cohpcar(filename=COHPCAR_path) cdata = cohpcar.cohp_data cdata_processed = {} #测试上传是否成功 for key in cdata: c = cdata[key] c["efermi"] = 0 c["energies"] = cohpcar.energies c["are_coops"] = False cdata_processed[key] = Cohp.from_dict(c) cp = CohpPlotter() cp.add_cohp_dict(cdata_processed) x = cp.get_plot() x.ylim([-6, 6]) x.show()