// build an entire tree from an existing hierarchy KinematicForest::KinematicForest(kernel::Model* m, IMP::atom::Hierarchy hierarchy) : Object("IMP_KINEMATICS_KINEMATIC_FOREST"), m_(m){ // TODO: implement IMP_NOT_IMPLEMENTED; IMP_UNUSED(hierarchy); }
Float ChiScoreLog::compute_score(const Profile& exp_profile, const Profile& model_profile, bool offset) const { IMP_UNUSED(offset); Float c = compute_scale_factor(exp_profile, model_profile); Float chi_square = 0.0; unsigned int profile_size = std::min(model_profile.size(), exp_profile.size()); // compute chi square for (unsigned int k=0; k<profile_size; k++) { // in the theoretical profile the error equals to 1 Float square_error = square(log(exp_profile.get_error(k))); Float weight_tilda = model_profile.get_weight(k) / square_error; Float delta = log(exp_profile.get_intensity(k)) - log(c*model_profile.get_intensity(k)); // Exclude the uncertainty originated from limitation of floating number if(fabs(delta/(log(exp_profile.get_intensity(k)))) >= 1.0e-15) chi_square += weight_tilda * square(delta); } chi_square /= profile_size; return sqrt(chi_square); }
double Fine2DRegistrationRestraint::unprotected_evaluate( DerivativeAccumulator *accum) const { IMP_UNUSED(accum); calls_++; IMP_USAGE_CHECK(accum == nullptr, "Fine2DRegistrationRestraint: This restraint does not " "provide derivatives "); // projection_ needs to be mutable, son this const function can change it. // project_particles changes the matrix of projection_ ProjectingOptions options(params_.pixel_size, params_.resolution); double score = 0; try { do_project_particles(ps_, projection_->get_data(), PP_.get_rotation(), PP_.get_translation(), options, masks_); score = score_function_->get_score(subject_, projection_); } catch (cv::Exception &e) { IMP_LOG(WARNING, "Fine2DRegistration. Error computing the score: " "Returning 1 (maximum score). Most probably because projecting " "out of the image size." << e.what() << std::endl); score = 1.0; } IMP_LOG_VERBOSE("Fine2DRegistration. Score: " << score << std::endl); return score; }
double Em2DRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const { IMP_UNUSED(accum); IMP_USAGE_CHECK(!accum, "No derivatives provided"); IMP_NEW(Model, model, ()); model = get_model(); // Project the model RegistrationResults regs = get_evenly_distributed_registration_results(params_.n_projections); unsigned int rows = em_images_[0]->get_header().get_number_of_rows(); unsigned int cols = em_images_[0]->get_header().get_number_of_columns(); ProjectingOptions options(params_.pixel_size, params_.resolution); Images projections = get_projections(particles_container_->get_particles(), regs, rows, cols, options); finder_->set_projections(projections); if (only_coarse_registration_) { IMP_LOG_TERSE("Em2DRestraint::unprotected::evaluate: Coarse registration" << std::endl); finder_->get_coarse_registration(); } else { if (fast_optimization_mode_) { IMP_LOG_TERSE("Em2DRestraint::unprotected::evaluate: Fast Mode " << number_of_optimized_projections_ << " projections optimized" << std::endl); finder_->set_fast_mode(number_of_optimized_projections_); } IMP_LOG_TERSE("Em2DRestraint::unprotected::evaluate: Complete registration" << std::endl); finder_->get_complete_registration(); } return finder_->get_global_score(); }
double EnvelopeFitRestraint::unprotected_evaluate( IMP::DerivativeAccumulator *accum) const { IMP_UNUSED(accum); // get the XYZs IMP::algebra::Vector3Ds coordinates(ps_.size()); for (unsigned int i = 0; i < ps_.size(); i++) { coordinates[i] = core::XYZ(ps_[i]).get_coordinates(); } // align algebra::Transformation3Ds map_transforms = pca_aligner_->align(coordinates); // filter and score, save best scoring only (or none if penetrating) bool best_found = false; IMP::algebra::Transformation3D best_trans; double best_score = -std::numeric_limits<double>::max(); for (unsigned int j = 0; j < map_transforms.size(); j++) { double score = envelope_score_->score(coordinates, map_transforms[j]); if (score > best_score) { best_score = score; best_trans = map_transforms[j]; best_found = true; } } if (best_found) const_cast<EnvelopeFitRestraint *>(this)->transformation_ = best_trans; else // store identity trans const_cast<EnvelopeFitRestraint *>(this)->transformation_ = algebra::Transformation3D(algebra::Vector3D(0, 0, 0)); return -best_score; }
void KNNData::fill_nearest_neighbors_v(const algebra::VectorKD& g, unsigned int k, double eps, Ints& ret) const { VectorWithIndex d(std::numeric_limits<int>::max(), g); RealRCTree::K_neighbor_search search( dynamic_cast<RealRCTree*>(tree_.get())->tree, d, k, eps); IMP_IF_CHECK(base::USAGE_AND_INTERNAL) { int nump = std::distance(dynamic_cast<RealRCTree*>(tree_.get())->tree.begin(), dynamic_cast<RealRCTree*>(tree_.get())->tree.end()); int realk = std::min<int>(nump, k); IMP_UNUSED(realk); IMP_INTERNAL_CHECK( std::distance(search.begin(), search.end()) == static_cast<int>(realk), "Got the wrong number of points out from CGAL neighbor" << " search. Expected " << realk << " got " << std::distance(search.begin(), search.end())); } Ints::iterator rit = ret.begin(); for (RealRCTree::K_neighbor_search::iterator it = search.begin(); it != search.end(); ++it) { *rit = it->first; ++rit; } }
void set_log_target(TextOutput l) { #if IMP_BASE_HAS_LOG4CXX IMP_UNUSED(l); #else internal::stream.set_stream(l); #endif }
double ClassnameScore::evaluate_if_good_index(Model *m, PASSINDEXTYPE vt, DerivativeAccumulator *da, double max) const { IMP_UNUSED(max); return evaluate_index(m, vt, da); }
IMPEM2D_BEGIN_NAMESPACE domino::SubsetFilter *DistanceFilterTable::get_subset_filter( const domino::Subset &subset, const domino::Subsets &prior_subsets) const { IMP_UNUSED(prior_subsets.size()); IMP_LOG_VERBOSE(" get_subset_filter " << std::endl); subset.show(); // The subset must contain the particles of my_subset_ for (domino::Subset::const_iterator it = my_subset_.begin(); it != my_subset_.end(); ++it) { if (!std::binary_search(subset.begin(), subset.end(), *it)) { return nullptr; } } // If the particles are in any of the prior subsets, a filter for them has // been created already. Do not create it again for (domino::Subsets::const_iterator it = prior_subsets.begin(); it != prior_subsets.end(); ++it) { if (std::includes(it->begin(), it->end(), my_subset_.begin(), my_subset_.end())) { return nullptr; } } domino::SubsetFilter *p = new DistanceFilter(subset, my_subset_, ps_table_, max_distance_); return p; }
void set_number_of_threads(unsigned int n) { IMP_USAGE_CHECK(n > 0, "Can't have 0 threads."); #ifdef _OPENMP internal::number_of_threads = n; #else IMP_UNUSED(n); #endif }
IMP::algebra::DenseGrid3D<float> get_complementarity_grid(const IMP::ParticlesTemp &ps, const ComplementarityGridParameters ¶ms) { IMP_NEW(SurfaceDistanceMap, sdm, (ps, params.voxel_size)); sdm->resample(); IMP::algebra::BoundingBox3D bb = IMP::em::get_bounding_box(sdm); IMP_LOG_VERBOSE( __FUNCTION__ << ": Sampled bounding box is " << bb.get_corner(0) << " to " << bb.get_corner(1) << '\n'); IMP::algebra::DenseGrid3D<float> grid(params.voxel_size, bb); IMP_GRID3D_FOREACH_VOXEL(grid, IMP_UNUSED(loop_voxel_index); long idx = sdm->get_voxel_by_location( voxel_center[0], voxel_center[1], voxel_center[2]); if ( idx > -1 ) { float v = sdm->get_value(idx); if ( v > 0 ) { //inside voxel if ( v - 1 > params.interior_cutoff_distance ) grid[voxel_center] = std::numeric_limits<float>::max(); else grid[voxel_center] = int((v - 1)/params.interior_thickness) + 1; /***Shouldn't happen if(grid[voxel_center] < 0) std::cout << "INSIDE voxel negative " << grid[voxel_center] << std::endl; **/ } else if ( v < 0 ) { // outside voxel v = -v - 1; // assume complementarity_thickness is sorted!!! Floats::const_iterator p = std::lower_bound( params.complementarity_thickness.begin(), params.complementarity_thickness.end(), v); if ( p == params.complementarity_thickness.end() ) v = 0; else { v = params.complementarity_value[ p - params.complementarity_thickness.begin()]; } grid[voxel_center] = v; /*** Shouldn't happen if(grid[voxel_center] >= std::numeric_limits<float>::max()) std::cout << "OUTSIDE voxel infinite " << grid[voxel_center] << std::endl; if(grid[voxel_center] > 0) std::cout << "OUTSIDE voxel positive " << grid[voxel_center] << std::endl; **/ } });
void set_log_timer(bool tb) { #if IMP_BASE_HAS_LOG4CXX // always on for now IMP_UNUSED(tb); #else internal::print_time = tb; reset_log_timer(); #endif }
void ModelObject::set_has_required_score_states(bool tf) { IMP_UNUSED(tf); IMP_USAGE_CHECK(tf, "Can only set them this way."); IMP_USAGE_CHECK(get_model(), "Must set model first"); if (!tf) { // they almost certainly depend on upstream things clear_caches(); } get_model()->do_set_has_required_score_states(this, true); // if (get_model()) get_model()->check_dependency_invariants(this); }
double RadiusOfGyrationRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const { IMP_UNUSED(accum); //IMP_USAGE_CHECK(!accum, "No derivatives computed"); if (accum) { IMP_WARN("Can not calcaulte derivatives\n"); } //calculate actual rog //todo - do not use get_input_particles function float actual_rog=get_actual_radius_of_gyration(get_input_particles()); IMP_LOG_VERBOSE("actual_rog:"<<actual_rog<<" predicted:"<<predicted_rog_<< " scale:"<<predicted_rog_*scale_<<" score: "<< hub_->evaluate(actual_rog)<<std::endl); return hub_->evaluate(actual_rog); }
double EzRestraint::unprotected_evaluate(DerivativeAccumulator *da) const { IMP_UNUSED(da); // check if derivatives are requested IMP_USAGE_CHECK(!da, "Derivatives not available"); double score = 0.0; for (unsigned i = 0; i < ps_.size(); ++i) { // if(da){ // FloatPair score_der = // ufs_[i]->evaluate_with_derivative //(fabs(core::XYZ(ps_[i]).get_coordinate(2))); // score += score_der.first; // core::XYZ(ps_[i]).add_to_derivative(2,score_der.second,*da); // }else{ score += ufs_[i]->evaluate(fabs(core::XYZ(ps_[i]).get_coordinate(2))); // } } return score; }
IMPSAXS_BEGIN_NAMESPACE double ChiScoreLog::compute_scale_factor(const Profile* exp_profile, const Profile* model_profile, const double offset) const { IMP_UNUSED(offset); double sum1 = 0.0, sum2 = 0.0; unsigned int profile_size = std::min(model_profile->size(), exp_profile->size()); for (unsigned int k = 0; k < profile_size; k++) { double square_error = square(exp_profile->get_error(k) / exp_profile->get_intensity(k)); double weight_tilda = model_profile->get_weight(k) / square_error; sum1 += weight_tilda * log(exp_profile->get_intensity(k) / model_profile->get_intensity(k)); sum2 += weight_tilda; } return std::exp(sum1 / sum2); }
IMPSAXS_BEGIN_NAMESPACE // TODO: currently assumes uniform sampling of experimental profile double RatioVolatilityScore::compute_score(const Profile* exp_profile, const Profile* model_profile, bool use_offset) const { IMP_UNUSED(use_offset); if (model_profile->size() != exp_profile->size()) { IMP_THROW("RatioVolatilityScore::compute_score is supported " << "only for profiles with the same q values!", ValueException); } double bin_size = PI / dmax_; // default dmax = 400 unsigned int number_of_bins = std::floor(exp_profile->get_max_q()/bin_size); // number of profile points in each bin double number_of_points_in_bin = exp_profile->size()/number_of_bins; Vector<double> ratio(number_of_bins, 0.0); for (unsigned int i = 0; i < number_of_bins; i++) { unsigned int index1 = algebra::get_rounded(i*number_of_points_in_bin); unsigned int index2 = algebra::get_rounded((i+1)*number_of_points_in_bin); // calculate average intensity in the bin double intensity1(0.0), intensity2(0.0); for (unsigned int j = index1; j<index2; j++) { intensity1 += exp_profile->get_intensity(j); intensity2 += model_profile->get_intensity(j); } intensity1 /= (index2-index1); intensity2 /= (index2-index1); ratio[i] = intensity1/intensity2; } double vr = 0; for (unsigned int i = 0; i < (number_of_bins-1); i++) { vr += 2*std::fabs(ratio[i]-ratio[i+1])/(ratio[i]+ratio[i+1]); } return 100*vr/number_of_bins; }
Float RigidBodyAnglePairScore::evaluate_index(Model *m, const ParticleIndexPair &pi, DerivativeAccumulator *da) const { IMP_UNUSED(da); // check if derivatives are requested IMP_USAGE_CHECK(!da, "Derivatives not implemented"); // check if rigid body IMP_USAGE_CHECK(RigidBody::get_is_setup(m, pi[0]), "Particle is not a rigid body"); IMP_USAGE_CHECK(RigidBody::get_is_setup(m, pi[1]), "Particle is not a rigid body"); // principal axis of inertia is aligned to x axis when creating rigid body algebra::Vector3D inertia=algebra::Vector3D(1.0,0.0,0.0); algebra::Vector3D origin=algebra::Vector3D(0.0,0.0,0.0); // get the two references frames algebra::ReferenceFrame3D rf0 = RigidBody(m, pi[0]).get_reference_frame(); algebra::ReferenceFrame3D rf1 = RigidBody(m, pi[1]).get_reference_frame(); // rigid body 0 algebra::Vector3D i0 = rf0.get_global_coordinates(inertia); algebra::Vector3D o0 = rf0.get_global_coordinates(origin); // rigid body 1 algebra::Vector3D i1 = rf1.get_global_coordinates(inertia); algebra::Vector3D o1 = rf1.get_global_coordinates(origin); // now calculate the angle Float sp=std::max(-1.0,std::min(1.0,(i1-o1).get_scalar_product(i0-o0))); Float angle = acos(sp); //std::cout << "ANGLE "<< angle <<std::endl; Float score = f_->evaluate(angle); return score; }
double PCAFitRestraint::unprotected_evaluate( IMP::DerivativeAccumulator *accum) const { IMP_UNUSED(accum); counter_++; // increase counter // generate projections boost::ptr_vector<internal::Projection> projections; if(reuse_direction_ && counter_ != 500 && best_projections_axis_.size() == images_.size()) { projector_.compute_projections(best_projections_axis_, IMP_DEG_2_RAD(20), // 20 degrees for now projections, images_[0].get_height()); } else { projector_.compute_projections(projections, images_[0].get_height()); counter_ = 0; } IMP_LOG_VERBOSE(projections.size() << " projections were created" << std::endl); // process projections for (unsigned int i = 0; i < projections.size(); i++) { projections[i].get_largest_connected_component(n_components_); projections[i].center(); projections[i].average(); projections[i].stddev(); projections[i].compute_PCA(); } // score each image against projections double total_score = 0.0; double area_threshold = 0.4; PCAFitRestraint* non_const_this = const_cast<PCAFitRestraint *>(this); non_const_this->best_projections_.clear(); non_const_this->best_projections_axis_.clear(); for (unsigned int i = 0; i < images_.size(); i++) { internal::ImageTransform best_transform; best_transform.set_score(0.000000001); int best_projection_id = 0; for (unsigned int j = 0; j < projections.size(); j++) { // do not align images with more than X% area difference double area_score = std::abs(images_[i].segmented_pixels() - projections[j].segmented_pixels()) / (double)std::max(images_[i].segmented_pixels(), projections[j].segmented_pixels()); if (area_score > area_threshold) continue; internal::ImageTransform curr_transform = images_[i].pca_align(projections[j]); curr_transform.set_area_score(area_score); if (curr_transform.get_score() > best_transform.get_score()) { best_transform = curr_transform; best_projection_id = projections[j].get_id(); } } IMP_LOG_VERBOSE("Image " << i << " Best projection " << best_projection_id << " " << best_transform << std::endl); total_score += -log(best_transform.get_score()); // save best projections and their projection axis internal::Image2D<> transformed_image; projections[best_projection_id] .rotate_circular(transformed_image, best_transform.get_angle()); transformed_image.translate(best_transform.get_x(), best_transform.get_y()); non_const_this->best_projections_.push_back(transformed_image); non_const_this->best_projections_axis_.push_back(projections[best_projection_id].get_axis()); } return total_score; }
IMPBASE_BEGIN_NAMESPACE void handle_error(const char *message) { IMP_UNUSED(message); // this method is just here to provide a place to break in the debugger }
double DistanceFilterTable::get_strength( const domino::Subset &subset, const domino::Subsets &prior_subsets) const { IMP_UNUSED(subset); IMP_UNUSED(prior_subsets.size()); return 1; }