3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Green Red Orange Magenta Azure Cyan Skyblue
51 real ellipticity(int nres,t_bb bb[])
57 static const t_ppwstr ppw[] = {
71 #define NPPW asize(ppw)
78 for(i=0; (i<nres); i++) {
81 for(j=0; (j<NPPW); j++) {
82 pp2=sqr(phi-ppw[j].phi)+sqr(psi-ppw[j].psi);
93 real ahx_len(int gnx,atom_id index[],rvec x[],matrix box)
94 /* Assume we have a list of Calpha atoms only! */
98 rvec_sub(x[index[0]],x[index[gnx-1]],dx);
103 real radius(FILE *fp,int nca,atom_id ca_index[],rvec x[])
104 /* Assume we have all the backbone */
110 for(i=0; (i<nca); i++) {
112 dl2=sqr(x[ai][XX])+sqr(x[ai][YY]);
115 fprintf(fp," %10g",dl2);
122 return sqrt(dlt/nca);
125 static real rot(rvec x1,rvec x2)
127 real phi1,dphi,cp,sp;
130 phi1=atan2(x1[YY],x1[XX]);
133 xx= cp*x2[XX]+sp*x2[YY];
134 yy=-sp*x2[XX]+cp*x2[YY];
136 dphi=RAD2DEG*atan2(yy,xx);
141 real twist(FILE *fp,int nca,atom_id caindex[],rvec x[])
148 for(i=1; (i<nca); i++) {
151 dphi=rot(x[a0],x[a1]);
161 real ca_phi(int gnx,atom_id index[],rvec x[],matrix box)
162 /* Assume we have a list of Calpha atoms only! */
165 int i,ai,aj,ak,al,t1,t2,t3;
166 rvec r_ij,r_kj,r_kl,m,n;
173 for(i=0; (i<gnx-4); i++) {
179 dih_angle(x[ai],x[aj],x[ak],x[al],NULL,
185 return (phitot/(gnx-4.0));
188 real dip(int nbb,atom_id bbind[],rvec x[],t_atom atom[])
195 for(i=0; (i<nbb); i++) {
198 for(m=0; (m<DIM); m++)
199 dipje[m]+=x[ai][m]*q;
204 real rise(int gnx,atom_id index[],rvec x[])
205 /* Assume we have a list of Calpha atoms only! */
213 for(i=1; (i<gnx); i++) {
220 return (ztot/(gnx-1.0));
223 void av_hblen(FILE *fp3,FILE *fp3a,
224 FILE *fp4,FILE *fp4a,
225 FILE *fp5,FILE *fp5a,
226 real t,int nres,t_bb bb[])
228 int i,n3=0,n4=0,n5=0;
231 for(i=0; (i<nres-3); i++)
233 fprintf(fp3a, "%10g",bb[i].d3);
237 fprintf(fp4a,"%10g",bb[i].d4);
242 fprintf(fp5a,"%10g",bb[i].d5);
247 fprintf(fp3,"%10g %10g\n",t,d3/n3);
248 fprintf(fp4,"%10g %10g\n",t,d4/n4);
249 fprintf(fp5,"%10g %10g\n",t,d5/n5);
256 void av_phipsi(FILE *fphi,FILE *fpsi,FILE *fphi2,FILE *fpsi2,
257 real t,int nres,t_bb bb[])
262 fprintf(fphi2,"%10g",t);
263 fprintf(fpsi2,"%10g",t);
264 for(i=0; (i<nres); i++)
268 fprintf(fphi2," %10g",bb[i].phi);
269 fprintf(fpsi2," %10g",bb[i].psi);
272 fprintf(fphi,"%10g %10g\n",t,(phi/n));
273 fprintf(fpsi,"%10g %10g\n",t,(psi/n));
278 static void set_ahcity(int nbb,t_bb bb[])
283 for(n=0; (n<nbb); n++) {
284 pp2=sqr(bb[n].phi-PHI_AHX)+sqr(bb[n].psi-PSI_AHX);
288 if ((bb[n].d4 < 0.36) || ((n > 0) && bb[n-1].bHelix))
294 t_bb *mkbbind(const char *fn,int *nres,int *nbb,int res0,
295 int *nall,atom_id **index,
296 char ***atomname,t_atom atom[],
299 static const char * bb_nm[] = { "N", "H", "CA", "C", "O", "HN" };
300 #define NBB asize(bb_nm)
303 int ai,i,i0,i1,j,k,ri,rnr,gnx,r0,r1;
305 fprintf(stderr,"Please select a group containing the entire backbone\n");
306 rd_index(fn,1,&gnx,index,&grpname);
308 fprintf(stderr,"Checking group %s\n",grpname);
309 r0=r1=atom[(*index)[0]].resind;
310 for(i=1; (i<gnx); i++) {
311 r0=min(r0,atom[(*index)[i]].resind);
312 r1=max(r1,atom[(*index)[i]].resind);
315 fprintf(stderr,"There are %d residues\n",rnr);
317 for(i=0; (i<rnr); i++)
318 bb[i].N=bb[i].H=bb[i].CA=bb[i].C=bb[i].O=-1,bb[i].resno=res0+i;
320 for(i=j=0; (i<gnx); i++) {
322 ri=atom[ai].resind-r0;
323 if (strcmp(*(resinfo[ri].name),"PRO") == 0) {
324 if (strcmp(*(atomname[ai]),"CD") == 0)
327 for(k=0; (k<NBB); k++)
328 if (strcmp(bb_nm[k],*(atomname[ai])) == 0) {
338 /* No attempt to address the case where some weird input has both H and HN atoms in the group */
355 for(i0=0; (i0<rnr); i0++) {
356 if ((bb[i0].N != -1) && (bb[i0].H != -1) &&
358 (bb[i0].C != -1) && (bb[i0].O != -1))
361 for(i1=rnr-1; (i1>=0); i1--) {
362 if ((bb[i1].N != -1) && (bb[i1].H != -1) &&
364 (bb[i1].C != -1) && (bb[i1].O != -1))
372 for(i=i0; (i<i1); i++) {
373 bb[i].Cprev=bb[i-1].C;
374 bb[i].Nnext=bb[i+1].N;
377 fprintf(stderr,"There are %d complete backbone residues (from %d to %d)\n",
378 rnr,bb[i0].resno,bb[i1].resno);
380 gmx_fatal(FARGS,"Zero complete backbone residues were found, cannot proceed");
381 for(i=0; (i<rnr); i++,i0++)
385 for(i=0; (i<rnr); i++) {
386 ri=atom[bb[i].CA].resind;
387 sprintf(bb[i].label,"%s%d",*(resinfo[ri].name),ri+res0);
391 *nbb=rnr*asize(bb_nm);
396 real pprms(FILE *fp,int nbb,t_bb bb[])
402 for(i=n=0; (i<nbb); i++) {
404 rms=sqrt(bb[i].pprms2);
407 fprintf(fp,"%10g ",rms);
412 rms=sqrt(rms2/n-sqr(rmst/n));
417 void calc_hxprops(int nres,t_bb bb[],rvec x[],matrix box)
419 int i,ao,an,t1,t2,t3;
420 rvec dx,r_ij,r_kj,r_kl,m,n;
423 for(i=0; (i<nres); i++) {
425 bb[i].d4=bb[i].d3=bb[i].d5=0;
428 rvec_sub(x[ao],x[an],dx);
433 rvec_sub(x[ao],x[an],dx);
438 rvec_sub(x[ao],x[an],dx);
443 dih_angle(x[bb[i].Cprev],x[bb[i].N],x[bb[i].CA],x[bb[i].C],NULL,
447 dih_angle(x[bb[i].N],x[bb[i].CA],x[bb[i].C],x[bb[i].Nnext],NULL,
450 bb[i].pprms2=sqr(bb[i].phi-PHI_AHX)+sqr(bb[i].psi-PSI_AHX);
453 1.4*sin((bb[i].psi+138.0)*DEG2RAD) -
454 4.1*cos(2.0*DEG2RAD*(bb[i].psi+138.0)) +
455 2.0*cos(2.0*DEG2RAD*(bb[i].phi+30.0));
459 static void check_ahx(int nres,t_bb bb[],rvec x[],
460 int *hstart,int *hend)
462 int h0,h1,h0sav,h1sav;
467 for(; (!bb[h0].bHelix) && (h0<nres-4); h0++)
469 for(h1=h0; bb[h1+1].bHelix && (h1<nres-1); h1++)
472 /*fprintf(stderr,"Helix from %d to %d\n",h0,h1);*/
473 if (h1-h0 > h1sav-h0sav) {
479 } while (h1 < nres-1);
484 void do_start_end(int nres,t_bb bb[],rvec x[],int *nbb,atom_id bbindex[],
485 int *nca,atom_id caindex[],
486 gmx_bool bRange,int rStart,int rEnd)
488 int i,j,hstart=0,hend=0;
491 for(i=0; (i<nres); i++) {
492 if ((bb[i].resno >= rStart) && (bb[i].resno <= rEnd))
494 if (bb[i].resno == rStart)
496 if (bb[i].resno == rEnd)
501 /* Find start and end of longest helix fragment */
502 check_ahx(nres,bb,x,&hstart,&hend);
504 fprintf(stderr,"helix from: %d through %d\n",
505 bb[hstart].resno,bb[hend].resno);
507 for(j=0,i=hstart; (i<=hend); i++) {
508 bbindex[j++]=bb[i].N;
509 bbindex[j++]=bb[i].H;
510 bbindex[j++]=bb[i].CA;
511 bbindex[j++]=bb[i].C;
512 bbindex[j++]=bb[i].O;
513 caindex[i-hstart]=bb[i].CA;
516 *nca=(hend-hstart+1);
519 void pr_bb(FILE *fp,int nres,t_bb bb[])
524 fprintf(fp,"%3s %3s %3s %3s %3s %7s %7s %7s %7s %7s %3s\n",
525 "AA","N","Ca","C","O","Phi","Psi","D3","D4","D5","Hx?");
526 for(i=0; (i<nres); i++) {
527 fprintf(fp,"%3d %3d %3d %3d %3d %7.2f %7.2f %7.3f %7.3f %7.3f %3s\n",
528 bb[i].resno,bb[i].N,bb[i].CA,bb[i].C,bb[i].O,
529 bb[i].phi,bb[i].psi,bb[i].d3,bb[i].d4,bb[i].d5,
530 bb[i].bHelix ? "Yes" : "No");