4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
49 t_atomtype
*read_atype(char *adb
,t_symtab
*tab
)
54 char buf
[STRLEN
],name
[STRLEN
];
59 sprintf(aadb
,"%s.atp",adb
);
64 snew(at
->atomname
,MAXAT
);
66 for(nratt
=0; ; nratt
++) {
68 fatal_error(0,"nratt >= MAXAT(%d). Increase the latter",MAXAT
);
72 /* Skip blank or comment-only lines */
74 fgets2(buf
,STRLEN
,in
);
79 } while (buf
&& strlen(buf
)==0);
84 if (sscanf(buf
,"%s%lf",name
,&m
) != 2)
86 set_at(&(at
->atom
[nratt
]),m
,0.0,nratt
,0);
87 at
->atomname
[nratt
]=put_symtab(tab
,name
);
88 fprintf(stderr
,"\rAtomtype %d",nratt
+1);
97 static void print_resatoms(FILE *out
,t_atomtype
*atype
,t_restp
*rtp
)
101 /* fprintf(out,"%5s\n",rtp->resname);
102 fprintf(out,"%5d\n",rtp->natom); */
103 fprintf(out
,"[ %s ]\n",rtp
->resname
);
104 fprintf(out
," [ atoms ]\n");
106 for(j
=0; (j
<rtp
->natom
); j
++) {
107 tp
=rtp
->atom
[j
].type
;
109 assert (tp
< atype
->nr
);
110 fprintf(out
,"%6s%6s%8.3f%6d\n",
111 *(rtp
->atomname
[j
]),*(atype
->atomname
[tp
]),
112 rtp
->atom
[j
].q
,rtp
->cgnr
[j
]);
116 static bool read_atoms(FILE *in
,char *line
,
117 t_restp
*r0
,t_symtab
*tab
,t_atomtype
*atype
)
119 int i
,j
,cg
,maxentries
;
120 char buf
[256],buf1
[256];
129 while (get_a_line(in
,line
,STRLEN
) && (strchr(line
,'[')==NULL
)) {
130 if (sscanf(line
,"%s%s%lf%d",buf
,buf1
,&q
,&cg
) != 4)
134 srenew(r0
->atom
, maxentries
);
135 srenew(r0
->atomname
, maxentries
);
136 srenew(r0
->cgnr
, maxentries
);
138 r0
->atomname
[i
]=put_symtab(tab
,buf
);
141 for(j
=0; (j
<atype
->nr
); j
++)
142 if (strcasecmp(buf1
,*(atype
->atomname
[j
])) == 0)
145 fatal_error(0,"Atom type %s (residue %s) not found in atomtype "
146 "database",buf1
,r0
->resname
);
148 r0
->atom
[i
].m
=atype
->atom
[j
].m
;
153 srenew(r0
->atomname
,i
);
159 bool read_bondeds(int bt
, FILE *in
, char *line
, t_restp
*rtp
)
164 maxrb
= rtp
->rb
[bt
].nb
;
165 while (get_a_line(in
,line
,STRLEN
) && (strchr(line
,'[')==NULL
)) {
166 if ( rtp
->rb
[bt
].nb
>= maxrb
) {
168 srenew(rtp
->rb
[bt
].b
,maxrb
);
171 for(j
=0; j
< btsNiatoms
[bt
]; j
++) {
172 if ( sscanf(line
+n
,"%s%n",str
,&ni
)==1 )
173 rtp
->rb
[bt
].b
[rtp
->rb
[bt
].nb
].a
[j
]=strdup(str
);
178 for( ; j
< MAXATOMLIST
; j
++)
179 rtp
->rb
[bt
].b
[rtp
->rb
[bt
].nb
].a
[j
]=NULL
;
180 while (isspace(line
[n
]))
183 rtp
->rb
[bt
].b
[rtp
->rb
[bt
].nb
].s
=strdup(line
+n
);
186 /* give back unused memory */
187 srenew(rtp
->rb
[bt
].b
,rtp
->rb
[bt
].nb
);
192 static void print_resbondeds(FILE *out
, int bt
, t_restp
*rtp
)
196 if (rtp
->rb
[bt
].nb
) {
197 fprintf(out
," [ %s ]\n",btsNames
[bt
]);
199 for(i
=0; i
< rtp
->rb
[bt
].nb
; i
++) {
200 for(j
=0; j
<btsNiatoms
[bt
]; j
++)
201 fprintf(out
,"%6s ",rtp
->rb
[bt
].b
[i
].a
[j
]);
202 if (rtp
->rb
[bt
].b
[i
].s
[0])
203 fprintf(out
," %s",rtp
->rb
[bt
].b
[i
].s
);
209 static void check_rtp(int nrtp
,t_restp rtp
[],char *libfn
)
213 /* check for double entries, assuming list is already sorted */
214 for(i
=1; (i
<nrtp
); i
++) {
215 if (strcasecmp(rtp
[i
-1].resname
,rtp
[i
].resname
) == 0)
216 fprintf(stderr
,"WARNING double entry %s in file %s\n",
217 rtp
[i
].resname
,libfn
);
221 static int comprtp(const void *a
,const void *b
)
228 return strcasecmp(ra
->resname
,rb
->resname
);
231 int get_bt(char* header
)
235 for(i
=0; i
<ebtsNR
; i
++)
236 if ( strcasecmp(btsNames
[i
],header
)==0 )
241 void clear_t_restp(t_restp
*rrtp
)
243 memset((void *)rrtp
, 0, sizeof(t_restp
));
246 int read_resall(char *ff
, int bts
[], t_restp
**rtp
,
247 t_atomtype
*atype
, t_symtab
*tab
, bool *bAlldih
, int *nrexcl
,
248 bool *HH14
, bool *bRemoveDih
)
251 char rrdb
[STRLEN
],line
[STRLEN
],header
[STRLEN
];
252 int i
,nrtp
,maxrtp
,bt
,nparam
;
254 bool bNextResidue
,bError
;
256 sprintf(rrdb
,"%s.rtp",ff
);
260 fprintf(debug
,"%9s %5s", "Residue", "atoms");
261 for(i
=0; i
<ebtsNR
; i
++)
262 fprintf(debug
," %10s",btsNames
[i
]);
266 /* these bonded parameters will overwritten be when *
267 * there is a [ bondedtypes ] entry in the .rtp file */
268 bts
[0] = 1; /* normal bonds */
269 bts
[1] = 1; /* normal angles */
270 bts
[2] = 1; /* normal dihedrals */
271 bts
[3] = 2; /* normal impropers */
274 /* Column 5 & 6 aren't really bonded types, but we include
275 * them here to avoid introducing a new section:
276 * Column 5: 1 means generate all dihedrals, 0 not.
277 * Column 6: Number of bonded neighbors to exclude.
278 * Coulmn 7: Generate 1,4 interactions between pairs of hydrogens
279 * Column 8: Remove impropers over the same bond as a proper dihedral
284 get_a_line(in
,line
,STRLEN
);
285 if (!get_header(line
,header
))
286 fatal_error(0,"in .rtp file at line:\n%s\n",line
);
287 if (strncasecmp("bondedtypes",header
,5)==0) {
288 get_a_line(in
,line
,STRLEN
);
289 if ((nparam
=sscanf(line
,"%d %d %d %d %d %d %d %d",&bts
[0],&bts
[1],&bts
[2],&bts
[3],bAlldih
,nrexcl
,HH14
,bRemoveDih
)) < 4 )
290 fatal_error(0,"need at least 4 (up to 8) parameters in .rtp file at line:\n%s\n",line
);
291 get_a_line(in
,line
,STRLEN
);
293 fprintf(stderr
,"Using default: not generating all possible dihedrals\n");
297 fprintf(stderr
,"Using default: excluding 3 bonded neighbors\n");
301 fprintf(stderr
,"Using default: generating 1,4 H--H interactions\n");
305 fprintf(stderr
,"Using default: removing impropers on same bond as a proper\n");
310 "Reading .rtp file without '[ bondedtypes ]' directive,\n"
311 "Will proceed as if the entry\n"
314 "\n; bonds angles dihedrals impropers all_dihedrals nr_exclusions HH14 remove_dih"
315 "\n %3d %3d %3d %3d %3d %3d %3d %3d"
317 "was present at the beginning of %s",
318 bts
[0],bts
[1],bts
[2],bts
[3], (*bAlldih
) ? 1 : 0,*nrexcl
,*HH14
,*bRemoveDih
,rrdb
);
322 if (nrtp
>= maxrtp
) {
326 clear_t_restp(&rrtp
[nrtp
]);
327 if (!get_header(line
,header
))
328 fatal_error(0,"in .rtp file at line:\n%s\n",line
);
329 rrtp
[nrtp
].resname
=strdup(header
);
331 get_a_line(in
,line
,STRLEN
);
334 while (!bNextResidue
) {
335 if (!get_header(line
,header
))
343 bError
=!read_bondeds(bt
,in
,line
,&rrtp
[nrtp
]);
345 if (strncasecmp("atoms",header
,5)==0)
346 bError
=!read_atoms(in
,line
,&(rrtp
[nrtp
]),tab
,atype
);
348 if (!feof(in
) && !get_header(line
,header
))
354 fatal_error(0,"in .rtp file in residue %s at line:\n%s\n",
355 rrtp
[nrtp
].resname
,line
);
357 if (rrtp
[nrtp
].natom
== 0)
358 fatal_error(0,"No atoms found in .rtp file in residue %s\n",
361 fprintf(debug
,"%3d %5s %5d",
362 nrtp
+1,rrtp
[nrtp
].resname
,rrtp
[nrtp
].natom
);
363 for(i
=0; i
<ebtsNR
; i
++)
364 fprintf(debug
," %10d",rrtp
[nrtp
].rb
[i
].nb
);
368 fprintf(stderr
,"\rResidue %d",nrtp
);
371 /* give back unused memory */
374 fprintf(stderr
,"\nSorting it all out...\n");
375 qsort(rrtp
,nrtp
,(size_t)sizeof(rrtp
[0]),comprtp
);
377 check_rtp(nrtp
,rrtp
,rrdb
);
384 void print_resall(FILE *out
, int bts
[], int nrtp
, t_restp rtp
[],
385 t_atomtype
*atype
, bool bAlldih
, int nrexcl
,
386 bool HH14
, bool bRemoveDih
)
390 /* print all the ebtsNR type numbers */
391 fprintf(out
,"[ bondedtypes ]\n");
392 fprintf(out
,"; bonds angles dihedrals impropers all_dihedrals nr_exclusions HH14 remove_dih\n");
393 fprintf(out
," %5d %6d %9d %9d %14d %14d %14d %14d\n\n",bts
[0],bts
[1],bts
[2],bts
[3],bAlldih
,nrexcl
,HH14
,bRemoveDih
);
395 for(i
=0; i
<nrtp
; i
++) {
396 if (rtp
[i
].natom
> 0) {
397 print_resatoms(out
,atype
,&rtp
[i
]);
398 for(bt
=0; bt
<ebtsNR
; bt
++)
399 print_resbondeds(out
,bt
,&rtp
[i
]);
404 /************************************************************
408 ***********************************************************/
409 int neq_str(char *a1
,char *a2
)
413 l
=min((int)strlen(a1
),(int)strlen(a2
));
415 while ( (j
<l
) && (toupper(a1
[j
]) == toupper(a2
[j
])) )
421 t_restp
*search_rtp(char *key
,int nrtp
,t_restp rtp
[])
427 for(i
=0; (i
<nrtp
); i
++) {
428 n
=neq_str(key
,rtp
[i
].resname
);
435 fatal_error(0,"Residue '%s' not found in residue topology database\n",key
);
436 if (strlen(rtp
[besti
].resname
) != strlen(key
))
437 fprintf(stderr
,"Warning: '%s' not found in residue topology database, "
438 "trying to use '%s'\n", key
, rtp
[besti
].resname
);