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