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
52namespace clipper
53{
54
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();
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
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
222 virtual ~HKL_data_base() {}
223 };
224
225
227
234 template<class T> class HKL_data : public HKL_data_base
235 {
236 public:
240 explicit HKL_data( const HKL_info& hkl_info );
242 HKL_data( const HKL_info& hkl_info, const Cell& cell );
246 explicit HKL_data( const HKL_data_base& hkl_data );
247
249 void init( const HKL_info& hkl_info, const Cell& cell );
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; const int index = hkl_info().index_of( hkl );
265 if ( index != -1 ) datum = list[index];
266 else get_data( hkl, datum );
267 datum.data_export( array ); }
268 void data_import( const HKL& hkl, const xtype array[] )
269 { T datum; datum.data_import( array ); set_data( hkl, datum ); }
270 void mask(const HKL_data_base& mask);
271
272 // data access methods: by HKL_reference_index
275 { return list[i.index()]; }
278 { return list[i.index()]; }
279
280 // data access methods: by HKL_reference_coord
284 bool get_data(const HKL_info::HKL_reference_coord& ih, T& data) const;
286 bool set_data(const HKL_info::HKL_reference_coord& ih, const T& data);
287
288 // data access methods: by index
290 const T& operator[] (const int& index) const { return list[index]; }
292 T& operator[] (const int& index) { return list[index]; }
293
294 // data access methods: by hkl
296 T operator[] (const HKL& hkl) const;
298 bool get_data(const HKL& hkl, T& data) const;
300 bool set_data(const HKL& hkl, const T& data);
301
302 // COMPUTATION OPERATORS
304 template<class C> void compute( const C& op )
305 { for (HKL_info::HKL_reference_index ih=parent_hkl_info->first(); !ih.last(); ih.next()) list[ih.index()] = op( ih ); }
307 template<class S, class C> void compute( const HKL_data<S>& src, const C& op )
308 { for (HKL_info::HKL_reference_index ih=parent_hkl_info->first(); !ih.last(); ih.next()) list[ih.index()] = op( ih, src[ih] ); }
310 template<class S1, class S2, class C> void compute( const HKL_data<S1>& src1, const HKL_data<S2>& src2, const C& op )
311 { for (HKL_info::HKL_reference_index ih=parent_hkl_info->first(); !ih.last(); ih.next()) list[ih.index()] = op( ih, src1[ih], src2[ih] ); }
312
313 // inherited functions lists for documentation purposes
314 //-- const HKL_info& base_hkl_info() const;
315 //-- const Cell& base_cell() const;
316 //-- const ftype invresolsq(const int& index) const;
317 //-- const Range<ftype> invresolsq_range() const;
318 //-- const int num_obs() const;
319 //-- HKL_reference_index first() const;
320 //-- HKL_reference_index first_data() const;
321 //-- HKL_reference_index& next_data( HKL_reference_index& ih ) const;
322
326 HKL_data<T>& operator =( const T& value );
327
328 void debug() const;
329
330 protected:
331 // members
332 std::vector<T> list;
333 };
334
335
336
337
338
339
340
341 // Template implementations
342
344 { return hkldata.invresolsq( index_ ); }
345
348 template<class T> HKL_data<T>::HKL_data( const HKL_info& hkl_info )
349 {
350 init( hkl_info, hkl_info.cell() );
351 }
352
356 template<class T> HKL_data<T>::HKL_data( const HKL_info& hkl_info, const Cell& cell )
357 {
358 init( hkl_info, cell );
359 }
360
366 {
368 }
369
374 template<class T> HKL_data<T>::HKL_data( const HKL_data_base& hkl_data )
375 {
376 init( hkl_data );
377 }
378
382 template<class T> void HKL_data<T>::init( const HKL_info& hkl_info, const Cell& cell )
383 {
384 HKL_data_base::init( hkl_info, cell );
385 update();
386 }
387
392 template<class T> void HKL_data<T>::init( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling )
393 {
395 update();
396 }
397
402 template<class T> void HKL_data<T>::init( const HKL_data_base& hkl_data )
403 {
404 HKL_data_base::init( hkl_data );
405 update();
406 }
407
409 template<class T> void HKL_data<T>::update()
410 {
411 if ( parent_hkl_info != NULL ) {
412 T null; null.set_null();
413 list.resize( parent_hkl_info->num_reflections(), null );
414 }
415 }
416
421 template<class T> void HKL_data<T>::mask(const HKL_data_base& mask)
422 {
423 T null; null.set_null();
424 for ( unsigned int i = 0; i < list.size(); i++ )
425 if ( mask.missing(i) ) list[i] = null;
426 }
427
433 template<class T> T HKL_data<T>::operator[] (const HKL_info::HKL_reference_coord& ih) const
434 {
435 if ( ih.index() < 0 ) { T null; null.set_null(); return null; }
436 T data = list[ih.index()];
437 if ( ih.friedel() ) data.friedel();
438 data.shift_phase( -ih.hkl().sym_phase_shift( parent_hkl_info->spacegroup().symop(ih.sym()) ) );
439 return data;
440 }
441
448 template<class T> bool HKL_data<T>::get_data(const HKL_info::HKL_reference_coord& ih, T& data) const
449 {
450 if ( ih.index() < 0 ) { data.set_null(); return false; }
451 data = list[ih.index()];
452 if ( ih.friedel() ) data.friedel();
453 data.shift_phase( -ih.hkl().sym_phase_shift( parent_hkl_info->spacegroup().symop(ih.sym()) ) );
454 return true;
455 }
456
463 template<class T> bool HKL_data<T>::set_data(const HKL_info::HKL_reference_coord& ih, const T& data)
464 {
465 if ( ih.index() < 0 ) return false;
466 T& ldata = list[ih.index()];
467 ldata = data;
468 ldata.shift_phase( ih.hkl().sym_phase_shift( parent_hkl_info->spacegroup().symop(ih.sym()) ) );
469 if ( ih.friedel() ) ldata.friedel();
470 return true;
471 }
472
478 template<class T> T HKL_data<T>::operator[] (const HKL& hkl) const
479 {
480 int index, sym; bool friedel;
481
482 index = parent_hkl_info->index_of( parent_hkl_info->
483 find_sym(hkl, sym, friedel) );
484 if ( index < 0 ) { T null; null.set_null(); return null; }
485 T data = list[index];
486 if (friedel) data.friedel();
487 data.shift_phase( -hkl.sym_phase_shift( parent_hkl_info->spacegroup().symop(sym) ) );
488 return data;
489 }
490
497 template<class T> bool HKL_data<T>::get_data(const HKL& hkl, T& data) const
498 {
499 int index, sym; bool friedel;
500
501 index = parent_hkl_info->index_of( parent_hkl_info->
502 find_sym(hkl, sym, friedel) );
503 if ( index < 0 ) { data.set_null(); return false; }
504 data = list[index];
505 if (friedel) data.friedel();
506 data.shift_phase( -hkl.sym_phase_shift(parent_hkl_info->spacegroup().symop(sym)) );
507 return true;
508 }
509
516 template<class T> bool HKL_data<T>::set_data(const HKL& hkl, const T& data_)
517 {
518 int index, sym; bool friedel;
519 index = parent_hkl_info->index_of( parent_hkl_info->
520 find_sym(hkl, sym, friedel) );
521 if ( index < 0 ) { return false; }
522 T& ldata = list[index];
523 ldata = data_;
524 ldata.shift_phase( hkl.sym_phase_shift(parent_hkl_info->spacegroup().symop(sym)) );
525 if (friedel) ldata.friedel();
526 return true;
527 }
528
529
537 template<class T> HKL_data<T>& HKL_data<T>::operator =( const HKL_data<T>& other )
538 {
539 if ( parent_hkl_info == NULL ) {
540 init( other );
541 } else {
542 if ( parent_hkl_info != other.parent_hkl_info )
543 Message::message( Message_fatal( "HKL_data<T>: mismatched parent HKL_info is assignment" ) );
544 }
545 list = other.list;
546 return *this;
547 }
548
549
552 template<class T> HKL_data<T>& HKL_data<T>::operator =( const T& value )
553 {
554 for ( unsigned int i = 0; i < list.size(); i++ ) list[i] = value;
555 return *this;
556 }
557
558
559 template<class T> void HKL_data<T>::debug() const
560 {
561 HKL_data_base::debug();
562 std::cout << "Size " << list.size() << "\n";
563 }
564
565
566} // namespace clipper
567
568#endif
cell description (automatically converts to radians)
Definition: cell.h:92
Cell object.
Definition: cell.h:122
Reflection data type objects.
Definition: hkl_data.h:104
void data_import(const xtype array[])
conversion from array (for I/O)
void shift_phase(const ftype &dphi)
apply phase shift to the data
void data_export(xtype array[]) const
conversion to array (for I/O)
static String data_names()
return names of data elements in this type
void friedel()
apply Friedel transformation to the data
static String type()
return the name of this data type
static int data_size()
return number of data elements in this type
void set_null()
initialise to 'missing' (all elements are set to null)
bool missing() const
return true if data is missing
HKL_data_base.
Definition: hkl_data.h:137
virtual bool missing(const int &index) const =0
check if a data entry in the list is marked as 'missing'
virtual void init(const HKL_info &hkl_info, const Cell &cell)
initialiser: from parent hkl_info and cell
Definition: hkl_data.cpp:86
virtual void update()=0
update: synchornize info with parent HKL_info
virtual void data_export(const HKL &hkl, xtype array[]) const =0
conversion to array (for I/O)
HKL_info::HKL_reference_index HKL_reference_index
Basic HKL_reference_index: see HKL_info.
Definition: hkl_data.h:141
virtual ~HKL_data_base()
destructor
Definition: hkl_data.h:222
const HKL_info & base_hkl_info() const
get the parent HKL_info object
Definition: hkl_data.h:157
virtual String type() const =0
get data type (a list of names corresponding to the im/export values)
virtual void mask(const HKL_data_base &mask)=0
mask the data by marking any data missing in 'mask' as missing
const Resolution & resolution() const
[CLIPPER2] get resolution
Definition: hkl_data.h:166
const Cell & base_cell() const
get the parent cell
Definition: hkl_data.h:159
const HKL_info & hkl_info() const
[CLIPPER2] get HKL_info object
Definition: hkl_data.h:170
bool is_null() const
test if object has been initialised
Definition: hkl_data.cpp:126
HKL_reference_index first_data() const
return HKL_reference_index pointing to first non-missing data
Definition: hkl_data.cpp:175
virtual void set_null(const int &index)=0
set data entry in the list to its null value
HKL_data_base()
null constructor
Definition: hkl_data.cpp:75
const HKL_sampling & hkl_sampling() const
[CLIPPER2] get HKL_sampling
Definition: hkl_data.h:168
virtual int data_size() const =0
return number of data elements in this type
ObjectCache< HKL_data_cacheobj >::Reference cacheref
object cache ref
Definition: hkl_data.h:213
Range< ftype > invresolsq_range() const
get resolution limits of the list (based on true cell and missing data)
Definition: hkl_data.cpp:149
int num_obs() const
get number of observations in this list (based on missing data)
Definition: hkl_data.cpp:160
virtual String data_names() const =0
return names of data elements in this type
HKL_reference_index & next_data(HKL_reference_index &ih) const
increment HKL_reference_index to next non-missing data
Definition: hkl_data.cpp:181
ftype invresolsq(const int &index) const
get resolution by reflection index (based on true cell)
Definition: hkl_data.cpp:139
const Spacegroup & spacegroup() const
[CLIPPER2] get spacegroup
Definition: hkl_data.h:162
const Cell & cell() const
[CLIPPER2] get cell
Definition: hkl_data.h:164
virtual void data_import(const HKL &hkl, const xtype array[])=0
conversion from array (for I/O)
HKL_reference_index first() const
return HKL_reference_index pointing to first reflection
Definition: hkl_data.cpp:170
HKL_info::HKL_reference_coord HKL_reference_coord
HKL HKL_reference_index: see HKL_info.
Definition: hkl_data.h:143
Definition: hkl_data.h:59
Definition: hkl_data.h:56
static Mutex mutex
thread safety
Definition: hkl_data.h:74
HKL_data<>
Definition: hkl_data.h:235
HKL_data(const HKL_info &hkl_info, const Cell &cell)
constructor: from parent hkl_info and cell
Definition: hkl_data.h:356
int data_size() const
return number of data elements in this type
Definition: hkl_data.h:261
void update()
update: synchornize info with parent HKL_info
Definition: hkl_data.h:409
bool set_data(const HKL &hkl, const T &data)
set data by hkl (returns false if no equivalent hkl)
Definition: hkl_data.h:516
String type() const
get data type (a list of names corresponding to the im/export values)
Definition: hkl_data.h:258
HKL_data(const Spacegroup &spacegroup, const Cell &cell, const HKL_sampling &hkl_sampling)
[CLIPPER2] constructor: from spacegroup, cell and hkl_sampling
Definition: hkl_data.h:365
void data_import(const HKL &hkl, const xtype array[])
conversion from array (for I/O)
Definition: hkl_data.h:268
void compute(const C &op)
Basic computation: fill this data list by function call.
Definition: hkl_data.h:304
void init(const HKL_data_base &hkl_data)
[CLIPPER2] initialiser: from another HKL_data object
Definition: hkl_data.h:402
HKL_data(const HKL_data_base &hkl_data)
[CLIPPER2] constructor: from another HKL_data object
Definition: hkl_data.h:374
void init(const HKL_info &hkl_info, const Cell &cell)
initialiser: from parent hkl_info and cell
Definition: hkl_data.h:382
void mask(const HKL_data_base &mask)
Definition: hkl_data.h:421
const T & operator[](const HKL_info::HKL_reference_index &i) const
get data by reflection HKL_reference_index
Definition: hkl_data.h:274
bool missing(const int &index) const
check if a data entry in the list is marked as 'missing'
Definition: hkl_data.h:259
HKL_data< T > & operator=(const HKL_data< T > &other)
assignment operator: copies the data from another list
Definition: hkl_data.h:537
HKL_data(const HKL_info &hkl_info)
constructor: from parent hkl_info
Definition: hkl_data.h:348
String data_names() const
return names of data elements in this type
Definition: hkl_data.h:262
void init(const Spacegroup &spacegroup, const Cell &cell, const HKL_sampling &hkl_sampling)
[CLIPPER2] initialiser: from spacegroup, cell, and HKL_sampling
Definition: hkl_data.h:392
void data_export(const HKL &hkl, xtype array[]) const
conversion to array (for I/O)
Definition: hkl_data.h:263
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:448
HKL_data()
null constructor
Definition: hkl_data.h:238
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:310
void set_null(const int &index)
set data entry in the list to its null value
Definition: hkl_data.h:260
bool get_data(const HKL &hkl, T &data) const
get data by hkl (returns false if no equivalent hkl)
Definition: hkl_data.h:497
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:463
void compute(const HKL_data< S > &src, const C &op)
Unary computation: fill this data list by computation from another.
Definition: hkl_data.h:307
ftype invresolsq() const
return the inv resol sq for the reflection (assumes index valid)
Definition: hkl_info.h:131
HKL reference with coord-like behaviour.
Definition: hkl_info.h:184
const int & sym() const
get current symop number
Definition: hkl_info.h:198
const bool & friedel() const
get current friedel flag
Definition: hkl_info.h:200
const HKL & hkl() const
return the current HKL
Definition: hkl_info.h:196
HKL reference with index-like behaviour.
Definition: hkl_info.h:152
HKL list container and tree root.
Definition: hkl_info.h:63
HKL_reference_index first() const
return HKL_reference_index pointing to first reflection
Definition: hkl_info.h:243
int index_of(const HKL &rfl) const
reflection index from hkl
Definition: hkl_info.h:100
const Spacegroup & spacegroup() const
get the spacegroup
Definition: hkl_info.h:80
std::vector< HKL > hkl
the reflection list
Definition: hkl_info.h:255
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:238
const HKL_sampling & hkl_sampling() const
[CLIPPER2] get HKL_sampling
Definition: hkl_info.h:82
const Cell & cell() const
get the cell
Definition: hkl_info.h:78
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
HKL sampling of reciprocal space.
Definition: coords.h:553
reflection 'Miller' index
Definition: coords.h:146
ftype sym_phase_shift(const Symop &op) const
return symmetry phase shift for this HKL under op
Definition: coords.h:707
Fatal message (level = 9)
Definition: clipper_message.h:129
static void message(const T &message)
pass a message
Definition: clipper_message.h:93
Mutex class: used for locking and unlocking shared resources.
Definition: clipper_thread.h:64
ObjectCache reference class.
Definition: clipper_memory.h:155
Resolution in angstroms.
Definition: coords.h:69
Spacegroup object.
Definition: spacegroup.h:173
spacegroup description
Definition: spacegroup.h:74
String extension with simple parsing methods.
Definition: clipper_types.h:65
ftype64 ftype
ftype definition for floating point representation
Definition: clipper_precision.h:58
ftype64 xtype
xtype definition for import/export of data
Definition: clipper_precision.h:61