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_toputil_c
= "$Id$";
32 #ident "@(#) toputil.c 1.68 9/30/97"
49 int at2type(char *str
,t_atomtype
*at
)
53 for (i
=0; (i
<at
->nr
) && strcasecmp(str
,*(at
->atomname
[i
])); i
++)
56 fatal_error(0,"Atomtype '%s' not found!",str
);
61 char *type2nm(int nt
, t_atomtype
*at
)
63 if ((nt
< 0) || (nt
>= at
->nr
))
64 fatal_error(0,"nt out of range: %d",nt
);
66 return *(at
->atomname
[nt
]);
69 void pr_alloc (int extra
, t_params
*pr
)
73 /* get new space for arrays */
75 fatal_error(0,"Trying to make array < 0 bytes\n");
78 if ((pr
->nr
== 0) && (pr
->param
!= NULL
)) {
79 fprintf(stderr
,"Warning: dangling pointer at %x\n",
80 (unsigned int)pr
->param
);
83 srenew(pr
->param
,pr
->nr
+extra
);
84 for(i
=pr
->nr
; (i
<pr
->nr
+extra
); i
++) {
85 for(j
=0; (j
<MAXATOMLIST
); j
++)
87 for(j
=0; (j
<MAXFORCEPARAM
); j
++)
89 pr
->param
[i
].s
= NULL
;
95 void init_atomtype (t_atomtype
*at
)
103 void init_plist(t_params plist
[])
107 for(i
=0; (i
<F_NRE
); i
++) {
109 plist
[i
].param
= NULL
;
113 void init_molinfo(t_molinfo
*mol
)
116 mol
->excl_set
= FALSE
;
117 mol
->bProcessed
= FALSE
;
118 init_plist(mol
->plist
);
119 init_block(&mol
->cgs
);
120 init_block(&mol
->mols
);
121 init_atom(&mol
->atoms
);
126 void done_bt (t_params
*pl
)
131 void done_mi(t_molinfo
*mi
)
135 done_atom (&(mi
->atoms
));
136 done_block(&(mi
->cgs
));
137 done_block(&(mi
->mols
));
138 for(i
=0; (i
<F_NRE
); i
++)
139 done_bt(&(mi
->plist
[i
]));
142 /* PRINTING STRUCTURES */
144 void print_at (FILE * out
, t_atomtype
*at
)
147 t_atom
*atom
= at
->atom
;
148 t_param
*nb
= at
->nb
;
150 fprintf (out
,"[ %s ]\n",dir2str(d_atomtypes
));
151 fprintf (out
,"; %6s %8s %8s %8s %12s %12s\n",
152 "type","mass","charge","particle","c6","c12");
153 for (i
=0; (i
<at
->nr
); i
++)
154 fprintf(out
,"%8s %8.3f %8.3f %8s %12e %12e\n",
155 *(at
->atomname
[i
]),atom
[i
].m
,atom
[i
].q
,"A",
161 static void print_nbt (FILE *out
,char *title
,t_atomtype
*at
,
162 int ftype
,t_params
*nbt
)
174 fprintf (out
,"; %s\n",title
);
175 fprintf (out
,"[ %s ]\n",dir2str(d_nonbond_params
));
176 fprintf (out
,"; %6s %8s","ai","aj");
177 fprintf (out
," %8s","funct");
178 for (j
=0; (j
<nrfp
); j
++)
179 fprintf (out
," %11c%1d",'c',j
);
182 /* print non-bondtypes */
183 for (i
=k
=0; (i
<at
->nr
); i
++)
184 for(j
=0; (j
<at
->nr
); j
++,k
++) {
185 fprintf (out
,"%8s %8s %8d",
186 *(at
->atomname
[i
]),*(at
->atomname
[j
]),f
);
187 for(l
=0; (l
<nrfp
); l
++)
188 fprintf (out
," %12.5e",nbt
->param
[k
].c
[l
]);
195 void print_bt(FILE *out
, directive d
, t_atomtype
*at
,
196 int ftype
,int fsubtype
,t_params plist
[],
199 /* This dihp is a DIRTY patch because the dih-types do not use
200 * all four atoms to determine the type.
202 static int dihp
[2][2] = { { 1,2 }, { 0,3 } };
205 bool bDih
=FALSE
,bSwapParity
;
254 fprintf(out
,"[ %s ]\n",dir2str(d
));
257 fprintf (out
,"%3s %4s","ai","aj");
258 for (j
=2; (j
<nral
); j
++)
259 fprintf (out
," %3c%c",'a','i'+j
);
262 for (j
=0; (j
<2); j
++)
263 fprintf (out
,"%3c%c",'a','i'+dihp
[f
][j
]);
265 fprintf (out
," funct");
266 for (j
=0; (j
<nrfp
); j
++)
267 fprintf (out
," %12c%1d",'c',j
);
270 /* print bondtypes */
271 for (i
=0; (i
<bt
->nr
); i
++) {
272 bSwapParity
= (bt
->param
[i
].C0
==NOTSET
) && (bt
->param
[i
].C1
==-1);
274 for (j
=0; (j
<nral
); j
++)
275 fprintf (out
,"%5s ",*(at
->atomname
[bt
->param
[i
].a
[j
]]));
278 fprintf (out
,"%5s ",*(at
->atomname
[bt
->param
[i
].a
[dihp
[f
][j
]]]));
279 fprintf (out
,"%5d ", bSwapParity
? -f
-1 : f
+1);
281 if (bt
->param
[i
].s
[0])
282 fprintf(out
," %s",bt
->param
[i
].s
);
284 for (j
=0; (j
<nrfp
&& (bt
->param
[i
].c
[j
] != NOTSET
)); j
++)
285 fprintf (out
,"%13.6e ",bt
->param
[i
].c
[j
]);
293 void print_block (FILE *out
, char *szName
,
294 char *szIndex
, char *szA
,
299 fprintf (out
,"; %s\n",szName
);
300 fprintf (out
,"; %4s %s\n",szIndex
,szA
);
301 for (i
=0; (i
< block
->nr
); i
++) {
302 for (i
=0; (i
< block
->nr
); i
++) {
303 fprintf (out
,"%6d",i
+1);
304 for (j
=block
->index
[i
]; (j
< ((int)block
->index
[i
+1])); j
++)
305 fprintf (out
,"%5u",block
->a
[j
]+1);
312 void print_excl(FILE *out
, t_block
*excl
)
320 for (i
=0; (i
< excl
->nr
) && !have_excl
; i
++)
321 if (excl
->index
[i
] != excl
->index
[i
+1])
325 fprintf (out
,"[ %s ]\n",dir2str(d_exclusions
));
326 fprintf (out
,"; %4s %s\n","i","excluded from i");
327 for (i
=0; (i
< excl
->nr
); i
++)
328 if (excl
->index
[i
] != excl
->index
[i
+1]) {
329 fprintf (out
,"%6d",i
+1);
330 for (j
=excl
->index
[i
]; (j
< excl
->index
[i
+1]); j
++)
331 fprintf (out
,"%5u",excl
->a
[j
]+1);
339 void print_atoms(FILE *out
,t_atomtype
*atype
,t_atoms
*at
,int *cgnr
)
347 fprintf(out
,"[ %s ]\n",as
);
348 fprintf(out
,"; %4s %6s %6s %7s%6s %6s %10s %10s %6s %10s %10s\n",
349 "nr","type","resnr","residue","atom","cgnr","charge","mass","typeB","chargeB","massB");
354 fprintf(debug
,"This molecule has %d atoms and %d residues\n",
358 /* if the information is present... */
359 for (i
=0; (i
< at
->nr
); i
++) {
360 itype
=at
->atom
[i
].type
;
361 if ((itype
< 0) || (itype
> atype
->nr
))
362 fatal_error(0,"itype = %d, i= %d in print_atoms",itype
,i
);
364 fprintf(out
,"%6d %6s %6d %6s %6s %6d %10g %10g",
365 i
+1,*(atype
->atomname
[itype
]),
367 *(at
->resname
[at
->atom
[i
].resnr
]),
368 *(at
->atomname
[i
]),cgnr
[i
],
369 at
->atom
[i
].q
,at
->atom
[i
].m
);
370 if (PERTURBED(at
->atom
[i
])) {
371 fprintf(out
," %6s %10g %10g",
372 *(atype
->atomname
[at
->atom
[i
].typeB
]),
373 at
->atom
[i
].qB
,at
->atom
[i
].mB
);
376 fprintf(out
," ; qtot %g\n",qtot
);
383 void print_bondeds(FILE *out
,int natoms
,directive d
,
384 int ftype
,int fsubtype
,t_params plist
[])
390 snew(atype
.atom
,natoms
);
391 snew(atype
.atomname
,natoms
);
393 for (i
=0; (i
< natoms
); i
++) {
395 sprintf(buf
,"%4d",(i
+1));
396 atype
.atomname
[i
]=put_symtab(&stab
,buf
);
398 print_bt(out
,d
,&atype
,ftype
,fsubtype
,plist
,TRUE
);
402 sfree(atype
.atomname
);