Skip to content

Commit

Permalink
fix tests bug
Browse files Browse the repository at this point in the history
  • Loading branch information
1041176461 committed Dec 28, 2023
1 parent 6daea8c commit d3cd024
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
25 changes: 18 additions & 7 deletions phonopy/interface/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,24 @@ def read_abacus_output(filename):
natom = int(re.search("[0-9]+", line).group())
if re.search(r"TOTAL-FORCE \(eV/Angstrom\)", line):
force = np.zeros((natom, 3))
ver_diff = file.readline()
if "---" not in ver_diff:
for i in range(3):
file.readline()
for i in range(natom):
_, fx, fy, fz = file.readline().split()
force[i] = (float(fx), float(fy), float(fz))
_match_pattern = (
r"^(\s*)([A-Za-z]*[0-9]+)((\s*[-]?[0-9]+\.[0-9]+){3})(.*)$"
)
_match = re.match(_match_pattern, line)
while not _match:
line = file.readline()
_match = re.match(_match_pattern, line)
iatom = 0
while _match:
fx, fy, fz = (_match.group(3).split()[i].strip() for i in range(3))
force[iatom] = (float(fx), float(fy), float(fz))
iatom += 1
if iatom == natom:
break
else:
line = file.readline()
_match = re.match(_match_pattern, line)

if force is None:
raise ValueError("Force data not found.")

Expand Down
3 changes: 2 additions & 1 deletion test/interface/test_abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def test_read_abacus_mag():

def test_read_abacus_output():
"""Test of read abacus output"""
force = read_abacus_output("./NaCl-abacus.out")
force = read_abacus_output(os.path.join(data_dir, "NaCl-abacus.out"))
assert force.mean() < 1e-10
assert force[0][0] + 1.85537138e-02 < 1e-5
print(force)


if __name__ == "__main__":
Expand Down

0 comments on commit d3cd024

Please sign in to comment.