4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_g_mindist_c
= "$Id$";
46 static void calc_mindist(real MinDist
,
49 atom_id index1
[], atom_id index2
[],
51 int *ixmin
, int *jxmin
)
64 /* hb2=(sqr(box[XX][XX])+sqr(box[YY][YY])+sqr(box[ZZ][ZZ]))*0.5; */
68 /* Must init pbc every step because of pressure coupling */
82 for(i
=0; (i
< nx1
); i
++) {
86 for(j
=j0
; (j
< j1
); j
++) {
89 pbc_dx(x
[ix
],x
[jx
],dx
);
105 void mindist_plot(char *fn
,FILE *atm
,real mind
,
106 char *dfile
,char *nfile
,bool bMat
,
107 int ng
,atom_id
*index
[], int gnx
[], char *grpn
[])
119 if ((natoms
=read_first_x(&status
,fn
,&t
,&x0
,box
))==0)
120 fatal_error(0,"Could not read coordinates from statusfile\n");
122 sprintf(buf
,"Number of Contacts < %g nm",mind
);
123 dist
=xvgropen(dfile
,"Minimum Distance","Time (ps)","Distance (nm)");
124 num
=xvgropen(nfile
,buf
,"Time (ps)","Number");
127 snew(leg
,(ng
*(ng
-1))/2);
128 for(i
=j
=0; (i
<ng
-1); i
++) {
129 for(k
=i
+1; (k
<ng
); k
++,j
++) {
130 sprintf(buf
,"%s-%s",grpn
[i
],grpn
[k
]);
134 xvgr_legend(dist
,j
,leg
);
135 xvgr_legend(num
,j
,leg
);
139 for(i
=0; (i
<ng
-1); i
++) {
140 sprintf(buf
,"%s-%s",grpn
[0],grpn
[i
+1]);
143 xvgr_legend(dist
,ng
-1,leg
);
144 xvgr_legend(num
,ng
-1,leg
);
148 fprintf(dist
,"%12g",t
);
149 fprintf(num
,"%12g",t
);
152 for(i
=0; (i
<ng
-1); i
++) {
153 for(k
=i
+1; (k
<ng
); k
++) {
154 calc_mindist(mind
,box
,x0
,gnx
[i
],gnx
[k
],
155 index
[i
],index
[k
],&md
,&nd
,
157 fprintf(dist
," %12g",md
);
158 fprintf(num
," %8d",nd
);
163 for(i
=1; (i
<ng
); i
++) {
164 calc_mindist(mind
,box
,x0
,gnx
[0],gnx
[i
],
165 index
[0],index
[i
],&md
,&nd
,
167 fprintf(dist
," %12g",md
);
168 fprintf(num
," %8d",nd
);
174 fprintf(atm
,"%12g %12d %12d\n",t
,min1
,min2
);
175 } while (read_next_x(status
,&t
,natoms
,x0
,box
));
184 int main(int argc
,char *argv
[])
186 static char *desc
[] = {
187 "g_mindist computes the distance between one group and a number of",
189 "Both the smallest distance and the number of contacts within a given",
190 "distance are plotted to two separate output files"
193 static bool bMat
=FALSE
;
194 static real mindist
=0.6;
196 { "-matrix", FALSE
, etBOOL
, {&bMat
},
197 "Calculate half a matrix of group-group distances" },
198 { "-d", FALSE
, etREAL
, {&mindist
},
199 "Distance for contacts" }
207 { efTRX
, "-f", NULL
, ffREAD
},
208 { efNDX
, NULL
, NULL
, ffREAD
},
209 { efXVG
, "-od","mindist",ffWRITE
},
210 { efXVG
, "-on","numcont", ffWRITE
},
211 { efOUT
, "-o","atm-pair", ffWRITE
}
213 #define NFILE asize(fnm)
215 CopyRight(stderr
,argv
[0]);
216 parse_common_args(&argc
,argv
,PCA_CAN_VIEW
| PCA_CAN_TIME
,TRUE
,
217 NFILE
,fnm
,asize(pa
),pa
,asize(desc
),desc
,0,NULL
);
220 fprintf(stderr
,"You can compute all distances between a number of groups\n"
221 "How many groups do you want (>= 2) ?\n");
223 fprintf(stderr
,"You can compute the distances between a first group\n"
224 "and a number of other groups.\n"
225 "How many other groups do you want (>= 1) ?\n");
236 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),ng
,gnx
,index
,grpname
);
238 atm
=ftp2FILE(efOUT
,NFILE
,fnm
,"w");
239 mindist_plot(ftp2fn(efTRX
,NFILE
,fnm
),atm
,mindist
,
240 opt2fn("-od",NFILE
,fnm
),opt2fn("-on",NFILE
,fnm
),
241 bMat
,ng
,index
,gnx
,grpname
);
244 xvgr_file(opt2fn("-od",NFILE
,fnm
),"-nxy");
245 xvgr_file(opt2fn("-on",NFILE
,fnm
),"-nxy");