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,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_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/qmmm.h"
57 #include "gromacs/mdtypes/md_enums.h"
58 #include "gromacs/utility/cstringutil.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 /* TODO: this should be made thread-safe */
69 /* Gaussian interface routines */
71 void init_gaussian(t_QMrec* qm)
73 ivec basissets[eQMbasisNR] = { { 0, 3, 0 }, { 0, 3, 0 }, /*added for double sto-3g entry in names.c*/
74 { 5, 0, 0 }, { 5, 0, 1 }, { 5, 0, 11 }, { 5, 6, 0 },
75 { 1, 6, 0 }, { 1, 6, 1 }, { 1, 6, 11 }, { 4, 6, 0 } };
79 if (!GMX_QMMM_GAUSSIAN)
82 "Cannot call GAUSSIAN unless linked against it. Use cmake "
83 "-DGMX_QMMM_PROGRAM=GAUSSIAN, and ensure that linking will work correctly.");
86 /* using the ivec above to convert the basis read form the mdp file
87 * in a human readable format into some numbers for the gaussian
88 * route. This is necessary as we are using non standard routes to
92 /* per layer we make a new subdir for integral file, checkpoint
93 * files and such. These dirs are stored in the QMrec for
98 if (!qm->nQMcpus) /* this we do only once per layer
99 * as we call g01 externally
103 for (i = 0; i < DIM; i++)
105 qm->SHbasis[i] = basissets[qm->QMbasis][i];
108 /* init gradually switching on of the SA */
110 /* we read the number of cpus and environment from the environment
113 buf = getenv("GMX_QM_GAUSSIAN_NCPUS");
116 sscanf(buf, "%d", &qm->nQMcpus);
122 fprintf(stderr, "number of CPUs for gaussian = %d\n", qm->nQMcpus);
123 buf = getenv("GMX_QM_GAUSSIAN_MEMORY");
126 sscanf(buf, "%d", &qm->QMmem);
130 qm->QMmem = 50000000;
132 fprintf(stderr, "memory for gaussian = %d\n", qm->QMmem);
133 buf = getenv("GMX_QM_ACCURACY");
136 sscanf(buf, "%d", &qm->accuracy);
142 fprintf(stderr, "accuracy in l510 = %d\n", qm->accuracy);
144 buf = getenv("GMX_QM_CPMCSCF");
147 sscanf(buf, "%d", &i);
148 qm->cpmcscf = (i != 0);
156 fprintf(stderr, "using cp-mcscf in l1003\n");
160 fprintf(stderr, "NOT using cp-mcscf in l1003\n");
162 buf = getenv("GMX_QM_SA_STEP");
165 sscanf(buf, "%d", &qm->SAstep);
169 /* init gradually switching on of the SA */
172 /* we read the number of cpus and environment from the environment
175 fprintf(stderr, "Level of SA at start = %d\n", qm->SAstep);
176 /* gaussian settings on the system */
177 buf = getenv("GMX_QM_GAUSS_DIR");
181 qm->gauss_dir = gmx_strdup(buf);
185 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_DIR, check gaussian manual\n");
188 buf = getenv("GMX_QM_GAUSS_EXE");
191 qm->gauss_exe = gmx_strdup(buf);
195 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_EXE set, check gaussian manual\n");
197 buf = getenv("GMX_QM_MODIFIED_LINKS_DIR");
200 qm->devel_dir = gmx_strdup(buf);
205 "no $GMX_QM_MODIFIED_LINKS_DIR, this is were the modified links reside.\n");
209 /* reactionfield, file is needed using gaussian */
210 /* rffile=fopen("rf.dat","w");*/
211 /* fprintf(rffile,"%f %f\n",fr->epsilon_r,fr->rcoulomb/BOHR2NM);*/
215 fprintf(stderr, "gaussian initialised...\n");
219 static void write_gaussian_SH_input(int step, gmx_bool swap, const t_forcerec* fr, t_QMrec* qm, t_MMrec* mm)
226 bSA = (qm->SAstep > 0);
228 out = fopen("input.com", "w");
229 /* write the route */
230 fprintf(out, "%s", "%scr=input\n");
231 fprintf(out, "%s", "%rwf=input\n");
232 fprintf(out, "%s", "%int=input\n");
233 fprintf(out, "%s", "%d2e=input\n");
235 * fprintf(out,"%s","%nosave\n");
237 fprintf(out, "%s", "%chk=input\n");
238 fprintf(out, "%s%d\n", "%mem=", qm->QMmem);
239 fprintf(out, "%s%3d\n", "%nprocshare=", qm->nQMcpus);
241 /* use the versions of
242 * l301 that computes the interaction between MM and QM atoms.
243 * l510 that can punch the CI coefficients
244 * l701 that can do gradients on MM atoms
248 fprintf(out, "%s%s%s", "%subst l510 ", qm->devel_dir, "/l510\n");
249 fprintf(out, "%s%s%s", "%subst l301 ", qm->devel_dir, "/l301\n");
250 fprintf(out, "%s%s%s", "%subst l701 ", qm->devel_dir, "/l701\n");
252 fprintf(out, "%s%s%s", "%subst l1003 ", qm->devel_dir, "/l1003\n");
253 fprintf(out, "%s%s%s", "%subst l9999 ", qm->devel_dir, "/l9999\n");
254 /* print the nonstandard route
256 fprintf(out, "%s", "#P nonstd\n 1/18=10,20=1,38=1/1;\n");
257 fprintf(out, "%s", " 2/9=110,15=1,17=6,18=5,40=1/2;\n");
260 fprintf(out, " 3/5=%d,6=%d,7=%d,25=1,32=1,43=1,94=-2/1,2,3;\n", qm->SHbasis[0],
261 qm->SHbasis[1], qm->SHbasis[2]); /*basisset stuff */
265 fprintf(out, " 3/5=%d,6=%d,7=%d,25=1,32=1,43=0,94=-2/1,2,3;\n", qm->SHbasis[0],
266 qm->SHbasis[1], qm->SHbasis[2]); /*basisset stuff */
269 if (step + 1) /* fetch initial guess from check point file */
270 { /* hack, to alyays read from chk file!!!!! */
271 fprintf(out, "%s%d,%s%d%s", " 4/5=1,7=6,17=", qm->CASelectrons, "18=", qm->CASorbitals,
274 else /* generate the first checkpoint file */
276 fprintf(out, "%s%d,%s%d%s", " 4/5=0,7=6,17=", qm->CASelectrons, "18=", qm->CASorbitals,
279 /* the rest of the input depends on where the system is on the PES
281 if (swap && bSA) /* make a slide to the other surface */
283 if (qm->CASorbitals > 6) /* use direct and no full diag */
285 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6,97=100/10;\n");
291 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6,97=100/10;\n", qm->accuracy);
292 if (mm->nrMMatoms > 0)
294 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
296 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
297 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1,97=100/3;\n");
298 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
302 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6,97=100/10;\n", qm->accuracy);
303 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
307 else if (bSA) /* do a "state-averaged" CAS calculation */
309 if (qm->CASorbitals > 6) /* no full diag */
311 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6/10;\n");
317 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6/10;\n", qm->accuracy);
318 if (mm->nrMMatoms > 0)
320 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
322 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
323 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1/3;\n");
324 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
328 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6/10;\n", qm->accuracy);
329 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
333 else if (swap) /* do a "swapped" CAS calculation */
335 if (qm->CASorbitals > 6)
337 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6,97=100/10;\n");
341 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6,97=100/10;\n", qm->accuracy);
343 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
345 else /* do a "normal" CAS calculation */
347 if (qm->CASorbitals > 6)
349 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6/10;\n");
353 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6/10;\n", qm->accuracy);
355 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
357 fprintf(out, "\ninput-file generated by gromacs\n\n");
358 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
359 for (i = 0; i < qm->nrQMatoms; i++)
361 fprintf(out, "%3d %10.7f %10.7f %10.7f\n", qm->atomicnumberQM[i],
362 qm->xQM[i][XX] / BOHR2NM, qm->xQM[i][YY] / BOHR2NM, qm->xQM[i][ZZ] / BOHR2NM);
364 /* MM point charge data */
365 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
368 for (i = 0; i < mm->nrMMatoms; i++)
370 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n", mm->xMM[i][XX] / BOHR2NM,
371 mm->xMM[i][YY] / BOHR2NM, mm->xMM[i][ZZ] / BOHR2NM, mm->MMcharges[i]);
374 if (bSA) /* put the SA coefficients at the end of the file */
376 fprintf(out, "\n%10.8f %10.8f\n", qm->SAstep * 0.5 / qm->SAsteps, 1 - qm->SAstep * 0.5 / qm->SAsteps);
377 fprintf(stderr, "State Averaging level = %d/%d\n", qm->SAstep, qm->SAsteps);
381 } /* write_gaussian_SH_input */
383 static void write_gaussian_input(int step, const t_forcerec* fr, t_QMrec* qm, t_MMrec* mm)
390 out = fopen("input.com", "w");
391 /* write the route */
393 if (qm->QMmethod >= eQMmethodRHF)
395 fprintf(out, "%s", "%chk=input\n");
399 fprintf(out, "%s", "%chk=se\n");
403 fprintf(out, "%s%3d\n", "%nprocshare=", qm->nQMcpus);
405 fprintf(out, "%s%d\n", "%mem=", qm->QMmem);
406 fprintf(out, "%s%s%s", "%subst l701 ", qm->devel_dir, "/l701\n");
407 fprintf(out, "%s%s%s", "%subst l301 ", qm->devel_dir, "/l301\n");
408 fprintf(out, "%s%s%s", "%subst l9999 ", qm->devel_dir, "/l9999\n");
411 fprintf(out, "%s", "#T ");
415 fprintf(out, "%s", "#P ");
417 if (qm->QMmethod == eQMmethodB3LYPLAN)
419 fprintf(out, " %s", "B3LYP/GEN Pseudo=Read");
423 fprintf(out, " %s", eQMmethod_names[qm->QMmethod]);
425 if (qm->QMmethod >= eQMmethodRHF)
427 if (qm->QMmethod == eQMmethodCASSCF)
429 /* in case of cas, how many electrons and orbitals do we need?
431 fprintf(out, "(%d,%d)", qm->CASelectrons, qm->CASorbitals);
433 fprintf(out, "/%s", eQMbasis_names[qm->QMbasis]);
436 if (QMMMrec->QMMMscheme == eQMMMschemenormal && mm->nrMMatoms)
438 fprintf(out, " %s", "Charge ");
440 if (step || qm->QMmethod == eQMmethodCASSCF)
442 /* fetch guess from checkpoint file, always for CASSCF */
443 fprintf(out, "%s", " guess=read");
445 fprintf(out, "\nNosymm units=bohr\n");
447 fprintf(out, "FORCE Punch=(Derivatives) ");
448 fprintf(out, "iop(3/33=1)\n\n");
449 fprintf(out, "input-file generated by gromacs\n\n");
450 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
451 for (i = 0; i < qm->nrQMatoms; i++)
453 fprintf(out, "%3d %10.7f %10.7f %10.7f\n", qm->atomicnumberQM[i],
454 qm->xQM[i][XX] / BOHR2NM, qm->xQM[i][YY] / BOHR2NM, qm->xQM[i][ZZ] / BOHR2NM);
457 /* Pseudo Potential and ECP are included here if selected (MEthod suffix LAN) */
458 if (qm->QMmethod == eQMmethodB3LYPLAN)
461 for (i = 0; i < qm->nrQMatoms; i++)
463 if (qm->atomicnumberQM[i] < 21)
465 fprintf(out, "%d ", i + 1);
468 fprintf(out, "\n%s\n****\n", eQMbasis_names[qm->QMbasis]);
470 for (i = 0; i < qm->nrQMatoms; i++)
472 if (qm->atomicnumberQM[i] > 21)
474 fprintf(out, "%d ", i + 1);
477 fprintf(out, "\n%s\n****\n\n", "lanl2dz");
479 for (i = 0; i < qm->nrQMatoms; i++)
481 if (qm->atomicnumberQM[i] > 21)
483 fprintf(out, "%d ", i + 1);
486 fprintf(out, "\n%s\n", "lanl2dz");
490 /* MM point charge data */
491 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
493 fprintf(stderr, "nr mm atoms in gaussian.c = %d\n", mm->nrMMatoms);
495 for (i = 0; i < mm->nrMMatoms; i++)
497 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n", mm->xMM[i][XX] / BOHR2NM,
498 mm->xMM[i][YY] / BOHR2NM, mm->xMM[i][ZZ] / BOHR2NM, mm->MMcharges[i]);
506 } /* write_gaussian_input */
508 static real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], t_QMrec* qm, t_MMrec* mm)
515 in = fopen("fort.7", "r");
517 /* (There was additional content in the file in case
518 * of QM optimizations / transition state search,
521 /* the next line is the energy and in the case of CAS, the energy
522 * difference between the two states.
524 if (nullptr == fgets(buf, 300, in))
526 gmx_fatal(FARGS, "Error reading Gaussian output");
530 sscanf(buf, "%lf\n", &QMener);
532 sscanf(buf, "%f\n", &QMener);
534 /* next lines contain the gradients of the QM atoms */
535 for (i = 0; i < qm->nrQMatoms; i++)
537 if (nullptr == fgets(buf, 300, in))
539 gmx_fatal(FARGS, "Error reading Gaussian output");
542 sscanf(buf, "%lf %lf %lf\n", &QMgrad[i][XX], &QMgrad[i][YY], &QMgrad[i][ZZ]);
544 sscanf(buf, "%f %f %f\n", &QMgrad[i][XX], &QMgrad[i][YY], &QMgrad[i][ZZ]);
547 /* the next lines are the gradients of the MM atoms */
548 if (qm->QMmethod >= eQMmethodRHF)
550 for (i = 0; i < mm->nrMMatoms; i++)
552 if (nullptr == fgets(buf, 300, in))
554 gmx_fatal(FARGS, "Error reading Gaussian output");
557 sscanf(buf, "%lf %lf %lf\n", &MMgrad[i][XX], &MMgrad[i][YY], &MMgrad[i][ZZ]);
559 sscanf(buf, "%f %f %f\n", &MMgrad[i][XX], &MMgrad[i][YY], &MMgrad[i][ZZ]);
567 static real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step, t_QMrec* qm, t_MMrec* mm)
574 in = fopen("fort.7", "r");
575 /* first line is the energy and in the case of CAS, the energy
576 * difference between the two states.
578 if (nullptr == fgets(buf, 300, in))
580 gmx_fatal(FARGS, "Error reading Gaussian output");
584 sscanf(buf, "%lf %lf\n", &QMener, &DeltaE);
586 sscanf(buf, "%f %f\n", &QMener, &DeltaE);
589 /* switch on/off the State Averaging */
591 if (DeltaE > qm->SAoff)
598 else if (DeltaE < qm->SAon || (qm->SAstep > 0))
600 if (qm->SAstep < qm->SAsteps)
607 fprintf(stderr, "Gap = %5f,SA = %3d\n", DeltaE, static_cast<int>(qm->SAstep > 0));
608 /* next lines contain the gradients of the QM atoms */
609 for (i = 0; i < qm->nrQMatoms; i++)
611 if (nullptr == fgets(buf, 300, in))
613 gmx_fatal(FARGS, "Error reading Gaussian output");
617 sscanf(buf, "%lf %lf %lf\n", &QMgrad[i][XX], &QMgrad[i][YY], &QMgrad[i][ZZ]);
619 sscanf(buf, "%f %f %f\n", &QMgrad[i][XX], &QMgrad[i][YY], &QMgrad[i][ZZ]);
622 /* the next lines, are the gradients of the MM atoms */
624 for (i = 0; i < mm->nrMMatoms; i++)
626 if (nullptr == fgets(buf, 300, in))
628 gmx_fatal(FARGS, "Error reading Gaussian output");
631 sscanf(buf, "%lf %lf %lf\n", &MMgrad[i][XX], &MMgrad[i][YY], &MMgrad[i][ZZ]);
633 sscanf(buf, "%f %f %f\n", &MMgrad[i][XX], &MMgrad[i][YY], &MMgrad[i][ZZ]);
637 /* the next line contains the two CI eigenvector elements */
638 if (nullptr == fgets(buf, 300, in))
640 gmx_fatal(FARGS, "Error reading Gaussian output");
644 sscanf(buf, "%d", &qm->CIdim);
645 snew(qm->CIvec1, qm->CIdim);
646 snew(qm->CIvec1old, qm->CIdim);
647 snew(qm->CIvec2, qm->CIdim);
648 snew(qm->CIvec2old, qm->CIdim);
652 /* before reading in the new current CI vectors, copy the current
653 * CI vector into the old one.
655 for (i = 0; i < qm->CIdim; i++)
657 qm->CIvec1old[i] = qm->CIvec1[i];
658 qm->CIvec2old[i] = qm->CIvec2[i];
662 for (i = 0; i < qm->CIdim; i++)
664 if (nullptr == fgets(buf, 300, in))
666 gmx_fatal(FARGS, "Error reading Gaussian output");
669 sscanf(buf, "%lf\n", &qm->CIvec1[i]);
671 sscanf(buf, "%f\n", &qm->CIvec1[i]);
675 for (i = 0; i < qm->CIdim; i++)
677 if (nullptr == fgets(buf, 300, in))
679 gmx_fatal(FARGS, "Error reading Gaussian output");
682 sscanf(buf, "%lf\n", &qm->CIvec2[i]);
684 sscanf(buf, "%f\n", &qm->CIvec2[i]);
691 static real inproduct(const real* a, const real* b, int n)
696 /* computes the inner product between two vectors (a.b), both of
697 * which have length n.
699 for (i = 0; i < n; i++)
706 static int hop(int step, t_QMrec* qm)
709 real d11 = 0.0, d12 = 0.0, d21 = 0.0, d22 = 0.0;
711 /* calculates the inproduct between the current Ci vector and the
712 * previous CI vector. A diabatic hop will be made if d12 and d21
713 * are much bigger than d11 and d22. In that case hop returns true,
714 * otherwise it returns false.
716 if (step) /* only go on if more than one step has been done */
718 d11 = inproduct(qm->CIvec1, qm->CIvec1old, qm->CIdim);
719 d12 = inproduct(qm->CIvec1, qm->CIvec2old, qm->CIdim);
720 d21 = inproduct(qm->CIvec2, qm->CIvec1old, qm->CIdim);
721 d22 = inproduct(qm->CIvec2, qm->CIvec2old, qm->CIdim);
723 fprintf(stderr, "-------------------\n");
724 fprintf(stderr, "d11 = %13.8f\n", d11);
725 fprintf(stderr, "d12 = %13.8f\n", d12);
726 fprintf(stderr, "d21 = %13.8f\n", d21);
727 fprintf(stderr, "d22 = %13.8f\n", d22);
728 fprintf(stderr, "-------------------\n");
730 if ((fabs(d12) > 0.5) && (fabs(d21) > 0.5))
738 static void do_gaussian(int step, char* exe)
742 /* make the call to the gaussian binary through system()
743 * The location of the binary will be picked up from the
744 * environment using getenv().
746 if (step) /* hack to prevent long inputfiles */
748 sprintf(buf, "%s < %s > %s", exe, "input.com", "input.log");
752 sprintf(buf, "%s < %s > %s", exe, "input.com", "input.log");
754 fprintf(stderr, "Calling '%s'\n", buf);
755 if (system(buf) != 0)
757 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
761 real call_gaussian(const t_forcerec* fr, t_QMrec* qm, t_MMrec* mm, rvec f[], rvec fshift[])
763 /* normal gaussian jobs */
767 rvec * QMgrad, *MMgrad;
771 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
772 snew(QMgrad, qm->nrQMatoms);
773 snew(MMgrad, mm->nrMMatoms);
775 write_gaussian_input(step, fr, qm, mm);
776 do_gaussian(step, exe);
777 QMener = read_gaussian_output(QMgrad, MMgrad, qm, mm);
778 /* put the QMMM forces in the force array and to the fshift
780 for (i = 0; i < qm->nrQMatoms; i++)
782 for (j = 0; j < DIM; j++)
784 f[i][j] = HARTREE_BOHR2MD * QMgrad[i][j];
785 fshift[i][j] = HARTREE_BOHR2MD * QMgrad[i][j];
788 for (i = 0; i < mm->nrMMatoms; i++)
790 for (j = 0; j < DIM; j++)
792 f[i + qm->nrQMatoms][j] = HARTREE_BOHR2MD * MMgrad[i][j];
793 fshift[i + qm->nrQMatoms][j] = HARTREE_BOHR2MD * MMgrad[i][j];
796 QMener = QMener * HARTREE2KJ * AVOGADRO;
801 } /* call_gaussian */
803 real call_gaussian_SH(const t_forcerec* fr, t_QMrec* qm, t_MMrec* mm, rvec f[], rvec fshift[])
805 /* a gaussian call routine intended for doing diabatic surface
806 * "sliding". See the manual for the theoretical background of this
812 static gmx_bool swapped = FALSE; /* handle for identifying the current PES */
813 gmx_bool swap = FALSE; /* the actual swap */
814 rvec * QMgrad, *MMgrad;
819 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
820 /* hack to do ground state simulations */
824 buf = getenv("GMX_QM_GROUND_STATE");
827 sscanf(buf, "%d", &state);
841 /* copy the QMMMrec pointer */
842 snew(QMgrad, qm->nrQMatoms);
843 snew(MMgrad, mm->nrMMatoms);
844 /* at step 0 there should be no SA */
847 /* temporray set to step + 1, since there is a chk start */
848 write_gaussian_SH_input(step, swapped, fr, qm, mm);
850 do_gaussian(step, exe);
851 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
853 /* check for a surface hop. Only possible if we were already state
860 swap = ((step != 0) && (hop(step, qm) != 0));
863 else /* already on the other surface, so check if we go back */
865 swap = ((step != 0) && (hop(step, qm) != 0));
866 swapped = !swap; /* so swapped shoud be false again */
868 if (swap) /* change surface, so do another call */
870 write_gaussian_SH_input(step, swapped, fr, qm, mm);
871 do_gaussian(step, exe);
872 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
875 /* add the QMMM forces to the gmx force array and fshift
877 for (i = 0; i < qm->nrQMatoms; i++)
879 for (j = 0; j < DIM; j++)
881 f[i][j] = HARTREE_BOHR2MD * QMgrad[i][j];
882 fshift[i][j] = HARTREE_BOHR2MD * QMgrad[i][j];
885 for (i = 0; i < mm->nrMMatoms; i++)
887 for (j = 0; j < DIM; j++)
889 f[i + qm->nrQMatoms][j] = HARTREE_BOHR2MD * MMgrad[i][j];
890 fshift[i + qm->nrQMatoms][j] = HARTREE_BOHR2MD * MMgrad[i][j];
893 QMener = QMener * HARTREE2KJ * AVOGADRO;
894 fprintf(stderr, "step %5d, SA = %5d, swap = %5d\n", step, static_cast<int>(qm->SAstep > 0),
895 static_cast<int>(swapped));
900 } /* call_gaussian_SH */
902 #pragma GCC diagnostic pop