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, 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.
41 #ifdef GMX_QMMM_GAUSSIAN
50 #include "gromacs/utility/smalloc.h"
51 #include "gromacs/math/units.h"
52 #include "gromacs/math/vec.h"
55 #include "gromacs/fileio/confio.h"
63 #include "gromacs/utility/fatalerror.h"
66 /* TODO: this should be made thread-safe */
68 /* Gaussian interface routines */
70 void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
73 *rffile = NULL, *out = NULL;
75 basissets[eQMbasisNR] = {{0, 3, 0},
76 {0, 3, 0}, /*added for double sto-3g entry in names.c*/
90 /* using the ivec above to convert the basis read form the mdp file
91 * in a human readable format into some numbers for the gaussian
92 * route. This is necessary as we are using non standard routes to
96 /* per layer we make a new subdir for integral file, checkpoint
97 * files and such. These dirs are stored in the QMrec for
102 if (!qm->nQMcpus) /* this we do only once per layer
103 * as we call g01 externally
107 for (i = 0; i < DIM; i++)
109 qm->SHbasis[i] = basissets[qm->QMbasis][i];
112 /* init gradually switching on of the SA */
114 /* we read the number of cpus and environment from the environment
117 buf = getenv("NCPUS");
120 sscanf(buf, "%d", &qm->nQMcpus);
126 fprintf(stderr, "number of CPUs for gaussian = %d\n", qm->nQMcpus);
130 sscanf(buf, "%d", &qm->QMmem);
134 qm->QMmem = 50000000;
136 fprintf(stderr, "memory for gaussian = %d\n", qm->QMmem);
140 sscanf(buf, "%d", &qm->accuracy);
146 fprintf(stderr, "accuracy in l510 = %d\n", qm->accuracy);
148 buf = getenv("CPMCSCF");
151 sscanf(buf, "%d", &i);
152 qm->cpmcscf = (i != 0);
160 fprintf(stderr, "using cp-mcscf in l1003\n");
164 fprintf(stderr, "NOT using cp-mcscf in l1003\n");
166 buf = getenv("SASTEP");
169 sscanf(buf, "%d", &qm->SAstep);
173 /* init gradually switching on of the SA */
176 /* we read the number of cpus and environment from the environment
179 fprintf(stderr, "Level of SA at start = %d\n", qm->SAstep);
180 /* punch the LJ C6 and C12 coefficients to be picked up by
181 * gaussian and usd to compute the LJ interaction between the
184 if (qm->bTS || qm->bOPT)
186 out = fopen("LJ.dat", "w");
187 for (i = 0; i < qm->nrQMatoms; i++)
191 fprintf(out, "%3d %10.7lf %10.7lf\n",
192 qm->atomicnumberQM[i], qm->c6[i], qm->c12[i]);
194 fprintf(out, "%3d %10.7f %10.7f\n",
195 qm->atomicnumberQM[i], qm->c6[i], qm->c12[i]);
200 /* gaussian settings on the system */
201 buf = getenv("GAUSS_DIR");
202 fprintf(stderr, "%s", buf);
206 qm->gauss_dir = strdup(buf);
210 gmx_fatal(FARGS, "no $GAUSS_DIR, check gaussian manual\n");
213 buf = getenv("GAUSS_EXE");
216 qm->gauss_exe = strdup(buf);
220 gmx_fatal(FARGS, "no $GAUSS_EXE, check gaussian manual\n");
222 buf = getenv("DEVEL_DIR");
225 qm->devel_dir = strdup (buf);
229 gmx_fatal(FARGS, "no $DEVEL_DIR, this is were the modified links reside.\n");
233 /* reactionfield, file is needed using gaussian */
234 /* rffile=fopen("rf.dat","w");*/
235 /* fprintf(rffile,"%f %f\n",fr->epsilon_r,fr->rcoulomb/BOHR2NM);*/
239 fprintf(stderr, "gaussian initialised...\n");
244 void write_gaussian_SH_input(int step, gmx_bool swap,
245 t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
256 bSA = (qm->SAstep > 0);
258 out = fopen("input.com", "w");
259 /* write the route */
260 fprintf(out, "%s", "%scr=input\n");
261 fprintf(out, "%s", "%rwf=input\n");
262 fprintf(out, "%s", "%int=input\n");
263 fprintf(out, "%s", "%d2e=input\n");
265 * fprintf(out,"%s","%nosave\n");
267 fprintf(out, "%s", "%chk=input\n");
268 fprintf(out, "%s%d\n", "%mem=", qm->QMmem);
269 fprintf(out, "%s%3d\n", "%nprocshare=", qm->nQMcpus);
271 /* use the versions of
272 * l301 that computes the interaction between MM and QM atoms.
273 * l510 that can punch the CI coefficients
274 * l701 that can do gradients on MM atoms
278 fprintf(out, "%s%s%s",
282 fprintf(out, "%s%s%s",
286 fprintf(out, "%s%s%s",
291 fprintf(out, "%s%s%s",
295 fprintf(out, "%s%s%s",
299 /* print the nonstandard route
302 "#P nonstd\n 1/18=10,20=1,38=1/1;\n");
304 " 2/9=110,15=1,17=6,18=5,40=1/2;\n");
308 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=1,94=-2/1,2,3;\n",
311 qm->SHbasis[2]); /*basisset stuff */
316 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=0,94=-2/1,2,3;\n",
319 qm->SHbasis[2]); /*basisset stuff */
322 if (step+1) /* fetch initial guess from check point file */
323 { /* hack, to alyays read from chk file!!!!! */
324 fprintf(out, "%s%d,%s%d%s", " 4/5=1,7=6,17=",
326 "18=", qm->CASorbitals, "/1,5;\n");
328 else /* generate the first checkpoint file */
330 fprintf(out, "%s%d,%s%d%s", " 4/5=0,7=6,17=",
332 "18=", qm->CASorbitals, "/1,5;\n");
334 /* the rest of the input depends on where the system is on the PES
336 if (swap && bSA) /* make a slide to the other surface */
338 if (qm->CASorbitals > 6) /* use direct and no full diag */
340 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6,97=100/10;\n");
346 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6,97=100/10;\n",
348 if (mm->nrMMatoms > 0)
350 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
352 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
353 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1,97=100/3;\n");
354 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
358 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6,97=100/10;\n",
360 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
364 else if (bSA) /* do a "state-averaged" CAS calculation */
366 if (qm->CASorbitals > 6) /* no full diag */
368 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6/10;\n");
374 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6/10;\n",
376 if (mm->nrMMatoms > 0)
378 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
380 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
381 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1/3;\n");
382 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
386 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6/10;\n",
388 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
392 else if (swap) /* do a "swapped" CAS calculation */
394 if (qm->CASorbitals > 6)
396 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6,97=100/10;\n");
400 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6,97=100/10;\n",
403 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
405 else /* do a "normal" CAS calculation */
407 if (qm->CASorbitals > 6)
409 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6/10;\n");
413 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6/10;\n",
416 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
418 fprintf(out, "\ninput-file generated by gromacs\n\n");
419 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
420 for (i = 0; i < qm->nrQMatoms; i++)
423 fprintf(out, "%3d %10.7lf %10.7lf %10.7lf\n",
424 qm->atomicnumberQM[i],
425 qm->xQM[i][XX]/BOHR2NM,
426 qm->xQM[i][YY]/BOHR2NM,
427 qm->xQM[i][ZZ]/BOHR2NM);
429 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
430 qm->atomicnumberQM[i],
431 qm->xQM[i][XX]/BOHR2NM,
432 qm->xQM[i][YY]/BOHR2NM,
433 qm->xQM[i][ZZ]/BOHR2NM);
436 /* MM point charge data */
437 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
440 for (i = 0; i < mm->nrMMatoms; i++)
443 fprintf(out, "%10.7lf %10.7lf %10.7lf %8.4lf\n",
444 mm->xMM[i][XX]/BOHR2NM,
445 mm->xMM[i][YY]/BOHR2NM,
446 mm->xMM[i][ZZ]/BOHR2NM,
449 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
450 mm->xMM[i][XX]/BOHR2NM,
451 mm->xMM[i][YY]/BOHR2NM,
452 mm->xMM[i][ZZ]/BOHR2NM,
457 if (bSA) /* put the SA coefficients at the end of the file */
460 fprintf(out, "\n%10.8lf %10.8lf\n",
461 qm->SAstep*0.5/qm->SAsteps,
462 1-qm->SAstep*0.5/qm->SAsteps);
464 fprintf(out, "\n%10.8f %10.8f\n",
465 qm->SAstep*0.5/qm->SAsteps,
466 1-qm->SAstep*0.5/qm->SAsteps);
468 fprintf(stderr, "State Averaging level = %d/%d\n", qm->SAstep, qm->SAsteps);
472 } /* write_gaussian_SH_input */
474 void write_gaussian_input(int step, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
484 out = fopen("input.com", "w");
485 /* write the route */
487 if (qm->QMmethod >= eQMmethodRHF)
499 fprintf(out, "%s%3d\n",
500 "%nprocshare=", qm->nQMcpus);
502 fprintf(out, "%s%d\n",
504 /* use the modified links that include the LJ contribution at the QM level */
505 if (qm->bTS || qm->bOPT)
507 fprintf(out, "%s%s%s",
508 "%subst l701 ", qm->devel_dir, "/l701_LJ\n");
509 fprintf(out, "%s%s%s",
510 "%subst l301 ", qm->devel_dir, "/l301_LJ\n");
514 fprintf(out, "%s%s%s",
515 "%subst l701 ", qm->devel_dir, "/l701\n");
516 fprintf(out, "%s%s%s",
517 "%subst l301 ", qm->devel_dir, "/l301\n");
519 fprintf(out, "%s%s%s",
520 "%subst l9999 ", qm->devel_dir, "/l9999\n");
531 if (qm->QMmethod == eQMmethodB3LYPLAN)
534 "B3LYP/GEN Pseudo=Read");
539 eQMmethod_names[qm->QMmethod]);
541 if (qm->QMmethod >= eQMmethodRHF)
543 if (qm->QMmethod == eQMmethodCASSCF)
545 /* in case of cas, how many electrons and orbitals do we need?
547 fprintf(out, "(%d,%d)",
548 qm->CASelectrons, qm->CASorbitals);
551 eQMbasis_names[qm->QMbasis]);
554 if (QMMMrec->QMMMscheme == eQMMMschemenormal && mm->nrMMatoms)
559 if (step || qm->QMmethod == eQMmethodCASSCF)
561 /* fetch guess from checkpoint file, always for CASSCF */
562 fprintf(out, "%s", " guess=read");
564 fprintf(out, "\nNosymm units=bohr\n");
568 fprintf(out, "OPT=(Redundant,TS,noeigentest,ModRedundant) Punch=(Coord,Derivatives) ");
572 fprintf(out, "OPT=(Redundant,ModRedundant) Punch=(Coord,Derivatives) ");
576 fprintf(out, "FORCE Punch=(Derivatives) ");
578 fprintf(out, "iop(3/33=1)\n\n");
579 fprintf(out, "input-file generated by gromacs\n\n");
580 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
581 for (i = 0; i < qm->nrQMatoms; i++)
584 fprintf(out, "%3d %10.7lf %10.7lf %10.7lf\n",
585 qm->atomicnumberQM[i],
586 qm->xQM[i][XX]/BOHR2NM,
587 qm->xQM[i][YY]/BOHR2NM,
588 qm->xQM[i][ZZ]/BOHR2NM);
590 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
591 qm->atomicnumberQM[i],
592 qm->xQM[i][XX]/BOHR2NM,
593 qm->xQM[i][YY]/BOHR2NM,
594 qm->xQM[i][ZZ]/BOHR2NM);
598 /* Pseudo Potential and ECP are included here if selected (MEthod suffix LAN) */
599 if (qm->QMmethod == eQMmethodB3LYPLAN)
602 for (i = 0; i < qm->nrQMatoms; i++)
604 if (qm->atomicnumberQM[i] < 21)
606 fprintf(out, "%d ", i+1);
609 fprintf(out, "\n%s\n****\n", eQMbasis_names[qm->QMbasis]);
611 for (i = 0; i < qm->nrQMatoms; i++)
613 if (qm->atomicnumberQM[i] > 21)
615 fprintf(out, "%d ", i+1);
618 fprintf(out, "\n%s\n****\n\n", "lanl2dz");
620 for (i = 0; i < qm->nrQMatoms; i++)
622 if (qm->atomicnumberQM[i] > 21)
624 fprintf(out, "%d ", i+1);
627 fprintf(out, "\n%s\n", "lanl2dz");
632 /* MM point charge data */
633 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
635 fprintf(stderr, "nr mm atoms in gaussian.c = %d\n", mm->nrMMatoms);
637 if (qm->bTS || qm->bOPT)
639 /* freeze the frontier QM atoms and Link atoms. This is
640 * important only if a full QM subsystem optimization is done
641 * with a frozen MM environmeent. For dynamics, or gromacs's own
642 * optimization routines this is not important.
644 for (i = 0; i < qm->nrQMatoms; i++)
646 if (qm->frontatoms[i])
648 fprintf(out, "%d F\n", i+1); /* counting from 1 */
651 /* MM point charges include LJ parameters in case of QM optimization
653 for (i = 0; i < mm->nrMMatoms; i++)
656 fprintf(out, "%10.7lf %10.7lf %10.7lf %8.4lf 0.0 %10.7lf %10.7lf\n",
657 mm->xMM[i][XX]/BOHR2NM,
658 mm->xMM[i][YY]/BOHR2NM,
659 mm->xMM[i][ZZ]/BOHR2NM,
661 mm->c6[i], mm->c12[i]);
663 fprintf(out, "%10.7f %10.7f %10.7f %8.4f 0.0 %10.7f %10.7f\n",
664 mm->xMM[i][XX]/BOHR2NM,
665 mm->xMM[i][YY]/BOHR2NM,
666 mm->xMM[i][ZZ]/BOHR2NM,
668 mm->c6[i], mm->c12[i]);
675 for (i = 0; i < mm->nrMMatoms; i++)
678 fprintf(out, "%10.7lf %10.7lf %10.7lf %8.4lf\n",
679 mm->xMM[i][XX]/BOHR2NM,
680 mm->xMM[i][YY]/BOHR2NM,
681 mm->xMM[i][ZZ]/BOHR2NM,
684 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
685 mm->xMM[i][XX]/BOHR2NM,
686 mm->xMM[i][YY]/BOHR2NM,
687 mm->xMM[i][ZZ]/BOHR2NM,
698 } /* write_gaussian_input */
700 real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], int step,
701 t_QMrec *qm, t_MMrec *mm)
712 in = fopen("fort.7", "r");
716 /* in case of an optimization, the coordinates are printed in the
717 * fort.7 file first, followed by the energy, coordinates and (if
718 * required) the CI eigenvectors.
720 if (qm->bTS || qm->bOPT)
722 for (i = 0; i < qm->nrQMatoms; i++)
724 if (NULL == fgets(buf, 300, in))
726 gmx_fatal(FARGS, "Error reading Gaussian output - not enough atom lines?");
730 sscanf(buf, "%d %lf %lf %lf\n",
736 sscanf(buf, "%d %f %f %f\n",
742 for (j = 0; j < DIM; j++)
744 qm->xQM[i][j] *= BOHR2NM;
748 /* the next line is the energy and in the case of CAS, the energy
749 * difference between the two states.
751 if (NULL == fgets(buf, 300, in))
753 gmx_fatal(FARGS, "Error reading Gaussian output");
757 sscanf(buf, "%lf\n", &QMener);
759 sscanf(buf, "%f\n", &QMener);
761 /* next lines contain the gradients of the QM atoms */
762 for (i = 0; i < qm->nrQMatoms; i++)
764 if (NULL == fgets(buf, 300, in))
766 gmx_fatal(FARGS, "Error reading Gaussian output");
769 sscanf(buf, "%lf %lf %lf\n",
774 sscanf(buf, "%f %f %f\n",
780 /* the next lines are the gradients of the MM atoms */
781 if (qm->QMmethod >= eQMmethodRHF)
783 for (i = 0; i < mm->nrMMatoms; i++)
785 if (NULL == fgets(buf, 300, in))
787 gmx_fatal(FARGS, "Error reading Gaussian output");
790 sscanf(buf, "%lf %lf %lf\n",
795 sscanf(buf, "%f %f %f\n",
806 real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step,
807 gmx_bool swapped, t_QMrec *qm, t_MMrec *mm)
818 in = fopen("fort.7", "r");
819 /* first line is the energy and in the case of CAS, the energy
820 * difference between the two states.
822 if (NULL == fgets(buf, 300, in))
824 gmx_fatal(FARGS, "Error reading Gaussian output");
828 sscanf(buf, "%lf %lf\n", &QMener, &DeltaE);
830 sscanf(buf, "%f %f\n", &QMener, &DeltaE);
833 /* switch on/off the State Averaging */
835 if (DeltaE > qm->SAoff)
842 else if (DeltaE < qm->SAon || (qm->SAstep > 0))
844 if (qm->SAstep < qm->SAsteps)
851 fprintf(stderr, "Gap = %5f,SA = %3d\n", DeltaE, (qm->SAstep > 0));
852 /* next lines contain the gradients of the QM atoms */
853 for (i = 0; i < qm->nrQMatoms; i++)
855 if (NULL == fgets(buf, 300, in))
857 gmx_fatal(FARGS, "Error reading Gaussian output");
861 sscanf(buf, "%lf %lf %lf\n",
866 sscanf(buf, "%f %f %f\n",
872 /* the next lines, are the gradients of the MM atoms */
874 for (i = 0; i < mm->nrMMatoms; i++)
876 if (NULL == fgets(buf, 300, in))
878 gmx_fatal(FARGS, "Error reading Gaussian output");
881 sscanf(buf, "%lf %lf %lf\n",
886 sscanf(buf, "%f %f %f\n",
893 /* the next line contains the two CI eigenvector elements */
894 if (NULL == fgets(buf, 300, in))
896 gmx_fatal(FARGS, "Error reading Gaussian output");
900 sscanf(buf, "%d", &qm->CIdim);
901 snew(qm->CIvec1, qm->CIdim);
902 snew(qm->CIvec1old, qm->CIdim);
903 snew(qm->CIvec2, qm->CIdim);
904 snew(qm->CIvec2old, qm->CIdim);
908 /* before reading in the new current CI vectors, copy the current
909 * CI vector into the old one.
911 for (i = 0; i < qm->CIdim; i++)
913 qm->CIvec1old[i] = qm->CIvec1[i];
914 qm->CIvec2old[i] = qm->CIvec2[i];
918 for (i = 0; i < qm->CIdim; i++)
920 if (NULL == fgets(buf, 300, in))
922 gmx_fatal(FARGS, "Error reading Gaussian output");
925 sscanf(buf, "%lf\n", &qm->CIvec1[i]);
927 sscanf(buf, "%f\n", &qm->CIvec1[i]);
931 for (i = 0; i < qm->CIdim; i++)
933 if (NULL == fgets(buf, 300, in))
935 gmx_fatal(FARGS, "Error reading Gaussian output");
938 sscanf(buf, "%lf\n", &qm->CIvec2[i]);
940 sscanf(buf, "%f\n", &qm->CIvec2[i]);
947 real inproduct(real *a, real *b, int n)
954 /* computes the inner product between two vectors (a.b), both of
955 * which have length n.
957 for (i = 0; i < n; i++)
964 int hop(int step, t_QMrec *qm)
969 d11 = 0.0, d12 = 0.0, d21 = 0.0, d22 = 0.0;
971 /* calculates the inproduct between the current Ci vector and the
972 * previous CI vector. A diabatic hop will be made if d12 and d21
973 * are much bigger than d11 and d22. In that case hop returns true,
974 * otherwise it returns false.
976 if (step) /* only go on if more than one step has been done */
978 d11 = inproduct(qm->CIvec1, qm->CIvec1old, qm->CIdim);
979 d12 = inproduct(qm->CIvec1, qm->CIvec2old, qm->CIdim);
980 d21 = inproduct(qm->CIvec2, qm->CIvec1old, qm->CIdim);
981 d22 = inproduct(qm->CIvec2, qm->CIvec2old, qm->CIdim);
983 fprintf(stderr, "-------------------\n");
984 fprintf(stderr, "d11 = %13.8f\n", d11);
985 fprintf(stderr, "d12 = %13.8f\n", d12);
986 fprintf(stderr, "d21 = %13.8f\n", d21);
987 fprintf(stderr, "d22 = %13.8f\n", d22);
988 fprintf(stderr, "-------------------\n");
990 if ((fabs(d12) > 0.5) && (fabs(d21) > 0.5))
998 void do_gaussian(int step, char *exe)
1003 /* make the call to the gaussian binary through system()
1004 * The location of the binary will be picked up from the
1005 * environment using getenv().
1007 if (step) /* hack to prevent long inputfiles */
1009 sprintf(buf, "%s < %s > %s",
1016 sprintf(buf, "%s < %s > %s",
1021 fprintf(stderr, "Calling '%s'\n", buf);
1022 #ifdef GMX_NO_SYSTEM
1023 printf("Warning-- No calls to system(3) supported on this platform.");
1024 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
1026 if (system(buf) != 0)
1028 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
1033 real call_gaussian(t_commrec *cr, t_forcerec *fr,
1034 t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
1036 /* normal gaussian jobs */
1049 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
1050 snew(QMgrad, qm->nrQMatoms);
1051 snew(MMgrad, mm->nrMMatoms);
1053 write_gaussian_input(step, fr, qm, mm);
1054 do_gaussian(step, exe);
1055 QMener = read_gaussian_output(QMgrad, MMgrad, step, qm, mm);
1056 /* put the QMMM forces in the force array and to the fshift
1058 for (i = 0; i < qm->nrQMatoms; i++)
1060 for (j = 0; j < DIM; j++)
1062 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1063 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1066 for (i = 0; i < mm->nrMMatoms; i++)
1068 for (j = 0; j < DIM; j++)
1070 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1071 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1074 QMener = QMener*HARTREE2KJ*AVOGADRO;
1079 } /* call_gaussian */
1081 real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
1082 rvec f[], rvec fshift[])
1084 /* a gaussian call routine intended for doing diabatic surface
1085 * "sliding". See the manual for the theoretical background of this
1095 swapped = FALSE; /* handle for identifying the current PES */
1097 swap = FALSE; /* the actual swap */
1106 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
1107 /* hack to do ground state simulations */
1111 buf = getenv("STATE");
1114 sscanf(buf, "%d", &state);
1128 /* copy the QMMMrec pointer */
1129 snew(QMgrad, qm->nrQMatoms);
1130 snew(MMgrad, mm->nrMMatoms);
1131 /* at step 0 there should be no SA */
1134 /* temporray set to step + 1, since there is a chk start */
1135 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1137 do_gaussian(step, exe);
1138 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, swapped, qm, mm);
1140 /* check for a surface hop. Only possible if we were already state
1147 swap = (step && hop(step, qm));
1150 else /* already on the other surface, so check if we go back */
1152 swap = (step && hop(step, qm));
1153 swapped = !swap; /* so swapped shoud be false again */
1155 if (swap) /* change surface, so do another call */
1157 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1158 do_gaussian(step, exe);
1159 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, swapped, qm, mm);
1162 /* add the QMMM forces to the gmx force array and fshift
1164 for (i = 0; i < qm->nrQMatoms; i++)
1166 for (j = 0; j < DIM; j++)
1168 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1169 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1172 for (i = 0; i < mm->nrMMatoms; i++)
1174 for (j = 0; j < DIM; j++)
1176 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1177 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1180 QMener = QMener*HARTREE2KJ*AVOGADRO;
1181 fprintf(stderr, "step %5d, SA = %5d, swap = %5d\n",
1182 step, (qm->SAstep > 0), swapped);
1187 } /* call_gaussian_SH */
1189 /* end of gaussian sub routines */
1193 gmx_qmmm_gaussian_empty;