-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwater_interface.cpp
109 lines (92 loc) · 2.58 KB
/
water_interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2013 Volodymyr Babin <[email protected]>
//
// This is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// The code is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You can find a copy of the GNU General Public License at
// http://www.gnu.org/licenses/.
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include "../water_potentials/ttm2f.h"
#include "../water_potentials/ttm3f.h"
#include "../water_potentials/ttm4f.h"
#include "../water_potentials/qtip4pf.h"
extern"C" {
#ifdef USE_CP2K
void force_water(
#else
void force_water_(
#endif
const double *x,
const double *y,
const double *z,
double *fx,
double *fy,
double *fz,
double *eclas,
const int *natom,
const int *nwalk,
const int *watpot)
{
const int nwater = *natom / 3;
double E;
double grd[9 * nwater];
double crd[9 * nwater];
// conversion constants
const double ANG = 1.889726132873;
const double AUTOKCAL = 627.50946943;
const double FAC = 1 / ANG / AUTOKCAL;
h2o::qtip4pf pot1;
h2o::ttm2f pot2;
h2o::ttm3f pot3;
h2o::ttm4f pot4;
for (int iw = 0; iw < *nwalk; iw++) {
// Convert to Angstroms
for (int iat = 0; iat < *natom; iat++) {
crd[3*iat] = x[iw * (*natom) + iat] / ANG;
crd[3*iat + 1] = y[iw * (*natom) + iat] / ANG;
crd[3*iat + 2] = z[iw * (*natom) + iat] / ANG;
}
switch (*watpot) {
case 1:
E = pot1(nwater, crd, grd);
break;
case 2:
E = pot2(nwater, crd, grd);
break;
case 3:
E = pot3(nwater, crd, grd);
break;
case 4:
E = pot4(nwater, crd, grd);
break;
default:
std::cerr << "Error: Parameter watpot out of range." << std::endl;
return;
break;
}
*eclas += E / AUTOKCAL;
// Convert forces to atomic units (for ABIN)
for (int iat = 0; iat < *natom; iat++) {
fx[iw * (*natom) + iat] = -grd[3*iat] * FAC;
fy[iw * (*natom) + iat] = -grd[1 + 3*iat] * FAC;
fz[iw * (*natom) + iat] = -grd[2 + 3*iat] * FAC;
}
// nwalk loop
}
*eclas /= *nwalk;
}
// externC
}