00001 #ifndef CCTBX_GEOMETRY_RESTRAINTS_PROXY_SELECT_H
00002 #define CCTBX_GEOMETRY_RESTRAINTS_PROXY_SELECT_H
00003
00004 #include <scitbx/array_family/shared.h>
00005 #include <scitbx/array_family/selections.h>
00006
00007 namespace cctbx { namespace geometry_restraints {
00008
00012 template <typename ProxyType>
00013 af::shared<ProxyType>
00014 shared_proxy_select(
00015 af::const_ref<ProxyType> const& self,
00016 std::size_t n_seq,
00017 af::const_ref<std::size_t> const& iselection)
00018 {
00019 af::shared<ProxyType> result;
00020 af::shared<std::size_t>
00021 reindexing_array = scitbx::af::reindexing_array(n_seq, iselection);
00022 af::const_ref<std::size_t>
00023 reindexing_array_ref = reindexing_array.const_ref();
00024 for(std::size_t i_proxy=0;i_proxy<self.size();i_proxy++) {
00025 ProxyType const& p = self[i_proxy];
00026 typename ProxyType::i_seqs_type new_i_seqs;
00027 bool is_valid = true;
00028 for(unsigned i=0;i<p.i_seqs.size();i++) {
00029 unsigned i_seq = p.i_seqs[i];
00030 CCTBX_ASSERT(i_seq < n_seq);
00031 new_i_seqs[i] = static_cast<unsigned>(reindexing_array[i_seq]);
00032 if (new_i_seqs[i] == n_seq) {
00033 is_valid = false;
00034 break;
00035 }
00036 }
00037 if (is_valid) {
00038 result.push_back(ProxyType(new_i_seqs, p));
00039 }
00040 }
00041 return result;
00042 }
00043
00047 template <typename ProxyType>
00048 af::shared<ProxyType>
00049 shared_planarity_proxy_select(
00050 af::const_ref<ProxyType> const& self,
00051 std::size_t n_seq,
00052 af::const_ref<std::size_t> const& iselection)
00053 {
00054 af::shared<ProxyType> result;
00055 af::shared<std::size_t>
00056 reindexing_array = scitbx::af::reindexing_array(n_seq, iselection);
00057 af::const_ref<std::size_t>
00058 reindexing_array_ref = reindexing_array.const_ref();
00059 for(std::size_t i_proxy=0;i_proxy<self.size();i_proxy++) {
00060 ProxyType const& p = self[i_proxy];
00061 af::const_ref<typename ProxyType::i_seqs_type::value_type>
00062 i_seqs = p.i_seqs.const_ref();
00063 af::const_ref<double>
00064 weights = p.weights.const_ref();
00065 af::shared<typename ProxyType::i_seqs_type::value_type> new_i_seqs;
00066 af::shared<double> new_weights;
00067 for(std::size_t i=0;i<i_seqs.size();i++) {
00068 std::size_t i_seq = i_seqs[i];
00069 CCTBX_ASSERT(i_seq < n_seq);
00070 std::size_t new_i_seq = reindexing_array_ref[i_seq];
00071 if (new_i_seq != n_seq) {
00072 new_i_seqs.push_back(new_i_seq);
00073 new_weights.push_back(weights[i]);
00074 }
00075 }
00076 if (new_i_seqs.size() > 3) {
00077 result.push_back(ProxyType(new_i_seqs, new_weights));
00078 }
00079 }
00080 return result;
00081 }
00082
00083 template <typename ProxyType>
00084 af::shared<ProxyType>
00085 shared_proxy_remove(
00086 af::const_ref<ProxyType> const& self,
00087 af::const_ref<bool> const& selection)
00088 {
00089 af::shared<ProxyType> result;
00090 for(std::size_t i_proxy=0;i_proxy<self.size();i_proxy++) {
00091 ProxyType const& p = self[i_proxy];
00092 af::const_ref<typename ProxyType::i_seqs_type::value_type>
00093 i_seqs = p.i_seqs.const_ref();
00094 for(unsigned i=0;i<i_seqs.size();i++) {
00095 unsigned i_seq = i_seqs[i];
00096 CCTBX_ASSERT(i_seq < selection.size());
00097 if (!selection[i_seq]) {
00098 result.push_back(p);
00099 break;
00100 }
00101 }
00102 }
00103 return result;
00104 }
00105
00106 }}
00107
00108 #endif // CCTBX_GEOMETRY_RESTRAINTS_PROXY_SELECT_H