Clipper
hkl_info.h
00001 
00004 //C Copyright (C) 2000-2006 Kevin Cowtan and University of York
00005 //L
00006 //L  This library is free software and is distributed under the terms
00007 //L  and conditions of version 2.1 of the GNU Lesser General Public
00008 //L  Licence (LGPL) with the following additional clause:
00009 //L
00010 //L     `You may also combine or link a "work that uses the Library" to
00011 //L     produce a work containing portions of the Library, and distribute
00012 //L     that work under terms of your choice, provided that you give
00013 //L     prominent notice with each copy of the work that the specified
00014 //L     version of the Library is used in it, and that you include or
00015 //L     provide public access to the complete corresponding
00016 //L     machine-readable source code for the Library including whatever
00017 //L     changes were used in the work. (i.e. If you make changes to the
00018 //L     Library you must distribute those, but you do not need to
00019 //L     distribute source or object code to those portions of the work
00020 //L     not covered by this licence.)'
00021 //L
00022 //L  Note that this clause grants an additional right and does not impose
00023 //L  any additional restriction, and so does not affect compatibility
00024 //L  with the GNU General Public Licence (GPL). If you wish to negotiate
00025 //L  other terms, please contact the maintainer.
00026 //L
00027 //L  You can redistribute it and/or modify the library under the terms of
00028 //L  the GNU Lesser General Public License as published by the Free Software
00029 //L  Foundation; either version 2.1 of the License, or (at your option) any
00030 //L  later version.
00031 //L
00032 //L  This library is distributed in the hope that it will be useful, but
00033 //L  WITHOUT ANY WARRANTY; without even the implied warranty of
00034 //L  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00035 //L  Lesser General Public License for more details.
00036 //L
00037 //L  You should have received a copy of the CCP4 licence and/or GNU
00038 //L  Lesser General Public License along with this library; if not, write
00039 //L  to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
00040 //L  The GNU Lesser General Public can also be obtained by writing to the
00041 //L  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00042 //L  MA 02111-1307 USA
00043 
00044 
00045 #ifndef CLIPPER_HKL_INFO
00046 #define CLIPPER_HKL_INFO
00047 
00048 
00049 #include "hkl_lookup.h"
00050 
00051 
00052 namespace clipper
00053 {
00054   class HKL_data_base;
00055 
00056 
00058 
00062   class HKL_info
00063   {
00064    public:
00066     HKL_info();
00068     HKL_info( const Spacegroup& spacegroup, const Cell& cell, const Resolution& resolution, const bool& generate = false );
00070     void init( const Spacegroup& spacegroup, const Cell& cell, const Resolution& resolution, const bool& generate = false );
00072     void init( const Spacegroup& spacegroup, const Cell& cell, const HKL_sampling& hkl_sampling, const bool& generate = true );
00073 
00075     bool is_null() const;
00076 
00078     const Cell& cell() const { return cell_; }
00080     const Spacegroup& spacegroup() const { return spacegroup_; }
00082     const HKL_sampling& hkl_sampling() const { return hkl_sampling_; }
00084     const Resolution& resolution() const { return resolution_; }
00085 
00087     void generate_hkl_list();
00089     void add_hkl_list( const std::vector<HKL>& add );
00090 
00092     inline int num_reflections() const { return hkl.size(); }
00093 
00095 
00096     inline const HKL& hkl_of( const int& index ) const { return hkl[index]; }
00098 
00100     inline int index_of( const HKL& rfl ) const
00101       { return lookup.index_of( rfl ); }
00102 
00104     inline const ftype32& invresolsq( const int& index ) const
00105       { return invresolsq_lookup[index]; }
00107     inline const Range<ftype>& invresolsq_range() const
00108       { return invresolsq_range_; }
00110     const HKL_class& hkl_class( const int& index ) const
00111       { return hkl_class_lookup[index]; }
00113     HKL find_sym( const HKL& rfl, int& sym, bool& friedel ) const;
00114 
00115 
00117 
00121     class HKL_reference_base
00122     {
00123     public:
00125       inline const HKL_info& base_hkl_info() const { return *hklinfo; }
00127       inline const int& index() const { return index_; }
00129       inline ftype invresolsq( const HKL_data_base& hkldata ) const;
00131       inline ftype invresolsq() const
00132         { return hklinfo->invresolsq( index_ ); }
00134       inline bool last() const
00135         { return ( index_ >= hklinfo->num_reflections() ); }
00136     protected:
00137       const HKL_info* hklinfo;
00138       int index_;
00139     };
00140 
00142 
00151     class HKL_reference_index : public HKL_reference_base
00152     {
00153     public:
00155       HKL_reference_index() {}
00157       HKL_reference_index( const HKL_info& hklinfo_, const int& index )
00158         { hklinfo = &hklinfo_; index_ = index; }
00160       inline const HKL& hkl() const { return hklinfo->hkl_of( index_ ); }
00162       inline const HKL_class& hkl_class() const
00163         { return hklinfo->hkl_class( index_ ); }
00165       inline HKL_reference_index& next() { index_++; return *this; }
00166       // inherited functions listed for documentation purposes
00167       //-- const HKL_info& base_hkl_info() const;
00168       //-- const int& index() const;
00169       //-- const ftype invresolsq() const;
00170       //-- bool last() const;
00171     };
00172 
00174 
00183     class HKL_reference_coord : public HKL_reference_base
00184     {
00185     public:
00187       HKL_reference_coord() {}
00189       HKL_reference_coord( const HKL_info& hklinfo_, const HKL& hkl ) {
00190         hklinfo = &hklinfo_;
00191         hkl_ = hkl;
00192         index_ = hklinfo->index_of( hklinfo->find_sym( hkl_, sym_, friedel_ ) );
00193         if ( index_ < 0 ) Message::message( Message_fatal( "HKL_reference_coord: hkl not found" ) );
00194       }
00196       inline const HKL& hkl() const { return hkl_; }
00198       inline const int& sym() const { return sym_; }
00200       inline const bool& friedel() const { return friedel_; }
00202 
00205       inline HKL_reference_coord& set_hkl( const HKL& hkl__ ) {
00206         hkl_ = hkl__;
00207         HKL equiv = hkl__.transform(hklinfo->isymop[sym_]);
00208         if ( friedel_ ) equiv = -equiv;
00209         index_ = hklinfo->index_of( equiv );
00210         if ( index_ < 0 ) index_ =
00211            hklinfo->index_of( hklinfo->find_sym( hkl_, sym_, friedel_ ) );
00212         return *this;
00213       }
00215       inline HKL_reference_coord& next() {
00216         sym_ = 0; friedel_ = false;
00217         index_++;
00218         if ( !last() ) hkl_ = hklinfo->hkl_of( index_ );
00219         return *this;
00220       }
00221       // increment h,k,l
00222       inline HKL_reference_coord& next_h() { hkl_.h()++; set_hkl( hkl_ ); return *this; }  
00223       inline HKL_reference_coord& next_k() { hkl_.k()++; set_hkl( hkl_ ); return *this; }  
00224       inline HKL_reference_coord& next_l() { hkl_.l()++; set_hkl( hkl_ ); return *this; }  
00225       inline HKL_reference_coord& prev_h() { hkl_.h()--; set_hkl( hkl_ ); return *this; }  
00226       inline HKL_reference_coord& prev_k() { hkl_.k()--; set_hkl( hkl_ ); return *this; }  
00227       inline HKL_reference_coord& prev_l() { hkl_.l()--; set_hkl( hkl_ ); return *this; }  
00228 
00229       inline HKL_reference_coord& operator =( const HKL& hkl__ )
00230         { return set_hkl( hkl__ ); }
00231       // inherited functions listed for documentation purposes
00232       //-- const HKL_info& base_hkl_info() const;
00233       //-- const int& index() const;
00234       //-- const ftype invresolsq() const;
00235       //-- bool last() const;
00236     protected:
00237       HKL hkl_;
00238       int sym_;
00239       bool friedel_;
00240     };
00241 
00243     HKL_reference_index first() const { return HKL_reference_index( *this, 0 ); }
00244 
00245     void debug() const;
00246 
00247    protected:
00248     Spacegroup spacegroup_;             
00249     Cell cell_;                         
00250     HKL_sampling hkl_sampling_;         
00251     Resolution resolution_;             
00252     std::vector<Isymop> isymop;         
00253 
00255     std::vector<HKL> hkl;
00257     std::vector<HKL_class> hkl_class_lookup;
00259     std::vector<ftype32> invresolsq_lookup;
00260 
00262     HKL_lookup lookup;
00264     Range<ftype> invresolsq_range_;
00265 
00266     // internal methods:
00268     void update_hkl_list();
00269 
00270     friend class HKL_info::HKL_reference_base;
00271     friend class HKL_info::HKL_reference_index;
00272     friend class HKL_info::HKL_reference_coord;
00273   };
00274 
00275 
00276 } // namespace clipper
00277 
00278 #endif