Example #1
0
SimpleExcludedVolume create_simple_excluded_volume_on_rigid_bodies(
                                         const core::RigidBodies &rbs,
                                         Refiner *ref)
{
  IMP_USAGE_CHECK(rbs.size() > 0, "At least one particle should be given");

  /****** Set the restraint ******/

  kernel::ParticlesTemp all;
  for (unsigned int i=0; i< rbs.size(); ++i) {
    kernel::ParticlesTemp cur= ref->get_refined(rbs[i]);
    all.insert(all.end(), cur.begin(), cur.end());
  }

  IMP_NEW(container::ListSingletonContainer, lsc, (all));

  IMP_NEW(core::ExcludedVolumeRestraint, evr, (lsc));

  /****** Add restraint to the model ******/

  //Model *mdl = rbs[0].get_model();
  //mdl->add_restraint(evr);

  /****** Return a SimpleExcludedVolume object ******/

  return SimpleExcludedVolume(evr);
}
Example #2
0
IMPRESTRAINER_BEGIN_NAMESPACE

SimpleConnectivity create_simple_connectivity_on_rigid_bodies(
                                       const core::RigidBodies &rbs,
                                       Refiner *ref)
{
  IMP_USAGE_CHECK(rbs.size() > 0, "At least one particle should be given");

  /****** Define PairScore ******/
  // Use RigidBodyDistancePairScore to accelerate computation of the distance
  // between two rigid bodies. The distance is defined as the minimal distance
  // over all bipartite pairs with one particle taken from each rigid body.

  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
  IMP_NEW(core::SphereDistancePairScore, sdps, (h));
  IMP_NEW(core::RigidBodyDistancePairScore, rdps, (sdps, ref));

  /****** Set the restraint ******/

  IMP_NEW(core::ConnectivityRestraint, cr, (rdps));
  for ( size_t i=0; i<rbs.size(); ++i )
    //cr->set_particles((*rbs)[i].get_particle());
    cr->add_particle(rbs[i].get_particle());

  /****** Add restraint to the model ******/

  //Model *mdl = rbs[0].get_model();
  //mdl->add_restraint(cr);

  /****** Return a SimpleConnectivity object ******/

  return SimpleConnectivity(cr, h, sdps);
}
Example #3
0
SimpleExcludedVolume create_simple_excluded_volume_on_molecules(
                     atom::Hierarchies const &mhs)
{
  IMP_CHECK_CODE(size_t mhs_size = mhs.size());

  IMP_USAGE_CHECK(mhs_size > 0, "At least one hierarchy should be given");

  kernel::ParticlesTemp ps;

  for ( size_t i=0; i<mhs.size(); ++i )
  {
    kernel::ParticlesTemp leaves= IMP::atom::get_leaves(mhs[i]);
    ps.insert(ps.end(), leaves.begin(), leaves.end());
  }

  /****** Set the restraint ******/

  IMP_NEW(container::ListSingletonContainer, lsc, (ps));

  IMP_NEW(core::ExcludedVolumeRestraint, evr, (lsc));

  /****** Add restraint to the model ******/

  //Model *mdl = mhs[0].get_particle()->get_model();
  //mdl->add_restraint(evr);

  /****** Return a SimpleExcludedVolume object ******/

  return SimpleExcludedVolume(evr);
}
int main(int argc, char *argv[]) {
  IMP::setup_from_argv(argc, argv, "Test ConsecutivePairContainer.");

  IMP_NEW(IMP::Model, m, ());
  IMP::ParticleIndexes ps;
  IMP::algebra::BoundingBox3D bb(IMP::algebra::Vector3D(0, 0, 0),
                                 IMP::algebra::Vector3D(10, 10, 10));
  for (unsigned int i = 0; i < 15; ++i) {
    ps.push_back(m->add_particle("P"));
    IMP::core::XYZ::setup_particle(m, ps.back(),
                                   IMP::algebra::get_random_vector_in(bb));
  }
  IMP_NEW(IMP::container::ConsecutivePairContainer, cpc, (m, ps));
  IMP_NEW(IMP::core::HarmonicDistancePairScore, hdps, (0, 1));
  IMP::Pointer<IMP::Restraint> r =
      IMP::container::create_restraint(hdps.get(), cpc.get());
  IMP_USAGE_CHECK(r->evaluate(false) > 0, "zero evaluate");
  IMP::Pointer<IMP::Restraint> rd = r->create_decomposition();
  IMP::RestraintsTemp rds = IMP::get_restraints(IMP::RestraintsTemp(1, rd));
  IMP_USAGE_CHECK(rds.size() == ps.size() - 1,
                  "Bad lengths: " << rds.size() << " vs " << ps.size() - 1);
  double re = r->evaluate(false);
  double rde = rd->evaluate(false);
  IMP_CHECK_VARIABLE(re);
  IMP_CHECK_VARIABLE(rde);
  IMP_USAGE_CHECK(std::abs(rde - re) < .1,
                  "Invalid decomposed score: " << re << " vs " << rde);
  return 0;
}
Example #5
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);
  }
}
Example #6
0
IMPMULTIFIT_BEGIN_NAMESPACE

