-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV_Tinker.cpp
182 lines (169 loc) · 5.63 KB
/
V_Tinker.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* V_Tinker.cpp
*
* Created on: Sep 7, 2012
* Author: dstuck
*/
#include "V_Tinker.h"
V_Tinker::V_Tinker(CoordUtil* coords, double eps, double beta) : coordKeeper(coords) {
tinkPrmFileName = coordKeeper->prmName;
// coordKeeper = coords;
// Initialize forcefield
vector<Particle> parts;
Particle p0(0.0, 1);
for(int i=0; i<coordKeeper->numModes; i++) {
parts.push_back(p0);
}
// Get cartesians from normal modes
vector< vector<double> > cartPos = coordKeeper->initCart;
// DES Temp for CN only!:
//cartPos[0][2] -= -0.00846;
//cartPos[1][2] += 0.00846;
//bool init = true;
int init = 1;
// cout << "inLen is: " << inLen << endl;
int prmLen = tinkPrmFileName.size();
double tinkEnergy = 0.0;
int nPart = coordKeeper->numPart;
int typeVec[nPart];
double xyzCoord[nPart*3];
double connMat[nPart*8];
for(int i=0; i<nPart*8 ; i++){
connMat[i]=0.0;
}
// TODO: Oops, the first column of connectivity contains tinker atomtypes...
for(int i=0; i<nPart; i++) {
typeVec[i] = coordKeeper->connectivity[i][0];
for(int k=0; k<3; k++) {
xyzCoord[k+i*3] = cartPos[i][k];
}
for(int j=1; j<coordKeeper->connectivity[i].size(); j++) {
connMat[j-1+i*8] = coordKeeper->connectivity[i][j];
}
}
string tinkPrm = tinkPrmFileName;
// Initialize tinker parameters
dstuckenergy_(nPart, typeVec, xyzCoord, connMat, tinkPrm.c_str(), prmLen, tinkEnergy, init);
if(!coordKeeper->readGeom) {
dstuckoptimize_(typeVec, xyzCoord, connMat, coordKeeper->numModes, coordKeeper->numPart);
for(int j=0; j<nPart; j++) {
for(int k=0; k<3; k++) {
coordKeeper->initCart[j][k] = xyzCoord[k+j*3];
}
}
coordKeeper->guessCarts = coordKeeper->initCart;
// cout << "DES: Coords after opt" << endl;
// for(int j=0; j<nPart; j++) {
// for(int k=0; k<3; k++) {
// cout << xyzCoord[k+j*3] << "\t";
// }
// cout << endl;
// }
}
// Set up tinker normal modes and frequencies!
int N = coordKeeper->numModes;
if(!coordKeeper->readOmega) {
double tinkModes[N*coordKeeper->numPart*3];
double tinkFreqs[N];
double redMass[N];
dstuckvibrate_(typeVec, xyzCoord, connMat, N, coordKeeper->numPart, redMass, tinkModes, tinkFreqs);
coordKeeper->reducedMass.clear();
for(int i=0; i<N; i++) {
coordKeeper->reducedMass.push_back(redMass[i]*1822.8886);
// cout << coordKeeper->reducedMass[i]/1822.8886 << endl;
}
coordKeeper->omega.clear();
for(int i=0; i<N; i++) {
// Don't want frequencies == 0 TODO: double check this
if(tinkFreqs[i] < 1.0) {
cout << "Frequency of " << tinkFreqs[i] << " set to 0.09 cm-1" << endl;
coordKeeper->omega.push_back(0.00000455633);
}
else {
coordKeeper->omega.push_back(tinkFreqs[i]*0.00000455633);
}
// coordKeeper.omega[i] = tinkFreqs[i]*0.00000455633;
// cout << tinkFreqs[i] << endl;
}
coordKeeper->normModes.clear();
coordKeeper->normModes.resize(N);
for(int i=0; i<N; i++) {
coordKeeper->normModes[i].resize(coordKeeper->numPart);
double vnorm = 0.0;
double tempVal = 0.0;
for(int j=0; j<coordKeeper->numPart; j++) {
coordKeeper->normModes[i][j].resize(3,0.0);
for(int k=0; k<3; k++) {
coordKeeper->normModes[i][j][k] = tinkModes[k+3*j+3*coordKeeper->numPart*i];
//cout << "DES Temp:" << tinkModes[k+3*j+3*coordKeeper->numPart*i] << endl;
}
}
}
}
else {
//cout << "DES Temp: Reading in frequencies from file" << endl;
}
// Get vEquib
double hartreeToKcal = 627.509469; //From http://en.wikipedia.org/wiki/Hartree 8/17/2012
vEquib = 0.0;
vEquib = GetVCart(coordKeeper->initCart)*hartreeToKcal;
}
V_Tinker::~V_Tinker() {
delete coordKeeper;
}
double V_Tinker::GetV(vector<Particle> part, Propagator * rho){
double V = 0.0;
V += GetV(part);
// cout << "Unmodified V =\t" << V << endl;
V += rho->ModifyPotential(part);
// cout << "Modified V =\t" << V << endl;
return V;
}
double V_Tinker::GetV(vector<Particle> part){
// Get cartesians from normal modes
vector< vector<double> > cartPos = coordKeeper->normalModeToCart(part);
return GetVCart(cartPos);
}
double V_Tinker::GetVCart(vector< vector<double> > cartPos) {
double hartreeToKcal = 627.509469; //From http://en.wikipedia.org/wiki/Hartree 8/17/2012
double V = 0.0;
// Call Tinker
//bool init = false;
int init = 0;
int prmLen = tinkPrmFileName.size();
double tinkEnergy = 0.0;
int nPart = coordKeeper->numPart;
int typeVec[nPart];
double xyzCoord[nPart*3];
double connMat[nPart*8];
for(int i=0; i<nPart*8 ; i++){
connMat[i]=0.0;
}
// DES Temp for CN only!:
//cartPos[0][2] += -0.00846;
//cartPos[1][2] += 0.00846;
// TODO: Oops, the first column of connectivity contains tinker atomtypes...
for(int i=0; i<nPart; i++) {
typeVec[i] = coordKeeper->connectivity[i][0];
for(int k=0; k<3; k++) {
xyzCoord[k+i*3] = cartPos[i][k];
}
for(int j=1; j<coordKeeper->connectivity[i].size(); j++) {
connMat[j-1+i*8] = coordKeeper->connectivity[i][j];
}
}
string tinkPrm = tinkPrmFileName;
dstuckenergy_(nPart, typeVec, xyzCoord, connMat, tinkPrm.c_str(), prmLen, tinkEnergy, init);
V = tinkEnergy;
// cout << "Tinker V =\t" << V << endl;
V -= vEquib;
V /= hartreeToKcal;
return V;
}
string V_Tinker::GetType() {
string name = "Tinker";
return name;
}
CoordUtil* V_Tinker::GetCoordUtil() {
return coordKeeper;
}