Clipper
hkl_info.h
1 
4 //C Copyright (C) 2000-2006 Kevin Cowtan and University of York
5 //L
6 //L This library is free software and is distributed under the terms
7 //L and conditions of version 2.1 of the GNU Lesser General Public
8 //L Licence (LGPL) with the following additional clause:
9 //L
10 //L `You may also combine or link a "work that uses the Library" to
11 //L produce a work containing portions of the Library, and distribute
12 //L that work under terms of your choice, provided that you give
13 //L prominent notice with each copy of the work that the specified
14 //L version of the Library is used in it, and that you include or
15 //L provide public access to the complete corresponding
16 //L machine-readable source code for the Library including whatever
17 //L changes were used in the work. (i.e. If you make changes to the
18 //L Library you must distribute those, but you do not need to
19 //L distribute source or object code to those portions of the work
20 //L not covered by this licence.)'
21 //L
22 //L Note that this clause grants an additional right and does not impose
23 //L any additional restriction, and so does not affect compatibility
24 //L with the GNU General Public Licence (GPL). If you wish to negotiate
25 //L other terms, please contact the maintainer.
26 //L
27 //L You can redistribute it and/or modify the library under the terms of
28 //L the GNU Lesser General Public License as published by the Free Software
29 //L Foundation; either version 2.1 of the License, or (at your option) any
30 //L later version.
31 //L
32 //L This library is distributed in the hope that it will be useful, but
33 //L WITHOUT ANY WARRANTY; without even the implied warranty of
34 //L MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 //L Lesser General Public License for more details.
36 //L
37 //L You should have received a copy of the CCP4 licence and/or GNU
38 //L Lesser General Public License along with this library; if not, write
39 //L to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
40 //L The GNU Lesser General Public can also be obtained by writing to the
41 //L Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
42 //L MA 02111-1307 USA
43 
44 
45 #ifndef CLIPPER_HKL_INFO
46 #define CLIPPER_HKL_INFO
47 
48 
49 #include "hkl_lookup.h"
50 
51 
52 namespace clipper
53 {
54  class HKL_data_base;
55 
56 
58 
62  class HKL_info
63  {
64  public:
66  HKL_info();
68  HKL_info( const Spacegroup& spacegroup, const Cell& cell, const Resolution& resolution, const bool& generate = false );
70  void init( const Spacegroup& spacegroup, const Cell& cell, const Resolution& resolution, const bool& generate = false );
72  void init( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling, const bool& generate = true );
73 
75  bool is_null() const;
76 
78  const Cell& cell() const { return cell_; }
80  const Spacegroup& spacegroup() const { return spacegroup_; }
82  const HKL_sampling& hkl_sampling() const { return hkl_sampling_; }
84  const Resolution& resolution() const { return resolution_; }
85 
87  void generate_hkl_list();
89  void add_hkl_list( const std::vector<HKL>& add );
90 
92  inline int num_reflections() const { return hkl.size(); }
93 
95 
96  inline const HKL& hkl_of( const int& index ) const { return hkl[index]; }
98 
100  inline int index_of( const HKL& rfl ) const
101  { return lookup.index_of( rfl ); }
102 
104  inline const ftype32& invresolsq( const int& index ) const
105  { return invresolsq_lookup[index]; }
107  inline const Range<ftype>& invresolsq_range() const
108  { return invresolsq_range_; }
110  const HKL_class& hkl_class( const int& index ) const
111  { return hkl_class_lookup[index]; }
113  HKL find_sym( const HKL& rfl, int& sym, bool& friedel ) const;
114 
115 
117 
122  {
123  public:
125  inline const HKL_info& base_hkl_info() const { return *hklinfo; }
127  inline const int& index() const { return index_; }
129  inline ftype invresolsq( const HKL_data_base& hkldata ) const;
131  inline ftype invresolsq() const
132  { return hklinfo->invresolsq( index_ ); }
134  inline bool last() const
135  { return ( index_ >= hklinfo->num_reflections() ); }
136  protected:
137  const HKL_info* hklinfo;
138  int index_;
139  };
140 
142 
152  {
153  public:
157  HKL_reference_index( const HKL_info& hklinfo_, const int& index )
158  { hklinfo = &hklinfo_; index_ = index; }
160  inline const HKL& hkl() const { return hklinfo->hkl_of( index_ ); }
162  inline const HKL_class& hkl_class() const
163  { return hklinfo->hkl_class( index_ ); }
165  inline HKL_reference_index& next() { index_++; return *this; }
166  // inherited functions listed for documentation purposes
167  //-- const HKL_info& base_hkl_info() const;
168  //-- const int& index() const;
169  //-- const ftype invresolsq() const;
170  //-- bool last() const;
171  };
172 
174 
184  {
185  public:
189  HKL_reference_coord( const HKL_info& hklinfo_, const HKL& hkl ) {
190  hklinfo = &hklinfo_;
191  hkl_ = hkl;
192  index_ = hklinfo->index_of( hklinfo->find_sym( hkl_, sym_, friedel_ ) );
193  if ( index_ < 0 ) Message::message( Message_fatal( "HKL_reference_coord: hkl not found" ) );
194  }
196  inline const HKL& hkl() const { return hkl_; }
198  inline const int& sym() const { return sym_; }
200  inline const bool& friedel() const { return friedel_; }
202 
205  inline HKL_reference_coord& set_hkl( const HKL& hkl__ ) {
206  hkl_ = hkl__;
207  HKL equiv = hkl__.transform(hklinfo->isymop[sym_]);
208  if ( friedel_ ) equiv = -equiv;
209  index_ = hklinfo->index_of( equiv );
210  if ( index_ < 0 ) index_ =
211  hklinfo->index_of( hklinfo->find_sym( hkl_, sym_, friedel_ ) );
212  return *this;
213  }
216  sym_ = 0; friedel_ = false;
217  index_++;
218  if ( !last() ) hkl_ = hklinfo->hkl_of( index_ );
219  return *this;
220  }
221  // increment h,k,l
222  inline HKL_reference_coord& next_h() { hkl_.h()++; set_hkl( hkl_ ); return *this; }
223  inline HKL_reference_coord& next_k() { hkl_.k()++; set_hkl( hkl_ ); return *this; }
224  inline HKL_reference_coord& next_l() { hkl_.l()++; set_hkl( hkl_ ); return *this; }
225  inline HKL_reference_coord& prev_h() { hkl_.h()--; set_hkl( hkl_ ); return *this; }
226  inline HKL_reference_coord& prev_k() { hkl_.k()--; set_hkl( hkl_ ); return *this; }
227  inline HKL_reference_coord& prev_l() { hkl_.l()--; set_hkl( hkl_ ); return *this; }
228  inline HKL_reference_coord& operator =( const HKL& hkl__ )
230  { return set_hkl( hkl__ ); }
231  // inherited functions listed for documentation purposes
232  //-- const HKL_info& base_hkl_info() const;
233  //-- const int& index() const;
234  //-- const ftype invresolsq() const;
235  //-- bool last() const;
236  protected:
237  HKL hkl_;
238  int sym_;
239  bool friedel_;
240  };
241 
243  HKL_reference_index first() const { return HKL_reference_index( *this, 0 ); }
244 
245  void debug() const;
246 
247  protected:
252  std::vector<Isymop> isymop;
253 
255  std::vector<HKL> hkl;
257  std::vector<HKL_class> hkl_class_lookup;
259  std::vector<ftype32> invresolsq_lookup;
260 
265 
266  // internal methods:
268  void update_hkl_list();
269 
270  friend class HKL_info::HKL_reference_base;
271  friend class HKL_info::HKL_reference_index;
272  friend class HKL_info::HKL_reference_coord;
273  };
274 
275 
276 } // namespace clipper
277 
278 #endif