TEST(qpsContainerModel, vectorPodEmpty)
{
    using Ints = qps::ContainerModel< QVector, int >;
    Ints ints;
    EXPECT_EQ( ints.rowCount(), 0 );
    EXPECT_EQ( ints.getItemCount(), 0 );
}
Esempio n. 2
0
void Fragment::set_residue_indexes(kernel::Model *m, kernel::ParticleIndex pi,
                                   Ints o) {
  if (o.empty()) {
    set_residue_indexes(m, pi, IntPairs());
    return;
  }
  std::sort(o.begin(), o.end());
  o.erase(std::unique(o.begin(), o.end()), o.end());
  IntPairs pairs;
  int begin = 0;
  for (unsigned int i = 1; i < o.size(); ++i) {
    if (o[i] != o[i - 1] + 1) {
      pairs.push_back(IntPair(o[begin], o[i - 1] + 1));
      begin = i;
    }
  }
  pairs.push_back(IntPair(o[begin], o.back() + 1));
  set_residue_indexes(m, pi, pairs);
  using IMP::operator<<;
  IMP_IF_CHECK(USAGE) {
    for (unsigned int i = 0; i < o.size(); ++i) {
      IMP_INTERNAL_CHECK(Fragment(m, pi).get_contains_residue(o[i]),
                         "Residue index not found after addition: "
                             << o << " became " << pairs);
    }
  }
}
Esempio n. 3
0
IMPMULTIFITEXPORT
IntsList get_anchor_indices_matching_secondary_structure(
    const AnchorsData &ad, const atom::SecondaryStructureResidues &match_ssrs,
    Float max_rmsd) {

  atom::SecondaryStructureResidues anchor_ssrs =
      ad.get_secondary_structure_particles();
  IMP_USAGE_CHECK(anchor_ssrs.size() == ad.points_.size(),
                  "Anchors do not have enough SSEs set");

  // double loop unfortunately: for each match_ps check all anchors
  IntsList all_matches;
  for (atom::SecondaryStructureResidues::const_iterator it_match =
           match_ssrs.begin();
       it_match != match_ssrs.end(); ++it_match) {
    Ints matches;
    int count = 0;
    for (atom::SecondaryStructureResidues::const_iterator it_anchor =
             anchor_ssrs.begin();
         it_anchor != anchor_ssrs.end(); ++it_anchor) {
      float match_score =
          atom::get_secondary_structure_match_score(*it_anchor, *it_match);
      if (match_score < max_rmsd) matches.push_back(count);
      count++;
    }
    all_matches.push_back(matches);
  }
  return all_matches;
}
Esempio n. 4
0
IMPEM2D_BEGIN_NAMESPACE

