void init(void) { int i; for(i=0;i<numSpheres;i++){ spheres[i][0] = (rand()%600)-300;//XPOS spheres[i][1] = (rand()%600)-300;//YPOS spheres[i][2] = rand()%400;//ZPOS spheres[i][3] = rand()%20;//SIZE spheres[i][4] = (rand()%20);//SPEED } MAXROT = 1.0/6.0*PI; glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); pmodel = glmReadOBJ("city.obj"); if (!pmodel) fprintf(stderr,"Cannot parse vase.obj"); //glmUnitize(pmodel); // make model to fit in a unit cube glmFacetNormals(pmodel); // generate normals - is this needed? glmVertexNormals(pmodel, 90.0); // average joining normals - allow for hard edges. tmodel = glmReadOBJ("tower.obj"); glmFacetNormals(tmodel); // generate normals - is this needed? glmVertexNormals(tmodel, 90.0); // average joining normals - allow for hard edges. readTop(); readFront(); readBack(); readRight(); readLeft(); readFire(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &front); glGenTextures(1, &top); glGenTextures(1, &left); glGenTextures(1, &right); glGenTextures(1, &back); glGenTextures(1, &fire); qsphere = gluNewQuadric(); }
int main(int argc, char * argv[]) { unsigned numBlock; float begin, end; std::string ifile, ofile, tfile; float time_prec = .01; TopInfo info; double refh; po::options_description desc ("Allow options"); desc.add_options() ("help,h", "print this message") ("begin,b", po::value<float > (&begin)->default_value(0.f), "start time") ("end,e", po::value<float > (&end )->default_value(0.f), "end time") ("block,n", po::value<unsigned > (&numBlock)->default_value(20), "number of block for averaging") ("refh,r", po::value<double > (&refh)->default_value(.1), "size of bin") ("top-file,t",po::value<std::string > (&tfile)->default_value ("mytop"), "topolgy of the system") ("output,o", po::value<std::string > (&ofile)->default_value ("momentum.wave.dat"), "the output of count of h-bond") ("input,f", po::value<std::string > (&ifile)->default_value ("traj.trr"), "the input .xtc file"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify (vm); if (vm.count("help")) { std::cout << desc<< "\n"; return 0; } if (vm.count("top-file")) { readTop (tfile, info); } std::cout << "###################################################" << std::endl; std::cout << "# begin->end: " << begin << " " << end << std::endl; std::cout << "# block: " << numBlock << std::endl; std::cout << "# top file: " << tfile << std::endl; std::cout << "###################################################" << std::endl; TrajLoader_trr tjl (ifile.c_str(), info); std::vector<std::vector<ValueType > > ch4xx; std::vector<std::vector<ValueType > > ch4vv; std::vector<std::vector<ValueType > > ch4ff; std::vector<std::vector<ValueType > > h2o; std::vector<std::vector<ValueType > > h2ovv; std::vector<std::vector<ValueType > > h2off; std::vector<std::vector<double > > com; std::vector<double > mass (3); std::vector<double > moment_r; mass[info.OIndexH2o] = 16; mass[info.H1IndexH2o] = 1; mass[info.H2IndexH2o] = 1; double totalmass = mass[info.OIndexH2o] + mass[info.H1IndexH2o] + mass[info.H2IndexH2o]; double boxSize[3]; boxSize[0] = tjl.getBox().x; boxSize[1] = tjl.getBox().y; boxSize[2] = tjl.getBox().z; int countread = 0; MomentumWave dw; dw.reinit (refh, tjl.getBox()); dw.initFile (ofile.c_str()); while (true == tjl.load()) { float time = tjl.getTime(); if (end != 0.f) { if (time < begin - time_prec) { continue; } else if (time > end + time_prec) { break; } } else { if (time < begin - time_prec) continue; } if (countread++ % 1 == 0) { // printf ("# load frame at time: %.1f ps\r", time); fflush (stdout); } tjl.formCoords (ch4xx, ch4vv, ch4ff, h2o, h2ovv, h2off); // cal coms { com.resize (h2o.size() / info.numAtomOnH2o); moment_r.resize (h2o.size() / info.numAtomOnH2o); for (unsigned ii = 0; ii < h2o.size() / info.numAtomOnH2o; ++ii) { std::vector<double > composi(3, 0.); std::vector<double > comvelo(3, 0.); for (unsigned jj = 1; jj < 3; ++jj) { for (unsigned dd = 0; dd < 3; ++dd) { double diff = h2o[info.numAtomOnH2o*ii+jj][dd] - h2o[info.numAtomOnH2o*ii+0][dd]; if (diff > boxSize[dd] * 0.5) { h2o[info.numAtomOnH2o*ii+jj][dd] -= boxSize[dd]; } else if (diff < -boxSize[dd] * 0.5) { h2o[info.numAtomOnH2o*ii+jj][dd] += boxSize[dd]; } } } for (unsigned jj = 0; jj < 3; ++jj) { for (unsigned dd = 0; dd < 3; ++dd) { composi[dd] += mass[jj] * h2o[info.numAtomOnH2o*ii+jj][dd]; comvelo[dd] += mass[jj] * h2ovv[info.numAtomOnH2o*ii+jj][dd]; } } for (unsigned dd = 0; dd < 3; ++dd) { composi[dd] /= totalmass; } std::vector<double > rr (composi); for (unsigned dd = 0; dd < 3; ++dd) { rr[dd] -= boxSize[dd] * 0.5; } double dr = rr[0] * rr[0] + rr[1] * rr[1] + rr[2] * rr[2]; dr = sqrt(dr); rr[0] /= dr; rr[1] /= dr; rr[2] /= dr; com[ii] = composi; moment_r[ii] = comvelo[0] * rr[0] + comvelo[1] * rr[1] + comvelo[2] * rr[2]; } } dw.calculate (time, com, moment_r); dw.write(); dw.clear (); } return 0; }