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_disre_c
= "$Id$";
61 static void init5(int n
)
67 static void reset5(void)
71 for(i
=0; (i
<ntop
); i
++) {
77 int tpcomp(const void *a
,const void *b
)
85 return (1e7
*(tpb
->v
-tpa
->v
));
88 static void add5(int ndr
,real viol
)
93 for(i
=1; (i
<ntop
); i
++)
94 if (top
[i
].v
< top
[mini
].v
)
96 if (viol
> top
[mini
].v
) {
102 static void print5(FILE *fp
)
106 qsort(top
,ntop
,sizeof(top
[0]),tpcomp
);
107 fprintf(fp
,"Index:");
108 for(i
=0; (i
<ntop
); i
++)
109 fprintf(fp
," %6d",top
[i
].n
);
110 fprintf(fp
,"\nViol: ");
111 for(i
=0; (i
<ntop
); i
++)
112 fprintf(fp
," %6.3f",top
[i
].v
);
116 void check_viol(FILE *log
,
117 t_ilist
*bonds
,t_iparams forceparams
[],
118 t_functype functype
[],
120 t_forcerec
*fr
,matrix box
,t_graph
*g
,
121 real
*sumv
,real
*averv
,
123 int isize
,atom_id index
[],real vvindex
[])
126 int i
,j
,nat
,n
,type
,ftype
,nviol
,ndr
;
127 real mviol
,tviol
,viol
,lam
,dvdl
;
128 static bool bFirst
=TRUE
;
137 forceatoms
=bonds
->iatoms
;
138 for(j
=0; (j
<isize
); j
++) {
141 for(i
=0; (i
<bonds
->nr
); ) {
143 ftype
=functype
[type
];
144 nat
=interaction_function
[ftype
].nratoms
;
148 while ((i
+n
< bonds
->nr
) &&
149 (forceparams
[forceatoms
[i
+n
]].disres
.index
==
150 forceparams
[forceatoms
[i
]].disres
.index
));
152 viol
=interaction_function
[ftype
].ifunc(n
,&forceatoms
[i
],
154 x
,f
,fr
,g
,box
,lam
,&dvdl
,
158 add5(forceparams
[type
].disres
.index
,viol
);
162 for(j
=0; (j
<isize
); j
++) {
163 if (index
[j
] == forceparams
[type
].disres
.index
)
176 fprintf(stderr
,"\nThere are %d restraints and %d pairs\n",ndr
,bonds
->nr
/3);
183 void patch_viol(t_ilist
*bonds
,t_iparams forceparams
[],
184 t_functype functype
[])
187 int i
,j
,type
,ftype
,nat
;
189 forceatoms
=bonds
->iatoms
;
190 for(i
=j
=0; (i
<bonds
->nr
); ) {
191 type
=forceatoms
[i
++];
192 ftype
=functype
[type
];
193 if (ftype
== F_DISRES
)
194 forceparams
[ftype
].disres
.index
=j
++;
195 nat
=interaction_function
[ftype
].nratoms
;
200 int main (int argc
,char *argv
[])
202 static char *desc
[] = {
203 "g_disre computes violations of distance restraints. If necessary",
204 "all protons can be added to a protein molecule. The program allways",
205 "computes the instantaneous violations rather than time-averaged,",
206 "because this analysis is done from a trajectory file afterwards",
207 "it does not make sense to use time averaging.[PAR]",
208 "An index file may be used to select specific restraints for",
211 static bool bProt
=FALSE
;
214 { "-prot", FALSE
, etBOOL
, {&bProt
},
215 "Protonate protein every step. This currently does not add terminal hydrogens, and therefore works only when the termini are capped." },
216 { "-ntop", FALSE
, etINT
, {&ntop
},
217 "Number of large violations that are stored in the log file every step" }
220 FILE *out
,*aver
,*numv
,*maxxv
,*xvg
=NULL
;
231 int status
,ntopatoms
,natoms
,i
,j
,nv
,step
;
232 real t
,sumv
,averv
,maxv
,lambda
;
243 { efTPX
, NULL
, NULL
, ffREAD
},
244 { efTRX
, "-f", NULL
, ffREAD
},
245 { efXVG
, "-ds", "drsum", ffWRITE
},
246 { efXVG
, "-da", "draver", ffWRITE
},
247 { efXVG
, "-dn", "drnum", ffWRITE
},
248 { efXVG
, "-dm", "drmax", ffWRITE
},
249 { efXVG
, "-dr", "restr", ffWRITE
},
250 { efLOG
, "-l", "disres", ffWRITE
},
251 { efNDX
, NULL
, "viol", ffOPTRD
}
253 #define NFILE asize(fnm)
255 CopyRight(stderr
,argv
[0]);
256 parse_common_args(&argc
,argv
,PCA_CAN_TIME
| PCA_CAN_VIEW
,TRUE
,
257 NFILE
,fnm
,asize(pa
),pa
,asize(desc
),desc
,0,NULL
);
260 read_tpxheader(ftp2fn(efTPX
,NFILE
,fnm
),&header
);
261 snew(xtop
,header
.natoms
);
262 read_tpx(ftp2fn(efTPX
,NFILE
,fnm
),&step
,&t
,&lambda
,&ir
,
263 box
,&ntopatoms
,xtop
,NULL
,NULL
,&top
);
265 check_nprocs_top(ftp2fn(efTPX
,NFILE
,fnm
),&top
,1);
267 g
= mk_graph(&top
.idef
,top
.atoms
.nr
,0);
268 cr
= init_par(&argc
,&argv
);
269 open_log(ftp2fn(efLOG
,NFILE
,fnm
),cr
);
271 if (ftp2bSet(efNDX
,NFILE
,fnm
)) {
272 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),1,&isize
,&index
,&grpname
);
273 xvg
=xvgropen(opt2fn("-dr",NFILE
,fnm
),"Inidividual Restraints","Time (ps)",
277 for(i
=0; (i
<isize
); i
++) {
280 sprintf(leg
[i
],"index %u",index
[i
]);
282 xvgr_legend(xvg
,isize
,leg
);
288 init_disres(stdlog
,top
.idef
.il
[F_DISRES
].nr
,&ir
);
290 natoms
=read_first_x(&status
,ftp2fn(efTRX
,NFILE
,fnm
),&t
,&x
,box
);
293 out
=xvgropen(opt2fn("-ds",NFILE
,fnm
),"Sum of Violations","Time (ps)","nm");
294 aver
=xvgropen(opt2fn("-da",NFILE
,fnm
),"Average Violation","Time (ps)","nm");
295 numv
=xvgropen(opt2fn("-dn",NFILE
,fnm
),"# Violations","Time (ps)","#");
296 maxxv
=xvgropen(opt2fn("-dm",NFILE
,fnm
),"Largest Violation","Time (ps)","nm");
300 atoms
->nr
=top
.atoms
.nr
;
301 atoms
->nres
=top
.atoms
.nres
;
302 snew(atoms
->atomname
,atoms
->nr
);
303 snew(atoms
->resname
,atoms
->nres
);
304 snew(atoms
->atom
,atoms
->nr
);
305 memcpy(atoms
->atom
,top
.atoms
.atom
,atoms
->nr
*sizeof(atoms
->atom
[0]));
306 memcpy(atoms
->atomname
,top
.atoms
.atomname
,
307 atoms
->nr
*sizeof(atoms
->atomname
[0]));
308 memcpy(atoms
->resname
,top
.atoms
.resname
,
309 atoms
->nres
*sizeof(atoms
->resname
[0]));
310 mdatoms
= atoms2md(&top
.atoms
,ir
.opts
.nFreeze
,FALSE
,FALSE
,FALSE
);
312 fprintf(stdlog
,"Made forcerec...\n");
313 calc_nsb(&(top
.blocks
[ebCGS
]),1,nsb
,0);
314 init_forcerec(stdlog
,fr
,&ir
,&(top
.blocks
[ebMOLS
]),cr
,
315 &(top
.blocks
[ebCGS
]),&(top
.idef
),mdatoms
,nsb
,box
,FALSE
);
319 rm_pbc(&top
.idef
,natoms
,box
,x
,x
);
322 protonate(&atoms
,&x
);
326 &(top
.idef
.il
[F_DISRES
]),
327 top
.idef
.iparams
,top
.idef
.functype
,
328 x
,f
,fr
,box
,g
,&sumv
,&averv
,&maxv
,&nv
,
329 isize
,index
,vvindex
);
331 fprintf(xvg
,"%10g",t
);
332 for(i
=0; (i
<isize
); i
++)
333 fprintf(xvg
," %10g",vvindex
[i
]);
336 fprintf(out
, "%10g %10g\n",t
,sumv
);
337 fprintf(aver
, "%10g %10g\n",t
,averv
);
338 fprintf(maxxv
,"%10g %10g\n",t
,maxv
);
339 fprintf(numv
, "%10g %10d\n",t
,nv
);
342 } while (read_next_x(status
,&t
,natoms
,x
,box
));
351 xvgr_file(opt2fn("-dr",NFILE
,fnm
),"-nxy");
353 xvgr_file(opt2fn("-dn",NFILE
,fnm
),NULL
);
354 xvgr_file(opt2fn("-da",NFILE
,fnm
),NULL
);
355 xvgr_file(opt2fn("-ds",NFILE
,fnm
),NULL
);
356 xvgr_file(opt2fn("-dm",NFILE
,fnm
),NULL
);