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

i-pi job update #647

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
37 changes: 20 additions & 17 deletions pyiron_contrib/atomistics/ipi/ipi_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,36 @@ def collect_props(self):

@staticmethod
def _collect_traj_helper(filename):
"""
For each snapshot collect the cell box edges and angles and the corresponding atom positions.
"""
f = open(filename)
lines = f.readlines()
# the first line for each snapshot is always the number of atoms.
# Identify the line number where each snapshot starts.
starts = [
i for i, x in enumerate(lines) if x.startswith("#")
] + [len(lines) + 1]
abc = []
ABC = []
traj = []
] + [len(lines) + 1] # and also record at what line number the last snapshot ends
cell_abc = [] # cell box edges
cell_ABC = [] # cell box angles
trajectory = []
start = starts[0]
for stop in starts[1:]:
temp_list = []
for stop in starts[1:]: # ignore the numer of atoms line
snap_lines = lines[start:stop - 1]
for i, l in enumerate(snap_lines):
split_l = l.split()
if i != 0:
temp_list.append([float(j) for j in split_l[1:]])
else:
abc.append([float(j) for j in split_l[2:5]])
ABC.append([float(j) for j in split_l[5:8]])
# second line contains the cell data. Collect it.
zeroth_line_values = [n for n in snap_lines[0].split()]
cell_abc.append(np.array(zeroth_line_values[2:5], dtype=float)) # collect cell box edges
cell_ABC.append(np.array(zeroth_line_values[5:8], dtype=float)) # collect cell box angles
# the remaining lines of the snapshot contain the positions/forces. Collect them.
temp_list = []
for l in snap_lines[1:]:
temp_list.append([float(n) for n in l.split()[1:]]) # first column is the species. Ignore it.
trajectory.append(temp_list)
start = stop
Copy link
Member

Choose a reason for hiding this comment

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

I still find this formulation really difficult to read. Could you switch it with start = starts[i-1] and move it up to the top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

starts[i-1] will become starts[-1] when i=0. I kept it this way to avoid this. Looking at it again, I think start=starts[i] at the beginning of the loop should work.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at it again, I think start=starts[i] at the beginning of the loop should work.

Good catch! Yeah, that should be perfect

traj.append(temp_list)
f.close()
return np.array(abc), np.array(ABC), np.array(traj)
return np.array(cell_abc), np.array(cell_ABC), np.array(trajectory)

def collect_trajectory(self):
#digits = "{0:0" + str(len(str(self.custom_input.n_beads))) + "}"
#f = open(self.working_directory + '/ipi_out.pos_' + digits.format(0) + '.xyz')
positions_out = self._collect_traj_helper(self.working_directory + '/ipi_out.pos.xyz')
forces_out = self._collect_traj_helper(self.working_directory + '/ipi_out.for.xyz')
self.custom_output.cell_abc = np.array(positions_out[0])
Expand Down