void get_anchors_for_density(em::DensityMap *dmap, int number_of_means,
                             float density_threshold, std::string pdb_filename,
                             std::string cmm_filename, std::string seg_filename,
                             std::string txt_filename) {
  dmap->set_was_used(true);
  IMP_NEW(multifit::DensityDataPoints, ddp, (dmap, density_threshold));
  IMP::statistics::internal::VQClustering vq(ddp, number_of_means);
  ddp->set_was_used(true);
  vq.run();
  multifit::DataPointsAssignment assignment(ddp, &vq);
  multifit::AnchorsData ad(assignment.get_centers(), *(assignment.get_edges()));
  multifit::write_pdb(pdb_filename, assignment);
  // also write cmm string into a file:
  if (cmm_filename != "") {
    multifit::write_cmm(cmm_filename, "anchor_graph", ad);
  }
  if (seg_filename != "") {
    float apix = dmap->get_spacing();
    multifit::write_segments_as_mrc(dmap, assignment, apix, apix,
                                    density_threshold, seg_filename);
  }
  if (txt_filename != "") {
    multifit::write_txt(txt_filename, ad);
  }
}
Example #7
0
display::Geometries get_interaction_graph_geometry(const InteractionGraph &ig) {
  display::Geometries ret;
  InteractionGraphConstVertexName vm = boost::get(boost::vertex_name, ig);
  InteractionGraphConstEdgeName em = boost::get(boost::edge_name, ig);
  boost::unordered_map<std::string, display::Color> colors;
  for (std::pair<InteractionGraphTraits::vertex_iterator,
                 InteractionGraphTraits::vertex_iterator> be =
           boost::vertices(ig);
       be.first != be.second; ++be.first) {
    Particle *p = dynamic_cast<Particle *>(vm[*be.first]);
    core::XYZ pd(p);
    for (std::pair<InteractionGraphTraits::out_edge_iterator,
                   InteractionGraphTraits::out_edge_iterator> ebe =
             boost::out_edges(*be.first, ig);
         ebe.first != ebe.second; ++ebe.first) {
      unsigned int target = boost::target(*ebe.first, ig);
      if (target > *be.first) continue;
      Particle *op = dynamic_cast<Particle *>(vm[target]);
      core::XYZ od(op);
      std::string on = em[*ebe.first]->get_name();
      IMP_NEW(display::SegmentGeometry, cg,
              (algebra::Segment3D(pd.get_coordinates(), od.get_coordinates())));
      if (colors.find(em[*ebe.first]->get_name()) == colors.end()) {
        colors[em[*ebe.first]->get_name()] =
            display::get_display_color(colors.size());
      }
      cg->set_color(colors[em[*ebe.first]->get_name()]);
      cg->set_name(on);
      ret.push_back(cg.get());
    }
  }
  return ret;
}
Example #8
0
void read_files(Model *m, const std::vector<std::string>& files,
                std::vector<std::string>& pdb_file_names,
                std::vector<std::string>& dat_files,
                std::vector<IMP::Particles>& particles_vec,
                Profiles& exp_profiles, bool residue_level,
                bool heavy_atoms_only, int multi_model_pdb,
                bool explicit_water, float max_q, int units) {

  for (unsigned int i = 0; i < files.size(); i++) {
    // check if file exists
    std::ifstream in_file(files[i].c_str());
    if (!in_file) {
      IMP_WARN("Can't open file " << files[i] << std::endl);
      return;
    }
    // 1. try as pdb
    try {
      read_pdb(m, files[i], pdb_file_names, particles_vec, residue_level,
               heavy_atoms_only, multi_model_pdb, explicit_water);
    }
    catch (const IMP::ValueException &e) {  // not a pdb file
      // 2. try as a dat profile file
      IMP_NEW(Profile, profile, (files[i], false, max_q, units));
      if (profile->size() == 0) {
        IMP_WARN("can't parse input file " << files[i] << std::endl);
        return;
      } else {
        dat_files.push_back(files[i]);
        exp_profiles.push_back(profile);
        IMP_LOG_TERSE("Profile read from file " << files[i]
                      << " size = " << profile->size() << std::endl);
      }
    }
  }
}
Example #9
0
void RecursiveAssignmentsTable::load_assignments(
    const Subset &s, AssignmentContainer *pac) const {
  set_was_used(true);
  IMP_OBJECT_LOG;
  IMP_NEW(SimpleAssignmentsTable, sac, (pst_, sft_, max_));
  recursive_load_assignments(s, pst_, sft_, max_, sac, pac);
}
Example #10
0
display::Geometries create_blame_geometries(const RestraintsTemp &rs,
                                            const ParticlesTemp &ps,
                                            double max, std::string name) {
  IMP_FUNCTION_LOG;
  FloatKey key("blame temporary key");
  assign_blame(rs, ps, key);
  if (max == NO_MAX) {
    max = -NO_MAX;
    for (unsigned int i = 0; i < ps.size(); ++i) {
      max = std::max(ps[i]->get_value(key), max);
    }
    IMP_LOG_TERSE("Maximum blame value is " << max << std::endl);
  }
  display::Geometries ret;
  for (unsigned int i = 0; i < ps.size(); ++i) {
    double colorv;
    if (max == 0) {
      colorv = 0;
    } else {
      colorv =
          display::get_linear_color_map_value(0, max, ps[i]->get_value(key));
    }
    display::Color c = display::get_hot_color(colorv);
    IMP_NEW(XYZRGeometry, g, (ps[i]));
    if (!name.empty()) {
      g->set_name(name);
    }
    g->set_color(c);
    ret.push_back(g);
  }
  return ret;
}
void Fine2DRegistrationRestraint::setup(
    ParticlesTemp &ps, const ProjectingParameters &params,
    Model *scoring_model,
    //                       ScoreFunctionPtr score_function,
    ScoreFunction *score_function, MasksManagerPtr masks) {

  IMP_LOG_TERSE("Initializing Fine2DRegistrationRestraint" << std::endl);
  ps_ = ps;
  params_ = params;
  // Generate all the projection masks for the structure
  if (masks == MasksManagerPtr()) {
    // Create the masks
    masks_ =
        MasksManagerPtr(new MasksManager(params.resolution, params.pixel_size));
    masks_->create_masks(ps);
    IMP_LOG_VERBOSE("Created " << masks_->get_number_of_masks()
                               << " masks withing Fine2DRegistrationRestraint "
                               << std::endl);
  } else {
    masks_ = masks;
    IMP_LOG_VERBOSE("masks given to Fine2DRegistrationRestraint " << std::endl);
  }
  // Create a particle for the projection parameters to be optimized
  subj_params_particle_ = new Particle(scoring_model);
  PP_ = ProjectionParameters::setup_particle(subj_params_particle_);
  PP_.set_parameters_optimized(true);
  // Add an score state to the model

  IMP_NEW(ProjectionParametersScoreState, pp_score_state,
          (subj_params_particle_));
  scoring_model->add_score_state(pp_score_state);

  score_function_ = score_function;
}
Example #12
0
int main(int argc, char *argv[]) {
  // TODO: emulate real runtime parameters by initializig fake argc / argv?
  try {
    IMP::base::setup_from_argv(argc, argv,
                               "Test of the main loop for npc transport");
    std::string config
        = IMP::npctransport::get_data_path("quick.pb");
    std::string assignment
        = IMP::base::create_temporary_file_name("output", ".pb");
    std::string output
        = IMP::base::create_temporary_file_name("output", ".rmf");
    IMP::base::set_log_level(IMP::base::LogLevel(IMP::base::SILENT));
    int num=IMP::npctransport::assign_ranges
      (config, assignment, 0, true, IMP::base::get_random_seed());
    std::cout << "num ranges " << num << std::endl;
    IMP_NEW(IMP::npctransport::SimulationData, sd,(assignment, true /* quick */));
    sd->set_rmf_file_name(output);
    sd->get_m()->set_log_level(IMP::base::SILENT);
    std::cout << "Files are " << assignment
              << " and " << output
              << std::endl;
  IMP::npctransport::do_main_loop(sd, IMP::RestraintsTemp());
  } catch (IMP::base::Exception e) {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 1;
  }
  return 0;
}
Example #13
0
void get_segmentation(em::DensityMap *dmap, double apix,
                      double density_threshold, int num_means,
                      const std::string pdb_filename,
                      const std::string cmm_filename,
                      const std::string seg_filename,
                      const std::string txt_filename) {
  IMP_LOG_VERBOSE("start setting trn_em" << std::endl);
  IMP_NEW(DensityDataPoints, ddp, (dmap, density_threshold));
  IMP_LOG_VERBOSE("initialize calculation of initial centers" << std::endl);
  statistics::internal::VQClustering vq(ddp, num_means);
  vq.run();
  DataPointsAssignment assignment(ddp, &vq);
  AnchorsData ad(assignment.get_centers(), *(assignment.get_edges()));
  multifit::write_pdb(pdb_filename, assignment);
  // also write cmm string into a file:
  if (cmm_filename != "") {
    write_cmm(cmm_filename, "anchor_graph", ad);
  }
  if (seg_filename != "") {
    write_segments_as_mrc(dmap, assignment, apix, apix, density_threshold,
                          seg_filename);
  }
  if (txt_filename != "") {
    write_txt(txt_filename, ad);
  }
}
SecondaryStructureResidue setup_coarse_secondary_structure_residue(
    const Particles &ssr_ps, Model *mdl,
    bool winner_takes_all_per_res) {
  Floats scores;
  scores.push_back(0.0);
  scores.push_back(0.0);
  scores.push_back(0.0);
  int count = 0;
  for (Particles::const_iterator p = ssr_ps.begin(); p != ssr_ps.end();
       ++p) {
    IMP_USAGE_CHECK(SecondaryStructureResidue::get_is_setup(*p),
                    "all particles must be SecondaryStructureResidues");
    SecondaryStructureResidue ssr(*p);
    Floats tmp_scores;
    tmp_scores.push_back(ssr.get_prob_helix());
    tmp_scores.push_back(ssr.get_prob_strand());
    tmp_scores.push_back(ssr.get_prob_coil());
    int max_i = 0;
    Float max = 0.0;
    for (int i = 0; i < 3; i++) {
      if (tmp_scores[i] > max) {
        max = tmp_scores[i];
        max_i = i;
      }
      if (!winner_takes_all_per_res) scores[i] += tmp_scores[i];
    }
    if (winner_takes_all_per_res) scores[max_i] += 1.0;
    count++;
  }
  IMP_NEW(Particle, coarse_p, (mdl));
  SecondaryStructureResidue ssres = SecondaryStructureResidue::setup_particle(
      coarse_p, scores[0] / count, scores[1] / count, scores[2] / count);
  return ssres;
}
Example #15
0
atom::Hierarchy create_coarse_molecule_from_molecule(
               const atom::Hierarchy &mh,int num_beads,
               Model *mdl,
               float bead_radius,
               bool add_conn_restraint) {
  IMP_NEW(IMP::statistics::internal::ParticlesDataPoints, ddp,
          (core::get_leaves(mh)));
  IMP::statistics::internal::VQClustering vq(ddp,num_beads);
  vq.run();
  multifit::DataPointsAssignment assignment(ddp,&vq);
  atom::Selections sel;
  algebra::Vector3Ds vecs;
  for (int i=0;i<num_beads;i++){
    IMP::statistics::internal::Array1DD xyz =
      assignment.get_cluster_engine()->get_center(i);
    vecs.push_back(algebra::Vector3D(xyz[0],xyz[1],xyz[2]));
  }
  //todo - mass should be a parameter
  atom::Hierarchy ret_prot=create_molecule(vecs,bead_radius,3,mdl);
  ParticlesTemp leaves=core::get_leaves(ret_prot);
  for (ParticlesTemp::iterator it = leaves.begin();it != leaves.end();it++){
    sel.push_back(atom::Selection(atom::Hierarchy(*it)));
  }
  if (add_conn_restraint){
  int k=1;//todo - make this a parameter
  Restraint *r = atom::create_connectivity_restraint(sel,k);
  if (r != nullptr){
    mdl->add_restraint(r);}
  }
  return ret_prot;
}
Example #16
0
CnSymmAxisDetector::CnSymmAxisDetector(int symm_deg,
                                       const atom::Hierarchies &mhs)
    : symm_deg_(symm_deg) {
  // create a density map
  kernel::Particles ps;
  for (atom::Hierarchies::const_iterator it = mhs.begin(); it != mhs.end();
       it++) {
    kernel::Particles temp_ps = core::get_leaves(*it);
    ps.insert(ps.end(), temp_ps.begin(), temp_ps.end());
  }
  // TODO - check the number of particles!!
  IMP_NEW(em::SampledDensityMap, sampled_dmap, (ps, 3., 1.));
  sampled_dmap->resample();
  sampled_dmap->calcRMS();
  dmap_ = new em::DensityMap(*(sampled_dmap->get_header()));
  dmap_->copy_map(sampled_dmap);
  double top_20_den_val = get_top_density_value(dmap_,
                                          dmap_->get_header()->dmin, 0.8);
  vecs_ = em::density2vectors(dmap_, top_20_den_val);
  // calculate  pca
  pca_ = algebra::get_principal_components(vecs_);
  // calculate transformation from the native axes system to the one
  // defined by the pca
  from_native_ = algebra::get_rotation_from_x_y_axes(
      pca_.get_principal_component(0), pca_.get_principal_component(1));
  to_native_ = from_native_.get_inverse();
  sampled_dmap = nullptr;
}
Example #17
0
void AnchorsData::setup_secondary_structure(Model *mdl) {
  for (int anum = 0; anum < (int)points_.size(); anum++) {
    IMP_NEW(Particle, ssr_p, (mdl));
    atom::SecondaryStructureResidue default_ssr =
        atom::SecondaryStructureResidue::setup_particle(ssr_p);
    secondary_structure_ps_.push_back(ssr_p);
  }
}
Example #18
0
IMP::algebra::DenseGrid3D<float>
get_complementarity_grid(const IMP::ParticlesTemp &ps,
  const ComplementarityGridParameters &params)
{
  IMP_NEW(SurfaceDistanceMap, sdm, (ps, params.voxel_size));
  sdm->resample();
  IMP::algebra::BoundingBox3D bb = IMP::em::get_bounding_box(sdm);
  IMP_LOG_VERBOSE( __FUNCTION__ << ": Sampled bounding box is "
      << bb.get_corner(0) << " to " << bb.get_corner(1) << '\n');
  IMP::algebra::DenseGrid3D<float> grid(params.voxel_size, bb);
  IMP_GRID3D_FOREACH_VOXEL(grid,
                           IMP_UNUSED(loop_voxel_index);
      long idx = sdm->get_voxel_by_location(
        voxel_center[0], voxel_center[1], voxel_center[2]);
      if ( idx > -1 )
      {
        float v = sdm->get_value(idx);
        if ( v > 0 )
        {
          //inside voxel
          if ( v - 1 > params.interior_cutoff_distance )
            grid[voxel_center] = std::numeric_limits<float>::max();
          else
            grid[voxel_center] = int((v - 1)/params.interior_thickness) + 1;

          /***Shouldn't happen
          if(grid[voxel_center] < 0)
            std::cout << "INSIDE voxel negative "
                            <<  grid[voxel_center] << std::endl;
          **/

        }
        else if ( v < 0 )
        {
          // outside voxel
          v = -v - 1;
          // assume complementarity_thickness is sorted!!!
          Floats::const_iterator p = std::lower_bound(
            params.complementarity_thickness.begin(),
            params.complementarity_thickness.end(), v);
          if ( p == params.complementarity_thickness.end() )
            v = 0;
          else
          {
            v = params.complementarity_value[
              p - params.complementarity_thickness.begin()];
          }
          grid[voxel_center] = v;
          /*** Shouldn't happen
          if(grid[voxel_center] >= std::numeric_limits<float>::max())
            std::cout << "OUTSIDE voxel infinite "
                                      <<  grid[voxel_center] << std::endl;
          if(grid[voxel_center] > 0)
            std::cout << "OUTSIDE voxel positive "
                                      <<  grid[voxel_center] << std::endl;
          **/
        }
      });
Example #19
0
CHARMMTopology *CHARMMParameters::create_topology(Hierarchy hierarchy) const {
  IMP_OBJECT_LOG;
  IMP_NEW(CHARMMTopology, topology, (this));

  Hierarchies chains = get_by_type(hierarchy, CHAIN_TYPE);

  for (Hierarchies::iterator chainit = chains.begin(); chainit != chains.end();
       ++chainit) {
    IMP_NEW(CHARMMSegmentTopology, segment, ());
    Hierarchies residues = get_by_type(*chainit, RESIDUE_TYPE);
    for (Hierarchies::iterator resit = residues.begin();
         resit != residues.end(); ++resit) {
      ResidueType restyp = Residue(*resit).get_residue_type();
      try {
        IMP_NEW(CHARMMResidueTopology, residue, (get_residue_topology(restyp)));
        segment->add_residue(residue);
      }
      catch (base::ValueException) {
        // If residue type is unknown, add empty topology for this residue
        IMP_WARN_ONCE(
            restyp.get_string(),
            "Residue type "
                << restyp
                << " was not found in "
                   "topology library; using empty topology for this residue",
            warn_context_);
        IMP_NEW(CHARMMResidueTopology, residue, (restyp));
        segment->add_residue(residue);
      }
    }
    topology->add_segment(segment);
  }
  // keep clang happy
  bool dumped = false;
  IMP_IF_LOG(VERBOSE) {
    dumped = true;
    warn_context_.dump_warnings();
  }
  if (!dumped) {
    warn_context_.clear_warnings();
  }
  // Topology objects are not designed to be added into other containers
  topology->set_was_used(true);
  return topology.release();
}
Example #20
0
SimpleDistance create_simple_distance(const kernel::Particles &ps)
{
  IMP_USAGE_CHECK(ps.size() == 2, "Two particles should be given");

  /****** Set the restraint ******/

  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
  IMP_NEW(core::DistanceRestraint, dr, (h, ps[0], ps[1]));

  /****** Add restraint to the model ******/

  //Model *mdl = (*ps)[0]->get_model();
  //mdl->add_restraint(dr);

  /****** Return a SimpleDistance object ******/

  return SimpleDistance(dr, h);
}
SingletonContainerAdaptor
::SingletonContainerAdaptor(const ParticlesTemp &t,
                                                 std::string name) {
  Model *m=internal::get_model(t);
  IMP_NEW(internal::InternalListSingletonContainer, c,
          (m, name));
  c->set_particles(t);
  P::operator=(c);
}
Example #22
0
unsigned int get_enclosing_image_size(const ParticlesTemp &ps,
                                      double pixel_size, unsigned int slack) {
  IMP_NEW(Particle, p, (ps[0]->get_model(), "cover Particle"));
  // core::XYZsTemp xyzs(ps);
  core::XYZs xyzs(ps);
  double diameter = 2 * core::get_enclosing_sphere(xyzs).get_radius();
  unsigned int size =
      static_cast<unsigned int>(diameter / pixel_size) + 2 * slack;
  return size;
}
Example #23
0
SimpleDiameter create_simple_diameter(const kernel::Particles &ps, Float diameter)
{
  IMP_USAGE_CHECK(ps.size() >= 2, "At least two particles should be given");

  /****** Set the restraint ******/

  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
  IMP_NEW(container::ListSingletonContainer, lsc, (get_as<kernel::ParticlesTemp>(ps)));
  IMP_NEW(core::DiameterRestraint, dr, (h, lsc, diameter));

  /****** Add restraint to the model ******/

  //Model *mdl = (*ps)[0]->get_model();
  //mdl->add_restraint(dr);

  /****** Return a SimpleDiameter object ******/

  return SimpleDiameter(dr, h);
}
SecondaryStructureResidues read_psipred(TextInput inf, Model* mdl) {
  Strings ss = parse_psipred_file(inf);
  int nres = ss[0].size();
  Particles ps;
  for (int nr = 0; nr < nres; nr++) {
    IMP_NEW(Particle, p, (mdl));
    ps.push_back(p);
  }
  return create_sses_from_strings(ss, ps);
}
Example #25
0
void Optimizer::set_restraints(const RestraintsTemp &rs) {
  if (rs.empty()) {
    // otherwise the SF can't figure out the model
    IMP_NEW(RestraintSet, rss, (get_model(), 1.0, "dummy restraint set"));
    RestraintsTemp rt(1, rss);
    set_scoring_function(new internal::RestraintsScoringFunction(rt));
  } else {
    set_scoring_function(new internal::RestraintsScoringFunction(rs));
  }
}
Example #26
0
int main(int argc, char *argv[]) {
  IMP::setup_from_argv(argc, argv, "Testing protection of particles");
// no checks in fast mode
#if IMP_HAS_CHECKS >= IMP_INTERNAL
  IMP_NEW(IMP::Model, m, ());
  IMP_NEW(IMP::Particle, p, (m));
  IMP::SetNumberOfThreads no(1);
  IMP_NEW(TouchyRestraint, r, (p, IMP::FloatKey(0)));
  try {
    r->evaluate(false);
    // there had better be an exception
    return 1;
    // the exception gets translated into a normal IMP exception
  }
  catch (const std::runtime_error &e) {
    std::cerr << e.what() << std::endl;
  }
#endif
  return 0;
}
Example #27
0
ClassnameContainerAdaptor::ClassnameContainerAdaptor(
    const PLURALVARIABLETYPE &t) {
  IMP_USAGE_CHECK(t.size() > 0,
                  "An Empty PLURALVARIABLETYPE list cannot be adapted to "
                  "container since it lacks model info");
  Model *m = internal::get_model(t);
  IMP_NEW(internal::StaticListContainer<ClassnameContainer>, c,
          (m, "ClassnameContainerInput%1%"));
  c->set(IMP::internal::get_index(t));
  P::operator=(c);
}
Example #28
0
IMPEXAMPLE_BEGIN_NAMESPACE

core::MonteCarloMover *create_serial_mover(const kernel::ParticlesTemp &ps) {
    core::MonteCarloMovers movers;
    for (unsigned int i = 0; i < ps.size(); ++i) {
        double scale = core::XYZR(ps[i]).get_radius();
        movers.push_back(new core::BallMover(ps[i]->get_model(),
                                             ps[i]->get_index(), scale * 2));
    }
    IMP_NEW(core::SerialMover, sm, (get_as<core::MonteCarloMoversTemp>(movers)));
    return sm.release();
}
Restraints MSConnectivityRestraint::do_create_current_decomposition() const {
  ParticlePairsTemp pp = get_connected_pairs();
  Restraints ret(pp.size());
  for (unsigned int i = 0; i < pp.size(); ++i) {
    IMP_NEW(PairRestraint, pr, (ps_, pp[i]));
    std::ostringstream oss;
    oss << get_name() << " " << i;
    pr->set_name(oss.str());
    ret[i] = pr;
  }
  return ret;
}
Example #30
0
void EzRestraint::setup() {
  Model *m = get_model();
  for (unsigned i = 0; i < ps_.size(); ++i) {
    // get residue type
    std::string restype = atom::Residue(atom::Atom(m, ps_[i]).get_parent())
                              .get_residue_type()
                              .get_string();
    // get parameters from residue type
    Floats param = get_parameters(restype);
    // create Sigmoid of Gaussian
    if (restype != "TYR" && restype != "TRP") {
      IMP_NEW(atom::internal::Sigmoid, ptr, (param[0], param[1], param[2]));
      ptr->set_was_used(true);
      ufs_.push_back(ptr);
    } else {
      IMP_NEW(atom::internal::Gaussian, ptr, (param[0], param[1], param[2]));
      ptr->set_was_used(true);
      ufs_.push_back(ptr);
    }
  }
}