-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysFlow.py
290 lines (264 loc) · 11.8 KB
/
AnalysFlow.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
from tool import *
from result_log import *
from tool_reactCount import generateReactions
import json
import pickle
import copy
import sys,os
from math import isnan
import global_var as gvar
import networkx as nx
import time
def trackBlocksXYZ():
Rstep = []
speRec = []
tempList=[]
printed = []
istep = 1
step = 1
pbc = gvar.pbcmole
bnd_cri = 1.5 # Criterion for bond linkage
fnames = gvar.trajFiles
bnd_cri = gvar.bnd_cri
# 1. read xyz data in
for fname in fnames:
with open(fname,'r') as f:
if (istep == 1):
#gvar.pbcXYZ = PBCRec[istep-1]
print(gvar.pbcXYZ)
# First Record:
p_time = time.time()
Natom = int(f.readline())
gvar.atomList = [0]*Natom # BuildUpAtomListi
temGrpRec= [[0]*2 for i in range(Natom)]
f.readline()
for i in range(Natom):
line = f.readline().split()
gvar.atomList[i] = \
[line[0],[float(line[1]),float(line[2]),float(line[3])],[]]
# ^ ^ ^
# ele.Name, element coordinate, neighbor
# Initialize global Mask Matrix
Element = [row[0] for row in gvar.atomList]
radii_array = np.array([*map(gvar.radii_dict.get, Element)])
radii_array = np.tile(radii_array,(len(Element),1))
gvar.GlobalMaskMat = (radii_array+radii_array.T)*bnd_cri
np.fill_diagonal(gvar.GlobalMaskMat,-1)
# Build atom list.
grpRec,nMol = buildNeigh_AtomicBased(10) # 20 anstrom into neighbour :::: Can be parallel
#print(nMol)
print("--- neighbor %s seconds1 ---" % (time.time() - p_time))
p_time = time.time()
gvar.blockList = [[0]*7 for i in range(nMol)] # BuildUpBlockList
Molid = 1
# Initial block
for rec in grpRec:
gvar.blockList[Molid-1][0] = Molid
gvar.blockList[Molid-1][1] = list(map(int,rec))
Molid = Molid+1
if(pbc):
BlockInfoUpdatePBC(bnd_cri) #:::: Can be parallel
printUnknowStruc() #:::: Can be parallel
else:
# for future develope AIMD-base non-fragment
pass
print(gvar.atomList[12])
print("--- neighbor %s seconds2 ---" % (time.time() - p_time))
p_time = time.time()
P_blockList = copy.deepcopy(gvar.blockList)
while True:
# if (debug): print(istep,step,len(blockList))
line = f.readline()
# Analyse Finished for one file.
if not line:
printUnknowStruc()
NodeTranslation("Graph_5000.dot")
gvar.DicReactionRec = generateReactions(gvar.GR)
PrintMetaDataRaw()
break
Natom =int(line)
f.readline()
for i in range(Natom):
line = f.readline().split()
#gvar.atomList[i] = \
#[line[0],[float(line[1]),float(line[2]),float(line[3])],[]]
#
gvar.atomList[i][1] =[float(line[1]),float(line[2]),float(line[3])]
if(istep%80 == 0):
print("number of Mol:",nMol)
printUnknowStruc()
if(istep%1000 == 0):
print("--- %s seconds ---" % (time.time() - p_time))
p_time = time.time()
print(istep)
if(istep%20 == 0):
time_neibor1 = time.time()
BlockNeighborUpdate(5)
time_neibor2 = time.time()
print("Neibor --- %s seconds ---" % (time_neibor2 - time_neibor1))
if(istep%1 == 0 and istep !=1 ):
p_1 = time.time()
if(pbc):
time_grp1 = time.time()
grpRec,nMol = buildDistMart(bnd_cri)
time_grp2 = time.time()
print("Group --- %s seconds ---" % (time_grp2 - time_grp1))
else:
pass
gvar.blockList = [[0]*7 for i in range(nMol)] # BuildUpBlockList
Molid = 1
for rec in grpRec:
gvar.blockList[Molid-1][0] = Molid
gvar.blockList[Molid-1][1] = list(map(int,rec))
Molid = Molid+1
p_2 = time.time()
if(pbc):
time_blk1 = time.time()
BlockInfoUpdatePBC(bnd_cri)
time_blk2 = time.time()
print("Block --- %s seconds ---" % (time_blk2 - time_blk1))
else:
pass
p_3 = time.time()
# Build Reaction Connection.
compare2Step(P_blockList, gvar.blockList, istep-1)
#
P_blockList = copy.deepcopy(gvar.blockList)
istep = 1+istep
return(tempList)
def trackBlocksLAMMPS():
Rstep = []
speRec = []
istep = 0
pbc = gvar.pbcmole
bnd_cri = 1.5 # Criterion for bond linkage
fnames = gvar.trajFiles
bnd_cri = gvar.bnd_cri
COORcount = -1
Natom = 0
# 1. read xyz data in
readFlag = 0 # 1. number of atoms; 2. Box bounds 3. Coord
for fname in fnames:
with open(fname,'r') as f:
while True:
line = f.readline()
# File-read Finished
if not line:
write_dot(gvar.GR,"G1cores.dot")
print(gvar.GR.number_of_edges())
printUnknowStruc()
NodeTranslation("Graph_5000.dot")
gvar.DicReactionRec = generateReactions(gvar.GR)
PrintMetaDataRaw()
break
if("NUMBER OF ATOMS" in line):
readFlag = 1
istep = istep+1
continue
if("BOUNDS" in line):
readFlag = 2
PBCcount = 0
pbcXYZList = [[0,0,0],[0,0,0]]
continue
if("x y z" in line):
readFlag = 3
lineSList = line.split()
lineSList.remove("ATOMS")
iatom = lineSList.index('id') - 1
ielement = lineSList.index('type') - 1
x = lineSList.index('x') - 1
y = lineSList.index('y') - 1
z = lineSList.index('z') - 1
#print(iatom,ielement,x,y,z)
COORcount = 0
continue
if(readFlag == 0): continue
if(readFlag == 1):
Natom =int(line)
if(istep ==1):gvar.atomList = [0]*Natom
readFlag = 0
continue
if(readFlag == 2):
pbcXYZList[0][PBCcount] = float(line.split()[0])
pbcXYZList[1][PBCcount] = float(line.split()[1])
PBCcount = PBCcount +1
if(PBCcount==3):
readFlag = 0
gvar.pbcXYZ =[tuple(pbcXYZList[0]),tuple(pbcXYZList[1])]
continue
if(readFlag == 3):
CoorRec = line.split()
COORcount = COORcount +1
element = gvar.lmpAtmDict[int(CoorRec[ielement])]
if(istep == 1):
gvar.atomList[int(CoorRec[iatom])-1] = \
[element,[float(CoorRec[x]),float(CoorRec[y]),float(CoorRec[z])],[]]
else:
gvar.atomList[int(CoorRec[iatom])-1][1] = \
[float(CoorRec[x]),float(CoorRec[y]),float(CoorRec[z])]
if(COORcount == Natom):
readFlag = 0
# AtomList RenerFinished. Analysis begin
if(COORcount == Natom ):
if(istep ==1):
# Initialize global Mask Matrix
Element = [row[0] for row in gvar.atomList]
radii_array = np.array([*map(gvar.radii_dict.get, Element)])
radii_array = np.tile(radii_array,(len(Element),1))
gvar.GlobalMaskMat = (radii_array+radii_array.T)*bnd_cri
np.fill_diagonal(gvar.GlobalMaskMat,-1)
#Build neiborList and calculate first steps of molecules
grpRec,nMol = buildNeigh_AtomicBased(10) # 10 anstrom into neighbour :::: Can be parallel
#print(nMol)
gvar.blockList = [[0]*7 for i in range(nMol)] # BuildUpBlockList
Molid = 1
# Initial block
for rec in grpRec:
gvar.blockList[Molid-1][0] = Molid
gvar.blockList[Molid-1][1] = list(map(int,rec))
Molid = Molid+1
if(pbc):
BlockInfoUpdatePBC(bnd_cri) #:::: Can be parallel
printUnknowStruc() #:::: Can be parallel
else:
# for future develope AIMD-base non-fragment
pass
print(gvar.atomList[12])
P_blockList = copy.deepcopy(gvar.blockList)
if(istep%1 == 0 and istep !=1 ):
if(pbc):
time_grp1 = time.time()
grpRec,nMol = buildDistMart(bnd_cri)
time_grp2 = time.time()
else:
pass
gvar.blockList = [[0]*7 for i in range(nMol)] # BuildUpBlockList
Molid = 1
for rec in grpRec:
gvar.blockList[Molid-1][0] = Molid
gvar.blockList[Molid-1][1] = list(map(int,rec))
Molid = Molid+1
if(pbc):
time_blk1 = time.time()
BlockInfoUpdatePBC(bnd_cri)
time_blk2 = time.time()
print("Block --- %s seconds ---" % (time_blk2 - time_blk1))
else:
pass
# Build Reaction Connection.
compare2Step(P_blockList, gvar.blockList, istep-1)
#
P_blockList = copy.deepcopy(gvar.blockList)
if(istep%80 == 0):
print("number of Mol:",nMol)
printUnknowStruc()
if(istep%1 == 0):
time_neibor1 = time.time()
BlockNeighborUpdate(5)
time_neibor2 = time.time()
print("Neibor --- %s seconds ---" % (time_neibor2 - time_neibor1))
# print(readFlag,Natom,gvar.pbcXYZ)
# print(gvar.atomList[0],istep)
# print(gvar.atomList[1],istep)
#print(CoorRec[ielement],CoorRec[iatom],CoorRec[x],CoorRec[y],CoorRec[z])
return(tempList)