Skip to content

Commit

Permalink
Fix traj parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Nov 21, 2024
1 parent 1f7606c commit ab08e91
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ipi/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def read_trajectory(

file_handle = open(filename, "r")
bohr2angstrom = unit_to_user("length", "angstrom", 1.0)
comment_regex = re.compile(r"([^)]+)\{([^}]+)\}")
comment_regex = re.compile(r"(\w+)\{([^}]+)\}")
step_regex = re.compile(r"Step:\s+(\d+)")

frames = []
Expand Down Expand Up @@ -207,10 +207,10 @@ def read_trajectory(

# parse comment to get the property
matches = comment_regex.findall(ret["comment"])

print("MATCHES ", matches)
# get what we have found
if len(matches) >= 2:
what = matches[-2][0]
if len(matches) == 2:
what = matches[0][0]
else: # defaults to reading positions
what = "positions"

Expand All @@ -219,13 +219,14 @@ def read_trajectory(
if len(matches) >= 1:
frame.info["step"] = int(matches[-1][0])

# if we have forces, set positions to zero (that data is missing!) and set forces instead
# if we have forces, set positions to zero (that data is missing!)
# and set forces instead
if what == "forces":
# set forces and convert to eV/angstrom
frame.positions *= 0
frame.arrays["forces"] = ret["atoms"].q.reshape(
(-1, 3)
) * unit_to_user("force", "ev/ang", 1.0)
) * unit_to_user("force", "ase", 1.0)

frames.append(frame)

Expand Down

0 comments on commit ab08e91

Please sign in to comment.