-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance.cc
More file actions
executable file
·137 lines (126 loc) · 3.49 KB
/
distance.cc
File metadata and controls
executable file
·137 lines (126 loc) · 3.49 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
/*
* given a pdb file, a set of trajectories, and a list of "native"
* contacts and cutoffs, compute the fraction of native contacts
* over the trajectories.
*/
//#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <unistd.h>
#include "traj.h"
string usage = "\n\n Usage:\n"
" distance -i idxi -j idxj -L boxL go1.dcd ... goN.dcd\n"
" Just measures the distance in Angstroms between"
" atoms/beads with indices idxi and idxj over the trajectories\n\n";
int main( int argc, char ** argv )
{
string pdbfile, qlist, output;
vector<string> dcd_names;
int c,nselect,resi,resj,natom;
int * selection;
vector<int> i, j;
vector<double> rij;
double com[3], mat[3][3], dr,dx,dy,dz;
double beta,gamma;
beta = 5.0;
gamma = 1.0;
double boxL = -1.0;
while (1) {
c=getopt(argc,argv,"hi:j:L:");
if (c == -1) // no more options
break;
switch (c) {
case 'h':
fprintf(stdout,"%s\n",usage.c_str());
exit(0);
break;
case 'i':
resi = atoi(optarg);
break;
case 'j':
resj = atoi(optarg);
break;
case 'L':
boxL = atof(optarg);
break;
default:
fprintf(stderr,"?? getopt returned character code 0%o ??\n", c);
fprintf(stderr,"%s\n",usage.c_str());
exit(1);
}
}
if (argc - optind < 1) {
fprintf(stdout,"%s\n",usage.c_str());
exit(0);
}
dcd_names.resize(argc-optind);
for (int t=0; t<dcd_names.size(); t++) {
dcd_names[t] = string(argv[optind+t]);
}
//DCDITrajFile inptraj;
BaseITrajFile *inptraj;
int slen = dcd_names[0].size();
if (slen-dcd_names[0].rfind(string(".dcd"))==4) {
fprintf(stderr,"dcd file\n");
inptraj = new DCDITrajFile(dcd_names[0].c_str());
} else if (slen-dcd_names[0].rfind(string(".xtc"))==4) {
fprintf(stderr,"xtc file\n");
inptraj = new XTCITrajFile(dcd_names[0].c_str());
} else {
fprintf(stderr,"unknown trajectory file type:\n");
fprintf(stderr,"%s\n",dcd_names[0].c_str());
exit(1);
}
//inptraj.open(dcd_names[0].c_str());
natom = inptraj->num_atoms();
inptraj->close();
//
float *X = new float[natom];
float *Y = new float[natom];
float *Z = new float[natom];
int frames = 0;
resi -= 1; // index from 0
resj -= 1;
// first pass to compute mean coordinates
for (int trajfile=0; trajfile<dcd_names.size(); trajfile++) {
int slen = dcd_names[trajfile].size();
if (slen-dcd_names[trajfile].rfind(string(".dcd"))==4) {
fprintf(stderr,"dcd file\n");
inptraj = new DCDITrajFile(dcd_names[trajfile].c_str());
} else if (slen-dcd_names[trajfile].rfind(string(".xtc"))==4) {
fprintf(stderr,"xtc file\n");
inptraj = new XTCITrajFile(dcd_names[trajfile].c_str());
} else {
fprintf(stderr,"unknown trajectory file type:\n");
fprintf(stderr,"%s\n",dcd_names[trajfile].c_str());
exit(1);
}
//inptraj->open(dcd_names[trajfile].c_str());
// iterate over frames ...
//inptraj.open( dcd_names[trajfile].c_str() );
//int no_frames = inptraj.total_frames();
//int no_frames = inptraj.actual_frames();
//for (int frame = 0; frame < no_frames; frame++) {
while (inptraj->frames_left()) {
frames++;
inptraj->read_frame(X,Y,Z,natom);
dx = X[resi]-X[resj];
dy = Y[resi]-Y[resj];
dz = Z[resi]-Z[resj];
if (boxL>0.) {
dx-=boxL*round(dx/boxL);
dy-=boxL*round(dy/boxL);
dz-=boxL*round(dz/boxL);
}
dr = sqrt(dx*dx+dy*dy+dz*dz);
//fprintf(stdout,"%8.3f %8.3f %8.3f %8.3f\n",Z[resi],Z[resj],dz,dr);
fprintf(stdout,"%8.3f\n",dr);
}
inptraj->close();
}
delete [] X;
delete [] Y;
delete [] Z;
return 0;
}