7
7
import mdtraj as md
8
8
import numpy as np
9
9
import json
10
+ import os .path
11
+
10
12
11
13
Nk = 1
12
14
if len (sys .argv )> 1 :
22
24
finishedLoad = time .time ()
23
25
print ("finished loading ({}k): {}" .format (Nk ,finishedLoad - start ))
24
26
25
- Nframes = traj .n_frames
26
- D = np .empty ((Nframes * (Nframes - 1 )/ 2 ,))
27
- j = 0
28
- for i in range (0 ,Nframes - 1 ):
29
- rmsds = md .rmsd (traj , traj , i )[i + 1 :]
30
- D [j :j + Nframes - i - 1 ]= rmsds
31
- j += Nframes - 1 - i
27
+ Zfile = 'z_fastcluster_load_{}k.json' .format (Nk )
28
+ Z = []
29
+ if os .path .isfile (Zfile ):
30
+ obj_text = open (Zfile , 'r' ).read ()
31
+ Zl = json .loads (obj_text )
32
+ Z = np .array (Zl )
33
+ print ('loaded the linkage matrix' )
34
+ else :
35
+ Nframes = traj .n_frames
36
+ D = np .empty ((Nframes * (Nframes - 1 )/ 2 ,))
37
+ j = 0
38
+ for i in range (0 ,Nframes - 1 ):
39
+ rmsds = md .rmsd (traj , traj , i )[i + 1 :]
40
+ D [j :j + Nframes - i - 1 ]= rmsds
41
+ j += Nframes - 1 - i
42
+
43
+ #D = np.empty((traj.n_frames, traj.n_frames))
44
+ #for i in range(traj.n_frames):
45
+ #D[i] = md.rmsd(traj, traj, i)
46
+ #D=squareform(D,checks=False) #rounding errors make D appear asymetric
32
47
33
- #D = np.empty((traj.n_frames, traj.n_frames))
34
- #for i in range(traj.n_frames):
35
- #D[i] = md.rmsd(traj, traj, i)
36
- #D=squareform(D,checks=False) #rounding errors make D appear asymetric
37
-
38
- finishedRMSD = time .time ()
39
- print ("finished rmsd: {}" .format (finishedRMSD - finishedLoad ))
40
- #Z-matrix contains the linkage history, see more at http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage
41
- Z = linkage (D , method = 'complete' ,preserve_input = False )
42
- finishedClust = time .time ()
48
+ finishedRMSD = time .time ()
49
+ print ("finished rmsd: {}" .format (finishedRMSD - finishedLoad ))
50
+ #Z-matrix contains the linkage history, see more at http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage
51
+ Z = linkage (D , method = 'complete' ,preserve_input = False )
52
+ #One would probably like to save the Z-matrix for the future, so that there is no need to redo the clustering
53
+ open (Zfile , 'w' ).write (json .dumps (Z .tolist ()))
54
+ finishedClust = time .time ()
55
+ print ("finished clustering: {}" .format (finishedClust - finishedRMSD ))
43
56
44
- #One would probably like to save the Z-matrix for the future, so that there is no need to redo the clustering
45
- open ('z_fastcluster_load_{}k.json' .format (Nk ), 'w' ).write (json .dumps (Z .tolist ()))
46
- print ("finished clustering: {}" .format (finishedClust - finishedRMSD ))
57
+ labels = cluster .hierarchy .fcluster (Z , 0.20 , criterion = 'distance' )
58
+ open ('frame_labels_{}k.dat' .format (Nk ), 'w' ).write (str (labels ))
0 commit comments