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, 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.
48 #include "gromacs/fileio/confio.h"
49 #include "gromacs/gmxlib/network.h"
50 #include "gromacs/gmxlib/nrnb.h"
51 #include "gromacs/math/units.h"
52 #include "gromacs/math/vec.h"
53 #include "gromacs/mdlib/force.h"
54 #include "gromacs/mdlib/ns.h"
55 #include "gromacs/mdlib/qmmm.h"
56 #include "gromacs/mdtypes/md_enums.h"
57 #include "gromacs/utility/cstringutil.h"
58 #include "gromacs/utility/fatalerror.h"
59 #include "gromacs/utility/smalloc.h"
61 /* TODO: this should be made thread-safe */
63 /* Gaussian interface routines */
65 void init_gaussian(t_QMrec *qm)
69 basissets[eQMbasisNR] = {{0, 3, 0},
70 {0, 3, 0}, /*added for double sto-3g entry in names.c*/
84 /* using the ivec above to convert the basis read form the mdp file
85 * in a human readable format into some numbers for the gaussian
86 * route. This is necessary as we are using non standard routes to
90 /* per layer we make a new subdir for integral file, checkpoint
91 * files and such. These dirs are stored in the QMrec for
96 if (!qm->nQMcpus) /* this we do only once per layer
97 * as we call g01 externally
101 for (i = 0; i < DIM; i++)
103 qm->SHbasis[i] = basissets[qm->QMbasis][i];
106 /* init gradually switching on of the SA */
108 /* we read the number of cpus and environment from the environment
111 buf = getenv("GMX_QM_GAUSSIAN_NCPUS");
114 sscanf(buf, "%d", &qm->nQMcpus);
120 fprintf(stderr, "number of CPUs for gaussian = %d\n", qm->nQMcpus);
121 buf = getenv("GMX_QM_GAUSSIAN_MEMORY");
124 sscanf(buf, "%d", &qm->QMmem);
128 qm->QMmem = 50000000;
130 fprintf(stderr, "memory for gaussian = %d\n", qm->QMmem);
131 buf = getenv("GMX_QM_ACCURACY");
134 sscanf(buf, "%d", &qm->accuracy);
140 fprintf(stderr, "accuracy in l510 = %d\n", qm->accuracy);
142 buf = getenv("GMX_QM_CPMCSCF");
145 sscanf(buf, "%d", &i);
146 qm->cpmcscf = (i != 0);
154 fprintf(stderr, "using cp-mcscf in l1003\n");
158 fprintf(stderr, "NOT using cp-mcscf in l1003\n");
160 buf = getenv("GMX_QM_SA_STEP");
163 sscanf(buf, "%d", &qm->SAstep);
167 /* init gradually switching on of the SA */
170 /* we read the number of cpus and environment from the environment
173 fprintf(stderr, "Level of SA at start = %d\n", qm->SAstep);
174 /* punch the LJ C6 and C12 coefficients to be picked up by
175 * gaussian and usd to compute the LJ interaction between the
178 if (qm->bTS || qm->bOPT)
180 out = fopen("LJ.dat", "w");
181 for (i = 0; i < qm->nrQMatoms; i++)
183 fprintf(out, "%3d %10.7f %10.7f\n",
184 qm->atomicnumberQM[i], qm->c6[i], qm->c12[i]);
188 /* gaussian settings on the system */
189 buf = getenv("GMX_QM_GAUSS_DIR");
190 fprintf(stderr, "%s", buf);
194 qm->gauss_dir = gmx_strdup(buf);
198 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_DIR, check gaussian manual\n");
201 buf = getenv("GMX_QM_GAUSS_EXE");
204 qm->gauss_exe = gmx_strdup(buf);
208 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_EXE set, check gaussian manual\n");
210 buf = getenv("GMX_QM_MODIFIED_LINKS_DIR");
213 qm->devel_dir = gmx_strdup (buf);
217 gmx_fatal(FARGS, "no $GMX_QM_MODIFIED_LINKS_DIR, this is were the modified links reside.\n");
221 /* reactionfield, file is needed using gaussian */
222 /* rffile=fopen("rf.dat","w");*/
223 /* fprintf(rffile,"%f %f\n",fr->epsilon_r,fr->rcoulomb/BOHR2NM);*/
227 fprintf(stderr, "gaussian initialised...\n");
232 void write_gaussian_SH_input(int step, gmx_bool swap,
233 t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
244 bSA = (qm->SAstep > 0);
246 out = fopen("input.com", "w");
247 /* write the route */
248 fprintf(out, "%s", "%scr=input\n");
249 fprintf(out, "%s", "%rwf=input\n");
250 fprintf(out, "%s", "%int=input\n");
251 fprintf(out, "%s", "%d2e=input\n");
253 * fprintf(out,"%s","%nosave\n");
255 fprintf(out, "%s", "%chk=input\n");
256 fprintf(out, "%s%d\n", "%mem=", qm->QMmem);
257 fprintf(out, "%s%3d\n", "%nprocshare=", qm->nQMcpus);
259 /* use the versions of
260 * l301 that computes the interaction between MM and QM atoms.
261 * l510 that can punch the CI coefficients
262 * l701 that can do gradients on MM atoms
266 fprintf(out, "%s%s%s",
270 fprintf(out, "%s%s%s",
274 fprintf(out, "%s%s%s",
279 fprintf(out, "%s%s%s",
283 fprintf(out, "%s%s%s",
287 /* print the nonstandard route
290 "#P nonstd\n 1/18=10,20=1,38=1/1;\n");
292 " 2/9=110,15=1,17=6,18=5,40=1/2;\n");
296 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=1,94=-2/1,2,3;\n",
299 qm->SHbasis[2]); /*basisset stuff */
304 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=0,94=-2/1,2,3;\n",
307 qm->SHbasis[2]); /*basisset stuff */
310 if (step+1) /* fetch initial guess from check point file */
311 { /* hack, to alyays read from chk file!!!!! */
312 fprintf(out, "%s%d,%s%d%s", " 4/5=1,7=6,17=",
314 "18=", qm->CASorbitals, "/1,5;\n");
316 else /* generate the first checkpoint file */
318 fprintf(out, "%s%d,%s%d%s", " 4/5=0,7=6,17=",
320 "18=", qm->CASorbitals, "/1,5;\n");
322 /* the rest of the input depends on where the system is on the PES
324 if (swap && bSA) /* make a slide to the other surface */
326 if (qm->CASorbitals > 6) /* use direct and no full diag */
328 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6,97=100/10;\n");
334 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6,97=100/10;\n",
336 if (mm->nrMMatoms > 0)
338 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
340 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
341 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1,97=100/3;\n");
342 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
346 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6,97=100/10;\n",
348 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
352 else if (bSA) /* do a "state-averaged" CAS calculation */
354 if (qm->CASorbitals > 6) /* no full diag */
356 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6/10;\n");
362 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6/10;\n",
364 if (mm->nrMMatoms > 0)
366 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
368 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
369 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1/3;\n");
370 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
374 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6/10;\n",
376 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
380 else if (swap) /* do a "swapped" CAS calculation */
382 if (qm->CASorbitals > 6)
384 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6,97=100/10;\n");
388 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6,97=100/10;\n",
391 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
393 else /* do a "normal" CAS calculation */
395 if (qm->CASorbitals > 6)
397 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6/10;\n");
401 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6/10;\n",
404 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
406 fprintf(out, "\ninput-file generated by gromacs\n\n");
407 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
408 for (i = 0; i < qm->nrQMatoms; i++)
410 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
411 qm->atomicnumberQM[i],
412 qm->xQM[i][XX]/BOHR2NM,
413 qm->xQM[i][YY]/BOHR2NM,
414 qm->xQM[i][ZZ]/BOHR2NM);
416 /* MM point charge data */
417 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
420 for (i = 0; i < mm->nrMMatoms; i++)
422 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
423 mm->xMM[i][XX]/BOHR2NM,
424 mm->xMM[i][YY]/BOHR2NM,
425 mm->xMM[i][ZZ]/BOHR2NM,
429 if (bSA) /* put the SA coefficients at the end of the file */
431 fprintf(out, "\n%10.8f %10.8f\n",
432 qm->SAstep*0.5/qm->SAsteps,
433 1-qm->SAstep*0.5/qm->SAsteps);
434 fprintf(stderr, "State Averaging level = %d/%d\n", qm->SAstep, qm->SAsteps);
438 } /* write_gaussian_SH_input */
440 void write_gaussian_input(int step, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
450 out = fopen("input.com", "w");
451 /* write the route */
453 if (qm->QMmethod >= eQMmethodRHF)
465 fprintf(out, "%s%3d\n",
466 "%nprocshare=", qm->nQMcpus);
468 fprintf(out, "%s%d\n",
470 /* use the modified links that include the LJ contribution at the QM level */
471 if (qm->bTS || qm->bOPT)
473 fprintf(out, "%s%s%s",
474 "%subst l701 ", qm->devel_dir, "/l701_LJ\n");
475 fprintf(out, "%s%s%s",
476 "%subst l301 ", qm->devel_dir, "/l301_LJ\n");
480 fprintf(out, "%s%s%s",
481 "%subst l701 ", qm->devel_dir, "/l701\n");
482 fprintf(out, "%s%s%s",
483 "%subst l301 ", qm->devel_dir, "/l301\n");
485 fprintf(out, "%s%s%s",
486 "%subst l9999 ", qm->devel_dir, "/l9999\n");
497 if (qm->QMmethod == eQMmethodB3LYPLAN)
500 "B3LYP/GEN Pseudo=Read");
505 eQMmethod_names[qm->QMmethod]);
507 if (qm->QMmethod >= eQMmethodRHF)
509 if (qm->QMmethod == eQMmethodCASSCF)
511 /* in case of cas, how many electrons and orbitals do we need?
513 fprintf(out, "(%d,%d)",
514 qm->CASelectrons, qm->CASorbitals);
517 eQMbasis_names[qm->QMbasis]);
520 if (QMMMrec->QMMMscheme == eQMMMschemenormal && mm->nrMMatoms)
525 if (step || qm->QMmethod == eQMmethodCASSCF)
527 /* fetch guess from checkpoint file, always for CASSCF */
528 fprintf(out, "%s", " guess=read");
530 fprintf(out, "\nNosymm units=bohr\n");
534 fprintf(out, "OPT=(Redundant,TS,noeigentest,ModRedundant) Punch=(Coord,Derivatives) ");
538 fprintf(out, "OPT=(Redundant,ModRedundant) Punch=(Coord,Derivatives) ");
542 fprintf(out, "FORCE Punch=(Derivatives) ");
544 fprintf(out, "iop(3/33=1)\n\n");
545 fprintf(out, "input-file generated by gromacs\n\n");
546 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
547 for (i = 0; i < qm->nrQMatoms; i++)
549 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
550 qm->atomicnumberQM[i],
551 qm->xQM[i][XX]/BOHR2NM,
552 qm->xQM[i][YY]/BOHR2NM,
553 qm->xQM[i][ZZ]/BOHR2NM);
556 /* Pseudo Potential and ECP are included here if selected (MEthod suffix LAN) */
557 if (qm->QMmethod == eQMmethodB3LYPLAN)
560 for (i = 0; i < qm->nrQMatoms; i++)
562 if (qm->atomicnumberQM[i] < 21)
564 fprintf(out, "%d ", i+1);
567 fprintf(out, "\n%s\n****\n", eQMbasis_names[qm->QMbasis]);
569 for (i = 0; i < qm->nrQMatoms; i++)
571 if (qm->atomicnumberQM[i] > 21)
573 fprintf(out, "%d ", i+1);
576 fprintf(out, "\n%s\n****\n\n", "lanl2dz");
578 for (i = 0; i < qm->nrQMatoms; i++)
580 if (qm->atomicnumberQM[i] > 21)
582 fprintf(out, "%d ", i+1);
585 fprintf(out, "\n%s\n", "lanl2dz");
590 /* MM point charge data */
591 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
593 fprintf(stderr, "nr mm atoms in gaussian.c = %d\n", mm->nrMMatoms);
595 if (qm->bTS || qm->bOPT)
597 /* freeze the frontier QM atoms and Link atoms. This is
598 * important only if a full QM subsystem optimization is done
599 * with a frozen MM environmeent. For dynamics, or gromacs's own
600 * optimization routines this is not important.
602 for (i = 0; i < qm->nrQMatoms; i++)
604 if (qm->frontatoms[i])
606 fprintf(out, "%d F\n", i+1); /* counting from 1 */
609 /* MM point charges include LJ parameters in case of QM optimization
611 for (i = 0; i < mm->nrMMatoms; i++)
613 fprintf(out, "%10.7f %10.7f %10.7f %8.4f 0.0 %10.7f %10.7f\n",
614 mm->xMM[i][XX]/BOHR2NM,
615 mm->xMM[i][YY]/BOHR2NM,
616 mm->xMM[i][ZZ]/BOHR2NM,
618 mm->c6[i], mm->c12[i]);
624 for (i = 0; i < mm->nrMMatoms; i++)
626 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
627 mm->xMM[i][XX]/BOHR2NM,
628 mm->xMM[i][YY]/BOHR2NM,
629 mm->xMM[i][ZZ]/BOHR2NM,
639 } /* write_gaussian_input */
641 real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], t_QMrec *qm, t_MMrec *mm)
652 in = fopen("fort.7", "r");
656 /* in case of an optimization, the coordinates are printed in the
657 * fort.7 file first, followed by the energy, coordinates and (if
658 * required) the CI eigenvectors.
660 if (qm->bTS || qm->bOPT)
662 for (i = 0; i < qm->nrQMatoms; i++)
664 if (NULL == fgets(buf, 300, in))
666 gmx_fatal(FARGS, "Error reading Gaussian output - not enough atom lines?");
670 sscanf(buf, "%d %lf %lf %lf\n",
676 sscanf(buf, "%d %f %f %f\n",
682 for (j = 0; j < DIM; j++)
684 qm->xQM[i][j] *= BOHR2NM;
688 /* the next line is the energy and in the case of CAS, the energy
689 * difference between the two states.
691 if (NULL == fgets(buf, 300, in))
693 gmx_fatal(FARGS, "Error reading Gaussian output");
697 sscanf(buf, "%lf\n", &QMener);
699 sscanf(buf, "%f\n", &QMener);
701 /* next lines contain the gradients of the QM atoms */
702 for (i = 0; i < qm->nrQMatoms; i++)
704 if (NULL == fgets(buf, 300, in))
706 gmx_fatal(FARGS, "Error reading Gaussian output");
709 sscanf(buf, "%lf %lf %lf\n",
714 sscanf(buf, "%f %f %f\n",
720 /* the next lines are the gradients of the MM atoms */
721 if (qm->QMmethod >= eQMmethodRHF)
723 for (i = 0; i < mm->nrMMatoms; i++)
725 if (NULL == fgets(buf, 300, in))
727 gmx_fatal(FARGS, "Error reading Gaussian output");
730 sscanf(buf, "%lf %lf %lf\n",
735 sscanf(buf, "%f %f %f\n",
746 real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step, t_QMrec *qm, t_MMrec *mm)
757 in = fopen("fort.7", "r");
758 /* first line is the energy and in the case of CAS, the energy
759 * difference between the two states.
761 if (NULL == fgets(buf, 300, in))
763 gmx_fatal(FARGS, "Error reading Gaussian output");
767 sscanf(buf, "%lf %lf\n", &QMener, &DeltaE);
769 sscanf(buf, "%f %f\n", &QMener, &DeltaE);
772 /* switch on/off the State Averaging */
774 if (DeltaE > qm->SAoff)
781 else if (DeltaE < qm->SAon || (qm->SAstep > 0))
783 if (qm->SAstep < qm->SAsteps)
790 fprintf(stderr, "Gap = %5f,SA = %3d\n", DeltaE, (qm->SAstep > 0));
791 /* next lines contain the gradients of the QM atoms */
792 for (i = 0; i < qm->nrQMatoms; i++)
794 if (NULL == fgets(buf, 300, in))
796 gmx_fatal(FARGS, "Error reading Gaussian output");
800 sscanf(buf, "%lf %lf %lf\n",
805 sscanf(buf, "%f %f %f\n",
811 /* the next lines, are the gradients of the MM atoms */
813 for (i = 0; i < mm->nrMMatoms; i++)
815 if (NULL == fgets(buf, 300, in))
817 gmx_fatal(FARGS, "Error reading Gaussian output");
820 sscanf(buf, "%lf %lf %lf\n",
825 sscanf(buf, "%f %f %f\n",
832 /* the next line contains the two CI eigenvector elements */
833 if (NULL == fgets(buf, 300, in))
835 gmx_fatal(FARGS, "Error reading Gaussian output");
839 sscanf(buf, "%d", &qm->CIdim);
840 snew(qm->CIvec1, qm->CIdim);
841 snew(qm->CIvec1old, qm->CIdim);
842 snew(qm->CIvec2, qm->CIdim);
843 snew(qm->CIvec2old, qm->CIdim);
847 /* before reading in the new current CI vectors, copy the current
848 * CI vector into the old one.
850 for (i = 0; i < qm->CIdim; i++)
852 qm->CIvec1old[i] = qm->CIvec1[i];
853 qm->CIvec2old[i] = qm->CIvec2[i];
857 for (i = 0; i < qm->CIdim; i++)
859 if (NULL == fgets(buf, 300, in))
861 gmx_fatal(FARGS, "Error reading Gaussian output");
864 sscanf(buf, "%lf\n", &qm->CIvec1[i]);
866 sscanf(buf, "%f\n", &qm->CIvec1[i]);
870 for (i = 0; i < qm->CIdim; i++)
872 if (NULL == fgets(buf, 300, in))
874 gmx_fatal(FARGS, "Error reading Gaussian output");
877 sscanf(buf, "%lf\n", &qm->CIvec2[i]);
879 sscanf(buf, "%f\n", &qm->CIvec2[i]);
886 real inproduct(real *a, real *b, int n)
893 /* computes the inner product between two vectors (a.b), both of
894 * which have length n.
896 for (i = 0; i < n; i++)
903 int hop(int step, t_QMrec *qm)
908 d11 = 0.0, d12 = 0.0, d21 = 0.0, d22 = 0.0;
910 /* calculates the inproduct between the current Ci vector and the
911 * previous CI vector. A diabatic hop will be made if d12 and d21
912 * are much bigger than d11 and d22. In that case hop returns true,
913 * otherwise it returns false.
915 if (step) /* only go on if more than one step has been done */
917 d11 = inproduct(qm->CIvec1, qm->CIvec1old, qm->CIdim);
918 d12 = inproduct(qm->CIvec1, qm->CIvec2old, qm->CIdim);
919 d21 = inproduct(qm->CIvec2, qm->CIvec1old, qm->CIdim);
920 d22 = inproduct(qm->CIvec2, qm->CIvec2old, qm->CIdim);
922 fprintf(stderr, "-------------------\n");
923 fprintf(stderr, "d11 = %13.8f\n", d11);
924 fprintf(stderr, "d12 = %13.8f\n", d12);
925 fprintf(stderr, "d21 = %13.8f\n", d21);
926 fprintf(stderr, "d22 = %13.8f\n", d22);
927 fprintf(stderr, "-------------------\n");
929 if ((fabs(d12) > 0.5) && (fabs(d21) > 0.5))
937 void do_gaussian(int step, char *exe)
942 /* make the call to the gaussian binary through system()
943 * The location of the binary will be picked up from the
944 * environment using getenv().
946 if (step) /* hack to prevent long inputfiles */
948 sprintf(buf, "%s < %s > %s",
955 sprintf(buf, "%s < %s > %s",
960 fprintf(stderr, "Calling '%s'\n", buf);
961 if (system(buf) != 0)
963 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
967 real call_gaussian(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
969 /* normal gaussian jobs */
982 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
983 snew(QMgrad, qm->nrQMatoms);
984 snew(MMgrad, mm->nrMMatoms);
986 write_gaussian_input(step, fr, qm, mm);
987 do_gaussian(step, exe);
988 QMener = read_gaussian_output(QMgrad, MMgrad, qm, mm);
989 /* put the QMMM forces in the force array and to the fshift
991 for (i = 0; i < qm->nrQMatoms; i++)
993 for (j = 0; j < DIM; j++)
995 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
996 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
999 for (i = 0; i < mm->nrMMatoms; i++)
1001 for (j = 0; j < DIM; j++)
1003 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1004 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1007 QMener = QMener*HARTREE2KJ*AVOGADRO;
1012 } /* call_gaussian */
1014 real call_gaussian_SH(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
1016 /* a gaussian call routine intended for doing diabatic surface
1017 * "sliding". See the manual for the theoretical background of this
1027 swapped = FALSE; /* handle for identifying the current PES */
1029 swap = FALSE; /* the actual swap */
1038 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
1039 /* hack to do ground state simulations */
1043 buf = getenv("GMX_QM_GROUND_STATE");
1046 sscanf(buf, "%d", &state);
1060 /* copy the QMMMrec pointer */
1061 snew(QMgrad, qm->nrQMatoms);
1062 snew(MMgrad, mm->nrMMatoms);
1063 /* at step 0 there should be no SA */
1066 /* temporray set to step + 1, since there is a chk start */
1067 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1069 do_gaussian(step, exe);
1070 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
1072 /* check for a surface hop. Only possible if we were already state
1079 swap = (step && hop(step, qm));
1082 else /* already on the other surface, so check if we go back */
1084 swap = (step && hop(step, qm));
1085 swapped = !swap; /* so swapped shoud be false again */
1087 if (swap) /* change surface, so do another call */
1089 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1090 do_gaussian(step, exe);
1091 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
1094 /* add the QMMM forces to the gmx force array and fshift
1096 for (i = 0; i < qm->nrQMatoms; i++)
1098 for (j = 0; j < DIM; j++)
1100 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1101 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1104 for (i = 0; i < mm->nrMMatoms; i++)
1106 for (j = 0; j < DIM; j++)
1108 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1109 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1112 QMener = QMener*HARTREE2KJ*AVOGADRO;
1113 fprintf(stderr, "step %5d, SA = %5d, swap = %5d\n",
1114 step, (qm->SAstep > 0), swapped);
1119 } /* call_gaussian_SH */
1121 /* end of gaussian sub routines */
1125 gmx_qmmm_gaussian_empty;