Skip to content

Commit fda6a74

Browse files
minor fixes
1 parent c38b833 commit fda6a74

16 files changed

+1025884
-3495
lines changed

10_onion_plots.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#%%
1+
# COMPUTE ONION
2+
# THIS CODE USES A DEPRECATED VERSION OF ONION
3+
# CONSIDER TO CHANGE THIS CODE WITH THE NEW VERSION
24
import os
35
import shutil
46
from pathlib import Path

11_onion_results.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#%%
21
import numpy as np
32
import matplotlib.pyplot as plt
43
from matplotlib.ticker import MaxNLocator

1_compute_hdf5.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
#%% Libraries
1+
#THIS CODE IS USED TO CONVERT .GRO AND .XTC TRAJECTORY INTO
2+
#HDF5 DATABASE
3+
#.GRO AND .XTC ZENODO LINK CAN BE FOUND IN THE ARTICLE
4+
5+
#Libraries
26
import MDAnalysis as mda
37
import dynsight
48
import h5py
59
import numpy as np
6-
#%% HDF5 file build
10+
# HDF5 file build
711
print(f"{'-'*10}\nSTART INITILIAZIATION PART\n{'-'*10}")
812
traj_name = "ice_water_O"
913
simulation_folder = "simulation"
@@ -21,6 +25,7 @@
2125
u = mda.Universe(topo_file,traj_file)
2226
dynsight.hdf5er.mda_to_hdf5(u, out_file, "ice_water")
2327
in_file = out_file
28+
#O atoms will be used as reference
2429
with h5py.File(in_file,"r") as file:
2530
dataset_box = file["Trajectories"]["ice_water"]["Box"]
2631
dataset_traj = file["Trajectories"]["ice_water"]["Trajectory"]
@@ -36,10 +41,11 @@
3641
file["Trajectories"][traj_name].create_dataset("Box", data=box)
3742
file["Trajectories"][traj_name].create_dataset("Trajectory", data = Ox_traj, chunks=(100,len(Ox_types),3))
3843
file["Trajectories"][traj_name].create_dataset("Types", data = Ox_types)
39-
44+
#Prepare for descriptors computation...
4045
file.create_group("LENS")
4146
file.create_group("SOAP")
4247
steps = Ox_traj.shape[0]
4348
atoms = Ox_traj.shape[1]
49+
#Just check
4450
print("\nReading HDF5 file:\n")
4551
print(f"Number of steps: {steps}\nNumber of particles: {atoms}\n")

2_compute_LENS.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE LENS DESCRIPTOR
22
import h5py
33
import numpy as np
44
import dynsight
5+
#LENS cutoff
56
LENS_CUTOFF = 10
6-
#%%
7+
#Load HDF5 file (see code 1_*)
78
in_file = "ice_water_O.hdf5"
89
traj_name = "ice_water_O"
910
frames_range = slice(0,500)
@@ -23,7 +24,8 @@
2324
with h5py.File(in_file, "r") as file:
2425
LENS = np.array(file["LENS"][f"LENS_{int(LENS_CUTOFF)}"][0,:,:])
2526
np.save(f"arrays/LENS_{int(LENS_CUTOFF)}",LENS)
26-
# %% Spatial smoothing
27+
28+
# Local denoising (Spatial smoothing)
2729
input_file = "ice_water_O.hdf5"
2830
with h5py.File(input_file, "r") as file:
2931
traj_array = np.array(file["Trajectories/ice_water_O/Trajectory"])
@@ -44,5 +46,3 @@
4446
cutoff=cutoff,
4547
volume_shape = volume_shape)
4648
np.save(res_array,averaged.T)
47-
48-
# %%

3_compute_SOAP.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE SOAP DESCRIPTOR
22
import h5py
33
import dynsight
44
import numpy as np
5+
#SOAP cutoff
56
SOAP_CUTOFF = 10
67

