Ejemplo n.º 1
0
DensityGrid get_rasterized_fast(const Gaussian3Ds &gmm, const Floats &weights,
                                double cell_width, const BoundingBox3D &bb, double factor) {
  DensityGrid ret(cell_width, bb, 0);
  for (unsigned int ng = 0; ng < gmm.size(); ng++) {
    Eigen::Matrix3d covar = get_covariance(gmm[ng]);
    Eigen::Matrix3d inverse = Eigen::Matrix3d::Zero(3, 3);

    double determinant;
    bool invertible;
    covar.computeInverseAndDetWithCheck(inverse, determinant, invertible);
    IMP_INTERNAL_CHECK((invertible && determinant > 0),
                       "Tried to invert Gaussian, but it's not proper matrix");
    double pre(get_gaussian_eval_prefactor(determinant));
    Eigen::Vector3d evals = covar.eigenvalues().real();
    double maxeval = sqrt(evals.maxCoeff());
    double cutoff = factor * maxeval;
    double cutoff2 = cutoff * cutoff;
    Vector3D c = gmm[ng].get_center();
    Vector3D lower = c - Vector3D(cutoff, cutoff, cutoff);
    Vector3D upper = c + Vector3D(cutoff, cutoff, cutoff);
    GridIndex3D lowerindex = ret.get_nearest_index(lower);
    GridIndex3D upperindex = ret.get_nearest_index(upper);
    Eigen::Vector3d center(c.get_data());
    IMP_INTERNAL_CHECK(invertible, "matrix wasn't invertible! uh oh!");
    IMP_GRID3D_FOREACH_SMALLER_EXTENDED_INDEX_RANGE(ret, upperindex, lowerindex,
                                                    upperindex, {
      GridIndex3D i(voxel_index[0], voxel_index[1], voxel_index[2]);
      Eigen::Vector3d r(get_vec_from_center(i, ret, center));
      if (r.squaredNorm() < cutoff2) {
        update_value(&ret, i, r, inverse, pre, weights[ng]);
      }
    })
  }
  return ret;
}
Ejemplo n.º 2
0
void KMCentersNode::post_one_neighbor(KMPointArray *sums, KMPoint *sum_sqs,
                                      Ints *weights, int center_ind,
                                      const KMPoint &p) {
    IMP_INTERNAL_CHECK((unsigned int)center_ind < sums->size(),
                       "the center index is out of range\n");
    // increment sums and sums sq
    for (int d = 0; d < centers_->get_dim(); d++) {
        (*((*sums)[center_ind]))[d] += p[d];
        (*sum_sqs)[center_ind] += p[d] * p[d];
    }
    // incremet weight
    IMP_INTERNAL_CHECK((unsigned int)center_ind < weights->size(),
                       "the center index is out of range\n");
    (*weights)[center_ind] += 1;
}
Ejemplo n.º 3
0
Archivo: knn.cpp Proyecto: drussel/imp
void KNNData::fill_nearest_neighbors_v(const algebra::VectorKD &g,
                                       unsigned int k,
                                       double eps,
                                       Ints &ret) const {
  VectorWithIndex d(std::numeric_limits<int>::max(), g);
  RealRCTree::
    K_neighbor_search search(dynamic_cast<RealRCTree*>(tree_.get())
                             ->tree,
                             d, k, eps);
  IMP_IF_CHECK(base::USAGE_AND_INTERNAL) {
    int nump=std::distance(dynamic_cast<RealRCTree*>(tree_.get())
                           ->tree.begin(),
                           dynamic_cast<RealRCTree*>(tree_.get())
                           ->tree.end());
    int realk=std::min<int>(nump, k);
    IMP_CHECK_VARIABLE(realk);
    IMP_INTERNAL_CHECK(std::distance(search.begin(), search.end())
                       == static_cast<int>(realk),
                       "Got the wrong number of points out from CGAL neighbor"
                       << " search. Expected " << realk
                       << " got "
                       << std::distance(search.begin(), search.end()));
  }
  Ints::iterator rit = ret.begin();
  for ( RealRCTree::K_neighbor_search::iterator it = search.begin();
        it != search.end(); ++it) {
    *rit= it->first;
    ++rit;
  }
}
Ejemplo n.º 4
0
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));
}
Ejemplo n.º 5
0
DenseGrid3D<float> get_rasterized(const Gaussian3Ds &gmm, const Floats &weights,
                                  double cell_width, const BoundingBox3D &bb) {
  DenseGrid3D<float> ret(cell_width, bb, 0);
  for (unsigned int ng = 0; ng < gmm.size(); ng++) {
    IMP_Eigen::Matrix3d covar = get_covariance(gmm[ng]);
    // suppress warning
    IMP_Eigen::Matrix3d inverse = IMP_Eigen::Matrix3d::Zero(3, 3);
    double determinant;
    bool invertible;
    covar.computeInverseAndDetWithCheck(inverse, determinant, invertible);
    double pre = 1.0 / pow(2 * algebra::PI, 2.0 / 3.0) / std::sqrt(determinant);
    if (!invertible || determinant < 0) {
      std::cout << "\n\n\n->>>>not proper matrix!!\n\n\n" << std::endl;
    }
    IMP_Eigen::Vector3d center(gmm[ng].get_center().get_data());
    IMP_INTERNAL_CHECK(invertible, "matrix wasn't invertible! uh oh!");
    IMP_FOREACH(const DenseGrid3D<float>::Index & i, ret.get_all_indexes()) {
      Vector3D aloc = ret.get_center(i);
      IMP_Eigen::Vector3d loc(aloc[0], aloc[1], aloc[2]);
      IMP_Eigen::Vector3d r = loc - center;
      double d = r.transpose() * (inverse * r);
      double score = pre * weights[ng] * std::exp(-0.5 * (d));
      if (score > 1e10) {
        score = 100;
      }
      if (score > 0) {
        ret[i] += score;
      }
    }
  }
  return ret;
}
Ejemplo n.º 6
0
void assign_blame(const RestraintsTemp &rs,
                  const ParticlesTemp &ps, FloatKey attribute) {
  IMP_FUNCTION_LOG;
  for (unsigned int i = 0; i < ps.size(); ++i) {
    if (ps[i]->has_attribute(attribute)) {
      ps[i]->set_value(attribute, 0);
    } else {
      ps[i]->add_attribute(attribute, 0, false);
    }
  }
  Restraints drs;
  for (unsigned int i = 0; i < rs.size(); ++i) {
    Pointer<Restraint> rd = rs[i]->create_decomposition();
    if (rd) {
      drs.push_back(rd);
    }
  }
  IMP_NEW(RestraintsScoringFunction, rsf, (drs));
  rsf->evaluate(false);
  DependencyGraph dg = get_dependency_graph(IMP::internal::get_model(rs));
  // attempt to get around boost/gcc bug and the most vexing parse
  DependencyGraphVertexIndex dgi((IMP::get_vertex_index(dg)));
  ControlledBy controlled_by;
  for (unsigned int i = 0; i < ps.size(); ++i) {
    ParticlesTemp cps = get_dependent_particles(ps[i], ps, dg, dgi);
    IMP_INTERNAL_CHECK(cps.size() > 0, "No dependent particles for " << ps[i]);
    for (unsigned int j = 0; j < cps.size(); ++j) {
      controlled_by[cps[j]] = ps[i];
    }
  }
  for (unsigned int i = 0; i < drs.size(); ++i) {
    distribute_blame(drs[i], controlled_by, attribute, 1.0);
  }
}
Ejemplo n.º 7
0
void KMCentersTree::skeleton_tree(const Ints &p_id,
  KMPoint *bb_lo,KMPoint *bb_hi) {
  //TODO: where do get n from ?
  IMP_INTERNAL_CHECK(data_points_ != nullptr,
                     "Points must be supplied to construct tree.");
  if (p_id.size() == 0) {
    for (int i = 0; i < data_points_->get_number_of_points(); i++)
      p_id_.push_back(i);
  }
  else {
    for (int i = 0; i < data_points_->get_number_of_points(); i++)
      p_id_.push_back(p_id[i]);
  }
  if (bb_lo == nullptr || bb_hi == nullptr) {
    bnd_box_ = bounding_rectangle(0,data_points_->get_number_of_points()-1);;
  }
  // if points are provided, use it
  if (bb_lo != nullptr) {
    copy_point(bb_lo,bnd_box_->get_point(0));
  }
  if (bb_hi != nullptr) {
    copy_point(bb_hi,bnd_box_->get_point(1));
  }
  root_ = nullptr;
}
Ejemplo n.º 8
0
double get_volume_from_residue_type(ResidueType rt) {
  typedef std::pair<ResidueType, double> RP;
  static const RP radii[]={RP(ResidueType("ALA"), 2.516),
                     RP(ResidueType("ARG"), 3.244),
                     RP(ResidueType("ASN"), 2.887),
                     RP(ResidueType("ASP"), 2.866),
                     RP(ResidueType("CYS"), 2.710),
                     RP(ResidueType("GLN"), 3.008),
                     RP(ResidueType("GLU"), 2.997),
                     RP(ResidueType("GLY"), 2.273),
                     RP(ResidueType("HIS"), 3.051),
                     RP(ResidueType("ILE"), 3.047),
                     RP(ResidueType("LEU"), 3.052),
                     RP(ResidueType("LYS"), 3.047),
                     RP(ResidueType("MET"), 3.068),
                     RP(ResidueType("PHE"), 3.259),
                     RP(ResidueType("PRO"), 2.780),
                     RP(ResidueType("SER"), 2.609),
                     RP(ResidueType("THR"), 2.799),
                     RP(ResidueType("TRP"), 3.456),
                     RP(ResidueType("TYR"), 3.318),
                     RP(ResidueType("VAL"), 2.888)};
  static const IMP::base::map<ResidueType, double> radii_map(radii,
                                                                 radii
                                                                 +sizeof(radii)
                                                                 /sizeof(RP));
  if (radii_map.find(rt) == radii_map.end()) {
    IMP_THROW( "Can't approximate volume of non-standard residue "
               << rt, ValueException);
  }
  double r= radii_map.find(rt)->second;
  IMP_INTERNAL_CHECK(r>0, "Read garbage r for "<< rt);
  return algebra::get_volume(algebra::Sphere3D(algebra::get_zero_vector_d<3>(),
                                               r));
}
Ejemplo n.º 9
0
void HierarchySaveLink::add_recursive(Model *m, kernel::ParticleIndex root,
                                      kernel::ParticleIndex p,
                                      kernel::ParticleIndexes rigid_bodies,
                                      RMF::NodeHandle cur, Data &data) {
  IMP_LOG_VERBOSE("Adding " << atom::Hierarchy(m, p) << std::endl);
  // make sure not to double add
  if (p != root) set_association(cur, m->get_particle(p));
  data.save_static.setup_node(m, p, cur);
  bool local_coords =
      data.save_local_coordinates.setup_node(m, p, cur, rigid_bodies);
  bool global_coords =
      data.save_global_coordinates.setup_node(m, p, cur, rigid_bodies);
  bool static_coords =
      data.save_static_coordinates.setup_node(m, p, cur, rigid_bodies);
  IMP_INTERNAL_CHECK(!local_coords || !global_coords,
                     "A particle can't have saved local and global coords");

  do_setup_node(m, root, p, cur);

  if (core::RigidBody::get_is_setup(m, p)) {
    rigid_bodies.push_back(p);
  }
  for (unsigned int i = 0; i < atom::Hierarchy(m, p).get_number_of_children();
       ++i) {
    kernel::ParticleIndex pc = atom::Hierarchy(m, p).get_child_index(i);
    RMF::NodeHandle curc =
        cur.add_child(get_good_name(m, pc), RMF::REPRESENTATION);
    add_recursive(m, root, pc, rigid_bodies, curc, data);
  }
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
/**
/param[in] p the node posting
/param[in] sum the sum of coordinates
/param[in] sum_sq the sum of squares
/param[in] n_data number of points
/param[in] ctrInd center index
*/
void KMCentersNode::post_neighbor(KMPointArray *sums, KMPoint *sum_sqs,
                                  Ints *weights, int center_ind) {
    IMP_INTERNAL_CHECK((unsigned int)center_ind < sums->size(),
                       "the center index is out of range\n");
    // increment sum
    for (int d = 0; d < centers_->get_dim(); d++) {
        (*((*sums)[center_ind]))[d] += sum_[d];
    }
    // incremet weight
    IMP_INTERNAL_CHECK((unsigned int)center_ind < weights->size(),
                       "the center index is out of range\n");
    (*weights)[center_ind] += n_data_;
    // increment sum of squares
    IMP_INTERNAL_CHECK((unsigned int)center_ind < sum_sqs->size(),
                       "the center index is out of range\n");
    (*sum_sqs)[center_ind] += sum_sq_;
}
Ejemplo n.º 12
0
void Object::unref() const {
  IMP_INTERNAL_CHECK(count_ != 0, "Too many unrefs on object");
  IMP_LOG_MEMORY("Unrefing object \"" << get_name() << "\" (" << count_ << ") {"
                                      << this << "}" << std::endl);
  --count_;
  if (count_ == 0) {
    delete this;
  }
}
Ejemplo n.º 13
0
const ParticlesTemp BondEndpointsRefiner::get_refined(
    Particle *p) const {
  IMP_INTERNAL_CHECK(get_can_refine(p), "Trying to refine the unrefinable");
  Bond d(p);
  ParticlesTemp ps(2);
  ps[0] = d.get_bonded(0);
  ps[1] = d.get_bonded(1);
  return ps;
}
Ejemplo n.º 14
0
void Transform::apply_index(Model *m, ParticleIndex pi) const {
  if (!XYZ::get_is_setup(m, pi)) {
    IMP_INTERNAL_CHECK(ignore_non_xyz_,
                       "The particle does not have XYZ attributes");
    return;
  }
  XYZ xyz = XYZ(m, pi);
  xyz.set_coordinates(t_.get_transformed(xyz.get_coordinates()));
}
Ejemplo n.º 15
0
void Transform::apply(Particle *p) const
{
  if (!XYZ::particle_is_instance(p)) {
    IMP_INTERNAL_CHECK(ignore_non_xyz_,
                       "The particle does not have XYZ attributes");
    return;
  }
  XYZ xyz = XYZ(p);
  xyz.set_coordinates(t_.get_transformed(xyz.get_coordinates()));
}
Ejemplo n.º 16
0
Particle* graph_get_neighbor(Particle* a, int i, const GraphData &d)
{
  Particle *edge= graph_get_edge(a, i, d);
  if (graph_get_node(edge, 0, d) == a) {
    return graph_get_node(edge, 1, d);
  } else {
    IMP_INTERNAL_CHECK(graph_get_node(edge, 1, d) == a,
               "Broken graph");
    return graph_get_node(edge, 0, d);
  }
}
Ejemplo n.º 17
0
Particle *HierarchyLoadLink::do_create(RMF::NodeConstHandle node,
                                       kernel::Model *m) {
  IMP_FUNCTION_LOG;
  kernel::ParticleIndex ret = m->add_particle(node.get_name());
  data_.insert(std::make_pair(ret, boost::make_shared<Data>(node.get_file())));
  create_recursive(m, ret, ret, node, kernel::ParticleIndexes(), *data_[ret]);
  IMP_INTERNAL_CHECK(atom::Hierarchy(m, ret).get_is_valid(true),
                     "Invalid hierarchy created");
  data_.find(ret)->second->load_bonds.setup_bonds(node, m, ret);
  return m->get_particle(ret);
}
Ejemplo n.º 18
0
DensityGrid get_rasterized(const Gaussian3Ds &gmm, const Floats &weights,
                           double cell_width, const BoundingBox3D &bb) {
  DensityGrid ret(cell_width, bb, 0);
  for (unsigned int ng = 0; ng < gmm.size(); ng++) {
    Eigen::Matrix3d covar = get_covariance(gmm[ng]);
    Eigen::Matrix3d inverse = Eigen::Matrix3d::Zero(3, 3);

    double determinant;
    bool invertible;
    covar.computeInverseAndDetWithCheck(inverse, determinant, invertible);
    IMP_INTERNAL_CHECK((invertible && determinant > 0),
                       "Tried to invert Gaussian, but it's not proper matrix");
    double pre(get_gaussian_eval_prefactor(determinant));
    Eigen::Vector3d center(gmm[ng].get_center().get_data());
    IMP_INTERNAL_CHECK(invertible, "matrix wasn't invertible! uh oh!");
    IMP_FOREACH(const DensityGrid::Index & i, ret.get_all_indexes()) {
      Eigen::Vector3d r(get_vec_from_center(i, ret, center));
      update_value(&ret, i, r, inverse, pre, weights[ng]);
    }
  }
  return ret;
}
Ejemplo n.º 19
0
algebra::Vector3Ds get_normals(const Ints &faces,
                               const algebra::Vector3Ds &vertices) {
  IMP_INTERNAL_CHECK(faces.size() % 3 == 0, "Not triangles");
  IMP_INTERNAL_CHECK(faces.size() > 0, "No faces");
  Ints count(vertices.size());
  algebra::Vector3Ds sum(vertices.size(), algebra::get_zero_vector_d<3>());
  for (unsigned int i = 0; i < faces.size() / 3; ++i) {
    algebra::Vector3D n =
        get_normal(faces.begin() + 3 * i, faces.begin() + 3 * i + 3, vertices);
    IMP_INTERNAL_CHECK(!IMP::isnan(n[0]), "Nan found");
    for (unsigned int j = 0; j < 3; ++j) {
      int v = faces[3 * i + j];
      sum[v] += n;
      count[v] += 1;
    }
  }
  for (unsigned int i = 0; i < count.size(); ++i) {
    sum[i] /= count[i];
    IMP_INTERNAL_CHECK(!IMP::isnan(sum[i][0]),
                       "Nan found at end:" << count[i] << " on " << i);
  }
  return sum;
}
Ejemplo n.º 20
0
Object::~Object() {
  IMP_INTERNAL_CHECK(
      get_is_valid(),
      "Object " << this << " previously freed "
                << "but something is trying to delete it again. Make sure "
                << "that all C++ code uses IMP::Pointer objects to"
                << " store it.");
#if IMP_HAS_CHECKS >= IMP_USAGE
  // if there is no exception currently being handled warn if it was not owned
  if (!was_owned_ && !std::uncaught_exception()) {
    IMP_WARN(
        "Object \"" << get_name() << "\" was never used."
                    << " See the IMP::Object documentation for an explanation."
                    << std::endl);
  }
#endif
#if IMP_HAS_CHECKS >= IMP_INTERNAL
  remove_live_object(this);
#endif
  IMP_LOG_MEMORY("Destroying object \"" << get_name() << "\" (" << this << ")"
                                        << std::endl);
#if IMP_HAS_LOG > IMP_NONE && !IMP_BASE_HAS_LOG4CXX
  // cleanup
  if (log_level_ != DEFAULT) {
    IMP::base::set_log_level(log_level_);
  }
#endif

  IMP_INTERNAL_CHECK(get_ref_count() == 0,
                     "Deleting object which still has references");
#if IMP_HAS_CHECKS >= IMP_USAGE
  check_value_ = 666666666;
#endif
#if IMP_HAS_CHECKS >= IMP_INTERNAL
  --live_objects_;
#endif
}
Ejemplo n.º 21
0
Ints get_triangles(SurfaceMeshGeometry *sg) {
  Ints ret;
  Ints::const_iterator it = sg->get_faces().begin();
  while (it != sg->get_faces().end()) {
    Ints::const_iterator eit = std::find(
        it, static_cast<Ints::const_iterator>(sg->get_faces().end()), -1);
    IMP_INTERNAL_CHECK(eit != sg->get_faces().end(), "No trailing -1");
    Ints cur(it, eit);
    Ints tris = get_triangulation_of_face(cur, sg->get_vertexes());
    ret.insert(ret.end(), tris.begin(), tris.end());
    it = eit;
    ++it;
  }
  return ret;
}
Ejemplo n.º 22
0
bool get_is_heterogen(Hierarchy h) {
  if (Atom::particle_is_instance(h)) {
    Atom a(h);
    bool ret= (a.get_atom_type() >= AT_UNKNOWN);
    IMP_INTERNAL_CHECK((ret && a.get_atom_type().get_string().find("HET:")==0)
                       || (!ret && a.get_atom_type().get_string().find("HET:")
                           == std::string::npos),
                       "Unexpected atom type found " << a.get_atom_type()
                       << (ret?" is ": " is not ") << "a heterogen.");
    return ret;
  } else {
    Residue r(h);
    return (r.get_residue_type()>= DTHY);
  }
}
Ejemplo n.º 23
0
IMPMULTIFIT_BEGIN_NAMESPACE
void add_surface_index(core::Hierarchy mh, Float apix, FloatKey shell_key,
                       FloatKey, FloatKey) {
  ParticlesTemp ps = core::get_leaves(mh);
  Pointer<em::SurfaceShellDensityMap> shell_map =
      new em::SurfaceShellDensityMap(ps, apix);

  for (unsigned int i = 0; i < ps.size(); i++) {
    IMP_INTERNAL_CHECK(!ps[i]->has_attribute(shell_key),
                       "Particle " << ps[i]->get_name()
                                   << " already has shell attribute"
                                   << std::endl);
    ps[i]->add_attribute(
        shell_key, shell_map->get_value(core::XYZ(ps[i]).get_coordinates()));
  }
}
Ejemplo n.º 24
0
Hierarchy create_protein(Model *m, std::string name, double resolution,
                         int number_of_residues, int first_residue_index,
                         double volume, bool ismol) {
  double mass =
      atom::get_mass_from_number_of_residues(number_of_residues) / 1000;
  if (volume < 0) {
    volume = atom::get_volume_from_mass(mass * 1000);
  }
  // assume a 20% overlap in the beads to make the protein not too bumpy
  double overlap_frac = .2;
  std::pair<int, double> nr = compute_n(volume, resolution, overlap_frac);
  Hierarchy pd = Hierarchy::setup_particle(new Particle(m));
  Ints residues;
  for (int i = 0; i < number_of_residues; ++i) {
    residues.push_back(i + first_residue_index);
  }
  atom::Fragment::setup_particle(pd, residues);
  if (ismol) Molecule::setup_particle(pd);
  pd->set_name(name);
  for (int i = 0; i < nr.first; ++i) {
    Particle *pc;
    if (nr.first > 1) {
      pc = new Particle(m);
      std::ostringstream oss;
      oss << name << "-" << i;
      pc->set_name(oss.str());
      atom::Fragment pcd = atom::Fragment::setup_particle(pc);
      Ints indexes;
      for (int j = i * (number_of_residues / nr.first) + first_residue_index;
           j < (i + 1) * (number_of_residues / nr.first) + first_residue_index;
           ++j) {
        indexes.push_back(j);
      }
      pcd.set_residue_indexes(indexes);
      pd.add_child(pcd);
    } else {
      pc = pd;
    }

    core::XYZR xyzd = core::XYZR::setup_particle(pc);
    xyzd.set_radius(nr.second);
    atom::Mass::setup_particle(pc, mass / nr.first);
  }
  IMP_INTERNAL_CHECK(pd.get_is_valid(true), "Invalid hierarchy produced "
                                                << pd);
  return pd;
}
Ejemplo n.º 25
0
bool PymolWriter::handle_surface(SurfaceMeshGeometry *g, Color color,
                                 std::string name) {
  setup(name, TRIANGLES);
  if (!open_type_) {
    get_stream() << "BEGIN, TRIANGLES, ";
    open_type_ = TRIANGLES;
  }
  Ints triangles = internal::get_triangles(g);
  algebra::Vector3Ds normals =
      internal::get_normals(triangles, g->get_vertexes());
  IMP_INTERNAL_CHECK(triangles.size() % 3 == 0,
                     "The returned triangles aren't triangles");
  for (unsigned int i = 0; i < triangles.size() / 3; ++i) {
    write_triangle(triangles.begin() + 3 * i, triangles.begin() + 3 * i + 3,
                   g->get_vertexes(), normals, color, get_stream());
  }
  return true;
}
Ejemplo n.º 26
0
Transformation2D get_transformation_aligning_pair(
          const Vector2Ds &set_from,
          const Vector2Ds &set_to) {
  IMP_INTERNAL_CHECK(set_from.size()==2 && set_to.size()==2,
      "rigid_align_first_to_second_2d:: The number of points "
      "in both sets must be 2");
  // v1 and v2 should be similar
  Vector2D v1 = set_from[1]-set_from[0];
  Vector2D v2 = set_to[1]-set_to[0];
  // Build the rotation to obtain vector v1
  Rotation2D R1 = get_rotation_to_x_axis(v1);
  // Build the rotation to obtain vector v2
  Rotation2D R2 = get_rotation_to_x_axis(v2);
  // Obtain the transformation from v1 to v2
  Rotation2D R = compose(R2,R1.get_inverse());
  Vector2D t = set_to[0] - R.get_rotated(set_from[0]);
  Transformation2D T(R,t);
  return T;
}
Ejemplo n.º 27
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.");
  }
  kernel::Particle *rbp = new kernel::Particle(h[0]->get_model());
  rbp->set_name(name);
  kernel::ParticlesTemp all;
  for (unsigned int i = 0; i < h.size(); ++i) {
    kernel::ParticlesTemp cur = rb_process(h[i]);
    all.insert(all.end(), cur.begin(), cur.end());
  }
  core::RigidBody rbd = core::RigidBody::setup_particle(rbp, 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;
}
Ejemplo n.º 28
0
void add_to_log(std::string str) {
  IMP_INTERNAL_CHECK(static_cast<int>(internal::initialized)==11111111,
                     "You connot use the log before main is called.");
  if (!contexts.empty()
      && context_initializeds != static_cast<int>(contexts.size())) {
    for (unsigned int i=0; i< contexts.size(); ++i) {
      if (context_initializeds < static_cast<int>(i)) {
        std::string message= std::string("begin ")
          +get_context_name(i)+":\n";
        internal::stream.write(message.c_str(), message.size());
        internal::stream.strict_sync();
        internal::log_indent+=2;
        context_initializeds=i;
      }
    }
  }
  internal::stream.write(str.c_str(), str.size());
  internal::stream.strict_sync();
}
void BerendsenThermostatOptimizerState::rescale_velocities() const
{
  MolecularDynamics *md = dynamic_cast<MolecularDynamics *>(get_optimizer());
  IMP_INTERNAL_CHECK(md, "Can only use velocity scaling with "
             "the molecular dynamics optimizer.");

  double kinetic_temp = md->get_kinetic_temperature(md->get_kinetic_energy());
  double rescale = std::sqrt(1.0 + (md->get_last_time_step() / tau_)
                             * (temperature_ / kinetic_temp - 1.0));

  for (unsigned int i=0; i< pis_.size(); ++i) {
    Particle *p = pis_[i];
    for (int i = 0; i < 3; ++i) {
      double velocity = p->get_value(vs_[i]);
      velocity *= rescale;
      p->set_value(vs_[i], velocity);
   }
 }
}
Ejemplo n.º 30
0
Hierarchy read_mol2(base::TextInput mol2_file,
                    Model *model,  Mol2Selector* mol2sel)
{
  if (!mol2sel) {
    mol2sel=new AllMol2Selector();
  }
  IMP::OwnerPointer<Mol2Selector> sel(mol2sel);
  // create a map to save atom_index and atom particle pairs
  compatibility::map<Int, Particle*>molecule_atoms;

  // create root particle
  Hierarchy root_d = root_particle(model, mol2_file.get_name());
  std::string line;
  Hierarchy molecule_d;
  while (std::getline(mol2_file.get_stream(), line)) {
    // check the line is the title line @<TRIPOS>MOLECULE
    if (internal::is_MOLECULE_rec(line)) {
      molecule_atoms.clear();
      molecule_d = read_molecule_mol2(model, mol2_file, root_d);
    }
    // check the starting line of atom block @<TRIPOS>ATOM
    else if (internal::is_MOL2ATOM_rec(line)) {
      if (!molecule_d) {
        IMP_THROW("Atom seen before molecule on line " << line,
                  IOException);
      }
      read_atom_mol2(model, mol2_file, molecule_d, molecule_atoms, mol2sel);
    }
    // check the starting line of bond block @<TRIPOS>BOND
    else if (internal::is_BOND_rec(line)) {
      read_bond_mol2(model, mol2_file, molecule_d, molecule_atoms);
    }
    else {
      IMP_LOG(TERSE, "Couldn't parse line " << line << std::endl);
    }
  }
  //Hierarchies mps = get_by_type(root_d, RESIDUE_TYPE);
  //  std::cout << "check " << mps.size() << std::endl;
  add_radii(root_d);
  IMP_INTERNAL_CHECK(root_d.get_is_valid(true), "Invalid hierarchy produced");
  return root_d;
}