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 * Gromacs Runs One Microsecond At Cannonball Speeds
41 char *edc_names
[edcNR
+1] = { "NONBND", "BOND", "DISRE", NULL
};
43 bool newres(int i
,t_atom atom
[])
45 return ((i
== 0) || (atom
[i
].resnr
!= atom
[i
-1].resnr
));
48 void pr_corr(FILE *log
,t_correct
*c
)
50 fprintf(log
,"Parameters for this disco run\n");
51 fprintf(log
,"maxnit = %d\n",c
->maxnit
);
52 fprintf(log
,"nbcheck = %d\n",c
->nbcheck
);
53 fprintf(log
,"nstprint = %d\n",c
->nstprint
);
54 fprintf(log
,"nstranlist = %d\n",c
->nstranlist
);
55 fprintf(log
,"ngrow = %d\n",c
->ngrow
);
56 fprintf(log
,"bExplicit = %s\n",BOOL(c
->bExplicit
));
57 fprintf(log
,"bChiral = %s\n",BOOL(c
->bChiral
));
58 fprintf(log
,"bPep = %s\n",BOOL(c
->bPep
));
59 fprintf(log
,"bDump = %s\n",BOOL(c
->bDump
));
60 fprintf(log
,"bLowerOnly = %s\n",BOOL(c
->bLowerOnly
));
61 fprintf(log
,"bRanlistFirst = %s\n",BOOL(c
->bRanlistFirst
));
62 fprintf(log
,"bCubic = %s\n",BOOL(c
->bCubic
));
63 fprintf(log
,"bBox = %s\n",BOOL(c
->bBox
));
64 fprintf(log
,"bCenter = %s\n",BOOL(c
->bCenter
));
65 fprintf(log
,"ndist = %d\n",c
->ndist
);
66 fprintf(log
,"npep = %d\n",c
->npep
);
67 fprintf(log
,"nimp = %d\n",c
->nimp
);
68 fprintf(log
,"lowdev = %g\n",c
->lodev
);
72 t_correct
*init_corr(int maxnit
,int nstprint
,int nbcheck
,int nstranlist
,
73 int ngrow
,bool bExplicit
,bool bChiral
,bool bPep
,
74 bool bDump
,real lowdev
,bool bLowerOnly
,
75 bool bRanlistFirst
,bool bCubic
,bool bBox
,bool bCenter
)
81 c
->nstprint
= nstprint
;
83 c
->nstranlist
= nstranlist
;
84 c
->bExplicit
= bExplicit
;
92 c
->bLowerOnly
= bLowerOnly
;
93 c
->bRanlistFirst
= bRanlistFirst
;
99 if (nstranlist
!= 0) {
101 "Warning: setting nstranlist to 0 when using ranlistfirst");
108 void init_corr2(t_correct
*c
,int natom
)
113 fatal_error(0,"Can not make tags without distances. %s, %d",
116 /* Initiate the ip index */
117 snew(c
->ip
,c
->ndist
);
119 /* Init boolean array */
120 snew(c
->bViol
,natom
);
122 /* Initiate omega array */
123 snew(c
->omega
,c
->npep
);
125 /* Initiate improper array */
126 srenew(c
->idih
,c
->nimp
+1);
128 /* Now make the tags */
129 snew(c
->tag
,natom
+1);
132 for(i
=0; (i
<c
->ndist
); i
++) {
134 if (c
->d
[i
].ai
!= ai
) {
135 /* New tag starts here, but skip over possible missing atoms */
136 while ((n
< natom
) && (n
<c
->d
[i
].ai
)) {
142 fatal_error(0,"Too many atoms, or distances not sorted");*/
152 fatal_error(0,"Too many atoms, or distances not sorted");
154 fprintf(debug
,"There are %d tags for %d atoms\n",n
,natom
);
157 for(i
=0; (i
<=natom
); i
++)
158 fprintf(debug
,"tag[%5d] = %d\n",i
,c
->tag
[i
]);
161 void center_in_box(int natom
,rvec xin
[],matrix box
,rvec xout
[])
166 /* Dump the optimization trajectory to an xtc file */
167 /* Put the whole thing in the center of the box 1st */
169 for(i
=0; (i
<natom
); i
++) {
170 copy_rvec(xin
[i
],xout
[i
]);
171 rvec_inc(xcm
,xin
[i
]);
173 for(m
=0; (m
<DIM
); m
++)
174 dx
[m
] = 0.5*box
[m
][m
]-xcm
[m
]/natom
;
175 for(i
=0; (i
<natom
); i
++)
176 rvec_inc(xout
[i
],dx
);
179 void define_peptide_bonds(FILE *log
,t_atoms
*atoms
,t_correct
*c
)
181 int i
,npep
,naa
,nlist
;
185 naa
= get_strings("aminoacids.dat",&aa
);
186 dlist
= mk_dlist(log
,atoms
,&nlist
,TRUE
,TRUE
,FALSE
,0,1,naa
,aa
);
187 for(i
=0; (i
<naa
); i
++)
192 snew(c
->pepbond
,nlist
);
193 for(i
=0; (i
<nlist
); i
++) {
194 if (has_dihedral(edOmega
,&dlist
[i
])) {
195 c
->pepbond
[npep
].ai
= dlist
[i
].atm
.minC
;
196 c
->pepbond
[npep
].aj
= dlist
[i
].atm
.minO
;
197 c
->pepbond
[npep
].ak
= dlist
[i
].atm
.N
;
198 c
->pepbond
[npep
].al
= dlist
[i
].atm
.H
;
199 c
->pepbond
[npep
].am
= dlist
[i
].atm
.Cn
[1];
205 pr_dlist(debug
,nlist
,dlist
,1.0);
207 fprintf(log
,"There are %d peptide bonds\n",npep
);
210 static char *aname(t_atoms
*atoms
,int i
)
214 sprintf(buf
,"%4s%3d:%4s",
215 *(atoms
->resname
[atoms
->atom
[i
].resnr
]),
216 atoms
->atom
[i
].resnr
+1,
217 *(atoms
->atomname
[i
]));
222 int find_atom(t_atoms
*atoms
,int resnr
,int j0
,char *nm
)
226 for(j
=j0
; (j
< atoms
->nr
) && (atoms
->atom
[j
].resnr
== resnr
); j
++)
227 if (strcmp(*atoms
->atomname
[j
],nm
) == 0) {
234 void define_impropers(FILE *log
,t_atoms
*atoms
,t_correct
*c
)
241 { NULL
, { "CA", "N", "C", "CB" } },
242 { NULL
, { "N", "CA", "H1", "H3" } },
243 { "LYSH", { "NZ", "CE", "HZ2", "HZ1" } },
244 { "LYSH", { "NZ", "CE", "HZ1", "HZ3" } },
245 { "LEU", { "CG", "CD2", "CD1", "CB" } },
246 { "VAL", { "CB", "CG2", "CG1", "CA" } },
247 { "ILE", { "CB", "CG1", "CG2", "CA" } },
248 { "THR", { "CB", "OG1", "CG2", "CA" } }
250 #define NID asize(id)
251 int i
,j
,k
,l
,aa
[4],nimp
;
254 for(i
=0; (i
<atoms
->nres
); i
++) {
255 /* Skip until residue number */
256 for(j
=0; (j
<atoms
->nr
) && (atoms
->atom
[j
].resnr
!= i
); j
++)
258 for(k
=0; (k
<NID
); k
++) {
259 if ((id
[k
].res
== NULL
) ||
260 (strcmp(id
[k
].res
,*atoms
->resname
[i
]) == 0)) {
261 /* This (i) is the right residue to look for this improper (k) */
263 aa
[l
] = find_atom(atoms
,i
,j
,id
[k
].aa
[l
]);
264 if ((aa
[0] != -1) && (aa
[1] != -1) && (aa
[2] != -1) && (aa
[3] != -1)) {
265 srenew(c
->imp
,nimp
+1);
266 c
->imp
[nimp
].ai
= aa
[0];
267 c
->imp
[nimp
].aj
= aa
[1];
268 c
->imp
[nimp
].ak
= aa
[2];
269 c
->imp
[nimp
].al
= aa
[3];
277 fprintf(log
,"There are %d impropers\n",c
->nimp
);
279 fprintf(debug
,"Overview of improper dihedrals\n");
280 for(i
=0; (i
<c
->nimp
); i
++) {
281 fprintf(debug
," %s",aname(atoms
,c
->imp
[i
].ai
));
282 fprintf(debug
," %s",aname(atoms
,c
->imp
[i
].aj
));
283 fprintf(debug
," %s",aname(atoms
,c
->imp
[i
].ak
));
284 fprintf(debug
," %s\n",aname(atoms
,c
->imp
[i
].al
));
289 void pr_dist(FILE *fp
,bool bHeader
,t_correct
*c
,int i
)
294 fprintf(fp
,"#%4s%5s%10s%10s%10s\n","ai","aj","ideal","lb","ub");
295 switch (c
->d
[i
].cons_type
) {
297 ideal
= 5*(c
->d
[i
].lb
+c
->d
[i
].ub
);
306 fatal_error(0,"cons_type for distance %d = %d\n",i
,c
->d
[i
].cons_type
);
308 fprintf(fp
,"%5d%5d%10.5f%10.5f%10.5f\n",1+c
->d
[i
].ai
,1+c
->d
[i
].aj
,
309 ideal
,10*c
->d
[i
].lb
,10*c
->d
[i
].ub
);
312 void pr_distances(FILE *fp
,t_correct
*c
)
316 for(i
=0; (i
<c
->ndist
); i
++)
317 pr_dist(fp
,(i
==0),c
,i
);
320 void add_dist(t_correct
*c
,int ai
,int aj
,real lb
,real ideal
,real ub
,real w
[])
324 if ((w
[ai
] != 0) || (w
[aj
] != 0)) {
325 if (n
== c
->maxdist
) {
327 srenew(c
->d
,c
->maxdist
);
332 c
->d
[n
].cons_type
= edcBOND
;
333 else if (ideal
== 0.0)
334 c
->d
[n
].cons_type
= edcNONBOND
;
336 c
->d
[n
].cons_type
= edcDISRE
;
339 c
->d
[n
].wi
= w
[ai
]/(w
[ai
]+w
[aj
]);
344 void read_dist(FILE *log
,char *fn
,int natom
,t_correct
*c
)
352 for(i
=0; (i
<edcNR
); i
++)
356 while (fgets(buf
,255,fp
)) {
359 if (sscanf(buf
,"%d%d%lf%lf%lf",&ai
,&aj
,&ideal
,&lb
,&ub
) != 5)
360 fprintf(stderr
,"Error in %s, line %d\n",fn
,nline
);
362 add_dist(c
,ai
-1,aj
-1,lb
*0.1,ideal
*0.1,ub
*0.1,c
->weight
);
363 nnn
[c
->d
[c
->ndist
-1].cons_type
]++;
369 fprintf(log
,"Read distances from file %s\n",fn
);
370 for(i
=0; (i
<edcNR
); i
++)
371 fprintf(log
,"There were %d %s distances\n",
372 nnn
[i
],edc_names
[i
]);
375 real
*read_weights(char *fn
,int natom
)
384 /* Read the weights from the occupancy field in the pdb file */
386 init_t_atoms(&newatoms
,natom
,TRUE
);
387 read_pdb_conf(fn
,title
,&newatoms
,x
,box
,FALSE
);
389 for(i
=0; (i
<newatoms
.nr
); i
++)
390 w
[i
] = newatoms
.pdbinfo
[i
].occup
;
391 free_t_atoms(&newatoms
);
397 void check_dist(FILE *log
,t_correct
*c
)
402 fprintf(log
,"Checking distances for internal consistency\n");
403 for(i
=0; (i
<c
->ndist
); i
++) {
404 if ((c
->d
[i
].ub
!= 0) && ((c
->d
[i
].ub
- c
->d
[i
].lb
) < tol
)) {
405 pr_dist(log
,TRUE
,c
,i
);