7-
# %%
88
traj_name = "ice_water_O"
99
in_file = f"{traj_name}.hdf5"
1010

@@ -26,10 +26,9 @@
2626
filled_soap = dynsight.soapify.fill_soap_vector_from_dscribe(soap,lmax=8,nmax=8)
2727
with h5py.File(in_file, "a") as file:
2828
file["SOAP"][f"SOAP_{int(SOAP_CUTOFF)}"].create_dataset("fill_SOAP", data=filled_soap)
29-
#np.save(f"arrays/SOAP_{int(SOAP_CUTOFF)}", soap)
3029
np.save(f"arrays/fullvect_SOAP_{int(SOAP_CUTOFF)}", filled_soap)
3130

32-
# %% Spatial smoothing
31+
# Local denoising (Spatial smoothing)
3332
input_file = "ice_water_O.hdf5"
3433
with h5py.File(input_file, "r") as file:
3534
traj_array = np.array(file["Trajectories/ice_water_O/Trajectory"])

4_compute_PCA.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE THE PCA ON SOAP
22
import numpy as np
33
from sklearn.decomposition import PCA
44
import matplotlib.pyplot as plt
55
import pandas as pd
6+
#SOAP cutoff
67
SOAP_CUTOFF = 10
8+
#number of PCA components
79
pc_components = 3
8-
#%%
910
print(f"{'-'*10}\nPCA SOAP\n{'-'*10}")
1011
soap_av = np.load(f"arrays/fullvect_SOAP_{SOAP_CUTOFF}.npy")
1112
print(soap_av.shape)
@@ -14,9 +15,10 @@
1415
pca = PCA(n_components=pc_components)
1516
pc_soap = pca.fit_transform(SOAP)
1617
np.save(f"arrays/SOAP_{SOAP_CUTOFF}_PC1.npy",np.transpose(pc_soap[:,0].reshape(500,2048)))
18+
#To compute other components....
1719
#np.save(f"arrays/SOAP_{SOAP_CUTOFF}_PC2.npy",np.transpose(pc_soap[:,1].reshape(500,2048)))
1820
#np.save(f"arrays/SOAP_{SOAP_CUTOFF}_PC3.npy",np.transpose(pc_soap[:,2].reshape(500,2048)))
19-
# %%
21+
2022
print(f"{'-'*10}\nPCA SP SOAP\n{'-'*10}")
2123
sp_cutoff = [10]
2224
for cutoff in sp_cutoff:
@@ -27,6 +29,7 @@
2729

2830
pca = PCA(n_components=pc_components)
2931
pc_soap = pca.fit_transform(SOAP)
32+
#To save other components....
3033
np.save(f"arrays/sp_{cutoff}_SOAP_{SOAP_CUTOFF}_PC1.npy",np.transpose(pc_soap[:,0].reshape(500,2048)))
3134
#np.save(f"arrays/sp_{cutoff}_SOAP_{SOAP_CUTOFF}_PC2.npy",np.transpose(pc_soap[:,1].reshape(500,2048)))
3235
#np.save(f"arrays/sp_{cutoff}_SOAP_{SOAP_CUTOFF}_PC3.npy",np.transpose(pc_soap[:,2].reshape(500,2048)))

5_compute_disp.py renamed to 5_compute_vel.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE VELOCITIES
22
import h5py
33
import numpy as np
44
import dynsight
5-
#%%
5+
6+
#100 ps
7+
sampling = 100
68
def read_from_xyz(filename):
79
with open(filename, "r") as file:
810
lines = file.readlines()
@@ -66,12 +68,12 @@ def compute_displacement(absolute,box):
6668
traj_array = traj_array.transpose(1,0,2)
6769
box_array = np.array(file[f"Trajectories/{traj_name}/Box"])
6870
trajectory = traj_array
69-
#disp_abs = compute_displacement(True)
71+
7072
disp_rel = compute_displacement(False,box_array)
71-
disp_rel = disp_rel / 100
73+
disp_rel = disp_rel / sampling
7274
np.save("arrays/vel.npy", disp_rel)
73-
#np.save("arrays/disp_abs.npy", disp_abs)
74-
# %% Spatial smoothing
75+
76+
# Local denoising (Spatial smoothing)
7577
input_file = "ice_water_O.hdf5"
7678
with h5py.File(input_file, "r") as file:
7779
traj_array = np.array(file["Trajectories/ice_water_O/Trajectory"])

