Example #1
0
void RestraintCache::add_restraint_internal(
    kernel::Restraint *r, unsigned int index, kernel::RestraintSet *parent,
    double parent_max, Subset parent_subset, const DepMap &dependencies) {
  IMP_OBJECT_LOG;
  IMP_LOG_TERSE("Processing " << Showable(r) << " with " << parent_max
                              << std::endl);
  r->set_was_used(true);
  // fix using PST
  Subset cur_subset = get_subset(r, dependencies);
  double cur_max = r->get_maximum_score();
  if (parent) {
    cur_max = std::min(parent_max / r->get_weight(), cur_max);
  }

  if (cur_max < std::numeric_limits<double>::max()) {
    IMP_LOG_TERSE("Adding restraint " << Showable(r) << " with max " << cur_max
                                      << " and subset " << cur_subset
                                      << std::endl);
    known_restraints_[r] = cur_subset;
    restraint_index_[r] = index;
  }
  add_restraint_set_child_internal(r, cur_subset, parent, parent_max,
                                   parent_subset);
  kernel::RestraintSet *rs = dynamic_cast<kernel::RestraintSet *>(r);
  if (rs) {
    add_restraint_set_internal(rs, index, cur_subset, cur_max, dependencies);
  } else {
    if (cur_max < std::numeric_limits<double>::max()) {
      cache_.access_generator().add_restraint(r, cur_subset, cur_max);
    }
  }
}
Example #2
0
void RestraintCache::add_restraint_set_child_internal(
    kernel::Restraint *r, const Subset &cur_subset,
    kernel::RestraintSet *parent, double parent_max, Subset parent_subset) {
  if (!parent) return;
  IMP_LOG_TERSE("Adding restraint " << Showable(r) << " to set "
                                    << Showable(parent) << std::endl);
  cache_.access_generator().add_to_set(
      parent, r, Slice(parent_subset, cur_subset), parent_max);
}
ScoreStatesTemp
SingleParticleScoringFunction
::get_required_score_states(const DependencyGraph &dg,
                            const DependencyGraphVertexIndex &index) const {
  IMP_OBJECT_LOG;
  ScoreStatesTemp from_restraints
      =IMP::internal::RestraintsScoringFunction::get_required_score_states(dg,
                                                                        index);
  IMP_LOG(TERSE, "Score states from restraints are " << from_restraints
          << "(" << IMP::internal::RestraintsScoringFunction::get_restraints()
          << ")" << std::endl);
  ScoreStatesTemp from_dummy
      = IMP::get_required_score_states(dummy_restraints_, dg, index);
  IMP_LOG(TERSE, "Score states from dummy are " << from_dummy
          << "(" << dummy_restraints_ << ")" << std::endl);
  ScoreStatesTemp deps
      = IMP::get_dependent_score_states(get_model()->get_particle(pi_),
                                        ModelObjectsTemp(), dg, index);
  IMP_LOG(TERSE, "Dependent score states are " << deps << std::endl);
  std::sort(deps.begin(), deps.end());
  ScoreStatesTemp allin= from_restraints+from_dummy;
  std::sort(allin.begin(), allin.end());
  // intersect the lists to determine which depend on this particle and are need
  ScoreStatesTemp ret;
  std::set_intersection(allin.begin(), allin.end(),
                        deps.begin(), deps.end(),
                        std::back_inserter(ret));
  IMP_LOG(TERSE, "Particle " << Showable(get_model()->get_particle(pi_))
          << " will update " << get_ordered_score_states(ret) << std::endl);
  return get_ordered_score_states(ret);
}
Example #4
0
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(); }
}
void
SingleParticleScoringFunction::do_update_dependencies(const DependencyGraph &dg,
                                     const DependencyGraphVertexIndex &index) {
  IMP_OBJECT_LOG;
  compatibility::map<Restraint*, int> mp;
  IMP_LOG(TERSE, "All restraints are " << all_restraints_ << std::endl);
  for (unsigned int i=0; i< all_restraints_.size(); ++i) {
    mp[all_restraints_[i]]= i;
  }
  Restraints mr;
  boost::tie(indexes_, mr)= get_my_restraints(get_model()->get_particle(pi_),
                                             mp, dg, index);
  IMP_LOG(TERSE, "Found " << mr << " for particle "
          << Showable(get_model()->get_particle(pi_)) << std::endl);
  IMP::internal::RestraintsScoringFunction::set_restraints(mr);
  IMP::internal::RestraintsScoringFunction::do_update_dependencies(dg, index);
}
Example #6
0
void RestraintCache::load_cache(const kernel::ParticlesTemp &particle_ordering,
                                RMF::HDF5::ConstGroup group) {
  ParticleIndex particle_index = get_particle_index(particle_ordering);
  base::map<RestraintID, kernel::Restraint *> index;
  for (KnownRestraints::const_iterator it = known_restraints_.begin();
       it != known_restraints_.end(); ++it) {
    index[get_restraint_id(particle_index, it->second,
                           restraint_index_.find(it->first)->second)] =
        it->first;
  }
  kernel::RestraintsTemp restraints;
  for (unsigned int i = 0; i < group.get_number_of_children(); ++i) {
    RMF::HDF5::ConstGroup ch = group.get_child_group(i);
    int restraint_index =
        ch.get_attribute<RMF::HDF5::IndexTraits>("restraint")[0];
    RMF::HDF5::Indexes particle_indexes =
        ch.get_attribute<RMF::HDF5::IndexTraits>("particles");
    RestraintID rid(restraint_index,
                    base::ConstVector<unsigned int>(Ints(
                        particle_indexes.begin(), particle_indexes.end())));
    kernel::Restraint *r = index.find(rid)->second;
    restraints.push_back(r);
    IMP_LOG_TERSE("Matching " << Showable(r) << " with " << ch.get_name()
                              << std::endl);
  }
  Orders orders = get_orders(known_restraints_, restraints, particle_ordering);
  for (unsigned int i = 0; i < group.get_number_of_children(); ++i) {
    RMF::HDF5::ConstGroup ch = group.get_child_group(i);
    RMF::HDF5::FloatConstDataSet1D scores =
        ch.get_child_float_data_set_1d("scores");
    RMF::HDF5::IntConstDataSet2D assignments =
        ch.get_child_int_data_set_2d("assignments");
    for (unsigned int j = 0; j < scores.get_size()[0]; ++j) {
      double s = scores.get_value(RMF::HDF5::DataSetIndex1D(j));
      RMF::HDF5::Ints rw = assignments.get_row(RMF::HDF5::DataSetIndex1D(j));
      Ints psit(rw.begin(), rw.end());
      Assignment ass = orders[i].get_subset_ordered(psit);
      cache_.insert(Key(restraints[i], ass), s);
    }
  }
  validate();
}
Example #7
0
void RestraintCache::add_restraint_set_internal(kernel::RestraintSet *rs,
                                                unsigned int index,
                                                const Subset &cur_subset,
                                                double cur_max,
                                                const DepMap &dependencies) {
  IMP_LOG_TERSE("Parsing restraint set " << Showable(rs) << std::endl);
  if (cur_max < std::numeric_limits<double>::max()) {
    for (kernel::RestraintSet::RestraintIterator it = rs->restraints_begin();
         it != rs->restraints_end(); ++it) {
      add_restraint_internal(*it, index, rs, cur_max, cur_subset, dependencies);
    }
  } else {
    for (kernel::RestraintSet::RestraintIterator it = rs->restraints_begin();
         it != rs->restraints_end(); ++it) {
      add_restraint_internal(*it, index, nullptr,
                             std::numeric_limits<double>::max(), Subset(),
                             dependencies);
    }
  }
}
Example #8
0
void RestraintCache::add_restraints(const kernel::RestraintsAdaptor &rs) {
  IMP_OBJECT_LOG;
  if (rs.empty()) return;
  kernel::Model *m = rs[0]->get_model();
  DependencyGraph dg = get_dependency_graph(m);
  ParticleStatesTable *pst = cache_.get_generator().get_particle_states_table();
  DepMap dependencies;
  kernel::ParticlesTemp allps = pst->get_particles();
  DependencyGraphVertexIndex index = IMP::get_vertex_index(dg);
  for (unsigned int i = 0; i < allps.size(); ++i) {
    kernel::ParticlesTemp depp =
        get_dependent_particles(allps[i], allps, dg, index);
    for (unsigned int j = 0; j < depp.size(); ++j) {
      dependencies[depp[j]].push_back(allps[i]);
    }
    dependencies[allps[i]].push_back(allps[i]);
    IMP_LOG_TERSE("Particle " << Showable(allps[i]) << " controls "
                              << dependencies[allps[i]] << std::endl);
  }

  for (unsigned int i = 0; i < rs.size(); ++i) {
    base::Pointer<kernel::Restraint> r = rs[i]->create_decomposition();
    IMP_IF_LOG(TERSE) {
      IMP_LOG_TERSE("Before:" << std::endl);
      IMP_LOG_WRITE(TERSE, show_restraint_hierarchy(rs[i]));
    }
    if (r) {
      IMP_LOG_TERSE("after:" << std::endl);
      IMP_LOG_WRITE(TERSE, show_restraint_hierarchy(r));
      add_restraint_internal(r, next_index_, nullptr,
                             std::numeric_limits<double>::max(), Subset(),
                             dependencies);
    }
    ++next_index_;
  }
  IMP_IF_LOG(TERSE) {
    IMP_LOG_WRITE(TERSE, show_restraint_information(IMP_STREAM));
  }
}
IncrementalScoringFunction::Data IncrementalScoringFunction::create_data(
    ParticleIndex pi, RestraintsTemp cr,
    const boost::unordered_map<Restraint *, int> &all,
    const Restraints &dummies) const {
  IMP_LOG_TERSE("Dependent restraints for particle "
                << get_model()->get_particle_name(pi) << " are " << cr
                << std::endl);
  Data ret;
  for (unsigned int j = 0; j < cr.size(); ++j) {
    if (all.find(cr[j]) != all.end()) {
      int index = all.find(cr[j])->second;
      IMP_INTERNAL_CHECK(
          std::find(ret.indexes.begin(), ret.indexes.end(), index) ==
              ret.indexes.end(),
          "Found duplicate restraint " << Showable(cr[j]) << " in list " << cr);
      ret.indexes.push_back(index);
    }
  }
  cr += RestraintsTemp(dummies.begin(), dummies.end());
  ret.sf = new IncrementalRestraintsScoringFunction(
      cr, 1.0, NO_MAX, get_model()->get_particle_name(pi) + " restraints");
  return ret;
}