Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / mdlib / qm_mopac.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #include "config.h"
38
39 #ifdef GMX_QMMM_MOPAC
40
41 #include <math.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45
46 #include "typedefs.h"
47 #include "macros.h"
48 #include "gromacs/utility/smalloc.h"
49 #include "gromacs/math/units.h"
50 #include "gromacs/math/vec.h"
51 #include "force.h"
52 #include "gromacs/fileio/confio.h"
53 #include "names.h"
54 #include "network.h"
55 #include "ns.h"
56 #include "nrnb.h"
57 #include "bondf.h"
58 #include "txtdump.h"
59 #include "qmmm.h"
60 #include "gromacs/utility/fatalerror.h"
61
62
63 /* mopac interface routines */
64 void
65 F77_FUNC(domldt, DOMLDT) (int *nrqmat, int labels[], char keywords[]);
66
67 void
68 F77_FUNC(domop, DOMOP) (int *nrqmat, double qmcrd[], int *nrmmat,
69                         double mmchrg[], double mmcrd[], double qmgrad[],
70                         double mmgrad[], double *energy, double qmcharges[]);
71
72
73
74 void init_mopac(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
75 {
76     /* initializes the mopac routines ans sets up the semiempirical
77      * computation by calling moldat(). The inline mopac routines can
78      * only perform gradient operations. If one would like to optimize a
79      * structure or find a transition state at PM3 level, gaussian is
80      * used instead.
81      */
82     char
83     *keywords;
84
85     snew(keywords, 240);
86
87     if (!qm->bSH)  /* if rerun then grad should not be done! */
88     {
89         sprintf(keywords, "PRECISE GEO-OK CHARGE=%d GRAD MMOK ANALYT %s\n",
90                 qm->QMcharge,
91                 eQMmethod_names[qm->QMmethod]);
92     }
93     else
94     {
95         sprintf(keywords, "PRECISE GEO-OK CHARGE=%d SINGLET GRAD %s C.I.=(%d,%d) root=2 MECI \n",
96                 qm->QMcharge,
97                 eQMmethod_names[qm->QMmethod],
98                 qm->CASorbitals, qm->CASelectrons/2);
99     }
100     F77_FUNC(domldt, DOMLDT) (&qm->nrQMatoms, qm->atomicnumberQM, keywords);
101     fprintf(stderr, "keywords are: %s\n", keywords);
102     free(keywords);
103
104 } /* init_mopac */
105
106 real call_mopac(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
107                 rvec f[], rvec fshift[])
108 {
109     /* do the actual QMMM calculation using directly linked mopac subroutines
110      */
111     double /* always double as the MOPAC routines are always compiled in
112               double precission! */
113     *qmcrd = NULL, *qmchrg = NULL, *mmcrd = NULL, *mmchrg = NULL,
114     *qmgrad, *mmgrad = NULL, energy;
115     int
116         i, j;
117     real
118         QMener = 0.0;
119     snew(qmcrd, 3*(qm->nrQMatoms));
120     snew(qmgrad, 3*(qm->nrQMatoms));
121     /* copy the data from qr into the arrays that are going to be used
122      * in the fortran routines of MOPAC
123      */
124     for (i = 0; i < qm->nrQMatoms; i++)
125     {
126         for (j = 0; j < DIM; j++)
127         {
128             qmcrd[3*i+j] = (double)qm->xQM[i][j]*10;
129         }
130     }
131     if (mm->nrMMatoms)
132     {
133         /* later we will add the point charges here. There are some
134          * conceptual problems with semi-empirical QM in combination with
135          * point charges that we need to solve first....
136          */
137         gmx_fatal(FARGS, "At present only ONIOM is allowed in combination"
138                   " with MOPAC QM subroutines\n");
139     }
140     else
141     {
142         /* now compute the energy and the gradients.
143          */
144
145         snew(qmchrg, qm->nrQMatoms);
146         F77_FUNC(domop, DOMOP) (&qm->nrQMatoms, qmcrd, &mm->nrMMatoms,
147                                 mmchrg, mmcrd, qmgrad, mmgrad, &energy, qmchrg);
148         /* add the gradients to the f[] array, and also to the fshift[].
149          * the mopac gradients are in kCal/angstrom.
150          */
151         for (i = 0; i < qm->nrQMatoms; i++)
152         {
153             for (j = 0; j < DIM; j++)
154             {
155                 f[i][j]       = (real)10*CAL2JOULE*qmgrad[3*i+j];
156                 fshift[i][j]  = (real)10*CAL2JOULE*qmgrad[3*i+j];
157             }
158         }
159         QMener = (real)CAL2JOULE*energy;
160         /* do we do something with the mulliken charges?? */
161
162         free(qmchrg);
163     }
164     free(qmgrad);
165     free(qmcrd);
166     return (QMener);
167 }
168
169 real call_mopac_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
170                    rvec f[], rvec fshift[])
171 {
172     /* do the actual SH QMMM calculation using directly linked mopac
173        subroutines */
174
175     double /* always double as the MOPAC routines are always compiled in
176               double precission! */
177     *qmcrd = NULL, *qmchrg = NULL, *mmcrd = NULL, *mmchrg = NULL,
178     *qmgrad, *mmgrad = NULL, energy;
179     int
180         i, j;
181     real
182         QMener = 0.0;
183
184     snew(qmcrd, 3*(qm->nrQMatoms));
185     snew(qmgrad, 3*(qm->nrQMatoms));
186     /* copy the data from qr into the arrays that are going to be used
187      * in the fortran routines of MOPAC
188      */
189     for (i = 0; i < qm->nrQMatoms; i++)
190     {
191         for (j = 0; j < DIM; j++)
192         {
193             qmcrd[3*i+j] = (double)qm->xQM[i][j]*10;
194         }
195     }
196     if (mm->nrMMatoms)
197     {
198         /* later we will add the point charges here. There are some
199          * conceptual problems with semi-empirical QM in combination with
200          * point charges that we need to solve first....
201          */
202         gmx_fatal(FARGS, "At present only ONIOM is allowed in combination with MOPAC\n");
203     }
204     else
205     {
206         /* now compute the energy and the gradients.
207          */
208         snew(qmchrg, qm->nrQMatoms);
209
210         F77_FUNC(domop, DOMOP) (&qm->nrQMatoms, qmcrd, &mm->nrMMatoms,
211                                 mmchrg, mmcrd, qmgrad, mmgrad, &energy, qmchrg);
212         /* add the gradients to the f[] array, and also to the fshift[].
213          * the mopac gradients are in kCal/angstrom.
214          */
215         for (i = 0; i < qm->nrQMatoms; i++)
216         {
217             for (j = 0; j < DIM; j++)
218             {
219                 f[i][j]      = (real)10*CAL2JOULE*qmgrad[3*i+j];
220                 fshift[i][j] = (real)10*CAL2JOULE*qmgrad[3*i+j];
221             }
222         }
223         QMener = (real)CAL2JOULE*energy;
224     }
225     free(qmgrad);
226     free(qmcrd);
227     return (QMener);
228 } /* call_mopac_SH */
229
230 #else
231 int
232     gmx_qmmm_mopac_empty;
233 #endif