| 1 |
mmeineke |
10 |
#include <iostream> |
| 2 |
|
|
#include <stdlib.h> |
| 3 |
|
|
|
| 4 |
|
|
#include "Atom.hpp" |
| 5 |
|
|
#include "SRI.hpp" |
| 6 |
|
|
#include "LRI.hpp" |
| 7 |
|
|
#include "Integrator.hpp" |
| 8 |
|
|
#include "SimInfo.hpp" |
| 9 |
|
|
#include "Thermo.hpp" |
| 10 |
|
|
#include "ReadWrite.hpp" |
| 11 |
|
|
|
| 12 |
|
|
extern "C"{ |
| 13 |
|
|
|
| 14 |
|
|
void v_constrain_a_( double &dt, int &n_atoms, double* mass, |
| 15 |
|
|
double* Rx, double* Ry, double* Rz, |
| 16 |
|
|
double* Vx, double* Vy, double* Vz, |
| 17 |
|
|
double* Fx, double* Fy, double* Fz, |
| 18 |
|
|
int &n_constrained, double *constr_sqr, |
| 19 |
|
|
int* constr_i, int* constr_j, |
| 20 |
|
|
double &box_x, double &box_y, double &box_z ); |
| 21 |
|
|
|
| 22 |
|
|
void v_constrain_b_( double &dt, int &n_atoms, double* mass, |
| 23 |
|
|
double* Rx, double* Ry, double* Rz, |
| 24 |
|
|
double* Vx, double* Vy, double* Vz, |
| 25 |
|
|
double* Fx, double* Fy, double* Fz, |
| 26 |
|
|
double &Kinetic, |
| 27 |
|
|
int &n_constrained, double *constr_sqr, |
| 28 |
|
|
int* constr_i, int* constr_j, |
| 29 |
|
|
double &box_x, double &box_y, double &box_z ); |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
|
| 33 |
chuckv |
249 |
Verlet::Verlet( SimInfo &info, ForceFields* the_ff ){ |
| 34 |
mmeineke |
10 |
|
| 35 |
|
|
// get what information we need from the SimInfo object |
| 36 |
|
|
|
| 37 |
|
|
entry_plug = &info; |
| 38 |
chuckv |
248 |
myFF = the_ff; |
| 39 |
mmeineke |
10 |
|
| 40 |
chuckv |
248 |
|
| 41 |
mmeineke |
10 |
c_natoms = info.n_atoms; |
| 42 |
|
|
c_atoms = info.atoms; |
| 43 |
|
|
c_sr_interactions = info.sr_interactions; |
| 44 |
|
|
c_n_SRI = info.n_SRI; |
| 45 |
|
|
c_is_constrained = 0; |
| 46 |
|
|
c_box_x = info.box_x; |
| 47 |
|
|
c_box_y = info.box_y; |
| 48 |
|
|
c_box_z = info.box_z; |
| 49 |
|
|
|
| 50 |
|
|
// give a little love back to the SimInfo object |
| 51 |
|
|
|
| 52 |
|
|
if( info.the_integrator != NULL ) delete info.the_integrator; |
| 53 |
|
|
info.the_integrator = this; |
| 54 |
|
|
|
| 55 |
|
|
// the rest are initialization issues |
| 56 |
|
|
|
| 57 |
|
|
is_first = 1; // let the integrate method know when the first call is |
| 58 |
|
|
|
| 59 |
|
|
// mass array setup |
| 60 |
|
|
|
| 61 |
|
|
c_mass = new double[c_natoms]; |
| 62 |
|
|
|
| 63 |
|
|
for(int i = 0; i < c_natoms; i++){ |
| 64 |
|
|
c_mass[i] = c_atoms[i]->getMass(); |
| 65 |
|
|
} |
| 66 |
|
|
|
| 67 |
|
|
// check for constraints |
| 68 |
|
|
|
| 69 |
|
|
Constraint *temp_con; |
| 70 |
|
|
Constraint *dummy_plug; |
| 71 |
|
|
temp_con = new Constraint[c_n_SRI]; |
| 72 |
|
|
|
| 73 |
|
|
c_n_constrained = 0; |
| 74 |
|
|
int constrained = 0; |
| 75 |
|
|
|
| 76 |
|
|
for(int i = 0; i < c_n_SRI; i++){ |
| 77 |
|
|
|
| 78 |
|
|
constrained = c_sr_interactions[i]->is_constrained(); |
| 79 |
|
|
|
| 80 |
|
|
if(constrained){ |
| 81 |
|
|
|
| 82 |
|
|
dummy_plug = c_sr_interactions[i]->get_constraint(); |
| 83 |
|
|
temp_con[c_n_constrained].set_a( dummy_plug->get_a() ); |
| 84 |
|
|
temp_con[c_n_constrained].set_b( dummy_plug->get_b() ); |
| 85 |
|
|
temp_con[c_n_constrained].set_dsqr( dummy_plug->get_dsqr() ); |
| 86 |
|
|
|
| 87 |
|
|
c_n_constrained++; |
| 88 |
|
|
constrained = 0; |
| 89 |
|
|
} |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
if(c_n_constrained > 0){ |
| 93 |
|
|
|
| 94 |
|
|
c_is_constrained = 1; |
| 95 |
|
|
c_constrained_i = new int[c_n_constrained]; |
| 96 |
|
|
c_constrained_j = new int[c_n_constrained]; |
| 97 |
|
|
c_constrained_dsqr = new double[c_n_constrained]; |
| 98 |
|
|
|
| 99 |
|
|
for( int i = 0; i < c_n_constrained; i++){ |
| 100 |
|
|
|
| 101 |
|
|
/* add 1 to the index for the fortran arrays. */ |
| 102 |
|
|
|
| 103 |
|
|
c_constrained_i[i] = temp_con[i].get_a() + 1; |
| 104 |
|
|
c_constrained_j[i] = temp_con[i].get_b() + 1; |
| 105 |
|
|
c_constrained_dsqr[i] = temp_con[i].get_dsqr(); |
| 106 |
|
|
} |
| 107 |
|
|
} |
| 108 |
|
|
|
| 109 |
|
|
delete[] temp_con; |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
|
| 113 |
|
|
Verlet::~Verlet(){ |
| 114 |
|
|
|
| 115 |
|
|
if( c_is_constrained ){ |
| 116 |
|
|
|
| 117 |
|
|
delete[] c_constrained_i; |
| 118 |
|
|
delete[] c_constrained_j; |
| 119 |
|
|
delete[] c_constrained_dsqr; |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
|
|
delete[] c_mass; |
| 123 |
|
|
c_mass = 0; |
| 124 |
|
|
} |
| 125 |
|
|
|
| 126 |
|
|
|
| 127 |
|
|
void Verlet::integrate( void ){ |
| 128 |
|
|
|
| 129 |
|
|
int i, j; /* loop counters */ |
| 130 |
|
|
|
| 131 |
|
|
double kE; |
| 132 |
|
|
|
| 133 |
|
|
double *Rx = new double[c_natoms]; |
| 134 |
|
|
double *Ry = new double[c_natoms]; |
| 135 |
|
|
double *Rz = new double[c_natoms]; |
| 136 |
|
|
|
| 137 |
|
|
double *Vx = new double[c_natoms]; |
| 138 |
|
|
double *Vy = new double[c_natoms]; |
| 139 |
|
|
double *Vz = new double[c_natoms]; |
| 140 |
|
|
|
| 141 |
|
|
double *Fx = new double[c_natoms]; |
| 142 |
|
|
double *Fy = new double[c_natoms]; |
| 143 |
|
|
double *Fz = new double[c_natoms]; |
| 144 |
|
|
|
| 145 |
mmeineke |
25 |
int time; |
| 146 |
|
|
|
| 147 |
mmeineke |
10 |
double dt = entry_plug->dt; |
| 148 |
|
|
double runTime = entry_plug->run_time; |
| 149 |
|
|
double sampleTime = entry_plug->sampleTime; |
| 150 |
|
|
double statusTime = entry_plug->statusTime; |
| 151 |
|
|
double thermalTime = entry_plug->thermalTime; |
| 152 |
|
|
|
| 153 |
|
|
int n_loops = (int)( runTime / dt ); |
| 154 |
|
|
int sample_n = (int)( sampleTime / dt ); |
| 155 |
|
|
int status_n = (int)( statusTime / dt ); |
| 156 |
|
|
int vel_n = (int)( thermalTime / dt ); |
| 157 |
|
|
|
| 158 |
|
|
Thermo *tStats = new Thermo( entry_plug ); |
| 159 |
|
|
|
| 160 |
|
|
StatWriter* e_out = new StatWriter( entry_plug ); |
| 161 |
|
|
DumpWriter* dump_out = new DumpWriter( entry_plug ); |
| 162 |
|
|
|
| 163 |
|
|
// the first time integrate is called, the forces need to be initialized |
| 164 |
|
|
|
| 165 |
|
|
|
| 166 |
chuckv |
248 |
myFF->doForces(); |
| 167 |
mmeineke |
10 |
|
| 168 |
|
|
if( entry_plug->setTemp ){ |
| 169 |
|
|
tStats->velocitize(); |
| 170 |
|
|
} |
| 171 |
|
|
|
| 172 |
mmeineke |
25 |
dump_out->writeDump( 0.0 ); |
| 173 |
|
|
e_out->writeStat( 0.0 ); |
| 174 |
|
|
|
| 175 |
mmeineke |
10 |
if( c_is_constrained ){ |
| 176 |
|
|
for(i = 0; i < n_loops; i++){ |
| 177 |
|
|
|
| 178 |
|
|
// fill R, V, and F arrays and RATTLE in fortran |
| 179 |
|
|
|
| 180 |
|
|
for( j=0; j<c_natoms; j++ ){ |
| 181 |
|
|
|
| 182 |
|
|
Rx[j] = c_atoms[j]->getX(); |
| 183 |
|
|
Ry[j] = c_atoms[j]->getY(); |
| 184 |
|
|
Rz[j] = c_atoms[j]->getZ(); |
| 185 |
|
|
|
| 186 |
|
|
Vx[j] = c_atoms[j]->get_vx(); |
| 187 |
|
|
Vy[j] = c_atoms[j]->get_vy(); |
| 188 |
|
|
Vz[j] = c_atoms[j]->get_vz(); |
| 189 |
|
|
|
| 190 |
|
|
Fx[j] = c_atoms[j]->getFx(); |
| 191 |
|
|
Fy[j] = c_atoms[j]->getFy(); |
| 192 |
|
|
Fz[j] = c_atoms[j]->getFz(); |
| 193 |
|
|
|
| 194 |
|
|
} |
| 195 |
|
|
|
| 196 |
|
|
v_constrain_a_( dt, c_natoms, c_mass, Rx, Ry, Rz, Vx, Vy, Vz, |
| 197 |
|
|
Fx, Fy, Fz, |
| 198 |
|
|
c_n_constrained, c_constrained_dsqr, |
| 199 |
|
|
c_constrained_i, c_constrained_j, |
| 200 |
|
|
c_box_x, c_box_y, c_box_z ); |
| 201 |
|
|
|
| 202 |
|
|
for( j=0; j<c_natoms; j++ ){ |
| 203 |
|
|
|
| 204 |
|
|
c_atoms[j]->setX(Rx[j]); |
| 205 |
|
|
c_atoms[j]->setY(Ry[j]); |
| 206 |
|
|
c_atoms[j]->setZ(Rz[j]); |
| 207 |
|
|
|
| 208 |
|
|
c_atoms[j]->set_vx(Vx[j]); |
| 209 |
|
|
c_atoms[j]->set_vy(Vy[j]); |
| 210 |
|
|
c_atoms[j]->set_vz(Vz[j]); |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
|
// calculate the forces |
| 214 |
|
|
|
| 215 |
chuckv |
248 |
myFF->doForces(); |
| 216 |
mmeineke |
10 |
|
| 217 |
|
|
// finish the constrain move ( same as above. ) |
| 218 |
|
|
|
| 219 |
|
|
for( j=0; j<c_natoms; j++ ){ |
| 220 |
|
|
|
| 221 |
|
|
Rx[j] = c_atoms[j]->getX(); |
| 222 |
|
|
Ry[j] = c_atoms[j]->getY(); |
| 223 |
|
|
Rz[j] = c_atoms[j]->getZ(); |
| 224 |
|
|
|
| 225 |
|
|
Vx[j] = c_atoms[j]->get_vx(); |
| 226 |
|
|
Vy[j] = c_atoms[j]->get_vy(); |
| 227 |
|
|
Vz[j] = c_atoms[j]->get_vz(); |
| 228 |
|
|
|
| 229 |
|
|
Fx[j] = c_atoms[j]->getFx(); |
| 230 |
|
|
Fy[j] = c_atoms[j]->getFy(); |
| 231 |
|
|
Fz[j] = c_atoms[j]->getFz(); |
| 232 |
|
|
} |
| 233 |
|
|
|
| 234 |
|
|
v_constrain_b_( dt, c_natoms, c_mass, Rx, Ry, Rz, Vx, Vy, Vz, |
| 235 |
|
|
Fx, Fy, Fz, |
| 236 |
|
|
kE, c_n_constrained, c_constrained_dsqr, |
| 237 |
|
|
c_constrained_i, c_constrained_j, |
| 238 |
|
|
c_box_x, c_box_y, c_box_z ); |
| 239 |
|
|
|
| 240 |
|
|
for( j=0; j<c_natoms; j++ ){ |
| 241 |
|
|
|
| 242 |
|
|
c_atoms[j]->setX(Rx[j]); |
| 243 |
|
|
c_atoms[j]->setY(Ry[j]); |
| 244 |
|
|
c_atoms[j]->setZ(Rz[j]); |
| 245 |
|
|
|
| 246 |
|
|
c_atoms[j]->set_vx(Vx[j]); |
| 247 |
|
|
c_atoms[j]->set_vy(Vy[j]); |
| 248 |
|
|
c_atoms[j]->set_vz(Vz[j]); |
| 249 |
|
|
} |
| 250 |
|
|
|
| 251 |
mmeineke |
25 |
time = i + 1; |
| 252 |
|
|
|
| 253 |
mmeineke |
10 |
if( entry_plug->setTemp ){ |
| 254 |
mmeineke |
25 |
if( !(time % vel_n) ) tStats->velocitize(); |
| 255 |
mmeineke |
10 |
} |
| 256 |
mmeineke |
25 |
if( !(time % sample_n) ) dump_out->writeDump( time * dt ); |
| 257 |
|
|
if( !(time % status_n) ) e_out->writeStat( time * dt ); |
| 258 |
mmeineke |
10 |
} |
| 259 |
|
|
} |
| 260 |
|
|
else{ |
| 261 |
|
|
for(i = 0; i < n_loops; i++){ |
| 262 |
|
|
|
| 263 |
|
|
move_a( dt ); |
| 264 |
|
|
|
| 265 |
|
|
// calculate the forces |
| 266 |
|
|
|
| 267 |
chuckv |
248 |
myFF->doForces(); |
| 268 |
mmeineke |
10 |
|
| 269 |
|
|
// complete the verlet move |
| 270 |
|
|
|
| 271 |
|
|
move_b( dt ); |
| 272 |
|
|
|
| 273 |
mmeineke |
25 |
time = i + 1; |
| 274 |
|
|
|
| 275 |
mmeineke |
10 |
if( entry_plug->setTemp ){ |
| 276 |
mmeineke |
25 |
if( !(time % vel_n) ) tStats->velocitize(); |
| 277 |
mmeineke |
10 |
} |
| 278 |
mmeineke |
25 |
if( !(time % sample_n) ) dump_out->writeDump( time * dt ); |
| 279 |
|
|
if( !(time % status_n) ) e_out->writeStat( time * dt ); |
| 280 |
mmeineke |
10 |
} |
| 281 |
|
|
} |
| 282 |
|
|
|
| 283 |
|
|
dump_out->writeFinal(); |
| 284 |
|
|
|
| 285 |
|
|
delete dump_out; |
| 286 |
|
|
delete e_out; |
| 287 |
|
|
|
| 288 |
|
|
} |
| 289 |
|
|
|
| 290 |
|
|
|
| 291 |
|
|
void Verlet::move_a(double dt){ |
| 292 |
|
|
|
| 293 |
|
|
const double e_convert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2 |
| 294 |
|
|
|
| 295 |
|
|
double qx, qy, qz; |
| 296 |
|
|
double vx, vy, vz; |
| 297 |
|
|
int ma; |
| 298 |
|
|
double h_dt = 0.5 * dt; |
| 299 |
|
|
double h_dt2 = h_dt * dt; |
| 300 |
|
|
|
| 301 |
|
|
for( ma = 0; ma < c_natoms; ma++){ |
| 302 |
|
|
|
| 303 |
|
|
qx = c_atoms[ma]->getX() + dt * c_atoms[ma]->get_vx() + |
| 304 |
|
|
h_dt2 * c_atoms[ma]->getFx() * e_convert / c_atoms[ma]->getMass(); |
| 305 |
|
|
qy = c_atoms[ma]->getY() + dt * c_atoms[ma]->get_vy() + |
| 306 |
|
|
h_dt2 * c_atoms[ma]->getFy() * e_convert / c_atoms[ma]->getMass(); |
| 307 |
|
|
qz = c_atoms[ma]->getZ() + dt * c_atoms[ma]->get_vz() + |
| 308 |
|
|
h_dt2 * c_atoms[ma]->getFz() * e_convert / c_atoms[ma]->getMass(); |
| 309 |
|
|
|
| 310 |
|
|
vx = c_atoms[ma]->get_vx() + |
| 311 |
|
|
h_dt * c_atoms[ma]->getFx() * e_convert / c_atoms[ma]->getMass(); |
| 312 |
|
|
vy = c_atoms[ma]->get_vy() + |
| 313 |
|
|
h_dt * c_atoms[ma]->getFy() * e_convert / c_atoms[ma]->getMass(); |
| 314 |
|
|
vz = c_atoms[ma]->get_vz() + |
| 315 |
|
|
h_dt * c_atoms[ma]->getFz() * e_convert / c_atoms[ma]->getMass(); |
| 316 |
|
|
|
| 317 |
|
|
c_atoms[ma]->setX(qx); |
| 318 |
|
|
c_atoms[ma]->setY(qy); |
| 319 |
|
|
c_atoms[ma]->setZ(qz); |
| 320 |
|
|
|
| 321 |
|
|
c_atoms[ma]->set_vx(vx); |
| 322 |
|
|
c_atoms[ma]->set_vy(vy); |
| 323 |
|
|
c_atoms[ma]->set_vz(vz); |
| 324 |
|
|
} |
| 325 |
|
|
} |
| 326 |
|
|
|
| 327 |
|
|
void Verlet::move_b( double dt ){ |
| 328 |
|
|
|
| 329 |
|
|
const double e_convert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2 |
| 330 |
|
|
|
| 331 |
|
|
double vx, vy, vz; |
| 332 |
|
|
int mb; |
| 333 |
|
|
double h_dt = 0.5 * dt; |
| 334 |
|
|
|
| 335 |
|
|
|
| 336 |
|
|
for( mb = 0; mb < c_natoms; mb++){ |
| 337 |
|
|
|
| 338 |
|
|
vx = c_atoms[mb]->get_vx() + |
| 339 |
|
|
h_dt * c_atoms[mb]->getFx() * e_convert / c_atoms[mb]->getMass(); |
| 340 |
|
|
vy = c_atoms[mb]->get_vy() + |
| 341 |
|
|
h_dt * c_atoms[mb]->getFy() * e_convert / c_atoms[mb]->getMass(); |
| 342 |
|
|
vz = c_atoms[mb]->get_vz() + |
| 343 |
|
|
h_dt * c_atoms[mb]->getFz() * e_convert / c_atoms[mb]->getMass(); |
| 344 |
|
|
|
| 345 |
|
|
c_atoms[mb]->set_vx(vx); |
| 346 |
|
|
c_atoms[mb]->set_vy(vy); |
| 347 |
|
|
c_atoms[mb]->set_vz(vz); |
| 348 |
|
|
} |
| 349 |
|
|
} |