Skip to content

Fix Lobsterenv Bug #3637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pymatgen/io/lobster/lobsterenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ def __init__(
if valences is None:
if valences_from_charges and filename_charge is not None:
chg = Charge(filename=filename_charge)
if valences_from_charges and obj_charge is not None:
if which_charge == "Mulliken":
self.valences = chg.Mulliken
elif which_charge == "Loewdin":
self.valences = chg.Loewdin
elif valences_from_charges and obj_charge is not None:
chg = obj_charge
if which_charge == "Mulliken":
self.valences = chg.Mulliken
Expand Down
15 changes: 15 additions & 0 deletions tests/io/lobster/test_lobsterenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ def setUp(self):
additional_condition=0,
adapt_extremum_to_add_cond=True,
)
self.chem_env_lobster_NaSi_wo_charges = LobsterNeighbors(
are_coops=False,
filename_icohp=f"{TEST_DIR}/ICOHPLIST.lobster.NaSi.gz",
structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaSi.gz"),
valences_from_charges=False,
filename_charge=None,
additional_condition=0,
adapt_extremum_to_add_cond=True,
)
# Test LobsterNeighbors using pymatgen objects
self.obj_icohp = Icohplist(filename=f"{TEST_DIR}/ICOHPLIST.lobster.NaSi.gz")
self.obj_charge = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.NaSi.gz")
Expand Down Expand Up @@ -855,3 +864,9 @@ def test_get_info_cohps_to_neighbors(self):
only_bonds_to=None,
per_bond=False,
)

def test_valences(self):
assert self.chem_env_lobster1_charges_noisecutoff.valences == [0.75, -0.75] # Mulliken
assert self.chem_env_lobster1_charges_loewdin.valences == [0.27, 0.27, 0.27, 0.27, -0.54, -0.54]
assert self.chem_env_w_obj.valences == [0.67] * 4 + [0.7] * 4 + [-0.7] * 4 + [-0.68] * 4 # charge_obj
assert self.chem_env_lobster_NaSi_wo_charges.valences == [1] * 8 + [-1] * 8 # BVA