-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_radial_correlations.py
executable file
·166 lines (132 loc) · 4.78 KB
/
compute_radial_correlations.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
import rust
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as clr
import cmasher as cmr
import hickle as hkl
import sys
import os
file_path = sys.argv[1]
[dname,file_name] = os.path.split(file_path)
dname = os.path.abspath(dname)
if '.hkl' in file_path:
points = hkl.load(file_path)[:,:-1]
elif '.txt' in file_path:
with open(file_path, 'r') as file:
first_line = file.readline()
# Determine the delimiter based on the first line
if ',' in first_line:
delimiter = ','
elif ' ' in first_line:
delimiter = ' '
else:
raise NotImplementedError("Delimiter not identified")
points = np.loadtxt(file_path, delimiter=delimiter)[:,0:2]
else:
print("Wrong file format")
sys.exit()
ndim = points.shape[1]
npoints = points.shape[0]
points -= points.min()
points /= points.max()
boxsize = 1.0
radius = boxsize / (npoints)**(1.0/ndim)
binsize = radius / 20.0
periodic = False
connected = False
logscaleplot = False
print(f"Found {npoints} points in {ndim}d")
if ndim == 2:
boop_orders = np.array([6])
boops = rust.compute_2d_boops(points, boop_orders, boxsize, periodic)
print(boops.shape)
_, gboop = rust.compute_radial_correlations_2d(points, boops[:,-1,:], boxsize, binsize, periodic,connected)
order = 60
nK =300
peak_angle = 0
# nK = 82.3286
# peak_angle = 2*np.pi/6.0 * (2.27)/(2.0*np.pi)
K = 2.0 * np.pi * nK / boxsize
exponent = K * points[:,0] * np.cos(peak_angle) + K * points[:,1] * np.sin(peak_angle)
translational_x = np.cos(exponent)
translational_y = np.sin(exponent)
translational = np.vstack([translational_x,translational_y]).T
np.savetxt(file_name+"_translational_"+str(nK)+".csv", translational)
radial_rdf, corr = rust.compute_radial_correlations_2d(points, translational, boxsize, binsize, periodic, connected)
_, or_corr = rust.compute_radial_gyromorphic_corr_2d(points, boxsize, binsize, periodic, order)
elif ndim == 3:
dummy = np.ones(points.shape[0]).reshape(-1,1)
radial_rdf, _ = rust.compute_radial_correlations_3d(points, dummy, boxsize, binsize, periodic, connected)
nbins = radial_rdf.shape[0]
bins = (np.arange(0, nbins) + 0.5)*binsize
print(bins.shape)
if connected:
suffix = "_connected"
else:
suffix = ""
np.savetxt(file_name+"_radial_rdf.csv", np.vstack([bins,radial_rdf]).T)
fig = plt.figure()#figsize=(10,10))
ax = fig.gca()
pc = ax.plot(bins, radial_rdf,c=cmr.ember(0.5))
ax.tick_params(labelsize=18)
ax.set_xlabel(r"$r$",fontsize=18)
ax.set_ylabel(r"$g(r)$",fontsize=18)
plt.savefig(file_name+"_radial_rdf.png", bbox_inches = 'tight',pad_inches = 0, dpi = 300)
plt.close()
sys.exit()
else:
print("Wrong dimensionality!")
nbins = radial_rdf.shape[0]
bins = (np.arange(0, nbins) + 0.5)*binsize
print(bins.shape)
if connected:
suffix = "_connected"
else:
suffix = ""
#np.savetxt("points.csv", points)
np.savetxt(file_name+"_radial_rdf.csv", np.vstack([bins,radial_rdf]).T)
np.savetxt(file_name+"_radial_corr"+suffix+".csv", np.vstack([bins,corr[:,0]+corr[:,1]]).T)
data = np.loadtxt(file_name+"_radial_rdf.csv")
bins = data[:,0]
radial_rdf = data[:,1]
fig = plt.figure()#figsize=(10,10))
ax = fig.gca()
ax.set_xlim(0,0.5)
pc = ax.plot(bins, radial_rdf,c=cmr.ember(0.5))
ax.tick_params(labelsize=18)
ax.set_xlabel(r"$r$",fontsize=18)
ax.set_ylabel(r"$g(r)$",fontsize=18)
plt.savefig(file_name+"_radial_rdf.png", bbox_inches = 'tight',pad_inches = 0, dpi = 300)
plt.close()
fig = plt.figure(figsize=(10,10))
ax = fig.gca()
pc = ax.plot(bins, corr[:,0]+corr[:,1])
ax.set_xlim(0,0.5)
plt.savefig(file_name+"_radial_corr_"+str(nK)+suffix+".png", dpi = 300)
plt.close()
np.savetxt(file_name+"_radial_gboop"+suffix+ ".csv", np.vstack([bins,gboop[:,0]+gboop[:,1]]).T)
fig = plt.figure(figsize=(10,10))
ax = fig.gca()
pc = ax.plot(bins, gboop[:,0]+gboop[:,1])
ax.set_xlim(0,0.5)
plt.savefig(file_name+"_radial_gboop"+suffix+".png", dpi = 300)
plt.close()
fig = plt.figure(figsize=(10,10))
ax = fig.gca()
pc = ax.plot(bins, np.sqrt(or_corr[:,0]**2+or_corr[:,1]**2))
ax.set_xlim(0,0.5)
plt.savefig(file_name+"_radial_orcorr.png", dpi = 300)
plt.close()
fig = plt.figure(figsize=(10,10))
ax = fig.gca()
pc = ax.plot(bins, np.sqrt(or_corr[:,0]**2+or_corr[:,1]**2)/np.where(radial_rdf == 0, 1, bins * radial_rdf))
ax.set_xlim(0,0.5)
ax.set_ylim(0,1)
plt.savefig(file_name+"_radial_orcorr_normalizationtests.png", dpi = 300)
plt.close()
np.savetxt(file_name+"_boop"+str(boop_orders[-1])+"_test.csv", np.vstack([boops[:,-1,0],boops[:,-1,1]]).T)
fig = plt.figure(figsize=(10,10))
ax = fig.gca()
pc = ax.scatter(boops[:,-1,0], boops[:,-1,1])
plt.savefig(file_name+"psi"+str(boop_orders[-1])+"_test.png", dpi = 300)
plt.close()