Skip to content

Commit

Permalink
Merge pull request #2410 from arosen93/rosen-gvec
Browse files Browse the repository at this point in the history
Allow for float ENCUTs in Wavecar class
  • Loading branch information
mkhorton committed Feb 23, 2022
2 parents c3f139c + a66ab85 commit 4547c25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4856,7 +4856,8 @@ def __init__(self, filename="WAVECAR", verbose=False, precision="normal", vasp_t
np.fromfile(f, dtype=np.float64, count=(recl8 - 3))

# extract kpoint, bands, energy, and lattice information
self.nk, self.nb, self.encut = np.fromfile(f, dtype=np.float64, count=3).astype(int)
self.nk, self.nb = np.fromfile(f, dtype=np.float64, count=2).astype(int)
self.encut = np.fromfile(f, dtype=np.float64, count=1)[0]
self.a = np.fromfile(f, dtype=np.float64, count=9).reshape((3, 3))
self.efermi = np.fromfile(f, dtype=np.float64, count=1)[0]
if verbose:
Expand Down
9 changes: 7 additions & 2 deletions pymatgen/io/vasp/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ def setUp(self):
self.wH2 = Wavecar(self.TEST_FILES_DIR / "WAVECAR.H2_low_symm")
self.wH2_gamma = Wavecar(self.TEST_FILES_DIR / "WAVECAR.H2_low_symm.gamma")
self.w_ncl = Wavecar(self.TEST_FILES_DIR / "WAVECAR.H2.ncl")
self.w_frac_encut = Wavecar(self.TEST_FILES_DIR / "WAVECAR.frac_encut")

def test_standard(self):
w = self.w
Expand All @@ -1805,7 +1806,7 @@ def test_standard(self):

self.assertEqual(w.filename, self.TEST_FILES_DIR / "WAVECAR.N2")
self.assertAlmostEqual(w.efermi, -5.7232, places=4)
self.assertEqual(w.encut, 25)
self.assertEqual(w.encut, 25.0)
self.assertEqual(w.nb, 9)
self.assertEqual(w.nk, 1)
self.assertTrue(np.allclose(w.a, a))
Expand All @@ -1821,6 +1822,10 @@ def test_standard(self):
for b in range(w.nb):
self.assertEqual(len(w.coeffs[k][b]), len(w.Gpoints[k]))

# Test WAVECAR with fractional encut
self.assertEqual(self.w_frac_encut.encut, 100.5)

# Test malformed WAVECARs
with self.assertRaises(ValueError):
Wavecar(self.TEST_FILES_DIR / "WAVECAR.N2.malformed")

Expand Down Expand Up @@ -1849,7 +1854,7 @@ def test_n2_45210(self):
w = Wavecar(self.TEST_FILES_DIR / "WAVECAR.N2.45210")
self.assertEqual(w.filename, self.TEST_FILES_DIR / "WAVECAR.N2.45210")
self.assertAlmostEqual(w.efermi, -5.7232, places=4)
self.assertEqual(w.encut, 25)
self.assertEqual(w.encut, 25.0)
self.assertEqual(w.nb, 9)
self.assertEqual(w.nk, 1)
self.assertTrue(np.allclose(w.a, self.a))
Expand Down
Binary file added test_files/WAVECAR.frac_encut
Binary file not shown.

0 comments on commit 4547c25

Please sign in to comment.