6_compute_CN.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE Nneigh
22
import h5py
33
import MDAnalysis as mda
44
import numpy as np
55
from MDAnalysis.analysis.distances import distance_array
66
import dynsight
77

8+
#Nneigh cutoff..
89
nn_cutoff = 10
9-
#%%
1010
def compute_distance(p1, p2, Lx, Ly, Lz):
1111
dp = np.abs(p2-p1)
1212
dp = np.minimum(dp, np.array([Lx,Ly,Lz]) - dp)
@@ -16,7 +16,6 @@ def compute_distance(p1, p2, Lx, Ly, Lz):
1616
topo_file = f"{simulation_folder}/ice_water.gro"
1717
traj_file = f"{simulation_folder}/ice_water_500.xtc"
1818
u = mda.Universe(topo_file, traj_file)
19-
#selected_atoms = u.select_atoms("type 1 or type 2")
2019
print(u.dimensions)
2120

2221

@@ -32,7 +31,7 @@ def compute_distance(p1, p2, Lx, Ly, Lz):
3231
nn = nn.T
3332
np.save(f"arrays/nn_{nn_cutoff}.npy", nn[::3,:])
3433

35-
# %% Spatial smoothing
34+
# Local denoising (Spatial smoothing)
3635
input_file = "ice_water_O.hdf5"
3736
with h5py.File(input_file, "r") as file:
3837
traj_array = np.array(file["Trajectories/ice_water_O/Trajectory"])

7_compute_dist5.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE d5
22
import h5py
33
import MDAnalysis as mda
44
import numpy as np
55
from MDAnalysis.analysis.distances import distance_array
66
import dynsight
77

8-
#%%
98
print(f"{'-'*10}\nDIST 5\n{'-'*10}")
109
simulation_folder = "simulation"
1110
topo_file = f"{simulation_folder}/ice_water.gro"
@@ -20,14 +19,12 @@
2019
id = np.argsort(distances)
2120
for i in range(0,6):
2221
print(f"atom {i}) coord: {selection.positions[i]}")
23-
#print(f"distances: {sort_distances[0,1:5]}")
24-
#print(f"id: {id[0,1:5]}")
2522
for i in range(sort_distances.shape[0]):
2623
dist_5[i,a] = sort_distances[i,5]
2724
a += 1
2825
dist_5 = np.array(dist_5)
2926
np.save("arrays/dist_5.npy",dist_5)
30-
# %% Spatial smoothing
27+
# Local denoising (Spatial smoothing)
3128
input_file = "ice_water_O.hdf5"
3229
with h5py.File(input_file, "r") as file:
3330
traj_array = np.array(file["Trajectories/ice_water_O/Trajectory"])

8_compute_OTO.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#%%
1+
#THIS CODE IS USED TO COMPUTE q_tet
22
import numpy as np
33
import h5py
44
import dynsight
5-
#%%
5+
66
def read_from_xyz(filename):
77
with open(filename, "r") as file:
88
lines = file.readlines()
@@ -146,7 +146,7 @@ def compute_oto(filename, box):
146146
# write_xyz(trajectory,q,"oto.xyz", "Properties=pos:R:3:color:S:1")
147147
np.save("arrays/OTO.npy",q)
148148

149-
# %% Spatial smoothing
149+
# Local denoising (Spatial smoothing)
150150
input_file = "ice_water_O.hdf5"
151151
with h5py.File(input_file, "r") as file:
152152
traj_array = np.array(file["Trajectories/ice_water_O/Trajectory"])

