示例#1
0
void MolecularDynamics::assign_velocities(Float temperature) {
  ParticleIndexes ips = get_simulation_particle_indexes();
  setup_degrees_of_freedom(ips);
  ParticlesTemp ps = IMP::internal::get_particle(get_model(), ips);

  boost::normal_distribution<Float> mrng(0., 1.);
  boost::variate_generator<RandomNumberGenerator &,
                           boost::normal_distribution<Float> >
      sampler(random_number_generator, mrng);

  for (ParticlesTemp::iterator iter = ps.begin(); iter != ps.end();
       ++iter) {
    Particle *p = *iter;
    LinearVelocity(p).set_velocity(algebra::Vector3D(sampler(), sampler(),
                                                     sampler()));
  }

  Float rescale =
      sqrt(temperature / get_kinetic_temperature(get_kinetic_energy()));

  for (ParticlesTemp::iterator iter = ps.begin(); iter != ps.end();
       ++iter) {
    Particle *p = *iter;
    LinearVelocity v(p);

    algebra::Vector3D velocity = v.get_velocity();
    velocity *= rescale;
    v.set_velocity(velocity);
  }
}
ParticlesTemp
GaussianProcessInterpolationRestraintSparse::get_input_particles() const
{
    ParticlesTemp ret;
    ParticlesTemp ret1 = gpi_->mean_function_->get_input_particles();
    ret.insert(ret.end(),ret1.begin(),ret1.end());
    ParticlesTemp ret2 = gpi_->covariance_function_->get_input_particles();
    ret.insert(ret.end(),ret2.begin(),ret2.end());
    return ret;
}
ParticlesTemp CHARMMStereochemistryRestraint::get_input_particles() const
{
  ParticlesTemp ps;
  for (Particles::const_iterator b = bonds_.begin(); b != bonds_.end(); ++b) {
    ps.push_back(*b);
    ParticlesTemp bps = bond_score_->get_input_particles(*b);
    ps.insert(ps.end(), bps.begin(), bps.end());
  }
  for (Particles::const_iterator a = angles_.begin();
       a != angles_.end(); ++a) {
    ps.push_back(*a);
    ParticlesTemp bps = angle_score_->get_input_particles(*a);
    ps.insert(ps.end(), bps.begin(), bps.end());
  }
  for (Particles::const_iterator d = dihedrals_.begin();
       d != dihedrals_.end(); ++d) {
    ps.push_back(*d);
    ParticlesTemp bps = dihedral_score_->get_input_particles(*d);
    ps.insert(ps.end(), bps.begin(), bps.end());
  }
  for (Particles::const_iterator i = impropers_.begin();
       i != impropers_.end(); ++i) {
    ps.push_back(*i);
    ParticlesTemp bps = improper_score_->get_input_particles(*i);
    ps.insert(ps.end(), bps.begin(), bps.end());
  }
  return ps;
}
示例#4
0
IMPCORE_BEGIN_NAMESPACE
MoveStatisticsScoreState::MoveStatisticsScoreState(
    const ParticlesTemp &ps)
    : ScoreState(ps[0]->get_model(), "MoveStatisticsScoreState%1%"),
      ps_(ps.begin(), ps.end()) {
  reset();
}
ParticlesTemp
CoreCloseBipartitePairContainer::get_all_possible_particles() const {
  ParticlesTemp ret = sc_[0]->get_particles();
  ParticlesTemp ret1= sc_[1]->get_particles();
  ret.insert(ret.end(), ret1.begin(), ret1.end());
  return ret;
}
示例#6
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;
}
IMPATOM_BEGIN_NAMESPACE

