File: range.h

package info (click to toggle)
cgal 3.6.1-2
  • links: PTS
  • area: non-free
  • in suites: squeeze
  • size: 62,184 kB
  • ctags: 95,782
  • sloc: cpp: 453,758; ansic: 96,821; sh: 226; makefile: 120; xml: 2
file content (225 lines) | stat: -rw-r--r-- 7,484 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* Copyright 2004
   Stanford University

   This file is part of the DSR PDB Library.

   The DSR PDB Library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation; either version 2.1 of the License, or (at your
   option) any later version.

   The DSR PDB Library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with the DSR PDB Library; see the file LICENSE.LGPL.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   MA 02110-1301, USA. */

#ifndef CGAL_DSR_PDB_RANGE_H
#define CGAL_DSR_PDB_RANGE_H
#include <CGAL/PDB/basic.h>
#include <CGAL/PDB/Point.h>
#include <CGAL/PDB/Chain.h>
#include <CGAL/PDB/Monomer.h>
#include <CGAL/PDB/Heterogen.h>
#include <CGAL/PDB/PDB.h>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/iterator/filter_iterator.hpp>
#include <boost/range.hpp>
#include <CGAL/PDB/internal/rangelib/filter.hpp>
#include <CGAL/PDB/internal/rangelib/transform.hpp>
#include <CGAL/PDB/internal/rangelib/algo.hpp>
#include <algorithm>


namespace CGAL { namespace PDB {

    using internal::rangelib::rng::for_each;
    using internal::rangelib::rng::copy;

//! boost changes from size to distance a 1.34, so use this
template <class Range>
unsigned int distance(const Range &r) {
  return std::distance(r.begin(), r.end());
}
    
#define CGAL_PDB_GET_MAP(ucname, lcname)                \
    template <class From>                               \
    struct Get_##lcname {                               \
      typedef ucname& result_type;                      \
      result_type operator()(From v) const {            \
        return v.lcname();                              \
      }                                                 \
    };                                                  \
    template <class From2>                               \
    struct Get_##lcname<const From2> {                   \
      typedef const ucname& result_type;                      \
      result_type operator()(From2 v) const {                 \
        return v.lcname();                              \
      }                                                 \
    };                                                  \

CGAL_PDB_GET_MAP(Atom, atom);
CGAL_PDB_GET_MAP(Monomer, monomer);
CGAL_PDB_GET_MAP(Chain, chain);
CGAL_PDB_GET_MAP(Model, model);
CGAL_PDB_GET_MAP(Heterogen, heterogen);

template <class A>
struct Get_point {
  typedef const Point & result_type;
  result_type operator()(A a) const {
    return a.point();
  }
};

template <class A>
struct Get_index {
  typedef Atom::Index result_type;
  result_type operator()(A a) const {
    return a.index();
  }
};

template <class A>
struct Get_key {
  typedef typename A::Key result_type;
  result_type operator()(const A& a) const {
    return a.key();
  }
};

#define CGAL_PDB_MAKE_RANGE(ucname, lcname)             \
    template <class Range>                                              \
    internal::rangelib::transformed_range<Range, Get_##lcname<typename std::iterator_traits<typename Range::iterator>::reference> > \
    make_##lcname##_range( Range r){                                   \
      return internal::rangelib::transformed(r, Get_##lcname<typename std::iterator_traits<typename Range::iterator>::reference>()); \
    }                                                                   \

    
    /**
    template <class Range>                                              \
    internal::rangelib::transformed_range<Range, Get_##lcname<const typename Range::iterator::reference> > \
    make_##lcname##_range(const Range& r){                                    \
      return internal::rangelib::transformed(r, Get_##lcname<const typename Range::iterator::reference>()); \
    }                                                                   \

     */
CGAL_PDB_MAKE_RANGE(Atom, atom);
CGAL_PDB_MAKE_RANGE(Monomer, monomer);
CGAL_PDB_MAKE_RANGE(Chain, chain);
CGAL_PDB_MAKE_RANGE(Model, model);
CGAL_PDB_MAKE_RANGE(Heterogen, heterogen);
CGAL_PDB_MAKE_RANGE(Point, point);
CGAL_PDB_MAKE_RANGE(Index, index);
CGAL_PDB_MAKE_RANGE(Key, key);


struct Get_bond_indices {
  typedef std::pair<unsigned int,unsigned int> result_type;
  template <class B>
  const result_type& operator()(const B & b) const {
    static result_type ret;
    //Chain::Monomer_iterator ma= b.first.first;
    //Monomer::Atom_label la= b.first.second;

    ret= std::make_pair(b.first.atom().index().index(),
			b.second.atom().index().index());
    return ret;
  }
    
};


//! Return an iterator range which returns a pair of indices for a bond
template <class Range>
internal::rangelib::transformed_range<Range, Get_bond_indices>
make_bond_indices_range(Range r){
  return internal::rangelib::transformed(r,Get_bond_indices());
}


//! Return true if an atom is a backbone atoms.
struct Is_backbone {
  typedef bool result_type;
  template <class A>
  bool operator()(const A &a) {
    return static_cast<Monomer::Atom_key>(a.key()) == Monomer::AL_C 
      || static_cast<Monomer::Atom_key>(a.key()) == Monomer::AL_CA 
      || static_cast<Monomer::Atom_key>(a.key()) == Monomer::AL_N;
  }
};


//! Return an iterator range which returns skips non-backbone atoms
template <class Range>
internal::rangelib::filtered_range<Range, Is_backbone>
make_backbone_range(Range r){
  return internal::rangelib::filtered(r, Is_backbone());
}

//! Return true if an atom is a AC.
struct Is_CA {
  typedef bool result_type;
  template <class A>
  bool operator()(const A &a) {
    return static_cast<Monomer::Atom_key>(a.key()) == Monomer::AL_CA;
  }
};

//! Return an iterator range which returns skips non-backbone atoms
template <class Range>
internal::rangelib::filtered_range<Range, Is_CA>
make_ca_range(Range r){
  return internal::rangelib::filtered(r, Is_CA());
}


template <class OK_atom>
struct Is_ok_bond {
  typedef bool result_type;
  Is_ok_bond(OK_atom ao): ao_(ao){}

  struct Atom_pair{
    Monomer::Atom_key k_;
    const Atom *a_;
    Atom_pair(Monomer::Atom_key k, const Atom *a): k_(k), a_(a){}
    const Atom& atom() const {return a_;}
    Monomer::Atom_key key() const {return k_;}
  };

  template <class B>
  bool operator()(const B &b) {
    Monomer::Atom_key ka= static_cast<Monomer::Atom_key>(b.first.key());
    Monomer::Atom_key kb= static_cast<Monomer::Atom_key>(b.second.key());
    const Atom *pa =&b.first.atom();
    const Atom *pb =&b.second.atom();
    if ( ao_(Atom_pair(ka, pa)) && ao_(Atom_pair(kb, pb))) {
      return true;
    } else {
      /*std::cout << "Rejected " << ka << "(" << pa << ") to " << kb 
	<< "(" << pb << ")" << std::endl;*/
      return false;
    }
  }
  OK_atom ao_;
};

//! Return an iterator range which returns skips non-backbone atoms
    template <class Range, class OKA>
internal::rangelib::filtered_range<Range, Is_ok_bond<OKA> >
make_filtered_bond_range(OKA oka, Range r){
  return internal::rangelib::filtered(r, Is_ok_bond<OKA>(oka));
}



/*! \example extracting_geometry.cpp
  This example shows how to use the various iterator adaptors for extracting geometry and connectivity.
 */

}}
#endif