1 /*! \file sfweight.h 2 Header file for structure factor weighting object 3 */ 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_SFWEIGHT 46 #define CLIPPER_SFWEIGHT 47 48 49 #include "function_object_bases.h" 50 #include "../core/resol_basisfn.h" 51 52 53 namespace clipper { 54 55 56 //! Structure factor weighting by sigmaa-related spline method. 57 /*! Perform structure factor weighting to obtain likelihood 58 weights for structure factors. 59 60 This implementation uses a single list of reflections for both 61 scaling and sigmaa, thus the only relevent usage flags are 62 NONE/BOTH. 63 64 The number of spline parameters or the number of reflections per 65 parameter may be specified. If either is zero, the other takes 66 priority. If both are non-zero, a compromise value is used. 67 \ingroup g_funcobj */ 68 template<class T> class SFweight_spline : public SFweight_base<T> { 69 public: 70 //! constructor 71 SFweight_spline( const int n_reflns = 1000, const int n_params = 20, const int n_phases = 24 ) { init( n_reflns, n_params, n_phases ); } 72 //! constructor: shorthand for constructor+operator 73 SFweight_spline( HKL_data<datatypes::F_phi<T> >& fb, HKL_data<datatypes::F_phi<T> >& fd, HKL_data<datatypes::Phi_fom<T> >& phiw, const HKL_data<datatypes::F_sigF<T> >& fo, const HKL_data<datatypes::F_phi<T> >& fc, const HKL_data<datatypes::Flag>& usage, const int n_reflns = 1000, const int n_params = 20 ); 74 //! initialise: from parameters 75 void init( const int n_reflns = 1000, const int n_params = 20, const int n_phases = 24 ); 76 77 // Likelihood weighting and map coefficient computation 78 bool operator() ( HKL_data<datatypes::F_phi<T> >& fb, HKL_data<datatypes::F_phi<T> >& fd, HKL_data<datatypes::Phi_fom<T> >& phiw, const HKL_data<datatypes::F_sigF<T> >& fo0, const HKL_data<datatypes::F_phi<T> >& fc0, const HKL_data<datatypes::Flag>& usage ); 79 // Likelihood weighting and map coefficient computation (MLHL) 80 bool operator() ( HKL_data<datatypes::F_phi<T> >& fb, HKL_data<datatypes::F_phi<T> >& fd, HKL_data<datatypes::Phi_fom<T> >& phiw, HKL_data<datatypes::ABCD<T> >& hl, const HKL_data<datatypes::F_sigF<T> >& fo0, const HKL_data<datatypes::ABCD<T> >& hl0, const HKL_data<datatypes::F_phi<T> >& fc0, const HKL_data<datatypes::Flag>& usage ); 81 82 template<class F> bool evaluate( HKL_data<datatypes::F_phi<T> >& fb, HKL_data<datatypes::F_phi<T> >& fd, HKL_data<datatypes::Phi_fom<T> >& phiw, HKL_data<datatypes::ABCD<T> >& hl, const HKL_data<datatypes::F_sigF<T> >& fo0, const HKL_data<datatypes::ABCD<T> >& hl0, const HKL_data<datatypes::F_phi<T> >& fc0, const HKL_data<datatypes::Flag>& usage, F tgt ); 83 template<class F> bool reevaluate( HKL_data<datatypes::F_phi<T> >& fb, HKL_data<datatypes::F_phi<T> >& fd, HKL_data<datatypes::Phi_fom<T> >& phiw, HKL_data<datatypes::ABCD<T> >& hl, const HKL_data<datatypes::F_sigF<T> >& fo0, const HKL_data<datatypes::ABCD<T> >& hl0, const HKL_data<datatypes::F_phi<T> >& fc0, const HKL_data<datatypes::Flag>& usage, F tgt ); params_scale()84 const std::vector<ftype>& params_scale() { return param_s; } params_error()85 const std::vector<ftype>& params_error() { return param_w; } log_likelihood_work()86 const double& log_likelihood_work() { return llw; } log_likelihood_free()87 const double& log_likelihood_free() { return llf; } 88 89 void debug() const; 90 91 struct TargetResult { ftype r, ds, dw, dss, dww, dsw; }; 92 TargetResult targetfn( const HKL_class cls, const datatypes::F_sigF<T>& fo0, const datatypes::F_phi<T>& fc0, const ftype& s, const ftype& w ) const; 93 TargetResult targethl( const HKL_class cls, const datatypes::F_sigF<T>& fo0, const datatypes::ABCD<T>& hl0, const datatypes::F_phi<T>& fc0, const ftype& s, const ftype& w ) const; 94 private: 95 struct HLterms { ftype cosa, sina, cos2a, sin2a; }; 96 class TargetFo { 97 public: 98 TargetResult operator() ( const HKL_class cls, const datatypes::F_sigF<T>& fo0, const datatypes::ABCD<T>& hl0, const datatypes::F_phi<T>& fc0, const ftype& s, const ftype& w, const std::vector<HLterms>& hlterms ); 99 datatypes::ABCD<T> abcd; 100 datatypes::Phi_fom<T> phiw; 101 }; 102 class TargetHL { 103 public: 104 TargetResult operator() ( const HKL_class cls, const datatypes::F_sigF<T>& fo0, const datatypes::ABCD<T>& hl0, const datatypes::F_phi<T>& fc0, const ftype& s, const ftype& w, const std::vector<HLterms>& hlterms ); 105 datatypes::ABCD<T> abcd; 106 datatypes::Phi_fom<T> phiw; 107 }; 108 int num_params( const HKL_data<datatypes::Flag_bool>& flag ) const; 109 int nparams, nreflns; 110 std::vector<ftype> param_s, param_w; 111 std::vector<T> scale_fo, scale_fc, value_s, value_w; 112 std::vector<HLterms> hlterms; 113 double llw, llf; 114 }; 115 116 117 } // namespace clipper 118 119 #endif 120