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
44 #include "gmx_fatal.h"
47 t_dlist *mk_dlist(FILE *log,
48 t_atoms *atoms, int *nlist,
49 gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bHChi,
50 int maxchi, int r0, gmx_residuetype_t rt)
52 int ires, i, j, k, ii;
54 int nl = 0, nc[edMax];
58 snew(dl, atoms->nres+1);
60 for (i = 0; (i < edMax); i++)
68 ires = atoms->atom[i].resind;
70 /* Initiate all atom numbers to -1 */
71 atm.minC = atm.H = atm.N = atm.C = atm.O = atm.minO = -1;
72 for (j = 0; (j < MAXCHI+3); j++)
77 /* Look for atoms in this residue */
78 /* maybe should allow for chis to hydrogens? */
79 while ((i < atoms->nr) && (atoms->atom[i].resind == ires))
81 if ((strcmp(*(atoms->atomname[i]), "H") == 0) ||
82 (strcmp(*(atoms->atomname[i]), "H1") == 0) )
86 else if (strcmp(*(atoms->atomname[i]), "N") == 0)
90 else if (strcmp(*(atoms->atomname[i]), "C") == 0)
94 else if ((strcmp(*(atoms->atomname[i]), "O") == 0) ||
95 (strcmp(*(atoms->atomname[i]), "O1") == 0))
99 else if (strcmp(*(atoms->atomname[i]), "CA") == 0)
103 else if (strcmp(*(atoms->atomname[i]), "CB") == 0)
107 else if ((strcmp(*(atoms->atomname[i]), "CG") == 0) ||
108 (strcmp(*(atoms->atomname[i]), "CG1") == 0) ||
109 (strcmp(*(atoms->atomname[i]), "OG") == 0) ||
110 (strcmp(*(atoms->atomname[i]), "OG1") == 0) ||
111 (strcmp(*(atoms->atomname[i]), "SG") == 0))
115 else if ((strcmp(*(atoms->atomname[i]), "CD") == 0) ||
116 (strcmp(*(atoms->atomname[i]), "CD1") == 0) ||
117 (strcmp(*(atoms->atomname[i]), "SD") == 0) ||
118 (strcmp(*(atoms->atomname[i]), "OD1") == 0) ||
119 (strcmp(*(atoms->atomname[i]), "ND1") == 0))
123 /* by grs - split the Cn[4] into 2 bits to check allowing dih to H */
124 else if (bHChi && ((strcmp(*(atoms->atomname[i]), "HG") == 0) ||
125 (strcmp(*(atoms->atomname[i]), "HG1") == 0)) )
129 else if ((strcmp(*(atoms->atomname[i]), "CE") == 0) ||
130 (strcmp(*(atoms->atomname[i]), "CE1") == 0) ||
131 (strcmp(*(atoms->atomname[i]), "OE1") == 0) ||
132 (strcmp(*(atoms->atomname[i]), "NE") == 0))
136 else if ((strcmp(*(atoms->atomname[i]), "CZ") == 0) ||
137 (strcmp(*(atoms->atomname[i]), "NZ") == 0))
141 /* HChi flag here too */
142 else if (bHChi && (strcmp(*(atoms->atomname[i]), "NH1") == 0))
149 thisres = *(atoms->resinfo[ires].name);
151 /* added by grs - special case for aromatics, whose chis above 2 are
152 not real and produce rubbish output - so set back to -1 */
153 if (strcmp(thisres, "PHE") == 0 ||
154 strcmp(thisres, "TYR") == 0 ||
155 strcmp(thisres, "PTR") == 0 ||
156 strcmp(thisres, "TRP") == 0 ||
157 strcmp(thisres, "HIS") == 0 ||
158 strcmp(thisres, "HISA") == 0 ||
159 strcmp(thisres, "HISB") == 0)
161 for (ii = 5; ii <= 7; ii++)
166 /* end fixing aromatics */
168 /* Special case for Pro, has no H */
169 if (strcmp(thisres, "PRO") == 0)
173 /* Carbon from previous residue */
184 /* Check how many dihedrals we have */
185 if ((atm.N != -1) && (atm.Cn[1] != -1) && (atm.C != -1) &&
186 (atm.O != -1) && ((atm.H != -1) || (atm.minC != -1)))
188 dl[nl].resnr = ires+1;
190 dl[nl].atm.Cn[0] = atm.N;
191 if ((atm.Cn[3] != -1) && (atm.Cn[2] != -1) && (atm.Cn[1] != -1))
215 if ((atm.minC != -1) && (atm.minO != -1))
219 dl[nl].index = gmx_residuetype_get_index(rt, thisres);
221 sprintf(dl[nl].name, "%s%d", thisres, ires+r0);
226 fprintf(debug, "Could not find N atom but could find other atoms"
227 " in residue %s%d\n", thisres, ires+r0);
230 fprintf(stderr, "\n");
232 fprintf(log, "There are %d residues with dihedrals\n", nl);
244 for (i = 0; (i < maxchi); i++)
249 fprintf(log, "There are %d dihedrals\n", j);
250 fprintf(log, "Dihedral: ");
253 fprintf(log, " Phi ");
257 fprintf(log, " Psi ");
261 for (i = 0; (i < maxchi); i++)
263 fprintf(log, "Chi%d ", i+1);
266 fprintf(log, "\nNumber: ");
269 fprintf(log, "%4d ", nl);
273 fprintf(log, "%4d ", nl);
277 for (i = 0; (i < maxchi); i++)
279 fprintf(log, "%4d ", nc[i]);
289 gmx_bool has_dihedral(int Dih, t_dlist *dl)
297 b = ((dl->atm.H != -1) && (dl->atm.N != -1) && (dl->atm.Cn[1] != -1) && (dl->atm.C != -1));
300 b = ((dl->atm.N != -1) && (dl->atm.Cn[1] != -1) && (dl->atm.C != -1) && (dl->atm.O != -1));
303 b = ((dl->atm.minO != -1) && (dl->atm.minC != -1) && (dl->atm.N != -1) && (dl->atm.Cn[1] != -1));
312 b = ((dl->atm.Cn[ddd] != -1) && (dl->atm.Cn[ddd+1] != -1) &&
313 (dl->atm.Cn[ddd+2] != -1) && (dl->atm.Cn[ddd+3] != -1));
316 pr_dlist(stdout, 1, dl, 1, 0, TRUE, TRUE, TRUE, TRUE, MAXCHI);
317 gmx_fatal(FARGS, "Non existant dihedral %d in file %s, line %d",
318 Dih, __FILE__, __LINE__);
323 static void pr_one_ro(FILE *fp, t_dlist *dl, int nDih, real dt)
326 for (k = 0; k < NROT; k++)
328 fprintf(fp, " %6.2f", dl->rot_occ[nDih][k]);
333 static void pr_ntr_s2(FILE *fp, t_dlist *dl, int nDih, real dt)
335 fprintf(fp, " %6.2f %6.2f\n", (dt == 0) ? 0 : dl->ntr[nDih]/dt, dl->S2[nDih]);
338 void pr_dlist(FILE *fp, int nl, t_dlist dl[], real dt, int printtype,
339 gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bOmega, int maxchi)
343 void (*pr_props)(FILE *, t_dlist *, int, real);
345 /* Analysis of dihedral transitions etc */
347 if (printtype == edPrintST)
349 pr_props = pr_ntr_s2;
350 fprintf(stderr, "Now printing out transitions and OPs...\n");
354 pr_props = pr_one_ro;
355 fprintf(stderr, "Now printing out rotamer occupancies...\n");
356 fprintf(fp, "\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n\n");
359 /* change atom numbers from 0 based to 1 based */
360 for (i = 0; (i < nl); i++)
362 fprintf(fp, "Residue %s\n", dl[i].name);
363 if (printtype == edPrintST)
365 fprintf(fp, " Angle [ AI, AJ, AK, AL] #tr/ns S^2D \n"
366 "--------------------------------------------\n");
370 fprintf(fp, " Angle [ AI, AJ, AK, AL] rotamers 0 g(-) t g(+)\n"
371 "--------------------------------------------\n");
375 fprintf(fp, " Phi [%5d,%5d,%5d,%5d]",
376 (dl[i].atm.H == -1) ? 1+dl[i].atm.minC : 1+dl[i].atm.H,
377 1+dl[i].atm.N, 1+dl[i].atm.Cn[1], 1+dl[i].atm.C);
378 pr_props(fp, &dl[i], edPhi, dt);
382 fprintf(fp, " Psi [%5d,%5d,%5d,%5d]", 1+dl[i].atm.N, 1+dl[i].atm.Cn[1],
383 1+dl[i].atm.C, 1+dl[i].atm.O);
384 pr_props(fp, &dl[i], edPsi, dt);
386 if (bOmega && has_dihedral(edOmega, &(dl[i])))
388 fprintf(fp, " Omega [%5d,%5d,%5d,%5d]", 1+dl[i].atm.minO, 1+dl[i].atm.minC,
389 1+dl[i].atm.N, 1+dl[i].atm.Cn[1]);
390 pr_props(fp, &dl[i], edOmega, dt);
392 for (Xi = 0; Xi < MAXCHI; Xi++)
394 if (bChi && (Xi < maxchi) && (dl[i].atm.Cn[Xi+3] != -1) )
396 fprintf(fp, " Chi%d[%5d,%5d,%5d,%5d]", Xi+1, 1+dl[i].atm.Cn[Xi],
397 1+dl[i].atm.Cn[Xi+1], 1+dl[i].atm.Cn[Xi+2],
398 1+dl[i].atm.Cn[Xi+3]);
399 pr_props(fp, &dl[i], Xi+edChi1, dt); /* Xi+2 was wrong here */
408 int pr_trans(FILE *fp, int nl, t_dlist dl[], real dt, int Xi)
410 /* never called at the moment */
415 fprintf(fp, "\\begin{table}[h]\n");
416 fprintf(fp, "\\caption{Number of dihedral transitions per nanosecond}\n");
417 fprintf(fp, "\\begin{tabular}{|l|l|}\n");
418 fprintf(fp, "\\hline\n");
419 fprintf(fp, "Residue\t&$\\chi_%d$\t\\\\\n", Xi+1);
420 for (i = 0; (i < nl); i++)
422 nn = dl[i].ntr[Xi]/dt;
426 fprintf(fp, "%s\t&\\HL{%d}\t\\\\\n", dl[i].name, nn);
431 fprintf(fp, "%s\t&\\%d\t\\\\\n", dl[i].name, nn);
434 fprintf(fp, "\\hline\n");
435 fprintf(fp, "\\end{tabular}\n");
436 fprintf(fp, "\\end{table}\n\n");