9_compute_checks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#%%
1+
# JUST CHECK
22
import numpy as np
33
import os
44

@@ -15,4 +15,3 @@
1515
for d in descriptors:
1616
arr = np.load(f"arrays/{d}")
1717
print(f"descriptor: {d[:-4].ljust(20)} - shape: {arr.shape}")
18-
# %%

D_plotter.ipynb

-983
This file was deleted.

PCA_plots.ipynb

+2-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"cell_type": "code",
46-
"execution_count": 3,
46+
"execution_count": null,
4747
"metadata": {},
4848
"outputs": [
4949
{
@@ -62,11 +62,9 @@
6262
"import seaborn as sns\n",
6363
"import numpy as np\n",
6464
"\n",
65-
"# Esempio di dati per pc_soap\n",
6665
"# pc_soap = np.random.rand(1000, 2) # Sostituire con i propri dati\n",
6766
"plt.scatter(pc_soap[::skip, 0], pc_soap[::skip, 1], s=0.5, color=\"black\", alpha=0.5)\n",
6867
"\n",
69-
"# Aggiungere linee di densità\n",
7068
"sns.kdeplot(x=pc_soap[::skip, 0], y=pc_soap[::skip, 1], levels=10, color=\"red\", linewidths=1)\n",
7169
"\n",
7270
"plt.title('SOAP PCA components')\n",
@@ -171,7 +169,7 @@
171169
},
172170
{
173171
"cell_type": "code",
174-
"execution_count": 7,
172+
"execution_count": null,
175173
"metadata": {},
176174
"outputs": [
177175
{
@@ -189,36 +187,28 @@
189187
"import matplotlib.pyplot as plt\n",
190188
"import numpy as np\n",
191189
"\n",
192-
"# Esempio di due array con 3 valori ciascuno\n",
193190
"array1 = ev * 100\n",
194191
"array2 = ev_10 * 100\n",
195192
"\n",
196-
"# Le etichette per le barre\n",
197193
"labels = ['PC1', 'PC2', 'PC3']\n",
198194
"\n",
199-
"# Posizione delle barre sul grafico\n",
200195
"x = np.arange(len(labels))\n",
201196
"\n",
202-
"# Larghezza delle barre\n",
203197
"width = 0.35\n",
204198
"\n",
205199
"fig, ax = plt.subplots(figsize=(10, 6))\n",
206200
"\n",
207-
"# Tracciare le barre per ciascun array\n",
208201
"bars1 = ax.bar(x - width/2, array1, width, label='SOAP', color='blue')\n",
209202
"bars2 = ax.bar(x + width/2, array2, width, label='⟨SOAP⟩', color='orange')\n",
210203
"\n",
211-
"# Aggiungere annotazioni sopra le barre per il primo array\n",
212204
"for bar in bars1:\n",
213205
" yval = bar.get_height()\n",
214206
" ax.text(bar.get_x() + bar.get_width() / 2.0, yval, f'{yval:.2f}', va='bottom', ha='center', fontweight='bold',fontsize=fontsize)\n",
215207
"\n",
216-
"# Aggiungere annotazioni sopra le barre per il secondo array\n",
217208
"for bar in bars2:\n",
218209
" yval = bar.get_height()\n",
219210
" ax.text(bar.get_x() + bar.get_width() / 2.0, yval, f'{yval:.2f}', va='bottom', ha='center', fontweight='bold',fontsize=fontsize)\n",
220211
"\n",
221-
"# Aggiungere etichette, titolo e legenda\n",
222212
"ax.set_xlabel('PCA Components', fontweight='bold',fontsize=fontsize)\n",
223213
"ax.set_ylabel('Explained variance (%)', fontweight='bold',fontsize=fontsize)\n",
224214
"ax.set_title('Explained variance', fontsize=fontsize+2)\n",

0 commit comments

Comments
 (0)