Created
March 5, 2019 09:45
-
-
Save yangyushi/21001037663128ce20bf8e465b8b324f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def array_to_xyz(filename, array): | |
""" | |
Append many frames to the same xyz file that ovito can read | |
The file is overwritten everytime | |
array: [frame_1, frame_2, ...] | |
coordinate in one frame: (dimension, number_of_particles) | |
""" | |
if '.xyz' == filename[-4:]: | |
fname = filename | |
else: | |
fname = name + '.xyz' | |
f = open(fname, 'w') | |
f.close() | |
for i, frame in enumerate(array): | |
dim, num = frame.shape | |
with open(fname, 'a') as f: | |
np.savetxt( | |
f, frame.T, | |
delimiter='\t', | |
fmt=['A\t%.8e'] + ['%.8e' for i in range(dim - 1)], | |
comments='', | |
header=f'{num}\nframe {i}' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment