Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DiversifyCrmsdByClustering.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/frag_picker/CompositeFragmentSelector.cc
11 /// @brief provides a selector that picks fragments diferent enough from the fragments that have been already picked
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
15 
16 // package headers
19 #include <core/pose/Pose.hh>
20 
21 #include <core/id/NamedAtomID.hh>
22 #include <numeric/model_quality/rms.hh>
23 #include <basic/Tracer.hh>
24 
25 // Clustering stuff
26 #include <numeric/ClusteringTreeNode.hh>
27 #include <numeric/agglomerative_hierarchical_clustering.hh>
28 
29 #include <utility/vector1.hh>
30 
31 namespace protocols {
32 namespace frag_picker {
33 
34 using namespace core;
35 
36 static basic::Tracer trDiversifyCrmsdByClustering(
37  "protocols.frag_picker.DiversifyCrmsdByClustering");
38 
40 
41  pose::PoseOP pose = src->get_chunk()->get_pose();
42  Size len = src->get_length();
43  Size offset = src->get_first_index_in_vall() - 1;
44  for (core::Size i = 1; i <= len; i++) {
45  id::NamedAtomID idCA("CA", i+offset);
46  PointPosition const& xyz = pose->xyz(idCA);
47  for (core::Size d = 1; d <= 3; ++d) {
48  dst(d, i) = xyz[d - 1];
49  }
50  }
51 }
52 
53 
54 /// @brief Selects desired number of fragments from a given set of candidates
56  ScoredCandidatesVector1 const& in,
58 {
59  if(in.size()==0) return;
60 
61  //-------------- Size of fragments
62  Size len = in[1].first->get_length();
63  trDiversifyCrmsdByClustering.Debug << "Diversifying fragments of size "<<len<<" #(in) = "<<in.size()<<std::endl;
64  //-------------- Resize container for xyz data
65  if(in.size() > xyz_.size()) {
66  trDiversifyCrmsdByClustering.Trace << "Reallocated: to "<<xyz_.size()<<std::endl;
67  xyz_.resize(in.size());
68  }
69  //-------------- Resize each xyz vector to match fragments' size
70  for(Size i=1;i<=in.size();i++) {
71  if((Size)xyz_[i].size2() != len) {
72  xyz_[i].redimension(3,len,0.0);
73  }
74  }
75  //-------------- Copy xyz coordinates, setup ids
77  for(Size i=1;i<=in.size();i++) {
78  copy_coordinates(in[i].first,xyz_[i]);
79  ids.push_back(i);
80  }
81 
82  //-------------- Prepare distance matrix
83  utility::vector1< utility::vector1<Real> > distances(in.size());
84  for(Size i=1;i<=in.size();i++)
85  distances[i].resize( in.size() );
86 
87  for(Size i=2;i<=in.size();i++) {
88  for(Size j=2;j<=in.size();j++) {
89  Real val = numeric::model_quality::rms_wrapper(len,xyz_[i],xyz_[j]);
90  distances[ i ][ j ] = val;
91  distances[ j ][ i ] = val;
92  }
93  distances[i][i] = 0.0;
94  }
95  utility::vector1<numeric::ClusteringTreeNodeOP> roots = numeric::average_link_clustering(distances,frags_per_pos());
96 
97  //----------- Retrieve clusters
98  for(Size i=1;i<=frags_per_pos();i++) {
99  utility::vector1<Size> ids_out;
100  numeric::get_cluster_data(ids,roots[i],ids_out);
101  out.push_back( in[ ids_out[1] ] );
102  trDiversifyCrmsdByClustering.Debug << "Fragment "<<i<<" cluster stats: dist="<<roots[i]->distance()
103  <<" size="<<roots[i]->size()<<std::endl;
104  }
105 
106  trDiversifyCrmsdByClustering.Trace<<out.size()<<" fragments passed through DiversifyCrmsdByClustering at query position "
107  << in[1].first->get_first_index_in_query()<<std::endl;
108 }
109 
110 } // frag_picker
111 } // protocols