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 by the GROMACS development team.
7 * Copyright (c) 2019,2020, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
40 #include "qm_gamess.h"
50 #include "gromacs/fileio/confio.h"
51 #include "gromacs/gmxlib/network.h"
52 #include "gromacs/gmxlib/nrnb.h"
53 #include "gromacs/math/units.h"
54 #include "gromacs/math/vec.h"
55 #include "gromacs/mdlib/qmmm.h"
56 #include "gromacs/mdtypes/commrec.h"
57 #include "gromacs/mdtypes/forcerec.h"
58 #include "gromacs/mdtypes/md_enums.h"
59 #include "gromacs/utility/fatalerror.h"
60 #include "gromacs/utility/smalloc.h"
62 // When not built in a configuration with QMMM support, much of this
63 // code is unreachable by design. Tell clang not to warn about it.
64 #pragma GCC diagnostic push
65 #pragma GCC diagnostic ignored "-Wmissing-noreturn"
67 /* QMMM sub routines */
68 /* mopac interface routines */
71 static void F77_FUNC(inigms, IMIGMS)();
73 static void F77_FUNC(grads, GRADS)(const int* nrqmat,
83 // Stub definitions to make compilation succeed when not configured
84 // for GAMESS support. In that case, the module gives a fatal error
85 // when the initialization function is called, so there is no need to
86 // issue fatal errors here, because that introduces problems with
87 // tools suggesting and prohibiting noreturn attributes.
89 void F77_FUNC(inigms, IMIGMS)(){};
90 // NOLINTNEXTLINE(readability-named-parameter)
91 void F77_FUNC(grads, GRADS)(const int*, real*, const int*, const real*, real*, real*, real*, real*){};
94 void init_gamess(const t_commrec* cr, t_QMrec* qm, t_MMrec* mm)
96 /* it works hopelessly complicated :-)
97 * first a file is written. Then the standard gamess input/output
98 * routine is called (no system()!) to set up all fortran arrays.
99 * this routine writes a punch file, like in a normal gamess run.
100 * via this punch file the other games routines, needed for gradient
101 * and energy evaluations are called. This setup works fine for
102 * dynamics simulations. 7-6-2002 (London)
106 char periodic_system[37][3] = { "XX", "H ", "He", "Li", "Be", "B ", "C ", "N ", "O ", "F ",
107 "Ne", "Na", "Mg", "Al", "Si", "P ", "S ", "Cl", "Ar", "K ",
108 "Ca", "Sc", "Ti", "V ", "Cr", "Mn", "Fe", "Co", "Ni", "Cu",
109 "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr" };
110 if (!GMX_QMMM_GAMESS)
113 "Cannot call GAMESS unless linked against it. Use cmake "
114 "-DGMX_QMMM_PROGRAM=GAMESS, and ensure that linking will work correctly.");
122 out = fopen("FOR009", "w");
123 /* of these options I am not completely sure.... the overall
124 * preformance on more than 4 cpu's is rather poor at the moment.
126 fprintf(out, "memory 48000000\nPARALLEL IOMODE SCREENED\n");
127 fprintf(out, "ELEC %d\nMULT %d\nSUPER ON\nNOSYM\nGEOMETRY ANGSTROM\n", qm->nelectrons,
129 for (i = 0; i < qm->nrQMatoms; i++)
132 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf %2s\n", i / 2., i / 3., i / 4.,
133 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
135 fprintf(out, "%10.7f %10.7f %10.7f %5.3f %2s\n", i / 2., i / 3., i / 4.,
136 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
141 for (j = i; j < i + 2; j++)
144 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf BQ\n", j / 5., j / 6., j / 7., 1.0);
146 fprintf(out, "%10.7f %10.7f %10.7f %5.3f BQ\n", j / 5., j / 6., j / 7., 2.0);
150 fprintf(out, "END\nBASIS %s\nRUNTYPE GRADIENT\nSCFTYPE %s\n",
151 eQMbasis_names[qm->QMbasis], eQMmethod_names[qm->QMmethod]); /* see enum.h */
155 F77_FUNC(inigms, IMIGMS)();
157 else /* normal serial run */
160 out = fopen("FOR009", "w");
161 /* of these options I am not completely sure.... the overall
162 * preformance on more than 4 cpu's is rather poor at the moment.
164 fprintf(out, "ELEC %d\nMULT %d\nSUPER ON\nNOSYM\nGEOMETRY ANGSTROM\n", qm->nelectrons,
166 for (i = 0; i < qm->nrQMatoms; i++)
169 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf %2s\n", i / 2., i / 3., i / 4.,
170 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
172 fprintf(out, "%10.7f %10.7f %10.7f %5.3f %2s\n", i / 2., i / 3., i / 4.,
173 qm->atomicnumberQM[i] * 1.0, periodic_system[qm->atomicnumberQM[i]]);
178 for (j = i; j < i + 2; j++)
181 fprintf(out, "%10.7lf %10.7lf %10.7lf %5.3lf BQ\n", j / 5., j / 6., j / 7., 1.0);
183 fprintf(out, "%10.7f %10.7f %10.7f %5.3f BQ\n", j / 5., j / 6., j / 7., 2.0);
187 fprintf(out, "END\nBASIS %s\nRUNTYPE GRADIENT\nSCFTYPE %s\n", eQMbasis_names[qm->QMbasis],
188 eQMmethod_names[qm->QMmethod]); /* see enum.h */
189 F77_FUNC(inigms, IMIGMS)();
193 real call_gamess(const t_QMrec* qm, const t_MMrec* mm, rvec f[], rvec fshift[])
195 /* do the actual QMMM calculation using GAMESS-UK. In this
196 * implementation (3-2001) a system call is made to the GAMESS-UK
197 * binary. Now we are working to get the electron integral, SCF, and
198 * gradient routines linked directly
201 real QMener = 0.0, *qmgrad, *mmgrad, *mmcrd, *qmcrd, energy = 0;
203 snew(qmcrd, 3 * (qm->nrQMatoms));
204 snew(mmcrd, 3 * (mm->nrMMatoms));
205 snew(qmgrad, 3 * (qm->nrQMatoms));
206 snew(mmgrad, 3 * (mm->nrMMatoms));
208 /* copy the data from qr into the arrays that are going to be used
209 * in the fortran routines of gamess
211 for (i = 0; i < qm->nrQMatoms; i++)
213 for (j = 0; j < DIM; j++)
215 qmcrd[DIM * i + j] = 1 / BOHR2NM * qm->xQM[i][j];
218 for (i = 0; i < mm->nrMMatoms; i++)
220 for (j = 0; j < DIM; j++)
222 mmcrd[DIM * i + j] = 1 / BOHR2NM * mm->xMM[i][j];
225 for (i = 0; i < 3 * qm->nrQMatoms; i += 3)
227 fprintf(stderr, "%8.5f, %8.5f, %8.5f\n", qmcrd[i], qmcrd[i + 1], qmcrd[i + 2]);
230 F77_FUNC(grads, GRADS)
231 (&qm->nrQMatoms, qmcrd, &mm->nrMMatoms, mm->MMcharges, mmcrd, qmgrad, mmgrad, &energy);
233 for (i = 0; i < qm->nrQMatoms; i++)
235 for (j = 0; j < DIM; j++)
237 f[i][j] = HARTREE_BOHR2MD * qmgrad[3 * i + j];
238 fshift[i][j] = HARTREE_BOHR2MD * qmgrad[3 * i + j];
241 for (i = 0; i < mm->nrMMatoms; i++)
243 for (j = 0; j < DIM; j++)
245 f[i][j] = HARTREE_BOHR2MD * mmgrad[3 * i + j];
246 fshift[i][j] = HARTREE_BOHR2MD * mmgrad[3 * i + j];
249 /* convert a.u to kJ/mol */
250 QMener = energy * HARTREE2KJ * AVOGADRO;
254 #pragma GCC diagnostic pop