예제 #1
0
파일: utility.cpp 프로젝트: salilab/imp
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);
      }
    }
  }
}
예제 #2
0
IMPATOM_BEGIN_INTERNAL_NAMESPACE

void add_dihedral_to_list(const CHARMMParameters *param, kernel::Particle *p1,
                          kernel::Particle *p2, kernel::Particle *p3,
                          kernel::Particle *p4, kernel::Particles &ps) {
  try {
    base::Vector<CHARMMDihedralParameters> p = param->get_dihedral_parameters(
        CHARMMAtom(p1).get_charmm_type(), CHARMMAtom(p2).get_charmm_type(),
        CHARMMAtom(p3).get_charmm_type(), CHARMMAtom(p4).get_charmm_type());
    for (base::Vector<CHARMMDihedralParameters>::const_iterator it = p.begin();
         it != p.end(); ++it) {
      Dihedral dd = Dihedral::setup_particle(
          new kernel::Particle(p1->get_model()), core::XYZ(p1), core::XYZ(p2),
          core::XYZ(p3), core::XYZ(p4));
      dd.set_ideal(it->ideal / 180.0 * PI);
      dd.set_multiplicity(it->multiplicity);
      if (it->force_constant < 0.0) {
        dd.set_stiffness(-std::sqrt(-it->force_constant * 2.0));
      } else {
        dd.set_stiffness(std::sqrt(it->force_constant * 2.0));
      }
      ps.push_back(dd);
    }
  }
  catch (const base::IndexException &e) {
    // If no parameters, warn, and create an empty dihedral
    IMP_WARN(e.what() << std::endl);
    Dihedral dd = Dihedral::setup_particle(
        new kernel::Particle(p1->get_model()), core::XYZ(p1), core::XYZ(p2),
        core::XYZ(p3), core::XYZ(p4));
    ps.push_back(dd);
  }
}
예제 #3
0
파일: links.cpp 프로젝트: salilab/imp
LoadLink::~LoadLink() {
  if (!frame_loaded_) {
    IMP_WARN("No frames were loaded from file \""
             << get_name() << "\" even though objects were linked or created."
             << std::endl);
  }
}
예제 #4
0
파일: links.cpp 프로젝트: salilab/imp
SaveLink::~SaveLink() {
  if (!frame_saved_) {
    IMP_WARN("No frames were saved to file \""
             << get_name() << "\" even though objects were added."
             << std::endl);
  }
}
double WeightedExcludedVolumeRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const
{
    bool calc_deriv = accum? true: false;
    IMP_LOG_VERBOSE("before resample\n");
    // //generate the transformed maps
    // std::vector<DensityMap*> transformed_maps;
    // for(int rb_i=0;rb_i<rbs_.size();rb_i++){
    //   DensityMap *dm=create_density_map(
    //       atom::get_bounding_box(atom::Hierarchy(rbs_[rb_i])),spacing);
    //   get_transformed_into(
    //       rbs_surface_maps_[rb_i],
    //       rbs_[rb_i].get_transformation()*rbs_orig_trans_[rb_i],
    //       dm,
    //       false);
    //   transformed_maps.push_back(dm);
    // }
    double score=0.;
    // MRCReaderWriter mrw;
    // for(int i=0;i<transformed_maps.size();i++){
    //   std::stringstream ss;
    //   ss<<"transformed_map_"<<i<<".mrc";
    //   std::stringstream s1;
    //   s1<<"transformed_pdb_"<<i<<".pdb";
    //   atom::write_pdb(atom::Hierarchy(rbs_[i]),s1.str().c_str());
    //   write_map(transformed_maps[i],ss.str().c_str(),mrw);
    //   for(int j=i+1;j<transformed_maps.size();j++){
    //     if (get_interiors_intersect(transformed_maps[i],
    //                                 transformed_maps[j])){
    //     score += CoarseCC::cross_correlation_coefficient(
    //                              *transformed_maps[i],
    //                              *transformed_maps[j],1.,false,true);
    //     }
    //   }
    // }
    em::SurfaceShellDensityMaps resampled_surfaces;
    for(unsigned int i=0; i<rbs_.size(); i++) {
        kernel::ParticlesTemp rb_ps=rb_refiner_->get_refined(rbs_[i]);
        resampled_surfaces.push_back(new em::SurfaceShellDensityMap(rb_ps,1.));
    }
    for(unsigned int i=0; i<rbs_.size(); i++) {
        for(unsigned int j=i+1; j<rbs_.size(); j++) {
            if (get_interiors_intersect(resampled_surfaces[i],
                                        resampled_surfaces[j])) {
                score += em::CoarseCC::cross_correlation_coefficient(
                             resampled_surfaces[i],
                             resampled_surfaces[j],1.,true,FloatPair(0.,0.));
            }
        }
    }

    if (calc_deriv) {
        IMP_WARN("WeightedExcludedVolumeRestraint currently"
                 <<" does not support derivatives\n");
    }
    /*for(int i=resampled_surfaces.size()-1;i<0;i--){
      delete(resampled_surfaces[i]);
      }*/
    return score;
}
예제 #6
0
SettingsData *read_settings(const char *filename) {
  std::fstream in;
  in.open(filename, std::fstream::in);
  if (!in.good()) {
    IMP_THROW("Problem opening file " << filename << " for reading "
                                      << std::endl,
              ValueException);
  }
  std::string line;
  IMP_NEW(SettingsData, header, ());
  getline(in, line);  // skip header line
  int status = 0;
  while (!in.eof()) {
    getline(in, line);  // skip header line
    std::vector<std::string> line_split;
    boost::split(line_split, line, boost::is_any_of("|"));
    if ((line_split.size() == 10) && (status == 0)) {  // protein  line
      IMP_LOG_VERBOSE("parsing component line:" << line << std::endl);
      header->add_component_header(parse_component_line(filename, line));
    } else if (status == 0) {  // map header line
      status = 1;
    } else if (status == 1) {  // map line
      IMP_LOG_VERBOSE("parsing EM line:" << line << std::endl);
      header->set_assembly_header(parse_assembly_line(filename, line));
      status = 2;
    } else if (line.length() > 0) {  // don't warn about empty lines
      IMP_WARN("the line was not parsed:" << line << "| with status:" << status
                                          << std::endl);
    }
  }
  in.close();
  header->set_assembly_filename(filename);
  header->set_data_path(".");
  return header.release();
}
void
load_union(const Subset &s0, const Subset &s1,
           AssignmentContainer *nd0, AssignmentContainer *nd1,
           const EdgeData &ed, double max_error,
           ParticleStatesTable* pst,
           const statistics::Metrics &metrics,
           unsigned int max,
           AssignmentContainer *out) {
  Ints ii0= get_index(s0, ed.intersection_subset);
  Ints ii1= get_index(s1, ed.intersection_subset);
  Ints ui0= get_index(ed.union_subset, s0);
  Ints ui1= get_index(ed.union_subset, s1);
  Ints uii= get_index(ed.union_subset, ed.intersection_subset);
  Assignments nd1a
    = nd1->get_assignments(IntRange(0, nd1->get_number_of_assignments()));
  // chunck outer and writing later
  unsigned int nd0sz= nd0->get_number_of_assignments();
  for (unsigned int i=0; i< nd0sz; ++i) {
    Assignment nd0a=nd0->get_assignment(i);
    Assignment nd0ae=get_sub_assignment(nd0a, ii0);
    for (unsigned int j=0; j< nd1a.size(); ++j) {
      Assignment nd1ae=get_sub_assignment(nd1a[j], ii1);
      bool merged_ok=(nd1ae==nd0ae);
      Assignment ss;
      if (!merged_ok && pst) {;
        double n= get_distance_if_smaller_than(ed.intersection_subset,
                                               nd0ae, nd1ae, pst,
                                               metrics, max_error);
        if ( n < max_error) {
          merged_ok=true;
        }
      }
      if (merged_ok) {
        ss= get_merged_assignment(ed.union_subset,
                                  nd0a, ui0,
                                  nd1a[j], ui1);
      }
      if (merged_ok) {
        bool ok=true;
        for (unsigned int k=0; k< ed.filters.size(); ++k) {
          if (ed.filters[k]->get_is_ok(ss)) {
            // pass
          } else {
            ok=false;
            break;
          }
        }
        if (ok) {
          out->add_assignment(ss);
          if (out->get_number_of_assignments() > max) {
            IMP_WARN("Truncated number of states at " << max
                     << " when merging " << s0 << " and " << s1);
            return;
          }
        }
      }
    }
  }
}
예제 #8
0
IMPBASE_BEGIN_NAMESPACE
#if IMP_HAS_LOG
void WarningContext::add_warning(std::string key, std::string warning) const {
  if (warning.empty()) return;
#if IMP_HAS_LOG >= IMP_WARN
  if (data_.find(key) == data_.end()) {
    data_.insert(key);
    IMP_WARN(warning);
  }
#endif
}
예제 #9
0
double EnvelopePenetrationRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  Float ret_score;
  ret_score = get_number_of_particles_outside_of_the_density(
      target_dens_map_, ps_, IMP::algebra::get_identity_transformation_3d(),
      threshold_);
  if (accum != nullptr) {
    IMP_WARN(
        "No derivatives have been assigned to the envelope penetration "
        "score\n");
  }
  return ret_score;
}
double DensityFillingRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  double ret_score;
  double covered_percentage = get_percentage_of_voxels_covered_by_particles(
      target_dens_map_, ps_, core::XYZR(ps_[0]).get_radius(),
      IMP::algebra::get_identity_transformation_3d(), threshold_);
  ret_score = 1. - covered_percentage;
  if (accum != nullptr) {
    IMP_WARN(
        "No derivatives have been assigned to the envelope penetration "
        "score\n");
  }
  return ret_score;
}
예제 #11
0
const RadiusDependentKernelParameters& KernelParameters::get_params(
  float radius,  float eps) {
  IMP_USAGE_CHECK(initialized_, "The Kernel Parameters are not initialized");
  typedef
    std::map<float, const RadiusDependentKernelParameters*>
    kernel_map;
  //we do not use find but use lower_bound and upper_bound to overcome
  //numerical instabilities


  //in maps, an iterator that addresses the location of an element
  //that with a key that is equal to or greater than the argument key,
  //or that addresses the location succeeding the last element in the
  //map if no match is found for the key.
  kernel_map::iterator lower_closest = radii2params_.lower_bound(radius);
  kernel_map::iterator upper_closest = radii2params_.upper_bound(radius);
   const RadiusDependentKernelParameters *closest = nullptr;
   if (algebra::get_are_almost_equal(radius,upper_closest->first,eps)) {
     closest = upper_closest->second;
     IMP_LOG_VERBOSE("for radius:"<<radius<<
             " the closest is:"<< upper_closest->first<<std::endl);
   }
   else {
     if (lower_closest != radii2params_.end()) {
       if (algebra::get_are_almost_equal(radius,lower_closest->first,eps)) {
         closest = lower_closest->second;
       }
     }
   }
   if (closest == nullptr) {
     IMP_WARN("could not find parameters for radius:"<<radius<<std::endl);
     IMP_WARN("Setting params for radius :"<<radius<<std::endl);
     return set_params(radius);
   } else {
     return *closest;
   }
}
예제 #12
0
파일: Optimizer.cpp 프로젝트: AljGaber/imp
double Optimizer::optimize(unsigned int max_steps) {
  IMP_OBJECT_LOG;
  if (!scoring_function_) {
    IMP_WARN("No scoring function provided - using Model's implicit "
             "scoring function (deprecated). Recommend you use a "
             "ScoringFunction object instead." << std::endl);
  }

  set_has_required_score_states(true);
  set_was_used(true);
  set_is_optimizing_states(true);
  double ret;
  IMP_THREADS((ret, max_steps), {
    ret = do_optimize(max_steps);
  });
예제 #13
0
double
RadiusOfGyrationRestraint::unprotected_evaluate(DerivativeAccumulator *accum)
const {
  IMP_UNUSED(accum);
  //IMP_USAGE_CHECK(!accum, "No derivatives computed");
  if (accum) {
    IMP_WARN("Can not calcaulte derivatives\n");
  }
  //calculate actual rog
  //todo - do not use get_input_particles function
  float actual_rog=get_actual_radius_of_gyration(get_input_particles());
  IMP_LOG_VERBOSE("actual_rog:"<<actual_rog<<" predicted:"<<predicted_rog_<<
          " scale:"<<predicted_rog_*scale_<<" score: "<<
          hub_->evaluate(actual_rog)<<std::endl);
  return hub_->evaluate(actual_rog);
}
예제 #14
0
파일: Projection.cpp 프로젝트: AljGaber/imp
void Projection::init(const IMP::algebra::Vector3Ds& points,
                      double max_radius, int axis_size) {
  // determine the image size needed to store the projection
  x_min_ = y_min_ = std::numeric_limits<float>::max();
  x_max_ = y_max_ = std::numeric_limits<float>::min();

  // determine translation to center
  algebra::Vector3D center(0.0, 0.0, 0.0);
  for (unsigned int i = 0; i < points.size(); i++) {
    x_min_ = std::min(x_min_, points[i][0]);
    y_min_ = std::min(y_min_, points[i][1]);
    x_max_ = std::max(x_max_, points[i][0]);
    y_max_ = std::max(y_max_, points[i][1]);
    center += points[i];
  }
  center /= points.size();

  static IMP::em::KernelParameters kp(resolution_);
  const IMP::em::RadiusDependentKernelParameters& params =
      kp.get_params(max_radius);

  double wrap_length = 2 * params.get_kdist() + 1.0;
  x_min_ = x_min_ - wrap_length - scale_;
  y_min_ = y_min_ - wrap_length - scale_;
  x_max_ = x_max_ + wrap_length + scale_;
  y_max_ = y_max_ + wrap_length + scale_;

  int width = (int)((x_max_ - x_min_) / scale_ + 2);
  int height = (int)((y_max_ - y_min_) / scale_ + 2);
  int size = std::max(width, height);

  // the determined size should be below axis size if specified
  if (axis_size > 0 && size <= axis_size)
    size = axis_size;
  else {
    IMP_WARN("wrong size estimate " << size << " vs. estimate " << axis_size
              << std::endl);
  }
  this->resize(boost::extents[size][size]);

  int i = 0, j = 0;
  get_index_for_point(center, i, j);
  t_i_ = size / 2 - i;
  t_j_ = size / 2 - j;
}
FittingSolutionRecords read_fitting_solutions(const char *fitting_fn) {
  std::fstream in;
  FittingSolutionRecords sols;
  in.open(fitting_fn, std::fstream::in);
  if (! in.good()) {
    IMP_WARN("Problem opening file " << fitting_fn <<
             " for reading; returning 0 solutions" << std::endl);
    in.close();
    return sols;
  }
  std::string line;
  getline(in, line); //skip header line
  while (!in.eof()) {
    if (!getline(in, line)) break;
    sols.push_back(parse_fitting_line(line));
  }
  in.close();
  return sols;
}
예제 #16
0
void CHARMMParameters::add_angle(kernel::Particle *p1, kernel::Particle *p2,
                                 kernel::Particle *p3,
                                 kernel::Particles &ps) const {
  IMP_OBJECT_LOG;
  Angle ad = Angle::setup_particle(new kernel::Particle(p1->get_model()),
                                   core::XYZ(p1), core::XYZ(p2), core::XYZ(p3));
  try {
    const CHARMMBondParameters &p = get_angle_parameters(
        CHARMMAtom(p1).get_charmm_type(), CHARMMAtom(p2).get_charmm_type(),
        CHARMMAtom(p3).get_charmm_type());
    ad.set_ideal(p.ideal / 180.0 * PI);
    ad.set_stiffness(std::sqrt(p.force_constant * 2.0));
  }
  catch (const base::IndexException &e) {
    // If no parameters, warn only
    IMP_WARN(e.what());
  }
  ps.push_back(ad);
}
예제 #17
0
void load_union(const Subset &s0, const Subset &s1, AssignmentContainer *nd0,
                AssignmentContainer *nd1, const EdgeData &ed, size_t max,
                AssignmentContainer *out) {
  Ints ii0 = get_index(s0, ed.intersection_subset);
  Ints ii1 = get_index(s1, ed.intersection_subset);
  Ints ui0 = get_index(ed.union_subset, s0);
  Ints ui1 = get_index(ed.union_subset, s1);
  Ints uii = get_index(ed.union_subset, ed.intersection_subset);
  Assignments nd1a =
      nd1->get_assignments(IntRange(0, nd1->get_number_of_assignments()));
  // chunck outer and writing later
  unsigned int nd0sz = nd0->get_number_of_assignments();
  IMP_PROGRESS_DISPLAY("Merging subsets " << s0 << " and " << s1,
                       nd0sz * nd1a.size());
  for (unsigned int i = 0; i < nd0sz; ++i) {
    Assignment nd0a = nd0->get_assignment(i);
    Assignment nd0ae = get_sub_assignment(nd0a, ii0);
    for (unsigned int j = 0; j < nd1a.size(); ++j) {
      Assignment nd1ae = get_sub_assignment(nd1a[j], ii1);
      if (nd1ae == nd0ae) {
        Assignment ss =
            get_merged_assignment(ed.union_subset, nd0a, ui0, nd1a[j], ui1);
        bool ok = true;
        for (unsigned int k = 0; k < ed.filters.size(); ++k) {
          if (!ed.filters[k]->get_is_ok(ss)) {
            ok = false;
            break;
          }
        }
        if (ok) {
          out->add_assignment(ss);
          if (out->get_number_of_assignments() > max) {
            IMP_WARN("Truncated number of states at " << max << " when merging "
                                                      << s0 << " and " << s1);
            return;
          }
        }
      }
      IMP::base::add_to_progress_display(1);
    }
  }
}
예제 #18
0
파일: log.cpp 프로젝트: newtonjoo/imp
void set_log_level(LogLevel l) {
  // snap to max level
  if (l > IMP_HAS_LOG) {
    l = LogLevel(IMP_HAS_LOG);
  }
#if IMP_BASE_HAS_LOG4CXX
  try {
    switch (l) {
      case PROGRESS:
      case SILENT:
        get_logger()->setLevel(log4cxx::Level::getOff());
        break;
      case WARNING:
        get_logger()->setLevel(log4cxx::Level::getWarn());
        break;
      case TERSE:
        get_logger()->setLevel(log4cxx::Level::getInfo());
        break;
      case VERBOSE:
        get_logger()->setLevel(log4cxx::Level::getDebug());
        break;
      case MEMORY:
        get_logger()->setLevel(log4cxx::Level::getTrace());
        break;
      case DEFAULT:
      case ALL_LOG:
      default:
        IMP_WARN("Unknown log level " << boost::lexical_cast<std::string>(l));
    }
  }
  catch (log4cxx::helpers::Exception &) {
    IMP_THROW("Invalid log level", ValueException);
  }
#else
  IMP_USAGE_CHECK(l >= SILENT && l < ALL_LOG,
                  "Setting log to invalid level: " << l);
#endif
  IMP_OMP_PRAGMA(critical(imp_log))
  if (internal::log_level != l) {
    internal::log_level = l;
  }
}
예제 #19
0
파일: Hierarchy.cpp 프로젝트: apolitis/imp
core::RigidBody setup_as_rigid_body(Hierarchy h) {
  IMP_USAGE_CHECK(h.get_is_valid(true),
                  "Invalid hierarchy passed to setup_as_rigid_body");
  IMP_WARN("create_rigid_body should be used instead of setup_as_rigid_body"
           << " as the former allows one to get volumes correct at coarser"
           << " levels of detail.");
  core::RigidBody rbd = core::RigidBody::setup_particle(h, get_leaves(h));
  rbd.set_coordinates_are_optimized(true);
  kernel::ParticlesTemp internal = core::get_internal(h);
  for (unsigned int i = 0; i < internal.size(); ++i) {
    if (internal[i] != h) {
      core::RigidMembers leaves(get_leaves(Hierarchy(internal[i])));
      if (!leaves.empty()) {
        algebra::ReferenceFrame3D rf = core::get_initial_reference_frame(
            get_as<kernel::ParticlesTemp>(leaves));
        core::RigidBody::setup_particle(internal[i], rf);
      }
    }
  }
  IMP_INTERNAL_CHECK(h.get_is_valid(true), "Invalid hierarchy produced");
  return rbd;
}
예제 #20
0
ProteinsAnchorsSamplingSpace read_protein_anchors_mapping(
    multifit::ProteomicsData *prots, const std::string &anchors_prot_map_fn,
    int max_paths) {
  ProteinsAnchorsSamplingSpace ret(prots);
  std::fstream in;
  IMP_LOG_TERSE("FN:" << anchors_prot_map_fn << std::endl);
  in.open(anchors_prot_map_fn.c_str(), std::fstream::in);
  if (!in.good()) {
    IMP_WARN(
        "Problem opening file " << anchors_prot_map_fn
                                << " for reading; returning empty mapping data"
                                << std::endl);
    in.close();
    return ret;
  }
  std::string line;
  // first line should be the anchors line
  getline(in, line);
  std::string anchors_fn =
      get_relative_path(anchors_prot_map_fn, parse_anchors_line(line));
  IMP_LOG_TERSE("FN:" << anchors_fn << std::endl);
  multifit::AnchorsData anchors_data =
      multifit::read_anchors_data(anchors_fn.c_str());
  ret.set_anchors(anchors_data);
  ret.set_anchors_filename(anchors_fn);
  while (!in.eof()) {
    if (!getline(in, line)) break;
    IMP_LOG_VERBOSE("working on line:" << line);
    IMP_USAGE_CHECK(is_protein_line(line), "the line should be a protein line");
    boost::tuple<std::string, std::string, IntsList> prot_data =
        parse_protein_line(anchors_prot_map_fn, line, max_paths);
    ret.set_paths_for_protein(boost::get<0>(prot_data),
                              boost::get<2>(prot_data));
    ret.set_paths_filename_for_protein(boost::get<0>(prot_data),
                                       boost::get<1>(prot_data));
  }
  return ret;
}
예제 #21
0
void handle_error(const char *msg)
{
  static bool is_handling=false;

  if (is_handling) {
    return;
  }
  is_handling=true;
  for (int i=internal::handlers.size()-1; i >=0; --i) {
    IMP_CHECK_OBJECT(internal::handlers[i]);
    try {
      internal::handlers[i]->handle_failure();
    } catch (const Exception &e) {
      IMP_WARN("Caught exception in failure handler \""
               << internal::handlers[i]->get_name() << "\": "
               << e.what() << std::endl);
    }
  }
  if (internal::print_exceptions) {
    IMP_ERROR(msg);
  }
  is_handling=false;
}
예제 #22
0
파일: Object.cpp 프로젝트: newtonjoo/imp
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
}
예제 #23
0
파일: estimates.cpp 프로젝트: newtonjoo/imp
IMPATOM_BEGIN_NAMESPACE

