Skip to content

Commit b123135

Browse files
authored
Merge pull request #511 from zincware/enable_single_snapshot_trajs
lammpstraj: catch empty header for traj with only one time step
2 parents c6cdaca + 842b1a8 commit b123135

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mdsuite/file_io/lammps_trajectory_files.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,19 @@ def _get_species_information(
229229

230230
return species_dict
231231

232-
def _get_sample_rate(self, file, n_particles: int) -> int:
232+
def _get_sample_rate(self, file, n_particles: int) -> typing.Union[int, None]:
233233
first_header = mdsuite.file_io.tabular_text_files.read_n_lines(
234234
file, self.n_header_lines, start_at=0
235235
)
236236
time_step_0 = int(first_header[1]) # Time in first configuration
237237
second_header = mdsuite.file_io.tabular_text_files.read_n_lines(
238238
file, self.n_header_lines, start_at=self.n_header_lines + n_particles
239239
)
240-
time__step_1 = int(second_header[1]) # Time in second configuration
240+
# catch single snapshot trajectory (second_header == [])
241+
if not second_header:
242+
return None
241243

244+
time__step_1 = int(second_header[1]) # Time in second configuration
242245
return time__step_1 - time_step_0
243246

244247

@@ -267,7 +270,7 @@ def extract_properties_from_header(
267270
trajectory_properties : dict
268271
A dict of the form
269272
{'MDSuite_Property_1': [column_indices], 'MDSuite_Property_2': ...}
270-
Example {'Unwrapped_Positions': [2,3,4], 'Velocities': [5,6,7]}
273+
Example {'Unwrapped_Positions': [2,3,4], 'Velocities': [5,6,8]}
271274
"""
272275

273276
column_dict_properties = {

0 commit comments

Comments
 (0)