diff --git a/pymatgen/apps/borg/tests/test_queen.py b/pymatgen/apps/borg/tests/test_queen.py index 51f3bead005..fe310c7caa5 100644 --- a/pymatgen/apps/borg/tests/test_queen.py +++ b/pymatgen/apps/borg/tests/test_queen.py @@ -30,7 +30,7 @@ def test_get_data(self): drone = VaspToComputedEntryDrone() self.queen = BorgQueen(drone, PymatgenTest.TEST_FILES_DIR, 1) data = self.queen.get_data() - assert len(data) == 15 + assert len(data) == 16 # added new folder for testing of chemical shift vasprun. def test_load_data(self): drone = VaspToComputedEntryDrone() diff --git a/pymatgen/io/vasp/inputs.py b/pymatgen/io/vasp/inputs.py index 149b5383cdf..95586595934 100644 --- a/pymatgen/io/vasp/inputs.py +++ b/pymatgen/io/vasp/inputs.py @@ -2281,9 +2281,9 @@ def from_file(filename: str): potcar = Potcar() functionals = [] - for p in fdata.split("End of Dataset"): - if p_strip := p.strip(): - single = PotcarSingle(p_strip + "\nEnd of Dataset\n") + for p in fdata.split("End of Dataset\n"): + if p.strip(): + single = PotcarSingle(p + "End of Dataset\n") potcar.append(single) functionals.append(single.functional) if len(set(functionals)) != 1: diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index d6ae6f28bae..4b41796a343 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -1149,8 +1149,13 @@ def update_charge_from_potcar(self, path): potcar_nelect = sum(ps.ZVAL * num for ps, num in zip(potcar, nums)) charge = potcar_nelect - nelect - for s in self.structures: - s._charge = charge + # If we do a chemical shift calculation, there is only one ionic step really, + # but parsing the vasprun.xml file will result in len(self.ionic_steps) > 1 + # only the first one contains a structure however, where we can update + # the charge. + if not self.incar.get("LCHIMAG"): + for s in self.structures: + s._charge = charge if hasattr(self, "initial_structure"): self.initial_structure._charge = charge if hasattr(self, "final_structure"): diff --git a/pymatgen/io/vasp/tests/test_inputs.py b/pymatgen/io/vasp/tests/test_inputs.py index eb6db855606..28eac47b390 100644 --- a/pymatgen/io/vasp/tests/test_inputs.py +++ b/pymatgen/io/vasp/tests/test_inputs.py @@ -1019,15 +1019,13 @@ def test_verify_correct_potcar_with_hash(self): def test_multi_potcar_with_and_without_hash(self): filename = f"{PymatgenTest.TEST_FILES_DIR}/POT_GGA_PAW_PBE_54/POTCAR.Fe_O.gz" cwd = os.path.abspath(os.path.dirname(__file__)) - loadfn(os.path.join(cwd, "../vasp_potcar_file_hashes.json")) - Potcar.from_file(filename) - # Still need to test the if POTCAR can be read. - # No longer testing for hashes - # for psingle in potcars: - # if hasattr(psingle, "hash_sha256_from_file"): - # assert psingle.hash_sha256_computed == psingle.hash_sha256_from_file - # else: - # assert psingle.file_hash in file_hash_db + file_hash_db = loadfn(os.path.join(cwd, "../vasp_potcar_file_hashes.json")) + potcars = Potcar.from_file(filename) + for psingle in potcars: + if hasattr(psingle, "hash_sha256_from_file"): + assert psingle.hash_sha256_computed == psingle.hash_sha256_from_file + else: + assert psingle.file_hash in file_hash_db # def test_default_functional(self): # p = PotcarSingle.from_symbol_and_functional("Fe") diff --git a/pymatgen/io/vasp/tests/test_outputs.py b/pymatgen/io/vasp/tests/test_outputs.py index eac9f623f35..b38de23cf79 100644 --- a/pymatgen/io/vasp/tests/test_outputs.py +++ b/pymatgen/io/vasp/tests/test_outputs.py @@ -665,6 +665,16 @@ def test_parsing_chemical_shift_calculations(self): assert n_estep == 10 assert vasp_run.converged + # test another chemical shift calculation done with 6.4.1 + # and also parsing the associated POTCAR file + filepath_wPOT = f"{self.TEST_FILES_DIR}/nmr/cs/with_POTCAR/vasprun.xml.gz" + vasp_run_wPOT = Vasprun(filepath_wPOT, parse_potcar_file=True) + + n_estep_wPOT = len(vasp_run_wPOT.ionic_steps[-1]["electronic_steps"]) + assert vasp_run_wPOT.converged + assert n_estep_wPOT == 4 + assert vasp_run_wPOT.final_structure._charge == 0.0 + def test_parsing_efg_calcs(self): filepath = f"{self.TEST_FILES_DIR}/nmr/efg/AlPO4/vasprun.xml" vasp_run = Vasprun(filepath) diff --git a/test_files/nmr/cs/with_POTCAR/POTCAR.gz b/test_files/nmr/cs/with_POTCAR/POTCAR.gz new file mode 100644 index 00000000000..8fe7adbc7cb Binary files /dev/null and b/test_files/nmr/cs/with_POTCAR/POTCAR.gz differ diff --git a/test_files/nmr/cs/with_POTCAR/vasprun.xml.gz b/test_files/nmr/cs/with_POTCAR/vasprun.xml.gz new file mode 100644 index 00000000000..22725976161 Binary files /dev/null and b/test_files/nmr/cs/with_POTCAR/vasprun.xml.gz differ