2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
43 #include "gromacs/topology/ifunc.h"
44 #include "gromacs/utility/fatalerror.h"
45 #include "gromacs/utility/smalloc.h"
46 #include "gromacs/utility/txtdump.h"
48 static void pr_harm(FILE *fp
, const t_iparams
*iparams
, const char *r
, const char *kr
)
50 fprintf(fp
, "%sA=%12.5e, %sA=%12.5e, %sB=%12.5e, %sB=%12.5e\n",
51 r
, iparams
->harmonic
.rA
, kr
, iparams
->harmonic
.krA
,
52 r
, iparams
->harmonic
.rB
, kr
, iparams
->harmonic
.krB
);
55 void pr_iparams(FILE *fp
, t_functype ftype
, const t_iparams
*iparams
)
61 pr_harm(fp
, iparams
, "th", "ct");
63 case F_CROSS_BOND_BONDS
:
64 fprintf(fp
, "r1e=%15.8e, r2e=%15.8e, krr=%15.8e\n",
65 iparams
->cross_bb
.r1e
, iparams
->cross_bb
.r2e
,
66 iparams
->cross_bb
.krr
);
68 case F_CROSS_BOND_ANGLES
:
69 fprintf(fp
, "r1e=%15.8e, r1e=%15.8e, r3e=%15.8e, krt=%15.8e\n",
70 iparams
->cross_ba
.r1e
, iparams
->cross_ba
.r2e
,
71 iparams
->cross_ba
.r3e
, iparams
->cross_ba
.krt
);
74 fprintf(fp
, "klinA=%15.8e, aA=%15.8e, klinB=%15.8e, aB=%15.8e\n",
75 iparams
->linangle
.klinA
, iparams
->linangle
.aA
,
76 iparams
->linangle
.klinB
, iparams
->linangle
.aB
);
79 fprintf(fp
, "thetaA=%15.8e, kthetaA=%15.8e, r13A=%15.8e, kUBA=%15.8e, thetaB=%15.8e, kthetaB=%15.8e, r13B=%15.8e, kUBB=%15.8e\n", iparams
->u_b
.thetaA
, iparams
->u_b
.kthetaA
, iparams
->u_b
.r13A
, iparams
->u_b
.kUBA
, iparams
->u_b
.thetaB
, iparams
->u_b
.kthetaB
, iparams
->u_b
.r13B
, iparams
->u_b
.kUBB
);
81 case F_QUARTIC_ANGLES
:
82 fprintf(fp
, "theta=%15.8e", iparams
->qangle
.theta
);
83 for (int i
= 0; i
< 5; i
++)
85 fprintf(fp
, ", c%c=%15.8e", '0'+i
, iparams
->qangle
.c
[i
]);
90 fprintf(fp
, "a=%15.8e, b=%15.8e, c=%15.8e\n",
91 iparams
->bham
.a
, iparams
->bham
.b
, iparams
->bham
.c
);
96 pr_harm(fp
, iparams
, "b0", "cb");
99 pr_harm(fp
, iparams
, "xi", "cx");
102 fprintf(fp
, "b0A=%15.8e, cbA=%15.8e, betaA=%15.8e, b0B=%15.8e, cbB=%15.8e, betaB=%15.8e\n",
103 iparams
->morse
.b0A
, iparams
->morse
.cbA
, iparams
->morse
.betaA
,
104 iparams
->morse
.b0B
, iparams
->morse
.cbB
, iparams
->morse
.betaB
);
107 fprintf(fp
, "b0=%15.8e, kb=%15.8e, kcub=%15.8e\n",
108 iparams
->cubic
.b0
, iparams
->cubic
.kb
, iparams
->cubic
.kcub
);
114 fprintf(fp
, "bm=%15.8e, kb=%15.8e\n", iparams
->fene
.bm
, iparams
->fene
.kb
);
117 fprintf(fp
, "lowA=%15.8e, up1A=%15.8e, up2A=%15.8e, kA=%15.8e, lowB=%15.8e, up1B=%15.8e, up2B=%15.8e, kB=%15.8e,\n",
118 iparams
->restraint
.lowA
, iparams
->restraint
.up1A
,
119 iparams
->restraint
.up2A
, iparams
->restraint
.kA
,
120 iparams
->restraint
.lowB
, iparams
->restraint
.up1B
,
121 iparams
->restraint
.up2B
, iparams
->restraint
.kB
);
127 fprintf(fp
, "tab=%d, kA=%15.8e, kB=%15.8e\n",
128 iparams
->tab
.table
, iparams
->tab
.kA
, iparams
->tab
.kB
);
131 fprintf(fp
, "alpha=%15.8e\n", iparams
->polarize
.alpha
);
134 fprintf(fp
, "alpha=%15.8e drcut=%15.8e khyp=%15.8e\n",
135 iparams
->anharm_polarize
.alpha
,
136 iparams
->anharm_polarize
.drcut
,
137 iparams
->anharm_polarize
.khyp
);
140 fprintf(fp
, "a=%15.8e, alpha1=%15.8e, alpha2=%15.8e, rfac=%15.8e\n",
141 iparams
->thole
.a
, iparams
->thole
.alpha1
, iparams
->thole
.alpha2
,
142 iparams
->thole
.rfac
);
145 fprintf(fp
, "al_x=%15.8e, al_y=%15.8e, al_z=%15.8e, rOH=%9.6f, rHH=%9.6f, rOD=%9.6f\n",
146 iparams
->wpol
.al_x
, iparams
->wpol
.al_y
, iparams
->wpol
.al_z
,
147 iparams
->wpol
.rOH
, iparams
->wpol
.rHH
, iparams
->wpol
.rOD
);
150 fprintf(fp
, "c6=%15.8e, c12=%15.8e\n", iparams
->lj
.c6
, iparams
->lj
.c12
);
153 fprintf(fp
, "c6A=%15.8e, c12A=%15.8e, c6B=%15.8e, c12B=%15.8e\n",
154 iparams
->lj14
.c6A
, iparams
->lj14
.c12A
,
155 iparams
->lj14
.c6B
, iparams
->lj14
.c12B
);
158 fprintf(fp
, "fqq=%15.8e, qi=%15.8e, qj=%15.8e, c6=%15.8e, c12=%15.8e\n",
160 iparams
->ljc14
.qi
, iparams
->ljc14
.qj
,
161 iparams
->ljc14
.c6
, iparams
->ljc14
.c12
);
164 fprintf(fp
, "qi=%15.8e, qj=%15.8e, c6=%15.8e, c12=%15.8e\n",
165 iparams
->ljcnb
.qi
, iparams
->ljcnb
.qj
,
166 iparams
->ljcnb
.c6
, iparams
->ljcnb
.c12
);
172 fprintf(fp
, "phiA=%15.8e, cpA=%15.8e, phiB=%15.8e, cpB=%15.8e, mult=%d\n",
173 iparams
->pdihs
.phiA
, iparams
->pdihs
.cpA
,
174 iparams
->pdihs
.phiB
, iparams
->pdihs
.cpB
,
175 iparams
->pdihs
.mult
);
178 fprintf(fp
, "label=%4d, type=%1d, low=%15.8e, up1=%15.8e, up2=%15.8e, fac=%15.8e)\n",
179 iparams
->disres
.label
, iparams
->disres
.type
,
180 iparams
->disres
.low
, iparams
->disres
.up1
,
181 iparams
->disres
.up2
, iparams
->disres
.kfac
);
184 fprintf(fp
, "ex=%4d, label=%d, power=%4d, c=%15.8e, obs=%15.8e, kfac=%15.8e)\n",
185 iparams
->orires
.ex
, iparams
->orires
.label
, iparams
->orires
.power
,
186 iparams
->orires
.c
, iparams
->orires
.obs
, iparams
->orires
.kfac
);
189 fprintf(fp
, "phiA=%15.8e, dphiA=%15.8e, kfacA=%15.8e, phiB=%15.8e, dphiB=%15.8e, kfacB=%15.8e\n",
190 iparams
->dihres
.phiA
, iparams
->dihres
.dphiA
, iparams
->dihres
.kfacA
,
191 iparams
->dihres
.phiB
, iparams
->dihres
.dphiB
, iparams
->dihres
.kfacB
);
194 fprintf(fp
, "pos0A=(%15.8e,%15.8e,%15.8e), fcA=(%15.8e,%15.8e,%15.8e), pos0B=(%15.8e,%15.8e,%15.8e), fcB=(%15.8e,%15.8e,%15.8e)\n",
195 iparams
->posres
.pos0A
[XX
], iparams
->posres
.pos0A
[YY
],
196 iparams
->posres
.pos0A
[ZZ
], iparams
->posres
.fcA
[XX
],
197 iparams
->posres
.fcA
[YY
], iparams
->posres
.fcA
[ZZ
],
198 iparams
->posres
.pos0B
[XX
], iparams
->posres
.pos0B
[YY
],
199 iparams
->posres
.pos0B
[ZZ
], iparams
->posres
.fcB
[XX
],
200 iparams
->posres
.fcB
[YY
], iparams
->posres
.fcB
[ZZ
]);
203 fprintf(fp
, "pos0=(%15.8e,%15.8e,%15.8e), geometry=%d, r=%15.8e, k=%15.8e\n",
204 iparams
->fbposres
.pos0
[XX
], iparams
->fbposres
.pos0
[YY
],
205 iparams
->fbposres
.pos0
[ZZ
], iparams
->fbposres
.geom
,
206 iparams
->fbposres
.r
, iparams
->fbposres
.k
);
209 for (int i
= 0; i
< NR_RBDIHS
; i
++)
211 fprintf(fp
, "%srbcA[%d]=%15.8e", i
== 0 ? "" : ", ", i
, iparams
->rbdihs
.rbcA
[i
]);
214 for (int i
= 0; i
< NR_RBDIHS
; i
++)
216 fprintf(fp
, "%srbcB[%d]=%15.8e", i
== 0 ? "" : ", ", i
, iparams
->rbdihs
.rbcB
[i
]);
222 /* Use the OPLS -> Ryckaert-Bellemans formula backwards to get
223 * the OPLS potential constants back.
225 const real
*rbcA
= iparams
->rbdihs
.rbcA
;
226 const real
*rbcB
= iparams
->rbdihs
.rbcB
;
229 VA
[3] = -0.25*rbcA
[4];
230 VA
[2] = -0.5*rbcA
[3];
231 VA
[1] = 4.0*VA
[3]-rbcA
[2];
232 VA
[0] = 3.0*VA
[2]-2.0*rbcA
[1];
234 VB
[3] = -0.25*rbcB
[4];
235 VB
[2] = -0.5*rbcB
[3];
236 VB
[1] = 4.0*VB
[3]-rbcB
[2];
237 VB
[0] = 3.0*VB
[2]-2.0*rbcB
[1];
239 for (int i
= 0; i
< NR_FOURDIHS
; i
++)
241 fprintf(fp
, "%sFourA[%d]=%15.8e", i
== 0 ? "" : ", ", i
, VA
[i
]);
244 for (int i
= 0; i
< NR_FOURDIHS
; i
++)
246 fprintf(fp
, "%sFourB[%d]=%15.8e", i
== 0 ? "" : ", ", i
, VB
[i
]);
254 fprintf(fp
, "dA=%15.8e, dB=%15.8e\n", iparams
->constr
.dA
, iparams
->constr
.dB
);
257 fprintf(fp
, "doh=%15.8e, dhh=%15.8e\n", iparams
->settle
.doh
,
258 iparams
->settle
.dhh
);
261 fprintf(fp
, "a=%15.8e\n", iparams
->vsite
.a
);
266 fprintf(fp
, "a=%15.8e, b=%15.8e\n", iparams
->vsite
.a
, iparams
->vsite
.b
);
271 fprintf(fp
, "a=%15.8e, b=%15.8e, c=%15.8e\n",
272 iparams
->vsite
.a
, iparams
->vsite
.b
, iparams
->vsite
.c
);
275 fprintf(fp
, "n=%2d, a=%15.8e\n", iparams
->vsiten
.n
, iparams
->vsiten
.a
);
277 case F_GB12_NOLONGERUSED
:
278 case F_GB13_NOLONGERUSED
:
279 case F_GB14_NOLONGERUSED
:
280 // These could only be generated by grompp, not written in
281 // a .top file. Now that implicit solvent is not
282 // supported, they can't be generated, and the values are
283 // ignored if read from an old .tpr file. So there is
287 fprintf(fp
, "cmapA=%1d, cmapB=%1d\n", iparams
->cmap
.cmapA
, iparams
->cmap
.cmapB
);
290 pr_harm(fp
, iparams
, "ktheta", "costheta0");
293 fprintf(fp
, "phiA=%15.8e, cpA=%15.8e",
294 iparams
->pdihs
.phiA
, iparams
->pdihs
.cpA
);
297 fprintf(fp
, "kphi=%15.8e", iparams
->cbtdihs
.cbtcA
[0]);
298 for (int i
= 1; i
< NR_CBTDIHS
; i
++)
300 fprintf(fp
, ", cbtcA[%d]=%15.8e", i
-1, iparams
->cbtdihs
.cbtcA
[i
]);
305 gmx_fatal(FARGS
, "unknown function type %d (%s) in %s line %d",
306 ftype
, interaction_function
[ftype
].name
, __FILE__
, __LINE__
);
310 template <typename T
>
312 printIlist(FILE *fp
, int indent
, const char *title
,
313 const t_functype
*functype
, const T
&ilist
,
314 gmx_bool bShowNumbers
,
315 gmx_bool bShowParameters
, const t_iparams
*iparams
)
317 int i
, j
, k
, type
, ftype
;
319 indent
= pr_title(fp
, indent
, title
);
320 pr_indent(fp
, indent
);
321 fprintf(fp
, "nr: %d\n", ilist
.size());
322 if (ilist
.size() > 0)
324 pr_indent(fp
, indent
);
325 fprintf(fp
, "iatoms:\n");
326 for (i
= j
= 0; i
< ilist
.size(); )
328 pr_indent(fp
, indent
+INDENT
);
329 type
= ilist
.iatoms
[i
];
330 ftype
= functype
[type
];
333 fprintf(fp
, "%d type=%d ", j
, type
);
336 printf("(%s)", interaction_function
[ftype
].name
);
337 for (k
= 0; k
< interaction_function
[ftype
].nratoms
; k
++)
339 fprintf(fp
, " %3d", ilist
.iatoms
[i
+ 1 + k
]);
344 pr_iparams(fp
, ftype
, &iparams
[type
]);
347 i
+= 1+interaction_function
[ftype
].nratoms
;
352 void pr_ilist(FILE *fp
, int indent
, const char *title
,
353 const t_functype
*functype
, const InteractionList
&ilist
,
354 gmx_bool bShowNumbers
,
355 gmx_bool bShowParameters
, const t_iparams
*iparams
)
357 printIlist(fp
, indent
, title
, functype
, ilist
,
358 bShowNumbers
, bShowParameters
, iparams
);
361 void pr_idef(FILE *fp
, int indent
, const char *title
, const t_idef
*idef
,
362 gmx_bool bShowNumbers
, gmx_bool bShowParameters
)
366 if (available(fp
, idef
, indent
, title
))
368 indent
= pr_title(fp
, indent
, title
);
369 pr_indent(fp
, indent
);
370 fprintf(fp
, "atnr=%d\n", idef
->atnr
);
371 pr_indent(fp
, indent
);
372 fprintf(fp
, "ntypes=%d\n", idef
->ntypes
);
373 for (i
= 0; i
< idef
->ntypes
; i
++)
375 pr_indent(fp
, indent
+INDENT
);
376 fprintf(fp
, "functype[%d]=%s, ",
377 bShowNumbers
? i
: -1,
378 interaction_function
[idef
->functype
[i
]].name
);
379 pr_iparams(fp
, idef
->functype
[i
], &idef
->iparams
[i
]);
381 pr_real(fp
, indent
, "fudgeQQ", idef
->fudgeQQ
);
383 for (j
= 0; (j
< F_NRE
); j
++)
385 printIlist(fp
, indent
, interaction_function
[j
].longname
,
386 idef
->functype
, idef
->il
[j
], bShowNumbers
,
387 bShowParameters
, idef
->iparams
);
392 void init_idef(t_idef
*idef
)
396 idef
->functype
= nullptr;
397 idef
->iparams
= nullptr;
399 idef
->iparams_posres
= nullptr;
400 idef
->iparams_fbposres
= nullptr;
401 for (int f
= 0; f
< F_NRE
; ++f
)
403 idef
->il
[f
].iatoms
= nullptr;
404 idef
->il
[f
].nalloc
= 0;
406 idef
->il
[f
].nr_nonperturbed
= 0;
408 idef
->cmap_grid
= nullptr;
409 idef
->iparams_posres_nalloc
= 0;
410 idef
->iparams_fbposres_nalloc
= 0;
414 void done_idef(t_idef
*idef
)
416 sfree(idef
->functype
);
417 sfree(idef
->iparams
);
418 sfree(idef
->iparams_posres
);
419 sfree(idef
->iparams_fbposres
);
420 for (int f
= 0; f
< F_NRE
; ++f
)
422 sfree(idef
->il
[f
].iatoms
);
425 delete idef
->cmap_grid
;
429 void copy_ilist(const t_ilist
*src
, t_ilist
*dst
)
432 dst
->nr_nonperturbed
= src
->nr_nonperturbed
;
433 dst
->nalloc
= src
->nalloc
;
435 snew(dst
->iatoms
, dst
->nr
);
436 for (int i
= 0; i
< dst
->nr
; ++i
)
438 dst
->iatoms
[i
] = src
->iatoms
[i
];