Ints ClusterSet::get_clusters_below_cutoff(double cutoff) const {
    Ints clusters;
    std::vector<bool> is_active(steps_, true);

    for (int i = steps_ - 1; i >= 0; --i) {
        if (is_active[i] == true && cluster_distances_[i] < cutoff) {
            clusters.push_back(get_id_for_cluster_at_step(i));
            // Deactivate all the members of the linkage matrix that contain
            // the elements of this cluster
            Ints to_deactivate;
            unsigned int id1 = joined_ids1_[i];
            unsigned int id2 = joined_ids2_[i];
            if (id1 >= n_elements_) to_deactivate.push_back(id1);
            if (id2 >= n_elements_) to_deactivate.push_back(id2);

            while (to_deactivate.size() > 0) {
                int id = to_deactivate.back();
                to_deactivate.pop_back();
                int j = get_step_from_id(id);  // new row to deactivate
                is_active[j] = false;
                unsigned int jid1 = joined_ids1_[j];
                unsigned int jid2 = joined_ids2_[j];
                if (jid1 >= n_elements_) to_deactivate.push_back(jid1);
                if (jid2 >= n_elements_) to_deactivate.push_back(jid2);
            }
        }
        is_active[i] = false;  // deactivate after considering it
    }
    return clusters;
}
Esempio n. 5
0
void ClusterSet::do_join_clusters(unsigned int cluster_id1,
                                  unsigned int cluster_id2,
                                  double distance_between_clusters) {
    IMP_LOG_VERBOSE("Joining clusters " << cluster_id1 << " and " << cluster_id2
                    << std::endl);

    joined_ids1_.push_back(cluster_id1);
    joined_ids2_.push_back(cluster_id2);
    cluster_distances_.push_back(distance_between_clusters);

    Ints ids;
    ids.push_back(cluster_id1);
    ids.push_back(cluster_id2);
    Ints new_cluster;
    for (unsigned int i = 0; i < 2; ++i) {
        if ((unsigned int)ids[i] < n_elements_) {
            new_cluster.push_back(ids[i]);
        } else {
            unsigned int s = get_step_from_id(ids[i]);
            new_cluster.insert(new_cluster.end(), clusters_elements_[s].begin(),
                               clusters_elements_[s].end());
        }
    }
    clusters_elements_.push_back(new_cluster);
    steps_++;
}
/// For algorithm details, see http://wiki.openstreetmap.org/wiki/Relation:multipolygon/Algorithm
void MultipolygonProcessor::process() {
  bool allClosed = true;
  // NOTE do not count multipolygon tag itself
  bool hasNoTags = relation_.tags.size() < 2;
  Ints outerIndecies;
  Ints innerIndecies;
  CoordinateSequences sequences;
  for (const auto &member : members_) {

    if (member.type!="w")
      continue;

    Coordinates coordinates;
    auto wayPair = context_.wayMap.find(member.refId);
    if (wayPair!=context_.wayMap.end()) {
      coordinates = wayPair->second->coordinates;
    } else {
      auto areaPair = context_.areaMap.find(member.refId);
      if (areaPair!=context_.areaMap.end()) {
        coordinates = areaPair->second->coordinates;

        // NOTE make coordinates to be closed ring
        coordinates.push_back(coordinates[0]);

        // NOTE merge tags to relation
        // hasNoTags prevents the case where relation has members with their own tags
        // which should be processed independently (geometry reusage)
        if (member.role=="outer" && hasNoTags)
          mergeTags(areaPair->second->tags);
      } else {
        auto relationPair = context_.relationMap.find(member.refId);
        if (relationPair==context_.relationMap.end())
          return; //  NOTE cannot fill relation: incomplete data

        resolve_(*relationPair->second);
      }
    }

    if (coordinates.empty())
      continue;

    if (member.role=="outer")
      outerIndecies.push_back(static_cast<int>(sequences.size()));
    else if (member.role=="inner")
      innerIndecies.push_back(static_cast<int>(sequences.size()));
    else
      continue;

    auto sequence = std::make_shared<CoordinateSequence>(member.refId, coordinates);
    if (!sequence->isClosed())
      allClosed = false;

    sequences.push_back(sequence);
  }

  if (outerIndecies.size()==1 && allClosed)
    simpleCase(sequences, outerIndecies, innerIndecies);
  else
    complexCase(sequences);
}
void Test_example_KeepIf_performance()
{
    using namespace fplus;

    typedef std::vector<int> Ints;
    auto run_loop = [&](const Ints values)
    {
        Ints odds;
        for (int x : values)
            if (is_odd_int(x))
                odds.push_back(x);
        return odds;
    };
    auto run_stl = [&](const Ints values)
    {
        Ints odds;
        std::copy_if(std::begin(values), std::end(values),
                std::back_inserter(odds), is_odd_int);
        return odds;
    };
    auto run_FunctionalPlus = [&](const Ints values)
        { return keep_if(is_odd_int, values); };

    // make debug runs faster
#if defined NDEBUG || defined _DEBUG
    std::size_t numRuns = 10;
#else
    std::size_t numRuns = 20000;
#endif

    Ints values = generate<Ints>(rand, 5000);
    run_n_times(run_loop, numRuns, "Hand-written for loop", values);
    run_n_times(run_stl, numRuns, "std::copy_if", values);
    run_n_times(run_FunctionalPlus, numRuns, "FunctionalPlus::keep_if", values);
}
Esempio n. 8
0
void KMCentersNode::compute_close_centers(const Ints &candidate_centers_inds,
        Ints *close_centers_inds) {
    const KMPoint *l, *h;
    l = bnd_box_.get_point(0);
    h = bnd_box_.get_point(1);
    // first we calculate the center that is closest to the middle of the
    // bounding box
    int mid_center_ind = mid_center(candidate_centers_inds);
    KMPoint *mid_cen = (*centers_)[mid_center_ind];
    double box_dot = 0.;  // holds (p-c').(c-c')
    double cc_dot = 0.;   // holds (c-c').(c-c')
    for (Ints::const_iterator it = candidate_centers_inds.begin();
            it != candidate_centers_inds.end(); it++) {
        if (*it == mid_center_ind) {
            close_centers_inds->push_back(*it);
        } else {
            KMPoint *cand_cen = (*centers_)[*it];
            KMPoint closest_vertex = bnd_box_.find_closest_vertex(*cand_cen);
            box_dot = 0.;
            cc_dot = 0.;
            for (int d = 0; d < bnd_box_.get_dim(); d++) {
                double cc_comp = (*cand_cen)[d] - (*mid_cen)[d];
                cc_dot += cc_comp * cc_comp;  // increment dot product
                if (cc_comp > 0) {
                    box_dot += cc_comp * ((*h)[d] - (*mid_cen)[d]);
                } else {
                    box_dot += cc_comp * ((*l)[d] - (*mid_cen)[d]);
                }
            }
            if (cc_dot < 2 * box_dot) {
                close_centers_inds->push_back(*it);
            }
        }
    }
}
Esempio n. 9
0
FrameHandles FrameHandle::get_children() const {
  Ints children = get_shared_data()->get_children(get_frame_id());
  FrameHandles ret(children.size());
  for (unsigned int i = 0; i < ret.size(); ++i) {
    ret[i] = FrameHandle(children[i], get_shared_data());
  }
  return ret;
}
Esempio n. 10
0
Ints ReplicaExchange::create_exarray()
{
 Ints exarray;
 for(int i=0;i<nproc_-1;++i) {
  exarray.push_back(0);
 }
 return exarray;
}
Esempio n. 11
0
int main() {
    Ints t;
    cout << t.sum() << endl;
    cout << t.sum(1) << endl;
    cout << t.sum(1, 2) << endl;
    cout << t.sum(1, 2, 3) << endl;

    return 0;
}
Esempio n. 12
0
// see http://wiki.openstreetmap.org/wiki/Relation:multipolygon/Algorithm
void MultipolygonProcessor::process()
{
    bool allClosed = true;

    Ints outerIndecies;
    Ints innerIndecies;
    CoordinateSequences sequences;
    for (const auto& member : members_) {

        if (member.type != "way") 
            continue;

        Coordinates coordinates;
        auto wayPair = context_.wayMap.find(member.refId);
        if (wayPair != context_.wayMap.end()) {
            coordinates = wayPair->second->coordinates;
        }
        else {
            auto areaPair = context_.areaMap.find(member.refId);
            if (areaPair != context_.areaMap.end()) {
                coordinates = areaPair->second->coordinates;
                // NOTE merge tags to relation
                if (member.role == "outer")
                    mergeTags(areaPair->second->tags);
            }
            else {
                auto relationPair = context_.relationMap.find(member.refId);
                if (relationPair == context_.relationMap.end())
                    return; //  NOTE cannot fill relation: incomplete data

                resolve_(*relationPair->second);
            }
        }

        if (coordinates.empty()) 
            continue;

        if (member.role == "outer")
            outerIndecies.push_back(static_cast<int>(sequences.size()));
        else if (member.role == "inner")
            innerIndecies.push_back(static_cast<int>(sequences.size()));
        else
            continue;

        auto sequence = std::make_shared<CoordinateSequence>(member.refId, coordinates);
        if (!sequence->isClosed()) 
            allClosed = false;

        sequences.push_back(sequence);
    }

    if (outerIndecies.size() == 1 && allClosed)
        simpleCase(sequences, outerIndecies, innerIndecies);
    else
        complexCase(sequences);
}
Esempio n. 13
0
Ints Fragment::get_residue_indexes() const {
  IntPairs ranges = get_residue_index_ranges();
  Ints ret;
  for (unsigned int i = 0; i < ranges.size(); ++i) {
    for (int j = ranges[i].first; j < ranges[i].second; ++j) {
      ret.push_back(j);
    }
  }
  return ret;
}
Esempio n. 14
0
void Paver::pave(const SearchType search) {
  temp_.resize(nvars());
  Ints certainties;
  certainties.assign(nrels() + flags_, -1);
  search_ = search;
  cert_ = 0;
  paving_.clear_boxes();
  bandb(paving_, certainties, varbox_.box());
  paving_.set_varbox(varbox_);
  paving_.set_type(search_);
}
Esempio n. 15
0
domino::SubsetFilter* ExampleSubsetFilterTable::get_subset_filter(
    const domino::Subset& cur_subset,
    const domino::Subsets& prior_subsets) const {
  IMP_OBJECT_LOG;
  Ints its = get_indexes(cur_subset, prior_subsets);
  if (its.size() != ps_.size()) {
    // either the subset doesn't contain the needed particles or the prior does
    return nullptr;
  } else {
    IMP_NEW(ExampleSubsetFilter, ret, (its, max_diff_));
    // remember to release
    return ret.release();
  }
}
em::DensityMap* remove_background(em::DensityMap *dmap,
                                  float threshold,float edge_threshold) {
  DensitySegmentationByCommunities ds(dmap,threshold);
  ds.build_density_graph(edge_threshold);
  IntsList cc_inds=ds.calculate_connected_components();
  //get the largest cc:
  Ints sizes;
  int max_ind=0;
  for(int i=0;i<(int)cc_inds.size();i++) {
    sizes.push_back(cc_inds[i].size());
    if (i>1){if (sizes[i]>sizes[max_ind]) max_ind=i;}
  }
  return get_segment_by_indexes(dmap,cc_inds[max_ind]);
}
Esempio n. 17
0
void NeuNetUI::selectedNets(Ints & netIds) const {
    netIds.clear();

    for (QTableWidgetItem *item : ui->nets->selectedItems())
        if (item && tuteNow.contains(item->row()))
            throw AlreadyTute();

    for (QTableWidgetItem *item : ui->nets->selectedItems()) {
        if (item && item->column() == 0) {
            int index = item->row();
            netIds.append(index);
        }
        item->setSelected(false);
    }
}
Esempio n. 18
0
void KMCentersTree::get_assignments(Ints &close_center)
{
  IMP_LOG(VERBOSE,"KMCentersTree::get_assignments for "
  << centers_->get_number_of_centers() << " centers "<<std::endl);
  close_center.clear();
  Ints candidate_centers;
  for (int j = 0; j < centers_->get_number_of_centers(); j++) {
    candidate_centers.push_back(j);
  }
  close_center.clear();
  for(int i=0;i<data_points_->get_number_of_points();i++) {
    close_center.push_back(0);
  }
  root_->get_assignments(candidate_centers,close_center);
}
Esempio n. 19
0
bool PymolWriter::handle_polygon(PolygonGeometry *g, Color color,
                                 std::string name) {
  setup(name, TRIANGLES);
  if (!open_type_) {
    get_stream() << "BEGIN, TRIANGLES, ";
    open_type_ = TRIANGLES;
  }
  Ints tris = internal::get_triangles(g);
  algebra::Vector3Ds normals = internal::get_normals(tris, g->get_geometry());
  for (unsigned int i = 0; i < tris.size() / 3; ++i) {
    write_triangle(tris.begin() + 3 * i, tris.begin() + 3 * i + 3,
                   g->get_geometry(), normals, color, get_stream());
  }
  return true;
}
Esempio n. 20
0
IntPairs Fragment::get_residue_index_ranges() const {
  if (!get_model()->get_has_attribute(get_begins_key(), get_particle_index())) {
    return IntPairs();
  }
  Ints begins =
      get_model()->get_attribute(get_begins_key(), get_particle_index());
  Ints ends = get_model()->get_attribute(get_ends_key(), get_particle_index());
  IMP_INTERNAL_CHECK(begins.size() == ends.size(),
                     "The fragment residues are corrupted.");
  IntPairs ret(begins.size());
  for (unsigned int i = 0; i < ret.size(); ++i) {
    ret[i] = IntPair(begins[i], ends[i]);
  }
  return ret;
}
Esempio n. 21
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;
  }
}
Esempio n. 22
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;
}
Esempio n. 23
0
void AnchorsData::set_secondary_structure_probabilities(
    const Particles &ssres_ps, const Ints &indices) {

  IMP_USAGE_CHECK(secondary_structure_ps_.size() == points_.size(),
                  "Secondary structure has not been set up, "
                  "run AnchorsData::setup_secondary_structure() first");
  int anum;
  for (int ssnum = 0; ssnum < (int)ssres_ps.size(); ssnum++) {
    IMP_USAGE_CHECK(
        atom::SecondaryStructureResidue::get_is_setup(ssres_ps[ssnum]),
        "SSE Particles must be decorated as"
        "SecondaryStructureResidues");
    if (indices.size() == 0)
      anum = ssnum;
    else
      anum = indices[ssnum];
    atom::SecondaryStructureResidue(secondary_structure_ps_[anum])
        .set_prob_helix(
             atom::SecondaryStructureResidue(ssres_ps[ssnum]).get_prob_helix());
    atom::SecondaryStructureResidue(secondary_structure_ps_[anum])
        .set_prob_strand(atom::SecondaryStructureResidue(ssres_ps[ssnum])
                             .get_prob_strand());
    atom::SecondaryStructureResidue(secondary_structure_ps_[anum])
        .set_prob_coil(
             atom::SecondaryStructureResidue(ssres_ps[ssnum]).get_prob_coil());
  }
}
Esempio n. 24
0
File: knn.cpp Progetto: 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;
  }
}
Esempio n. 25
0
void KMCentersNodeSplit::get_neighbors(const Ints &cands, KMPointArray *sums,
                                       KMPoint *sum_sqs, Ints *weights) {
  if (cands.size() == 1) {
    IMP_LOG_VERBOSE("KMCentersNodeSplit::get_neighbors the data points are"
                    << " associated to center : " << cands[0] << std::endl);
    // post points as neighbors
    post_neighbor(sums, sum_sqs, weights, cands[0]);
  }
      // get cloest candidate to the box represented by the node
      else {
    Ints new_cands;
    IMP_LOG_VERBOSE(
        "KMCentersNodeSplit::get_neighbors compute close centers for node:\n");
    IMP_LOG_WRITE(VERBOSE, show(IMP_STREAM));
    compute_close_centers(cands, &new_cands);
    for (unsigned int i = 0; i < new_cands.size(); i++) {
      IMP_LOG_VERBOSE(new_cands[i] << "  | ");
    }
    IMP_LOG_VERBOSE("\nKMCentersNodeSplit::get_neighbors call left child with "
                    << new_cands.size() << " candidates\n");
    children_[0]->get_neighbors(new_cands, sums, sum_sqs, weights);
    IMP_LOG_VERBOSE("KMCentersNodeSplit::get_neighbors call right child with "
                    << new_cands.size() << " candidates\n");
    children_[1]->get_neighbors(new_cands, sums, sum_sqs, weights);
  }
}
Esempio n. 26
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;
}
TEST(qpsContainerModel, vectorPtrData)
{
    using Ints = qps::ContainerModel< QVector, int >;
    Ints ints;
    ints.append( 42 );
    ints.append( 43 );
    ints.append( 44 );
    QVariant v = ints.data( ints.index( 0 ) );
    EXPECT_EQ( v.toString(), "42" );

    using QObjects = qps::ContainerModel< QVector, QObject* >;
    QObjects objects;
    QObject* o = new QObject();
    objects.append( o );
    EXPECT_EQ( objects.data( objects.index( 0 ), QObjects::ItemRole ), QVariant::fromValue<QObject*>( o ) );
    //EXPECT_EQ( objects.data( objects.index( 0 ) ), QVariant( "Item #0" ) );
}
Esempio n. 28
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;
}
PartitionalClustering *
RecursivePartitionalClusteringMetric::create_full_clustering(
    PartitionalClustering *center_cluster) {
  IMP::base::Vector<Ints> clusters(center_cluster->get_number_of_clusters());
  Ints reps(clusters.size());
  for (unsigned int i = 0; i < clusters.size(); ++i) {
    Ints outer = center_cluster->get_cluster(i);
    reps[i] = clustering_->get_cluster_representative(
        center_cluster->get_cluster_representative(i));
    for (unsigned int j = 0; j < outer.size(); ++j) {
      Ints inner = clustering_->get_cluster(outer[j]);
      clusters[i].insert(clusters[i].end(), inner.begin(), inner.end());
    }
  }
  IMP_NEW(internal::TrivialPartitionalClustering, ret, (clusters, reps));
  validate_partitional_clustering(ret, metric_->get_number_of_items());
  return ret.release();
}
Esempio n. 30
0
Hierarchy create_protein(Model *m, std::string name, double resolution,
                         const Ints db) {
  Hierarchy root = Hierarchy::setup_particle(new Particle(m));
  Domain::setup_particle(root, IntRange(db.front(), db.back()));
  for (unsigned int i = 1; i < db.size(); ++i) {
    std::ostringstream oss;
    oss << name << "-" << i - 1;
    Hierarchy cur = create_protein(
        m, oss.str(), resolution, db[i] - db[i - 1], db[i - 1],
        atom::get_volume_from_mass(
            atom::get_mass_from_number_of_residues(db[i] - db[i - 1])),
        false);
    root.add_child(cur);
  }
  Molecule::setup_particle(root);
  root->set_name(name);
  return root;
}