Clipper
rotation.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_ROTATION
00046 #define CLIPPER_ROTATION
00047 
00048 
00049 #include "clipper_types.h"
00050 
00051 
00052 namespace clipper
00053 {
00054 
00055   // forward definition
00056   class Rotation;
00057 
00058 
00060   /* Rotations are generally handled through the clipper::Rotation
00061      class. This class only exists for conversion purposes.
00062 
00063      This particular class represents generic Euler angles. The
00064      convention is selected from the 24 possible conventions according
00065      to the template parameter. The integer convention code is
00066      enumerated in the Rotation::EULERtype enumation in the form
00067      Rotation::EulerZYZr, Rotation::EulerXYZs etc., where the X/Y/Z
00068      indicates the axes of rotation in order, and the r/s indicates
00069      static or rotating axes. The type of an Euler class is also given
00070      as a prefix to the result of format(). */
00071   template<int T> class Euler {
00072   public:
00074     Euler() {}
00076     Euler( const ftype& alpha, const ftype& beta,  const ftype& gamma ) :
00077       alpha_(alpha), beta_(beta), gamma_(gamma) {}
00079     Euler( const Rotation& rot );
00081     Rotation rotation() const;
00082     const ftype& alpha() const { return alpha_; }  
00083     const ftype& beta()  const { return beta_;  }  
00084     const ftype& gamma() const { return gamma_; }  
00085     String format() const;  
00086   private:
00087     static void params( int& r1, int& r2, int& r3, int& s );
00088     ftype alpha_, beta_, gamma_;
00089   };
00090 
00092   /* Rotations are generally handled through the clipper::Rotation
00093      class. This class only exists for conversion purposes.
00094 
00095      This particular class represents Euler_ccp4 angles according to the
00096      CCP4 standard, i.e.
00097      - Rotation 1 (alpha) about K,
00098      - Rotation 2 (beta) about the new J,
00099      - Rotation 3 (gamma) about the new K. */
00100   class Euler_ccp4 {
00101   public:
00103     Euler_ccp4() {}
00105     Euler_ccp4( const ftype& alpha, const ftype& beta,  const ftype& gamma ) :
00106       alpha_(alpha), beta_(beta), gamma_(gamma) {}
00107     const ftype& alpha() const { return alpha_; }  
00108     const ftype& beta()  const { return beta_;  }  
00109     const ftype& gamma() const { return gamma_; }  
00110     String format() const;  
00111   private:
00112     ftype alpha_, beta_, gamma_;
00113   };
00114 
00116   /* Rotations are generally handled through the clipper::Rotation
00117      class. This class only exists for conversion purposes.
00118 
00119      This particular class represents Polar_ccp4 angles according to the
00120      CCP4 standard, i.e.
00121      - omega gives inclination of rotation axis to K axis,
00122      - phi gives anticlockwise rotation from I to projection of
00123      rotation axis onto I-J plane,
00124      - kappa is the rotation about the rotation axis. */
00125   class Polar_ccp4 {
00126   public:
00128     Polar_ccp4() {}
00130     Polar_ccp4( const ftype& omega, const ftype& phi,  const ftype& kappa ) :
00131       omega_(omega), phi_(phi), kappa_(kappa) {}
00132     const ftype& psi() const { return omega_; }    
00133     const ftype& omega() const { return omega_; }  
00134     const ftype& phi()   const { return phi_;  }   
00135     const ftype& kappa() const { return kappa_; }  
00136     String format() const;  
00137   private:
00138     ftype omega_, phi_, kappa_;
00139   };
00140 
00142 
00145   class Rotation {
00146   public:
00148     Rotation() {}
00150     template<int T> explicit Rotation( const Euler<T>& euler )
00151       { (*this) = euler.rotation(); }
00153     explicit Rotation( const Euler_ccp4& euler );
00155     explicit Rotation( const Polar_ccp4& polar );
00157     explicit Rotation( const Mat33<>& matrix );
00159     Rotation( const ftype& w, const ftype& x, const ftype& y,  const ftype& z )
00160       : w_(w), x_(x), y_(y), z_(z) {}
00161     const ftype& w() const { return w_; }  
00162     const ftype& x() const { return x_; }  
00163     const ftype& y() const { return y_; }  
00164     const ftype& z() const { return z_; }  
00165     template<int T> Euler<T> euler() const 
00166       { return Euler<T>( *this ); }
00167     Euler_ccp4 euler_ccp4() const;  
00168     Polar_ccp4 polar_ccp4() const;  
00169     Mat33<> matrix() const;    
00170 
00171     const Rotation& norm();
00173     ftype abs_angle() const;
00175     Rotation inverse() const { return Rotation( w_, -x_, -y_, -z_ ); }
00177     static Rotation zero() { return Rotation( 1.0, 0.0, 0.0, 0.0 ); }
00179     static Rotation null() { return Rotation( Util::nan(), 0.0, 0.0, 0.0 ); }
00181     bool is_null() const { return Util::is_nan( w_ ); }
00183     friend Rotation operator* ( const Rotation& r1, const Rotation& r2 );
00184     String format() const;  
00185 
00186     enum EULERtype { EulerXYZr,EulerXYZs,EulerXYXr,EulerXYXs,
00187                      EulerXZXr,EulerXZXs,EulerXZYr,EulerXZYs,
00188                      EulerYZXr,EulerYZXs,EulerYZYr,EulerYZYs,
00189                      EulerYXYr,EulerYXYs,EulerYXZr,EulerYXZs,
00190                      EulerZXYr,EulerZXYs,EulerZXZr,EulerZXZs,
00191                      EulerZYZr,EulerZYZs,EulerZYXr,EulerZYXs };
00192   protected:
00193     ftype w_, x_, y_, z_;
00194   };
00195 
00196 
00197 } // namespace clipper
00198 
00199 #endif