double get_protein_density_from_reference(
    ProteinDensityReference density_reference) {
  double density = 0.625;  // ALBER reference
  switch (density_reference) {
    // Alber et al. (2005) r = 0.726*std::pow(m, .3333);
    case ALBER:
      break;
    // Harpaz et al. 0.826446=1/1.21 Da/A3 ~ 1.372 g/cm3
    case HARPAZ:
      density = 0.826446;
      break;
    // Andersson and Hovmoller (1998) Theoretical 1.22 g/cm3
    case ANDERSSON:
      density = 0.7347;
      break;
    // Tsai et al. (1999) Theoretical 1.40 g/cm3
    case TSAI:
      density = 0.84309;
      break;
    // Quillin and Matthews (2000) Theoretical 1.43 g/cm3
    case QUILLIN:
      density = 0.86116;
      break;
    // Squire and Himmel (1979) and Gekko and Noguchi (1979) Experimental 1.37
    case SQUIRE:
      density = 0.82503;
      break;
    // unknown reference;
    default:
      IMP_WARN(
          "unknown density reference... Density set to its default value.");
  }
  return density;
}
예제 #24
0
ProteomicsData *read_proteomics_data(const char *prot_fn) {
  std::fstream in;
  IMP_NEW(ProteomicsData, data, ());
  in.open(prot_fn, std::fstream::in);
  if (! in.good()) {
    IMP_WARN("Problem opening file " << prot_fn <<
                  " for reading; returning empty proteomics data" << std::endl);
    in.close();
    return data.release();
  }
  std::string line;
  getline(in, line); //skip proteins header line
  getline(in, line); //skip proteins header line
  while ((!in.eof()) && (!is_interaction_header_line(line, data))){
    parse_protein_line(line,data);
    if (!getline(in, line)) break;
  }
  getline(in, line);
  while ((!in.eof()) && (!is_xlink_header_line(line,data))){
    parse_interaction_line(line,data);
    if (!getline(in, line)) break;
  }
  getline(in, line);
  while (!in.eof() && (!is_ev_header_line(line,data))){
    parse_xlink_line(line,data);
    if (!getline(in, line)) break;
  }
  getline(in, line);
  while (!in.eof()) { //ev lines
    parse_ev_line(line,data);
    if (!getline(in, line)) break;
    if (line.size()==0) break;
  }
  in.close();
  return data.release();
}
예제 #25
0
void CHARMMPatch::apply(CHARMMResidueTopology *res1,
                        CHARMMResidueTopology *res2) const
{
  if (res1->get_patched()) {
    IMP_THROW("Cannot patch an already-patched residue", ValueException);
  }
  if (res2->get_patched()) {
    IMP_THROW("Cannot patch an already-patched residue", ValueException);
  }
  check_empty_patch(this);

  // Extra checks for the commonly-used CHARMM DISU patch
  if (get_type() == "DISU"
      && (res1->get_type() != "CYS" || res2->get_type() != "CYS")) {
    IMP_WARN("Applying a DISU patch to two residues that are not both 'CYS' "
             "(they are " << *res1 << " and " << *res2 << "). This is "
             "probably not what was intended.");
  }

  // Copy or update atoms
  for (base::Vector<CHARMMAtomTopology>::const_iterator it = atoms_.begin();
       it != atoms_.end(); ++it) {
    std::pair<CHARMMResidueTopology *, CHARMMAtomTopology> resatom =
                                handle_two_patch_atom(*it, res1, res2);
    try {
      resatom.first->get_atom(resatom.second.get_name()) = resatom.second;
    } catch (ValueException &e) {
      resatom.first->add_atom(resatom.second);
    }
  }

  // Delete atoms
  for (base::Vector<std::string>::const_iterator it = deleted_atoms_.begin();
       it != deleted_atoms_.end(); ++it) {
    std::pair<CHARMMResidueTopology *, CHARMMAtomTopology> resatom =
                                handle_two_patch_atom(*it, res1, res2);
    try {
      resatom.first->remove_atom(resatom.second.get_name());
    } catch (ValueException &e) {
      // ignore atoms that don't exist to start with
    }
  }

  // Add angles/bonds/dihedrals/impropers
  for (unsigned int i = 0; i < get_number_of_bonds(); ++i) {
    CHARMMResidueTopology *res =
                get_two_patch_residue_for_bond(get_bond(i), res1, res2);
    res->add_bond(CHARMMBond(handle_two_patch_bond(get_bond(i), res1,
                                                   res2, res)));
  }
  for (unsigned int i = 0; i < get_number_of_angles(); ++i) {
    CHARMMResidueTopology *res =
               get_two_patch_residue_for_bond(get_angle(i), res1, res2);
    res->add_angle(CHARMMAngle(handle_two_patch_bond(get_angle(i), res1, res2,
                                                     res)));
  }
  for (unsigned int i = 0; i < get_number_of_dihedrals(); ++i) {
    CHARMMResidueTopology *res =
                    get_two_patch_residue_for_bond(get_dihedral(i), res1, res2);
    res->add_dihedral(CHARMMDihedral(handle_two_patch_bond(get_dihedral(i),
                                                           res1, res2, res)));
  }
  for (unsigned int i = 0; i < get_number_of_impropers(); ++i) {
    CHARMMResidueTopology *res =
                    get_two_patch_residue_for_bond(get_improper(i), res1, res2);
    res->add_improper(CHARMMDihedral(handle_two_patch_bond(get_improper(i),
                                                           res1, res2, res)));
  }

  // Add internal coordinates
  for (unsigned int i = 0; i < get_number_of_internal_coordinates(); ++i) {
    CHARMMInternalCoordinate ic = get_internal_coordinate(i);
    CHARMMResidueTopology *res =
                    get_two_patch_residue_for_bond(get_internal_coordinate(i),
                                                   res1, res2);
    res->add_internal_coordinate(
            CHARMMInternalCoordinate(handle_two_patch_bond(ic, res1,
                                                           res2, res),
                                ic.get_first_distance(), ic.get_first_angle(),
                                ic.get_dihedral(), ic.get_second_angle(),
                                ic.get_second_distance(), ic.get_improper()));
  }

  res1->set_patched(true);
  res2->set_patched(true);
}
예제 #26
0
파일: CoarseCC.cpp 프로젝트: AljGaber/imp
float CoarseCC::local_cross_correlation_coefficient(
    const DensityMap *em_map, DensityMap *model_map,
    float voxel_data_threshold) {
  IMP_INTERNAL_CHECK(
      model_map->get_header()->dmax > voxel_data_threshold,
      "voxel_data_threshold: " << voxel_data_threshold
                               << " is not within the map range: "
                               << model_map->get_header()->dmin << "-"
                               << model_map->get_header()->dmax << std::endl);
  const DensityHeader *model_header = model_map->get_header();
  const DensityHeader *em_header = em_map->get_header();

  const emreal *em_data = em_map->get_data();
  const emreal *model_data = model_map->get_data();

  // validity checks
  IMP_USAGE_CHECK(
      em_map->same_voxel_size(model_map),
      "This function cannot handle density maps of different pixelsize. "
          << "First map pixelsize : " << em_header->get_spacing() << "; "
          << "Second map pixelsize: " << model_header->get_spacing());

  // Check if the model map has zero RMS
  if ((fabs(model_map->get_header()->rms - 0.0) < EPS)) {
    IMP_WARN("The model map rms is zero, and the user ask to divide"
             << " by rms. returning 0!" << std::endl);
    return 0.0;
  }

  long nvox = em_header->get_number_of_voxels();
  ;
  emreal ccc = 0.0;
  emreal model_mean = 0.;
  emreal em_mean = 0.;
  emreal model_rms = 0.;
  emreal em_rms = 0.;
  IMP_LOG_VERBOSE("calc local CC with different origins" << std::endl);
  model_map->get_header_writable()->compute_xyz_top();

  // Given the same size of the maps and the dimension order, the difference
  // between two positions in voxels is always the same

  // calculate the difference in voxels between the origin of the  model map
  // and the origin of the em map.
  float voxel_size = em_map->get_header()->get_spacing();
  int ivoxx_shift = (int)floor(
      (model_header->get_xorigin() - em_header->get_xorigin()) / voxel_size);
  int ivoxy_shift = (int)floor(
      (model_header->get_yorigin() - em_header->get_yorigin()) / voxel_size);
  int ivoxz_shift = (int)floor(
      (model_header->get_zorigin() - em_header->get_zorigin()) / voxel_size);

  long j;  // Index for em data
  long i;  // Index for model data
           // calculate the shift in index of the origin of model_map in em_map
           // ( j can be negative)
  j = ivoxz_shift * em_header->get_nx() * em_header->get_ny() +
      ivoxy_shift * em_header->get_nx() + ivoxx_shift;
  int num_elements = 0;  //
  for (i = 0; i < nvox; i++) {
    // if the voxel of the model is above the threshold
    if (model_data[i] > voxel_data_threshold) {
      // Check if the voxel belongs to the em map volume, and only then
      // compute the correlation
      if (j + i >= 0 && j + i < nvox) {
        num_elements++;
        em_mean += em_data[j + i];
        model_mean += model_data[i];
      }
    }
  }
  em_mean = em_mean / num_elements;
  model_mean = model_mean / num_elements;
  em_rms = 0.;
  model_rms = 0.;
  for (i = 0; i < nvox; i++) {
    // if the voxel of the model is above the threshold
    if (model_data[i] > voxel_data_threshold) {
      // Check if the voxel belongs to the em map volume, and only then
      // compute the correlation
      if (j + i >= 0 && j + i < nvox) {
        ccc += (em_data[j + i] - em_mean) * (model_data[i] - model_mean);
        em_rms += (em_data[j + i] - em_mean) * (em_data[j + i] - em_mean);
        model_rms +=
            (model_data[i] - model_mean) * (model_data[i] - model_mean);
      }
    }
  }
  em_rms = std::sqrt(em_rms / num_elements);
  model_rms = std::sqrt(model_rms / num_elements);
  IMP_INTERNAL_CHECK(num_elements > 0,
                     "No voxels participated in the calculation"
                         << " may be that the voxel_data_threshold:"
                         << voxel_data_threshold << " is off" << std::endl);
  ccc = ccc / (1. * num_elements * em_rms * model_rms);
  IMP_LOG_VERBOSE(" local ccc : " << ccc << " voxel# " << num_elements
                                  << " norm factors (map,model) " << em_rms
                                  << "  " << model_rms << " means(map,model) "
                                  << em_mean << " " << model_mean << std::endl);

  return ccc;
}
예제 #27
0
파일: CoarseCC.cpp 프로젝트: salilab/imp
algebra::Vector3Ds CoarseCC::calc_derivatives(const DensityMap *em_map,
                                              const DensityMap *model_map,
                                              const Particles &model_ps,
                                              const FloatKey &w_key,
                                              KernelParameters *kernel_params,
                                              const float &scalefac,
                                              const algebra::Vector3Ds &dv) {
  algebra::Vector3Ds dv_out;
  dv_out.insert(dv_out.end(), dv.size(), algebra::Vector3D(0., 0., 0.));
  double tdvx = 0., tdvy = 0., tdvz = 0., tmp, rsq;
  int iminx, iminy, iminz, imaxx, imaxy, imaxz;

  const DensityHeader *model_header = model_map->get_header();
  const DensityHeader *em_header = em_map->get_header();
  const float *x_loc = em_map->get_x_loc();
  const float *y_loc = em_map->get_y_loc();
  const float *z_loc = em_map->get_z_loc();
  IMP_INTERNAL_CHECK(model_ps.size() == dv.size(),
                     "input derivatives array size does not match "
                         << "the number of particles in the model map\n");
  core::XYZRs model_xyzr = core::XYZRs(model_ps);
  // this would go away once we have XYZRW decorator
  const emreal *em_data = em_map->get_data();
  float lim = kernel_params->get_lim();
  long ivox;
  // validate that the model and em maps are not empty
  IMP_USAGE_CHECK(em_header->rms >= EPS,
                  "EM map is empty ! em_header->rms = " << em_header->rms);
  if (model_header->rms <= EPS) {
    IMP_WARN("Model map is empty ! model_header->rms = " << model_header->rms
             << " derivatives are not calculated. the model centroid is : " <<
             core::get_centroid(core::XYZs(model_ps)) <<
             " the map centroid is " << em_map->get_centroid() <<
             "number of particles in model:"<<model_ps.size()
             << std::endl);
    return dv_out;
  }
  // Compute the derivatives
  int nx = em_header->get_nx();
  int ny = em_header->get_ny();
  // int nz=em_header->get_nz();
  IMP_INTERNAL_CHECK(em_map->get_rms_calculated(),
                     "RMS should be calculated for calculating derivatives \n");
  long nvox = em_header->get_number_of_voxels();
  double lower_comp = 1. * nvox * em_header->rms * model_header->rms;

  for (unsigned int ii = 0; ii < model_ps.size(); ii++) {
    float x, y, z;
    x = model_xyzr[ii].get_x();
    y = model_xyzr[ii].get_y();
    z = model_xyzr[ii].get_z();
    IMP_IF_LOG(VERBOSE) {
      algebra::Vector3D vv(x, y, z);
      IMP_LOG_VERBOSE(
          "start value:: (" << x << "," << y << "," << z << " ) "
                            << em_map->get_value(x, y, z) << " : "
                            << em_map->get_dim_index_by_location(vv, 0) << ","
                            << em_map->get_dim_index_by_location(vv, 1) << ","
                            << em_map->get_dim_index_by_location(vv, 2)
                            << std::endl);
    }

    calc_local_bounding_box(  // em_map,
        model_map, x, y, z, kernel_params->get_rkdist(), iminx, iminy, iminz, imaxx,
        imaxy, imaxz);

    IMP_LOG_VERBOSE("local bb: [" << iminx << "," << iminy << "," << iminz
                                  << "] [" << imaxx << "," << imaxy << ","
                                  << imaxz << "] \n");
    tdvx = .0;
    tdvy = .0;
    tdvz = .0;
    for (int ivoxz = iminz; ivoxz <= imaxz; ivoxz++) {
      for (int ivoxy = iminy; ivoxy <= imaxy; ivoxy++) {
        ivox = ivoxz * nx * ny + ivoxy * nx + iminx;
        for (int ivoxx = iminx; ivoxx <= imaxx; ivoxx++) {
          /*          if (em_data[ivox]<EPS) {
            ivox++;
            continue;
            }*/
          float dx = x_loc[ivox] - x;
          float dy = y_loc[ivox] - y;
          float dz = z_loc[ivox] - z;
          rsq = dx * dx + dy * dy + dz * dz;
          rsq = EXP(-rsq * kernel_params->get_inv_rsigsq());
          tmp = (x - x_loc[ivox]) * rsq;
          if (std::abs(tmp) > lim) {
            tdvx += tmp * em_data[ivox];
          }
          tmp = (y - y_loc[ivox]) * rsq;
          if (std::abs(tmp) > lim) {
            tdvy += tmp * em_data[ivox];
          }
          tmp = (z - z_loc[ivox]) * rsq;
          if (std::abs(tmp) > lim) {
            tdvz += tmp * em_data[ivox];
          }
          ivox++;
        }
      }
    }
    tmp = model_ps[ii]->get_value(w_key) * 2. * kernel_params->get_inv_rsigsq() *
          scalefac * kernel_params->get_rnormfac() / lower_comp;
    IMP_LOG_VERBOSE("for particle:" << ii << " (" << tdvx << "," << tdvy << ","
                                    << tdvz << ")" << std::endl);
    dv_out[ii][0] = tdvx * tmp;
    dv_out[ii][1] = tdvy * tmp;
    dv_out[ii][2] = tdvz * tmp;

  }  // particles
  return dv_out;
}