int main() { srand(time(NULL)); // initialize the random-generator const int HEIGHT = 600; const int WIDTH = 800; // modify here const double PROP = 0.68; // probability for bond to be open Xcbwin Window; vector<int> sites(WIDTH, 1); Window.Open(WIDTH, HEIGHT); for (int y = 0; y < HEIGHT; ++y) { for (int x = 0; x < WIDTH; ++x) { if (sites[x]) { Window.Black(); Window.DrawPoint(x, y); } } doPercolationStep(&sites, PROP, y); } Window.Screenshot(); Window.WaitForKeypress(); }
void Tracker::spin() { ros::Rate loopRateTracking(100); tf::Transform transform; std_msgs::Header lastHeader; while (!exiting()) { // When a camera sequence is played several times, // the seq id will decrease, in this case we want to // continue the tracking. if (header_.seq < lastHeader.seq) lastTrackedImage_ = 0; if (lastTrackedImage_ < header_.seq) { lastTrackedImage_ = header_.seq; // If we can estimate the camera displacement using tf, // we update the cMo to compensate for robot motion. if (compensateRobotMotion_) try { tf::StampedTransform stampedTransform; listener_.lookupTransform (header_.frame_id, // camera frame name header_.stamp, // current image time header_.frame_id, // camera frame name lastHeader.stamp, // last processed image time worldFrameId_, // frame attached to the environment stampedTransform ); vpHomogeneousMatrix newMold; transformToVpHomogeneousMatrix (newMold, stampedTransform); cMo_ = newMold * cMo_; mutex_.lock(); tracker_->setPose(image_, cMo_); mutex_.unlock(); } catch(tf::TransformException& e) { mutex_.unlock(); } // If we are lost but an estimation of the object position // is provided, use it to try to reinitialize the system. if (state_ == LOST) { // If the last received message is recent enough, // use it otherwise do nothing. if (ros::Time::now () - objectPositionHint_.header.stamp < ros::Duration (1.)) transformToVpHomogeneousMatrix (cMo_, objectPositionHint_.transform); mutex_.lock(); tracker_->setPose(image_, cMo_); mutex_.unlock(); } // We try to track the image even if we are lost, // in the case the tracker recovers... if (state_ == TRACKING || state_ == LOST) try { mutex_.lock(); // tracker_->setPose(image_, cMo_); // Removed as it is not necessary when the pose is not modified from outside. tracker_->track(image_); tracker_->getPose(cMo_); mutex_.unlock(); } catch(...) { mutex_.unlock(); ROS_WARN_THROTTLE(10, "tracking lost"); state_ = LOST; } // Publish the tracking result. if (state_ == TRACKING) { geometry_msgs::Transform transformMsg; vpHomogeneousMatrixToTransform(transformMsg, cMo_); // Publish position. if (transformationPublisher_.getNumSubscribers () > 0) { geometry_msgs::TransformStampedPtr objectPosition (new geometry_msgs::TransformStamped); objectPosition->header = header_; objectPosition->child_frame_id = childFrameId_; objectPosition->transform = transformMsg; transformationPublisher_.publish(objectPosition); } // Publish result. if (resultPublisher_.getNumSubscribers () > 0) { geometry_msgs::PoseWithCovarianceStampedPtr result (new geometry_msgs::PoseWithCovarianceStamped); result->header = header_; result->pose.pose.position.x = transformMsg.translation.x; result->pose.pose.position.y = transformMsg.translation.y; result->pose.pose.position.z = transformMsg.translation.z; result->pose.pose.orientation.x = transformMsg.rotation.x; result->pose.pose.orientation.y = transformMsg.rotation.y; result->pose.pose.orientation.z = transformMsg.rotation.z; result->pose.pose.orientation.w = transformMsg.rotation.w; const vpMatrix& covariance = tracker_->getCovarianceMatrix(); for (unsigned i = 0; i < covariance.getRows(); ++i) for (unsigned j = 0; j < covariance.getCols(); ++j) { unsigned idx = i * covariance.getCols() + j; if (idx >= 36) continue; result->pose.covariance[idx] = covariance[i][j]; } resultPublisher_.publish(result); } // Publish moving edge sites. if (movingEdgeSitesPublisher_.getNumSubscribers () > 0) { visp_tracker::MovingEdgeSitesPtr sites (new visp_tracker::MovingEdgeSites); updateMovingEdgeSites(sites); sites->header = header_; movingEdgeSitesPublisher_.publish(sites); } // Publish KLT points. if (kltPointsPublisher_.getNumSubscribers () > 0) { visp_tracker::KltPointsPtr klt (new visp_tracker::KltPoints); updateKltPoints(klt); klt->header = header_; kltPointsPublisher_.publish(klt); } // Publish to tf. transform.setOrigin (tf::Vector3(transformMsg.translation.x, transformMsg.translation.y, transformMsg.translation.z)); transform.setRotation (tf::Quaternion (transformMsg.rotation.x, transformMsg.rotation.y, transformMsg.rotation.z, transformMsg.rotation.w)); transformBroadcaster_.sendTransform (tf::StampedTransform (transform, header_.stamp, header_.frame_id, childFrameId_)); } } lastHeader = header_; spinOnce(); loopRateTracking.sleep(); } }
PeptideHit AScore::compute(const PeptideHit & hit, PeakSpectrum & real_spectrum, double fragment_mass_tolerance, bool fragment_mass_unit_ppm, Size max_peptide_len, Size max_num_perm) { PeptideHit phospho = hit; //reset phospho phospho.setScore(-1); if (real_spectrum.empty()) { return phospho; } String sequence_str = phospho.getSequence().toString(); Size number_of_phosphorylation_events = numberOfPhosphoEvents_(sequence_str); AASequence seq_without_phospho = removePhosphositesFromSequence_(sequence_str); if (seq_without_phospho.toUnmodifiedString().size() > max_peptide_len) { LOG_DEBUG << "\tcalculation aborted: peptide too long: " << seq_without_phospho.toString() << std::endl; return phospho; } // determine all phospho sites vector<Size> sites(getSites_(seq_without_phospho)); Size number_of_STY = sites.size(); if (number_of_phosphorylation_events == 0 || number_of_STY == 0 || number_of_STY == number_of_phosphorylation_events) { return phospho; } vector<vector<Size> > permutations(computePermutations_(sites, (Int)number_of_phosphorylation_events)); LOG_DEBUG << "\tnumber of permutations: " << permutations.size() << std::endl; // TODO: using a heuristic to calculate the best phospho sites if the number of permutations are exceeding the maximum. // A heuristic could be to calculate the best site for the first phosphorylation and based on this the best site for the second // phosphorylation and so on until every site is determined if (permutations.size() > max_num_perm) { LOG_DEBUG << "\tcalculation aborted: number of permutations exceeded" << std::endl; return phospho; } vector<PeakSpectrum> th_spectra(createTheoreticalSpectra_(permutations, seq_without_phospho)); // prepare real spectrum windows if (!real_spectrum.isSorted()) { real_spectrum.sortByPosition(); } vector<PeakSpectrum> windows_top10(peakPickingPerWindowsInSpectrum_(real_spectrum)); // calculate peptide score for each possible phospho site permutation vector<vector<double> > peptide_site_scores(calculatePermutationPeptideScores_(th_spectra, windows_top10, fragment_mass_tolerance, fragment_mass_unit_ppm)); // rank peptide permutations ascending multimap<double, Size> ranking(rankWeightedPermutationPeptideScores_(peptide_site_scores)); multimap<double, Size>::reverse_iterator rev = ranking.rbegin(); String seq1 = th_spectra[rev->second].getName(); phospho.setSequence(AASequence::fromString(seq1)); phospho.setMetaValue("search_engine_sequence", hit.getSequence().toString()); double peptide1_score = rev->first; phospho.setMetaValue("AScore_pep_score", peptide1_score); // initialize score with highest peptide score (aka highest weighted score) ++rev; String seq2 = th_spectra[rev->second].getName(); double peptide2_score = rev->first; vector<ProbablePhosphoSites> phospho_sites; determineHighestScoringPermutations_(peptide_site_scores, phospho_sites, permutations, ranking); Int rank = 1; double best_Ascore = std::numeric_limits<double>::max(); // the lower the better for (vector<ProbablePhosphoSites>::iterator s_it = phospho_sites.begin(); s_it != phospho_sites.end(); ++s_it) { double Ascore = 0; if (peptide1_score == peptide2_score) // set Ascore = 0 for each phosphorylation site { LOG_DEBUG << "\tscore of best (" << seq1 << ") and second best peptide (" << seq2 << ") are equal (" << peptide1_score << ")" << std::endl; } else { vector<PeakSpectrum> site_determining_ions; computeSiteDeterminingIons_(th_spectra, *s_it, site_determining_ions, fragment_mass_tolerance, fragment_mass_unit_ppm); Size N = site_determining_ions[0].size(); // all possibilities have the same number so take the first one double p = static_cast<double>(s_it->peak_depth) / 100.0; Size n_first = 0; // number of matching peaks for first peptide for (Size window_idx = 0; window_idx != windows_top10.size(); ++window_idx) // for each 100 m/z window { n_first += numberOfMatchedIons_(site_determining_ions[0], windows_top10[window_idx], s_it->peak_depth, fragment_mass_tolerance, fragment_mass_unit_ppm); } double P_first = computeCumulativeScore_(N, n_first, p); Size n_second = 0; // number of matching peaks for second peptide for (Size window_idx = 0; window_idx < windows_top10.size(); ++window_idx) //each 100 m/z window { n_second += numberOfMatchedIons_(site_determining_ions[1], windows_top10[window_idx], s_it->peak_depth, fragment_mass_tolerance, fragment_mass_unit_ppm); } Size N2 = site_determining_ions[1].size(); // all possibilities have the same number so take the first one double P_second = computeCumulativeScore_(N2, n_second, p); //abs is used to avoid -0 score values double score_first = abs(-10 * log10(P_first)); double score_second = abs(-10 * log10(P_second)); LOG_DEBUG << "\tfirst - N: " << N << ",p: " << p << ",n: " << n_first << ", score: " << score_first << std::endl; LOG_DEBUG << "\tsecond - N: " << N2 << ",p: " << p << ",n: " << n_second << ", score: " << score_second << std::endl; Ascore = score_first - score_second; LOG_DEBUG << "\tAscore_" << rank << ": " << Ascore << std::endl; } if (Ascore < best_Ascore) { best_Ascore = Ascore; } phospho.setMetaValue("AScore_" + String(rank), Ascore); ++rank; } phospho.setScore(best_Ascore); return phospho; }
void SpinAdapted::InitBlocks::InitStartingBlock (SpinBlock& startingBlock, const bool &forward, int leftState, int rightState, const int & forward_starting_size, const int &backward_starting_size, const int& restartSize, const bool &restart, const bool& warmUp, int integralIndex, const vector<SpinQuantum>& braquanta, const vector<SpinQuantum>& ketquanta) { if (restart && restartSize != 1) { int len = restart? restartSize : forward_starting_size; vector<int> sites(len); if (forward) for (int i=0; i<len; i++) sites[i] = i; else for (int i=0; i<len; i++) sites[i] = dmrginp.last_site() - len +i ; if (restart) SpinBlock::restore (forward, sites, startingBlock, leftState, rightState); else SpinBlock::restore (true, sites, startingBlock, leftState, rightState); } else if (forward) { if(startingBlock.nonactive_orb().size()!=0) startingBlock = SpinBlock(0, forward_starting_size - 1,startingBlock.nonactive_orb() , true); else startingBlock = SpinBlock(0, forward_starting_size - 1, integralIndex, leftState==rightState, true); if (dmrginp.add_noninteracting_orbs() && dmrginp.molecule_quantum().get_s().getirrep() != 0 && dmrginp.spinAdapted()) { SpinQuantum s = dmrginp.molecule_quantum(); s = SpinQuantum(s.get_s().getirrep(), s.get_s(), IrrepSpace(0)); int qs = 1, ns = 1; StateInfo addstate(ns, &s, &qs); SpinBlock dummyblock(addstate, integralIndex); SpinBlock newstartingBlock; newstartingBlock.set_integralIndex() = integralIndex; newstartingBlock.default_op_components(false, startingBlock, dummyblock, true, true, leftState==rightState); newstartingBlock.setstoragetype(LOCAL_STORAGE); if( braquanta.size()!= 0) newstartingBlock.BuildSumBlock(NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, startingBlock, dummyblock,braquanta,ketquanta); else newstartingBlock.BuildSumBlock(NO_PARTICLE_SPIN_NUMBER_CONSTRAINT, startingBlock, dummyblock); startingBlock.clear(); startingBlock = newstartingBlock; } } else { std::vector<int> backwardSites; if(dmrginp.spinAdapted()) { for (int i = 0; i < backward_starting_size; ++i) backwardSites.push_back (dmrginp.last_site() - i - 1); } else { for (int i = 0; i < backward_starting_size; ++i) backwardSites.push_back (dmrginp.last_site()/2 - i - 1); } sort (backwardSites.begin (), backwardSites.end ()); startingBlock.set_integralIndex() = integralIndex; startingBlock.default_op_components(false, leftState==rightState); startingBlock.BuildTensorProductBlock (backwardSites); } }