/*! * This will read a single frame from the xtc file (must be open) into * a Cuboid container. The box dimensions are retrieved for the frame and transfered * to the container. Coordinates are copied into both the particle vector "p" and the * "trial" vector. In doing so, positions are converted from nm to angstroms and the * coordinate system is shifted so that origin is on the middle of the box. As a safefy * measure we do a container collision check to see if all particles are within the Cuboid * boundaries. * * \note The container particle vector *must* match the number of particles in the xtc file. If not * an error message will be issued and the function will abort. * \note You may want to transfer the new box size to the pair potential if periodic boundaries are used. */ bool FormatXTC::loadnextframe(Space &c) { if (xd!=NULL) { if (natoms_xtc==(int)c.p.size()) { int rc = read_xtc(xd, natoms_xtc, &step_xtc, &time_xtc, xdbox, x_xtc, &prec_xtc); if (rc==0) { static double ten=10; Geometry::Cuboid* geo = dynamic_cast<Geometry::Cuboid*>(c.geo); Point l( xdbox[0][0], xdbox[1][1], xdbox[2][2] ); geo->setlen(l*ten); for (size_t i=0; i<c.p.size(); i++) { c.p[i].x() = x_xtc[i][0]*ten - geo->len_half.x(); // store pos. in container. c.p[i].y() = x_xtc[i][1]*ten - geo->len_half.y(); c.p[i].z() = x_xtc[i][2]*ten - geo->len_half.z(); c.trial[i].x()=c.p[i].x(); c.trial[i].y()=c.p[i].y(); c.trial[i].z()=c.p[i].z(); if ( geo->collision(c.p[i]) ) { std::cerr << "# ioxtc load error: particle-container collision!" << endl; return false; } } return true; } } else std::cerr << "# ioxtc load error: xtcfile-container particle mismatch!" << endl; } else std::cerr << "# ioxtc load error: xtc file not available for reading!" << endl; return false; }
bool XtcLoader:: load () { if (inited){ matrix tmpBox; int st = read_xtc (xd, natoms, &step, &time, tmpBox, xx, &prec); box[0] = tmpBox[0][0]; box[1] = tmpBox[1][1]; box[2] = tmpBox[2][2]; if (st == exdrOK) return true; else return false; } else { std::cerr << "not initiated, do nothing." << std::endl; return false; } }
int main (int argc, char *argv[]) { int st; SimParams params; int max_steps = std::numeric_limits<int>::max(); std::string within_filename, output_filename; po::options_description desc("Options"); desc.add_options() ("help,h", "Print help messages") ("group,g", po::value<std::string>()->default_value("He"), "Group for temperature profiles") ("index,n", po::value<std::string>()->default_value("index.ndx"), ".ndx file containing atomic indices for groups") ("gro", po::value<std::string>()->default_value("conf.gro"), ".gro file containing list of atoms/molecules") ("top", po::value<std::string>()->default_value("topol.top"), ".top file containing atomic/molecular properties") ("within,w", po::value<std::string>(&within_filename)->default_value("within.dat"), ".dat file specifying solvating molecules") ("output,o", po::value<std::string>(&output_filename)->default_value("qDist.txt"), "Output filename"); 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"; exit(EXIT_SUCCESS); } std::map<std::string, std::vector<int> > groups; groups = ReadNdx(vm["index"].as<std::string>()); std::vector<Molecule> molecules = GenMolecules(vm["top"].as<std::string>(), params); AtomGroup all_atoms(vm["gro"].as<std::string>(), molecules); AtomGroup selected_group(vm["group"].as<std::string>(), SelectGroup(groups, vm["group"].as<std::string>()), all_atoms); std::fstream within_file(within_filename.c_str()); assert(within_file.is_open()); arma::irowvec within = arma::zeros<arma::irowvec>(selected_group.size()); arma::irowvec nearest = arma::zeros<arma::irowvec>(4); Histogram q_hist(100, 0.01); rvec *x_in = NULL; matrix box_mat; arma::rowvec box = arma::zeros<arma::rowvec>(DIMS); std::string xtc_filename = "prod.xtc"; XDRFILE *xtc_file; params.ExtractTrajMetadata(strdup(xtc_filename.c_str()), (&x_in), box); xtc_file = xdrfile_open(strdup(xtc_filename.c_str()), "r"); params.set_max_time(vm["max_time"].as<double>()); arma::rowvec dx; arma::mat dx_near = arma::zeros<arma::mat>(4,DIMS); arma::rowvec r2 = arma::zeros<arma::rowvec>(selected_group.size()); float time,prec; for (int step=0; step<max_steps; step++) { if(read_xtc(xtc_file, params.num_atoms(), &st, &time, box_mat, x_in, &prec)) break; params.set_box(box_mat); int i = 0; for (std::vector<int>::iterator i_atom = selected_group.begin(); i_atom != selected_group.end(); i_atom++, i++) { selected_group.set_position(i, x_in[*i_atom]); } ReadInt(within, within_file); for (int i_atom = 0; i_atom < selected_group.size(); ++i_atom) { if (!within(i_atom)) continue; selected_group.FindNearestk(selected_group.position(i_atom), params.box(), selected_group.index_to_molecule(i_atom), 4, dx, r2, nearest); int q = 0; for (int i_near = 0; i_near < 4; ++i_near) { FindDxNoShift(dx, selected_group.position(i_atom), selected_group.position(i_near), box); dx_near.row(i_near) = arma::normalise(dx); for (int i_near2 = 0; i_near2 < i_near; ++i_near2) { double sqrt_q = arma::dot(dx_near.row(i_near),dx_near.row(i_near2)) + 1.0/3.0; q += sqrt_q*sqrt_q; } } q_hist.Add(q); } } q_hist.Print(output_filename, true); }
void read_xtc2structure(char * filename,char * out_file, int ion_position,vector<int> quartet_1_serial,vector<int> quartet_2_serial,struct atom * atom_head,int step_frame ) { int natoms,step; float time_temp; float p; matrix box; rvec *x; XDRFILE *xtc; xtc=xdrfile_open(filename,"r"); int read_return=read_xtc_natoms(filename,&natoms); int num_step=0; ofstream out(out_file); out<<"#calculate the distence of ion to the center of the two quartets in z-axis/"<<endl; out<<"#Time\t"<<"dist2ions"<<"\t"<<"dist2quartets"<<endl; double * ion_coor; ion_coor=dvector(0,2); struct chain * chain_head; chain_head=read_pdb_to_chain(atom_head); struct chain * ch_q_1_G_1; struct chain * ch_q_1_G_2; struct chain * ch_q_1_G_3; struct chain * ch_q_1_G_4; struct chain * ch_q_2_G_1; struct chain * ch_q_2_G_2; struct chain * ch_q_2_G_3; struct chain * ch_q_2_G_4; ch_q_1_G_1=get_base_chain(chain_head,quartet_1_serial.at(0)); ch_q_1_G_2=get_base_chain(chain_head,quartet_1_serial.at(1)); ch_q_1_G_3=get_base_chain(chain_head,quartet_1_serial.at(2)); ch_q_1_G_4=get_base_chain(chain_head,quartet_1_serial.at(3)); ch_q_2_G_1=get_base_chain(chain_head,quartet_2_serial.at(0)); ch_q_2_G_2=get_base_chain(chain_head,quartet_2_serial.at(1)); ch_q_2_G_3=get_base_chain(chain_head,quartet_2_serial.at(2)); ch_q_2_G_4=get_base_chain(chain_head,quartet_2_serial.at(3)); struct base_purine_serial * bs_q_1_G_1; struct base_purine_serial * bs_q_1_G_2; struct base_purine_serial * bs_q_1_G_3; struct base_purine_serial * bs_q_1_G_4; struct base_purine_serial * bs_q_2_G_1; struct base_purine_serial * bs_q_2_G_2; struct base_purine_serial * bs_q_2_G_3; struct base_purine_serial * bs_q_2_G_4; //得到G碱基的原子的序号。 bs_q_1_G_1=read_pdb2purine_base(atom_head,*ch_q_1_G_1); bs_q_1_G_2=read_pdb2purine_base(atom_head,*ch_q_1_G_2); bs_q_1_G_3=read_pdb2purine_base(atom_head,*ch_q_1_G_3); bs_q_1_G_4=read_pdb2purine_base(atom_head,*ch_q_1_G_4); bs_q_2_G_1=read_pdb2purine_base(atom_head,*ch_q_2_G_1); bs_q_2_G_2=read_pdb2purine_base(atom_head,*ch_q_2_G_2); bs_q_2_G_3=read_pdb2purine_base(atom_head,*ch_q_2_G_3); bs_q_2_G_4=read_pdb2purine_base(atom_head,*ch_q_2_G_4); x=(rvec * )calloc(natoms,sizeof(x[0])); while(1) { read_return=read_xtc(xtc,natoms,&step,&time_temp,box,x,&p); num_step++; if(step%10000==0) { cout<<"Reading frame : "<<step<<"\t time :"<<time_temp<<endl; } if(read_return!=0) { break; } if(num_step%step_frame==0) { double ** q_1_G_1_matrix; double ** q_1_G_2_matrix; double ** q_1_G_3_matrix; double ** q_1_G_4_matrix; double ** q_2_G_1_matrix; double ** q_2_G_2_matrix; double ** q_2_G_3_matrix; double ** q_2_G_4_matrix; q_1_G_1_matrix=dmatrix(0,8,0,2); q_1_G_2_matrix=dmatrix(0,8,0,2); q_1_G_3_matrix=dmatrix(0,8,0,2); q_1_G_4_matrix=dmatrix(0,8,0,2); q_2_G_1_matrix=dmatrix(0,8,0,2); q_2_G_2_matrix=dmatrix(0,8,0,2); q_2_G_3_matrix=dmatrix(0,8,0,2); q_2_G_4_matrix=dmatrix(0,8,0,2); for(int i=0;i<natoms;i++) { // cout<<step<<"\t"<<time_temp<<"\t"<<natom<<"\t"<<x[natom][0]<<"\t"<<x[natom][1]<<"\t"<<x[natom][2]<<endl; if((i+1)==ion_position) { ion_coor[0]=10*x[i][0]; ion_coor[1]=10*x[i][1]; ion_coor[2]=10*x[i][2]; // cout<<"get ions coordination"<<endl; } //q_1_G_1 if((i+1)==bs_q_1_G_1->C2_serial) { q_1_G_1_matrix[6][0]=10*x[i][0]; q_1_G_1_matrix[6][1]=10*x[i][1]; q_1_G_1_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->C4_serial) { q_1_G_1_matrix[8][0]=10*x[i][0]; q_1_G_1_matrix[8][1]=10*x[i][1]; q_1_G_1_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->C5_serial) { q_1_G_1_matrix[3][0]=10*x[i][0]; q_1_G_1_matrix[3][1]=10*x[i][1]; q_1_G_1_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->C6_serial) { q_1_G_1_matrix[4][0]=10*x[i][0]; q_1_G_1_matrix[4][1]=10*x[i][1]; q_1_G_1_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->C8_serial) { q_1_G_1_matrix[1][0]=10*x[i][0]; q_1_G_1_matrix[1][1]=10*x[i][1]; q_1_G_1_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->N1_serial) { q_1_G_1_matrix[5][0]=10*x[i][0]; q_1_G_1_matrix[5][1]=10*x[i][1]; q_1_G_1_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->N3_serial) { q_1_G_1_matrix[7][0]=10*x[i][0]; q_1_G_1_matrix[7][1]=10*x[i][1]; q_1_G_1_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->N7_serial) { q_1_G_1_matrix[2][0]=10*x[i][0]; q_1_G_1_matrix[2][1]=10*x[i][1]; q_1_G_1_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_1->N9_serial) { q_1_G_1_matrix[0][0]=10*x[i][0]; q_1_G_1_matrix[0][1]=10*x[i][1]; q_1_G_1_matrix[0][2]=10*x[i][2]; } // q_1_G_2 if((i+1)==bs_q_1_G_2->C2_serial) { q_1_G_2_matrix[6][0]=10*x[i][0]; q_1_G_2_matrix[6][1]=10*x[i][1]; q_1_G_2_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->C4_serial) { q_1_G_2_matrix[8][0]=10*x[i][0]; q_1_G_2_matrix[8][1]=10*x[i][1]; q_1_G_2_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->C5_serial) { q_1_G_2_matrix[3][0]=10*x[i][0]; q_1_G_2_matrix[3][1]=10*x[i][1]; q_1_G_2_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->C6_serial) { q_1_G_2_matrix[4][0]=10*x[i][0]; q_1_G_2_matrix[4][1]=10*x[i][1]; q_1_G_2_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->C8_serial) { q_1_G_2_matrix[1][0]=10*x[i][0]; q_1_G_2_matrix[1][1]=10*x[i][1]; q_1_G_2_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->N1_serial) { q_1_G_2_matrix[5][0]=10*x[i][0]; q_1_G_2_matrix[5][1]=10*x[i][1]; q_1_G_2_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->N3_serial) { q_1_G_2_matrix[7][0]=10*x[i][0]; q_1_G_2_matrix[7][1]=10*x[i][1]; q_1_G_2_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->N7_serial) { q_1_G_2_matrix[2][0]=10*x[i][0]; q_1_G_2_matrix[2][1]=10*x[i][1]; q_1_G_2_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_2->N9_serial) { q_1_G_2_matrix[0][0]=10*x[i][0]; q_1_G_2_matrix[0][1]=10*x[i][1]; q_1_G_2_matrix[0][2]=10*x[i][2]; } //q_1_G_3 if((i+1)==bs_q_1_G_3->C2_serial) { q_1_G_3_matrix[6][0]=10*x[i][0]; q_1_G_3_matrix[6][1]=10*x[i][1]; q_1_G_3_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->C4_serial) { q_1_G_3_matrix[8][0]=10*x[i][0]; q_1_G_3_matrix[8][1]=10*x[i][1]; q_1_G_3_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->C5_serial) { q_1_G_3_matrix[3][0]=10*x[i][0]; q_1_G_3_matrix[3][1]=10*x[i][1]; q_1_G_3_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->C6_serial) { q_1_G_3_matrix[4][0]=10*x[i][0]; q_1_G_3_matrix[4][1]=10*x[i][1]; q_1_G_3_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->C8_serial) { q_1_G_3_matrix[1][0]=10*x[i][0]; q_1_G_3_matrix[1][1]=10*x[i][1]; q_1_G_3_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->N1_serial) { q_1_G_3_matrix[5][0]=10*x[i][0]; q_1_G_3_matrix[5][1]=10*x[i][1]; q_1_G_3_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->N3_serial) { q_1_G_3_matrix[7][0]=10*x[i][0]; q_1_G_3_matrix[7][1]=10*x[i][1]; q_1_G_3_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->N7_serial) { q_1_G_3_matrix[2][0]=10*x[i][0]; q_1_G_3_matrix[2][1]=10*x[i][1]; q_1_G_3_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_3->N9_serial) { q_1_G_3_matrix[0][0]=10*x[i][0]; q_1_G_3_matrix[0][1]=10*x[i][1]; q_1_G_3_matrix[0][2]=10*x[i][2]; } //q_1_G_4 if((i+1)==bs_q_1_G_4->C2_serial) { q_1_G_4_matrix[6][0]=10*x[i][0]; q_1_G_4_matrix[6][1]=10*x[i][1]; q_1_G_4_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->C4_serial) { q_1_G_4_matrix[8][0]=10*x[i][0]; q_1_G_4_matrix[8][1]=10*x[i][1]; q_1_G_4_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->C5_serial) { q_1_G_4_matrix[3][0]=10*x[i][0]; q_1_G_4_matrix[3][1]=10*x[i][1]; q_1_G_4_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->C6_serial) { q_1_G_4_matrix[4][0]=10*x[i][0]; q_1_G_4_matrix[4][1]=10*x[i][1]; q_1_G_4_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->C8_serial) { q_1_G_4_matrix[1][0]=10*x[i][0]; q_1_G_4_matrix[1][1]=10*x[i][1]; q_1_G_4_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->N1_serial) { q_1_G_4_matrix[5][0]=10*x[i][0]; q_1_G_4_matrix[5][1]=10*x[i][1]; q_1_G_4_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->N3_serial) { q_1_G_4_matrix[7][0]=10*x[i][0]; q_1_G_4_matrix[7][1]=10*x[i][1]; q_1_G_4_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->N7_serial) { q_1_G_4_matrix[2][0]=10*x[i][0]; q_1_G_4_matrix[2][1]=10*x[i][1]; q_1_G_4_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_1_G_4->N9_serial) { q_1_G_4_matrix[0][0]=10*x[i][0]; q_1_G_4_matrix[0][1]=10*x[i][1]; q_1_G_4_matrix[0][2]=10*x[i][2]; } //q_2_G_1 if((i+1)==bs_q_2_G_1->C2_serial) { q_2_G_1_matrix[6][0]=10*x[i][0]; q_2_G_1_matrix[6][1]=10*x[i][1]; q_2_G_1_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->C4_serial) { q_2_G_1_matrix[8][0]=10*x[i][0]; q_2_G_1_matrix[8][1]=10*x[i][1]; q_2_G_1_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->C5_serial) { q_2_G_1_matrix[3][0]=10*x[i][0]; q_2_G_1_matrix[3][1]=10*x[i][1]; q_2_G_1_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->C6_serial) { q_2_G_1_matrix[4][0]=10*x[i][0]; q_2_G_1_matrix[4][1]=10*x[i][1]; q_2_G_1_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->C8_serial) { q_2_G_1_matrix[1][0]=10*x[i][0]; q_2_G_1_matrix[1][1]=10*x[i][1]; q_2_G_1_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->N1_serial) { q_2_G_1_matrix[5][0]=10*x[i][0]; q_2_G_1_matrix[5][1]=10*x[i][1]; q_2_G_1_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->N3_serial) { q_2_G_1_matrix[7][0]=10*x[i][0]; q_2_G_1_matrix[7][1]=10*x[i][1]; q_2_G_1_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->N7_serial) { q_2_G_1_matrix[2][0]=10*x[i][0]; q_2_G_1_matrix[2][1]=10*x[i][1]; q_2_G_1_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_1->N9_serial) { q_2_G_1_matrix[0][0]=10*x[i][0]; q_2_G_1_matrix[0][1]=10*x[i][1]; q_2_G_1_matrix[0][2]=10*x[i][2]; } //q_2_G_2 if((i+1)==bs_q_2_G_2->C2_serial) { q_2_G_2_matrix[6][0]=10*x[i][0]; q_2_G_2_matrix[6][1]=10*x[i][1]; q_2_G_2_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->C4_serial) { q_2_G_2_matrix[8][0]=10*x[i][0]; q_2_G_2_matrix[8][1]=10*x[i][1]; q_2_G_2_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->C5_serial) { q_2_G_2_matrix[3][0]=10*x[i][0]; q_2_G_2_matrix[3][1]=10*x[i][1]; q_2_G_2_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->C6_serial) { q_2_G_2_matrix[4][0]=10*x[i][0]; q_2_G_2_matrix[4][1]=10*x[i][1]; q_2_G_2_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->C8_serial) { q_2_G_2_matrix[1][0]=10*x[i][0]; q_2_G_2_matrix[1][1]=10*x[i][1]; q_2_G_2_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->N1_serial) { q_2_G_2_matrix[5][0]=10*x[i][0]; q_2_G_2_matrix[5][1]=10*x[i][1]; q_2_G_2_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->N3_serial) { q_2_G_2_matrix[7][0]=10*x[i][0]; q_2_G_2_matrix[7][1]=10*x[i][1]; q_2_G_2_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->N7_serial) { q_2_G_2_matrix[2][0]=10*x[i][0]; q_2_G_2_matrix[2][1]=10*x[i][1]; q_2_G_2_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_2->N9_serial) { q_2_G_2_matrix[0][0]=10*x[i][0]; q_2_G_2_matrix[0][1]=10*x[i][1]; q_2_G_2_matrix[0][2]=10*x[i][2]; } //q_2_G_3 if((i+1)==bs_q_2_G_3->C2_serial) { q_2_G_3_matrix[6][0]=10*x[i][0]; q_2_G_3_matrix[6][1]=10*x[i][1]; q_2_G_3_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->C4_serial) { q_2_G_3_matrix[8][0]=10*x[i][0]; q_2_G_3_matrix[8][1]=10*x[i][1]; q_2_G_3_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->C5_serial) { q_2_G_3_matrix[3][0]=10*x[i][0]; q_2_G_3_matrix[3][1]=10*x[i][1]; q_2_G_3_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->C6_serial) { q_2_G_3_matrix[4][0]=10*x[i][0]; q_2_G_3_matrix[4][1]=10*x[i][1]; q_2_G_3_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->C8_serial) { q_2_G_3_matrix[1][0]=10*x[i][0]; q_2_G_3_matrix[1][1]=10*x[i][1]; q_2_G_3_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->N1_serial) { q_2_G_3_matrix[5][0]=10*x[i][0]; q_2_G_3_matrix[5][1]=10*x[i][1]; q_2_G_3_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->N3_serial) { q_2_G_3_matrix[7][0]=10*x[i][0]; q_2_G_3_matrix[7][1]=10*x[i][1]; q_2_G_3_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->N7_serial) { q_2_G_3_matrix[2][0]=10*x[i][0]; q_2_G_3_matrix[2][1]=10*x[i][1]; q_2_G_3_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_3->N9_serial) { q_2_G_3_matrix[0][0]=10*x[i][0]; q_2_G_3_matrix[0][1]=10*x[i][1]; q_2_G_3_matrix[0][2]=10*x[i][2]; } //q_2_G_4 if((i+1)==bs_q_2_G_4->C2_serial) { q_2_G_4_matrix[6][0]=10*x[i][0]; q_2_G_4_matrix[6][1]=10*x[i][1]; q_2_G_4_matrix[6][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->C4_serial) { q_2_G_4_matrix[8][0]=10*x[i][0]; q_2_G_4_matrix[8][1]=10*x[i][1]; q_2_G_4_matrix[8][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->C5_serial) { q_2_G_4_matrix[3][0]=10*x[i][0]; q_2_G_4_matrix[3][1]=10*x[i][1]; q_2_G_4_matrix[3][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->C6_serial) { q_2_G_4_matrix[4][0]=10*x[i][0]; q_2_G_4_matrix[4][1]=10*x[i][1]; q_2_G_4_matrix[4][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->C8_serial) { q_2_G_4_matrix[1][0]=10*x[i][0]; q_2_G_4_matrix[1][1]=10*x[i][1]; q_2_G_4_matrix[1][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->N1_serial) { q_2_G_4_matrix[5][0]=10*x[i][0]; q_2_G_4_matrix[5][1]=10*x[i][1]; q_2_G_4_matrix[5][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->N3_serial) { q_2_G_4_matrix[7][0]=10*x[i][0]; q_2_G_4_matrix[7][1]=10*x[i][1]; q_2_G_4_matrix[7][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->N7_serial) { q_2_G_4_matrix[2][0]=10*x[i][0]; q_2_G_4_matrix[2][1]=10*x[i][1]; q_2_G_4_matrix[2][2]=10*x[i][2]; } if((i+1)==bs_q_2_G_4->N9_serial) { q_2_G_4_matrix[0][0]=10*x[i][0]; q_2_G_4_matrix[0][1]=10*x[i][1]; q_2_G_4_matrix[0][2]=10*x[i][2]; } } double ** q_1_G_1_rotation_matrix; double ** q_1_G_2_rotation_matrix; double ** q_1_G_3_rotation_matrix; double ** q_1_G_4_rotation_matrix; double ** q_2_G_1_rotation_matrix; double ** q_2_G_2_rotation_matrix; double ** q_2_G_3_rotation_matrix; double ** q_2_G_4_rotation_matrix; q_1_G_1_rotation_matrix=dmatrix(0,2,0,2); q_1_G_2_rotation_matrix=dmatrix(0,2,0,2); q_1_G_3_rotation_matrix=dmatrix(0,2,0,2); q_1_G_4_rotation_matrix=dmatrix(0,2,0,2); q_2_G_1_rotation_matrix=dmatrix(0,2,0,2); q_2_G_2_rotation_matrix=dmatrix(0,2,0,2); q_2_G_3_rotation_matrix=dmatrix(0,2,0,2); q_2_G_4_rotation_matrix=dmatrix(0,2,0,2); Rotation_matrix(q_1_G_1_matrix,'G',q_1_G_1_rotation_matrix); Rotation_matrix(q_1_G_2_matrix,'G',q_1_G_2_rotation_matrix); Rotation_matrix(q_1_G_3_matrix,'G',q_1_G_3_rotation_matrix); Rotation_matrix(q_1_G_4_matrix,'G',q_1_G_4_rotation_matrix); Rotation_matrix(q_2_G_1_matrix,'G',q_2_G_1_rotation_matrix); Rotation_matrix(q_2_G_2_matrix,'G',q_2_G_2_rotation_matrix); Rotation_matrix(q_2_G_3_matrix,'G',q_2_G_3_rotation_matrix); Rotation_matrix(q_2_G_4_matrix,'G',q_2_G_4_rotation_matrix); //以q_1_G_1为基准,校正z-axis的方向。 double * vector_q_1_G_1; double * vector_q_1_G_2; double * vector_q_1_G_3; double * vector_q_1_G_4; double * vector_q_2_G_1; double * vector_q_2_G_2; double * vector_q_2_G_3; double * vector_q_2_G_4; vector_q_1_G_1=dvector(0,2); vector_q_1_G_2=dvector(0,2); vector_q_1_G_3=dvector(0,2); vector_q_1_G_4=dvector(0,2); vector_q_2_G_1=dvector(0,2); vector_q_2_G_2=dvector(0,2); vector_q_2_G_3=dvector(0,2); vector_q_2_G_4=dvector(0,2); for(int i=0;i<3;i++) { vector_q_1_G_1[i]=q_1_G_1_rotation_matrix[i][2]; vector_q_1_G_2[i]=q_1_G_2_rotation_matrix[i][2]; vector_q_1_G_3[i]=q_1_G_3_rotation_matrix[i][2]; vector_q_1_G_4[i]=q_1_G_4_rotation_matrix[i][2]; vector_q_2_G_1[i]=q_2_G_1_rotation_matrix[i][2]; vector_q_2_G_2[i]=q_2_G_2_rotation_matrix[i][2]; vector_q_2_G_3[i]=q_2_G_3_rotation_matrix[i][2]; vector_q_2_G_4[i]=q_2_G_4_rotation_matrix[i][2]; } if(dot_product_vector(vector_q_1_G_1,vector_q_1_G_2,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_1_G_2_rotation_matrix[j][i]= - q_1_G_2_rotation_matrix[j][i]; } } } if(dot_product_vector(vector_q_1_G_1,vector_q_1_G_3,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_1_G_3_rotation_matrix[j][i]= - q_1_G_3_rotation_matrix[j][i]; } } } if(dot_product_vector(vector_q_1_G_1,vector_q_1_G_4,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_1_G_4_rotation_matrix[j][i]= - q_1_G_4_rotation_matrix[j][i]; } } } if(dot_product_vector(vector_q_1_G_1,vector_q_2_G_1,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_2_G_1_rotation_matrix[j][i]= - q_2_G_1_rotation_matrix[j][i]; } } } if(dot_product_vector(vector_q_1_G_1,vector_q_2_G_2,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_2_G_2_rotation_matrix[j][i]= - q_2_G_2_rotation_matrix[j][i]; } } } if(dot_product_vector(vector_q_1_G_1,vector_q_2_G_3,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_2_G_3_rotation_matrix[j][i]= - q_2_G_3_rotation_matrix[j][i]; } } } if(dot_product_vector(vector_q_1_G_1,vector_q_2_G_4,3)<0) { for(int i=1;i<3;i++) { for(int j=0;j<3;j++) { q_2_G_4_rotation_matrix[j][i]= - q_2_G_4_rotation_matrix[j][i]; } } } free_dvector(vector_q_1_G_1,0,2); free_dvector(vector_q_1_G_2,0,2); free_dvector(vector_q_1_G_3,0,2); free_dvector(vector_q_1_G_4,0,2); free_dvector(vector_q_2_G_1,0,2); free_dvector(vector_q_2_G_2,0,2); free_dvector(vector_q_2_G_3,0,2); free_dvector(vector_q_2_G_4,0,2); //get the origin position of 8 guanine. double * origin_vector_q_1_G_1; double * origin_vector_q_1_G_2; double * origin_vector_q_1_G_3; double * origin_vector_q_1_G_4; double * origin_vector_q_2_G_1; double * origin_vector_q_2_G_2; double * origin_vector_q_2_G_3; double * origin_vector_q_2_G_4; origin_vector_q_1_G_1=dvector(0,2); origin_vector_q_1_G_2=dvector(0,2); origin_vector_q_1_G_3=dvector(0,2); origin_vector_q_1_G_4=dvector(0,2); origin_vector_q_2_G_1=dvector(0,2); origin_vector_q_2_G_2=dvector(0,2); origin_vector_q_2_G_3=dvector(0,2); origin_vector_q_2_G_4=dvector(0,2); origin_vector(q_1_G_1_matrix,q_1_G_1_rotation_matrix,'G',origin_vector_q_1_G_1); origin_vector(q_1_G_2_matrix,q_1_G_2_rotation_matrix,'G',origin_vector_q_1_G_2); origin_vector(q_1_G_3_matrix,q_1_G_3_rotation_matrix,'G',origin_vector_q_1_G_3); origin_vector(q_1_G_4_matrix,q_1_G_4_rotation_matrix,'G',origin_vector_q_1_G_4); origin_vector(q_2_G_1_matrix,q_2_G_1_rotation_matrix,'G',origin_vector_q_2_G_1); origin_vector(q_2_G_2_matrix,q_2_G_2_rotation_matrix,'G',origin_vector_q_2_G_2); origin_vector(q_2_G_3_matrix,q_2_G_3_rotation_matrix,'G',origin_vector_q_2_G_3); origin_vector(q_2_G_4_matrix,q_2_G_4_rotation_matrix,'G',origin_vector_q_2_G_4); //get the z-axis vector_q_1_G_1=dvector(0,2); vector_q_1_G_2=dvector(0,2); vector_q_1_G_3=dvector(0,2); vector_q_1_G_4=dvector(0,2); vector_q_2_G_1=dvector(0,2); vector_q_2_G_2=dvector(0,2); vector_q_2_G_3=dvector(0,2); vector_q_2_G_4=dvector(0,2); for(int i=0;i<3;i++) { vector_q_1_G_1[i]=q_1_G_1_rotation_matrix[i][2]; vector_q_1_G_2[i]=q_1_G_2_rotation_matrix[i][2]; vector_q_1_G_3[i]=q_1_G_3_rotation_matrix[i][2]; vector_q_1_G_4[i]=q_1_G_4_rotation_matrix[i][2]; vector_q_2_G_1[i]=q_2_G_1_rotation_matrix[i][2]; vector_q_2_G_2[i]=q_2_G_2_rotation_matrix[i][2]; vector_q_2_G_3[i]=q_2_G_3_rotation_matrix[i][2]; vector_q_2_G_4[i]=q_2_G_4_rotation_matrix[i][2]; // cout<<vector_q_1_G_1[i]<<endl; //for test // cout<<vector_q_1_G_2[i]<<endl; //for test // cout<<vector_q_1_G_3[i]<<endl; //for test // cout<<vector_q_1_G_4[i]<<endl; //for test // cout<<vector_q_2_G_1[i]<<endl; //for test // cout<<vector_q_2_G_2[i]<<endl; //for test // cout<<vector_q_2_G_3[i]<<endl; //for test // cout<<vector_q_2_G_4[i]<<endl; //for test } double * vector_q_1_G_1_2; double * vector_q_1_G_3_4; double * vector_q_1_G_1_2_3_4; double * vector_q_2_G_1_2; double * vector_q_2_G_3_4; double * vector_q_2_G_1_2_3_4; double * vector_orientation; vector_q_1_G_1_2=dvector(0,2); vector_q_1_G_3_4=dvector(0,2); vector_q_1_G_1_2_3_4=dvector(0,2); vector_q_2_G_1_2=dvector(0,2); vector_q_2_G_3_4=dvector(0,2); vector_q_2_G_1_2_3_4=dvector(0,2); vector_orientation=dvector(0,2); rotate_2_vector(vector_q_1_G_1,vector_q_1_G_2, vector_q_1_G_1_2); // for test // for(int i=0;i<3;i++) // { // cout<<vector_q_1_G_1_2[i]<<endl; // } // rotate_2_vector(vector_q_1_G_3,vector_q_1_G_4,vector_q_1_G_3_4); rotate_2_vector(vector_q_2_G_1,vector_q_2_G_2,vector_q_2_G_1_2); rotate_2_vector(vector_q_2_G_3,vector_q_2_G_4,vector_q_2_G_3_4); rotate_2_vector(vector_q_1_G_1_2,vector_q_1_G_3_4,vector_q_1_G_1_2_3_4); rotate_2_vector(vector_q_2_G_1_2,vector_q_2_G_3_4,vector_q_2_G_1_2_3_4); rotate_2_vector(vector_q_1_G_1_2_3_4,vector_q_2_G_1_2_3_4,vector_orientation); //for test /* for(int i=0;i<3;i++) { cout<<vector_orientation[i]<<endl; } */ // //get the center position. double * center_position_vector; double * center_1; double * center_2; double * vector_2_ion; double * vector_1_2; center_position_vector=dvector(0,2); vector_2_ion=dvector(0,2); center_1=dvector(0,2); center_2=dvector(0,2); vector_1_2=dvector(0,2); for(int i=0;i<3;i++) { center_position_vector[i]=(origin_vector_q_1_G_1[i]+origin_vector_q_1_G_2[i]+origin_vector_q_1_G_3[i]+origin_vector_q_1_G_4[i]+origin_vector_q_2_G_1[i]+origin_vector_q_2_G_2[i]+origin_vector_q_2_G_3[i]+origin_vector_q_2_G_4[i])/8; center_1[i]=(origin_vector_q_1_G_1[i]+origin_vector_q_1_G_2[i]+origin_vector_q_1_G_3[i]+origin_vector_q_1_G_4[i])/4; center_2[i]=(origin_vector_q_2_G_1[i]+origin_vector_q_2_G_2[i]+origin_vector_q_2_G_3[i]+origin_vector_q_2_G_4[i])/4; vector_2_ion[i]=ion_coor[i]-center_position_vector[i]; vector_1_2[i]=center_1[i]-center_2[i]; } double length=0; double dist_z=0; double dist=0; length=dot_product_vector(vector_orientation,vector_2_ion,3); dist_z=dot_product_vector(vector_orientation,vector_1_2,3); dist=sqrt(dot_product_vector(vector_1_2,vector_1_2,3)); // out<<fixed<<showpoint; out<<time_temp<<"\t"<<setprecision(4)<<fabs(length)<<"\t"<<setprecision(4)<<dist<<"\t"<<setprecision(4)<<fabs(dist_z)<<endl; free_dmatrix(q_1_G_1_matrix,0,2,0,8); free_dmatrix(q_1_G_2_matrix,0,2,0,8); free_dmatrix(q_1_G_3_matrix,0,2,0,8); free_dmatrix(q_1_G_4_matrix,0,2,0,8); free_dmatrix(q_2_G_1_matrix,0,2,0,8); free_dmatrix(q_2_G_2_matrix,0,2,0,8); free_dmatrix(q_2_G_3_matrix,0,2,0,8); free_dmatrix(q_2_G_4_matrix,0,2,0,8); free_dmatrix(q_1_G_1_rotation_matrix,0,2,0,2); free_dmatrix(q_1_G_2_rotation_matrix,0,2,0,2); free_dmatrix(q_1_G_3_rotation_matrix,0,2,0,2); free_dmatrix(q_1_G_4_rotation_matrix,0,2,0,2); free_dmatrix(q_2_G_1_rotation_matrix,0,2,0,2); free_dmatrix(q_2_G_2_rotation_matrix,0,2,0,2); free_dmatrix(q_2_G_3_rotation_matrix,0,2,0,2); free_dmatrix(q_2_G_4_rotation_matrix,0,2,0,2); free_dvector(vector_q_1_G_1,0,2); free_dvector(vector_q_1_G_2,0,2); free_dvector(vector_q_1_G_3,0,2); free_dvector(vector_q_1_G_4,0,2); free_dvector(vector_q_2_G_1,0,2); free_dvector(vector_q_2_G_2,0,2); free_dvector(vector_q_2_G_3,0,2); free_dvector(vector_q_2_G_4,0,2); free_dvector(origin_vector_q_1_G_1,0,2); free_dvector(origin_vector_q_1_G_2,0,2); free_dvector(origin_vector_q_1_G_3,0,2); free_dvector(origin_vector_q_1_G_4,0,2); free_dvector(origin_vector_q_2_G_1,0,2); free_dvector(origin_vector_q_2_G_2,0,2); free_dvector(origin_vector_q_2_G_3,0,2); free_dvector(origin_vector_q_2_G_4,0,2); free_dvector(vector_q_1_G_1_2,0,2); free_dvector(vector_q_1_G_3_4,0,2); free_dvector(vector_q_1_G_1_2_3_4,0,2); free_dvector(vector_q_2_G_1_2,0,2); free_dvector(vector_q_2_G_3_4,0,2); free_dvector( vector_q_2_G_1_2_3_4,0,2); free_dvector( vector_orientation,0,2); } } xdrfile_close(xtc); out.close(); }
void ReadWrite(char *rfile, char *wfile, int in_xtcBool, int out_xtcBool, int in_trrBool, int out_trrBool) { XDRFILE *xd_read, *xd_write; int result_xtc, result_trr; int natoms_xtc, natoms_trr; int step_xtc, step_trr; float time_xtc, time_trr; matrix box_xtc, box_trr; rvec *x_xtc, *x_trr, *v_trr, *f_trr; float prec_xtc = 1000.0; float lambda_trr = 0.0; xd_read = xdrfile_open(rfile, "r"); if (NULL == xd_read) die("Opening xdrfile for reading"); /* Test whether output file exists */ if ((xd_write = xdrfile_open(wfile,"r")) != NULL) { xdrfile_close(xd_write); die("Output file exists."); } /* Output file does not exist. Now we can open it for writing */ xd_write = xdrfile_open(wfile, "w"); if (NULL == xd_write) die("Opening xdrfile for writing"); /* .xtc -> .xtc */ if(in_xtcBool && out_xtcBool) { result_xtc = read_xtc_natoms(rfile, &natoms_xtc); if (exdrOK != result_xtc) die_r("read_xtc_natoms",result_xtc); x_xtc = (rvec *)calloc(natoms_xtc, sizeof(x_xtc[0])); while(1) { result_xtc = read_xtc(xd_read, natoms_xtc, &step_xtc, &time_xtc, box_xtc, x_xtc, &prec_xtc); if (result_xtc == 0) // if not reach the end of file, write it to the output.xtc file { if (exdrOK != result_xtc) die_r("Reading xtc file", result_xtc); result_xtc = write_xtc(xd_write, natoms_xtc, step_xtc, time_xtc, box_xtc, x_xtc, prec_xtc); if (result_xtc != 0) die_r("Writing xtc file", result_xtc); } else break; } } /* .xtc -> .trr */ if(in_xtcBool && out_trrBool) { result_xtc = read_xtc_natoms(rfile, &natoms_xtc); if (exdrOK != result_xtc) die_r("read_xtc_natoms",result_xtc); x_xtc = (rvec *)calloc(natoms_xtc, sizeof(x_xtc[0])); while(1) { result_xtc = read_xtc(xd_read, natoms_xtc, &step_xtc, &time_xtc, box_xtc, x_xtc, &prec_xtc); if (result_xtc == 0) // if not reach the end of file, write it to the output.trr file { if (exdrOK != result_xtc) die_r("Reading xtc file", result_xtc); result_trr = write_trr(xd_write, natoms_xtc, step_xtc, time_xtc, lambda_trr, box_xtc, x_xtc, NULL, NULL); if (0 != result_trr) die_r("Writing trr file",result_trr); } else break; } } /* .trr -> .trr */ if(in_trrBool && out_trrBool) { result_trr = read_trr_natoms(rfile, &natoms_trr); if (exdrOK != result_trr) die_r("read_trr_natoms",result_trr); x_trr = (rvec *)calloc(natoms_trr, sizeof(x_trr[0])); v_trr = (rvec *)calloc(natoms_trr, sizeof(v_trr[0])); f_trr = (rvec *)calloc(natoms_trr, sizeof(f_trr[0])); while (1) { result_trr = read_trr(xd_read, natoms_trr, &step_trr, &time_trr, &lambda_trr, box_trr, x_trr, v_trr, f_trr); int ii_trr, jj_trr, x_ck=0, v_ck=0, f_ck=0; int x_ck_bool=0, v_ck_bool=0, f_ck_bool=0; for (ii_trr = 0; ii_trr < natoms_trr; ii_trr++) { for(jj_trr = 0; jj_trr < DIM; jj_trr++) { if (x_trr[ii_trr][jj_trr] == 0) x_ck++; if (v_trr[ii_trr][jj_trr] == 0) v_ck++; if (f_trr[ii_trr][jj_trr] == 0) f_ck++; } } if (x_ck == natoms_trr*DIM) x_ck_bool = 1; if (v_ck == natoms_trr*DIM) v_ck_bool = 1; if (f_ck == natoms_trr*DIM) f_ck_bool = 1; if (result_trr == 0) // if not reach the end of file, write it to the output.trr file { if (exdrOK != result_trr) die_r("Reading trr file",result_trr); if(v_ck_bool && f_ck_bool) result_trr = write_trr(xd_write, natoms_trr, step_trr, time_trr, lambda_trr, box_trr, x_trr, NULL, NULL); else if(v_ck_bool) result_trr = write_trr(xd_write, natoms_trr, step_trr, time_trr, lambda_trr, box_trr, x_trr, NULL, f_trr); else if(f_ck_bool) result_trr = write_trr(xd_write, natoms_trr, step_trr, time_trr, lambda_trr, box_trr, x_trr, v_trr, NULL); else result_trr = write_trr(xd_write, natoms_trr, step_trr, time_trr, lambda_trr, box_trr, x_trr, v_trr, f_trr); if (0 != result_trr) die_r("Writing trr file",result_trr); } else break; } } /* .trr -> .xtc */ if(in_trrBool && out_xtcBool) { result_trr = read_trr_natoms(rfile, &natoms_trr); if (exdrOK != result_trr) die_r("read_trr_natoms",result_trr); x_trr = (rvec *)calloc(natoms_trr, sizeof(x_trr[0])); v_trr = (rvec *)calloc(natoms_trr, sizeof(v_trr[0])); f_trr = (rvec *)calloc(natoms_trr, sizeof(f_trr[0])); while(1) { result_trr = read_trr(xd_read, natoms_trr, &step_trr, &time_trr, &lambda_trr, box_trr, x_trr, v_trr, f_trr); if (result_trr == 0) // if not reach the end of file, write it to the output.trr file { if (exdrOK != result_trr) die_r("Reading trr file", result_trr); result_xtc = write_xtc(xd_write, natoms_trr, step_trr, time_trr, box_trr, x_trr, prec_xtc); if (result_xtc != 0) die_r("Writing xtc file", result_xtc); } else break; } } xdrfile_close(xd_read); xdrfile_close(xd_write); }
int main (int argc, char *argv[]) { int st; SimParams params; enum RdfWeighting { kNone, kTotalDipole, kPermanentDipole, kInducedDipole }; po::options_description desc("Options"); desc.add_options() ("help,h", "Print help messages") ("group1", po::value<std::string>()->required(), "Group around which rdf is centered") ("group2", po::value<std::string>()->required(), "Group for which rdf will be calculated around the positions of group 1") ("index,n", po::value<std::string>()->default_value("index.ndx"), ".ndx file containing atomic indices for groups") ("gro", po::value<std::string>()->default_value("conf.gro"), ".gro file containing list of atoms/molecules") ("top", po::value<std::string>()->default_value("topol.top"), ".top file containing atomic/molecular properties") ("output,o", po::value<std::string>()->default_value("rdf.txt"), "Name for output file.") ("max_time,t", po::value<double>()->default_value(0.0), "Maximum simulation time to use in calculations") ("rdf_weighting,w", po::value<std::string>()->default_value("none"), "weighting factor for rdf. Choose from 'none', 'dipole', " "'permanent_dipole', and 'induced_dipole'"); 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"; exit(EXIT_SUCCESS); } RdfWeighting rdf_weighting; bool need_field = false; if (vm["rdf_weighting"].as<std::string>() == "none") { rdf_weighting = kNone; } else if (vm["rdf_weighting"].as<std::string>() == "dipole") { rdf_weighting = kTotalDipole; need_field = true; } else if (vm["rdf_weighting"].as<std::string>() == "permanent_dipole") { rdf_weighting = kPermanentDipole; } else if (vm["rdf_weighting"].as<std::string>() == "induced_dipole") { rdf_weighting = kInducedDipole; need_field = true; } std::map<std::string, std::vector<int> > groups; groups = ReadNdx(vm["index"].as<std::string>()); std::vector<Molecule> molecules = GenMolecules(vm["top"].as<std::string>(), params); SystemGroup all_atoms(vm["gro"].as<std::string>(), molecules); SubsystemGroup *first_group_pointer = SubsystemGroup::MakeSubsystemGroup( vm["group1"].as<std::string>(), SelectGroup(groups, vm["group1"].as<std::string>()), all_atoms); SubsystemGroup &first_group = *first_group_pointer; SubsystemGroup *second_group_pointer = SubsystemGroup::MakeSubsystemGroup( vm["group2"].as<std::string>(), SelectGroup(groups, vm["group2"].as<std::string>()), all_atoms); SubsystemGroup &second_group = *second_group_pointer; rvec *x_in = NULL; matrix box_mat; arma::rowvec box = arma::zeros<arma::rowvec>(DIMS); std::string xtc_filename = "prod.xtc"; XDRFILE *xtc_file; params.ExtractTrajMetadata(strdup(xtc_filename.c_str()), (&x_in), box); xtc_file = xdrfile_open(strdup(xtc_filename.c_str()), "r"); params.set_box(box); params.set_max_time(vm["max_time"].as<double>()); if (need_field) second_group.OpenFieldFile(); Histogram rdf_hist(params.box(0)/2.0/0.05, 0.05); arma::rowvec dx, dipole; float time, prec; int step = 0; double avg_volume; for (step = 0; step < params.max_steps(); ++step) { if(read_xtc(xtc_file, params.num_atoms(), &st, &time, box_mat, x_in, &prec)) break; params.set_box(box_mat); avg_volume += params.volume(); first_group.set_positions(x_in); second_group.set_positions(x_in); if (need_field) { second_group.SetElectricField(all_atoms, params.box()); if (!second_group.field_check()) second_group.WriteElectricField(); } second_group.UpdateCom(); for (int i_other = 0; i_other < second_group.num_molecules(); ++i_other) { switch(rdf_weighting) { case kPermanentDipole: second_group.PermanentDipole(i_other, params.box(), dipole, true); dipole *= ENM_TO_D; break; case kInducedDipole: second_group.InducedDipole(i_other, dipole, true); dipole *= ENM_TO_D; break; case kTotalDipole: second_group.PermanentDipole(i_other, params.box(), dipole, true); second_group.InducedDipole(i_other, dipole); dipole *= ENM_TO_D; break; default: break; } for (int i_atom = 0; i_atom < first_group.size(); ++i_atom) { FindDxNoShift(dx, first_group.position(i_atom), second_group.com_position(i_other), params.box()); double distance = arma::norm(dx); double weight; if (rdf_weighting == kTotalDipole || rdf_weighting == kInducedDipole || rdf_weighting == kPermanentDipole) { dx = arma::normalise(dx); weight = arma::dot(dx,dipole); } else { weight = 1.0; } rdf_hist.Add(distance, weight); } } } xdrfile_close(xtc_file); avg_volume /= step; rdf_hist.Multiply(1.0/avg_volume/step/first_group.size()/ second_group.num_molecules()); rdf_hist.WeightByShellVolume(); rdf_hist.Print(vm["output"].as<std::string>(), true); }
int main(int argc, char * argv[]) { ValueType begin, end, rup, refh, cellSize; std::string ifile, ofile, method; ValueType x0, x1; po::options_description desc ("Allow options"); desc.add_options() ("help,h", "print this message") ("begin,b", po::value<ValueType > (&begin)->default_value(0.f), "start time") ("end,e", po::value<ValueType > (&end )->default_value(0.f), "end time") ("x0", po::value<ValueType > (&x0)->default_value(0.f), "lower bound of the interval") ("x1", po::value<ValueType > (&x1)->default_value(1.f), "upper bound of the interval, if x1 == 0, use the whole box") ("rup,u", po::value<ValueType > (&rup)->default_value(3.f), "max r to make rdf") ("refh", po::value<ValueType > (&refh)->default_value(0.01f), "bin size") ("cell-size,c", po::value<ValueType > (&cellSize)->default_value(1.f), "cell list radius") ("method,m", po::value<std::string > (&method)->default_value ("adress"), "type of simulation to analyze") ("input,f", po::value<std::string > (&ifile)->default_value ("traj.xtc"), "the input .xtc file") ("output,o", po::value<std::string > (&ofile)->default_value ("rdf.out"), "the output 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 (x0 > x1) { ValueType tmpx = x0; x0 = x1; x1 = tmpx; } std::cout << "###################################################" << std::endl; std::cout << "# begin->end: " << begin << " " << end << std::endl; std::cout << "# [x0, x1 ]: " << x0 << " " << x1 << std::endl; std::cout << "# rup: " << rup << std::endl; std::cout << "# refh: " << refh << std::endl; std::cout << "# method: " << method << std::endl; std::cout << "# input: " << ifile << std::endl; std::cout << "###################################################" << std::endl; XDRFILE *fp; int natoms, step; float time; matrix box; rvec * xx; float prec = 1000; float time_prec = .01; char tmpfname[1024]; strncpy (tmpfname, ifile.c_str(), 1023); int c; if ((c = read_xtc_natoms (tmpfname, &natoms)) == 0) { // printf ("%d %d\n", c, natoms); xx = (rvec *) malloc (sizeof(rvec) * natoms); } else { // printf ("%d %d\n", c, natoms); fprintf (stderr, "error read_xtc_natoms"); exit (1); } fp = xdrfile_open (ifile.c_str(), "r"); if (fp == NULL){ std::cerr << "cannot open file " << ifile << std::endl; exit (1); } if (read_xtc (fp, natoms, &step, &time, box, xx, &prec) != 0) { std::cerr << "error reading file " << ifile << std::endl; return 1; } int nmolecules = 0; if (method == std::string("adress")){ nmolecules = natoms / 4; } else if (method == std::string("atom")){ nmolecules = natoms / 3; } else if (method == std::string("cg")){ nmolecules = natoms; } else { std::cerr << "wrong method" << std::endl; return 1; } VectorType vbox; vbox.x = box[0][0]; vbox.y = box[1][1]; vbox.z = box[2][2]; if (cellSize >= .5 * vbox.x){ std::cerr << "the cell size should be less than half of the box size" << std::endl; return 1; } std::vector<std::vector<ValueType > > coms; coms.reserve (nmolecules); CellList clist (nmolecules, vbox, cellSize); Rdf myrdf; myrdf.reinit (rup, refh, x0, x1); int countread = 0; while (read_xtc (fp, natoms, &step, &time, box, xx, &prec) == 0){ 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); } coms.clear (); if (method == std::string ("adress")){ int nmol = natoms / 4; for (int i = 0; i < nmol; ++i){ if (xx[i*4+3][0] < 0 ) xx[i*4+3][0] += box[0][0]; else if (xx[i*4+3][0] >= box[0][0]) xx[i*4+3][0] -= box[0][0]; if (xx[i*4+3][1] < 0 ) xx[i*4+3][1] += box[1][1]; else if (xx[i*4+3][1] >= box[1][1]) xx[i*4+3][1] -= box[1][1]; if (xx[i*4+3][2] < 0 ) xx[i*4+3][2] += box[2][2]; else if (xx[i*4+3][2] >= box[2][2]) xx[i*4+3][2] -= box[2][2]; std::vector<ValueType > tmp(3); tmp[0] = xx[i*4+3][0]; tmp[1] = xx[i*4+3][1]; tmp[2] = xx[i*4+3][2]; coms.push_back(tmp); } } else if (method == std::string ("atom")){ int nmol = natoms / 3; for (int i = 0; i < nmol; ++i){ std::vector<ValueType > com(3, 0.); for (int dd = 0; dd < 3; ++dd){ ValueType dx1, dx2; dx1 = xx[i*3+1][dd] - xx[i*3+0][dd]; dx2 = xx[i*3+2][dd] - xx[i*3+0][dd]; if (dx1 > 0.5 * box[dd][dd]) {dx1 -= box[dd][dd]; printf ("hit\n");} if (dx1 <-0.5 * box[dd][dd]) {dx1 += box[dd][dd]; printf ("hit\n");} if (dx2 > 0.5 * box[dd][dd]) {dx2 -= box[dd][dd]; printf ("hit\n");} if (dx2 <-0.5 * box[dd][dd]) {dx2 += box[dd][dd]; printf ("hit\n");} com[dd] = 16. * xx[i*3+0][dd] + 1. * (xx[i*3+0][dd] + dx1) + 1. * (xx[i*3+0][dd] + dx2); com[dd] /= 18.; if (com[dd] < 0 ) com[dd] += box[dd][dd]; else if (com[dd] >= box[dd][dd]) com[dd] -= box[dd][dd]; } coms.push_back (com); } } else if (method == std::string ("cg")){ int nmol = natoms; for (int i = 0; i < nmol; ++i){ if (xx[i][0] < 0 ) xx[i][0] += box[0][0]; else if (xx[i][0] >= box[0][0]) xx[i][0] -= box[0][0]; if (xx[i][1] < 0 ) xx[i][1] += box[1][1]; else if (xx[i][1] >= box[1][1]) xx[i][1] -= box[1][1]; if (xx[i][2] < 0 ) xx[i][2] += box[2][2]; else if (xx[i][2] >= box[2][2]) xx[i][2] -= box[2][2]; std::vector<ValueType > tmp(3); tmp[0] = xx[i][0]; tmp[1] = xx[i][1]; tmp[2] = xx[i][2]; coms.push_back(tmp); } } clist.rebuild (coms); myrdf.deposit (coms, vbox, clist); } printf ("\n"); xdrfile_close (fp); free (xx); myrdf.calculate(); FILE *fout = fopen (ofile.c_str(), "w"); if (fout == NULL){ std::cerr << "cannot open file " << ofile << std::endl; exit (1); } fprintf (fout, "%f %f\n", 0., myrdf.getValue(0)); for (unsigned i = 1; i < myrdf.getN(); ++i){ fprintf (fout, "%f %f\n", (i) * refh, myrdf.getValue(i)); } fclose (fout); return 0; }
vector<double> read_xtc2dist(char * filename,vector<int> serial_1,vector<int> serial_2,vector<double> mass_1,vector<double> mass_2) { int natoms,step; float time_temp; float p; vector<double> coor_x; vector<double> coor_y; vector<double> coor_z; vector<double> result; matrix box; rvec *x; XDRFILE *xtc; xtc=xdrfile_open(filename,"r"); int read_return=read_xtc_natoms(filename,&natoms); x=(rvec * )calloc(natoms,sizeof(x[0])); while(1) { read_return=read_xtc(xtc,natoms,&step,&time_temp,box,x,&p); if(step%100000==0) { cout<<"Reading frame"<<"\t"<<step<<" time "<<time_temp<<endl; } if(read_return!=0) { break; } coor_x.clear(); coor_y.clear(); coor_z.clear(); for(int i=0;i<serial_1.size();i++) { // cout<<step<<"\t"<<time_temp<<"\t"<<natom<<"\t"<<x[natom][0]<<"\t"<<x[natom][1]<<"\t"<<x[natom][2]<<endl; int natom=serial_1.at(i); coor_x.push_back(x[natom][0]); coor_y.push_back(x[natom][1]); coor_z.push_back(x[natom][2]); } vector<double> cent_1 =get_center(coor_x,coor_y,coor_z,mass_1); coor_x.clear(); coor_y.clear(); coor_z.clear(); for(int i=0;i<serial_2.size();i++) { int natom=serial_2.at(i); coor_x.push_back(x[natom][0]); coor_y.push_back(x[natom][1]); coor_z.push_back(x[natom][2]); } vector<double> cent_2 =get_center(coor_x,coor_y,coor_z,mass_2); double dist_temp=get_dist(cent_1,cent_2); result.push_back(time_temp); result.push_back(dist_temp); } xdrfile_close(xtc); return result; }
static void test_xtc() { char *testfn = "test.xtc"; XDRFILE *xd; int result,i,j,k,nframes=13; int natoms2,natoms1=173; int step2,step1=1993; float time2,time1=1097.23; matrix box2,box1; rvec *x2,*x1; float prec2,prec1=1000; float toler=1e-3; printf("Testing xtc functionality:"); for(i=0; (i<DIM); i++) for(j=0; (j<DIM); j++) box1[i][j] = (i+1)*3.7 + (j+1); x1 = calloc(natoms1,sizeof(*x1)); if (NULL == x1) die("Allocating memory for x1 in test_xtc"); for(i=0; (i<natoms1); i++) for(j=0; (j<DIM); j++) x1[i][j] = (i+1)*3.7 + (j+1); xd = xdrfile_open(testfn,"w"); if (NULL == xd) die("Opening xdrfile for writing"); for(k=0; (k<nframes); k++) { result = write_xtc(xd,natoms1,step1+k,time1+k,box1,x1,prec1); if (0 != result) die_r("Writing xtc file",result); } xdrfile_close(xd); result = read_xtc_natoms(testfn,&natoms2); if (exdrOK != result) die_r("read_xtc_natoms",result); if (natoms2 != natoms1) die("Number of atoms incorrect when reading trr"); x2 = calloc(natoms2,sizeof(x2[0])); if (NULL == x2) die("Allocating memory for x2"); xd = xdrfile_open(testfn,"r"); if (NULL == xd) die("Opening xdrfile for reading"); k = 0; do { result = read_xtc(xd,natoms2,&step2,&time2,box2,x2,&prec2); if (exdrENDOFFILE != result) { if (exdrOK != result) die_r("read_xtc",result); if (natoms2 != natoms1) die("natoms2 != natoms1"); if (step2-step1 != k) die("incorrect step"); if (fabs(time2-time1-k) > toler) die("incorrect time"); if (fabs(prec2-prec1) > toler) die("incorrect precision"); for(i=0; (i<DIM); i++) for(j=0; (j<DIM); j++) if (fabs(box2[i][j] - box1[i][j]) > toler) die("box incorrect"); for(i=0; (i<natoms1); i++) for(j=0; (j<DIM); j++) if (fabs(x2[i][j] - x1[i][j]) > toler) die("x incorrect"); } k++; } while (result == exdrOK); xdrfile_close(xd); #ifdef HAVE_UNISTD unlink(testfn); #endif printf(" PASSED\n"); }