geometricFit.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: geometricFit.h,v 1.4.18.2 2007/06/17 07:02:22 oliver Exp $
00005 // Author:
00006 //
00007 //
00008 
00009 #ifndef BALL_STRUCTURE_DOCKING_GEOMETRICFIT_H
00010 #define BALL_STRUCTURE_DOCKING_GEOMETRICFIT_H
00011 
00012 #ifndef BALL_DATATYPE_REGULARDATA3D_H
00013 #include <BALL/DATATYPE/regularData3D.h>
00014 #endif
00015 
00016 #ifndef BALL_KERNEL_SYSTEM_H
00017 #include <BALL/KERNEL/system.h>
00018 #endif
00019 
00020 #ifndef BALL_MATHS_COMPLEX_H
00021 #include <BALL/MATHS/complex.h>
00022 #endif
00023 
00024 #ifndef BALL_MATHS_FFT3D_H
00025 #include <BALL/MATHS/FFT3D.h>
00026 #endif
00027 
00028 #ifndef BALL_STRUCTURE_DOCKING_DOCKINGALGORITHM_H
00029 #include <BALL/STRUCTURE/DOCKING/dockingAlgorithm.h>
00030 #endif
00031 
00032 namespace BALL
00033 {
00040   class BALL_EXPORT GeometricFit : public DockingAlgorithm
00041   {
00042     public:
00043       BALL_CREATE(GeometricFit)
00044       
00045       
00050       struct BALL_EXPORT Option 
00051       {
00052         // the parameter r,
00053         // "Any grid point is considered inside the molecule if there is at 
00054         // least one atom nucleus within a distance r from it." 
00055         // Default value is 1.8 Angstrom
00056         static const String NEAR_RADIUS;
00057 
00058         // Default grid spacing. 
00059         // Default value is 1.0 Angstrom
00060         static const String GRID_SPACING;
00061   
00062         // grid size = (ceil)(molecule size / grid spacing);
00063         static const String GRID_SIZE;  
00064 
00065         // The thickness of the surface of the protein
00066         // Default value is 1.0 Angstrom
00067         static const String SURFACE_THICKNESS;
00068 
00069         // Degree interval is the delta parameter, 
00070         // which is the degrees that protein B rotates every time
00071         // Default value is 20 degrees
00072         static const String DEGREE_INTERVAL;
00073 
00074         // How many peaks should the program keep for each rotation
00075         static const String TOP_N;
00076 
00083         static const String SURFACE_TYPE; 
00084 
00085         // How many results should be kept in total (also in DockingAlgorithms)
00086         static const String BEST_NUM;
00087 
00088         // Verbosity of the Algorithm (also in DockingAlgorithm)
00089         static const String VERBOSITY;
00090         
00091         // Euler angels for redocking
00092         static const String PHI_MIN;
00093         static const String PHI_MAX;
00094         static const String DEG_PHI;
00095         
00096         static const String THETA_MIN;
00097         static const String THETA_MAX;
00098         static const String DEG_THETA;
00099         
00100         static const String PSI_MIN;
00101         static const String PSI_MAX;
00102         static const String DEG_PSI;
00103         
00104         // penalty value of the inside points
00105         // Default value for static protein is -15, for mobile protein 1
00106         static const String PENALTY_STATIC;
00107         static const String PENALTY_MOBILE;
00108         
00109       };
00110     
00111       struct BALL_EXPORT Default
00112       {
00113         // Default parameter r,
00114         // Default value is 1.8 Angstrom
00115         static const float NEAR_RADIUS;
00116 
00117         // Default grid spacing. 
00118         // Default value is 1.0 Angstrom
00119         static const float GRID_SPACING;
00120 
00121         // grid size = (ceil)(molecule size / grid spacing);
00122         static const int GRID_SIZE; 
00123 
00124         // Default thickness of the surface of the protein
00125         // Default value is 1.0 Angstrom
00126         static const float SURFACE_THICKNESS;
00127 
00128         // Degree interval is the delta parameter, 
00129         // which is the degrees that protein B rotates every time
00130         // Default value is 20 degrees
00131         static const double DEGREE_INTERVAL;
00132 
00136         static const int SURFACE_TYPE;
00137 
00138         // How many peaks should the program keep for each rotation
00139         static const int TOP_N;
00140 
00141         // How many overall top best peaks should the program keep 
00142         // after doing all rotations.
00143         static const int BEST_NUM;
00144 
00145         // Verbosity of the algorithm
00146         // Default value is 0
00147         // For values > 1, some information is printed on Log
00148         // For values > 5, timing information is included
00149         static const int VERBOSITY;
00150         
00151         // Euler angels for redocking
00152         static const float PHI_MIN;
00153         static const float PHI_MAX;
00154         static const float DEG_PHI;
00155         
00156         static const float THETA_MIN;
00157         static const float THETA_MAX;
00158         static const float DEG_THETA;
00159         
00160         static const float PSI_MIN;
00161         static const float PSI_MAX;
00162         static const float DEG_PSI;
00163         
00164         // penalty value of the inside points
00165         // Default value for static protein is -15, for mobile protein 1
00166         static const int PENALTY_STATIC;
00167         static const int PENALTY_MOBILE;
00168       };
00169 
00175       class BALL_EXPORT Peak_
00176       {
00177         public:
00178 
00179           // constructor
00180           Peak_() ;
00181 
00182           // destructor
00183           ~Peak_() ;
00184 
00185           // Operator <
00186           bool operator < (const Peak_& p) const ;
00187 
00188           double  value;
00189           Vector3 orientation;
00190           Vector3 translation;
00191       };
00192 
00193 
00197       class BALL_EXPORT RotationAngles_
00198       {
00199         public: 
00200 
00201           // constructor
00202           RotationAngles_() ;
00203           
00204           // constructor
00205           RotationAngles_( int step ) ;
00206 
00207           // destructor
00208           ~RotationAngles_()  {};
00209 
00210           // generate all non-degenerate rotation angles.
00211           // This algorithm is based on ???
00212           bool generateSomeAngles( const float deg_phi,   const float deg_psi, const float deg_theta,
00213                                    const float phi_min,   const float phi_max,
00214                                    const float psi_min,   const float psi_max,
00215                                    const float theta_min, const float theta_max ) ;
00216 
00217           // generate all non-degenerate rotation angles.
00218           // This algorithm is based on ???
00219           bool generateAllAngles( const int deg ) ;
00220 
00221           int getRotationNum()
00222             
00223           {
00224             return ang_num_;
00225           }
00226 
00227           int getXAng( int n ) // get the euler angle rotate around x axis
00228             
00229           {
00230             return phi_[n];
00231           }
00232 
00233           int getYAng( int n ) // get the euler angle rotate around y axis
00234             
00235           {
00236             return theta_[n];
00237           }
00238 
00239           int getZAng( int n ) // get the euler angle rotate around z axis
00240             
00241           {
00242             return psi_[n];
00243           }
00244 
00245         private:
00246           int max_rotation_;
00247           int  ang_num_;
00248           vector<int> phi_;
00249           vector<int> theta_;
00250           vector<int> psi_;
00251       };
00252 
00253       // PROTEIN_A is the static protein, i.e., the bigger one;
00254       // PROTEIN_B is the mobile protein, i.e., the smaller one.
00255       enum ProteinIndex{  PROTEIN_A = 1, PROTEIN_B    = 2 };
00256 
00257       // The surface type to use for construction of the grids.
00258       enum SurfaceType {  CONNOLLY  = 1, VAN_DER_WAALS = 2, FTDOCK = 3 };
00259 
00260       // Default constructor
00261       // Creates an empty GeometricFit object
00262       GeometricFit() 
00263         ;
00264 
00270       GeometricFit(System &system1, System &system2)
00271         ;
00272 
00277       GeometricFit(Options& new_options)
00278         ;
00279       
00284       GeometricFit(System &system1,System &system2 ,Options& new_options)
00285         ;
00286         
00287         
00288 /*       // Copy constructor */
00289 /*       // Copies an existing GeometricFit object */
00290 /*       GeometricFit( const GeometricFit& geo_fit ); */
00291 
00292       // Destructor
00293       ~GeometricFit() ;
00294 
00297       virtual void setup(System& system1, System& system2, Options& new_options)
00298         ;
00299       
00300       virtual void setup(System& system1, System& system2)
00301         ;   
00302   
00305       void start()
00306         ;
00307 
00308       // return the overall docking progress as a percentage
00309       float getProgress() const
00310         ;
00311       
00312       // 
00313       bool hasFinished() const
00314         ;
00315 
00318       Vector3 getTranslation(Index con_num) const
00319         ;
00320 
00323       Vector3 getOrientation(Index con_num) const
00324         ;
00325 
00328       ConformationSet getConformationSet(Index total_number = 0)
00329         ;
00330       
00332       // the member variables
00333 
00336       Options options;
00337       
00338     protected:
00339 
00340       // Free all allocated memory and destroys the options and results
00341       void destroy_()
00342         ;
00343 
00344       // find the inside points
00345       void findInsidePoints_( System& system, ProteinIndex pro_idx )
00346         ;
00347 
00348       // find out the surface points according to the Connolly's surface definition.
00349       void findConnollySurfacePoints_( System& system, ProteinIndex pro_idx )
00350         ;
00351 
00352       // find out the surface points according to the van der Waal's surface definition.
00353       void findVanDerWaalsSurfacePoints_( System& system, ProteinIndex pro_idx )
00354         ;
00355 
00356       // find the inside points using the same algorithm as FTDock
00357       void findFTDockInsidePoints_( System& system, ProteinIndex pro_idx )
00358         ;
00359 
00360       // find out the surface points according to the FTDock surface definition.
00361       void findFTDockSurfacePoints_( System& system, ProteinIndex pro_idx )
00362         ;
00363 
00366       Vector3 getMassCenter_( System& system ) 
00367         ;
00368 
00371       float getRadius_( System& system )
00372         ;
00373 
00374       void doPreTranslation_( ProteinIndex pro_idx )
00375         ;
00376 
00377       void initGridSizes_()
00378         ;
00379 
00385       int optimizeGridSize_( int raw_size )
00386         ;
00387 
00390       void initFFTGrid_( ProteinIndex pro_idx )
00391         ;
00392 
00393       // make grid from System
00394       void makeFFTGrid_( ProteinIndex pro_idx )
00395         ;
00396 
00397       // get the global peaks and put them into a list
00398       void getGlobalPeak_(Peak_* peak_list)
00399         ;
00400 
00401       // change the orientation of protein around its center according to euler_ang
00402       void changeProteinOrientation_( System& system, Vector3 euler_ang )
00403         ;
00404 
00405       // calculate the conjugate of each point in FFT grid
00406       void calcConjugate_( ProteinIndex pro_idx )
00407         ;
00408 
00409       // calculate the product of the two FFT grids
00410       void FFTGridMulti_()
00411         ;
00412 
00413       // get the transformation of the peak value according to its position in matrix
00414       Vector3 getTranslation_( const Vector3& mat_pos )
00415         ;
00416 
00417       Vector3 getSeparation_( const Vector3& mat_pos )
00418         ;
00419 
00420 
00421       // here we have two units for the size
00422       // index : in the unit of grid points
00423       // coord : in the unit of Angstrom
00424 
00425       // the FFT grid for protein A
00426       FFT3D*  FFT_grid_a_;
00427       
00428       // the FFT grid for protein B
00429       FFT3D*  FFT_grid_b_;
00430 
00431       float radius_a_;
00432       float radius_b_;
00433 
00434       Vector3 FFT_grid_lower_index_;
00435       Vector3 FFT_grid_upper_index_;
00436       Vector3 FFT_grid_lower_coord_;
00437       Vector3 FFT_grid_upper_coord_;     
00438       
00439       Vector3 FFT_grid_size_index_;
00440 
00441       // the translation we do to the system b before FFT
00442       // it is to reduse the size of the FFT_grid
00443       Vector3 pre_translation_a_;
00444       Vector3 pre_translation_b_;
00445 
00446       Vector3 FFT_grid_origin_;
00447 
00448       // current execution progress
00449       int current_round_;
00450 
00451       // execution round of whole work
00452       int total_round_;
00453 
00454       // ordered set of the top_n peaks
00455       std::multiset<Peak_> peak_set_;
00456 
00457       // Needed to produce the correct results in getRankedConformations
00458       System system_backup_a_;
00459       System system_backup_b_;
00460 
00461       // Vectors to store orientation and translation of the results in the ranked conformations
00462       vector<Vector3> translations_;
00463       vector<Vector3> orientations_;
00464 
00465     }; // class GeometricFit
00466 
00467 } // namespace BALL
00468 
00469 #endif