/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: resize_array() { int nf = _number_of_frames() ; Eigen::Array<float,Eigen::Dynamic,Eigen::Dynamic> temp_x(_natoms(),nf) ; Eigen::Array<float,Eigen::Dynamic,Eigen::Dynamic> temp_y(_natoms(),nf) ; Eigen::Array<float,Eigen::Dynamic,Eigen::Dynamic> temp_z(_natoms(),nf) ; temp_x = _x() ; temp_y = _y() ; temp_z = _z() ; _x().resize(_natoms(),_number_of_frames()+1) ; _y().resize(_natoms(),_number_of_frames()+1) ; _z().resize(_natoms(),_number_of_frames()+1) ; // see: slice.cpp in retired_ideas/play_with_eigen/ // mat1.block(i,j,rows,cols) // a.block(0, 0, 3, 1) = b.block(0,0,3,1) ; _x().block(0, 0, _natoms(), nf) = temp_x.block(0,0,_natoms(),nf) ; _y().block(0, 0, _natoms(), nf) = temp_y.block(0,0,_natoms(),nf) ; _z().block(0, 0, _natoms(), nf) = temp_z.block(0,0,_natoms(),nf) ; return ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... int sascalc::Prop:: self_overlap(float &cutoff, int &frame){ int check = 0 ; // overlapped == 1 // default == no overlap will return == 0 float dist ; float this_x , that_x ; float this_y , that_y ; float this_z , that_z ; float dx2, dy2, dz2 ; int count = 1 ; for(int i = 0 ; i != _natoms()-1 ; ++i) { this_x = _x()(i,frame) ; this_y = _y()(i,frame) ; this_z = _z()(i,frame) ; for(int j = i+1 ; j != _natoms() ; ++j) { that_x = _x()(j,frame) ; that_y = _y()(j,frame) ; that_z = _z()(j,frame) ; dx2 = (this_x - that_x)*(this_x - that_x) ; dy2 = (this_y - that_y)*(this_y - that_y) ; dz2 = (this_z - that_z)*(this_z - that_z) ; dist = sqrt(dx2+dy2+dz2) ; if(dist < cutoff) { std::cout << "count = " << count << std::endl ; std::cout << "this_atom = " << _atom_name()[count-1] << std::endl ; std::cout << "that_atom = " << _atom_name()[count] << std::endl ; std::cout << "dist = " << dist << std::endl ; std::cout << "this_x = " << this_x << std::endl ; std::cout << "this_y = " << this_y << std::endl ; std::cout << "this_z = " << this_z << std::endl ; std::cout << "that_x = " << that_x << std::endl ; std::cout << "that_y = " << that_y << std::endl ; std::cout << "that_z = " << that_z << std::endl ; check = 1 ; return check ; } } // std::cout << count << " " ; count++ ; } std::cout << std::endl ; return check ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sascalc::Prop:: calc_pmi(int &frame) { std::vector<float> com = calc_com(frame) ; _x().col(frame) -= com[0] ; _y().col(frame) -= com[1] ; _z().col(frame) -= com[2] ; float Ixx = (_atom_mass()*(_y().col(frame)*_y().col(frame) + _z().col(frame)*_z().col(frame))).sum() ; float Iyy = (_atom_mass()*(_x().col(frame)*_x().col(frame) + _z().col(frame)*_z().col(frame))).sum() ; float Izz = (_atom_mass()*(_x().col(frame)*_x().col(frame) + _y().col(frame)*_y().col(frame))).sum() ; float Ixy = (-_atom_mass()*(_x().col(frame)*_y().col(frame))).sum() ; float Ixz = (-_atom_mass()*(_x().col(frame)*_z().col(frame))).sum() ; float Iyz = (-_atom_mass()*(_y().col(frame)*_z().col(frame))).sum() ; float Iyx = (-_atom_mass()*(_y().col(frame)*_x().col(frame))).sum() ; float Izx = (-_atom_mass()*(_z().col(frame)*_x().col(frame))).sum() ; float Izy = (-_atom_mass()*(_z().col(frame)*_y().col(frame))).sum() ; Eigen::Matrix3f I ; I << Ixx, Ixy, Ixz, Iyx, Iyy, Iyz, Izx, Izy, Izz; Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigensolver(I); if (eigensolver.info() != Eigen::Success) { std::cout << "PMI calculation failed" << std::endl ; return ; } _uk() = eigensolver.eigenvalues() ; // .col(0) ; _ak() = eigensolver.eigenvectors() ; // std::cout << "The eigenvalues of I are:\n" << eigensolver.eigenvalues() << std::endl; // std::cout << "Here's a matrix whose columns are eigenvectors of I \n" // << "corresponding to these eigenvalues:\n" // << eigensolver.eigenvectors() << std::endl; _x().col(frame) += com[0] ; _y().col(frame) += com[1] ; _z().col(frame) += com[2] ; return ; }
void Compute(gmp_randstate_t r) const { // The algorithm is sample x and z from the exponential distribution; if // (x-1)^2 < 2*z, return (random sign)*x; otherwise repeat. Probability // of acceptance is sqrt(pi/2) * exp(-1/2) = 0.7602. while (true) { _edist(_x, r); _edist(_z, r); for (mp_size_t k = 1; ; ++k) { _x.ExpandTo(r, k - 1); _z.ExpandTo(r, k - 1); mpfr_prec_t prec = std::max(mpfr_prec_t(MPFR_PREC_MIN), k * bits); mpfr_set_prec(_xf, prec); mpfr_set_prec(_zf, prec); // Try for acceptance first; so compute upper limit on (y-1)^2 and // lower limit on 2*z. if (_x.UInteger() == 0) { _x(_xf, MPFR_RNDD); mpfr_ui_sub(_xf, 1u, _xf, MPFR_RNDU); } else { _x(_xf, MPFR_RNDU); mpfr_sub_ui(_xf, _xf, 1u, MPFR_RNDU); } mpfr_sqr(_xf, _xf, MPFR_RNDU); _z(_zf, MPFR_RNDD); mpfr_mul_2ui(_zf, _zf, 1u, MPFR_RNDD); if (mpfr_cmp(_xf, _zf) < 0) { // (y-1)^2 < 2*z, so accept if (_x.Boolean(r)) _x.Negate(); // include a random sign return; } // Try for rejection; so compute lower limit on (y-1)^2 and upper // limit on 2*z. if (_x.UInteger() == 0) { _x(_xf, MPFR_RNDU); mpfr_ui_sub(_xf, 1u, _xf, MPFR_RNDD); } else { _x(_xf, MPFR_RNDD); mpfr_sub_ui(_xf, _xf, 1u, MPFR_RNDD); } mpfr_sqr(_xf, _xf, MPFR_RNDD); _z(_zf, MPFR_RNDU); mpfr_mul_2ui(_zf, _zf, 1u, MPFR_RNDU); if (mpfr_cmp(_xf, _zf) > 0) // (y-1)^2 > 2*z, so reject break; // Otherwise repeat with more precision } // Reject and start over with a new y and z } }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... std::vector<float> sascalc::Prop:: calc_com(int &frame) { if(_total_mass() <= 0.0) { calc_mass() ; std::cout << "com tot mass = " << _total_mass() << std::endl ; } float comx = 0.0, comy = 0.0, comz = 0.0 ; try { comx = (_atom_mass()*_x().col(frame)).sum() / _total_mass() ; comy = (_atom_mass()*_y().col(frame)).sum() / _total_mass() ; comz = (_atom_mass()*_z().col(frame)).sum() / _total_mass() ; } catch(std::overflow_error e) { std::cout << "failed in calc_com" << std::endl ; std::cout << "total_mass = " << _total_mass() << std::endl ; std::cout << e.what() << " -> "; std::vector<float> com = {comx, comy, comz} ; return com ; } std::vector<float> com = {comx, comy, comz} ; return com ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_dcd(std::string &dcd_input_file_name) { int input_natoms, input_nset, input_reverseEndian ; FILE *dcd_file_pointer ; dcd_file_pointer = sasio::open_dcd_read(dcd_input_file_name, input_natoms, input_nset, input_reverseEndian) ; int input_frame = 0 ; _number_of_frames() = 0 ; _x().setZero(_natoms(), input_nset); _y().setZero(_natoms(), input_nset); _z().setZero(_natoms(), input_nset); std::cout << "_x().cols() = " << _x().cols() << std::endl ; std::cout << "input_nset = " << input_nset << std::endl ; for(int i = 0 ; i < input_nset ; ++i) { std::cout << "." ; read_dcd_step(dcd_file_pointer, i, input_natoms, input_reverseEndian) ; } int result = close_dcd_read(dcd_file_pointer) ; std::cout << std::endl ; return ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_dcd_step(FILE *dcd_infile, int &frame, int &natoms, int &reverseEndian) { int charmm = 0 ; int num_fixed = 0 ; int result ; std::vector<float> vector_x(natoms) ; std::vector<float> vector_y(natoms) ; std::vector<float> vector_z(natoms) ; result = read_dcdstep(dcd_infile,natoms,&vector_x[0],&vector_y[0],&vector_z[0],num_fixed,frame,reverseEndian,charmm) ; if(_x().cols() < frame) { std::cout << "resizing array: cols() = " << _x().cols() << " frame = " << frame << std::endl ; resize_array() ; } for(int i = 0 ; i < _natoms() ; ++i) { _x()(i,frame) = vector_x[i] ; _y()(i,frame) = vector_y[i] ; _z()(i,frame) = vector_z[i] ; } _number_of_frames()++ ; return ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... std::vector<std::vector<float >> sascalc::Prop:: calc_minmax(int &frame){ float min_x = _x().col(frame).minCoeff() ; float max_x = _x().col(frame).maxCoeff() ; float min_y = _y().col(frame).minCoeff() ; float max_y = _y().col(frame).maxCoeff() ; float min_z = _z().col(frame).minCoeff() ; float max_z = _z().col(frame).maxCoeff() ; std::vector<float> min_vector ; std::vector<float> max_vector ; min_vector.push_back(min_x) ; min_vector.push_back(min_y) ; min_vector.push_back(min_z) ; max_vector.push_back(max_x) ; max_vector.push_back(max_y) ; max_vector.push_back(max_z) ; std::vector<std::vector<float >> minmax ; minmax.push_back(min_vector) ; minmax.push_back(max_vector) ; return minmax ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: write_dcd_step(FILE *outfile, int &frame, int &step) { int step_result = 0 ; step_result = write_dcdstep(outfile,_natoms(),&_x()(0,frame),&_y()(0,frame),&_z()(0,frame),step+1) ; return ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... float sascalc::Prop:: calc_rmsd(sasmol::SasMol &mol, int &frame){ float dx = (_x().col(frame)-mol._x().col(frame)).pow(2.0).sum() ; float dy = (_y().col(frame)-mol._y().col(frame)).pow(2.0).sum() ; float dz = (_z().col(frame)-mol._z().col(frame)).pow(2.0).sum() ; float rmsd = sqrt((dx + dy + dz)/_natoms()) ; return rmsd ; }
Parser::Parser(const vector<Production>& productions, const string& parserTablePath) : BasicParser(productions), parserTablePath(parserTablePath) { #ifdef _DEBUG stream.open("ParserResult.txt", fstream::out | fstream::binary); #endif // String Begin Rule quotationMarks = Rule('\"', &context); Rule ruleString = quotationMarks + *!quotationMarks + quotationMarks; ruleString.buildDFA(); ruleString.setShowName("\"{String}\""); Production::Item itemString(ruleString); // String End // Digit Start Rule _0('0', &context); Rule _9('9', &context); Rule _0_9 = _0 - _9; Rule ruleDigit = +_0_9; ruleDigit.buildDFA(); ruleDigit.setShowName("\"{Digit}\""); Production::Item itemDigit(ruleDigit); // Digit End // Real Start Rule _point('.', &context); Rule ruleReal = *_0_9 + _point + +_0_9; ruleReal.buildDFA(); ruleReal.setShowName("\"{Real}\""); Production::Item itemReal(ruleReal); // Real End // Letter Start Rule _('_', &context); Rule _a('a', &context); Rule _z('z', &context); Rule _A('A', &context); Rule _Z('Z', &context); Rule _a_z = _a - _z; Rule _A_Z = _A - _Z; Rule ruleLetter = ((+_ + ruleDigit) | (+(_ | _a_z | _A_Z))) + *(_ | ruleDigit | _a_z | _A_Z); ruleLetter.buildDFA(); ruleLetter.setShowName("\"{Letter}\""); Production::Item itemLetter(ruleLetter); // Letter End vts.push_back(pair<string, Production::Item>("{String}", itemString)); vts.push_back(pair<string, Production::Item>("{Digit}", itemDigit)); vts.push_back(pair<string, Production::Item>("{Real}", itemReal)); vts.push_back(pair<string, Production::Item>("{Letter}", itemLetter)); }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... float sascalc::Prop:: calc_rg(int &frame){ std::vector<float> com = calc_com(frame) ; float rgx = ((_x().col(frame) - com[0]).pow(2.0)).sum() ; float rgy = ((_y().col(frame) - com[1]).pow(2.0)).sum() ; float rgz = ((_z().col(frame) - com[2]).pow(2.0)).sum() ; float rg = sqrt((rgx + rgy + rgz) / _natoms()) ; return rg ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... Eigen::Matrix3f sasmath::Math:: find_u(sasmol::SasMol &mol, int &frame) { Eigen::Matrix3f r ; float rxx = (mol._x().col(frame)*_x().col(frame)).sum() ; float rxy = (mol._x().col(frame)*_y().col(frame)).sum() ; float rxz = (mol._x().col(frame)*_z().col(frame)).sum() ; float ryx = (mol._y().col(frame)*_x().col(frame)).sum() ; float ryy = (mol._y().col(frame)*_y().col(frame)).sum() ; float ryz = (mol._y().col(frame)*_z().col(frame)).sum() ; float rzx = (mol._z().col(frame)*_x().col(frame)).sum() ; float rzy = (mol._z().col(frame)*_y().col(frame)).sum() ; float rzz = (mol._z().col(frame)*_z().col(frame)).sum() ; r << rxx,rxy,rxz, ryx,ryy,ryz, rzx,rzy,rzz; Eigen::Matrix3f rtr = r.transpose() * r ; Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigensolver(rtr); if (eigensolver.info() != Eigen::Success) { std::cout << "find_u calculation failed" << std::endl ; } Eigen::Matrix<float,3,1> uk ; // eigenvalues Eigen::Matrix3f ak ; // eigenvectors uk = eigensolver.eigenvalues() ; ak = eigensolver.eigenvectors() ; Eigen::Matrix3f akt = ak.transpose() ; Eigen::Matrix3f new_ak ; new_ak.row(0) = akt.row(2) ; //sort eigenvectors new_ak.row(1) = akt.row(1) ; new_ak.row(2) = akt.row(0) ; // python ak0 --> ak[2] ; ak1 --> ak[1] ; ak2 --> ak[0] //Eigen::Matrix<float,3,1> ak2 = akt.row(2).cross(akt.row(1)) ; Eigen::MatrixXf rak0 = (r * (akt.row(2).transpose())) ; Eigen::MatrixXf rak1 = (r * (akt.row(1).transpose())) ; Eigen::Matrix<float,3,1> urak0 ; if(uk[2] == 0.0) { urak0 = 1E15 * rak0 ; } else { urak0 = (1.0/sqrt(fabs(uk[2])))*rak0 ; } Eigen::Matrix<float,3,1> urak1 ; if(uk[1] == 0.0) { urak1 = 1E15 * rak1 ; } else { urak1 = (1.0/sqrt(fabs(uk[1])))*rak1 ; } Eigen::Matrix<float,3,1> urak2 = urak0.col(0).cross(urak1.col(0)) ; Eigen::Matrix3f bk ; bk << urak0,urak1,urak2; Eigen::Matrix3f u ; u = (bk * new_ak).transpose() ; return u ; /* u = array([[-0.94513198, 0.31068658, 0.100992 ], [-0.3006246 , -0.70612572, -0.64110165], [-0.12786863, -0.63628635, 0.76078203]]) check: u = -0.945133 0.310686 0.100992 -0.300624 -0.706126 -0.641102 -0.127869 -0.636287 0.760782 */ }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_pdb(const std::string &filename) { std::string line, word ; std::string element_string ; std::ifstream infile(filename) ; int count = 0 ; int frame = 0 ; //string s(line, index, number_characters) ; std::vector<float> vector_x; std::vector<float> vector_y; std::vector<float> vector_z; while(getline(infile,line)) { std::istringstream record(line) ; record >> word ; std::string temp1(word,0,5) ; if(temp1 != "ATOM" && temp1 != "HETAT") { std::cout << "excluding: " << word << std::endl ; } else { std::string tmp(line,0,6) ; _atom_record().push_back(tmp) ; std::string tmp2(line,6,5) ; _atom_index().push_back(stoi(tmp2)) ; std::string tmp3(line,12,4) ; _atom_name().push_back(tmp3) ; std::string tmp4(line,16,1) ; _atom_altloc().push_back(tmp4) ; std::string tmp5(line,17,3) ; _atom_resname().push_back(tmp5) ; std::string tmp6(line,21,1) ; _atom_chain().push_back(tmp6) ; std::string tmp7(line,22,4) ; _atom_resid().push_back(stoi(tmp7)) ; std::string tmp8(line,26,1) ; _atom_icode().push_back(tmp8) ; std::string tmp9(line,30,8) ; vector_x.push_back(stof(tmp9)) ; std::string tmp10(line,38,8) ; vector_y.push_back(stof(tmp10)) ; std::string tmp11(line,46,8) ; vector_z.push_back(stof(tmp11)) ; try { std::string tmp12(line,54,6) ; if(util::has_only_spaces(tmp12)) { _atom_occupancy().push_back("0.00") ; } else { _atom_occupancy().push_back(tmp12) ; } } catch(const std::out_of_range& oor) { _atom_occupancy().push_back("0.00") ; std::cerr<<"Occupancy: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp13(line,60,6) ; if(util::has_only_spaces(tmp13)) { _atom_beta().push_back("0.00") ; } else { _atom_beta().push_back(tmp13) ; } } catch(const std::out_of_range& oor) { _atom_beta().push_back("0.00") ; std::cerr<<"Beta: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp14(line,72,4) ; if(util::has_only_spaces(tmp14)) { _atom_segname().push_back("SEGN") ; } else { _atom_segname().push_back(tmp14) ; } } catch(const std::out_of_range& oor) { _atom_segname().push_back("SEGN") ; std::cerr<<"Segname: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp15(line,76,2) ; if(util::has_only_spaces(tmp15)) { std::cout << "Element not found" << std::endl; element_string = element_from_name(tmp3) ; _atom_element().push_back(element_string) ; } else { _atom_element().push_back(tmp15) ; } } catch(const std::out_of_range& oor) { element_string = element_from_name(tmp3) ; _atom_element().push_back(element_string) ; std::cerr<<"Element: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp16(line,78,2) ; if(util::has_only_spaces(tmp16)) { _atom_charge().push_back(" ") ; } else { _atom_charge().push_back(tmp16) ; } } catch(const std::out_of_range& oor) { _atom_charge().push_back(" ") ; std::cerr<<"Charge: Out of range error: "<< oor.what() <<std::endl ; } count++ ; } } _natoms() = count ; infile.close() ; int nf = _number_of_frames() ; if(_number_of_frames() == 0) { _x().setZero(_natoms(), 1); _y().setZero(_natoms(), 1); _z().setZero(_natoms(), 1); } else { resize_array() ; } for(int i = 0 ; i < _natoms() ; ++i) { _x()(i,_number_of_frames()) = vector_x[i] ; _y()(i,_number_of_frames()) = vector_y[i] ; _z()(i,_number_of_frames()) = vector_z[i] ; } std::vector<std::string> s_element ; s_element = util::strip_white_space(_atom_element()) ; _atom_selement() = s_element ; dynamic_cast<sasmol::SasMol*>(this)->calc_mass() ; _atom_com() = dynamic_cast<sasmol::SasMol*>(this)->calc_com(frame) ; _number_of_frames() += 1 ; _set_unique_attributes(); /* 1 2 3 4 5 6 7 8 012345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 0 6 1 2 7 ATOM 1 N GLY X 1 -21.525 -67.562 86.759 1.00 0.00 GAG N ATOM 2 HT1 GLY X 1 -22.003 -68.460 86.892 1.00 0.00 GAG H ATOM 3 HT2 GLY X 1 -21.905 -66.929 87.525 1.00 0.00 GAG H */ }
void sasio::Files:: write_pdb(const std::string &filename, int &frame) { std::ofstream outfile(filename) ; std::string time_and_user_string ; time_and_user_string = util::time_and_user(); std::string temp_remark = "REMARK PDB FILE WRITTEN "; temp_remark += time_and_user_string ; std::string remark(temp_remark,0,80) ; std::cout << remark << std::endl ; outfile << remark << std::endl; //std::string dum1 =" 1 2 3 4 5 6 7 8"; //std::string dum2 ="12345678901234567890123456789012345678901234567890123456789012345678901234567890"; //outfile << dum1 << std::endl; //outfile << dum2 << std::endl; std::stringstream line ; std::stringstream my_stringstream; for(int i = 0 ; i < _natoms() ; ++i) { line.str( std::string() ); line.clear() ; std::string tmp(_atom_record()[i],0,6) ; line << std::setfill(' ') << std::setw(6) << tmp ; if(_atom_index()[i] > 99999) { std::string tmp2(std::to_string(99999),0,5) ; line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ; } else if(_atom_index()[i] < -9999) { std::string tmp2(std::to_string(-9999),0,5) ; line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ; } else { std::string tmp2(std::to_string(_atom_index()[i]),0,5) ; line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ; } std::string tmp0 = " "; line << tmp0 ; std::string tmp3(_atom_name()[i],0,4) ; line << std::setfill(' ') << std::setw(4) << std::left << tmp3 ; std::string tmp4(_atom_altloc()[i],0,1) ; line << std::setw(1) << tmp4 ; std::string tmp5(_atom_resname()[i],0,3) ; line << std::setfill(' ') << std::setw(4) << std::left << tmp5 ; std::string tmp6(_atom_chain()[i],0,1) ; line << std::setfill(' ') << std::setw(1) << std::left << tmp6 ; if(_atom_resid()[i] > 9999) { std::string tmp7(std::to_string(9999),0,4) ; line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ; } else if(_atom_resid()[i] < -999) { std::string tmp7(std::to_string(-999),0,4) ; line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ; } else { std::string tmp7(std::to_string(_atom_resid()[i]),0,4) ; line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ; } std::string tmp8(_atom_icode()[i],0,1) ; line << std::setw(4) << std::left << tmp8 ; //std::string f_str = std::to_string(f); //here // my_stringstream << _x()(i,frame) ; //my_stringstream << std::to_string(_x()(i,frame)) ; //line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ; line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ; my_stringstream << _y()(i,frame) ; line << my_stringstream.str() ; my_stringstream << _z()(i,frame) ; line << my_stringstream.str() ; std::string tmp12(_atom_occupancy()[i],0,6) ; line << std::setfill(' ') << std::setw(6) << std::right << tmp12 ; std::string tmp13(_atom_beta()[i],0,6) ; line << std::setfill(' ') << std::setw(6) << std::right << tmp13 ; std::string tmp14(_atom_segname()[i],0,4) ; line << std::setfill(' ') << std::setw(10) << std::right << tmp14 ; std::string tmp15(_atom_element()[i],0,2) ; line << std::setfill(' ') << std::setw(2) << std::right << tmp15 ; std::string tmp16(_atom_charge()[i],0,2) ; line << std::setfill(' ') << std::setw(2) << std::right << tmp16 ; outfile << line.str() << std::endl ; } outfile << "END" << std::endl; outfile.close() ; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_xyz(const std::string &filename) { /* NOT CHECKED FOR MULTIPLE FRAMES */ std::string line, word ; std::ifstream infile(filename) ; std::string local_natoms ; infile >> local_natoms ; _natoms() = stoi(local_natoms) ; _number_of_frames() = 1 ; // HARDWIRED // #### need to cleanly read the end of the first line // #### and the next line getline(infile,line) ; std::istringstream record(line) ; while(record >> word) ; getline(infile,line) ; while(record >> word) ; std::vector<float> vector_x; std::vector<float> vector_y; std::vector<float> vector_z; std::vector<float> coor; while(getline(infile,line)) { std::istringstream record(line) ; record >> word ; _atom_name().push_back(word) ; while(record >> word) { coor.push_back(stod(word)); } } auto begin = coor.begin() ; auto end = coor.end() ; std::vector<float>::iterator ii ; for(ii = begin ; ii != end ; ii+=3) { vector_x.push_back(*ii) ; vector_y.push_back(*(ii+1)) ; vector_z.push_back(*(ii+2)); } infile.close() ; if(_number_of_frames() == 0) { _x().setZero(_natoms(), 1); _y().setZero(_natoms(), 1); _z().setZero(_natoms(), 1); } else { resize_array() ; } for(int i = 0 ; i < _natoms() ; ++i) { _x()(i,_number_of_frames()) = vector_x[i] ; _y()(i,_number_of_frames()) = vector_y[i] ; _z()(i,_number_of_frames()) = vector_z[i] ; } _number_of_frames()++ ; return ; /* 5 test N -3.259000 -5.011000 -14.360000 */ } // end of read_xyz