Skip to content

Commit fe5cec7

Browse files
committed
Remove custom STXXL configuration from the code. From now on STXXL
should be configured externally as suggested in STXXL documentation.
1 parent 62c8c14 commit fe5cec7

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

examples/fastcluster_load.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import mdtraj as md
88
import numpy as np
99
import json
10+
import os.path
11+
1012

1113
Nk=1
1214
if len(sys.argv)>1:
@@ -22,25 +24,35 @@
2224
finishedLoad=time.time()
2325
print ("finished loading ({}k): {}".format(Nk,finishedLoad-start))
2426

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
3247

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))
4356

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))

src/inmatrix.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@
77

88
#include "inmatrix.h"
99

10-
InMatrix::InMatrix(unsigned numpoints, const string cachefile,
11-
const string cacheOptions, unsigned long ramUse):sorter(Cmp(),ramUse) {
10+
InMatrix::InMatrix(unsigned numpoints, unsigned long ramUse):sorter(Cmp(),ramUse) {
1211

1312
//set Matrix::threshold, numPoints
14-
stxxl::config * cfg = stxxl::config::get_instance();
15-
unsigned long diskSize=numpoints?12L*numpoints*(numpoints-1)/2:2L*1024L*1024L*1024L;
16-
stxxl::disk_config disk1(cachefile, diskSize, cacheOptions);
17-
//disk1.direct = stxxl::disk_config::DIRECT_OFF;
18-
cfg->add_disk(disk1);
1913
}
2014

2115
bool InMatrix::getNext(uint &row, uint &col, float &value) {

src/inmatrix.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ struct InMatrix: public Matrix {
3535
uint pos;
3636

3737

38-
InMatrix(unsigned numpoints=0, const std::string cachefile="sorter.tmp",
39-
const std::string cacheOptions="syscall nodirect unlink",
38+
InMatrix(unsigned numpoints=0,
4039
unsigned long ramUse=1L*1024*1024*1024);
4140

4241
~InMatrix() {

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char **argv) {
4747
if (!extractOptions("--linkage=%s", method, argc, argv))
4848
strcat(method,"complete");
4949

50-
InMatrix inMat(0,"sorter.tmp","syscall nodirect unlink",64*1024*1024);
50+
InMatrix inMat(0,64*1024*1024);
5151

5252
using std::chrono::duration_cast;
5353
using std::chrono::milliseconds;

0 commit comments

Comments
 (0)