Clipper
hkl_data.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_DATA
46 #define CLIPPER_HKL_DATA
47 
48 
49 #include "hkl_info.h"
50 
51 
52 namespace clipper
53 {
54 
55  class HKL_data_cacheobj : public HKL_info
56  {
57  public:
58  class Key
59  {
60  public:
61  Key( const Spgr_descr& spgr_descr, const Cell& cell_descr, const HKL_sampling& hkl_sam ) : spgr_descr_(spgr_descr), cell_descr_(cell_descr), hkl_sampling_(hkl_sam) {}
62  const Spgr_descr& spgr_descr() const { return spgr_descr_; }
63  const Cell_descr& cell_descr() const { return cell_descr_; }
64  const HKL_sampling& hkl_sampling() const { return hkl_sampling_; }
65  private:
66  Spgr_descr spgr_descr_;
67  Cell_descr cell_descr_;
68  HKL_sampling hkl_sampling_;
69  };
70 
71  HKL_data_cacheobj( const Key& hkl_data_cachekey );
72  bool matches( const Key& hkl_data_cachekey ) const;
73  String format() const;
74  static Mutex mutex;
75  private:
76  Key key;
77  };
78 
79 
81 
104  {
105  protected:
107  //-- Datatype_base();
109  void set_null();
111  static String type();
113  void friedel();
115  void shift_phase(const ftype& dphi);
117  bool missing() const;
119  static int data_size();
121  static String data_names();
123  void data_export( xtype array[] ) const;
125  void data_import( const xtype array[] );
126  };
127 
128 
130 
137  {
138  public:
139  // Coordinate reference types
144 
146  virtual void init( const HKL_info& hkl_info, const Cell& cell );
148  virtual void init( const HKL_data_base& hkl_data );
150  virtual void init( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling );
151 
152  // generic methods
154  bool is_null() const;
155 
157  const HKL_info& base_hkl_info() const { return *parent_hkl_info; }
159  const Cell& base_cell() const { return *parent_cell; }
160 
162  const Spacegroup& spacegroup() const { return spacegroup_; }
164  const Cell& cell() const { return cell_; }
166  const Resolution& resolution() const { return resolution_; }
168  const HKL_sampling& hkl_sampling() const { return hkl_sampling_; }
170  const HKL_info& hkl_info() const { return *parent_hkl_info; }
171 
173  ftype invresolsq( const int& index ) const;
177  int num_obs() const;
178 
180  virtual void update() = 0;
182  virtual String type() const = 0;
184  virtual bool missing(const int& index) const = 0;
186  virtual void set_null(const int& index) = 0;
188  virtual int data_size() const = 0;
190  virtual String data_names() const = 0;
192  virtual void data_export( const HKL& hkl, xtype array[] ) const = 0;
194  virtual void data_import( const HKL& hkl, const xtype array[] ) = 0;
196  virtual void mask(const HKL_data_base& mask) = 0;
197 
199  HKL_reference_index first() const;
201  HKL_reference_index first_data() const;
203  HKL_reference_index& next_data( HKL_reference_index& ih ) const;
204 
205  void debug() const;
206 
207  protected:
208  const HKL_info* parent_hkl_info;
209  const Cell* parent_cell;
210  bool cell_matches_parent;
211 
212  // clipper2 members
214  Spacegroup spacegroup_;
215  Cell cell_;
216  HKL_sampling hkl_sampling_;
217  Resolution resolution_;
218 
220  HKL_data_base();
222  virtual ~HKL_data_base() {}
223  };
224 
225 
227 
234  template<class T> class HKL_data : public HKL_data_base
235  {
236  public:
238  HKL_data() {}
240  explicit HKL_data( const HKL_info& hkl_info );
242  HKL_data( const HKL_info& hkl_info, const Cell& cell );
244  HKL_data( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling );
246  explicit HKL_data( const HKL_data_base& hkl_data );
247 
249  void init( const HKL_info& hkl_info, const Cell& cell );
251  void init( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling );
253  void init( const HKL_data_base& hkl_data );
255  void update();
256 
257  // type specific methods
258  String type() const { return T::type(); }
259  bool missing(const int& index) const { return list[index].missing(); }
260  void set_null(const int& index) { list[index].set_null(); }
261  int data_size() const { return T::data_size(); }
262  String data_names() const { return T::data_names(); }
263  void data_export( const HKL& hkl, xtype array[] ) const
264  { T datum; get_data( hkl, datum ); datum.data_export( array ); }
265  void data_import( const HKL& hkl, const xtype array[] )
266  { T datum; datum.data_import( array ); set_data( hkl, datum ); }
267  void mask(const HKL_data_base& mask);
268 
269  // data access methods: by HKL_reference_index
272  { return list[i.index()]; }
275  { return list[i.index()]; }
276 
277  // data access methods: by HKL_reference_coord
279  T operator[] (const HKL_info::HKL_reference_coord& ih) const;
281  bool get_data(const HKL_info::HKL_reference_coord& ih, T& data) const;
283  bool set_data(const HKL_info::HKL_reference_coord& ih, const T& data);
284 
285  // data access methods: by index
287  const T& operator[] (const int& index) const { return list[index]; }
289  T& operator[] (const int& index) { return list[index]; }
290 
291  // data access methods: by hkl
293  T operator[] (const HKL& hkl) const;
295  bool get_data(const HKL& hkl, T& data) const;
297  bool set_data(const HKL& hkl, const T& data);
298 
299  // COMPUTATION OPERATORS
301  template<class C> void compute( const C& op )
302  { for (HKL_info::HKL_reference_index ih=parent_hkl_info->first(); !ih.last(); ih.next()) list[ih.index()] = op( ih ); }
304  template<class S, class C> void compute( const HKL_data<S>& src, const C& op )
305  { for (HKL_info::HKL_reference_index ih=parent_hkl_info->first(); !ih.last(); ih.next()) list[ih.index()] = op( ih, src[ih] ); }
307  template<class S1, class S2, class C> void compute( const HKL_data<S1>& src1, const HKL_data<S2>& src2, const C& op )
308  { for (HKL_info::HKL_reference_index ih=parent_hkl_info->first(); !ih.last(); ih.next()) list[ih.index()] = op( ih, src1[ih], src2[ih] ); }
309 
310  // inherited functions lists for documentation purposes
311  //-- const HKL_info& base_hkl_info() const;
312  //-- const Cell& base_cell() const;
313  //-- const ftype invresolsq(const int& index) const;
314  //-- const Range<ftype> invresolsq_range() const;
315  //-- const int num_obs() const;
316  //-- HKL_reference_index first() const;
317  //-- HKL_reference_index first_data() const;
318  //-- HKL_reference_index& next_data( HKL_reference_index& ih ) const;
319 
321  HKL_data<T>& operator =( const HKL_data<T>& other );
323  HKL_data<T>& operator =( const T& value );
324 
325  void debug() const;
326 
327  protected:
328  // members
329  std::vector<T> list;
330  };
331 
332 
333 
334 
335 
336 
337 
338  // Template implementations
339 
341  { return hkldata.invresolsq( index_ ); }
342 
345  template<class T> HKL_data<T>::HKL_data( const HKL_info& hkl_info )
346  {
347  init( hkl_info, hkl_info.cell() );
348  }
349 
353  template<class T> HKL_data<T>::HKL_data( const HKL_info& hkl_info, const Cell& cell )
354  {
355  init( hkl_info, cell );
356  }
357 
362  template<class T> HKL_data<T>::HKL_data( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling )
363  {
364  init( spacegroup, cell, hkl_sampling );
365  }
366 
371  template<class T> HKL_data<T>::HKL_data( const HKL_data_base& hkl_data )
372  {
373  init( hkl_data );
374  }
375 
379  template<class T> void HKL_data<T>::init( const HKL_info& hkl_info, const Cell& cell )
380  {
381  HKL_data_base::init( hkl_info, cell );
382  update();
383  }
384 
389  template<class T> void HKL_data<T>::init( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling )
390  {
391  HKL_data_base::init( spacegroup, cell, hkl_sampling );
392  update();
393  }
394 
399  template<class T> void HKL_data<T>::init( const HKL_data_base& hkl_data )
400  {
401  HKL_data_base::init( hkl_data );
402  update();
403  }
404 
406  template<class T> void HKL_data<T>::update()
407  {
408  if ( parent_hkl_info != NULL ) {
409  T null; null.set_null();
410  list.resize( parent_hkl_info->num_reflections(), null );
411  }
412  }
413 
418  template<class T> void HKL_data<T>::mask(const HKL_data_base& mask)
419  {
420  T null; null.set_null();
421  for ( int i = 0; i < list.size(); i++ )
422  if ( mask.missing(i) ) list[i] = null;
423  }
424 
430  template<class T> T HKL_data<T>::operator[] (const HKL_info::HKL_reference_coord& ih) const
431  {
432  if ( ih.index() < 0 ) { T null; null.set_null(); return null; }
433  T data = list[ih.index()];
434  if ( ih.friedel() ) data.friedel();
435  data.shift_phase( -ih.hkl().sym_phase_shift( parent_hkl_info->spacegroup().symop(ih.sym()) ) );
436  return data;
437  }
438 
445  template<class T> bool HKL_data<T>::get_data(const HKL_info::HKL_reference_coord& ih, T& data) const
446  {
447  if ( ih.index() < 0 ) { data.set_null(); return false; }
448  data = list[ih.index()];
449  if ( ih.friedel() ) data.friedel();
450  data.shift_phase( -ih.hkl().sym_phase_shift( parent_hkl_info->spacegroup().symop(ih.sym()) ) );
451  return true;
452  }
453 
460  template<class T> bool HKL_data<T>::set_data(const HKL_info::HKL_reference_coord& ih, const T& data)
461  {
462  if ( ih.index() < 0 ) return false;
463  T& ldata = list[ih.index()];
464  ldata = data;
465  ldata.shift_phase( ih.hkl().sym_phase_shift( parent_hkl_info->spacegroup().symop(ih.sym()) ) );
466  if ( ih.friedel() ) ldata.friedel();
467  return true;
468  }
469 
475  template<class T> T HKL_data<T>::operator[] (const HKL& hkl) const
476  {
477  int index, sym; bool friedel;
478 
479  index = parent_hkl_info->index_of( parent_hkl_info->
480  find_sym(hkl, sym, friedel) );
481  if ( index < 0 ) { T null; null.set_null(); return null; }
482  T data = list[index];
483  if (friedel) data.friedel();
484  data.shift_phase( -hkl.sym_phase_shift( parent_hkl_info->spacegroup().symop(sym) ) );
485  return data;
486  }
487 
494  template<class T> bool HKL_data<T>::get_data(const HKL& hkl, T& data) const
495  {
496  int index, sym; bool friedel;
497 
498  index = parent_hkl_info->index_of( parent_hkl_info->
499  find_sym(hkl, sym, friedel) );
500  if ( index < 0 ) { data.set_null(); return false; }
501  data = list[index];
502  if (friedel) data.friedel();
503  data.shift_phase( -hkl.sym_phase_shift(parent_hkl_info->spacegroup().symop(sym)) );
504  return true;
505  }
506 
513  template<class T> bool HKL_data<T>::set_data(const HKL& hkl, const T& data_)
514  {
515  int index, sym; bool friedel;
516  index = parent_hkl_info->index_of( parent_hkl_info->
517  find_sym(hkl, sym, friedel) );
518  if ( index < 0 ) { return false; }
519  T& ldata = list[index];
520  ldata = data_;
521  ldata.shift_phase( hkl.sym_phase_shift(parent_hkl_info->spacegroup().symop(sym)) );
522  if (friedel) ldata.friedel();
523  return true;
524  }
525 
526 
534  template<class T> HKL_data<T>& HKL_data<T>::operator =( const HKL_data<T>& other )
535  {
536  if ( parent_hkl_info == NULL ) {
537  init( other );
538  } else {
539  if ( parent_hkl_info != other.parent_hkl_info )
540  Message::message( Message_fatal( "HKL_data<T>: mismatched parent HKL_info is assignment" ) );
541  }
542  list = other.list;
543  return *this;
544  }
545 
546 
549  template<class T> HKL_data<T>& HKL_data<T>::operator =( const T& value )
550  {
551  for ( int i = 0; i < list.size(); i++ ) list[i] = value;
552  return *this;
553  }
554 
555 
556  template<class T> void HKL_data<T>::debug() const
557  {
558  HKL_data_base::debug();
559  std::cout << "Size " << list.size() << "\n";
560  }
561 
562 
563 } // namespace clipper
564 
565 #endif
HKL_info::HKL_reference_coord HKL_reference_coord
HKL HKL_reference_index: see HKL_info.
Definition: hkl_data.h:143
bool missing() const
return true if data is missing
HKL_data_base()
null constructor
Definition: hkl_data.cpp:75
HKL_data()
null constructor
Definition: hkl_data.h:238
void mask(const HKL_data_base &mask)
Definition: hkl_data.h:418
HKL_data<>
Definition: hkl_data.h:234
void compute(const HKL_data< S > &src, const C &op)
Unary computation: fill this data list by computation from another.
Definition: hkl_data.h:304
virtual String type() const =0
get data type (a list of names corresponding to the im/export values)
void init(const Spacegroup &spacegroup, const Cell &cell, const Resolution &resolution, const bool &generate=false)
initialiser: Takes spacegroup, cell, and resolution
Definition: hkl_info.cpp:112
static String data_names()
return names of data elements in this type
virtual ~HKL_data_base()
destructor
Definition: hkl_data.h:222
Fatal message (level = 9)
Definition: clipper_message.h:129
const HKL & hkl() const
return the current HKL
Definition: hkl_info.h:196
void init(const HKL_info &hkl_info, const Cell &cell)
initialiser: from parent hkl_info and cell
Definition: hkl_data.h:379
bool is_null() const
test if object has been initialised
Definition: hkl_data.cpp:126
static int data_size()
return number of data elements in this type
virtual void data_import(const HKL &hkl, const xtype array[])=0
conversion from array (for I/O)
const HKL_info & base_hkl_info() const
get the parent HKL_info object
Definition: hkl_data.h:157
void data_export(xtype array[]) const
conversion to array (for I/O)
void data_import(const HKL &hkl, const xtype array[])
conversion from array (for I/O)
Definition: hkl_data.h:265
bool set_data(const HKL_info::HKL_reference_coord &ih, const T &data)
set data by HKL_reference_coord (returns false if no equivalent hkl)
Definition: hkl_data.h:460
HKL sampling of reciprocal space.
Definition: coords.h:552
const Spacegroup & spacegroup() const
get the spacegroup
Definition: hkl_info.h:80
virtual void init(const HKL_info &hkl_info, const Cell &cell)
initialiser: from parent hkl_info and cell
Definition: hkl_data.cpp:86
Range< ftype > invresolsq_range() const
get resolution limits of the list (based on true cell and missing data)
Definition: hkl_data.cpp:149
const int & sym() const
get current symop number
Definition: hkl_info.h:198
HKL reference with index-like behaviour.
Definition: hkl_info.h:151
void data_import(const xtype array[])
conversion from array (for I/O)
cell description (automatically converts to radians)
Definition: cell.h:91
Resolution in angstroms.
Definition: coords.h:68
Definition: hkl_data.h:58
spacegroup description
Definition: spacegroup.h:73
virtual String data_names() const =0
return names of data elements in this type
ObjectCache< HKL_data_cacheobj >::Reference cacheref
object cache ref
Definition: hkl_data.h:213
ftype64 ftype
ftype definition for floating point representation
Definition: clipper_precision.h:58
HKL_reference_index & next_data(HKL_reference_index &ih) const
increment HKL_reference_index to next non-missing data
Definition: hkl_data.cpp:181
HKL list container and tree root.
Definition: hkl_info.h:62
const Cell & base_cell() const
get the parent cell
Definition: hkl_data.h:159
ObjectCache reference class.
Definition: clipper_memory.h:154
const Cell & cell() const
get the cell
Definition: hkl_info.h:78
virtual void update()=0
update: synchornize info with parent HKL_info
Cell object.
Definition: cell.h:121
Spacegroup object.
Definition: spacegroup.h:172
virtual void set_null(const int &index)=0
set data entry in the list to its null value
const HKL_sampling & hkl_sampling() const
[CLIPPER2] get HKL_sampling
Definition: hkl_data.h:168
HKL find_sym(const HKL &rfl, int &sym, bool &friedel) const
find symop no and friedel to bring an HKL into ASU
Definition: hkl_info.cpp:236
HKL_reference_index first_data() const
return HKL_reference_index pointing to first non-missing data
Definition: hkl_data.cpp:175
int num_obs() const
get number of observations in this list (based on missing data)
Definition: hkl_data.cpp:160
std::vector< HKL > hkl
the reflection list
Definition: hkl_info.h:255
virtual bool missing(const int &index) const =0
check if a data entry in the list is marked as 'missing'
const HKL_info & hkl_info() const
[CLIPPER2] get HKL_info object
Definition: hkl_data.h:170
String extension with simple parsing methods.
Definition: clipper_types.h:64
ftype invresolsq(const int &index) const
get resolution by reflection index (based on true cell)
Definition: hkl_data.cpp:139
bool missing(const int &index) const
check if a data entry in the list is marked as 'missing'
Definition: hkl_data.h:259
HKL_reference_index first() const
return HKL_reference_index pointing to first reflection
Definition: hkl_info.h:243
virtual void data_export(const HKL &hkl, xtype array[]) const =0
conversion to array (for I/O)
const Cell & cell() const
[CLIPPER2] get cell
Definition: hkl_data.h:164
void data_export(const HKL &hkl, xtype array[]) const
conversion to array (for I/O)
Definition: hkl_data.h:263
const Spacegroup & spacegroup() const
[CLIPPER2] get spacegroup
Definition: hkl_data.h:162
HKL_data< T > & operator=(const HKL_data< T > &other)
assignment operator: copies the data from another list
Definition: hkl_data.h:534
String type() const
get data type (a list of names corresponding to the im/export values)
Definition: hkl_data.h:258
const Resolution & resolution() const
[CLIPPER2] get resolution
Definition: hkl_data.h:166
Mutex class: used for locking and unlocking shared resources.
Definition: clipper_thread.h:64
HKL_info::HKL_reference_index HKL_reference_index
Basic HKL_reference_index: see HKL_info.
Definition: hkl_data.h:141
void set_null(const int &index)
set data entry in the list to its null value
Definition: hkl_data.h:260
static void message(const T &message)
pass a message
Definition: clipper_message.h:93
void compute(const HKL_data< S1 > &src1, const HKL_data< S2 > &src2, const C &op)
Binary computation: fill this data list by computation from another.
Definition: hkl_data.h:307
static Mutex mutex
thread safety
Definition: hkl_data.h:74
virtual int data_size() const =0
return number of data elements in this type
void friedel()
apply Friedel transformation to the data
int data_size() const
return number of data elements in this type
Definition: hkl_data.h:261
const T & operator[](const HKL_info::HKL_reference_index &i) const
get data by reflection HKL_reference_index
Definition: hkl_data.h:271
ftype64 xtype
xtype definition for import/export of data
Definition: clipper_precision.h:61
void compute(const C &op)
Basic computation: fill this data list by function call.
Definition: hkl_data.h:301
Definition: hkl_data.h:55
HKL reference with coord-like behaviour.
Definition: hkl_info.h:183
String data_names() const
return names of data elements in this type
Definition: hkl_data.h:262
ftype invresolsq() const
return the inv resol sq for the reflection (assumes index valid)
Definition: hkl_info.h:131
HKL_reference_index first() const
return HKL_reference_index pointing to first reflection
Definition: hkl_data.cpp:170
void set_null()
initialise to 'missing' (all elements are set to null)
virtual void mask(const HKL_data_base &mask)=0
mask the data by marking any data missing in 'mask' as missing
Reflection data type objects.
Definition: hkl_data.h:103
static String type()
return the name of this data type
void shift_phase(const ftype &dphi)
apply phase shift to the data
const bool & friedel() const
get current friedel flag
Definition: hkl_info.h:200
ftype sym_phase_shift(const Symop &op) const
return symmetry phase shift for this HKL under op
Definition: coords.h:707
HKL_data_base.
Definition: hkl_data.h:136
void update()
update: synchornize info with parent HKL_info
Definition: hkl_data.h:406
reflection 'Miller' index
Definition: coords.h:145
bool get_data(const HKL_info::HKL_reference_coord &ih, T &data) const
get data by HKL_reference_coord (returns false if no equivalent hkl)
Definition: hkl_data.h:445
const HKL_sampling & hkl_sampling() const
[CLIPPER2] get HKL_sampling
Definition: hkl_info.h:82