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
48 #include "gromacs/legacyheaders/typedefs.h"
49 #include "gromacs/legacyheaders/macros.h"
50 #include "gromacs/utility/smalloc.h"
51 #include "gromacs/math/units.h"
52 #include "gromacs/math/vec.h"
53 #include "gromacs/legacyheaders/force.h"
54 #include "gromacs/fileio/confio.h"
55 #include "gromacs/legacyheaders/names.h"
56 #include "gromacs/legacyheaders/network.h"
57 #include "gromacs/legacyheaders/ns.h"
58 #include "gromacs/legacyheaders/nrnb.h"
59 #include "gromacs/legacyheaders/txtdump.h"
60 #include "gromacs/legacyheaders/qmmm.h"
61 #include "gromacs/utility/fatalerror.h"
64 /* TODO: this should be made thread-safe */
66 /* Gaussian interface routines */
68 void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
71 *rffile = NULL, *out = NULL;
73 basissets[eQMbasisNR] = {{0, 3, 0},
74 {0, 3, 0}, /*added for double sto-3g entry in names.c*/
88 /* using the ivec above to convert the basis read form the mdp file
89 * in a human readable format into some numbers for the gaussian
90 * route. This is necessary as we are using non standard routes to
94 /* per layer we make a new subdir for integral file, checkpoint
95 * files and such. These dirs are stored in the QMrec for
100 if (!qm->nQMcpus) /* this we do only once per layer
101 * as we call g01 externally
105 for (i = 0; i < DIM; i++)
107 qm->SHbasis[i] = basissets[qm->QMbasis][i];
110 /* init gradually switching on of the SA */
112 /* we read the number of cpus and environment from the environment
115 buf = getenv("GMX_QM_GAUSSIAN_NCPUS");
118 sscanf(buf, "%d", &qm->nQMcpus);
124 fprintf(stderr, "number of CPUs for gaussian = %d\n", qm->nQMcpus);
125 buf = getenv("GMX_QM_GAUSSIAN_MEMORY");
128 sscanf(buf, "%d", &qm->QMmem);
132 qm->QMmem = 50000000;
134 fprintf(stderr, "memory for gaussian = %d\n", qm->QMmem);
135 buf = getenv("GMX_QM_ACCURACY");
138 sscanf(buf, "%d", &qm->accuracy);
144 fprintf(stderr, "accuracy in l510 = %d\n", qm->accuracy);
146 buf = getenv("GMX_QM_CPMCSCF");
149 sscanf(buf, "%d", &i);
150 qm->cpmcscf = (i != 0);
158 fprintf(stderr, "using cp-mcscf in l1003\n");
162 fprintf(stderr, "NOT using cp-mcscf in l1003\n");
164 buf = getenv("GMX_QM_SA_STEP");
167 sscanf(buf, "%d", &qm->SAstep);
171 /* init gradually switching on of the SA */
174 /* we read the number of cpus and environment from the environment
177 fprintf(stderr, "Level of SA at start = %d\n", qm->SAstep);
178 /* punch the LJ C6 and C12 coefficients to be picked up by
179 * gaussian and usd to compute the LJ interaction between the
182 if (qm->bTS || qm->bOPT)
184 out = fopen("LJ.dat", "w");
185 for (i = 0; i < qm->nrQMatoms; i++)
189 fprintf(out, "%3d %10.7lf %10.7lf\n",
190 qm->atomicnumberQM[i], qm->c6[i], qm->c12[i]);
192 fprintf(out, "%3d %10.7f %10.7f\n",
193 qm->atomicnumberQM[i], qm->c6[i], qm->c12[i]);
198 /* gaussian settings on the system */
199 buf = getenv("GMX_QM_GAUSS_DIR");
200 fprintf(stderr, "%s", buf);
204 qm->gauss_dir = gmx_strdup(buf);
208 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_DIR, check gaussian manual\n");
211 buf = getenv("GMX_QM_GAUSS_EXE");
214 qm->gauss_exe = gmx_strdup(buf);
218 gmx_fatal(FARGS, "no $GMX_QM_GAUSS_EXE set, check gaussian manual\n");
220 buf = getenv("GMX_QM_MODIFIED_LINKS_DIR");
223 qm->devel_dir = gmx_strdup (buf);
227 gmx_fatal(FARGS, "no $GMX_QM_MODIFIED_LINKS_DIR, this is were the modified links reside.\n");
231 /* reactionfield, file is needed using gaussian */
232 /* rffile=fopen("rf.dat","w");*/
233 /* fprintf(rffile,"%f %f\n",fr->epsilon_r,fr->rcoulomb/BOHR2NM);*/
237 fprintf(stderr, "gaussian initialised...\n");
242 void write_gaussian_SH_input(int step, gmx_bool swap,
243 t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
254 bSA = (qm->SAstep > 0);
256 out = fopen("input.com", "w");
257 /* write the route */
258 fprintf(out, "%s", "%scr=input\n");
259 fprintf(out, "%s", "%rwf=input\n");
260 fprintf(out, "%s", "%int=input\n");
261 fprintf(out, "%s", "%d2e=input\n");
263 * fprintf(out,"%s","%nosave\n");
265 fprintf(out, "%s", "%chk=input\n");
266 fprintf(out, "%s%d\n", "%mem=", qm->QMmem);
267 fprintf(out, "%s%3d\n", "%nprocshare=", qm->nQMcpus);
269 /* use the versions of
270 * l301 that computes the interaction between MM and QM atoms.
271 * l510 that can punch the CI coefficients
272 * l701 that can do gradients on MM atoms
276 fprintf(out, "%s%s%s",
280 fprintf(out, "%s%s%s",
284 fprintf(out, "%s%s%s",
289 fprintf(out, "%s%s%s",
293 fprintf(out, "%s%s%s",
297 /* print the nonstandard route
300 "#P nonstd\n 1/18=10,20=1,38=1/1;\n");
302 " 2/9=110,15=1,17=6,18=5,40=1/2;\n");
306 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=1,94=-2/1,2,3;\n",
309 qm->SHbasis[2]); /*basisset stuff */
314 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=0,94=-2/1,2,3;\n",
317 qm->SHbasis[2]); /*basisset stuff */
320 if (step+1) /* fetch initial guess from check point file */
321 { /* hack, to alyays read from chk file!!!!! */
322 fprintf(out, "%s%d,%s%d%s", " 4/5=1,7=6,17=",
324 "18=", qm->CASorbitals, "/1,5;\n");
326 else /* generate the first checkpoint file */
328 fprintf(out, "%s%d,%s%d%s", " 4/5=0,7=6,17=",
330 "18=", qm->CASorbitals, "/1,5;\n");
332 /* the rest of the input depends on where the system is on the PES
334 if (swap && bSA) /* make a slide to the other surface */
336 if (qm->CASorbitals > 6) /* use direct and no full diag */
338 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6,97=100/10;\n");
344 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6,97=100/10;\n",
346 if (mm->nrMMatoms > 0)
348 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
350 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
351 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1,97=100/3;\n");
352 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
356 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6,97=100/10;\n",
358 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
362 else if (bSA) /* do a "state-averaged" CAS calculation */
364 if (qm->CASorbitals > 6) /* no full diag */
366 fprintf(out, " 5/5=2,16=-2,17=10000000,28=2,32=2,38=6/10;\n");
372 fprintf(out, " 5/5=2,6=%d,17=31000200,28=2,32=2,38=6/10;\n",
374 if (mm->nrMMatoms > 0)
376 fprintf(out, " 7/7=1,16=-2,30=1/1;\n");
378 fprintf(out, " 11/31=1,42=1,45=1/1;\n");
379 fprintf(out, " 10/6=1,10=700006,28=2,29=1,31=1/3;\n");
380 fprintf(out, " 7/30=1/16;\n 99/10=4/99;\n");
384 fprintf(out, " 5/5=2,6=%d,17=11000000,28=2,32=2,38=6/10;\n",
386 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
390 else if (swap) /* do a "swapped" CAS calculation */
392 if (qm->CASorbitals > 6)
394 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6,97=100/10;\n");
398 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6,97=100/10;\n",
401 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
403 else /* do a "normal" CAS calculation */
405 if (qm->CASorbitals > 6)
407 fprintf(out, " 5/5=2,16=-2,17=0,28=2,32=2,38=6/10;\n");
411 fprintf(out, " 5/5=2,6=%d,17=1000000,28=2,32=2,38=6/10;\n",
414 fprintf(out, " 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
416 fprintf(out, "\ninput-file generated by gromacs\n\n");
417 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
418 for (i = 0; i < qm->nrQMatoms; i++)
421 fprintf(out, "%3d %10.7lf %10.7lf %10.7lf\n",
422 qm->atomicnumberQM[i],
423 qm->xQM[i][XX]/BOHR2NM,
424 qm->xQM[i][YY]/BOHR2NM,
425 qm->xQM[i][ZZ]/BOHR2NM);
427 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
428 qm->atomicnumberQM[i],
429 qm->xQM[i][XX]/BOHR2NM,
430 qm->xQM[i][YY]/BOHR2NM,
431 qm->xQM[i][ZZ]/BOHR2NM);
434 /* MM point charge data */
435 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
438 for (i = 0; i < mm->nrMMatoms; i++)
441 fprintf(out, "%10.7lf %10.7lf %10.7lf %8.4lf\n",
442 mm->xMM[i][XX]/BOHR2NM,
443 mm->xMM[i][YY]/BOHR2NM,
444 mm->xMM[i][ZZ]/BOHR2NM,
447 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
448 mm->xMM[i][XX]/BOHR2NM,
449 mm->xMM[i][YY]/BOHR2NM,
450 mm->xMM[i][ZZ]/BOHR2NM,
455 if (bSA) /* put the SA coefficients at the end of the file */
458 fprintf(out, "\n%10.8lf %10.8lf\n",
459 qm->SAstep*0.5/qm->SAsteps,
460 1-qm->SAstep*0.5/qm->SAsteps);
462 fprintf(out, "\n%10.8f %10.8f\n",
463 qm->SAstep*0.5/qm->SAsteps,
464 1-qm->SAstep*0.5/qm->SAsteps);
466 fprintf(stderr, "State Averaging level = %d/%d\n", qm->SAstep, qm->SAsteps);
470 } /* write_gaussian_SH_input */
472 void write_gaussian_input(int step, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
482 out = fopen("input.com", "w");
483 /* write the route */
485 if (qm->QMmethod >= eQMmethodRHF)
497 fprintf(out, "%s%3d\n",
498 "%nprocshare=", qm->nQMcpus);
500 fprintf(out, "%s%d\n",
502 /* use the modified links that include the LJ contribution at the QM level */
503 if (qm->bTS || qm->bOPT)
505 fprintf(out, "%s%s%s",
506 "%subst l701 ", qm->devel_dir, "/l701_LJ\n");
507 fprintf(out, "%s%s%s",
508 "%subst l301 ", qm->devel_dir, "/l301_LJ\n");
512 fprintf(out, "%s%s%s",
513 "%subst l701 ", qm->devel_dir, "/l701\n");
514 fprintf(out, "%s%s%s",
515 "%subst l301 ", qm->devel_dir, "/l301\n");
517 fprintf(out, "%s%s%s",
518 "%subst l9999 ", qm->devel_dir, "/l9999\n");
529 if (qm->QMmethod == eQMmethodB3LYPLAN)
532 "B3LYP/GEN Pseudo=Read");
537 eQMmethod_names[qm->QMmethod]);
539 if (qm->QMmethod >= eQMmethodRHF)
541 if (qm->QMmethod == eQMmethodCASSCF)
543 /* in case of cas, how many electrons and orbitals do we need?
545 fprintf(out, "(%d,%d)",
546 qm->CASelectrons, qm->CASorbitals);
549 eQMbasis_names[qm->QMbasis]);
552 if (QMMMrec->QMMMscheme == eQMMMschemenormal && mm->nrMMatoms)
557 if (step || qm->QMmethod == eQMmethodCASSCF)
559 /* fetch guess from checkpoint file, always for CASSCF */
560 fprintf(out, "%s", " guess=read");
562 fprintf(out, "\nNosymm units=bohr\n");
566 fprintf(out, "OPT=(Redundant,TS,noeigentest,ModRedundant) Punch=(Coord,Derivatives) ");
570 fprintf(out, "OPT=(Redundant,ModRedundant) Punch=(Coord,Derivatives) ");
574 fprintf(out, "FORCE Punch=(Derivatives) ");
576 fprintf(out, "iop(3/33=1)\n\n");
577 fprintf(out, "input-file generated by gromacs\n\n");
578 fprintf(out, "%2d%2d\n", qm->QMcharge, qm->multiplicity);
579 for (i = 0; i < qm->nrQMatoms; i++)
582 fprintf(out, "%3d %10.7lf %10.7lf %10.7lf\n",
583 qm->atomicnumberQM[i],
584 qm->xQM[i][XX]/BOHR2NM,
585 qm->xQM[i][YY]/BOHR2NM,
586 qm->xQM[i][ZZ]/BOHR2NM);
588 fprintf(out, "%3d %10.7f %10.7f %10.7f\n",
589 qm->atomicnumberQM[i],
590 qm->xQM[i][XX]/BOHR2NM,
591 qm->xQM[i][YY]/BOHR2NM,
592 qm->xQM[i][ZZ]/BOHR2NM);
596 /* Pseudo Potential and ECP are included here if selected (MEthod suffix LAN) */
597 if (qm->QMmethod == eQMmethodB3LYPLAN)
600 for (i = 0; i < qm->nrQMatoms; i++)
602 if (qm->atomicnumberQM[i] < 21)
604 fprintf(out, "%d ", i+1);
607 fprintf(out, "\n%s\n****\n", eQMbasis_names[qm->QMbasis]);
609 for (i = 0; i < qm->nrQMatoms; i++)
611 if (qm->atomicnumberQM[i] > 21)
613 fprintf(out, "%d ", i+1);
616 fprintf(out, "\n%s\n****\n\n", "lanl2dz");
618 for (i = 0; i < qm->nrQMatoms; i++)
620 if (qm->atomicnumberQM[i] > 21)
622 fprintf(out, "%d ", i+1);
625 fprintf(out, "\n%s\n", "lanl2dz");
630 /* MM point charge data */
631 if (QMMMrec->QMMMscheme != eQMMMschemeoniom && mm->nrMMatoms)
633 fprintf(stderr, "nr mm atoms in gaussian.c = %d\n", mm->nrMMatoms);
635 if (qm->bTS || qm->bOPT)
637 /* freeze the frontier QM atoms and Link atoms. This is
638 * important only if a full QM subsystem optimization is done
639 * with a frozen MM environmeent. For dynamics, or gromacs's own
640 * optimization routines this is not important.
642 for (i = 0; i < qm->nrQMatoms; i++)
644 if (qm->frontatoms[i])
646 fprintf(out, "%d F\n", i+1); /* counting from 1 */
649 /* MM point charges include LJ parameters in case of QM optimization
651 for (i = 0; i < mm->nrMMatoms; i++)
654 fprintf(out, "%10.7lf %10.7lf %10.7lf %8.4lf 0.0 %10.7lf %10.7lf\n",
655 mm->xMM[i][XX]/BOHR2NM,
656 mm->xMM[i][YY]/BOHR2NM,
657 mm->xMM[i][ZZ]/BOHR2NM,
659 mm->c6[i], mm->c12[i]);
661 fprintf(out, "%10.7f %10.7f %10.7f %8.4f 0.0 %10.7f %10.7f\n",
662 mm->xMM[i][XX]/BOHR2NM,
663 mm->xMM[i][YY]/BOHR2NM,
664 mm->xMM[i][ZZ]/BOHR2NM,
666 mm->c6[i], mm->c12[i]);
673 for (i = 0; i < mm->nrMMatoms; i++)
676 fprintf(out, "%10.7lf %10.7lf %10.7lf %8.4lf\n",
677 mm->xMM[i][XX]/BOHR2NM,
678 mm->xMM[i][YY]/BOHR2NM,
679 mm->xMM[i][ZZ]/BOHR2NM,
682 fprintf(out, "%10.7f %10.7f %10.7f %8.4f\n",
683 mm->xMM[i][XX]/BOHR2NM,
684 mm->xMM[i][YY]/BOHR2NM,
685 mm->xMM[i][ZZ]/BOHR2NM,
696 } /* write_gaussian_input */
698 real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], int step,
699 t_QMrec *qm, t_MMrec *mm)
710 in = fopen("fort.7", "r");
714 /* in case of an optimization, the coordinates are printed in the
715 * fort.7 file first, followed by the energy, coordinates and (if
716 * required) the CI eigenvectors.
718 if (qm->bTS || qm->bOPT)
720 for (i = 0; i < qm->nrQMatoms; i++)
722 if (NULL == fgets(buf, 300, in))
724 gmx_fatal(FARGS, "Error reading Gaussian output - not enough atom lines?");
728 sscanf(buf, "%d %lf %lf %lf\n",
734 sscanf(buf, "%d %f %f %f\n",
740 for (j = 0; j < DIM; j++)
742 qm->xQM[i][j] *= BOHR2NM;
746 /* the next line is the energy and in the case of CAS, the energy
747 * difference between the two states.
749 if (NULL == fgets(buf, 300, in))
751 gmx_fatal(FARGS, "Error reading Gaussian output");
755 sscanf(buf, "%lf\n", &QMener);
757 sscanf(buf, "%f\n", &QMener);
759 /* next lines contain the gradients of the QM atoms */
760 for (i = 0; i < qm->nrQMatoms; i++)
762 if (NULL == fgets(buf, 300, in))
764 gmx_fatal(FARGS, "Error reading Gaussian output");
767 sscanf(buf, "%lf %lf %lf\n",
772 sscanf(buf, "%f %f %f\n",
778 /* the next lines are the gradients of the MM atoms */
779 if (qm->QMmethod >= eQMmethodRHF)
781 for (i = 0; i < mm->nrMMatoms; i++)
783 if (NULL == fgets(buf, 300, in))
785 gmx_fatal(FARGS, "Error reading Gaussian output");
788 sscanf(buf, "%lf %lf %lf\n",
793 sscanf(buf, "%f %f %f\n",
804 real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step,
805 gmx_bool swapped, t_QMrec *qm, t_MMrec *mm)
816 in = fopen("fort.7", "r");
817 /* first line is the energy and in the case of CAS, the energy
818 * difference between the two states.
820 if (NULL == fgets(buf, 300, in))
822 gmx_fatal(FARGS, "Error reading Gaussian output");
826 sscanf(buf, "%lf %lf\n", &QMener, &DeltaE);
828 sscanf(buf, "%f %f\n", &QMener, &DeltaE);
831 /* switch on/off the State Averaging */
833 if (DeltaE > qm->SAoff)
840 else if (DeltaE < qm->SAon || (qm->SAstep > 0))
842 if (qm->SAstep < qm->SAsteps)
849 fprintf(stderr, "Gap = %5f,SA = %3d\n", DeltaE, (qm->SAstep > 0));
850 /* next lines contain the gradients of the QM atoms */
851 for (i = 0; i < qm->nrQMatoms; i++)
853 if (NULL == fgets(buf, 300, in))
855 gmx_fatal(FARGS, "Error reading Gaussian output");
859 sscanf(buf, "%lf %lf %lf\n",
864 sscanf(buf, "%f %f %f\n",
870 /* the next lines, are the gradients of the MM atoms */
872 for (i = 0; i < mm->nrMMatoms; i++)
874 if (NULL == fgets(buf, 300, in))
876 gmx_fatal(FARGS, "Error reading Gaussian output");
879 sscanf(buf, "%lf %lf %lf\n",
884 sscanf(buf, "%f %f %f\n",
891 /* the next line contains the two CI eigenvector elements */
892 if (NULL == fgets(buf, 300, in))
894 gmx_fatal(FARGS, "Error reading Gaussian output");
898 sscanf(buf, "%d", &qm->CIdim);
899 snew(qm->CIvec1, qm->CIdim);
900 snew(qm->CIvec1old, qm->CIdim);
901 snew(qm->CIvec2, qm->CIdim);
902 snew(qm->CIvec2old, qm->CIdim);
906 /* before reading in the new current CI vectors, copy the current
907 * CI vector into the old one.
909 for (i = 0; i < qm->CIdim; i++)
911 qm->CIvec1old[i] = qm->CIvec1[i];
912 qm->CIvec2old[i] = qm->CIvec2[i];
916 for (i = 0; i < qm->CIdim; i++)
918 if (NULL == fgets(buf, 300, in))
920 gmx_fatal(FARGS, "Error reading Gaussian output");
923 sscanf(buf, "%lf\n", &qm->CIvec1[i]);
925 sscanf(buf, "%f\n", &qm->CIvec1[i]);
929 for (i = 0; i < qm->CIdim; i++)
931 if (NULL == fgets(buf, 300, in))
933 gmx_fatal(FARGS, "Error reading Gaussian output");
936 sscanf(buf, "%lf\n", &qm->CIvec2[i]);
938 sscanf(buf, "%f\n", &qm->CIvec2[i]);
945 real inproduct(real *a, real *b, int n)
952 /* computes the inner product between two vectors (a.b), both of
953 * which have length n.
955 for (i = 0; i < n; i++)
962 int hop(int step, t_QMrec *qm)
967 d11 = 0.0, d12 = 0.0, d21 = 0.0, d22 = 0.0;
969 /* calculates the inproduct between the current Ci vector and the
970 * previous CI vector. A diabatic hop will be made if d12 and d21
971 * are much bigger than d11 and d22. In that case hop returns true,
972 * otherwise it returns false.
974 if (step) /* only go on if more than one step has been done */
976 d11 = inproduct(qm->CIvec1, qm->CIvec1old, qm->CIdim);
977 d12 = inproduct(qm->CIvec1, qm->CIvec2old, qm->CIdim);
978 d21 = inproduct(qm->CIvec2, qm->CIvec1old, qm->CIdim);
979 d22 = inproduct(qm->CIvec2, qm->CIvec2old, qm->CIdim);
981 fprintf(stderr, "-------------------\n");
982 fprintf(stderr, "d11 = %13.8f\n", d11);
983 fprintf(stderr, "d12 = %13.8f\n", d12);
984 fprintf(stderr, "d21 = %13.8f\n", d21);
985 fprintf(stderr, "d22 = %13.8f\n", d22);
986 fprintf(stderr, "-------------------\n");
988 if ((fabs(d12) > 0.5) && (fabs(d21) > 0.5))
996 void do_gaussian(int step, char *exe)
1001 /* make the call to the gaussian binary through system()
1002 * The location of the binary will be picked up from the
1003 * environment using getenv().
1005 if (step) /* hack to prevent long inputfiles */
1007 sprintf(buf, "%s < %s > %s",
1014 sprintf(buf, "%s < %s > %s",
1019 fprintf(stderr, "Calling '%s'\n", buf);
1020 #ifdef GMX_NO_SYSTEM
1021 printf("Warning-- No calls to system(3) supported on this platform.");
1022 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
1024 if (system(buf) != 0)
1026 gmx_fatal(FARGS, "Call to '%s' failed\n", buf);
1031 real call_gaussian(t_commrec *cr, t_forcerec *fr,
1032 t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
1034 /* normal gaussian jobs */
1047 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
1048 snew(QMgrad, qm->nrQMatoms);
1049 snew(MMgrad, mm->nrMMatoms);
1051 write_gaussian_input(step, fr, qm, mm);
1052 do_gaussian(step, exe);
1053 QMener = read_gaussian_output(QMgrad, MMgrad, step, qm, mm);
1054 /* put the QMMM forces in the force array and to the fshift
1056 for (i = 0; i < qm->nrQMatoms; i++)
1058 for (j = 0; j < DIM; j++)
1060 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1061 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1064 for (i = 0; i < mm->nrMMatoms; i++)
1066 for (j = 0; j < DIM; j++)
1068 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1069 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1072 QMener = QMener*HARTREE2KJ*AVOGADRO;
1077 } /* call_gaussian */
1079 real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
1080 rvec f[], rvec fshift[])
1082 /* a gaussian call routine intended for doing diabatic surface
1083 * "sliding". See the manual for the theoretical background of this
1093 swapped = FALSE; /* handle for identifying the current PES */
1095 swap = FALSE; /* the actual swap */
1104 sprintf(exe, "%s/%s", qm->gauss_dir, qm->gauss_exe);
1105 /* hack to do ground state simulations */
1109 buf = getenv("GMX_QM_GROUND_STATE");
1112 sscanf(buf, "%d", &state);
1126 /* copy the QMMMrec pointer */
1127 snew(QMgrad, qm->nrQMatoms);
1128 snew(MMgrad, mm->nrMMatoms);
1129 /* at step 0 there should be no SA */
1132 /* temporray set to step + 1, since there is a chk start */
1133 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1135 do_gaussian(step, exe);
1136 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, swapped, qm, mm);
1138 /* check for a surface hop. Only possible if we were already state
1145 swap = (step && hop(step, qm));
1148 else /* already on the other surface, so check if we go back */
1150 swap = (step && hop(step, qm));
1151 swapped = !swap; /* so swapped shoud be false again */
1153 if (swap) /* change surface, so do another call */
1155 write_gaussian_SH_input(step, swapped, fr, qm, mm);
1156 do_gaussian(step, exe);
1157 QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, swapped, qm, mm);
1160 /* add the QMMM forces to the gmx force array and fshift
1162 for (i = 0; i < qm->nrQMatoms; i++)
1164 for (j = 0; j < DIM; j++)
1166 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1167 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1170 for (i = 0; i < mm->nrMMatoms; i++)
1172 for (j = 0; j < DIM; j++)
1174 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1175 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1178 QMener = QMener*HARTREE2KJ*AVOGADRO;
1179 fprintf(stderr, "step %5d, SA = %5d, swap = %5d\n",
1180 step, (qm->SAstep > 0), swapped);
1185 } /* call_gaussian_SH */
1187 /* end of gaussian sub routines */
1191 gmx_qmmm_gaussian_empty;