RemoveRigidMotionOptimizerState::RemoveRigidMotionOptimizerState(
    const ParticlesTemp &pis, unsigned skip_steps) :
  pis_(pis.begin(), pis.end()), skip_steps_(skip_steps),
    call_number_(0)
{
  vs_[0] = FloatKey("vx");
  vs_[1] = FloatKey("vy");
  vs_[2] = FloatKey("vz");
}
示例#8
0
const ParticlesTemp RigidLeavesRefiner::get_refined(Particle *p) const {
  ParticlesTemp members = core::RigidBody(p).get_rigid_members();
  ParticlesTemp ret;
  for (ParticlesTemp::const_iterator it = members.begin(); it != members.end();
       ++it) {
    if (atom::Hierarchy::get_is_setup(*it)
        && atom::Hierarchy(*it).get_number_of_children() == 0) {
      ret.push_back(*it);
    }
  }
  return ret;
}
示例#9
0
core::MonteCarloMoverResult BallMover::do_propose() {
  IMP_OBJECT_LOG;

  // random displacement
  algebra::Vector3D displacement = algebra::get_random_vector_in(
      algebra::Sphere3D(algebra::Vector3D(0.0, 0.0, 0.0), max_tr_));

  // store old coordinates of master particle
  oldcoord_ = core::XYZ(p_).get_coordinates();

  // master particle coordinates after displacement
  algebra::Vector3D nc = oldcoord_ + displacement;

  // find center of the closest cell
  double mindist = 1.0e+24;
  unsigned icell = 0;
  for (unsigned 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();

  // set new coordinates for master particle
  core::XYZ(p_).set_coordinates(cell_tr.get_transformed(nc));

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

  ParticlesTemp ret;
  ret.push_back(p_);
  ret.insert(ret.end(), ps_.begin(), ps_.end());

  return core::MonteCarloMoverResult(get_indexes(ret), 1.0);
}
示例#10
0
Float MolecularDynamics::get_kinetic_energy() const {
  // Conversion factor to get energy in kcal/mol from velocities in A/fs and
  // mass in g/mol
  static const Float conversion = 1.0 / 4.1868e-4;

  Float ekinetic = 0.;
  ParticlesTemp ps = get_simulation_particles();
  for (ParticlesTemp::iterator iter = ps.begin(); iter != ps.end();
       ++iter) {
    Particle *p = *iter;
    algebra::Vector3D v = LinearVelocity(p).get_velocity();
    Float mass = Mass(p).get_mass();

    ekinetic += mass * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  }
  return 0.5 * ekinetic * conversion;
}
示例#11
0
// write approximate function, remove rigid bodies for intermediates
core::RigidBody create_rigid_body(const Hierarchies& h,
                                  std::string name) {
  if (h.empty()) return core::RigidBody();
  for (unsigned int i=0; i< h.size(); ++i) {
    IMP_USAGE_CHECK(h[i].get_is_valid(true), "Invalid hierarchy passed.");
  }
  Particle *rbp= new Particle(h[0]->get_model());
  rbp->set_name(name);
  ParticlesTemp all;
  for (unsigned int i=0; i< h.size(); ++i) {
    ParticlesTemp cur= rb_process(h[i]);
    all.insert(all.end(), cur.begin(), cur.end());
  }
  core::RigidBody rbd
    = core::RigidBody::setup_particle(rbp, core::XYZs(all));
  rbd.set_coordinates_are_optimized(true);
  for (unsigned int i=0; i< h.size(); ++i) {
    IMP_INTERNAL_CHECK(h[i].get_is_valid(true), "Invalid hierarchy produced");
  }
  return rbd;
}
示例#12
0
Subset RestraintCache::get_subset(Restraint *r,
                                  const DepMap &dependencies) const {
  ParticlesTemp ups = IMP::get_input_particles(r->get_inputs());
  std::sort(ups.begin(), ups.end());
  ups.erase(std::unique(ups.begin(), ups.end()), ups.end());
  ParticlesTemp outps;
  for (unsigned int i = 0; i < ups.size(); ++i) {
    DepMap::const_iterator it = dependencies.find(ups[i]);
    if (it != dependencies.end()) {
      outps = outps + it->second;
    }
  }
  std::sort(outps.begin(), outps.end());
  outps.erase(std::unique(outps.begin(), outps.end()), outps.end());
  return Subset(outps);
}
示例#13
0
ExampleSubsetFilterTable::ExampleSubsetFilterTable(
    unsigned int max_diff, const ParticlesTemp& ps)
    : domino::SubsetFilterTable("ExampleSubsetFilterTable%1%"),
      max_diff_(max_diff),
      ps_(ps.begin(), ps.end()) {}
示例#14
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;
}
示例#15
0
ModelObjectsTemp RigidBodyMover::do_get_inputs() const {
  ParticlesTemp ret = ParticlesTemp(1, d_);
  ret.insert(ret.end(), ps_.begin(), ps_.end());
  return ret;
}
void CoreClosePairContainer::check_duplicates_input() const {
  ParticlesTemp ps = c_->get_particles();
  std::sort(ps.begin(), ps.end());
  IMP_USAGE_CHECK(std::unique(ps.begin(), ps.end()) == ps.end(),
                  "Duplicates in input");
}
示例#17
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);
}
示例#18
0
ModelObjectsTemp BallMover::do_get_inputs() const {
  ParticlesTemp ret;
  ret.push_back(p_);
  ret.insert(ret.end(), ps_.begin(), ps_.end());
  return ret;
}