Move main.*, splitter.*, gmx_omp_nthreads.* to mdlib
[gromacs.git] / src / gromacs / mdlib / qm_mopac.cpp
blob525fcc02380a616ce9039d5b0594a04dd4c68800
1 /*
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.
37 #include "gmxpre.h"
39 #include "config.h"
41 #if GMX_QMMM_MOPAC
43 #include <math.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
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/fatalerror.h"
58 #include "gromacs/utility/smalloc.h"
61 /* mopac interface routines */
62 void
63 F77_FUNC(domldt, DOMLDT) (int *nrqmat, int labels[], char keywords[]);
65 void
66 F77_FUNC(domop, DOMOP) (int *nrqmat, double qmcrd[], int *nrmmat,
67 double mmchrg[], double mmcrd[], double qmgrad[],
68 double mmgrad[], double *energy, double qmcharges[]);
72 void init_mopac(t_QMrec *qm)
74 /* initializes the mopac routines ans sets up the semiempirical
75 * computation by calling moldat(). The inline mopac routines can
76 * only perform gradient operations. If one would like to optimize a
77 * structure or find a transition state at PM3 level, gaussian is
78 * used instead.
80 char
81 *keywords;
83 snew(keywords, 240);
85 if (!qm->bSH) /* if rerun then grad should not be done! */
87 sprintf(keywords, "PRECISE GEO-OK CHARGE=%d GRAD MMOK ANALYT %s\n",
88 qm->QMcharge,
89 eQMmethod_names[qm->QMmethod]);
91 else
93 sprintf(keywords, "PRECISE GEO-OK CHARGE=%d SINGLET GRAD %s C.I.=(%d,%d) root=2 MECI \n",
94 qm->QMcharge,
95 eQMmethod_names[qm->QMmethod],
96 qm->CASorbitals, qm->CASelectrons/2);
98 F77_FUNC(domldt, DOMLDT) (&qm->nrQMatoms, qm->atomicnumberQM, keywords);
99 fprintf(stderr, "keywords are: %s\n", keywords);
100 free(keywords);
102 } /* init_mopac */
104 real call_mopac(t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
106 /* do the actual QMMM calculation using directly linked mopac subroutines
108 double /* always double as the MOPAC routines are always compiled in
109 double precission! */
110 *qmcrd = NULL, *qmchrg = NULL, *mmcrd = NULL, *mmchrg = NULL,
111 *qmgrad, *mmgrad = NULL, energy;
113 i, j;
114 real
115 QMener = 0.0;
116 snew(qmcrd, 3*(qm->nrQMatoms));
117 snew(qmgrad, 3*(qm->nrQMatoms));
118 /* copy the data from qr into the arrays that are going to be used
119 * in the fortran routines of MOPAC
121 for (i = 0; i < qm->nrQMatoms; i++)
123 for (j = 0; j < DIM; j++)
125 qmcrd[3*i+j] = (double)qm->xQM[i][j]*10;
128 if (mm->nrMMatoms)
130 /* later we will add the point charges here. There are some
131 * conceptual problems with semi-empirical QM in combination with
132 * point charges that we need to solve first....
134 gmx_fatal(FARGS, "At present only ONIOM is allowed in combination"
135 " with MOPAC QM subroutines\n");
137 else
139 /* now compute the energy and the gradients.
142 snew(qmchrg, qm->nrQMatoms);
143 F77_FUNC(domop, DOMOP) (&qm->nrQMatoms, qmcrd, &mm->nrMMatoms,
144 mmchrg, mmcrd, qmgrad, mmgrad, &energy, qmchrg);
145 /* add the gradients to the f[] array, and also to the fshift[].
146 * the mopac gradients are in kCal/angstrom.
148 for (i = 0; i < qm->nrQMatoms; i++)
150 for (j = 0; j < DIM; j++)
152 f[i][j] = (real)10*CAL2JOULE*qmgrad[3*i+j];
153 fshift[i][j] = (real)10*CAL2JOULE*qmgrad[3*i+j];
156 QMener = (real)CAL2JOULE*energy;
157 /* do we do something with the mulliken charges?? */
159 free(qmchrg);
161 free(qmgrad);
162 free(qmcrd);
163 return (QMener);
166 real call_mopac_SH(t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
168 /* do the actual SH QMMM calculation using directly linked mopac
169 subroutines */
171 double /* always double as the MOPAC routines are always compiled in
172 double precission! */
173 *qmcrd = NULL, *qmchrg = NULL, *mmcrd = NULL, *mmchrg = NULL,
174 *qmgrad, *mmgrad = NULL, energy;
176 i, j;
177 real
178 QMener = 0.0;
180 snew(qmcrd, 3*(qm->nrQMatoms));
181 snew(qmgrad, 3*(qm->nrQMatoms));
182 /* copy the data from qr into the arrays that are going to be used
183 * in the fortran routines of MOPAC
185 for (i = 0; i < qm->nrQMatoms; i++)
187 for (j = 0; j < DIM; j++)
189 qmcrd[3*i+j] = (double)qm->xQM[i][j]*10;
192 if (mm->nrMMatoms)
194 /* later we will add the point charges here. There are some
195 * conceptual problems with semi-empirical QM in combination with
196 * point charges that we need to solve first....
198 gmx_fatal(FARGS, "At present only ONIOM is allowed in combination with MOPAC\n");
200 else
202 /* now compute the energy and the gradients.
204 snew(qmchrg, qm->nrQMatoms);
206 F77_FUNC(domop, DOMOP) (&qm->nrQMatoms, qmcrd, &mm->nrMMatoms,
207 mmchrg, mmcrd, qmgrad, mmgrad, &energy, qmchrg);
208 /* add the gradients to the f[] array, and also to the fshift[].
209 * the mopac gradients are in kCal/angstrom.
211 for (i = 0; i < qm->nrQMatoms; i++)
213 for (j = 0; j < DIM; j++)
215 f[i][j] = (real)10*CAL2JOULE*qmgrad[3*i+j];
216 fshift[i][j] = (real)10*CAL2JOULE*qmgrad[3*i+j];
219 QMener = (real)CAL2JOULE*energy;
221 free(qmgrad);
222 free(qmcrd);
223 return (QMener);
224 } /* call_mopac_SH */
226 #else
228 gmx_qmmm_mopac_empty;
229 #endif