Clipper
fftmap.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_FFTMAP
46 #define CLIPPER_FFTMAP
47 
48 
49 #include "coords.h"
50 
51 #include <complex>
52 
53 
54 namespace clipper
55 {
56  // fft type
57  typedef float ffttype;
58 
59  // forward definition
60  namespace datatypes {
61  template<class T> class F_phi;
62  }
63 
64  // base class for FFT classes
65  class FFTmap_base {
66  public:
67  enum FFTtype { Default, Measure, Estimate };
68  protected:
69  static Mutex mutex;
70  };
71 
73 
80  class FFTmap_p1 : public FFTmap_base
81  {
82  public:
84  FFTmap_p1();
86  FFTmap_p1( const FFTmap_p1& other ) { copy(other); }
88  FFTmap_p1( const Grid_sampling& grid_sam, const FFTtype type = Default );
90  const FFTmap_p1& operator =(const FFTmap_p1& other) { return copy(other); }
92  void init( const Grid_sampling& grid_sam, const FFTtype type = Default );
94  void reset();
95 
97  const Grid_sampling& grid_real() const { return grid_sam_; }
99  const Grid& grid_reci() const { return grid_reci_; }
101  bool uniq_reci( const Coord_grid& c ) const { return ( (c.w()>0 && c.w()<grid_half_.nw()) || (c.w()<=grid_half_.nw() && ( (c.v()>0 && c.v()<grid_half_.nv()) || (c.v()<=grid_half_.nv() && c.u()<=grid_half_.nu()) ) ) ); }
102 
104  void fft_h_to_x( const ftype& scale );
106  void fft_x_to_h( const ftype& scale );
107 
109  std::complex<ffttype> get_hkl( const HKL& hkl ) const;
111  void set_hkl( const HKL& hkl, const std::complex<ffttype>& f );
113  const std::complex<ffttype>& cplx_data( const Coord_grid& c ) const
114  { return data_c[ grid_reci_.index( c ) ]; }
116  std::complex<ffttype>& cplx_data( const Coord_grid& c )
117  { return data_c[ grid_reci_.index( c ) ]; }
119  const ffttype& real_data( const Coord_grid& c ) const
120  { return data_r[ grid_real_.index( c ) ]; }
122  ffttype& real_data( const Coord_grid& c )
123  { return data_r[ grid_real_.index( c ) ]; }
124 
126  static FFTtype& default_type() { return default_type_; }
127 
128  void debug() const;
129 
130  protected:
131  const FFTmap_p1& copy( const FFTmap_p1& other );
132 
133  enum FFTmode { NONE, RECI, REAL, OTHER };
134 
135  FFTmode mode;
136  FFTtype type_;
141 
143  std::vector<char> req_l, req_u;
144 
145  std::vector<ffttype> datavec;
146  ffttype* data_r;
147  std::complex<ffttype>* data_c;
148 
149  static FFTtype default_type_;
150  };
151 
152 
154 
165  class FFTmap : private FFTmap_p1
166  {
167  public:
169  FFTmap();
171  FFTmap( const Spacegroup& spacegroup, const Cell& cell, const Grid_sampling grid_sam, const FFTtype type = Default );
173  void init( const Spacegroup& spacegroup, const Cell& cell, const Grid_sampling grid_sam, const FFTtype type = Default );
175  void reset();
176 
178  const Cell& cell() const { return cell_; }
180  const Spacegroup& spacegroup() const { return spacegroup_; }
182  const Grid_sampling& grid_sampling() const { return FFTmap_p1::grid_real(); }
184  void fft_h_to_x();
186  void fft_x_to_h();
187 
189  template<class T> void get_recip_data( const HKL& rfl, datatypes::F_phi<T>& fphi ) const;
191  template<class T> void set_recip_data( const HKL& rfl, const datatypes::F_phi<T>& fphi );
192 
194  template<class T> void get_real_data( const Coord_grid& c, T& datum ) const;
196  template<class T> void set_real_data( const Coord_grid& c, const T& datum );
197 
199  datatypes::F_phi<ffttype> get_recip_data( const HKL& rfl ) const;
201  const ffttype& get_real_data( const Coord_grid& c ) const
202  { return real_data(c.unit(grid_real())); }
203 
205  template<class H, class X> void fft_rfl_to_map( const H& h, X& x );
207  template<class H, class X> void fft_map_to_rfl( const X& x, H& h );
208 
209  void debug() const;
210 
211  protected:
214  std::vector<Isymop> isymop;
215  };
216 
217 
218  // template implementations
219 
220 
232  template<class H, class X> void FFTmap::fft_rfl_to_map( const H& h, X& x )
233  {
234  // zero the map
235  reset();
236 
237  // copy from reflection data
238  typename H::HKL_reference_index ih;
239  for ( ih = h.first_data(); !ih.last(); h.next_data( ih ) )
240  set_recip_data( ih.hkl(), h[ih] );
241 
242  // fft
243  fft_h_to_x();
244 
245  // and copy into the map
246  typename X::Map_reference_index ix;
247  for ( ix = x.first(); !ix.last(); ix.next() )
248  get_real_data( ix.coord(), x[ix] );
249  }
250 
251 
264  template<class H, class X> void FFTmap::fft_map_to_rfl( const X& x, H& h )
265  {
266  // zero the map
267  reset();
268 
269  // copy into the map
270  typename X::Map_reference_index ix;
271  for ( ix = x.first(); !ix.last(); ix.next() )
272  set_real_data( ix.coord(), x[ix] );
273 
274  // fft
275  fft_x_to_h();
276 
277  // now fill it
278  typename H::HKL_reference_index ih;
279  for ( ih = h.first(); !ih.last(); ih.next() )
280  get_recip_data( ih.hkl(), h[ih] );
281  }
282 
283 
284 } // namespace clipper
285 
286 #endif
std::complex< ffttype > get_hkl(const HKL &hkl) const
get reciprocal space data: slow form with hemisphere check
Definition: fftmap.cpp:213
void init(const Spacegroup &spacegroup, const Cell &cell, const Grid_sampling grid_sam, const FFTtype type=Default)
initialiser
Definition: fftmap.cpp:309
void reset()
Reset.
Definition: fftmap.cpp:322
const FFTmap_p1 & operator=(const FFTmap_p1 &other)
Assignment operator.
Definition: fftmap.h:90
void set_hkl(const HKL &hkl, const std::complex< ffttype > &f)
set reciprocal space data: slow form with hemisphere check
Definition: fftmap.cpp:229
FFTmap: P1 map with symmetry used for calculating FFTs.
Definition: fftmap.h:165
void fft_x_to_h()
Transform to reciprocal space.
Definition: fftmap.cpp:343
const int & u() const
get u
Definition: coords.h:248
const int & nv() const
get nv
Definition: coords.h:486
FFTmap()
Null constructor.
Definition: fftmap.cpp:277
void fft_h_to_x(const ftype &scale)
Transform to real space.
Definition: fftmap.cpp:149
const Cell & cell() const
get the cell
Definition: fftmap.h:178
void set_real_data(const Coord_grid &c, const T &datum)
set real space data
Definition: fftmap.cpp:397
static Mutex mutex
Thread safety.
Definition: fftmap.h:69
static FFTtype & default_type()
set/get default optimisation type
Definition: fftmap.h:126
Spacegroup spacegroup_
spacegroup
Definition: fftmap.h:213
Grid coordinate.
Definition: coords.h:236
Definition: fftmap.h:65
const ffttype & real_data(const Coord_grid &c) const
get real space data
Definition: fftmap.h:119
void fft_x_to_h(const ftype &scale)
Transform to reciprocal space.
Definition: fftmap.cpp:181
FFTtype type_
optimisation options
Definition: fftmap.h:136
ffttype & real_data(const Coord_grid &c)
set real space data
Definition: fftmap.h:122
FFTmap_p1: low level P1 map used for calculating FFTs.
Definition: fftmap.h:80
ffttype * data_r
pointer to real data
Definition: fftmap.h:146
generic grid
Definition: coords.h:479
bool uniq_reci(const Coord_grid &c) const
Test whether a coordinate is in the valid part of the recip. grid.
Definition: fftmap.h:101
Grid_sampling grid_sam_
unit cell grid
Definition: fftmap.h:137
ftype64 ftype
ftype definition for floating point representation
Definition: clipper_precision.h:58
Cell object.
Definition: cell.h:121
Grid grid_real_
real space grid
Definition: fftmap.h:139
Spacegroup object.
Definition: spacegroup.h:172
void fft_rfl_to_map(const H &h, X &x)
calculate map-like object from reflection-like object
Definition: fftmap.h:232
Grid grid_reci_
reciprocal space grid
Definition: fftmap.h:138
Cell cell_
unit cell
Definition: fftmap.h:212
const Grid_sampling & grid_real() const
Return real space grid.
Definition: fftmap.h:97
const int & nu() const
get nu
Definition: coords.h:485
void fft_map_to_rfl(const X &x, H &h)
calculate reflection-like object from map-like object
Definition: fftmap.h:264
const Spacegroup & spacegroup() const
get the spacegroup
Definition: fftmap.h:180
int index(const Coord_grid &c) const
grid indexing operator
Definition: coords.h:494
const ffttype & get_real_data(const Coord_grid &c) const
get real space data (No error checking)
Definition: fftmap.h:201
Coord_grid unit(const Grid_sampling &g) const
reduce to unit box: (0..nu-1, 0..nv-1, 0..nw-1)
Definition: coords.h:744
FFTmap_p1(const FFTmap_p1 &other)
Copy constructor.
Definition: fftmap.h:86
void set_recip_data(const HKL &rfl, const datatypes::F_phi< T > &fphi)
set reciprocal space data
Definition: fftmap.cpp:365
const int & w() const
get w
Definition: coords.h:250
const int & nw() const
get nw
Definition: coords.h:487
void init(const Grid_sampling &grid_sam, const FFTtype type=Default)
initialiser: takes grid
Definition: fftmap.cpp:96
std::vector< ffttype > datavec
vector for the data
Definition: fftmap.h:145
void reset()
Reset.
Definition: fftmap.cpp:117
Mutex class: used for locking and unlocking shared resources.
Definition: clipper_thread.h:64
void fft_h_to_x()
Transform to real space.
Definition: fftmap.cpp:333
Grid sampling of a unit cell.
Definition: coords.h:515
Reflection data type: F + phi model or map coeff (e.g. Fcalc, Fbest)
Definition: fftmap.h:61
static FFTtype default_type_
default optimisation options
Definition: fftmap.h:149
std::vector< char > req_u
real section lookup
Definition: fftmap.h:143
std::complex< ffttype > * data_c
pointer to complex data
Definition: fftmap.h:147
const int & v() const
get v
Definition: coords.h:249
Matrix< char > req_uv
reci section lookup
Definition: fftmap.h:142
std::complex< ffttype > & cplx_data(const Coord_grid &c)
set reciprocal space data
Definition: fftmap.h:116
const std::complex< ffttype > & cplx_data(const Coord_grid &c) const
get reciprocal space data
Definition: fftmap.h:113
std::vector< Isymop > isymop
Integerised symops.
Definition: fftmap.h:214
const Grid_sampling & grid_sampling() const
get the cell grid
Definition: fftmap.h:182
const FFTmap_p1 & copy(const FFTmap_p1 &other)
copy function
Definition: fftmap.cpp:257
FFTmode mode
real or reciprocal space?
Definition: fftmap.h:135
const Grid & grid_reci() const
Return reciprocal space grid (i.e. half real grid + 1 section).
Definition: fftmap.h:99
void get_recip_data(const HKL &rfl, datatypes::F_phi< T > &fphi) const
get reciprocal space data
Definition: fftmap.cpp:354
reflection 'Miller' index
Definition: coords.h:145
void get_real_data(const Coord_grid &c, T &datum) const
get real space data
Definition: fftmap.cpp:387
FFTmap_p1()
Null constructor.
Definition: fftmap.cpp:72
Grid grid_half_
half grid (for marking unique)
Definition: fftmap.h:140