-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize fatband plots from Lobster (#3688)
* fatband fix * pre-commit auto-fixes * update plot * pre-commit auto-fixes * Fix ruff * Fix linting * Fix linting * pre-commit auto-fixes * Fix linting * Fix linting * pre-commit auto-fixes * Fix linting * pre-commit auto-fixes * Type * Type * pre-commit auto-fixes * new test * Review comments * pre-commit auto-fixes * linting * remove redundant Lobsterout.ATTRIBUTE_DEFAULTS * fix: handle kwargs and filename missing case * Fix typo in Fatband init docs --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Janosh Riebesell <[email protected]>
- Loading branch information
1 parent
668fa57
commit 72977a9
Showing
3 changed files
with
139 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Si3 O6 | ||
1.0 | ||
5.0218978900000000 0.0000000000000000 0.0000000000000000 | ||
-2.5109484399999999 4.3490909799999997 0.0000000000000000 | ||
0.0000000000000000 0.0000000000000000 5.5119294099999996 | ||
Si O | ||
3 6 | ||
direct | ||
0.0000000000000000 0.4763431500000000 0.6666670000000000 Si | ||
0.5236568500000000 0.5236568500000000 0.0000000000000000 Si | ||
0.4763431500000000 0.0000000000000000 0.3333330000000000 Si | ||
0.1589037800000000 0.7440031600000000 0.4613477300000000 O | ||
0.2559968400000000 0.4149006200000000 0.7946807299999999 O | ||
0.5850993799999999 0.8410962200000000 0.1280147300000000 O | ||
0.7440031600000000 0.1589037800000000 0.5386522700000000 O | ||
0.4149006200000000 0.2559968400000000 0.2053192700000000 O | ||
0.8410962200000000 0.5850993799999999 0.8719852700000000 O |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ | |
__email__ = "[email protected], [email protected]" | ||
__date__ = "Dec 10, 2017" | ||
|
||
|
||
module_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
|
@@ -1260,41 +1259,59 @@ def test_msonable(self): | |
lobsterout_from_dict = Lobsterout.from_dict(dict_data) | ||
assert dict_data == lobsterout_from_dict.as_dict() | ||
# test initialization with empty attributes (ensure file is not read again) | ||
dict_data_empty = self.lobsterout_doscar_lso.ATTRIBUTE_DEFAULTS | ||
dict_data_empty = dict.fromkeys(self.lobsterout_doscar_lso._ATTRIBUTES, None) | ||
lobsterout_empty_init_dict = Lobsterout.from_dict(dict_data_empty).as_dict() | ||
for attribute in lobsterout_empty_init_dict: | ||
if "@" not in attribute: | ||
assert dict_data_empty[attribute] == lobsterout_empty_init_dict[attribute] | ||
assert lobsterout_empty_init_dict[attribute] is None | ||
|
||
with pytest.raises(ValueError, match="invalid=val is not a valid attribute for Lobsterout"): | ||
Lobsterout(filename=None, invalid="val") | ||
|
||
|
||
class TestFatband(PymatgenTest): | ||
def setUp(self): | ||
self.structure = Vasprun( | ||
filename=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
ionic_step_skip=None, | ||
ionic_step_offset=0, | ||
parse_dos=True, | ||
parse_eigen=False, | ||
parse_projected_eigen=False, | ||
parse_potcar_file=False, | ||
occu_tol=1e-8, | ||
exception_on_bad_xml=True, | ||
).final_structure | ||
self.fatband_SiO2_p_x = Fatband( | ||
filenames=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x", | ||
Kpointsfile=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
structure=self.structure, | ||
vasprun_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
) | ||
self.vasprun_SiO2_p_x = Vasprun(filename=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml") | ||
self.bs_symmline = self.vasprun_SiO2_p_x.get_band_structure(line_mode=True, force_hybrid_mode=True) | ||
self.fatband_SiO2_p = Fatband( | ||
filenames=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p", | ||
Kpointsfile=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/KPOINTS", | ||
vasprun=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/vasprun.xml", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/KPOINTS", | ||
vasprun_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/vasprun.xml", | ||
structure=self.structure, | ||
) | ||
self.fatband_SiO2_p2 = Fatband( | ||
filenames=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/KPOINTS", | ||
structure=self.structure, | ||
vasprun_file=None, | ||
efermi=1.0647039, | ||
) | ||
self.vasprun_SiO2_p = Vasprun(filename=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/vasprun.xml") | ||
self.bs_symmline2 = self.vasprun_SiO2_p.get_band_structure(line_mode=True, force_hybrid_mode=True) | ||
self.fatband_SiO2_spin = Fatband( | ||
filenames=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_Spin", | ||
Kpointsfile=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_Spin/KPOINTS", | ||
vasprun=os.path.join( | ||
TEST_FILES_DIR, | ||
"cohp", | ||
"Fatband_SiO2/Test_Spin/vasprun.xml", | ||
), | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_Spin/KPOINTS", | ||
vasprun_file=os.path.join(TEST_FILES_DIR, "cohp", "Fatband_SiO2/Test_Spin/vasprun.xml"), | ||
structure=self.structure, | ||
) | ||
|
||
self.vasprun_SiO2_spin = Vasprun( | ||
filename=os.path.join( | ||
TEST_FILES_DIR, | ||
|
@@ -1334,6 +1351,7 @@ def test_attributes(self): | |
assert self.fatband_SiO2_p.structure[0].frac_coords == approx([0.0, 0.47634315, 0.666667]) | ||
assert self.fatband_SiO2_p.structure[0].species_string == "Si" | ||
assert self.fatband_SiO2_p.structure[0].coords == approx([-1.19607309, 2.0716597, 3.67462144]) | ||
assert self.fatband_SiO2_p.efermi == approx(1.0647039) | ||
|
||
assert list(self.fatband_SiO2_spin.label_dict["M"]) == approx([0.5, 0.0, 0.0]) | ||
assert self.fatband_SiO2_spin.efermi == self.vasprun_SiO2_spin.efermi | ||
|
@@ -1353,6 +1371,13 @@ def test_attributes(self): | |
assert self.fatband_SiO2_spin.structure[0].coords == approx([-1.19607309, 2.0716597, 3.67462144]) | ||
|
||
def test_raises(self): | ||
with pytest.raises(ValueError, match="vasprun_file or efermi have to be provided"): | ||
Fatband( | ||
filenames=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_Spin", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_Spin/KPOINTS", | ||
vasprun_file=None, | ||
structure=self.structure, | ||
) | ||
with pytest.raises( | ||
ValueError, match="The are two FATBAND files for the same atom and orbital. The program will stop" | ||
): | ||
|
@@ -1361,8 +1386,20 @@ def test_raises(self): | |
f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/FATBAND_si1_3p_x.lobster", | ||
f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/FATBAND_si1_3p_x.lobster", | ||
], | ||
Kpointsfile=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
structure=self.structure, | ||
) | ||
|
||
with pytest.raises(ValueError, match="A structure object has to be provided"): | ||
self.fatband_SiO2_p_x = Fatband( | ||
filenames=[ | ||
f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/FATBAND_si1_3p_x.lobster", | ||
f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/FATBAND_si1_3p_x.lobster", | ||
], | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
structure=None, | ||
) | ||
|
||
with pytest.raises( | ||
|
@@ -1374,15 +1411,17 @@ def test_raises(self): | |
f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/FATBAND_si1_3p_x.lobster", | ||
f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p/FATBAND_si1_3p.lobster", | ||
], | ||
Kpointsfile=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
structure=self.structure, | ||
) | ||
|
||
with pytest.raises(ValueError, match="No FATBAND files in folder or given"): | ||
self.fatband_SiO2_p_x = Fatband( | ||
filenames=".", | ||
Kpointsfile=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
kpoints_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/KPOINTS", | ||
vasprun_file=f"{TEST_FILES_DIR}/cohp/Fatband_SiO2/Test_p_x/vasprun.xml", | ||
structure=self.structure, | ||
) | ||
|
||
def test_get_bandstructure(self): | ||
|