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,2018,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
46 #include "gromacs/listed_forces/bonded.h"
47 #include "gromacs/pbcutil/rmpbc.h"
48 #include "gromacs/utility/cstringutil.h"
49 #include "gromacs/utility/fatalerror.h"
50 #include "gromacs/utility/futil.h"
51 #include "gromacs/utility/smalloc.h"
53 static const char* pp_pat[] = { "C", "N", "CA", "C", "N" };
54 #define NPP (sizeof(pp_pat) / sizeof(pp_pat[0]))
56 static bool d_comp(const t_dih& a, const t_dih& b)
58 if (a.ai[1] < b.ai[1])
62 else if (a.ai[1] == b.ai[1])
64 return a.ai[2] < b.ai[2];
73 static void calc_dihs(t_xrama* xr)
76 rvec r_ij, r_kj, r_kl, m, n;
78 gmx_rmpbc_t gpbc = nullptr;
80 gpbc = gmx_rmpbc_init(xr->idef, xr->ePBC, xr->natoms);
81 gmx_rmpbc(gpbc, xr->natoms, xr->box, xr->x);
84 for (i = 0; (i < xr->ndih); i++)
87 dd->ang = dih_angle(xr->x[dd->ai[0]], xr->x[dd->ai[1]], xr->x[dd->ai[2]], xr->x[dd->ai[3]],
88 nullptr, r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3);
92 gmx_bool new_data(t_xrama* xr)
94 if (!read_next_x(xr->oenv, xr->traj, &xr->t, xr->x, xr->box))
104 static int find_atom(const char* find, char*** names, int start, int nr)
108 for (i = start; (i < nr); i++)
110 if (std::strcmp(find, *names[i]) == 0)
118 static void add_xr(t_xrama* xr, const int ff[5], const t_atoms* atoms)
123 srenew(xr->dih, xr->ndih + 2);
124 for (i = 0; (i < 4); i++)
126 xr->dih[xr->ndih].ai[i] = ff[i];
128 for (i = 0; (i < 4); i++)
130 xr->dih[xr->ndih + 1].ai[i] = ff[i + 1];
134 srenew(xr->pp, xr->npp + 1);
135 xr->pp[xr->npp].iphi = xr->ndih - 2;
136 xr->pp[xr->npp].ipsi = xr->ndih - 1;
137 xr->pp[xr->npp].bShow = FALSE;
138 sprintf(buf, "%s-%d", *atoms->resinfo[atoms->atom[ff[1]].resind].name,
139 atoms->resinfo[atoms->atom[ff[1]].resind].nr);
140 xr->pp[xr->npp].label = gmx_strdup(buf);
144 static void get_dih(t_xrama* xr, const t_atoms* atoms)
150 for (i = 0; (i < atoms->nr);)
153 for (j = 0; (j < NPP); j++)
155 if ((ff[j] = find_atom(pp_pat[j], atoms->atomname, found, atoms->nr)) == -1)
165 add_xr(xr, ff, atoms);
168 fprintf(stderr, "Found %d phi-psi combinations\n", xr->npp);
171 static void min_max(t_xrama* xr)
175 xr->amin = xr->natoms;
177 for (i = 0; (i < xr->ndih); i++)
179 for (j = 0; (j < 4); j++)
181 ai = xr->dih[i].ai[j];
186 else if (ai > xr->amax)
194 static void get_dih_props(t_xrama* xr, const t_idef* idef, int mult)
196 int i, ft, ftype, nra;
200 ia = idef->il[F_PDIHS].iatoms;
201 for (i = 0; (i < idef->il[F_PDIHS].nr);)
204 ftype = idef->functype[ft];
205 nra = interaction_function[ftype].nratoms;
207 if (ftype != F_PDIHS)
209 gmx_incons("ftype is not a dihedral");
214 dd = std::lower_bound(xr->dih, xr->dih + xr->ndih, key, d_comp);
215 if (dd < xr->dih + xr->ndih && !d_comp(key, *dd))
217 dd->mult = idef->iparams[ft].pdihs.mult;
218 dd->phi0 = idef->iparams[ft].pdihs.phiA;
224 /* Fill in defaults for values not in the topology */
225 for (i = 0; (i < xr->ndih); i++)
227 if (xr->dih[i].mult == 0)
229 fprintf(stderr, "Dihedral around %d,%d not found in topology. Using mult=%d\n",
230 xr->dih[i].ai[1], xr->dih[i].ai[2], mult);
231 xr->dih[i].mult = mult;
232 xr->dih[i].phi0 = 180;
238 t_topology* init_rama(gmx_output_env_t* oenv, const char* infile, const char* topfile, t_xrama* xr, int mult)
243 top = read_top(topfile, &xr->ePBC);
245 /*get_dih2(xr,top->idef.functype,&(top->idef.bondeds),&(top->atoms));*/
246 get_dih(xr, &(top->atoms));
247 get_dih_props(xr, &(top->idef), mult);
248 xr->natoms = read_first_x(oenv, &xr->traj, infile, &t, &(xr->x), xr->box);
249 xr->idef = &(top->idef);