forked from levkeO/detectInstantons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingPartDist.py
More file actions
161 lines (125 loc) · 4.46 KB
/
Copy pathsingPartDist.py
File metadata and controls
161 lines (125 loc) · 4.46 KB
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
"""Module to calculate distance measures of single particle trajectories
"""
import pylab as pl
import numpy as np
def readCoords(filexyz, numFrames, numPart):
"""
Reads data from an xyz file
Args:
filexyz(string): name of the xyz file to read
numFrames (int): number of frames in file
numPart (int): number of particles
Return:
allCoords (list of list) for each frame a list of all
particles consisting of list of all three coordinates
for each particle (x,y,z)
"""
frame = -1
allCoords = np.zeros((numFrames,numPart,3))
with open(filexyz, 'r') as readFile:
for line in readFile:
splitL = line.split()
if len(splitL) ==1:
frame +=1
if frame == numFrames:
break
particleCounter = 0
elif not splitL[0] == 'Atoms.':
allCoords[frame][particleCounter,0] =splitL[1]
allCoords[frame][particleCounter,1] =splitL[2]
allCoords[frame][particleCounter,2] =splitL[3]
particleCounter+=1
return allCoords
#@njit
def periodic_boundary(xyzArray,L):
"""
Makes sure that the given coordinates are inside the box of Length L (between -L/2 and L/2)
And applies periodic boundary conditions
Origin is in the middle of the box, could be an option to put it at the left later
Args:
xyzArray (array with 3 entries): array with one set of coordinates (3D)
L(int):, length of box, square box assumed
Return:
an xyz-coordinate array inside the box
Examples:
>>> periodic_boundary([1,3,6],10)
[1, 3, -4]
"""
for dim in range(3):
if xyzArray[dim]>L/2 : xyzArray[dim]-=L
if xyzArray[dim]<-L/2 : xyzArray[dim]+=L
return xyzArray
def squareDist(coords, frame1, frame2,L):
"""
Distance between two frames of one particle taking care of boundary
conditions
Args:
coords (list of list): coordinates of one particle for several frames in 3d
frame1 (int): index of first frame to calculate distance
frame2 (int): index of second frame to calculate distance
L(int):, length of box, square box assumed
Return:
squared distance (float)
Example:
dsjkldsyjdsyjkl
"""
dist = coords[frame2,:]-coords[frame1,:]
dist = periodic_boundary(dist,L)
return dist[0]**2 + dist[1]**2 + dist[2]**2
def spaceDists(coords, refCoord,L):
dist = coords-refCoord
dist = periodic_boundary(dist,L)
return dist[0]**2 + dist[1]**2 + dist[2]**2
#@njit
def averageDistPos(coords, start1,end1,start2,end2,reference,L):
# not sure if this is a sensible setup, probably not
dist1 = coords[start1:end1,:]- coords[reference,:]
dist2 = coords[start2:end2,:]- coords[reference,:]
for t in range(len(dist1)):
dist1[t] = periodic_boundary(dist1[t],L)
dist2[t] = periodic_boundary(dist2[t],L)
average1 = dist1.mean(axis=0)
average2 = dist2.mean(axis=0)
distance = average2-average1
distance = periodic_boundary(distance,L)
return distance[0]**2 +distance[1]**2 + distance[2]**2
def averagePos(coords, start1,end1,L):
# not sure if this is a sensible setup, probably not
dist1 = coords[start1:end1,:]#- coords[reference,:]
#dist2 = coords[start2:end2,:]#- coords[reference,:]
for t in range(len(dist1)):
dist1[t] = periodic_boundary(dist1[t],L)
#dist2[t] = periodic_boundary(dist2[t],L)
average = dist1.mean(axis=0)
return average
class singlepathOld:
def __init__(self,part_coord,centre,L):
self.centre = centre
self.L = L
self.part_coord = part_coord
self.create()
def create(self):
self.diffs = np.sqrt([squareDist(self.part_coord,t,self.centre,self.L) for t in range(self.part_coord.shape[0])])
class singlepath:
def __init__(self,part_coord,centre,L):
self.centre = centre
self.L = L
self.part_coord = part_coord
self.create()
def create(self):
self.diffs = np.sqrt([squareDist(self.part_coord,t,self.centre,self.L) for t in range(self.part_coord.shape[0])])
def coarseTraject(allCoords,delta,numFrames,numPart,L):
"""
-200 is in
Coarse grain trajectory by averaging every frame over frame-delta to frame+ delta
"""
newCoords = np.zeros((numFrames-2*delta,numPart,3))
for particle in range(numPart):
for t in range(delta,numFrames-delta):
cenDist = [0,0,0]
for lag in range(-delta,delta+1):
dist = allCoords[t][particle,:]-allCoords[t+lag][particle,:]
dist = periodic_boundary(dist,L)
cenDist+=dist
newCoords[t-delta][particle,:]= allCoords[t][particle,:]+cenDist/(2*delta+1)
return newCoords