Skip to content

Commit 6dacfff

Browse files
Na-Kawajanosh
andauthored
Fix Procar.get_projection_on_elements for structures with multiple same-element ionic sites (#3261)
Add test for get_projction_on_elements() when structure have multiple ionic sites with the same elements. Signed-off-by: Naoto kawaguchi <[email protected]> * split test_get_projection_on_elements() into separate test --------- Signed-off-by: Naoto kawaguchi <[email protected]> Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 59de1c5 commit 6dacfff

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pymatgen/io/vasp/outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3864,7 +3864,7 @@ def get_projection_on_elements(self, structure: Structure):
38643864
name = structure.species[iat].symbol
38653865
for spin, d in self.data.items():
38663866
for k, b in itertools.product(range(self.nkpoints), range(self.nbands)):
3867-
dico[spin][b][k][name] = np.sum(d[k, b, iat, :])
3867+
dico[spin][b][k][name] += np.sum(d[k, b, iat, :])
38683868

38693869
return dico
38703870

tests/io/vasp/test_outputs.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,14 +1592,6 @@ def test_init(self):
15921592
assert p.nbands == 10
15931593
assert p.nkpoints == 10
15941594
assert p.nions == 3
1595-
lat = Lattice.cubic(3.0)
1596-
struct = Structure(
1597-
lat,
1598-
["Li", "Na", "K"],
1599-
[[0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]],
1600-
)
1601-
d = p.get_projection_on_elements(struct)
1602-
assert d[Spin.up][2][2] == approx({"Na": 0.042, "K": 0.646, "Li": 0.042})
16031595
filepath = f"{TEST_FILES_DIR}/PROCAR"
16041596
p = Procar(filepath)
16051597
assert p.get_occupation(0, "dxy")[Spin.up] == approx(0.96214813853000025)
@@ -1621,6 +1613,21 @@ def test_phase_factors(self):
16211613
p = Procar(filepath)
16221614
assert p.phase_factors[Spin.up][0, 0, 0, 0] == approx(-0.13 + 0.199j)
16231615

1616+
def test_get_projection_on_elements(self):
1617+
filepath = f"{TEST_FILES_DIR}/PROCAR.simple"
1618+
p = Procar(filepath)
1619+
struct = Structure(
1620+
Lattice.cubic(3.0),
1621+
["Li", "Na", "K"],
1622+
[[0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]],
1623+
)
1624+
d = p.get_projection_on_elements(struct)
1625+
assert d[Spin.up][2][2] == approx({"Na": 0.042, "K": 0.646, "Li": 0.042})
1626+
# https://github.com/materialsproject/pymatgen/pull/3261
1627+
struct.replace_species({"K": "Na"})
1628+
d2 = p.get_projection_on_elements(struct)
1629+
assert d2[Spin.up][2][2] == approx({"Na": 0.688, "Li": 0.042})
1630+
16241631

16251632
class TestXdatcar(PymatgenTest):
16261633
def test_init(self):

0 commit comments

Comments
 (0)