Skip to content

Instantly share code, notes, and snippets.

@Roninkoi
Created May 9, 2023 08:44
Show Gist options
  • Select an option

  • Save Roninkoi/b7acbc48b11c3dec37b31d490ca5e582 to your computer and use it in GitHub Desktop.

Select an option

Save Roninkoi/b7acbc48b11c3dec37b31d490ca5e582 to your computer and use it in GitHub Desktop.
Extract last frame of LAMMPS xyz file
#!/bin/env python3
# Extract last frame from LAMMPS xyz dump file
# inpath and write it to outpath
inpath = "AgNWSiO2.xyz"
outpath = "data.AgNWSiO2"
df = open(inpath, "r")
buf = []
i = 0
for l in df:
# ITEM: TIME
# ITEM: TIMESTEP
if "ITEM: TIME" in l:
buf.clear()
print("Step:", i)
i += 1
buf.append(l)
df.close()
df = open(outpath, "w")
for l in buf:
df.write(l)
df.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment