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,2017,2018,2019, 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.
39 #include "qm_gamess.h"
49 #include "gromacs/fileio/confio.h"
50 #include "gromacs/gmxlib/network.h"
51 #include "gromacs/gmxlib/nrnb.h"
52 #include "gromacs/math/units.h"
53 #include "gromacs/math/vec.h"
54 #include "gromacs/mdlib/qmmm.h"
55 #include "gromacs/mdtypes/commrec.h"
56 #include "gromacs/mdtypes/forcerec.h"
57 #include "gromacs/mdtypes/md_enums.h"
58 #include "gromacs/utility/fatalerror.h"
59 #include "gromacs/utility/smalloc.h"
61 // When not built in a configuration with QMMM support, much of this
62 // code is unreachable by design. Tell clang not to warn about it.
63 #pragma GCC diagnostic push
64 #pragma GCC diagnostic ignored "-Wmissing-noreturn"
66 /* QMMM sub routines */
67 /* mopac interface routines */
70 static void F77_FUNC(inigms, IMIGMS)();
72 static void F77_FUNC(grads, GRADS)(const int* nrqmat,
82 // Stub definitions to make compilation succeed when not configured
83 // for GAMESS support. In that case, the module gives a fatal error
84 // when the initialization function is called, so there is no need to
85 // issue fatal errors here, because that introduces problems with
86 // tools suggesting and prohibiting noreturn attributes.
88 void F77_FUNC(inigms, IMIGMS)(){};
89 // NOLINTNEXTLINE(readability-named-parameter)
90 void F77_FUNC(grads, GRADS)(const int*, real*, const int*, const real*, real*, real*, real*, real*){};
93 void init_gamess(const t_commrec* cr, t_QMrec* qm, t_MMrec* mm)
95 /* it works hopelessly complicated :-)
96 * first a file is written. Then the standard gamess input/output
97 * routine is called (no system()!) to set up all fortran arrays.
98 * this routine writes a punch file, like in a normal gamess run.
99 * via this punch file the other games routines, needed for gradient
100 * and energy evaluations are called. This setup works fine for
101 * dynamics simulations. 7-6-2002 (London)
105 char periodic_system[37][3] = { "XX", "H ", "He", "Li", "Be", "B ", "C ", "N ", "O ", "F ",
106 "Ne", "Na", "Mg", "Al", "Si", "P ", "S ", "Cl", "Ar", "K ",
107 "Ca", "Sc", "Ti", "V ", "Cr", "Mn", "Fe", "Co", "Ni", "Cu",
108 "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr" };
109 if (!GMX_QMMM_GAMESS)
112 "Cannot call GAMESS unless linked against it. Use cmake "
113 "-DGMX_QMMM_PROGRAM=GAMESS, and ensure that linking will work correctly.");
121 out = fopen("FOR009", "w");
122 /* of these options I am not completely sure.... the overall
123 * preformance on more than 4 cpu's is rather poor at the moment.
125 fprintf(out, "memory 48000000\nPARALLEL IOMODE SCREENED\n");
126 fprintf(out, "ELEC %d\nMULT %d\nSUPER ON\nNOSYM\nGEOMETRY ANGSTROM\n", qm->nelectrons,
128 for (i = 0; i < qm->nrQMatoms; i++)
131 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf %2s\n", i / 2., i / 3., i / 4.,
132 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
134 fprintf(out, "%10.7f %10.7f %10.7f %5.3f %2s\n", i / 2., i / 3., i / 4.,
135 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
140 for (j = i; j < i + 2; j++)
143 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf BQ\n", j / 5., j / 6., j / 7., 1.0);
145 fprintf(out, "%10.7f %10.7f %10.7f %5.3f BQ\n", j / 5., j / 6., j / 7., 2.0);
149 fprintf(out, "END\nBASIS %s\nRUNTYPE GRADIENT\nSCFTYPE %s\n",
150 eQMbasis_names[qm->QMbasis], eQMmethod_names[qm->QMmethod]); /* see enum.h */
154 F77_FUNC(inigms, IMIGMS)();
156 else /* normal serial run */
159 out = fopen("FOR009", "w");
160 /* of these options I am not completely sure.... the overall
161 * preformance on more than 4 cpu's is rather poor at the moment.
163 fprintf(out, "ELEC %d\nMULT %d\nSUPER ON\nNOSYM\nGEOMETRY ANGSTROM\n", qm->nelectrons,
165 for (i = 0; i < qm->nrQMatoms; i++)
168 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf %2s\n", i / 2., i / 3., i / 4.,
169 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
171 fprintf(out, "%10.7f %10.7f %10.7f %5.3f %2s\n", i / 2., i / 3., i / 4.,
172 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
177 for (j = i; j < i + 2; j++)
180 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf BQ\n", j / 5., j / 6., j / 7., 1.0);
182 fprintf(out, "%10.7f %10.7f %10.7f %5.3f BQ\n", j / 5., j / 6., j / 7., 2.0);
186 fprintf(out, "END\nBASIS %s\nRUNTYPE GRADIENT\nSCFTYPE %s\n", eQMbasis_names[qm->QMbasis],
187 eQMmethod_names[qm->QMmethod]); /* see enum.h */
188 F77_FUNC(inigms, IMIGMS)();
192 real call_gamess(const t_QMrec* qm, const t_MMrec* mm, rvec f[], rvec fshift[])
194 /* do the actual QMMM calculation using GAMESS-UK. In this
195 * implementation (3-2001) a system call is made to the GAMESS-UK
196 * binary. Now we are working to get the electron integral, SCF, and
197 * gradient routines linked directly
200 real QMener = 0.0, *qmgrad, *mmgrad, *mmcrd, *qmcrd, energy = 0;
202 snew(qmcrd, 3 * (qm->nrQMatoms));
203 snew(mmcrd, 3 * (mm->nrMMatoms));
204 snew(qmgrad, 3 * (qm->nrQMatoms));
205 snew(mmgrad, 3 * (mm->nrMMatoms));
207 /* copy the data from qr into the arrays that are going to be used
208 * in the fortran routines of gamess
210 for (i = 0; i < qm->nrQMatoms; i++)
212 for (j = 0; j < DIM; j++)
214 qmcrd[DIM * i + j] = 1 / BOHR2NM * qm->xQM[i][j];
217 for (i = 0; i < mm->nrMMatoms; i++)
219 for (j = 0; j < DIM; j++)
221 mmcrd[DIM * i + j] = 1 / BOHR2NM * mm->xMM[i][j];
224 for (i = 0; i < 3 * qm->nrQMatoms; i += 3)
226 fprintf(stderr, "%8.5f, %8.5f, %8.5f\n", qmcrd[i], qmcrd[i + 1], qmcrd[i + 2]);
229 F77_FUNC(grads, GRADS)
230 (&qm->nrQMatoms, qmcrd, &mm->nrMMatoms, mm->MMcharges, mmcrd, qmgrad, mmgrad, &energy);
232 for (i = 0; i < qm->nrQMatoms; i++)
234 for (j = 0; j < DIM; j++)
236 f[i][j] = HARTREE_BOHR2MD * qmgrad[3 * i + j];
237 fshift[i][j] = HARTREE_BOHR2MD * qmgrad[3 * i + j];
240 for (i = 0; i < mm->nrMMatoms; i++)
242 for (j = 0; j < DIM; j++)
244 f[i][j] = HARTREE_BOHR2MD * mmgrad[3 * i + j];
245 fshift[i][j] = HARTREE_BOHR2MD * mmgrad[3 * i + j];
248 /* convert a.u to kJ/mol */
249 QMener = energy * HARTREE2KJ * AVOGADRO;
253 #pragma GCC diagnostic pop