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,2017,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.
39 #include "qm_gaussian.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/force.h"
55 #include "gromacs/mdlib/forcerec.h"
56 #include "gromacs/mdlib/ns.h"
57 #include "gromacs/mdlib/qmmm.h"
58 #include "gromacs/mdtypes/md_enums.h"
59 #include "gromacs/utility/cstringutil.h"
60 #include "gromacs/utility/fatalerror.h"
61 #include "gromacs/utility/smalloc.h"
63 // When not built in a configuration with QMMM support, much of this
64 // code is unreachable by design. Tell clang not to warn about it.
65 #pragma GCC diagnostic push
66 #pragma GCC diagnostic ignored "-Wmissing-noreturn"
68 /* TODO: this should be made thread-safe */
70 /* Gaussian interface routines */
72 void init_gaussian(t_QMrec *qm)
75 basissets[eQMbasisNR] = {{0, 3, 0},
76 {0, 3, 0}, /*added for double sto-3g entry in names.c*/
90 if (!GMX_QMMM_GAUSSIAN)
92 gmx_fatal(FARGS, "Cannot call GAUSSIAN unless linked against it. Use cmake -DGMX_QMMM_PROGRAM=GAUSSIAN, and ensure that linking will work correctly.");
95 /* using the ivec above to convert the basis read form the mdp file
96 * in a human readable format into some numbers for the gaussian
97 * route. This is necessary as we are using non standard routes to
101 /* per layer we make a new subdir for integral file, checkpoint
102 * files and such. These dirs are stored in the QMrec for
107 if (!qm->nQMcpus) /* this we do only once per layer
108 * as we call g01 externally
112 for (i = 0; i < DIM; i++)
114 qm->SHbasis[i] = basissets[qm->QMbasis][i];
117 /* init gradually switching on of the SA */
119 /* we read the number of cpus and environment from the environment
122 buf = getenv("GMX_QM_GAUSSIAN_NCPUS");
125 sscanf(buf, "%d", &qm->nQMcpus);
131 fprintf(stderr, "number of CPUs for gaussian = %d\n", qm->nQMcpus);
132 buf = getenv("GMX_QM_GAUSSIAN_MEMORY");
135 sscanf(buf, "%d", &qm->QMmem);
139 qm->QMmem = 50000000;
141 fprintf(stderr, "memory for gaussian = %d\n", qm->QMmem);
142 buf = getenv("GMX_QM_ACCURACY");
145 sscanf(buf, "%d", &qm->accuracy);
151 fprintf(stderr, "accuracy in l510 = %d\n", qm->accuracy);
153 buf = getenv("GMX_QM_CPMCSCF");
156 sscanf(buf, "%d", &i);
157 qm->cpmcscf = (i != 0);
165 fprintf(stderr, "using cp-mcscf in l1003\n");
169 fprintf(stderr, "NOT using cp-mcscf in l1003\n");
171 buf = getenv("GMX_QM_SA_STEP");
174 sscanf(buf, "%d", &qm->SAstep);
178 /* init gradually switching on of the SA */
181 /* we read the number of cpus and environment from the environment
184 fprintf(stderr, "Level of SA at start = %d\n", qm->SAstep);
185 /* gaussian settings on the system */
186 buf = getenv("GMX_QM_GAUSS_DIR");
190 qm->gauss_dir = gmx_strdup(buf);
194 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_DIR, check gaussian manual\n");
197 buf = getenv("GMX_QM_GAUSS_EXE");
200 qm->gauss_exe = gmx_strdup(buf);
204 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_EXE set, check gaussian manual\n");
206 buf = getenv("GMX_QM_MODIFIED_LINKS_DIR");
209 qm->devel_dir = gmx_strdup (buf);
213 gmx_fatal(FARGS, "no $GMX_QM_MODIFIED_LINKS_DIR, this is were the modified links reside.\n");
217 /* reactionfield, file is needed using gaussian */
218 /* rffile=fopen("rf.dat","w");*/
219 /* fprintf(rffile,"%f %f\n",fr->epsilon_r,fr->rcoulomb/BOHR2NM);*/
223 fprintf(stderr, "gaussian initialised...\n");
227 static void write_gaussian_SH_input(int step, gmx_bool swap,
228 const t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
239 bSA = (qm->SAstep > 0);
241 out = fopen("input.com", "w");
242 /* write the route */
243 fprintf(out, "%s", "%scr=input\n");
244 fprintf(out, "%s", "%rwf=input\n");
245 fprintf(out, "%s", "%int=input\n");
246 fprintf(out, "%s", "%d2e=input\n");
248 * fprintf(out,"%s","%nosave\n");
250 fprintf(out, "%s", "%chk=input\n");
251 fprintf(out, "%s%d\n", "%mem=", qm->QMmem);
252 fprintf(out, "%s%3d\n", "%nprocshare=", qm->nQMcpus);
254 /* use the versions of
255 * l301 that computes the interaction between MM and QM atoms.
256 * l510 that can punch the CI coefficients
257 * l701 that can do gradients on MM atoms
261 fprintf(out, "%s%s%s",
265 fprintf(out, "%s%s%s",
269 fprintf(out, "%s%s%s",
274 fprintf(out, "%s%s%s",
278 fprintf(out, "%s%s%s",
282 /* print the nonstandard route
285 "#P nonstd\n 1/18=10,20=1,38=1/1;\n");
287 " 2/9=110,15=1,17=6,18=5,40=1/2;\n");
291 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=1,94=-2/1,2,3;\n",
294 qm->SHbasis[2]); /*basisset stuff */
299 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=0,94=-2/1,2,3;\n",
302 qm->SHbasis[2]); /*basisset stuff */
305 if (step+1) /* fetch initial guess from check point file */
306 { /* hack, to alyays read from chk file!!!!! */
307 fprintf(out, "%s%d,%s%d%s", " 4/5=1,7=6,17=",
309 "18=", qm->CASorbitals, "/1,5;\n");
311 else /* generate the first checkpoint file */
313 fprintf(out, "%s%d,%s%d%s", " 4/5=0,7=6,17=",
315 "18=", qm->CASorbitals, "/1,5;\n");
317 /* the rest of the input depends on where the system is on the PES
319 if (swap && bSA) /* make a slide to the other surface */
321 if (qm->CASorbitals > 6) /* use direct and no full diag */
323 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6,97=100/10;\n");
329 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6,97=100/10;\n",
331 if (mm->nrMMatoms > 0)
333 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
335 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
336 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1,97=100/3;\n");
337 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
341 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6,97=100/10;\n",
343 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
347 else if (bSA) /* do a "state-averaged" CAS calculation */
349 if (qm->CASorbitals > 6) /* no full diag */
351 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6/10;\n");
357 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6/10;\n",
359 if (mm->nrMMatoms > 0)
361 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
363 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
364 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1/3;\n");
365 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
369 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6/10;\n",
371 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
375 else if (swap) /* do a "swapped" CAS calculation */
377 if (qm->CASorbitals > 6)
379 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6,97=100/10;\n");
383 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6,97=100/10;\n",
386 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
388 else /* do a "normal" CAS calculation */
390 if (qm->CASorbitals > 6)
392 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6/10;\n");
396 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6/10;\n",
399 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
401 fprintf(out, "\ninput-file generated by gromacs\n\n");
402 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
403 for (i = 0; i < qm->nrQMatoms; i++)
405 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
406 qm->atomicnumberQM[i],
407 qm->xQM[i][XX]/BOHR2NM,
408 qm->xQM[i][YY]/BOHR2NM,
409 qm->xQM[i][ZZ]/BOHR2NM);
411 /* MM point charge data */
412 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
415 for (i = 0; i < mm->nrMMatoms; i++)
417 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
418 mm->xMM[i][XX]/BOHR2NM,
419 mm->xMM[i][YY]/BOHR2NM,
420 mm->xMM[i][ZZ]/BOHR2NM,
424 if (bSA) /* put the SA coefficients at the end of the file */
426 fprintf(out, "\n%10.8f %10.8f\n",
427 qm->SAstep*0.5/qm->SAsteps,
428 1-qm->SAstep*0.5/qm->SAsteps);
429 fprintf(stderr, "State Averaging level = %d/%d\n", qm->SAstep, qm->SAsteps);
433 } /* write_gaussian_SH_input */
435 static void write_gaussian_input(int step, const t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
445 out = fopen("input.com", "w");
446 /* write the route */
448 if (qm->QMmethod >= eQMmethodRHF)
460 fprintf(out, "%s%3d\n",
461 "%nprocshare=", qm->nQMcpus);
463 fprintf(out, "%s%d\n",
465 fprintf(out, "%s%s%s",
466 "%subst l701 ", qm->devel_dir, "/l701\n");
467 fprintf(out, "%s%s%s",
468 "%subst l301 ", qm->devel_dir, "/l301\n");
469 fprintf(out, "%s%s%s",
470 "%subst l9999 ", qm->devel_dir, "/l9999\n");
481 if (qm->QMmethod == eQMmethodB3LYPLAN)
484 "B3LYP/GEN Pseudo=Read");
489 eQMmethod_names[qm->QMmethod]);
491 if (qm->QMmethod >= eQMmethodRHF)
493 if (qm->QMmethod == eQMmethodCASSCF)
495 /* in case of cas, how many electrons and orbitals do we need?
497 fprintf(out, "(%d,%d)",
498 qm->CASelectrons, qm->CASorbitals);
501 eQMbasis_names[qm->QMbasis]);
504 if (QMMMrec->QMMMscheme == eQMMMschemenormal && mm->nrMMatoms)
509 if (step || qm->QMmethod == eQMmethodCASSCF)
511 /* fetch guess from checkpoint file, always for CASSCF */
512 fprintf(out, "%s", " guess=read");
514 fprintf(out, "\nNosymm units=bohr\n");
516 fprintf(out, "FORCE Punch=(Derivatives) ");
517 fprintf(out, "iop(3/33=1)\n\n");
518 fprintf(out, "input-file generated by gromacs\n\n");
519 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
520 for (i = 0; i < qm->nrQMatoms; i++)
522 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
523 qm->atomicnumberQM[i],
524 qm->xQM[i][XX]/BOHR2NM,
525 qm->xQM[i][YY]/BOHR2NM,
526 qm->xQM[i][ZZ]/BOHR2NM);
529 /* Pseudo Potential and ECP are included here if selected (MEthod suffix LAN) */
530 if (qm->QMmethod == eQMmethodB3LYPLAN)
533 for (i = 0; i < qm->nrQMatoms; i++)
535 if (qm->atomicnumberQM[i] < 21)
537 fprintf(out, "%d ", i+1);
540 fprintf(out, "\n%s\n****\n", eQMbasis_names[qm->QMbasis]);
542 for (i = 0; i < qm->nrQMatoms; i++)
544 if (qm->atomicnumberQM[i] > 21)
546 fprintf(out, "%d ", i+1);
549 fprintf(out, "\n%s\n****\n\n", "lanl2dz");
551 for (i = 0; i < qm->nrQMatoms; i++)
553 if (qm->atomicnumberQM[i] > 21)
555 fprintf(out, "%d ", i+1);
558 fprintf(out, "\n%s\n", "lanl2dz");
563 /* MM point charge data */
564 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
566 fprintf(stderr, "nr mm atoms in gaussian.c = %d\n", mm->nrMMatoms);
568 for (i = 0; i < mm->nrMMatoms; i++)
570 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
571 mm->xMM[i][XX]/BOHR2NM,
572 mm->xMM[i][YY]/BOHR2NM,
573 mm->xMM[i][ZZ]/BOHR2NM,
582 } /* write_gaussian_input */
584 static real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], t_QMrec *qm, t_MMrec *mm)
595 in = fopen("fort.7", "r");
597 /* (There was additional content in the file in case
598 * of QM optimizations / transition state search,
601 /* the next line is the energy and in the case of CAS, the energy
602 * difference between the two states.
604 if (nullptr == fgets(buf, 300, in))
606 gmx_fatal(FARGS, "Error reading Gaussian output");
610 sscanf(buf, "%lf\n", &QMener);
612 sscanf(buf, "%f\n", &QMener);
614 /* next lines contain the gradients of the QM atoms */
615 for (i = 0; i < qm->nrQMatoms; i++)
617 if (nullptr == fgets(buf, 300, in))
619 gmx_fatal(FARGS, "Error reading Gaussian output");
622 sscanf(buf, "%lf %lf %lf\n",
627 sscanf(buf, "%f %f %f\n",
633 /* the next lines are the gradients of the MM atoms */
634 if (qm->QMmethod >= eQMmethodRHF)
636 for (i = 0; i < mm->nrMMatoms; i++)
638 if (nullptr == fgets(buf, 300, in))
640 gmx_fatal(FARGS, "Error reading Gaussian output");
643 sscanf(buf, "%lf %lf %lf\n",
648 sscanf(buf, "%f %f %f\n",
659 static real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step, t_QMrec *qm, t_MMrec *mm)
670 in = fopen("fort.7", "r");
671 /* first line is the energy and in the case of CAS, the energy
672 * difference between the two states.
674 if (nullptr == fgets(buf, 300, in))
676 gmx_fatal(FARGS, "Error reading Gaussian output");
680 sscanf(buf, "%lf %lf\n", &QMener, &DeltaE);
682 sscanf(buf, "%f %f\n", &QMener, &DeltaE);
685 /* switch on/off the State Averaging */
687 if (DeltaE > qm->SAoff)
694 else if (DeltaE < qm->SAon || (qm->SAstep > 0))
696 if (qm->SAstep < qm->SAsteps)
703 fprintf(stderr, "Gap = %5f,SA = %3d\n", DeltaE, static_cast<int>(qm->SAstep > 0));
704 /* next lines contain the gradients of the QM atoms */
705 for (i = 0; i < qm->nrQMatoms; i++)
707 if (nullptr == fgets(buf, 300, in))
709 gmx_fatal(FARGS, "Error reading Gaussian output");
713 sscanf(buf, "%lf %lf %lf\n",
718 sscanf(buf, "%f %f %f\n",
724 /* the next lines, are the gradients of the MM atoms */
726 for (i = 0; i < mm->nrMMatoms; i++)
728 if (nullptr == fgets(buf, 300, in))
730 gmx_fatal(FARGS, "Error reading Gaussian output");
733 sscanf(buf, "%lf %lf %lf\n",
738 sscanf(buf, "%f %f %f\n",
745 /* the next line contains the two CI eigenvector elements */
746 if (nullptr == fgets(buf, 300, in))
748 gmx_fatal(FARGS, "Error reading Gaussian output");
752 sscanf(buf, "%d", &qm->CIdim);
753 snew(qm->CIvec1, qm->CIdim);
754 snew(qm->CIvec1old, qm->CIdim);
755 snew(qm->CIvec2, qm->CIdim);
756 snew(qm->CIvec2old, qm->CIdim);
760 /* before reading in the new current CI vectors, copy the current
761 * CI vector into the old one.
763 for (i = 0; i < qm->CIdim; i++)
765 qm->CIvec1old[i] = qm->CIvec1[i];
766 qm->CIvec2old[i] = qm->CIvec2[i];
770 for (i = 0; i < qm->CIdim; i++)
772 if (nullptr == fgets(buf, 300, in))
774 gmx_fatal(FARGS, "Error reading Gaussian output");
777 sscanf(buf, "%lf\n", &qm->CIvec1[i]);
779 sscanf(buf, "%f\n", &qm->CIvec1[i]);
783 for (i = 0; i < qm->CIdim; i++)
785 if (nullptr == fgets(buf, 300, in))
787 gmx_fatal(FARGS, "Error reading Gaussian output");
790 sscanf(buf, "%lf\n", &qm->CIvec2[i]);
792 sscanf(buf, "%f\n", &qm->CIvec2[i]);
799 static real inproduct(const real *a, const real *b, int n)
806 /* computes the inner product between two vectors (a.b), both of
807 * which have length n.
809 for (i = 0; i < n; i++)
816 static int hop(int step, t_QMrec *qm)
821 d11 = 0.0, d12 = 0.0, d21 = 0.0, d22 = 0.0;
823 /* calculates the inproduct between the current Ci vector and the
824 * previous CI vector. A diabatic hop will be made if d12 and d21
825 * are much bigger than d11 and d22. In that case hop returns true,
826 * otherwise it returns false.
828 if (step) /* only go on if more than one step has been done */
830 d11 = inproduct(qm->CIvec1, qm->CIvec1old, qm->CIdim);
831 d12 = inproduct(qm->CIvec1, qm->CIvec2old, qm->CIdim);
832 d21 = inproduct(qm->CIvec2, qm->CIvec1old, qm->CIdim);
833 d22 = inproduct(qm->CIvec2, qm->CIvec2old, qm->CIdim);
835 fprintf(stderr, "-------------------\n");
836 fprintf(stderr, "d11 = %13.8f\n", d11);
837 fprintf(stderr, "d12 = %13.8f\n", d12);
838 fprintf(stderr, "d21 = %13.8f\n", d21);
839 fprintf(stderr, "d22 = %13.8f\n", d22);
840 fprintf(stderr, "-------------------\n");
842 if ((fabs(d12) > 0.5) && (fabs(d21) > 0.5))
850 static void do_gaussian(int step, char *exe)
855 /* make the call to the gaussian binary through system()
856 * The location of the binary will be picked up from the
857 * environment using getenv().
859 if (step) /* hack to prevent long inputfiles */
861 sprintf(buf, "%s < %s > %s",
868 sprintf(buf, "%s < %s > %s",
873 fprintf(stderr, "Calling '%s'\n", buf);
874 if (system(buf) != 0)
876 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
880 real call_gaussian(const t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
882 /* normal gaussian jobs */
895 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
896 snew(QMgrad, qm->nrQMatoms);
897 snew(MMgrad, mm->nrMMatoms);
899 write_gaussian_input(step, fr, qm, mm);
900 do_gaussian(step, exe);
901 QMener = read_gaussian_output(QMgrad, MMgrad, qm, mm);
902 /* put the QMMM forces in the force array and to the fshift
904 for (i = 0; i < qm->nrQMatoms; i++)
906 for (j = 0; j < DIM; j++)
908 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
909 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
912 for (i = 0; i < mm->nrMMatoms; i++)
914 for (j = 0; j < DIM; j++)
916 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
917 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
920 QMener = QMener*HARTREE2KJ*AVOGADRO;
925 } /* call_gaussian */
927 real call_gaussian_SH(const t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
929 /* a gaussian call routine intended for doing diabatic surface
930 * "sliding". See the manual for the theoretical background of this
940 swapped = FALSE; /* handle for identifying the current PES */
942 swap = FALSE; /* the actual swap */
951 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
952 /* hack to do ground state simulations */
956 buf = getenv("GMX_QM_GROUND_STATE");
959 sscanf(buf, "%d", &state);
973 /* copy the QMMMrec pointer */
974 snew(QMgrad, qm->nrQMatoms);
975 snew(MMgrad, mm->nrMMatoms);
976 /* at step 0 there should be no SA */
979 /* temporray set to step + 1, since there is a chk start */
980 write_gaussian_SH_input(step, swapped, fr, qm, mm);
982 do_gaussian(step, exe);
983 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
985 /* check for a surface hop. Only possible if we were already state
992 swap = ((step != 0) && (hop(step, qm) != 0));
995 else /* already on the other surface, so check if we go back */
997 swap = ((step != 0) && (hop(step, qm) != 0));
998 swapped = !swap; /* so swapped shoud be false again */
1000 if (swap) /* change surface, so do another call */
1002 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1003 do_gaussian(step, exe);
1004 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
1007 /* add the QMMM forces to the gmx force array and fshift
1009 for (i = 0; i < qm->nrQMatoms; i++)
1011 for (j = 0; j < DIM; j++)
1013 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1014 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1017 for (i = 0; i < mm->nrMMatoms; i++)
1019 for (j = 0; j < DIM; j++)
1021 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1022 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1025 QMener = QMener*HARTREE2KJ*AVOGADRO;
1026 fprintf(stderr, "step %5d, SA = %5d, swap = %5d\n",
1027 step, static_cast<int>(qm->SAstep > 0), static_cast<int>(swapped));
1032 } /* call_gaussian_SH */
1034 #pragma GCC diagnostic pop