Skip to content
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

WIP: Fix consideration of translation symmetry for some (extremely rare) edge cases in LobsterEnv #4148

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7e5b838
partially test translations in lobsterenv
JaGeo Oct 30, 2024
0778527
pre-commit auto-fixes
pre-commit-ci[bot] Oct 30, 2024
44047b4
Merge branch 'materialsproject:master' into fix_icohp
naik-aakash Dec 3, 2024
8cc5c8f
Merge branch 'master' into fix_icohp
JaGeo Jan 14, 2025
0d5ff55
Merge branch 'master' of github.com:JaGeo/pymatgen into fix_icohp
JaGeo Jan 24, 2025
e7b558a
merge current mastr
JaGeo Jan 24, 2025
8a8003e
pre-commit auto-fixes
pre-commit-ci[bot] Jan 24, 2025
a922572
Merge branch 'materialsproject:master' into fix_icohp
naik-aakash Feb 6, 2025
aa1fda5
add new test data
JaGeo Feb 6, 2025
bc1aa7b
merge conflict
JaGeo Feb 6, 2025
9ac8003
pre-commit auto-fixes
pre-commit-ci[bot] Feb 6, 2025
527e675
fix some more
JaGeo Feb 6, 2025
8af3352
Merge branch 'fix_icohp' of github.com:JaGeo/pymatgen into fix_icohp
JaGeo Feb 6, 2025
df3589a
pre-commit auto-fixes
pre-commit-ci[bot] Feb 6, 2025
5520121
fix nearly everything except for two inter neighbor things
JaGeo Feb 6, 2025
5921ed8
Merge branch 'fix_icohp' of github.com:JaGeo/pymatgen into fix_icohp
JaGeo Feb 6, 2025
8c27943
pre-commit auto-fixes
pre-commit-ci[bot] Feb 6, 2025
e908e47
add more fixes
JaGeo Feb 7, 2025
17037c2
add more fixes
JaGeo Feb 7, 2025
5436d40
pre-commit auto-fixes
pre-commit-ci[bot] Feb 7, 2025
cfdd0ea
fix the just introduced bug and add a warning for very rare cases tha…
JaGeo Feb 7, 2025
bf1b7fd
fix the just introduced bug and add a warning for very rare cases tha…
JaGeo Feb 7, 2025
47aca41
pre-commit auto-fixes
pre-commit-ci[bot] Feb 7, 2025
53a2a67
fix next test by adapting cutoff
JaGeo Feb 7, 2025
9154b3c
Merge branch 'fix_icohp' of github.com:JaGeo/pymatgen into fix_icohp
JaGeo Feb 7, 2025
413ed2f
pre-commit auto-fixes
pre-commit-ci[bot] Feb 7, 2025
c474ff8
fix some bugs
JaGeo Feb 7, 2025
43ea1fc
Merge branch 'fix_icohp' of github.com:JaGeo/pymatgen into fix_icohp
JaGeo Feb 7, 2025
ebe4bc1
pre-commit auto-fixes
pre-commit-ci[bot] Feb 7, 2025
0acbb0c
fix some bugs
JaGeo Feb 7, 2025
5646066
remove translation correction
JaGeo Feb 7, 2025
d195474
Merge branch 'materialsproject:master' into fix_icohp
naik-aakash Feb 24, 2025
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
4 changes: 4 additions & 0 deletions src/pymatgen/electronic_structure/cohp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,10 @@ def is_spin_polarized(self) -> bool:
"""
return self._is_spin_polarized

@property
def translation(self) -> list[int, int, int]:
return self._translation

def icohpvalue(self, spin: Spin = Spin.up) -> float:
"""
Args:
Expand Down
70 changes: 53 additions & 17 deletions src/pymatgen/io/lobster/lobsterenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,14 +790,9 @@ def _evaluate_ce(
raise ValueError("Please give two limits or leave them both at None")

# Find environments based on ICOHP values
(
list_icohps,
list_keys,
list_lengths,
list_neighisite,
list_neighsite,
list_coords,
) = self._find_environments(additional_condition, lowerlimit, upperlimit, only_bonds_to)
(list_icohps, list_keys, list_lengths, list_neighisite, list_neighsite, list_coords) = self._find_environments(
additional_condition, lowerlimit, upperlimit, only_bonds_to
)

self.list_icohps = list_icohps
self.list_lengths = list_lengths
Expand Down Expand Up @@ -939,11 +934,14 @@ def _find_environments(
lengths_from_ICOHPs,
neighbors_from_ICOHPs,
selected_ICOHPs,
translations_ICOHPs,
) = additional_conds

if len(neighbors_from_ICOHPs) > 0:
centralsite = site

copysite = copy.copy(centralsite)
cell_start = centralsite.frac_coords - copysite.to_unit_cell().frac_coords
print(cell_start)
neighbors_by_distance_start = self.structure.get_sites_in_sphere(
pt=centralsite.coords,
r=np.max(lengths_from_ICOHPs) + 0.5,
Expand All @@ -955,50 +953,71 @@ def _find_environments(
list_distances = []
index_here_list = []
coords = []
translations_by_distance = []
for neigh_new in sorted(neighbors_by_distance_start, key=lambda x: x[1]):
site_here = neigh_new[0].to_unit_cell()
index_here = neigh_new[2]
index_here_list.append(index_here)
cell_here = neigh_new[3]

new_coords = [
site_here.frac_coords[0] + float(cell_here[0]),
site_here.frac_coords[1] + float(cell_here[1]),
site_here.frac_coords[2] + float(cell_here[2]),
]
coords.append(site_here.lattice.get_cartesian_coords(new_coords))

# new_site = PeriodicSite(
# species=site_here.species_string,
# coords=site_here.lattice.get_cartesian_coords(new_coords),
# lattice=site_here.lattice,
# to_unit_cell=False,
# coords_are_cartesian=True,
# )
neighbors_by_distance.append(neigh_new[0])
list_distances.append(neigh_new[1])
translations_by_distance.append(cell_here)
_list_neighsite = []
_list_neighisite = []
copied_neighbors_from_ICOHPs = copy.copy(neighbors_from_ICOHPs)
copied_distances_from_ICOHPs = copy.copy(lengths_from_ICOHPs)
copied_translations_from_ICOHPs = copy.copy(translations_ICOHPs)
_neigh_coords = []
_neigh_frac_coords = []

for neigh_idx, neigh in enumerate(neighbors_by_distance):
index_here2 = index_here_list[neigh_idx]

print(index_here2)
for dist_idx, dist in enumerate(copied_distances_from_ICOHPs):
if (
np.isclose(dist, list_distances[neigh_idx], rtol=1e-4)
and copied_neighbors_from_ICOHPs[dist_idx] == index_here2
and (
(
copied_translations_from_ICOHPs[dist_idx][0]
== -translations_by_distance[neigh_idx][0]
and copied_translations_from_ICOHPs[dist_idx][1]
== -translations_by_distance[neigh_idx][1]
and copied_translations_from_ICOHPs[dist_idx][2]
== -translations_by_distance[neigh_idx][2]
)
or (
copied_translations_from_ICOHPs[dist_idx][0]
== translations_by_distance[neigh_idx][0]
and copied_translations_from_ICOHPs[dist_idx][1]
== translations_by_distance[neigh_idx][1]
and copied_translations_from_ICOHPs[dist_idx][2]
== translations_by_distance[neigh_idx][2]
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could raise a warning if this fall-back option is taken. I think with updating to reading the CONTCAR, most issues should be fixed, however.

)
):
_list_neighsite.append(neigh)
_list_neighisite.append(index_here2)
_neigh_coords.append(coords[neigh_idx])
_neigh_frac_coords.append(neigh.frac_coords)
print("test")
print(copied_translations_from_ICOHPs[dist_idx])
print(translations_by_distance[neigh_idx])
print(cell_start)
del copied_distances_from_ICOHPs[dist_idx]
del copied_neighbors_from_ICOHPs[dist_idx]
del copied_translations_from_ICOHPs[dist_idx]
break

print(_list_neighsite)
list_neighisite.append(_list_neighisite)
list_neighsite.append(_list_neighsite)
list_lengths.append(lengths_from_ICOHPs)
Expand Down Expand Up @@ -1042,6 +1061,7 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs: list[float] = []
neighbors_from_ICOHPs: list[int] = []
icohps_from_ICOHPs: list[IcohpValue] = []
translation_from_ICOHPs: list[list[int, int, int]] = []

for key, icohp in icohps.items():
atomnr1 = self._get_atomnumber(icohp._atom1)
Expand All @@ -1062,11 +1082,14 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
# add translation to icohp value
translation_from_ICOHPs.append(icohp.translation)
elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

# ONLY_ANION_CATION_BONDS
elif additional_condition == 1:
Expand All @@ -1076,12 +1099,14 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

# NO_ELEMENT_TO_SAME_ELEMENT_BONDS
elif additional_condition == 2:
Expand All @@ -1091,12 +1116,14 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

# ONLY_ANION_CATION_BONDS_AND_NO_ELEMENT_TO_SAME_ELEMENT_BONDS
elif additional_condition == 3:
Expand All @@ -1108,12 +1135,14 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

# ONLY_ELEMENT_TO_OXYGEN_BONDS
elif additional_condition == 4:
Expand All @@ -1123,12 +1152,14 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

# DO_NOT_CONSIDER_ANION_CATION_BONDS
elif additional_condition == 5:
Expand All @@ -1138,12 +1169,14 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

# ONLY_CATION_CATION_BONDS
elif additional_condition == 6 and val1 > 0.0 and val2 > 0.0: # type: ignore[operator]
Expand All @@ -1152,18 +1185,21 @@ def _find_relevant_atoms_additional_condition(
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

elif atomnr2 == site_idx:
neighbors_from_ICOHPs.append(atomnr1)
lengths_from_ICOHPs.append(icohp._length)
icohps_from_ICOHPs.append(icohp.summed_icohp)
keys_from_ICOHPs.append(key)
translation_from_ICOHPs.append(icohp.translation)

return (
keys_from_ICOHPs,
lengths_from_ICOHPs,
neighbors_from_ICOHPs,
icohps_from_ICOHPs,
translation_from_ICOHPs,
)

@staticmethod
Expand Down
Loading