4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * Gyas ROwers Mature At Cryogenic Speed
47 static const char *pp_pat
[] = { "C", "N", "CA", "C", "N" };
48 #define NPP (sizeof(pp_pat)/sizeof(pp_pat[0]))
50 static int d_comp(const void *a
,const void *b
)
57 if (da
->ai
[1] < db
->ai
[1])
59 else if (da
->ai
[1] == db
->ai
[1])
60 return (da
->ai
[2] - db
->ai
[2]);
66 static void calc_dihs(t_xrama
*xr
)
69 rvec r_ij
,r_kj
,r_kl
,m
,n
;
73 rm_pbc(xr
->idef
,xr
->natoms
,xr
->box
,xr
->x
,xr
->x
);
75 for(i
=0; (i
<xr
->ndih
); i
++) {
77 dd
->ang
=dih_angle(xr
->box
,
78 xr
->x
[dd
->ai
[0]],xr
->x
[dd
->ai
[1]],
79 xr
->x
[dd
->ai
[2]],xr
->x
[dd
->ai
[3]],
80 r_ij
,r_kj
,r_kl
,m
,n
,&cos_phi
,&sign
);
84 bool new_data(t_xrama
*xr
)
86 if (!read_next_x(xr
->traj
,&xr
->t
,xr
->natoms
,xr
->x
,xr
->box
))
94 static int find_atom(const char *find
,char ***names
,int start
,int nr
)
98 for(i
=start
; (i
<nr
); i
++)
99 if (strcmp(find
,*names
[i
]) == 0)
104 static void add_xr(t_xrama
*xr
,int ff
[5],t_atoms
*atoms
)
109 srenew(xr
->dih
,xr
->ndih
+2);
111 xr
->dih
[xr
->ndih
].ai
[i
]=ff
[i
];
113 xr
->dih
[xr
->ndih
+1].ai
[i
]=ff
[i
+1];
116 srenew(xr
->pp
,xr
->npp
+1);
117 xr
->pp
[xr
->npp
].iphi
=xr
->ndih
-2;
118 xr
->pp
[xr
->npp
].ipsi
=xr
->ndih
-1;
119 xr
->pp
[xr
->npp
].bShow
=FALSE
;
120 sprintf(buf
,"%s-%d",*atoms
->resname
[atoms
->atom
[ff
[1]].resnr
],
121 atoms
->atom
[ff
[1]].resnr
+1);
122 xr
->pp
[xr
->npp
].label
=strdup(buf
);
126 static void get_dih(t_xrama
*xr
,t_atoms
*atoms
)
131 for(i
=0; (i
<atoms
->nr
); ) {
133 for(j
=0; (j
<NPP
); j
++) {
134 if ((ff
[j
]=find_atom(pp_pat
[j
],atoms
->atomname
,found
,atoms
->nr
)) == -1)
143 fprintf(stderr
,"Found %d phi-psi combinations\n",xr
->npp
);
146 static int search_ff(int thisff
[NPP
],int ndih
,int **ff
)
151 for(j
=0; (j
<ndih
); j
++) {
153 for(k
=1; (k
<=3); k
++)
154 bFound
= bFound
&& (thisff
[k
]==ff
[j
][k
]);
165 ff
[ndih
][k
]=thisff
[k
];
171 static void get_dih2(t_xrama
*xr
,t_functype functype
[],
172 t_ilist
*bondeds
,t_atoms
*atoms
)
174 int found
,**ff
,thisff
[NPP
];
175 int i
,j
,k
,type
,ftype
,nat
,ai
,aj
,ak
,al
;
176 char *cai
,*caj
,*cak
,*cal
;
181 maxdih
=1+(bondeds
->nr
/5);
183 for(j
=0; (j
<maxdih
); j
++) {
186 fprintf(stderr
,"There may be as many as %d dihedrals...\n",maxdih
);
188 iatoms
=bondeds
->iatoms
;
189 for(i
=0; (i
<bondeds
->nr
); ) {
191 ftype
=functype
[type
];
192 nat
=interaction_function
[ftype
].nratoms
+1;
194 if (ftype
== F_PDIHS
) {
195 ai
=iatoms
[1]; cai
=*atoms
->atomname
[ai
];
196 aj
=iatoms
[2]; caj
=*atoms
->atomname
[aj
];
197 ak
=iatoms
[3]; cak
=*atoms
->atomname
[ak
];
198 al
=iatoms
[4]; cal
=*atoms
->atomname
[al
];
200 for(j
=0; (j
<NPP
); j
++)
202 if (strcasecmp(cai
,"C") == 0) {
203 /* May be a Phi angle */
204 if ((strcasecmp(caj
,"N") == 0) &&
205 (strcasecmp(cak
,"CA") == 0) &&
206 (strcasecmp(cal
,"C") == 0))
207 thisff
[0]=ai
,thisff
[1]=aj
,thisff
[2]=ak
,thisff
[3]=al
;
209 else if (strcasecmp(cai
,"N") == 0) {
210 /* May be a Psi angle */
211 if ((strcasecmp(caj
,"CA") == 0) &&
212 (strcasecmp(cak
,"C") == 0) &&
213 (strcasecmp(cal
,"N") == 0))
214 thisff
[1]=ai
,thisff
[2]=aj
,thisff
[3]=ak
,thisff
[4]=al
;
216 if (thisff
[1] != -1) {
217 ndih
=search_ff(thisff
,ndih
,ff
);
219 fatal_error(0,"More than %n dihedrals found. SEGV?",maxdih
);
222 fprintf(stderr
,"No Phi or Psi, atoms: %s %s %s %s\n",
229 for(j
=0; (j
<ndih
); j
++) {
230 if ((ff
[j
][0] != -1) && (ff
[j
][4] != -1))
231 add_xr(xr
,ff
[j
],atoms
);
233 fprintf(stderr
,"Incomplete dihedral(%d) atoms: ",j
);
234 for(k
=0; (k
<NPP
); k
++)
235 fprintf(stderr
,"%2s ",
236 ff
[j
][k
] == -1 ? "-1" : *atoms
->atomname
[ff
[j
][k
]]);
237 fprintf(stderr
,"\n");
240 fprintf(stderr
,"Found %d phi-psi combinations\n",xr
->npp
);
243 static void min_max(t_xrama
*xr
)
249 for(i
=0; (i
<xr
->ndih
); i
++)
250 for(j
=0; (j
<4); j
++) {
254 else if (ai
> xr
->amax
)
259 static void get_dih_props(t_xrama
*xr
,t_idef
*idef
)
265 ia
=idef
->il
[F_PDIHS
].iatoms
;
266 for (i
=0; (i
<idef
->il
[F_PDIHS
].nr
); ) {
268 ftype
=idef
->functype
[ft
];
269 nra
=interaction_function
[ftype
].nratoms
;
271 assert (ftype
== F_PDIHS
);
275 if ((dd
= bsearch(&key
,xr
->dih
,xr
->ndih
,(size_t)sizeof(key
),d_comp
))
277 dd
->mult
=idef
->iparams
[ft
].pdihs
.mult
;
278 dd
->phi0
=idef
->iparams
[ft
].pdihs
.phiA
;
285 for(i
=0; (i
<xr
->ndih
); i
++)
286 if (xr
->dih
[i
].mult
== 0)
287 fatal_error(0,"Dihedral around %d,%d not found in topology",
288 xr
->dih
[i
].ai
[1],xr
->dih
[i
].ai
[2]);
293 t_topology
*init_rama(char *infile
,char *topfile
,t_xrama
*xr
)
298 top
=read_top(topfile
);
300 /*get_dih2(xr,top->idef.functype,&(top->idef.bondeds),&(top->atoms));*/
301 get_dih(xr
,&(top
->atoms
));
302 get_dih_props(xr
,&(top
->idef
));
303 xr
->natoms
=read_first_x(&xr
->traj
,infile
,&t
,&(xr
->x
),xr
->box
);
304 xr
->idef
=&(top
->idef
);