Ejemplo n.º 1
0
std::string InputOutputException::get_message(ModelObject *o) const {
  std::ostringstream oss;
  switch (get_entity()) {
    case DERIVATIVE:
      if (o->get_model()->get_stage() == BEFORE_EVALUATING) {
        oss << "Derivatives cannot be read before evaluating.";
        break;
      }
    default:
      switch (get_operation()) {
        case GET:
          oss << "Not in input list.";
          break;
        case SET:
        case ADD:
        case REMOVE:
          oss << "Not in output list.";
          break;
        default:
          // should not exist
          oss << "Unknown read/write error";
      }
      break;
  };
  oss << " Violating object: \"" << o->get_name() << "\".";
  if (particle_index_ >= 0) {
    oss << " Attribute " << get_key_name() << " of particle \""
        << o->get_model()
               ->get_particle(ParticleIndex(get_particle_index()))
               ->get_name() << "\" with id " << get_particle_index();
  } else {
    oss << "Container \"" << container_name_ << "\".";
  }
  return oss.str();
}
Ejemplo n.º 2
0
void RestraintCache::save_cache(const kernel::ParticlesTemp &particle_ordering,
                                const kernel::RestraintsTemp &restraints,
                                RMF::HDF5::Group group,
                                unsigned int max_entries) {
  RMF::HDF5::FloatDataSet1Ds scores;
  RMF::HDF5::IntDataSet2Ds assignments;
  base::map<kernel::Restraint *, int> restraint_index;
  ParticleIndex particle_index = get_particle_index(particle_ordering);
  Orders orders = get_orders(known_restraints_, restraints, particle_ordering);
  // create data sets for restraints
  for (unsigned int i = 0; i < restraints.size(); ++i) {
    kernel::Restraint *r = restraints[i];
    RestraintID rid =
        get_restraint_id(particle_index, known_restraints_.find(r)->second,
                         restraint_index_.find(r)->second);
    RMF::HDF5::Group g = group.add_child_group(r->get_name());
    g.set_attribute<RMF::HDF5::IndexTraits>(
        "restraint", RMF::HDF5::Indexes(1, rid.get_restraint_index()));
    g.set_attribute<RMF::HDF5::IndexTraits>(
        "particles", RMF::HDF5::Indexes(rid.get_particle_indexes().begin(),
                                        rid.get_particle_indexes().end()));
    scores.push_back(g.add_child_data_set<RMF::HDF5::FloatTraits, 1>("scores"));
    assignments.push_back(
        g.add_child_data_set<RMF::HDF5::IntTraits, 2>("assignments"));
    restraint_index[r] = i;
  }
  // finally start saving them
  unsigned int count = 0;
  for (Cache::ContentIterator it = cache_.contents_begin();
       it != cache_.contents_end(); ++it) {
    int ri = restraint_index.find(it->key.get_restraint())->second;
    Ints ord = orders[ri].get_list_ordered(it->key.get_assignment());
    double score = it->value;
    RMF::HDF5::DataSetIndexD<2> asz = assignments[ri].get_size();
    RMF::HDF5::DataSetIndexD<1> row(asz[0]);
    asz[1] = ord.size();
    ++asz[0];
    assignments[ri].set_size(asz);
    assignments[ri].set_row(row, RMF::HDF5::Ints(ord.begin(), ord.end()));
    RMF::HDF5::DataSetIndexD<1> ssz = scores[ri].get_size();
    RMF::HDF5::DataSetIndexD<1> nsz = ssz;
    ++nsz[0];
    scores[ri].set_size(nsz);
    scores[ri].set_value(ssz, score);
    ++count;
    if (count > max_entries) break;
  }
}
Ejemplo n.º 3
0
void RestraintCache::load_cache(const kernel::ParticlesTemp &particle_ordering,
                                RMF::HDF5::ConstGroup group) {
  ParticleIndex particle_index = get_particle_index(particle_ordering);
  base::map<RestraintID, kernel::Restraint *> index;
  for (KnownRestraints::const_iterator it = known_restraints_.begin();
       it != known_restraints_.end(); ++it) {
    index[get_restraint_id(particle_index, it->second,
                           restraint_index_.find(it->first)->second)] =
        it->first;
  }
  kernel::RestraintsTemp restraints;
  for (unsigned int i = 0; i < group.get_number_of_children(); ++i) {
    RMF::HDF5::ConstGroup ch = group.get_child_group(i);
    int restraint_index =
        ch.get_attribute<RMF::HDF5::IndexTraits>("restraint")[0];
    RMF::HDF5::Indexes particle_indexes =
        ch.get_attribute<RMF::HDF5::IndexTraits>("particles");
    RestraintID rid(restraint_index,
                    base::ConstVector<unsigned int>(Ints(
                        particle_indexes.begin(), particle_indexes.end())));
    kernel::Restraint *r = index.find(rid)->second;
    restraints.push_back(r);
    IMP_LOG_TERSE("Matching " << Showable(r) << " with " << ch.get_name()
                              << std::endl);
  }
  Orders orders = get_orders(known_restraints_, restraints, particle_ordering);
  for (unsigned int i = 0; i < group.get_number_of_children(); ++i) {
    RMF::HDF5::ConstGroup ch = group.get_child_group(i);
    RMF::HDF5::FloatConstDataSet1D scores =
        ch.get_child_float_data_set_1d("scores");
    RMF::HDF5::IntConstDataSet2D assignments =
        ch.get_child_int_data_set_2d("assignments");
    for (unsigned int j = 0; j < scores.get_size()[0]; ++j) {
      double s = scores.get_value(RMF::HDF5::DataSetIndex1D(j));
      RMF::HDF5::Ints rw = assignments.get_row(RMF::HDF5::DataSetIndex1D(j));
      Ints psit(rw.begin(), rw.end());
      Assignment ass = orders[i].get_subset_ordered(psit);
      cache_.insert(Key(restraints[i], ass), s);
    }
  }
  validate();
}
Ejemplo n.º 4
0
IMPCORE_END_INTERNAL_NAMESPACE
IMPCORE_BEGIN_NAMESPACE
void RigidBody::normalize_rotation() {
  double &q0 = get_model()->access_attribute(
      internal::rigid_body_data().quaternion_[0], get_particle_index());
  double &q1 = get_model()->access_attribute(
      internal::rigid_body_data().quaternion_[1], get_particle_index());
  double &q2 = get_model()->access_attribute(
      internal::rigid_body_data().quaternion_[2], get_particle_index());
  double &q3 = get_model()->access_attribute(
      internal::rigid_body_data().quaternion_[3], get_particle_index());
  algebra::VectorD<4> v(q0, q1, q2, q3);
  // IMP_LOG_TERSE( "Rotation was " << v << std::endl);
  double sm = v.get_squared_magnitude();
  if (sm < .001) {
    v = algebra::VectorD<4>(1, 0, 0, 0);
    // IMP_LOG_TERSE( "Rotation is " << v << std::endl);
    q0 = 1;
    q1 = 0;
    q2 = 0;
    q3 = 0;
  } else if (std::abs(sm - 1.0) > .01) {
    v = v.get_unit_vector();
    // IMP_LOG_TERSE( "Rotation is " << v << std::endl);
    q0 = v[0];
    q1 = v[1];
    q2 = v[2];
    q3 = v[3];
  }

  // evil hack
  get_model()->set_attribute(internal::rigid_body_data().torque_[0],
                             get_particle_index(), 0);
  get_model()->set_attribute(internal::rigid_body_data().torque_[1],
                             get_particle_index(), 0);
  get_model()->set_attribute(internal::rigid_body_data().torque_[2],
                             get_particle_index(), 0);
}