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

Adapt to the latest version of PWmat output file #3823

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 7 additions & 7 deletions pymatgen/io/pwmat/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ class ListLocator(MSONable):
"""Find the element indices (starts from 0) of a certain paragraph of text from the list."""

@staticmethod
def locate_all_lines(strs_lst: list[str], content: str) -> list[int]:
def locate_all_lines(strs_lst: list[str], content: str, exclusion: str | None = None) -> list[int]:
"""Locate the elements in list where a certain paragraph of text is located (return all indices)

Args:
strs_lst (list[str]): List of strings.
content (str): Certain paragraph of text that needs to be located.
exclusion (str): Certain paragraph of text that is excluded.
"""
str_idxs: list[int] = [] # starts from 0 to be compatible with list
str_no: int = -1
for tmp_str in strs_lst:
str_no += 1
if content.upper() in tmp_str.upper():
if (content.upper() in tmp_str.upper()) and (not exclusion or exclusion.upper() not in tmp_str.upper()):
str_idxs.append(str_no)
return str_idxs

Expand Down Expand Up @@ -277,13 +278,13 @@ def get_e_tot(self) -> np.ndarray:
"""
# strs_lst:
# [' 216 atoms', 'Iteration (fs) = 0.3000000000E+01',
# ' Etot', 'Ep', 'Ek (eV) = -0.2831881714E+05 -0.2836665392E+05 0.4783678177E+02',
# ' Etot', 'Ep', 'Ek = -0.2831881714E+05 -0.2836665392E+05 0.4783678177E+02',
# ' SCF = 7']
strs_lst = self.strs_lst[0].split(",")
aim_index = ListLocator.locate_all_lines(strs_lst=strs_lst, content="EK (EV) =")[0]
aim_index = ListLocator.locate_all_lines(strs_lst=strs_lst, content="EK")[0]
# strs_lst[aim_index].split() :
# ['Ek', '(eV)', '=', '-0.2831881714E+05', '-0.2836665392E+05', '0.4783678177E+02']
return np.array([float(strs_lst[aim_index].split()[3].strip())])
return np.array([float(strs_lst[aim_index].split("=")[1].split()[0].strip())])

def get_atom_energies(self) -> np.ndarray | None:
"""Return the energies of individual atoms in material system.
Expand Down Expand Up @@ -315,8 +316,7 @@ def get_atom_forces(self) -> np.ndarray:
"""
forces = []
aim_content = "Force".upper()
aim_idx = ListLocator.locate_all_lines(strs_lst=self.strs_lst, content=aim_content)[0]

aim_idx = ListLocator.locate_all_lines(strs_lst=self.strs_lst, content=aim_content, exclusion="average")[0]
for line in self.strs_lst[aim_idx + 1 : aim_idx + self.num_atoms + 1]:
# ['14', '0.089910342901203', '0.077164252174742', '0.254144099204679']
forces.append([float(val) for val in line.split()[1:4]])
Expand Down
Binary file modified tests/files/io/pwmat/MOVEMENT.lzma
Binary file not shown.