ParticlesTemp RigidBodyMover::propose_move(Float f) {
    IMP_OBJECT_LOG;
    {
        ::boost::uniform_real<> rand(0,1);
        double fc =rand(random_number_generator);
        if (fc > f) return ParticlesTemp();
    }
    last_transformation_= d_.get_reference_frame().get_transformation_to();
    algebra::Vector3D translation
        = algebra::get_random_vector_in(algebra::Sphere3D(d_.get_coordinates(),
                                        max_translation_));
    algebra::Vector3D axis =
        algebra::get_random_vector_on(algebra::Sphere3D(algebra::Vector3D(0.0,
                                      0.0,
                                      0.0),
                                      1.));
    ::boost::uniform_real<> rand(-max_angle_,max_angle_);
    Float angle =rand(random_number_generator);
    algebra::Rotation3D r
        = algebra::get_rotation_about_axis(axis, angle);
    algebra::Rotation3D rc
        = r*d_.get_reference_frame().get_transformation_to().get_rotation();
    algebra::Transformation3D t(rc, translation);
    IMP_LOG(VERBOSE,"proposed move " << t << std::endl);
    d_.set_reference_frame(algebra::ReferenceFrame3D(t));
    return ParticlesTemp(1, d_);
}
Example #2
0
InteractionGraph get_interaction_graph(ScoringFunctionAdaptor rsi,
                                       const ParticlesTemp &ps) {
  if (ps.empty()) return InteractionGraph();
  InteractionGraph ret(ps.size());
  Restraints rs =
      create_decomposition(rsi->create_restraints());
  // Model *m= ps[0]->get_model();
  boost::unordered_map<ModelObject *, int> map;
  InteractionGraphVertexName pm = boost::get(boost::vertex_name, ret);
  DependencyGraph dg = get_dependency_graph(ps[0]->get_model());
  DependencyGraphVertexIndex index = IMP::get_vertex_index(dg);
  /*IMP_IF_LOG(VERBOSE) {
    IMP_LOG_VERBOSE( "dependency graph is \n");
    IMP::internal::show_as_graphviz(dg, std::cout);
    }*/
  for (unsigned int i = 0; i < ps.size(); ++i) {
    ParticlesTemp t = get_dependent_particles(
        ps[i], ParticlesTemp(ps.begin(), ps.end()), dg, index);
    for (unsigned int j = 0; j < t.size(); ++j) {
      IMP_USAGE_CHECK(map.find(t[j]) == map.end(),
                      "Currently particles which depend on more "
                          << "than one particle "
                          << "from the input set are not supported."
                          << "  Particle \"" << t[j]->get_name()
                          << "\" depends on \"" << ps[i]->get_name()
                          << "\" and \""
                          << ps[map.find(t[j])->second]->get_name() << "\"");
      map[t[j]] = i;
    }
    IMP_IF_LOG(VERBOSE) {
      IMP_LOG_VERBOSE("Particle \"" << ps[i]->get_name() << "\" controls ");
      for (unsigned int i = 0; i < t.size(); ++i) {
        IMP_LOG_VERBOSE("\"" << t[i]->get_name() << "\" ");
      }
      IMP_LOG_VERBOSE(std::endl);
    }
    pm[i] = ps[i];
  }
  IMP::Restraints all_rs = IMP::get_restraints(rs);
  for (Restraints::const_iterator it = all_rs.begin();
       it != all_rs.end(); ++it) {
    ModelObjectsTemp pl = (*it)->get_inputs();
    add_edges(ps, pl, map, *it, ret);
  }
  /* Make sure that composite score states (eg the normalizer for
     rigid body rotations) don't induce interactions among unconnected
     particles.*/
  ScoreStatesTemp ss = get_required_score_states(rs);
  for (ScoreStatesTemp::const_iterator it = ss.begin(); it != ss.end(); ++it) {
    ModelObjectsTemps interactions = (*it)->get_interactions();
    for (unsigned int i = 0; i < interactions.size(); ++i) {
      add_edges(ps, interactions[i], map, *it, ret);
    }
  }
  IMP_INTERNAL_CHECK(boost::num_vertices(ret) == ps.size(),
                     "Wrong number of vertices " << boost::num_vertices(ret)
                                                 << " vs " << ps.size());
  return ret;
}
Example #3
0
Restraints _ConstRestraint::do_create_decomposition() const {
  Restraints ret;
  for (unsigned int i = 0; i < ps_.size(); ++i) {
    ret.push_back(
        new _ConstRestraint(v_ / ps_.size(), ParticlesTemp(1, ps_[i])));
    ret.back()->set_last_score(v_ / ps_.size());
  }
  return ret;
}
ModelObjectsTemp WeightedExcludedVolumeRestraint::do_get_inputs() const {
    ModelObjectsTemp ret = rb_refiner_->get_inputs(
                               get_model(), IMP::get_indexes(ParticlesTemp(particles_begin(),
                                       particles_end())));
    for (ParticleConstIterator it = particles_begin(); it != particles_end();
            ++it) {
        ParticlesTemp curr = rb_refiner_->get_refined(*it);
        ret += curr;
    }
    return ret;
}
Example #5
0
ParticleIndexes Simulator::get_simulation_particle_indexes() const {
  IMP_OBJECT_LOG;
  ParticleIndexes ps;
  if (get_number_of_particles() == 0) {
    Model *m = get_model();
    ParticleIndexes pis = m->get_particle_indexes();
    for (ParticleIndexes::const_iterator it = pis.begin();
         it != pis.end(); ++it) {
      if (get_is_simulation_particle(*it)) {
        ps.push_back(*it);
      }
    }
  } else {
    ps = IMP::internal::get_index(
        ParticlesTemp(particles_begin(), particles_end()));
  }
  return ps;
}
Example #6
0
SubsetGraph get_restraint_graph(ScoringFunctionAdaptor in,
                                const ParticleStatesTable *pst) {
  RestraintsTemp rs =
      IMP::create_decomposition(in->create_restraints());
  // ScoreStatesTemp ss= get_required_score_states(rs);
  SubsetGraph ret(rs.size());  // + ss.size());
  IMP_LOG_TERSE("Creating restraint graph on " << rs.size() << " restraints."
                                               << std::endl);
  boost::unordered_map<Particle *, int> map;
  SubsetGraphVertexName pm = boost::get(boost::vertex_name, ret);
  DependencyGraph dg = get_dependency_graph(rs[0]->get_model());
  DependencyGraphVertexIndex index = IMP::get_vertex_index(dg);
  /*IMP_IF_LOG(VERBOSE) {
    IMP_LOG_VERBOSE( "dependency graph is \n");
    IMP::internal::show_as_graphviz(dg, std::cout);
    }*/
  Subset ps = pst->get_subset();
  for (unsigned int i = 0; i < ps.size(); ++i) {
    ParticlesTemp t = get_dependent_particles(
        ps[i], ParticlesTemp(ps.begin(), ps.end()), dg, index);
    for (unsigned int j = 0; j < t.size(); ++j) {
      IMP_USAGE_CHECK(map.find(t[j]) == map.end(),
                      "Currently particles which depend on more "
                          << "than one particle "
                          << "from the input set are not supported."
                          << "  Particle \"" << t[j]->get_name()
                          << "\" depends on \"" << ps[i]->get_name()
                          << "\" and \""
                          << ps[map.find(t[j])->second]->get_name() << "\"");
      map[t[j]] = i;
    }
    IMP_IF_LOG(VERBOSE) {
      IMP_LOG_VERBOSE("Particle \"" << ps[i]->get_name() << "\" controls ");
      for (unsigned int i = 0; i < t.size(); ++i) {
        IMP_LOG_VERBOSE("\"" << t[i]->get_name() << "\" ");
      }
      IMP_LOG_VERBOSE(std::endl);
    }
  }
  for (unsigned int i = 0; i < rs.size(); ++i) {
    ParticlesTemp pl = IMP::get_input_particles(rs[i]->get_inputs());
    std::sort(pl.begin(), pl.end());
    pl.erase(std::unique(pl.begin(), pl.end()), pl.end());
    Subset os(pl);
    for (unsigned int j = 0; j < pl.size(); ++j) {
      pl[j] = ps[map[pl[j]]];
    }
    std::sort(pl.begin(), pl.end());
    pl.erase(std::unique(pl.begin(), pl.end()), pl.end());
    Subset s(pl);
    IMP_LOG_VERBOSE("Subset for restraint " << rs[i]->get_name() << " is " << s
                                            << " from " << os << std::endl);
    pm[i] = s;
  }
  /*ScoreStatesTemp ss= get_required_score_states(rs);
    for (ScoreStatesTemp::const_iterator it= ss.begin();
    it != ss.end(); ++it) {
    ParticlesTemp pl= (*it)->get_input_particles();
    add_edges(ps, pl, map, *it, ret);
    ParticlesTemp opl= (*it)->get_output_particles();
    add_edges(ps, opl, map, *it, ret);
    }
    IMP_INTERNAL_CHECK(boost::num_vertices(ret) == ps.size(),
    "Wrong number of vertices "
    << boost::num_vertices(ret)
    << " vs " << ps.size());*/
  for (unsigned int i = 0; i < boost::num_vertices(ret); ++i) {
    for (unsigned int j = 0; j < i; ++j) {
      if (get_intersection(pm[i], pm[j]).size() > 0) {
        boost::add_edge(i, j, ret);
        IMP_LOG_VERBOSE("Connecting " << rs[i]->get_name() << " with "
                                      << rs[j]->get_name() << std::endl);
      }
    }
  }
  return ret;
}
ModelObjectsTemp ConsecutivePairContainer::do_get_inputs() const {
  return ParticlesTemp();
}
ParticlesTemp PairContainerStatistics::get_input_particles() const {
  return ParticlesTemp();
}
ParticlesTemp ConsecutivePairContainer::get_input_particles() const {
    return ParticlesTemp();
}
ParticlesTemp HarmonicUpperBoundSphereDiameterPairScore
::get_input_particles(Particle*p) const {
  return ParticlesTemp(1, p);
}
Example #11
0
ParticlesTemp FixedRefiner::get_input_particles(Particle *) const {
  return ParticlesTemp();
}
Example #12
0
ParticlesTemp CoverBond::get_output_particles(Particle *p) const {
  return ParticlesTemp(1,p);
}
Example #13
0
ModelObjectsTemp RigidBodyMover::do_get_inputs() const {
  ParticlesTemp ret = ParticlesTemp(1, d_);
  ret.insert(ret.end(), ps_.begin(), ps_.end());
  return ret;
}
Example #14
0
core::MonteCarloMoverResult RigidBodyMover::do_propose() {
  IMP_OBJECT_LOG;

  // store last reference frame of master rigid body
  oldtr_ = d_.get_reference_frame().get_transformation_to();

  // generate new coordinates of center of mass of master rb
  algebra::Vector3D nc = algebra::get_random_vector_in(
      algebra::Sphere3D(d_.get_coordinates(), max_tr_));

  // find center of the closest cell
  double mindist = 1.0e+24;
  unsigned icell = 0;
  for (unsigned int i = 0; i < ctrs_.size(); ++i) {
    // calculate distance between nc and cell center
    double dist = algebra::get_l2_norm(nc - ctrs_[i]);
    // find minimum distance
    if (dist < mindist) {
      mindist = dist;
      icell = i;
    }
  }

  // find inverse transformation
  algebra::Transformation3D cell_tr = trs_[icell].get_inverse();

  // r: rotation around random axis
  algebra::VectorD<3> axis = algebra::get_random_vector_on(
      algebra::Sphere3D(algebra::VectorD<3>(0.0, 0.0, 0.0), 1.));

  ::boost::uniform_real<> rand(-max_ang_, max_ang_);
  Float angle = rand(random_number_generator);
  algebra::Rotation3D r = algebra::get_rotation_about_axis(axis, angle);

  // ri: composing rotation of reference frame transformation and
  // rotation due to boundary-crossing
  algebra::Rotation3D ri =
      cell_tr.get_rotation() *
      d_.get_reference_frame().get_transformation_to().get_rotation();
  // rc: composing ri with random rotation r
  algebra::Rotation3D rc = r * ri;

  // new reference frame for master rb
  d_.set_reference_frame(algebra::ReferenceFrame3D(
      algebra::Transformation3D(rc, cell_tr.get_transformed(nc))));

  // set new coordinates for slave particles
  oldcoords_.clear();
  for (unsigned i = 0; i < ps_norb_.size(); ++i) {
    core::XYZ xyz = core::XYZ(ps_norb_[i]);
    algebra::Vector3D oc = xyz.get_coordinates();
    // store old coordinates
    oldcoords_.push_back(oc);
    // apply cell transformation
    algebra::Vector3D nc = cell_tr.get_transformed(oc);
    xyz.set_coordinates(nc);
  }

  // set new reference frames for slave rbs
  oldtrs_.clear();
  for (unsigned i = 0; i < rbs_.size(); ++i) {
    algebra::Transformation3D ot =
        rbs_[i].get_reference_frame().get_transformation_to();
    // store old reference frame transformation
    oldtrs_.push_back(ot);
    // create new reference frame
    algebra::Rotation3D rr = cell_tr.get_rotation() * ot.get_rotation();
    algebra::Vector3D tt = cell_tr.get_transformed(rbs_[i].get_coordinates());
    // set new reference frame for slave rbs
    rbs_[i].set_reference_frame(
        algebra::ReferenceFrame3D(algebra::Transformation3D(rr, tt)));
  }

  ParticlesTemp ret = ParticlesTemp(1, d_);
  ret.insert(ret.end(), ps_.begin(), ps_.end());

  return core::MonteCarloMoverResult(get_indexes(ret), 1.0);
}
/* Return all particles whose attributes are read by the restraints. To
   do this, ask the pair score what particles it uses.*/
