4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_resall_c
= "$Id$";
43 t_atomtype
*read_atype(char *adb
,t_symtab
*tab
)
48 char buf
[STRLEN
],name
[STRLEN
];
53 sprintf(aadb
,"%s.atp",adb
);
58 snew(at
->atomname
,MAXAT
);
60 for(nratt
=0; ; nratt
++) {
62 fatal_error(0,"nratt >= MAXAT(%d). Increase the latter",MAXAT
);
65 if (fgets2(buf
,STRLEN
,in
) == NULL
)
67 if (sscanf(buf
,"%s%lf",name
,&m
) != 2)
69 set_at(&(at
->atom
[nratt
]),m
,0.0,nratt
,0);
70 at
->atomname
[nratt
]=put_symtab(tab
,name
);
71 fprintf(stderr
,"\rAtomtype %d",nratt
+1);
80 static void print_resatoms(FILE *out
,t_atomtype
*atype
,t_restp
*rtp
)
84 /* fprintf(out,"%5s\n",rtp->resname);
85 fprintf(out,"%5d\n",rtp->natom); */
86 fprintf(out
,"[ %s ]\n",rtp
->resname
);
87 fprintf(out
," [ atoms ]\n");
89 for(j
=0; (j
<rtp
->natom
); j
++) {
92 assert (tp
< atype
->nr
);
93 fprintf(out
,"%6s%6s%8.3f%6d\n",
94 *(rtp
->atomname
[j
]),*(atype
->atomname
[tp
]),
95 rtp
->atom
[j
].q
,rtp
->cgnr
[j
]);
99 static bool read_atoms(FILE *in
,char *line
,
100 t_restp
*r0
,t_symtab
*tab
,t_atomtype
*atype
)
102 int i
,j
,cg
,maxentries
;
103 char buf
[256],buf1
[256];
112 while (get_a_line(in
,line
,STRLEN
) && (strchr(line
,'[')==NULL
)) {
113 if (sscanf(line
,"%s%s%lf%d",buf
,buf1
,&q
,&cg
) != 4)
117 srenew(r0
->atom
, maxentries
);
118 srenew(r0
->atomname
, maxentries
);
119 srenew(r0
->cgnr
, maxentries
);
121 r0
->atomname
[i
]=put_symtab(tab
,buf
);
124 for(j
=0; (j
<atype
->nr
); j
++)
125 if (strcasecmp(buf1
,*(atype
->atomname
[j
])) == 0)
128 fatal_error(0,"Atom type %s (residue %s) not found in atomtype "
129 "database",buf1
,r0
->resname
);
131 r0
->atom
[i
].m
=atype
->atom
[j
].m
;
136 srenew(r0
->atomname
,i
);
142 bool read_bondeds(int bt
, FILE *in
, char *line
, t_restp
*rtp
)
147 maxrb
= rtp
->rb
[bt
].nb
;
148 while (get_a_line(in
,line
,STRLEN
) && (strchr(line
,'[')==NULL
)) {
149 if ( rtp
->rb
[bt
].nb
>= maxrb
) {
151 srenew(rtp
->rb
[bt
].b
,maxrb
);
154 for(j
=0; j
< btsNiatoms
[bt
]; j
++) {
155 if ( sscanf(line
+n
,"%s%n",str
,&ni
)==1 )
156 rtp
->rb
[bt
].b
[rtp
->rb
[bt
].nb
].a
[j
]=strdup(str
);
161 for( ; j
< MAXATOMLIST
; j
++)
162 rtp
->rb
[bt
].b
[rtp
->rb
[bt
].nb
].a
[j
]=NULL
;
164 sscanf(line
+n
,"%s",str
);
165 rtp
->rb
[bt
].b
[rtp
->rb
[bt
].nb
].s
=strdup(str
);
168 /* give back unused memory */
169 srenew(rtp
->rb
[bt
].b
,rtp
->rb
[bt
].nb
);
174 static void print_resbondeds(FILE *out
, int bt
, t_restp
*rtp
)
178 if (rtp
->rb
[bt
].nb
) {
179 fprintf(out
," [ %s ]\n",btsNames
[bt
]);
181 for(i
=0; i
< rtp
->rb
[bt
].nb
; i
++) {
182 for(j
=0; j
<btsNiatoms
[bt
]; j
++)
183 fprintf(out
,"%6s ",rtp
->rb
[bt
].b
[i
].a
[j
]);
184 if (rtp
->rb
[bt
].b
[i
].s
[0])
185 fprintf(out
," %s",rtp
->rb
[bt
].b
[i
].s
);
191 static void check_rtp(int nrtp
,t_restp rtp
[],char *libfn
)
195 /* check for double entries, assuming list is already sorted */
196 for(i
=1; (i
<nrtp
); i
++) {
197 if (strcasecmp(rtp
[i
-1].resname
,rtp
[i
].resname
) == 0)
198 fprintf(stderr
,"WARNING double entry %s in file %s\n",
199 rtp
[i
].resname
,libfn
);
203 static int comprtp(const void *a
,const void *b
)
210 return strcasecmp(ra
->resname
,rb
->resname
);
213 int get_bt(char* header
)
217 for(i
=0; i
<ebtsNR
; i
++)
218 if ( strcasecmp(btsNames
[i
],header
)==0 )
223 void clear_t_restp(t_restp
*rrtp
)
225 memset((void *)rrtp
, 0, sizeof(t_restp
));
228 int read_resall(char *ff
, int bts
[], t_restp
**rtp
,
229 t_atomtype
*atype
, t_symtab
*tab
)
232 char rrdb
[STRLEN
],line
[STRLEN
],header
[STRLEN
];
233 int i
,nrtp
,maxrtp
,bt
;
235 bool bNextResidue
,bError
;
237 sprintf(rrdb
,"%s.rtp",ff
);
241 fprintf(debug
,"%9s %5s", "Residue", "atoms");
242 for(i
=0; i
<ebtsNR
; i
++)
243 fprintf(debug
," %10s",btsNames
[i
]);
247 /* these bonded parameters will overwritten be when *
248 * there is a [ bondedtypes ] entry in the .rtp file */
249 bts
[0] = 1; /* normal bonds */
250 bts
[1] = 1; /* normal angles */
251 bts
[2] = 1; /* normal dihedrals */
252 bts
[3] = 2; /* normal impropers */
256 get_a_line(in
,line
,STRLEN
);
257 if (!get_header(line
,header
))
258 fatal_error(0,"in .rtp file at line:\n%s\n",line
);
259 if (strncasecmp("bondedtypes",header
,5)==0) {
260 get_a_line(in
,line
,STRLEN
);
261 if (sscanf(line
,"%d %d %d %d",&bts
[0],&bts
[1],&bts
[2],&bts
[3]) != ebtsNR
)
262 fatal_error(0,"need %d parameters in .rtp file at line:\n%s\n",
264 get_a_line(in
,line
,STRLEN
);
267 "Reading .rtp file without '[ bondedtypes ]' directive,\n"
268 "Will proceed as if the entry\n"
271 "\n; bonds angles dihedrals impropers"
274 "was present at the beginning of %s",
275 bts
[0],bts
[1],bts
[2],bts
[3],rrdb
);
279 if (nrtp
>= maxrtp
) {
283 clear_t_restp(&rrtp
[nrtp
]);
284 if (!get_header(line
,header
))
285 fatal_error(0,"in .rtp file at line:\n%s\n",line
);
286 rrtp
[nrtp
].resname
=strdup(header
);
288 get_a_line(in
,line
,STRLEN
);
291 while (!bNextResidue
) {
292 if (!get_header(line
,header
))
300 bError
=!read_bondeds(bt
,in
,line
,&rrtp
[nrtp
]);
302 if (strncasecmp("atoms",header
,5)==0)
303 bError
=!read_atoms(in
,line
,&(rrtp
[nrtp
]),tab
,atype
);
305 if (!feof(in
) && !get_header(line
,header
))
311 fatal_error(0,"in .rtp file in residue %s at line:\n%s\n",
312 rrtp
[nrtp
].resname
,line
);
314 if (rrtp
[nrtp
].natom
== 0)
315 fatal_error(0,"No atoms found in .rtp file in residue %s\n",
318 fprintf(debug
,"%3d %5s %5d",
319 nrtp
+1,rrtp
[nrtp
].resname
,rrtp
[nrtp
].natom
);
320 for(i
=0; i
<ebtsNR
; i
++)
321 fprintf(debug
," %10d",rrtp
[nrtp
].rb
[i
].nb
);
325 fprintf(stderr
,"\rResidue %d",nrtp
);
328 /* give back unused memory */
331 fprintf(stderr
,"\nSorting it all out...\n");
332 qsort(rrtp
,nrtp
,(size_t)sizeof(rrtp
[0]),comprtp
);
334 check_rtp(nrtp
,rrtp
,rrdb
);
341 void print_resall(FILE *out
, int bts
[], int nrtp
, t_restp rtp
[],
346 /* print all the ebtsNR type numbers */
347 fprintf(out
,"[ bondedtypes ]\n");
348 fprintf(out
,"; bonds angles dihedrals impropers\n");
349 fprintf(out
," %5d %6d %9d %9d\n\n",bts
[0],bts
[1],bts
[2],bts
[3]);
351 for(i
=0; i
<nrtp
; i
++) {
352 if (rtp
[i
].natom
> 0) {
353 print_resatoms(out
,atype
,&rtp
[i
]);
354 for(bt
=0; bt
<ebtsNR
; bt
++)
355 print_resbondeds(out
,bt
,&rtp
[i
]);
360 /************************************************************
364 ***********************************************************/
365 int neq_str(char *a1
,char *a2
)
369 l
=min((int)strlen(a1
),(int)strlen(a2
));
371 while ( (j
<l
) && (toupper(a1
[j
]) == toupper(a2
[j
])) )
377 t_restp
*search_rtp(char *key
,int nrtp
,t_restp rtp
[])
383 for(i
=0; (i
<nrtp
); i
++) {
384 n
=neq_str(key
,rtp
[i
].resname
);
391 fatal_error(0,"Residue '%s' not found in residue topology database\n",key
);
392 if (strlen(rtp
[besti
].resname
) != strlen(key
))
393 fprintf(stderr
,"Warning: '%s' not found in residue topology database, "
394 "trying to use '%s'\n", key
, rtp
[besti
].resname
);