Float AngleTripletScore::evaluate(const ParticleTriplet &p, DerivativeAccumulator *da) const { IMP_CHECK_OBJECT(f_.get()); IMP_CHECK_OBJECT(p[0]); IMP_CHECK_OBJECT(p[1]); IMP_CHECK_OBJECT(p[2]); XYZ d0 = XYZ::decorate_particle(p[0]); XYZ d1 = XYZ::decorate_particle(p[1]); XYZ d2 = XYZ::decorate_particle(p[2]); Float score; if (da) { algebra::Vector3D derv0, derv1, derv2; double angle = internal::angle(d0, d1, d2, &derv0, &derv1, &derv2); Float deriv; boost::tie(score, deriv) = f_->evaluate_with_derivative(angle); d0.add_to_derivatives(derv0 * deriv, *da); d1.add_to_derivatives(derv1 * deriv, *da); d2.add_to_derivatives(derv2 * deriv, *da); } else { double angle = internal::angle(d0, d1, d2, nullptr, nullptr, nullptr); score = f_->evaluate(angle); } return score; }
void QuadsOptimizerState::update() { IMP_OBJECT_LOG; if (!f_) return; IMP_LOG(TERSE, "Begin QuadsOptimizerState::update" << std::endl); IMP_CHECK_OBJECT(f_); IMP_CHECK_OBJECT(c_); c_->apply(f_); IMP_LOG(TERSE, "End QuadsOptimizerState::update" << std::endl); }
void MovedSingletonContainer::do_score_state_before_evaluate() { IMP_OBJECT_LOG; IMP_CHECK_OBJECT(this); IMP_CHECK_OBJECT(pc_); if (pc_version_ != pc_->get_contents_hash()) { pc_version_ = pc_->get_contents_hash(); IMP_LOG_TERSE("First call" << std::endl); initialize(); } else { ParticleIndexes mved = do_get_moved(); IMP_LOG_TERSE("Setting moved list: " << Showable(mved) << std::endl); swap(mved); } IMP_IF_CHECK(USAGE_AND_INTERNAL) { validate(); } }
ComplementarityRestraint::GridObject *ComplementarityRestraint::get_grid_object( core::RigidBody rb, const kernel::ParticlesTemp &a, ObjectKey ok, double thickness, double value, double interior_thickness, double voxel) const { IMP_USAGE_CHECK(!a.empty(), "No particles passed for excluded volume"); for (unsigned int i = 1; i < a.size(); ++i) { IMP_USAGE_CHECK(core::RigidMember(a[0]).get_rigid_body() == core::RigidMember(a[i]).get_rigid_body(), "Not all particles are from the same rigid body."); } if (!rb->has_attribute(ok)) { IMP_LOG_TERSE("Creating grid for rigid body " << rb->get_name() << std::endl); IMP::algebra::DenseGrid3D<float> grid = get_grid(a, thickness, value, interior_thickness, voxel); IMP_LOG_TERSE("Grid has size " << grid.get_number_of_voxels(0) << ", " << grid.get_number_of_voxels(1) << ", " << grid.get_number_of_voxels(2) << std::endl); base::Pointer<GridObject> n(new GridObject( GridPair(rb.get_reference_frame().get_transformation_to(), grid))); rb->add_cache_attribute(ok, n); } IMP_CHECK_OBJECT(rb->get_value(ok)); IMP_INTERNAL_CHECK(dynamic_cast<GridObject *>(rb->get_value(ok)), "The saved grid is not a grid."); return dynamic_cast<GridObject *>(rb->get_value(ok)); }
IMP::display::Geometries RestraintGeometry::get_components() const { IMP_CHECK_OBJECT(r_); base::Pointer<kernel::Restraint> rd = r_->create_current_decomposition(); if (!rd) return IMP::display::Geometries(); kernel::RestraintSet *rs = dynamic_cast<kernel::RestraintSet *>(rd.get()); rd->set_was_used(true); IMP::display::Geometries ret; if (!rs) { kernel::ParticlesTemp ps = IMP::get_input_particles(r_->get_inputs()); r_->set_was_used(true); for (unsigned int i = 0; i < ps.size(); ++i) { if (!get_has_coordinates(ps[i])) continue; for (unsigned int j = 0; j < i; ++j) { if (!get_has_coordinates(ps[j])) continue; ret.push_back(new SegmentGeometry(algebra::Segment3D( get_coordinates(ps[i]), get_coordinates(ps[j])))); } } } else { for (unsigned int i = 0; i < rs->get_number_of_restraints(); ++i) { kernel::Restraint *rc = rs->get_restraint(i); rc->set_was_used(true); ret.push_back(new RestraintGeometry(rc, m_)); } } return ret; }
const Ints &PartitionalClusteringWithCenter::get_cluster(unsigned int i) const { IMP_CHECK_OBJECT(this); IMP_USAGE_CHECK(i < get_number_of_clusters(), "There are only " << get_number_of_clusters() << " clusters. Not " << i); return clusters_[i]; }
void LogWrapper::show_it(std::ostream &out) const { IMP_CHECK_OBJECT(this); for (RestraintConstIterator it = restraints_begin(); it != restraints_end(); ++it) { (*it)->show(out); } out << "... end LogWrapper " << get_name() << std::endl; }
IMP::display::Geometries RestraintSetGeometry::get_components() const { IMP_CHECK_OBJECT(r_); Geometries ret; for (unsigned int i = 0; i < r_->get_number_of_restraints(); ++i) { ret.push_back(new RestraintGeometry(r_->get_restraint(i))); } return ret; }
IMPSTATISTICS_BEGIN_NAMESPACE unsigned int PartitionalClusteringWithCenter::get_number_of_clusters() const { IMP_CHECK_OBJECT(this); return clusters_.size(); }
double MSConnectivityRestraint::unprotected_evaluate( DerivativeAccumulator *accum) const { IMP_CHECK_OBJECT(ps_.get()); IMP_OBJECT_LOG; tree_.finalize(); MSConnectivityScore mcs(tree_, ps_.get(), eps_, *const_cast<MSConnectivityRestraint *>(this)); return mcs.score(accum); }
double ConnectivityRestraint::unprotected_evaluate( DerivativeAccumulator *accum) const { IMP_CHECK_OBJECT(ps_.get()); IMP_OBJECT_LOG; base::Vector<Edge> mst; if (!sc_) return 0; kernel::ParticleIndexPairs edges = get_edges(sc_, ps_); return ps_->evaluate_indexes(get_model(), edges, accum, 0, edges.size()); }
double ExampleComplexRestraint::unprotected_evaluate(DerivativeAccumulator *da) const { IMP_CHECK_OBJECT(sc_.get()); double v = 0; core::XYZ dp(get_model(), p_); double radius = diameter_ / 2.0; IMP_CONTAINER_FOREACH(SingletonContainer, sc_, v += core::internal::evaluate_distance_pair_score( dp, core::XYZ(get_model(), _1), da, f_.get(), boost::lambda::_1 - radius););
void Optimizer::set_is_optimizing_states(bool tf) const { IMP_LOG_VERBOSE("Reseting OptimizerStates " << std::flush); for (OptimizerStateConstIterator it = optimizer_states_begin(); it != optimizer_states_end(); ++it) { IMP_CHECK_OBJECT(*it); (*it)->set_is_optimizing(tf); IMP_LOG_VERBOSE("." << std::flush); } IMP_LOG_VERBOSE("done." << std::endl); }
void Optimizer::update_states() const { IMP_LOG_VERBOSE( "Updating OptimizerStates " << std::flush); for (OptimizerStateConstIterator it = optimizer_states_begin(); it != optimizer_states_end(); ++it) { IMP_CHECK_OBJECT(*it); (*it)->update(); IMP_LOG_VERBOSE( "." << std::flush); } IMP_LOG_VERBOSE( "done." << std::endl); }
void ConfigurationSet::load_configuration(int i) const { set_was_used(true); IMP_OBJECT_LOG; IMP_CHECK_OBJECT(this); IMP_USAGE_CHECK(i < static_cast<int>(get_number_of_configurations()) && i >= -1, "Invalid configuration requested."); if (i==-1) { base_->load_configuration(); } else { configurations_[i]->load_configuration(); } }
void Optimizer::update_states() const { IMP_LOG_VERBOSE("Updating OptimizerStates " << std::flush); BOOST_FOREACH(ScoreState * ss, get_required_score_states()) { ss->before_evaluate(); } for (OptimizerStateConstIterator it = optimizer_states_begin(); it != optimizer_states_end(); ++it) { IMP_CHECK_OBJECT(*it); (*it)->update(); IMP_LOG_VERBOSE("." << std::flush); } IMP_LOG_VERBOSE("done." << std::endl); }
double MonteCarlo::do_optimize(unsigned int max_steps) { IMP_OBJECT_LOG; IMP_CHECK_OBJECT(this); if (get_number_of_movers() == 0) { IMP_THROW("Running MonteCarlo without providing any" << " movers isn't very useful.", ValueException); } ParticleIndexes movable = get_movable_particles(); // provide a way of feeding in this value last_energy_ = do_evaluate(movable); if (return_best_) { best_ = new Configuration(get_model()); best_energy_ = last_energy_; } reset_statistics(); update_states(); IMP_LOG_TERSE("MC Initial energy is " << last_energy_ << std::endl); for (unsigned int i = 0; i < max_steps; ++i) { if (get_stop_on_good_score() && get_scoring_function()->get_had_good_score()) { break; } do_step(); if (best_energy_ < get_score_threshold()) break; } IMP_LOG_TERSE("MC Final energy is " << last_energy_ << std::endl); if (return_best_) { // std::cout << "Final score is " << get_model()->evaluate(false) //<< std::endl; best_->swap_configuration(); IMP_LOG_TERSE("MC Returning energy " << best_energy_ << std::endl); IMP_IF_CHECK(USAGE) { IMP_LOG_TERSE("MC Got " << do_evaluate(get_movable_particles()) << std::endl); /*IMP_INTERNAL_CHECK((e >= std::numeric_limits<double>::max() && best_energy_ >= std::numeric_limits<double>::max()) || std::abs(best_energy_ - e) < .01+.1* std::abs(best_energy_ +e), "Energies do not match " << best_energy_ << " vs " << e << std::endl);*/ } return do_evaluate(movable); } else { return last_energy_;
ParticlePairsTemp MSConnectivityRestraint::get_connected_pairs() const { IMP_CHECK_OBJECT(ps_.get()); tree_.finalize(); MSConnectivityScore mcs(tree_, ps_.get(), eps_, *const_cast<MSConnectivityRestraint *>(this)); EdgeSet edges = mcs.get_connected_pairs(); ParticlePairsTemp ret(edges.size()); unsigned index = 0; for (EdgeSet::iterator p = edges.begin(); p != edges.end(); ++p) { ret[index++] = ParticlePair(mcs.get_particle(p->first), mcs.get_particle(p->second)); } return ret; }
MonteCarloMoverResult MonteCarlo::do_move() { ParticleIndexes ret; double prob = 1.0; for (MoverIterator it = movers_begin(); it != movers_end(); ++it) { IMP_LOG_VERBOSE("Moving using " << (*it)->get_name() << std::endl); IMP_CHECK_OBJECT(*it); { // IMP_LOG_CONTEXT("Mover " << (*it)->get_name()); MonteCarloMoverResult cur = (*it)->propose(); ret += cur.get_moved_particles(); prob *= cur.get_proposal_ratio(); } IMP_LOG_VERBOSE("end\n"); } return MonteCarloMoverResult(ret, prob); }
void ModelObject::validate_outputs() const { if (!get_has_dependencies()) return; IMP_IF_CHECK(USAGE_AND_INTERNAL) { IMP_CHECK_OBJECT(this); ModelObjectsTemp ret = do_get_outputs(); std::sort(ret.begin(), ret.end()); ret.erase(std::unique(ret.begin(), ret.end()), ret.end()); ModelObjectsTemp saved = get_model()->get_dependency_graph_outputs(this); std::sort(saved.begin(), saved.end()); ModelObjectsTemp intersection; std::set_intersection(saved.begin(), saved.end(), ret.begin(), ret.end(), std::back_inserter(intersection)); IMP_USAGE_CHECK( intersection.size() == ret.size(), "Dependencies changed without invalidating dependencies." << " Make sure you call set_has_dependencies(false) any " << "time the list of dependencies changed. Object is " << get_name() << " of type " << get_type_name()); } }
void handle_error(const char *msg) { static bool is_handling=false; if (is_handling) { return; } is_handling=true; for (int i=internal::handlers.size()-1; i >=0; --i) { IMP_CHECK_OBJECT(internal::handlers[i]); try { internal::handlers[i]->handle_failure(); } catch (const Exception &e) { IMP_WARN("Caught exception in failure handler \"" << internal::handlers[i]->get_name() << "\": " << e.what() << std::endl); } } if (internal::print_exceptions) { IMP_ERROR(msg); } is_handling=false; }
ParticlePairsTemp ConnectivityRestraint::get_connected_pairs() const { IMP_CHECK_OBJECT(ps_.get()); kernel::ParticleIndexPairs edges = get_edges(sc_, ps_); return IMP::internal::get_particle(get_model(), edges); }
void DynamicListQuadContainer::do_show(std::ostream &out) const { IMP_CHECK_OBJECT(this); out << get_number_of_particle_quads() << " Quads" << std::endl; }
void ListPairContainer::do_show(std::ostream &out) const { IMP_CHECK_OBJECT(this); out << get_number_of_particle_pairs() << " Pairs" << std::endl; }
void CoreCloseBipartitePairContainer::do_show(std::ostream &out) const { IMP_CHECK_OBJECT(this); out << "container " << sc_[0]->get_name() << " and " << sc_[1]->get_name() << std::endl; }
bool Particle::get_is_active() const { IMP_CHECK_OBJECT(this); return get_model() && get_model()->get_has_particle(get_index()); }
unsigned int _take_particles(Model *, const Particles &ps, base::TextOutput) { for (unsigned int i = 0; i < ps.size(); ++i) { IMP_CHECK_OBJECT(ps[i]); } return ps.size(); }
unsigned int _take_particles(const Particles &ps) { for (unsigned int i = 0; i < ps.size(); ++i) { IMP_CHECK_OBJECT(ps[i]); } return ps.size(); }
unsigned int FixedRefiner::get_number_of_refined(Particle *) const { IMP_CHECK_OBJECT(this); return ps_.size(); }
void TripletContainerSet::do_show(std::ostream &out) const { IMP_CHECK_OBJECT(this); out << get_number_of_particle_triplets() << " containers" << std::endl; }