ParticlesTemp ExampleRestraint::get_input_particles() const
{
  return ParticlesTemp(1,p_);
}
Example #16
0
ParticlesTemp Transform::get_output_particles(Particle *p) const {
  return ParticlesTemp(1,p);
}
ModelObjectsTemp vonMisesKappaConjugateRestraint::do_get_inputs() const {
  return ParticlesTemp(1, kappa_);
}
/* Return all particles whose attributes are read by the restraints. To
   do this, ask the pair score what particles it uses.*/
ModelObjectsTemp vonMisesKappaJeffreysRestraint::do_get_inputs() const {
  return ParticlesTemp(1, kappa_);
}
ParticlesTemp RigidBodyMover::get_output_particles() const {
    return ParticlesTemp(1, d_);
}


namespace {
  ParticleIndexes expand(Particle *p, Refiner *r) {
    if (r->get_can_refine(p)) {
      ParticleIndexes ret= IMP::internal::get_index(r->get_refined(p));
      IMP_IF_CHECK(USAGE) {
        compatibility::set<ParticleIndex> uret(ret.begin(), ret.end());
        IMP_USAGE_CHECK(uret.size()==ret.size(),
                        "Duplicate particles in refined result: "
                        << uret.size() << " != " << ret.size());
      }
      return ret;
    } else {
      return IMP::internal::get_index(ParticlesTemp(1,p));
    }
  }
  void fill_close_pairs(ClosePairsFinder* cpf,
                        Model *m,
                        double dist,
                        const ParticleIndexes &pa,
                        const ParticleIndexes &pb,
                        ParticleIndexPairs &pairs) {
    cpf->set_distance(dist);
    pairs= cpf->get_close_pairs(m, pa, pb);
    /*for (unsigned int i=0; i< ppt.size(); ++i) {
      double d=get_distance(XYZR(ppt[i][0]), XYZR(ppt[i][1]));
      if (d < dist) {
        distances.push_back(d);
        pairs.push_back(ppt[i]);
Example #21
0
/* Return all particles whose attributes are read by the restraints. To
   do this, ask the pair score what particles it uses.*/
ModelObjectsTemp JeffreysRestraint::do_get_inputs() const {
  return ParticlesTemp(1, p_);
}
ParticlesTemp DistributeQuadsScoreState
::get_output_particles() const {
  return ParticlesTemp();
}
ParticlesTemp
InternalDynamicListTripletContainer::get_input_particles() const {
  return ParticlesTemp();
}
ParticlesTemp QuadContainerStatistics::get_output_particles() const {
  return ParticlesTemp();
}
Example #25
0
ParticleIndexesAdaptor::ParticleIndexesAdaptor(const Particles &ps)
    : tmp_(new ParticleIndexes(ps.size())), val_(tmp_.get()) {
  *tmp_ = get_indexes(ParticlesTemp(ps.begin(), ps.end()));
}