예제 #1
0
// compute centroid from refined particles
void CentroidOfRefined::apply_index(Model *m,
                                    ParticleIndex pi) const {
  IMP_LOG_PROGRESS("BEGIN - updating centroid pi" << pi << " coords " <<
                   IMP::core::XYZ(m, pi).get_coordinates());
  // retrieving pis by ref if possible is cumbersome but is required for speed
  ParticleIndexes pis_if_not_byref;
  ParticleIndexes const* pPis;
  if(refiner_->get_is_by_ref_supported()){
    ParticleIndexes const& pis =
      refiner_->get_refined_indexes_by_ref(m, pi);
    pPis = &pis;
  } else{
    pis_if_not_byref = refiner_->get_refined_indexes(m, pi);
    pPis = &pis_if_not_byref;
  }
  ParticleIndexes const& pis = *pPis;
  unsigned int n = pis.size();
  double tw = 0;
  if (w_ != FloatKey()) {
    IMP_USAGE_CHECK( m->get_has_attribute(w_, pi),
                     "Centroid particle lacks non-trivial weight key" << w_ );
    for (unsigned int i = 0; i < n; ++i) {
      ParticleIndex cur_pi = pis[i];
      IMP_USAGE_CHECK( m->get_has_attribute(w_, cur_pi),
                       "CentroidOfRefined - Fine particle #" << i
                       << " lacks non-trivial weight key" << w_);
      tw += m->get_attribute(w_, cur_pi);
    }
    m->set_attribute(w_, pi, tw);
  } else {
    tw = 1;
  }
  for (unsigned int j = 0; j < ks_.size(); ++j) {
    double v = 0;
    for (unsigned int i = 0; i < n; ++i) {
      double w;
      ParticleIndex cur_pi = pis[i];
      if (w_ != FloatKey()) {
        w = m->get_attribute(w_, cur_pi) / tw;
      } else {
        w = Float(1.0) / n;
      }
      v += m->get_attribute(ks_[j], cur_pi) * w;
    }
    m->set_attribute(ks_[j], pi, v);
  }
  IMP_LOG_PROGRESS("DONE - updated centroid pi" << pi << " coords " <<
                   IMP::core::XYZ(m, pi).get_coordinates());
}
예제 #2
0
void ExclusiveConsecutivePairContainer::do_destroy() {
  if(get_model() == nullptr){ return; }
  if(!get_model()->get_is_valid()) { return ; }
  IMP_LOG_PROGRESS("Destroying exclusive pair container with "
                   << ps_.size() << " particles" << std::endl);
  for (unsigned int i = 0; i < ps_.size(); ++i) {
    if(!get_model()->get_has_particle(ps_[i])) {
        continue;
    }
    if( get_model()->get_has_attribute(get_exclusive_key(), ps_[i]) ) {
        get_model()->remove_attribute(get_exclusive_key(), ps_[i]);
    }
    if( get_model()->get_has_attribute(get_exclusive_object_key(), ps_[i]) ){
      get_model()->remove_attribute(get_exclusive_object_key(), ps_[i]);
    }
  }
}
예제 #3
0
/** Take a set of core::XYZR particles and relax them relative to a set of
    restraints. Excluded volume is handle separately, so don't include it
in the passed list of restraints. */
void optimize_balls(const kernel::ParticlesTemp &ps, const kernel::RestraintsTemp &rs,
                    const PairPredicates &excluded,
                    const OptimizerStates &opt_states, base::LogLevel ll) {
    // make sure that errors and log messages are marked as coming from this
    // function
    IMP_FUNCTION_LOG;
    base::SetLogState sls(ll);
    IMP_ALWAYS_CHECK(!ps.empty(), "No kernel::Particles passed.", ValueException);
    kernel::Model *m = ps[0]->get_model();
    //double scale = core::XYZR(ps[0]).get_radius();

    IMP_NEW(core::SoftSpherePairScore, ssps, (10));
    IMP_NEW(core::ConjugateGradients, cg, (m));
    cg->set_optimizer_states(opt_states);
    {
        // set up restraints for cg
        IMP_NEW(container::ListSingletonContainer, lsc, (ps));
        IMP_NEW(container::ClosePairContainer, cpc,
                (lsc, 0, core::XYZR(ps[0]).get_radius()));
        cpc->add_pair_filters(excluded);
        base::Pointer<kernel::Restraint> r
            = container::create_restraint(ssps.get(), cpc.get());
        cg->set_scoring_function(rs + kernel::RestraintsTemp(1, r.get()));
        cg->set_optimizer_states(opt_states);
    }
    IMP_NEW(core::MonteCarlo, mc, (m));
    mc->set_optimizer_states(opt_states);
    IMP_NEW(core::IncrementalScoringFunction, isf, (ps, rs));
    {
        // set up MC
        mc->add_mover(create_serial_mover(ps));
        // we are special casing the nbl term for montecarlo, but using all for CG
        mc->set_incremental_scoring_function(isf);
        // use special incremental support for the non-bonded part
        isf->add_close_pair_score(ssps, 0, ps, excluded);
        // make pointer vector
    }

    IMP_LOG_PROGRESS("Performing initial optimization" << std::endl);
    {
        boost::ptr_vector<ScopedSetFloatAttribute> attrs;
        for (unsigned int j = 0; j < attrs.size(); ++j) {
            attrs.push_back(
                new ScopedSetFloatAttribute(ps[j], core::XYZR::get_radius_key(), 0));
        }
        cg->optimize(1000);
    }
    // shrink each of the particles, relax the configuration, repeat
    for (int i = 0; i < 11; ++i) {
        boost::ptr_vector<ScopedSetFloatAttribute> attrs;
        double factor = .1 * i;
        IMP_LOG_PROGRESS("Optimizing with radii at " << factor << " of full"
                         << std::endl);
        for (unsigned int j = 0; j < ps.size(); ++j) {
            attrs.push_back(
                new ScopedSetFloatAttribute(ps[j], core::XYZR::get_radius_key(),
                                            core::XYZR(ps[j]).get_radius() * factor));
        }
        // changed all radii
        isf->set_moved_particles(isf->get_movable_indexes());
        for (int j = 0; j < 5; ++j) {
            mc->set_kt(100.0 / (3 * j + 1));
            mc->optimize(ps.size() * (j + 1) * 100);
            double e = cg->optimize(10);
            IMP_LOG_PROGRESS("Energy is " << e << std::endl);
            if (e < .000001) break;
        }
    }
}