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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * 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.
50 #include "gmx_fatal.h"
54 static const char *pp_pat[] = { "C", "N", "CA", "C", "N" };
55 #define NPP (sizeof(pp_pat)/sizeof(pp_pat[0]))
57 static int d_comp(const void *a,const void *b)
64 if (da->ai[1] < db->ai[1])
66 else if (da->ai[1] == db->ai[1])
67 return (da->ai[2] - db->ai[2]);
73 static void calc_dihs(t_xrama *xr)
76 rvec r_ij,r_kj,r_kl,m,n;
79 gmx_rmpbc_t gpbc=NULL;
81 gpbc = gmx_rmpbc_init(xr->idef,xr->ePBC,xr->natoms,xr->box);
82 gmx_rmpbc(gpbc,xr->natoms,xr->box,xr->x);
85 for(i=0; (i<xr->ndih); i++) {
87 dd->ang=dih_angle(xr->x[dd->ai[0]],xr->x[dd->ai[1]],
88 xr->x[dd->ai[2]],xr->x[dd->ai[3]],
90 r_ij,r_kj,r_kl,m,n,&sign,&t1,&t2,&t3);
94 gmx_bool new_data(t_xrama *xr)
96 if (!read_next_x(xr->oenv,xr->traj,&xr->t,xr->natoms,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++)
109 if (strcmp(find,*names[i]) == 0)
114 static void add_xr(t_xrama *xr,int ff[5],t_atoms *atoms)
119 srenew(xr->dih,xr->ndih+2);
121 xr->dih[xr->ndih].ai[i]=ff[i];
123 xr->dih[xr->ndih+1].ai[i]=ff[i+1];
126 srenew(xr->pp,xr->npp+1);
127 xr->pp[xr->npp].iphi=xr->ndih-2;
128 xr->pp[xr->npp].ipsi=xr->ndih-1;
129 xr->pp[xr->npp].bShow=FALSE;
130 sprintf(buf,"%s-%d",*atoms->resinfo[atoms->atom[ff[1]].resind].name,
131 atoms->resinfo[atoms->atom[ff[1]].resind].nr);
132 xr->pp[xr->npp].label=strdup(buf);
136 static void get_dih(t_xrama *xr,t_atoms *atoms)
142 for(i=0; (i<atoms->nr); ) {
144 for(j=0; (j<NPP); j++) {
145 if ((ff[j]=find_atom(pp_pat[j],atoms->atomname,found,atoms->nr)) == -1)
154 fprintf(stderr,"Found %d phi-psi combinations\n",xr->npp);
157 static int search_ff(int thisff[NPP],int ndih,int **ff)
160 gmx_bool bFound=FALSE;
162 for(j=0; (j<ndih); j++) {
164 for(k=1; (k<=3); k++)
165 bFound = bFound && (thisff[k]==ff[j][k]);
176 ff[ndih][k]=thisff[k];
182 static void min_max(t_xrama *xr)
188 for(i=0; (i<xr->ndih); i++)
189 for(j=0; (j<4); j++) {
193 else if (ai > xr->amax)
198 static void get_dih_props(t_xrama *xr,t_idef *idef,int mult)
204 ia=idef->il[F_PDIHS].iatoms;
205 for (i=0; (i<idef->il[F_PDIHS].nr); ) {
207 ftype=idef->functype[ft];
208 nra=interaction_function[ftype].nratoms;
210 if (ftype != F_PDIHS)
211 gmx_incons("ftype is not a dihedral");
215 if ((dd = (t_dih *)bsearch(&key,xr->dih,xr->ndih,(size_t)sizeof(key),d_comp))
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++) {
226 if (xr->dih[i].mult == 0) {
228 "Dihedral around %d,%d not found in topology. Using mult=%d\n",
229 xr->dih[i].ai[1],xr->dih[i].ai[2],mult);
230 xr->dih[i].mult=mult;
238 t_topology *init_rama(const output_env_t oenv,const char *infile,
239 const char *topfile, t_xrama *xr,int mult)
245 top=read_top(topfile,&xr->ePBC);
247 /*get_dih2(xr,top->idef.functype,&(top->idef.bondeds),&(top->atoms));*/
248 get_dih(xr,&(top->atoms));
249 get_dih_props(xr,&(top->idef),mult);
250 xr->natoms=read_first_x(oenv,&xr->traj,infile,&t,&(xr->x),xr->box);
251 xr->idef=&(top->idef);