-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_vornoi.py
199 lines (175 loc) · 8.19 KB
/
compute_vornoi.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
'''
Using tess created by https://github.com/wackywendell
This program is built to add functionality to tess as a way to extract more information from vornoi polyhedron.
Might end up trying to build an extension of tess' Cell and container classes which add more object oriented functions
Carter Francis
'''
import numpy as np
from tess import Container
def get_radii(atom_list, radii):
radi_list = atom_list
for num,r in enumerate(radii):
radi_list[atom_list==num+1]=r
return radi_list
def make_container(boundingbox, atom_type, atom_pos, radii=[0.23, 0.14], central_atom=2):
is_cental_atom = atom_type == central_atom
limit = (boundingbox[0][1] - boundingbox[0][0], boundingbox[1][1] - boundingbox[1][0],
boundingbox[2][1] - boundingbox[2][0])
radii = get_radii(atom_type, radii)
cntr = Container(atom_pos, limits=limit, periodic=True, radii=radii)
cntr = [c for is_c, c in zip(is_cental_atom, cntr) if is_c]
return cntr
def get_face_freq(container,edge_thresh=0,face_threshold=0):
vcell_list = [v.vertices() for v in container] # all of the indicies of a face
vlist_list = [v.face_vertices()for v in container] # of the positions of the indiceis
falist_list = [v.face_areas() for v in container] # areas of all of the faces
#print(falist_list)
r_thresh2 = edge_thresh*edge_thresh
indexes = []
for vcell,vlist,falist in zip(vcell_list,vlist_list,falist_list): # unpacks into just the values for one cell
edges = np.zeros(15)
for face, face_area in zip(vlist, falist):
if face_area > face_threshold:
n_edge = 0
for i,index in enumerate(face):
a = index
b = face[(i+1)%len(face)] # wrapping to complete face
dx = vcell[a][0] - vcell[b][0]
dy = vcell[a][1] - vcell[b][1]
dz = vcell[a][2] - vcell[b][2]
r2 = dx*dx+dy*dy+dz*dz
#print(r2)
if r2 > r_thresh2:
n_edge +=1
edges[n_edge] = edges[n_edge]+1
indexes.append(list(np.array(edges,dtype=int)))
#print(indexes)
index,freq, top_top, top_ten_freq = compute_freq(indexes,verbose=True)
return index,freq, top_top, top_ten_freq
def compute_freq(container,verbose=False):
face_frequency = [v.face_freq_table() for v in container]
l = [len(le) for le in face_frequency]
max_size = 15 # much easier than trying to deal with trailing
face_frequency_padded = [f+[0]*(max_size-le) for f,le in zip(face_frequency,l)]
index,freq = np.unique(face_frequency_padded,axis=0, return_counts=True)
top_ten = sorted(range(len(freq)), key=lambda i: freq[i])[-10:]
top_ten_freq = np.divide(freq[top_ten], len(container))
if verbose:
print("The top 10 Vornoi indexes are:")
[print(i,f)for i, f in zip(index[top_ten],top_ten_freq)]
print("The percent sum is:", np.sum(top_ten_freq))
return index, freq, index[top_ten], top_ten_freq
def determine_surface_area(container, verbose=False):
surface_area = [v.surface_area() for v in container]
if verbose:
print(np.shape(surface_area))
print("The max is:", max(surface_area))
print("The min is:", min(surface_area))
print("The Average is:", np.average(surface_area))
return surface_area, np.average(surface_area), np.std(surface_area)
def determine_volume(container,verbose=False):
volume = [v.volume() for v in container]
if verbose:
print("The max is:", max(volume))
print("The min is:", min(volume))
print("The Average is:", np.average(volume))
return volume, np.average(volume),np.std(volume)
def characterize_index(indices,container):
containers = []
average_areas = []
area_stds = []
average_volumes = []
volume_stds = []
for index in indices:
index_container = [c for c in container if list(c.face_freq_table()) == list(np.trim_zeros(index, 'b'))]
containers.append(index_container)
for cont in containers:
_, average_area, area_std = determine_surface_area(cont)
_, average_volume, volume_std = determine_volume(cont)
average_areas.append(average_area)
area_stds.append(area_std)
average_volumes.append(average_volume)
volume_stds.append(volume_std)
return average_areas, area_stds, average_volumes, volume_stds
'''
#Testing
# input position files...
TwoE12Cooling = '/Users/shaw/Shaw/MSE760/FinalProject/2E12Cool/traj.lammpstrj'
OneE12Cooling = '/home/carter/Documents/Classes/760/FinalProject/1E12Cool/traj.lammpstrj'
FiveE11Cooling = '/Users/shaw/Shaw/MSE760/FinalProject760(ExternalCluster)/5E11Cool/traj.lammpstrj'
TwoE11Cooling = '/Users/shaw/Shaw/MSE760/FinalProject760(ExternalCluster)/2E11Cool_2/traj.lammpstrj'
'''
'''
t, n, bb, at, ap = load_traj(OneE12Cooling)
f_time = len(t)-300
cntr = make_container(bb[f_time],at[f_time],ap[f_time])
#get_freq()
#get_index()
#get_volume()
get_face_freq(cntr, 0.1, 0.1)
get_face_freq(cntr, 0)
get_face_freq(cntr, 0.001)
get_face_freq(cntr, 0.02)
get_face_freq(cntr, 0.03)
#print([v.face_freq_table() for v in cntr])
'''
'''
#Eventaully I should make extend the contianer class to just add functionality...
class extended_container(Container):
def __init__(self,boundingbox, atom_type, atom_pos, radii=[0.23, 0.14], central_atom=2):
is_cental_atom = atom_type == central_atom
limit = (boundingbox[0][1] - boundingbox[0][0], boundingbox[1][1] - boundingbox[1][0],
boundingbox[2][1] - boundingbox[2][0])
radi_list = atom_type
for num, r in enumerate(radii):
radi_list[atom_type == num + 1] = r
Container.__init__(self,atom_pos, limits=limit, periodic=True, radii=radi_list)
self.container = [c for is_c, c in zip(is_cental_atom, self) if is_c]
_, _, self.indices, self.ind_freq = self.get_freq()
def get_freq(self, verbose=False):
face_frequency = [v.face_freq_table() for v in self.container]
l = [len(le) for le in face_frequency]
max_size = 15 # much easier than trying to deal with trailing
face_frequency_padded = [f + [0] * (max_size - le) for f, le in zip(face_frequency, l)]
index, freq = np.unique(face_frequency_padded, axis=0, return_counts=True)
top_ten = sorted(range(len(freq)), key=lambda i: freq[i])[-10:]
top_ten_freq = np.divide(freq[top_ten], len(self.container))
if verbose:
print("The top 10 Vornoi indexes are:")
[print(i, f) for i, f in zip(index[top_ten], top_ten_freq)]
print("The percent sum is:", np.sum(top_ten_freq))
return index, freq, index[top_ten], top_ten_freq
def get_surface_area(self, verbose=False):
surface_area = [v.surface_area() for v in self.container]
if verbose:
print(np.shape(surface_area))
print("The max is:", max(surface_area))
print("The min is:", min(surface_area))
print("The Average is:", np.average(surface_area))
return surface_area, np.average(surface_area), np.std(surface_area)
def get_volume(self, verbose=False):
volume = [v.volume() for v in self.container]
if verbose:
print("The max is:", max(volume))
print("The min is:", min(volume))
print("The Average is:", np.average(volume))
return volume, np.average(volume), np.std(volume)
def get_index(self):
containers = []
average_areas = []
area_stds = []
average_volumes = []
volume_stds = []
for index in self.indices:
index_container = [c for c in self.container if list(c.face_freq_table()) == list(np.trim_zeros(index, 'b'))]
containers.append(index_container)
for cont in containers:
_, average_area, area_std = cont.get_surface_area()
_, average_volume, volume_std = determine_volume(cont)
average_areas.append(average_area)
area_stds.append(area_std)
average_volumes.append(average_volume)
volume_stds.append(volume_std)
return average_areas, area_stds, average_volumes, volume_stds
'''