-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.py
96 lines (89 loc) · 3.2 KB
/
load.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'''
Loading the positions from a traj file. May add additional support for different file types.
Carter Francis
'''
import numpy as np
def load_traj(file_name):
with open (file_name) as traj:
file_list = [line.strip(" \n").split(" ") for line in traj]
timestep = []
num_atoms = []
box_bounds = []
atoms_pos = []
#This shouldn't work and I don't know why it does but whatever....
for line in file_list:
if "ITEM:" in line:
holder = []
id = line[1]
if id is not None:
if "TIMESTEP" == id:
timestep.append(holder)
elif "NUMBER" == id:
num_atoms.append(holder)
elif "BOX" == id:
box_bounds.append(holder)
elif "ATOMS" == id:
atoms_pos.append(holder)
else:
holder.append(line)
position = []
atom_type = []
for positions in atoms_pos:
position_holder = []
atom_holder = []
for pos in positions:
atom_holder.append(pos[1])
position_holder.append(pos[2:5])
atom_type.append(atom_holder)
position.append(position_holder)
position=np.float_(position)
box_bounds = np.float_(box_bounds)
atom_type = np.float_(atom_type)
return timestep, num_atoms, box_bounds, atom_type,position
# There is probably a better way to do this. This just seaches for the heading and prints the values below that...
def read_lammps_out(out_file, heading):
with open(out_file) as f:
thermo=[]
read = False
for line in f:
if "Loop time" in line:
read = False
if read:
# How many times can you cast one thing....
thermo.append(list(np.array(line.rstrip("\n").split(), dtype=float)))
if heading in line:
read = True
headings = heading.split()
print(headings)
thermo = [x for x in zip(*thermo)]
return thermo, headings
def reduce(filename,lammps_out,datapoints):
'''
Notice that the timestep needs to be a multiple of the traj output...
:param filename:
:param lammps_out:
:param timestep:
:return:
'''
timestep, num_atoms, box_bounds, atom_type, position = load_traj(filename)
stable_len = 154
seperation = len(position[stable_len:])/datapoints
indexes = [int(stable_len+np.floor(i*seperation))for i in range(0,datapoints)]
indexes = indexes
p = position[indexes]
na = np.reshape(num_atoms,len(num_atoms))[indexes]
bb = box_bounds[indexes]
at = atom_type[indexes]
print(np.shape(timestep))
print(indexes)
ts = np.reshape(timestep,len(timestep))[indexes]
thermo, headings = read_lammps_out(lammps_out,"Step Temp Press TotEng PotEng Enthalpy")
ind=list(np.array(np.multiply(indexes,5),dtype=int)) # pythp
print(ind)
temp = np.reshape(thermo[1], len(thermo[1]))[ind] # python is broken... it hates reslicing...
return p,na, bb, at, ts, temp
'''
reduce('/home/carter/Documents/Classes/760/FinalProject/1E12Cool/traj.lammpstrj',
'/home/carter/Documents/Classes/760/FinalProject/1E12Cool/out_1E12.lammps',100)
'''