/* SRC: classes/exception.php line 152 */ void c_Exception::t_inittrace() { INSTANCE_METHOD_INJECTION_BUILTIN(Exception, Exception::initTrace); Variant v_top; Variant v_frame; ObjectData *obj_tmp UNUSED; { const CallInfo *cit0 = NULL; MethodCallPackage mcp0; mcp0.staticMethodCall(NAMSTR(s_sys_ssf08d205d, "static"), NAMSTR(s_sys_ssc453e9e9, "getTraceOptions")); mcp0.lateStaticBind(fi.getThreadInfo()); cit0 = mcp0.ci; const Array &tmp1((x_debug_backtrace(toBoolean((cit0->getMeth0Args())(mcp0, 0))))); m_trace = tmp1; } LOOP_COUNTER(1); { while (!(empty(m_trace))) { LOOP_COUNTER_CHECK(1); { { const Variant &tmp0((m_trace.rvalAt(0LL, AccessFlags::Error))); v_top.assignVal(tmp0); } { bool tmp0; { bool tmp1 = ((isset(v_top, NAMSTR(s_sys_ssc82dbd12, "class"), true) && isset(v_top, NAMSTR(s_sys_ss52403931, "function"), true))); if (tmp1) { const String &tmp2((toString(v_top.rvalAt(NAMSTR(s_sys_ssc82dbd12, "class"), AccessFlags::Error_Key)))); int64 tmp3((x_strcasecmp(tmp2, NAMSTR(s_sys_ssae8717ad, "exception")))); tmp1 = (same(tmp3, 0LL)); } bool tmp4 = (tmp1); if (tmp4) { const String &tmp5((toString(v_top.rvalAt(NAMSTR(s_sys_ss52403931, "function"), AccessFlags::Error_Key)))); int64 tmp6((x_strcasecmp(tmp5, NAMSTR(s_sys_ssa26bedd7, "__init__")))); tmp4 = (same(tmp6, 0LL)); } tmp0 = (tmp4); } if (tmp0) { { { const Variant &tmp0((x_array_shift(ref(m_trace)))); v_frame.assignVal(tmp0); } if (isset(v_frame, NAMSTR(s_sys_ss8ce7db5b, "file"), true)) { { const Variant &tmp0((v_frame.rvalAt(NAMSTR(s_sys_ss8ce7db5b, "file"), AccessFlags::Error_Key))); m_file.assignVal(tmp0); } } if (isset(v_frame, NAMSTR(s_sys_ssddf8728c, "line"), true)) { { const Variant &tmp0((v_frame.rvalAt(NAMSTR(s_sys_ssddf8728c, "line"), AccessFlags::Error_Key))); m_line.assignVal(tmp0); } } return; } } } x_array_shift(ref(m_trace)); } } } }
/// /// @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 */ }
MatrixXf EMclustering::initialization(MatrixXf x, int k) { srand (1); int n = x.cols(); int d = x.rows(); //cerr<<n<<"d "<<d<<endl; VectorXi idx(k); //idx.setRandom(k); //cerr<<idx<<endl; idx(0) = rand()%n; for(int i=1;i<k;i++) { int random;// = rand()%n; //cerr<<random<<endl; bool flag2 = true; while(flag2) { random = rand()%n; flag2 = false; for(int j=0;j<i;j++) { if(idx(j)==random) { flag2 = true; break; } } } idx(i) = random; } //cerr<<"idx"<<idx<<endl<<endl; int tmpsize = idx.size(); MatrixXf m(d,tmpsize); for(int i=0;i<tmpsize;i++) m.col(i) = x.col(idx(i)); //cerr<<m<<endl<<endl; VectorXf tmp1(m.cols()); tmp1 = m.cwiseProduct(m).colwise().sum(); //cerr<<tmp1<<endl<<endl; tmp1 = tmp1.adjoint()/2; //cerr<<tmp1<<endl<<endl; MatrixXf tmp2(m.adjoint().rows(),x.cols()); tmp2 = m.adjoint() * x; //cerr<<tmp2<<endl<<endl; MatrixXf tmp3(tmp2.rows(),tmp2.cols()); tmp3 = tmp2.colwise() - tmp1; //cerr<<tmp3<<endl<<endl; double tmp4; int tmp5; int tmpd = tmp3.cols(); VectorXi label(tmpd); for(int i=0;i<tmpd;i++) { tmp4 = tmp3.col(i).maxCoeff(&tmp5); label(i) = tmp5; } //cerr<<label<<endl<<endl; VectorXi tmp6(label.size()); VectorXi u = unique(label, tmp6); //cerr<<u<<endl<<endl; //cerr<<tmp6<<endl<<endl; int max = 100; int t=0; while(k!=u.size()&&t<max) { t++; //cerr<<"-----------"<<endl; //idx.setRandom(k); idx(0) = rand()%n;//cerr<<k<<" "<<u.size()<<" "<<idx(0)<<endl; for(int i=1;i<k;i++) { int random;// = rand()%n; bool flag2 = true; while(flag2) {random = rand()%n; flag2 = false; for(int j=0;j<i;j++) { if(idx(j)==random||x.col(idx(j))==x.col(random)) { flag2 = true; break; } } } idx(i) = random;//cerr<<idx(i)<<" "; }//cerr<<endl; //cerr<<"idx"<<idx<<endl<<endl;; //cerr<<"u"<<u<<endl<<endl; for(int i=0;i<tmpsize;i++) m.col(i) = x.col(idx(i)); //cerr<<m<<endl<<endl; tmp1 = m.cwiseProduct(m).colwise().sum(); //cerr<<tmp1<<endl<<endl; tmp1 = tmp1.adjoint()/2; //cerr<<tmp1<<endl<<endl; tmp2 = m.adjoint() * x; //cerr<<tmp2<<endl<<endl; tmp3 = tmp2.colwise() - tmp1; //cerr<<tmp3<<endl<<endl; tmpd = tmp3.cols(); for(int i=0;i<tmpd;i++) { tmp4 = tmp3.col(i).maxCoeff(&tmp5); label(i) = tmp5; } //cerr<<"label"<<label.size()<<endl<<endl; //cerr<<"end"<<endl; u = unique(label, tmp6); label = tmp6; //cerr<<"u"<<u<<endl<<endl; //cerr<<tmp6<<endl<<endl; }//cerr<<k<<" "<<u.size()<<endl; //cerr<<t<<endl; //cerr<<u.size()<<endl; MatrixXf r(n,k); r.setZero(n,k); int j=0; int tmplabel[k]; for(int i=0;i<k;i++) tmplabel[i] = 0; for(int i=0;i<n;i++) { r(i,label(j)) = 1; tmplabel[label(j)] = 1; j++; } //for(int i=0;i<n;i++) //{ // if(tmplabel[i]==0) // { // r(i,0) = 1; // } //} j = 0; for(int i=0;i<k;i++) { if(tmplabel[i]==0) { //cerr<<i<<endl; for(int ii=0;ii<n/k;ii++) { int ttt = rand()%n; //for(int jj=0;jj<k;jj++) // r(ttt,jj)=0; r(ttt,i) = 1; } //j ++;//cerr<<j<<endl; } } //cerr<<r.cols()<<endl; //cerr<<r<<endl; //delete [] tmplabel; idx.resize(0); m.resize(0,0); tmp1.resize(0); tmp2.resize(0,0); tmp3.resize(0,0); tmp6.resize(0); u.resize(0); label.resize(0); return r; }
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() ; }