Ejemplo n.º 1
0
Archivo: pdb.cpp Proyecto: salilab/imp
IMPATOM_BEGIN_INTERNAL_NAMESPACE

Particle* atom_particle(Model* m, const std::string& atom_type,
                        Element element, bool is_hetatm,
                        int atom_index, int residue_index,
                        double x, double y, double z,
                        double occupancy, double temp_factor) {
  AtomType atom_name;
  std::string string_name = atom_type;
  // determine AtomType
  if (is_hetatm) {
    string_name = "HET:" + string_name;
    if (!get_atom_type_exists(string_name)) {
      atom_name = add_atom_type(string_name, element);
    } else {
      atom_name = AtomType(string_name);
    }
  } else {  // ATOM line
    boost::trim(string_name);
    if (string_name.empty()) {
      string_name = "UNK";
    }
    if (!AtomType::get_key_exists(string_name)) {
      IMP_LOG_VERBOSE("ATOM record type not found: \""
                      << string_name << "\" in PDB file " << std::endl);
      atom_name = add_atom_type(string_name, element);
    } else {
      atom_name = AtomType(string_name);
    }
  }
  // new particle
  Particle* p = new Particle(m);
  p->add_attribute(get_pdb_index_key(), atom_index);
  algebra::Vector3D v(x, y, z);
  // atom decorator
  Atom d = Atom::setup_particle(p, atom_name);
  std::ostringstream oss;
  oss << "Atom " + atom_name.get_string() << " of residue " << residue_index;
  p->set_name(oss.str());
  core::XYZ::setup_particle(p, v).set_coordinates_are_optimized(true);
  d.set_input_index(atom_index);
  d.set_occupancy(occupancy);
  d.set_temperature_factor(temp_factor);
  d.set_element(element);
  // check if the element matches
  Element e2 = get_element_for_atom_type(atom_name);
  if (element != e2) {
    IMP_LOG_VERBOSE(
        "AtomType element and PDB line elements don't match. AtomType "
        << e2 << " vs. determined from PDB " << element << std::endl);
  }
  return p;
}
Ejemplo n.º 2
0
void Nuisance::set_lower(Float d) {
    Particle * p = get_particle();
    if (! p->has_attribute(get_lower_key()))
            p->add_attribute(get_lower_key(), d);
    p->set_value(get_lower_key(), d);
}
Ejemplo n.º 3
0
void KMLProxy::run(Particles *initial_centers) {
  IMP_INTERNAL_CHECK(is_init_,"The proxy was not initialized");
  IMP_LOG(VERBOSE,"KMLProxy::run start \n");
  //use the initial centers if provided
  KMPointArray *kmc=nullptr;
  if (initial_centers != nullptr)  {
    IMP_INTERNAL_CHECK(kcenters_ == initial_centers->size(),
    "the number of initial points differs from the number of required"
    <<" centers\n");
    IMP_LOG(VERBOSE,"KMLProxy::run initial centers provided : \n");
    kmc = allocate_points(kcenters_,atts_.size());
    for (unsigned int i=0;i<kcenters_;i++){
      Particle *cen=(*initial_centers)[i];
      for(unsigned int j=0;j<atts_.size();j++) {
        (*(*kmc)[i])[j]=cen->get_value(atts_[j]);
       }
    }
  }
  IMP_LOG(VERBOSE,"KMLProxy::run load initial guess \n");
  //load the initail guess
  KMFilterCenters ctrs(kcenters_, data_, kmc,damp_factor_);

  //apply lloyd search
  IMP_LOG(VERBOSE,"KMLProxy::run load lloyd \n");
  lloyd_alg_ = new KMLocalSearchLloyd(&ctrs,&term_);
  log_header();
  IMP_CHECK_CODE(clock_t start = clock());
  IMP_LOG(VERBOSE,"KMLProxy::run excute lloyd \n");
  lloyd_alg_->execute();
  IMP_LOG(VERBOSE,"KMLProxy::run analyse \n");
  KMFilterCentersResults best_clusters = lloyd_alg_->get_best();
  IMP_CHECK_CODE(Float exec_time = elapsed_time(start));
  // print summary
  IMP_LOG_WRITE(TERSE,log_summary(&best_clusters,exec_time));
  IMP_LOG_WRITE(TERSE,best_clusters.show(IMP_STREAM));
  IMP_INTERNAL_CHECK(kcenters_
                     == (unsigned int) best_clusters.get_number_of_centers(),
             "The final number of centers does not match the requested one");
  IMP_INTERNAL_CHECK (dim_ == (unsigned int) best_clusters.get_dim(),
              "The dimension of the final clusters is wrong");
  //TODO clear the centroids list
  //set the centroids:
  Particle *p;
  IMP_LOG(VERBOSE,"KMLProxy::run load best results \n");
  for (unsigned int ctr_ind = 0; ctr_ind < kcenters_; ctr_ind++) {
    KMPoint *kmp = best_clusters[ctr_ind];
    //create a new particle
    p = new Particle(m_);
    centroids_.push_back(p);
    for (unsigned int att_ind = 0; att_ind < dim_; att_ind++) {
      p->add_attribute(atts_[att_ind],(*kmp)[att_ind],false);
    }
  }
  //set the assignment of particles to centers
  //array of number of all points
  //TODO - return this
  IMP_LOG(VERBOSE,"KMLProxy::run get assignments \n");
  const Ints *close_center = best_clusters.get_assignments();
  IMP_LOG(VERBOSE,"KMLProxy::run get assignments 2\n");
  for (int i=0;i<data_->get_number_of_points();i++) {
    //std::cout<<"ps number i: " << i << " close center : "
    //<< (*close_center)[i] << std::endl;
    assignment_[ps_[i]]=(*close_center)[i];
  }
}