3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * GROwing Monsters And Cloning Shrimps
39 #ifdef GMX_QMMM_GAUSSIAN
65 #include "gmx_fatal.h"
70 /* TODO: this should be made thread-safe */
72 /* Gaussian interface routines */
74 void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
77 *rffile=NULL,*out=NULL;
79 basissets[eQMbasisNR]={{0,3,0},
80 {0,3,0},/*added for double sto-3g entry in names.c*/
94 /* using the ivec above to convert the basis read form the mdp file
95 * in a human readable format into some numbers for the gaussian
96 * route. This is necessary as we are using non standard routes to
100 /* per layer we make a new subdir for integral file, checkpoint
101 * files and such. These dirs are stored in the QMrec for
106 if(!qm->nQMcpus){ /* this we do only once per layer
107 * as we call g01 externally
111 qm->SHbasis[i]=basissets[qm->QMbasis][i];
113 /* init gradually switching on of the SA */
115 /* we read the number of cpus and environment from the environment
118 buf = getenv("NCPUS");
120 sscanf(buf,"%d",&qm->nQMcpus);
123 fprintf(stderr,"number of CPUs for gaussian = %d\n",qm->nQMcpus);
126 sscanf(buf,"%d",&qm->QMmem);
129 fprintf(stderr,"memory for gaussian = %d\n",qm->QMmem);
132 sscanf(buf,"%d",&qm->accuracy);
135 fprintf(stderr,"accuracy in l510 = %d\n",qm->accuracy);
137 buf = getenv("CPMCSCF");
141 qm->cpmcscf = (i!=0);
146 fprintf(stderr,"using cp-mcscf in l1003\n");
148 fprintf(stderr,"NOT using cp-mcscf in l1003\n");
149 buf = getenv("SASTEP");
151 sscanf(buf,"%d",&qm->SAstep);
153 /* init gradually switching on of the SA */
155 /* we read the number of cpus and environment from the environment
158 fprintf(stderr,"Level of SA at start = %d\n",qm->SAstep);
159 /* punch the LJ C6 and C12 coefficients to be picked up by
160 * gaussian and usd to compute the LJ interaction between the
163 if(qm->bTS||qm->bOPT){
164 out = fopen("LJ.dat","w");
165 for(i=0;i<qm->nrQMatoms;i++){
168 fprintf(out,"%3d %10.7lf %10.7lf\n",
169 qm->atomicnumberQM[i],qm->c6[i],qm->c12[i]);
171 fprintf(out,"%3d %10.7f %10.7f\n",
172 qm->atomicnumberQM[i],qm->c6[i],qm->c12[i]);
177 /* gaussian settings on the system */
178 buf = getenv("GAUSS_DIR");
179 fprintf(stderr,"%s",buf);
182 qm->gauss_dir=strdup(buf);
185 gmx_fatal(FARGS,"no $GAUSS_DIR, check gaussian manual\n");
187 buf = getenv("GAUSS_EXE");
189 qm->gauss_exe=strdup(buf);
192 gmx_fatal(FARGS,"no $GAUSS_EXE, check gaussian manual\n");
193 buf = getenv("DEVEL_DIR");
195 qm->devel_dir = strdup (buf);
198 gmx_fatal(FARGS,"no $DEVEL_DIR, this is were the modified links reside.\n");
201 /* reactionfield, file is needed using gaussian */
202 /* rffile=fopen("rf.dat","w");*/
203 /* fprintf(rffile,"%f %f\n",fr->epsilon_r,fr->rcoulomb/BOHR2NM);*/
207 fprintf(stderr,"gaussian initialised...\n");
212 void write_gaussian_SH_input(int step,gmx_bool swap,
213 t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
224 bSA = (qm->SAstep>0);
226 out = fopen("input.com","w");
227 /* write the route */
228 fprintf(out,"%s","%scr=input\n");
229 fprintf(out,"%s","%rwf=input\n");
230 fprintf(out,"%s","%int=input\n");
231 fprintf(out,"%s","%d2e=input\n");
233 * fprintf(out,"%s","%nosave\n");
235 fprintf(out,"%s","%chk=input\n");
236 fprintf(out,"%s%d\n","%mem=",qm->QMmem);
237 fprintf(out,"%s%3d\n","%nprocshare=",qm->nQMcpus);
239 /* use the versions of
240 * l301 that computes the interaction between MM and QM atoms.
241 * l510 that can punch the CI coefficients
242 * l701 that can do gradients on MM atoms
246 fprintf(out,"%s%s%s",
250 fprintf(out,"%s%s%s",
254 fprintf(out,"%s%s%s",
259 fprintf(out,"%s%s%s",
263 fprintf(out,"%s%s%s",
267 /* print the nonstandard route
270 "#P nonstd\n 1/18=10,20=1,38=1/1;\n");
272 " 2/9=110,15=1,17=6,18=5,40=1/2;\n");
275 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=1,94=-2/1,2,3;\n",
278 qm->SHbasis[2]); /*basisset stuff */
281 " 3/5=%d,6=%d,7=%d,25=1,32=1,43=0,94=-2/1,2,3;\n",
284 qm->SHbasis[2]); /*basisset stuff */
286 if (step+1) /* fetch initial guess from check point file */
287 /* hack, to alyays read from chk file!!!!! */
288 fprintf(out,"%s%d,%s%d%s"," 4/5=1,7=6,17=",
290 "18=",qm->CASorbitals,"/1,5;\n");
291 else /* generate the first checkpoint file */
292 fprintf(out,"%s%d,%s%d%s"," 4/5=0,7=6,17=",
294 "18=",qm->CASorbitals,"/1,5;\n");
295 /* the rest of the input depends on where the system is on the PES
297 if(swap && bSA){ /* make a slide to the other surface */
298 if(qm->CASorbitals>6){ /* use direct and no full diag */
299 fprintf(out," 5/5=2,16=-2,17=10000000,28=2,32=2,38=6,97=100/10;\n");
303 fprintf(out," 5/5=2,6=%d,17=31000200,28=2,32=2,38=6,97=100/10;\n",
306 fprintf(out," 7/7=1,16=-2,30=1/1;\n");
307 fprintf(out," 11/31=1,42=1,45=1/1;\n");
308 fprintf(out," 10/6=1,10=700006,28=2,29=1,31=1,97=100/3;\n");
309 fprintf(out," 7/30=1/16;\n 99/10=4/99;\n");
312 fprintf(out," 5/5=2,6=%d,17=11000000,28=2,32=2,38=6,97=100/10;\n",
314 fprintf(out," 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
318 else if(bSA){ /* do a "state-averaged" CAS calculation */
319 if(qm->CASorbitals>6){ /* no full diag */
320 fprintf(out," 5/5=2,16=-2,17=10000000,28=2,32=2,38=6/10;\n");
324 fprintf(out," 5/5=2,6=%d,17=31000200,28=2,32=2,38=6/10;\n",
327 fprintf(out," 7/7=1,16=-2,30=1/1;\n");
328 fprintf(out," 11/31=1,42=1,45=1/1;\n");
329 fprintf(out," 10/6=1,10=700006,28=2,29=1,31=1/3;\n");
330 fprintf(out," 7/30=1/16;\n 99/10=4/99;\n");
333 fprintf(out," 5/5=2,6=%d,17=11000000,28=2,32=2,38=6/10;\n",
335 fprintf(out," 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
339 else if(swap){/* do a "swapped" CAS calculation */
340 if(qm->CASorbitals>6)
341 fprintf(out," 5/5=2,16=-2,17=0,28=2,32=2,38=6,97=100/10;\n");
343 fprintf(out," 5/5=2,6=%d,17=1000000,28=2,32=2,38=6,97=100/10;\n",
345 fprintf(out," 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
347 else {/* do a "normal" CAS calculation */
348 if(qm->CASorbitals>6)
349 fprintf(out," 5/5=2,16=-2,17=0,28=2,32=2,38=6/10;\n");
351 fprintf(out," 5/5=2,6=%d,17=1000000,28=2,32=2,38=6/10;\n",
353 fprintf(out," 7/7=1,16=-2,30=1/1,2,3,16;\n 99/10=4/99;\n");
355 fprintf(out, "\ninput-file generated by gromacs\n\n");
356 fprintf(out,"%2d%2d\n",qm->QMcharge,qm->multiplicity);
357 for (i=0;i<qm->nrQMatoms;i++){
359 fprintf(out,"%3d %10.7lf %10.7lf %10.7lf\n",
360 qm->atomicnumberQM[i],
361 qm->xQM[i][XX]/BOHR2NM,
362 qm->xQM[i][YY]/BOHR2NM,
363 qm->xQM[i][ZZ]/BOHR2NM);
365 fprintf(out,"%3d %10.7f %10.7f %10.7f\n",
366 qm->atomicnumberQM[i],
367 qm->xQM[i][XX]/BOHR2NM,
368 qm->xQM[i][YY]/BOHR2NM,
369 qm->xQM[i][ZZ]/BOHR2NM);
372 /* MM point charge data */
373 if(QMMMrec->QMMMscheme!=eQMMMschemeoniom && mm->nrMMatoms){
375 for(i=0;i<mm->nrMMatoms;i++){
377 fprintf(out,"%10.7lf %10.7lf %10.7lf %8.4lf\n",
378 mm->xMM[i][XX]/BOHR2NM,
379 mm->xMM[i][YY]/BOHR2NM,
380 mm->xMM[i][ZZ]/BOHR2NM,
383 fprintf(out,"%10.7f %10.7f %10.7f %8.4f\n",
384 mm->xMM[i][XX]/BOHR2NM,
385 mm->xMM[i][YY]/BOHR2NM,
386 mm->xMM[i][ZZ]/BOHR2NM,
391 if(bSA) {/* put the SA coefficients at the end of the file */
393 fprintf(out,"\n%10.8lf %10.8lf\n",
394 qm->SAstep*0.5/qm->SAsteps,
395 1-qm->SAstep*0.5/qm->SAsteps);
397 fprintf(out,"\n%10.8f %10.8f\n",
398 qm->SAstep*0.5/qm->SAsteps,
399 1-qm->SAstep*0.5/qm->SAsteps);
401 fprintf(stderr,"State Averaging level = %d/%d\n",qm->SAstep,qm->SAsteps);
405 } /* write_gaussian_SH_input */
407 void write_gaussian_input(int step ,t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
417 out = fopen("input.com","w");
418 /* write the route */
420 if(qm->QMmethod>=eQMmethodRHF)
427 fprintf(out,"%s%3d\n",
428 "%nprocshare=",qm->nQMcpus);
429 fprintf(out,"%s%d\n",
431 /* use the modified links that include the LJ contribution at the QM level */
432 if(qm->bTS||qm->bOPT){
433 fprintf(out,"%s%s%s",
434 "%subst l701 ",qm->devel_dir,"/l701_LJ\n");
435 fprintf(out,"%s%s%s",
436 "%subst l301 ",qm->devel_dir,"/l301_LJ\n");
439 fprintf(out,"%s%s%s",
440 "%subst l701 ",qm->devel_dir,"/l701\n");
441 fprintf(out,"%s%s%s",
442 "%subst l301 ",qm->devel_dir,"/l301\n");
444 fprintf(out,"%s%s%s",
445 "%subst l9999 ",qm->devel_dir,"/l9999\n");
453 if(qm->QMmethod==eQMmethodB3LYPLAN){
455 "B3LYP/GEN Pseudo=Read");
459 eQMmethod_names[qm->QMmethod]);
461 if(qm->QMmethod>=eQMmethodRHF){
462 if(qm->QMmethod==eQMmethodCASSCF){
463 /* in case of cas, how many electrons and orbitals do we need?
465 fprintf(out,"(%d,%d)",
466 qm->CASelectrons,qm->CASorbitals);
469 eQMbasis_names[qm->QMbasis]);
472 if(QMMMrec->QMMMscheme==eQMMMschemenormal && mm->nrMMatoms){
476 if (step || qm->QMmethod==eQMmethodCASSCF){
477 /* fetch guess from checkpoint file, always for CASSCF */
478 fprintf(out,"%s"," guess=read");
480 fprintf(out,"\nNosymm units=bohr\n");
483 fprintf(out,"OPT=(Redundant,TS,noeigentest,ModRedundant) Punch=(Coord,Derivatives) ");
486 fprintf(out,"OPT=(Redundant,ModRedundant) Punch=(Coord,Derivatives) ");
489 fprintf(out,"FORCE Punch=(Derivatives) ");
491 fprintf(out,"iop(3/33=1)\n\n");
492 fprintf(out, "input-file generated by gromacs\n\n");
493 fprintf(out,"%2d%2d\n",qm->QMcharge,qm->multiplicity);
494 for (i=0;i<qm->nrQMatoms;i++){
496 fprintf(out,"%3d %10.7lf %10.7lf %10.7lf\n",
497 qm->atomicnumberQM[i],
498 qm->xQM[i][XX]/BOHR2NM,
499 qm->xQM[i][YY]/BOHR2NM,
500 qm->xQM[i][ZZ]/BOHR2NM);
502 fprintf(out,"%3d %10.7f %10.7f %10.7f\n",
503 qm->atomicnumberQM[i],
504 qm->xQM[i][XX]/BOHR2NM,
505 qm->xQM[i][YY]/BOHR2NM,
506 qm->xQM[i][ZZ]/BOHR2NM);
510 /* Pseudo Potential and ECP are included here if selected (MEthod suffix LAN) */
511 if(qm->QMmethod==eQMmethodB3LYPLAN){
513 for(i=0;i<qm->nrQMatoms;i++){
514 if(qm->atomicnumberQM[i]<21){
515 fprintf(out,"%d ",i+1);
518 fprintf(out,"\n%s\n****\n",eQMbasis_names[qm->QMbasis]);
520 for(i=0;i<qm->nrQMatoms;i++){
521 if(qm->atomicnumberQM[i]>21){
522 fprintf(out,"%d ",i+1);
525 fprintf(out,"\n%s\n****\n\n","lanl2dz");
527 for(i=0;i<qm->nrQMatoms;i++){
528 if(qm->atomicnumberQM[i]>21){
529 fprintf(out,"%d ",i+1);
532 fprintf(out,"\n%s\n","lanl2dz");
537 /* MM point charge data */
538 if(QMMMrec->QMMMscheme!=eQMMMschemeoniom && mm->nrMMatoms){
539 fprintf(stderr,"nr mm atoms in gaussian.c = %d\n",mm->nrMMatoms);
541 if(qm->bTS||qm->bOPT){
542 /* freeze the frontier QM atoms and Link atoms. This is
543 * important only if a full QM subsystem optimization is done
544 * with a frozen MM environmeent. For dynamics, or gromacs's own
545 * optimization routines this is not important.
547 for(i=0;i<qm->nrQMatoms;i++){
548 if(qm->frontatoms[i]){
549 fprintf(out,"%d F\n",i+1); /* counting from 1 */
552 /* MM point charges include LJ parameters in case of QM optimization
554 for(i=0;i<mm->nrMMatoms;i++){
556 fprintf(out,"%10.7lf %10.7lf %10.7lf %8.4lf 0.0 %10.7lf %10.7lf\n",
557 mm->xMM[i][XX]/BOHR2NM,
558 mm->xMM[i][YY]/BOHR2NM,
559 mm->xMM[i][ZZ]/BOHR2NM,
561 mm->c6[i],mm->c12[i]);
563 fprintf(out,"%10.7f %10.7f %10.7f %8.4f 0.0 %10.7f %10.7f\n",
564 mm->xMM[i][XX]/BOHR2NM,
565 mm->xMM[i][YY]/BOHR2NM,
566 mm->xMM[i][ZZ]/BOHR2NM,
568 mm->c6[i],mm->c12[i]);
574 for(i=0;i<mm->nrMMatoms;i++){
576 fprintf(out,"%10.7lf %10.7lf %10.7lf %8.4lf\n",
577 mm->xMM[i][XX]/BOHR2NM,
578 mm->xMM[i][YY]/BOHR2NM,
579 mm->xMM[i][ZZ]/BOHR2NM,
582 fprintf(out,"%10.7f %10.7f %10.7f %8.4f\n",
583 mm->xMM[i][XX]/BOHR2NM,
584 mm->xMM[i][YY]/BOHR2NM,
585 mm->xMM[i][ZZ]/BOHR2NM,
596 } /* write_gaussian_input */
598 real read_gaussian_output(rvec QMgrad[],rvec MMgrad[],int step,
599 t_QMrec *qm, t_MMrec *mm)
610 in=fopen("fort.7","r");
614 /* in case of an optimization, the coordinates are printed in the
615 * fort.7 file first, followed by the energy, coordinates and (if
616 * required) the CI eigenvectors.
618 if(qm->bTS||qm->bOPT){
619 for(i=0;i<qm->nrQMatoms;i++){
620 if( NULL == fgets(buf,300,in))
622 gmx_fatal(FARGS,"Error reading Gaussian output - not enough atom lines?");
626 sscanf(buf,"%d %lf %lf %lf\n",
632 sscanf(buf,"%d %f %f %f\n",
639 qm->xQM[i][j]*=BOHR2NM;
643 /* the next line is the energy and in the case of CAS, the energy
644 * difference between the two states.
646 if(NULL == fgets(buf,300,in))
648 gmx_fatal(FARGS,"Error reading Gaussian output");
652 sscanf(buf,"%lf\n",&QMener);
654 sscanf(buf,"%f\n", &QMener);
656 /* next lines contain the gradients of the QM atoms */
657 for(i=0;i<qm->nrQMatoms;i++){
658 if(NULL == fgets(buf,300,in))
660 gmx_fatal(FARGS,"Error reading Gaussian output");
663 sscanf(buf,"%lf %lf %lf\n",
668 sscanf(buf,"%f %f %f\n",
674 /* the next lines are the gradients of the MM atoms */
675 if(qm->QMmethod>=eQMmethodRHF){
676 for(i=0;i<mm->nrMMatoms;i++){
677 if(NULL==fgets(buf,300,in))
679 gmx_fatal(FARGS,"Error reading Gaussian output");
682 sscanf(buf,"%lf %lf %lf\n",
687 sscanf(buf,"%f %f %f\n",
698 real read_gaussian_SH_output(rvec QMgrad[],rvec MMgrad[],int step,
699 gmx_bool swapped,t_QMrec *qm, t_MMrec *mm)
710 in=fopen("fort.7","r");
711 /* first line is the energy and in the case of CAS, the energy
712 * difference between the two states.
714 if(NULL == fgets(buf,300,in))
716 gmx_fatal(FARGS,"Error reading Gaussian output");
720 sscanf(buf,"%lf %lf\n",&QMener,&DeltaE);
722 sscanf(buf,"%f %f\n", &QMener,&DeltaE);
725 /* switch on/off the State Averaging */
727 if(DeltaE > qm->SAoff){
732 else if (DeltaE < qm->SAon || (qm->SAstep > 0)){
733 if (qm->SAstep < qm->SAsteps){
739 fprintf(stderr,"Gap = %5f,SA = %3d\n",DeltaE,(qm->SAstep>0));
740 /* next lines contain the gradients of the QM atoms */
741 for(i=0;i<qm->nrQMatoms;i++){
742 if(NULL==fgets(buf,300,in))
744 gmx_fatal(FARGS,"Error reading Gaussian output");
748 sscanf(buf,"%lf %lf %lf\n",
753 sscanf(buf,"%f %f %f\n",
759 /* the next lines, are the gradients of the MM atoms */
761 for(i=0;i<mm->nrMMatoms;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",
779 /* the next line contains the two CI eigenvector elements */
780 if(NULL==fgets(buf,300,in))
782 gmx_fatal(FARGS,"Error reading Gaussian output");
785 sscanf(buf,"%d",&qm->CIdim);
786 snew(qm->CIvec1,qm->CIdim);
787 snew(qm->CIvec1old,qm->CIdim);
788 snew(qm->CIvec2,qm->CIdim);
789 snew(qm->CIvec2old,qm->CIdim);
791 /* before reading in the new current CI vectors, copy the current
792 * CI vector into the old one.
794 for(i=0;i<qm->CIdim;i++){
795 qm->CIvec1old[i] = qm->CIvec1[i];
796 qm->CIvec2old[i] = qm->CIvec2[i];
800 for(i=0;i<qm->CIdim;i++){
801 if(NULL==fgets(buf,300,in))
803 gmx_fatal(FARGS,"Error reading Gaussian output");
806 sscanf(buf,"%lf\n",&qm->CIvec1[i]);
808 sscanf(buf,"%f\n", &qm->CIvec1[i]);
812 for(i=0;i<qm->CIdim;i++){
813 if(NULL==fgets(buf,300,in))
815 gmx_fatal(FARGS,"Error reading Gaussian output");
818 sscanf(buf,"%lf\n",&qm->CIvec2[i]);
820 sscanf(buf,"%f\n", &qm->CIvec2[i]);
827 real inproduct(real *a, real *b, int n)
834 /* computes the inner product between two vectors (a.b), both of
835 * which have length n.
843 int hop(int step, t_QMrec *qm)
848 d11=0.0,d12=0.0,d21=0.0,d22=0.0;
850 /* calculates the inproduct between the current Ci vector and the
851 * previous CI vector. A diabatic hop will be made if d12 and d21
852 * are much bigger than d11 and d22. In that case hop returns true,
853 * otherwise it returns false.
855 if(step){ /* only go on if more than one step has been done */
856 d11 = inproduct(qm->CIvec1,qm->CIvec1old,qm->CIdim);
857 d12 = inproduct(qm->CIvec1,qm->CIvec2old,qm->CIdim);
858 d21 = inproduct(qm->CIvec2,qm->CIvec1old,qm->CIdim);
859 d22 = inproduct(qm->CIvec2,qm->CIvec2old,qm->CIdim);
861 fprintf(stderr,"-------------------\n");
862 fprintf(stderr,"d11 = %13.8f\n",d11);
863 fprintf(stderr,"d12 = %13.8f\n",d12);
864 fprintf(stderr,"d21 = %13.8f\n",d21);
865 fprintf(stderr,"d22 = %13.8f\n",d22);
866 fprintf(stderr,"-------------------\n");
868 if((fabs(d12)>0.5)&&(fabs(d21)>0.5))
874 void do_gaussian(int step,char *exe)
879 /* make the call to the gaussian binary through system()
880 * The location of the binary will be picked up from the
881 * environment using getenv().
883 if(step) /* hack to prevent long inputfiles */
884 sprintf(buf,"%s < %s > %s",
889 sprintf(buf,"%s < %s > %s",
893 fprintf(stderr,"Calling '%s'\n",buf);
895 printf("Warning-- No calls to system(3) supported on this platform.");
896 gmx_fatal(FARGS,"Call to '%s' failed\n",buf);
898 if ( system(buf) != 0 )
899 gmx_fatal(FARGS,"Call to '%s' failed\n",buf);
903 real call_gaussian(t_commrec *cr, t_forcerec *fr,
904 t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
906 /* normal gaussian jobs */
919 sprintf(exe,"%s/%s",qm->gauss_dir,qm->gauss_exe);
920 snew(QMgrad,qm->nrQMatoms);
921 snew(MMgrad,mm->nrMMatoms);
923 write_gaussian_input(step,fr,qm,mm);
924 do_gaussian(step,exe);
925 QMener = read_gaussian_output(QMgrad,MMgrad,step,qm,mm);
926 /* put the QMMM forces in the force array and to the fshift
928 for(i=0;i<qm->nrQMatoms;i++){
930 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
931 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
934 for(i=0;i<mm->nrMMatoms;i++){
936 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
937 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
940 QMener = QMener*HARTREE2KJ*AVOGADRO;
945 } /* call_gaussian */
947 real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
948 rvec f[], rvec fshift[])
950 /* a gaussian call routine intended for doing diabatic surface
951 * "sliding". See the manual for the theoretical background of this
961 swapped=FALSE; /* handle for identifying the current PES */
963 swap=FALSE; /* the actual swap */
972 sprintf(exe,"%s/%s",qm->gauss_dir,qm->gauss_exe);
973 /* hack to do ground state simulations */
976 buf = getenv("STATE");
978 sscanf(buf,"%d",&state);
987 /* copy the QMMMrec pointer */
988 snew(QMgrad,qm->nrQMatoms);
989 snew(MMgrad,mm->nrMMatoms);
990 /* at step 0 there should be no SA */
993 /* temporray set to step + 1, since there is a chk start */
994 write_gaussian_SH_input(step,swapped,fr,qm,mm);
996 do_gaussian(step,exe);
997 QMener = read_gaussian_SH_output(QMgrad,MMgrad,step,swapped,qm,mm);
999 /* check for a surface hop. Only possible if we were already state
1004 swap = (step && hop(step,qm));
1007 else { /* already on the other surface, so check if we go back */
1008 swap = (step && hop(step,qm));
1009 swapped =!swap; /* so swapped shoud be false again */
1011 if (swap){/* change surface, so do another call */
1012 write_gaussian_SH_input(step,swapped,fr,qm,mm);
1013 do_gaussian(step,exe);
1014 QMener = read_gaussian_SH_output(QMgrad,MMgrad,step,swapped,qm,mm);
1017 /* add the QMMM forces to the gmx force array and fshift
1019 for(i=0;i<qm->nrQMatoms;i++){
1021 f[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1022 fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
1025 for(i=0;i<mm->nrMMatoms;i++){
1027 f[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1028 fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
1031 QMener = QMener*HARTREE2KJ*AVOGADRO;
1032 fprintf(stderr,"step %5d, SA = %5d, swap = %5d\n",
1033 step,(qm->SAstep>0),swapped);
1038 } /* call_gaussian_SH */
1040 /* end of gaussian sub routines */
1044 gmx_qmmm_gaussian_empty;