2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
47 #include "gromacs/listed_forces/bonded.h"
48 #include "gromacs/math/functions.h"
49 #include "gromacs/math/units.h"
50 #include "gromacs/math/utilities.h"
51 #include "gromacs/math/vec.h"
52 #include "gromacs/topology/index.h"
53 #include "gromacs/topology/topology.h"
54 #include "gromacs/utility/arraysize.h"
55 #include "gromacs/utility/fatalerror.h"
56 #include "gromacs/utility/smalloc.h"
58 real ellipticity(int nres, t_bb bb[])
64 // Avoid warnings about narrowing conversions from double to real
66 # pragma warning(disable : 4838)
68 static const t_ppwstr ppw[] = { { -67, -44, 0.31 }, { -66, -41, 0.31 }, { -59, -44, 0.44 },
69 { -57, -47, 0.56 }, { -53, -52, 0.78 }, { -48, -57, 1.00 },
70 { -70.5, -35.8, 0.15 }, { -57, -79, 0.23 }, { -38, -78, 1.20 },
71 { -60, -30, 0.24 }, { -54, -28, 0.46 }, { -44, -33, 0.68 } };
73 # pragma warning(default : 4838)
75 #define NPPW asize(ppw)
78 real ell, pp2, phi, psi;
81 for (i = 0; (i < nres); i++)
85 for (j = 0; (j < NPPW); j++)
87 pp2 = gmx::square(phi - ppw[j].phi) + gmx::square(psi - ppw[j].psi);
99 real ahx_len(int gnx, const int index[], rvec x[])
100 /* Assume we have a list of Calpha atoms only! */
104 rvec_sub(x[index[0]], x[index[gnx - 1]], dx);
109 real radius(FILE* fp, int nca, const int ca_index[], rvec x[])
110 /* Assume we have all the backbone */
116 for (i = 0; (i < nca); i++)
119 dl2 = gmx::square(x[ai][XX]) + gmx::square(x[ai][YY]);
123 fprintf(fp, " %10g", dl2);
133 return std::sqrt(dlt / nca);
136 static real rot(rvec x1, const rvec x2)
138 real phi1, dphi, cp, sp;
141 phi1 = std::atan2(x1[YY], x1[XX]);
144 xx = cp * x2[XX] + sp * x2[YY];
145 yy = -sp * x2[XX] + cp * x2[YY];
147 dphi = gmx::c_rad2Deg * std::atan2(yy, xx);
152 real twist(int nca, const int caindex[], rvec x[])
159 for (i = 1; (i < nca); i++)
163 dphi = rot(x[a0], x[a1]);
172 return (pt / (nca - 1));
175 real ca_phi(int gnx, const int index[], rvec x[])
176 /* Assume we have a list of Calpha atoms only! */
179 int i, ai, aj, ak, al, t1, t2, t3;
180 rvec r_ij, r_kj, r_kl, m, n;
188 for (i = 0; (i < gnx - 4); i++)
195 * dih_angle(x[ai], x[aj], x[ak], x[al], nullptr, r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3);
199 return (phitot / (gnx - 4.0));
202 real dip(int nbb, int const bbind[], const rvec x[], const t_atom atom[])
209 for (i = 0; (i < nbb); i++)
213 for (m = 0; (m < DIM); m++)
215 dipje[m] += x[ai][m] * q;
221 real rise(int gnx, const int index[], rvec x[])
222 /* Assume we have a list of Calpha atoms only! */
230 for (i = 1; (i < gnx); i++)
238 return (ztot / (gnx - 1.0));
241 void av_hblen(FILE* fp3, FILE* fp3a, FILE* fp4, FILE* fp4a, FILE* fp5, FILE* fp5a, real t, int nres, t_bb bb[])
243 int i, n3 = 0, n4 = 0, n5 = 0;
244 real d3 = 0, d4 = 0, d5 = 0;
246 for (i = 0; (i < nres - 3); i++)
250 fprintf(fp3a, "%10g", bb[i].d3);
255 fprintf(fp4a, "%10g", bb[i].d4);
261 fprintf(fp5a, "%10g", bb[i].d5);
267 fprintf(fp3, "%10g %10g\n", t, d3 / n3);
268 fprintf(fp4, "%10g %10g\n", t, d4 / n4);
269 fprintf(fp5, "%10g %10g\n", t, d5 / n5);
275 void av_phipsi(FILE* fphi, FILE* fpsi, FILE* fphi2, FILE* fpsi2, real t, int nres, t_bb bb[])
278 real phi = 0, psi = 0;
280 fprintf(fphi2, "%10g", t);
281 fprintf(fpsi2, "%10g", t);
282 for (i = 0; (i < nres); i++)
288 fprintf(fphi2, " %10g", bb[i].phi);
289 fprintf(fpsi2, " %10g", bb[i].psi);
293 fprintf(fphi, "%10g %10g\n", t, (phi / n));
294 fprintf(fpsi, "%10g %10g\n", t, (psi / n));
295 fprintf(fphi2, "\n");
296 fprintf(fpsi2, "\n");
299 static void set_ahcity(int nbb, t_bb bb[])
304 for (n = 0; (n < nbb); n++)
306 pp2 = gmx::square(bb[n].phi - PHI_AHX) + gmx::square(bb[n].psi - PSI_AHX);
308 bb[n].bHelix = FALSE;
311 if ((bb[n].d4 < 0.36) || ((n > 0) && bb[n - 1].bHelix))
319 t_bb* mkbbind(const char* fn,
329 static const char* bb_nm[] = { "N", "H", "CA", "C", "O", "HN" };
330 #define NBB asize(bb_nm)
335 fprintf(stderr, "Please select a group containing the entire backbone\n");
336 rd_index(fn, 1, &gnx, index, &grpname);
338 fprintf(stderr, "Checking group %s\n", grpname);
339 r0 = r1 = atom[(*index)[0]].resind;
340 for (int i = 1; (i < gnx); i++)
342 r0 = std::min(r0, atom[(*index)[i]].resind);
343 r1 = std::max(r1, atom[(*index)[i]].resind);
345 int rnr = r1 - r0 + 1;
346 fprintf(stderr, "There are %d residues\n", rnr);
348 for (int i = 0; (i < rnr); i++)
350 bb[i].N = bb[i].H = bb[i].CA = bb[i].C = bb[i].O = -1;
351 bb[i].resno = res0 + i;
354 for (int i = 0; (i < gnx); i++)
356 int ai = (*index)[i];
357 // Create an index into the residue index for the topology.
358 int resindex = atom[ai].resind;
359 // Create an index into the residues present in the selected
361 int bbindex = resindex - r0;
362 if (std::strcmp(*(resinfo[resindex].name), "PRO") == 0)
364 // For PRO in a peptide, there is no H bound to backbone
365 // N, so use CD instead.
366 if (std::strcmp(*(atomname[ai]), "CD") == 0)
372 for (; (k < NBB); k++)
374 if (std::strcmp(bb_nm[k], *(atomname[ai])) == 0)
381 case 0: bb[bbindex].N = ai; break;
384 /* No attempt to address the case where some weird input has both H and HN atoms in the group */
387 case 2: bb[bbindex].CA = ai; break;
388 case 3: bb[bbindex].C = ai; break;
389 case 4: bb[bbindex].O = ai; break;
395 for (; (i0 < rnr); i0++)
397 if ((bb[i0].N != -1) && (bb[i0].H != -1) && (bb[i0].CA != -1) && (bb[i0].C != -1)
404 for (; (i1 >= 0); i1--)
406 if ((bb[i1].N != -1) && (bb[i1].H != -1) && (bb[i1].CA != -1) && (bb[i1].C != -1)
421 for (int i = i0; (i < i1); i++)
423 bb[i].Cprev = bb[i - 1].C;
424 bb[i].Nnext = bb[i + 1].N;
426 rnr = std::max(0, i1 - i0 + 1);
427 fprintf(stderr, "There are %d complete backbone residues (from %d to %d)\n", rnr, bb[i0].resno, bb[i1].resno);
430 gmx_fatal(FARGS, "Zero complete backbone residues were found, cannot proceed");
432 for (int i = 0; (i < rnr); i++, i0++)
438 for (int i = 0; (i < rnr); i++)
440 int resindex = atom[bb[i].CA].resind;
441 sprintf(bb[i].label, "%s%d", *(resinfo[resindex].name), resinfo[resindex].nr);
445 *nbb = rnr * asize(bb_nm);
450 real pprms(FILE* fp, int nbb, t_bb bb[])
453 real rms, rmst, rms2;
456 for (i = n = 0; (i < nbb); i++)
460 rms = std::sqrt(bb[i].pprms2);
462 rms2 += bb[i].pprms2;
463 fprintf(fp, "%10g ", rms);
468 rms = std::sqrt(rms2 / n - gmx::square(rmst / n));
473 void calc_hxprops(int nres, t_bb bb[], const rvec x[])
475 int i, ao, an, t1, t2, t3;
476 rvec dx, r_ij, r_kj, r_kl, m, n;
478 for (i = 0; (i < nres); i++)
481 bb[i].d4 = bb[i].d3 = bb[i].d5 = 0;
485 rvec_sub(x[ao], x[an], dx);
491 rvec_sub(x[ao], x[an], dx);
497 rvec_sub(x[ao], x[an], dx);
501 bb[i].phi = gmx::c_rad2Deg
502 * dih_angle(x[bb[i].Cprev],
515 bb[i].psi = gmx::c_rad2Deg
516 * dih_angle(x[bb[i].N],
529 bb[i].pprms2 = gmx::square(bb[i].phi - PHI_AHX) + gmx::square(bb[i].psi - PSI_AHX);
531 bb[i].jcaha += 1.4 * std::sin((bb[i].psi + 138.0) * gmx::c_deg2Rad)
532 - 4.1 * std::cos(2.0 * gmx::c_deg2Rad * (bb[i].psi + 138.0))
533 + 2.0 * std::cos(2.0 * gmx::c_deg2Rad * (bb[i].phi + 30.0));
537 static void check_ahx(int nres, t_bb bb[], int* hstart, int* hend)
539 int h0, h1, h0sav, h1sav;
541 set_ahcity(nres, bb);
542 h0 = h0sav = h1sav = 0;
545 for (; (!bb[h0].bHelix) && (h0 < nres - 4); h0++) {}
546 for (h1 = h0; bb[h1 + 1].bHelix && (h1 < nres - 1); h1++) {}
549 /*fprintf(stderr,"Helix from %d to %d\n",h0,h1);*/
550 if (h1 - h0 > h1sav - h0sav)
557 } while (h1 < nres - 1);
562 void do_start_end(int nres, t_bb bb[], int* nbb, int bbindex[], int* nca, int caindex[], gmx_bool bRange, int rStart, int rEnd)
564 int i, j, hstart = 0, hend = 0;
568 for (i = 0; (i < nres); i++)
570 if ((bb[i].resno >= rStart) && (bb[i].resno <= rEnd))
574 if (bb[i].resno == rStart)
578 if (bb[i].resno == rEnd)
586 /* Find start and end of longest helix fragment */
587 check_ahx(nres, bb, &hstart, &hend);
589 fprintf(stderr, "helix from: %d through %d\n", bb[hstart].resno, bb[hend].resno);
591 for (j = 0, i = hstart; (i <= hend); i++)
593 bbindex[j++] = bb[i].N;
594 bbindex[j++] = bb[i].H;
595 bbindex[j++] = bb[i].CA;
596 bbindex[j++] = bb[i].C;
597 bbindex[j++] = bb[i].O;
598 caindex[i - hstart] = bb[i].CA;
601 *nca = (hend - hstart + 1);
604 void pr_bb(FILE* fp, int nres, t_bb bb[])
610 "%3s %3s %3s %3s %3s %7s %7s %7s %7s %7s %3s\n",
622 for (i = 0; (i < nres); i++)
625 "%3d %3d %3d %3d %3d %7.2f %7.2f %7.3f %7.3f %7.3f %3s\n",
636 bb[i].bHelix ? "Yes" : "No");