int read_trr_nframes(char *fn, unsigned long *nframes) { XDRFILE *xd; int result, step; float time, lambda; int natoms; matrix box; rvec *x; *nframes = 0; read_trr_natoms(fn, &natoms); x = malloc(natoms * sizeof(*x)); xd = xdrfile_open(fn, "r"); if (NULL == xd) return exdrFILENOTFOUND; do { result = read_trr(xd, natoms, &step, &time, &lambda, box, x, NULL, NULL); if (exdrENDOFFILE != result) { (*nframes)++; } } while (result == exdrOK); xdrfile_close(xd); free(x); return exdrOK; }
bool TrrLoader:: load () { if (inited){ matrix tmpBox; int st = read_trr (xd, natoms, &step, &time, &lambda, tmpBox, xx, vv, ff); 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; } }
Frame TRR::get_next_frame() { matrix frameMatrix; int i; atom_coordinates = new rvec[this->number_of_atoms]; std::vector<double> x_coordinate(this->number_of_atoms), y_coordinate(this->number_of_atoms), z_coordinate(this->number_of_atoms); return_code = read_trr(this->file, this->number_of_atoms, &step, &time, &precision, frameMatrix, atom_coordinates, nullptr, nullptr); if (return_code == exdrOK) { for (i = 0; i < this->number_of_atoms; i++) { x_coordinate[i] = (double) atom_coordinates[i][0]; y_coordinate[i] = (double) atom_coordinates[i][1]; z_coordinate[i] = (double) atom_coordinates[i][2]; } } else { throw new std::runtime_error("the library for reading trr had return code " + return_code); } Frame frame (x_coordinate,y_coordinate,z_coordinate); return frame; }
int main( int argc, char *argv[] ) { /******************************************************************** * Define variables * ********************************************************************/ /* * Constants * * Source: 2010 CODATA * c (speed of light in vacuum): 299792458 m s^-1 * mu_0 (magnetic constant): 4*pi * 10^-7 N A^-2 (A=Ampere) * e (elementary charge): 1.602176565 * 10^-19 C * nA (Avogadro constant): 6.02214129 * 10^23 mol^-1 * kB (Boltzmann constant): 1.3806488 * 10^-23 J K^-1 * * Coulomb constant k=1/(4*pi*epsilon_0)=c^2*mu_0/(4*pi) * fQQ = 2.99792458^2 * 10^16 * 10^-7 N m^2 C^-2 * = 2.99792458^2 * 6.02214129 * 1.602176565^2 kJ mol^-1 nm e^-2 * = 138.93545782935 * * PI to 20 decimal places: 3.14159265358979323846 */ const double kB = 1.3806488e-3 ; /* 10^-23 kJ K^-1 */ const double fQQ = 138.93545782935 ; /* kJ mol^-1 nm e^-2 */ const double pi = 3.14159265358979323846 ; const double nA = 6.02214129 ; /* 10^23 mol^-1 */ double *averDens, *averPU, *dens, *pU ; /* * frame */ int frame; /* * pair pointers for loop */ long int pair, totalPairs; int *molI, *molJ; /* * center of mass */ double msum ; /* * variables for pair force calculation */ int i, j, im, jm, iMin, iMax, jMin, jMax ; double mi, qi, sigi, epsi, qj, sigj, epsj; /* * variables for xdrfile_trr */ int gmxStep,read_return,gmxNAtoms; float gmxTime,gmxLambda; matrix gmxBox; rvec *x, *v, *f; XDRFILE *trr; /******************************************************************** * Reading parameters from param.txt * ********************************************************************/ FILE *file_par; /* * atom = index of atoms in each molecule * mol = index of molecules in the system */ int mol, atom, molTypes; /* * atomNr = number of atoms in each type of molecule * molNr = number of each type of molecule in the system */ int *atomNr, *molNr, *iAtom, *iMol, *mini, *maxi; char line[256], tmp[256], filenameTRR[256]; double **mass, **charge, **sigma, **epsilon; int k; int nAtoms, nMols; double *molMass; /* * open param.txt */ file_par = fopen("param.txt","r") ; if ( NULL==file_par ) { printf( "<> Error: Cannot open file param.txt !\n" ) ; exit(1); } mol = 0; /* * read comments (two lines) */ fgets( line, sizeof( line ), file_par ); fgets( line, sizeof( line ), file_par ); /* * read name of trr file */ fgets( line, sizeof( line ), file_par ); sscanf( line, "%s%s", tmp, filenameTRR ); /* * read number of molecules */ fgets( line, sizeof( line ), file_par ); sscanf( line, "%s%d", tmp, &molTypes ); atomNr = malloc(molTypes * sizeof(int)); molNr = malloc(molTypes * sizeof(int)); printf ( " There are %d types of molecules:\n", molTypes ); printf ( " %-16s", "MoleculeName" ); for ( mol=0; mol<molTypes; mol++ ) { fgets( line, sizeof( line ), file_par ); sscanf( line, "%s%d", tmp, &molNr[mol] ); printf ( "%8s", tmp ); } printf ( "\n" ); /* * read atomic information */ charge = malloc(molTypes * sizeof(double *)); mass = malloc(molTypes * sizeof(double *)); sigma = malloc(molTypes * sizeof(double *)); epsilon = malloc(molTypes * sizeof(double *)); for ( mol=0; mol<molTypes; mol++ ) { fgets( line, sizeof( line ), file_par ); sscanf( line, "%s%d", tmp, &atomNr[mol] ); charge[mol] = malloc(atomNr[mol] * sizeof(double)); mass[mol] = malloc(atomNr[mol] * sizeof(double)); sigma[mol] = malloc(atomNr[mol] * sizeof(double)); epsilon[mol] = malloc(atomNr[mol] * sizeof(double)); for ( atom=0; atom<atomNr[mol]; atom++ ) { fgets( line, sizeof( line ), file_par ); sscanf( line, "%lf%lf%lf%lf", &charge[mol][atom], &mass[mol][atom], &sigma[mol][atom], &epsilon[mol][atom] ); } } /* * close param.txt */ fclose( file_par ); /* * print number of atoms in each type of molecule */ printf ( " %-16s", "ContainAtoms" ); for ( mol=0; mol<molTypes; mol++ ) { printf ( "%8d", atomNr[mol] ); } printf ( "\n" ); /******************************************************************** * Check number of molecules and atoms in each molecule * ********************************************************************/ /* * calculate total number of atoms and molecules */ nAtoms = 0; nMols = 0; for ( mol=0; mol<molTypes; mol++ ) { nAtoms += molNr[mol]*atomNr[mol]; nMols += molNr[mol]; } iAtom = malloc(nAtoms * sizeof(int)); iMol = malloc(nAtoms * sizeof(int)); /* * determine mass of each type of molecule */ molMass = malloc(molTypes * sizeof(double)); printf ( " %-16s", "MolarMass" ); for ( mol=0; mol<molTypes; mol++ ) { molMass[mol] = 0.0; for ( atom=0; atom<atomNr[mol]; atom++ ) { molMass[mol] += mass[mol][atom]; } printf ( "%8.2f", molMass[mol] ); } printf ( "\n" ); /* * print number of atoms in each type of molecule */ printf ( " %-16s", "N_Molecules" ); for ( mol=0; mol<molTypes; mol++ ) { printf ( "%8d", molNr[mol] ); } printf ( "\n" ); /* * assign atom index and mol index for each atom in the system * i = atom index, j = mol index */ i = 0; j = 0; for ( mol=0; mol<molTypes; mol++ ) { for ( k=0; k<molNr[mol]; k++ ) { for ( atom=0; atom<atomNr[mol]; atom++ ) { iMol[i] = mol; iAtom[i] = atom; i++; } j++; } } if ( nAtoms != i ) { printf("Incorrect number of atoms in the system!\n"); printf("Program stops at assigning atom index and mol index!\n"); exit(1); } if ( nMols != j ) { printf("Incorrect number of molecules in the system!\n"); printf("Program stops at assigning atom index and mol index!\n"); exit(1); } /* * assign starting index and ending index for each molecule in the system * i = atom index, j = mol index */ mini = malloc(nMols * sizeof(int)); maxi = malloc(nMols * sizeof(int)); i = 0; j = 0; for ( mol=0; mol<molTypes; mol++ ) { for ( k=0; k<molNr[mol]; k++ ) { mini[j] = i; i += atomNr[mol]; maxi[j] = i; j++; } } if ( nAtoms != i ) { printf("Incorrect number of atoms in the system!\n"); printf("Program stops at assigning atom index and mol index!\n"); exit(1); } if ( nMols != j ) { printf("Incorrect number of molecules in the system!\n"); printf("Program stops at assigning atom index and mol index!\n"); exit(1); } /******************************************************************** * Allocating arrays * ********************************************************************/ x = calloc(nAtoms,sizeof(x[0])); v = calloc(nAtoms,sizeof(x[0])); f = calloc(nAtoms,sizeof(x[0])); totalPairs = nMols*(nMols-1)/2 ; molI = malloc( sizeof( int ) * totalPairs ); molJ = malloc( sizeof( int ) * totalPairs ); /* * read trr files for coordinates */ trr = xdrfile_open (filenameTRR,"r"); read_trr_natoms (filenameTRR, &gmxNAtoms); /*printf("Total Number of Frames %10d\n", nFrames);*/ /*printf("Starting from Frame %10d\n", nStart);*/ /* * start of loop (frame) */ for (frame=0; frame<2; frame++) { /* * read trr file */ read_return = read_trr (trr,gmxNAtoms,&gmxStep,&gmxTime,&gmxLambda,gmxBox,x,v,f); if (read_return!=0) { printf ("Failed to read trr file!\n"); exit(1); } if (gmxNAtoms!=nAtoms) { printf ("Incorrect number of Atoms!\n"); exit(1); } /* * generate density profile */ for (im=0; im<nMols; im++) { msum = 0.0; iMin = mini[im]; iMax = maxi[im]; for (i=iMin; i<iMax; i++) { mi = mass[iMol[i]][iAtom[i]]; msum += mi; } if ( fabs(msum-molMass[iMol[iMin]])>0.01 ) { printf ("Incorrect molar weight of molecule %d!\n", im); exit(1); } } /* * find all pairs */ pair = 0; for ( im=0; im<nMols-1; im++ ) { for ( jm=im+1; jm<nMols; jm++ ) { molI[pair] = im; molJ[pair] = jm; pair++; } } if ( totalPairs != pair ) { printf ( "Incorrect number of pairs of molecules!\n" ); exit(1); } /* * end of loop (frame) */ } /* * close trajectory file */ xdrfile_close (trr); printf ( " There are %d molecules in total.\n", nMols ); printf ( " There are %d atoms in total.\n", nAtoms ); /***************************************************************************** * End of function main * *****************************************************************************/ return 0; }
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); }
static void test_trr() { char *testfn = "test.trr"; 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 lambda2,lambda1=0.4; float toler=1e-3; printf("Testing trr 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 trr file for writing"); for(k=0; (k<nframes); k++) { result = write_trr(xd,natoms1,step1+k,time1+k,lambda1,box1,x1,NULL,NULL); if (0 != result) die_r("Writing trr file",result); } xdrfile_close(xd); result = read_trr_natoms(testfn,&natoms2); if (exdrOK != result) die_r("read_trr_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 trr file for reading"); for(k=0; (k<nframes); k++) { result = read_trr(xd,natoms2,&step2,&time2,&lambda2,box2,x2,NULL,NULL); 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(lambda2-lambda2) > toler) die("incorrect lambda"); 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"); } xdrfile_close(xd); #ifdef HAVE_UNISTD unlink(testfn); #endif printf(" PASSED\n"); }
void read_trr2structure(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 lambda; matrix box; rvec *x,*v,*f; XDRFILE *xtc; xtc=xdrfile_open(filename,"r"); int read_return=read_trr_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_trr(xtc,natoms,&step,&time_temp,&lambda,box,x,v,f); 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(); }