BALL
1.4.1
|
00001 #ifndef BALL_NMR_EMPIRICALHSSHIFTPROCESSOR_H 00002 #define BALL_NMR_EMPIRICALHSSHIFTPROCESSOR_H 00003 00004 #ifndef BALL_MATHS_CUBICSPLINE2D_H 00005 # include <BALL/MATHS/cubicSpline2D.h> 00006 #endif 00007 00008 #ifndef BALL_MATHS_CUBICSPLINE1D_H 00009 # include <BALL/MATHS/cubicSpline1D.h> 00010 #endif 00011 00012 00013 #ifndef BALL_FORMAT_GENERICMOLFILE_H 00014 # include <BALL/FORMAT/genericMolFile.h> 00015 #endif 00016 00017 #ifndef BALL_NMR_SHIFT_MODULE_H 00018 # include<BALL/NMR/shiftModule.h> 00019 #endif 00020 00021 #ifndef BALL_KERNEL_EXPRESSION_H 00022 # include<BALL/KERNEL/expression.h> 00023 #endif 00024 00025 #ifndef BALL_DATATYPE_OPTIONS_H 00026 # include <BALL/DATATYPE/options.h> 00027 #endif 00028 00029 00030 #include <set> 00031 #include <map> 00032 00033 namespace BALL 00034 { 00035 class Atom; 00036 00040 class BALL_EXPORT EmpiricalHSShiftProcessor 00041 : public ShiftModule 00042 { 00043 public: 00044 00045 BALL_CREATE(EmpiricalHSShiftProcessor) 00046 00047 static const int VERBOSITY_LEVEL_CRITICAL; 00048 static const int VERBOSITY_LEVEL_DEBUG; 00049 00053 00054 struct BALL_EXPORT Option 00055 { 00058 static const char* VERBOSITY; 00059 00060 }; 00061 00063 struct BALL_EXPORT Default 00064 { 00065 static const int VERBOSITY; 00066 }; 00067 00069 00070 00074 00078 static const char* PROPERTY__EHS_SHIFT; 00079 00081 00084 00087 EmpiricalHSShiftProcessor(); 00088 00091 virtual ~EmpiricalHSShiftProcessor(); 00092 00094 00097 00130 virtual void init(); 00131 00133 00136 00142 virtual bool start(); 00143 00144 00157 virtual Processor::Result operator () (Composite& composite); 00158 00176 virtual bool finish(); 00177 00179 00182 00183 Options options; 00184 00187 void setDefaultOptions(); 00189 00190 protected: 00191 00192 00193 /*_ Neested class providing atom properties for the shift computations 00194 * */ 00195 class BALL_EXPORT PropertiesForShift_ 00196 { 00197 public: 00198 00201 PropertiesForShift_(int verbosity_ = EmpiricalHSShiftProcessor::VERBOSITY_LEVEL_CRITICAL); 00202 00205 Atom* current_atom; 00206 00223 bool computeProperties_(Atom* atom, std::set<String> properties); 00224 00236 std::pair<float, String> operator [] (const String& property_name); 00237 00242 static bool isDiscrete(String property); 00243 00247 static bool isMixed(String property); 00248 00249 protected: 00250 00251 // Storing the atoms properties 00252 // ...as numerical value 00253 std::map<String, float> properties_real_; 00254 // ... as alphanumerical/discrete value 00255 std::map<String, String> properties_string_; 00256 00257 protected: 00258 00259 float getChiAngle_(Residue* residue); 00260 float getChi2Angle_(Residue* residue); 00261 char getAminoAcid_(Residue* residue); 00262 char getSecondaryStructure_(Residue* residue); 00263 float getHA_HBondLen_(Residue* residue); 00264 float getHA2_HBondLen_(Residue* residue); 00265 float getHN_HBondLen_(Residue* residue); 00266 float getO_HBondLen_(Residue* residue); 00267 bool hasDisulfidBond_(Residue* residue); 00268 bool hasHA_HBond_(Residue* residue); 00269 bool hasHA2_HBond_(Residue* residue); 00270 bool hasHN_HBond_(Residue* residue); 00271 bool hasO_HBond_(Residue* residue); 00272 00273 private: 00274 // verbosity of the classes methods 00275 int verbosity_; 00276 }; // end of nested class 00277 00278 00279 /*_ Neested class handling the empirical hypersurfaces. 00280 **/ 00281 00282 class ShiftHyperSurface_ 00283 { 00284 public: 00285 typedef std::map<String, std::map<String, float> > tabletype; 00286 00290 00291 enum HYPERSURFACE__TYPE{ 00292 REAL__REAL, 00293 REAL__DISCRETE, 00294 DISCRETE__REAL, // not used 00295 DISCRETE__DISCRETE, 00296 CHI__REAL, // not used 00297 REAL__CHI, 00298 CHI__DISCRETE, 00299 DISCRETE__CHI, 00300 CHI__CHI, 00301 SINGLE__REAL, 00302 SINGLE__DISCRETE, 00303 SINGLE__CHI 00304 }; 00305 00306 /*_ Constructors and Destructors. 00307 */ 00308 ShiftHyperSurface_(int verbosity = EmpiricalHSShiftProcessor::VERBOSITY_LEVEL_CRITICAL); 00309 00310 /*_ Detailed constructor. 00311 * Creates a ShiftHyperSurface given the <b>filename<\b> of the data file, 00312 * the atom type, and the two property types according to its deduced 00313 * hypersurface types (see {\tt HYPERSURFACE__TYPE()}). 00314 * 00315 * If the data file cannot be found, no hypersurface is created. 00316 * 00317 * In the special case that the two properties have the same type, we create just one table entry in 00318 * {\tt table_} or just one spline { \tt in s1d_ }. 00319 * 00320 * In case of hypersurfaces of type {\tt REAL__DISCRETE} the splines default values are set to the 00321 * row-averages if given specified in the datafile. 00322 * 00323 * In case of hypersurfaces of type {\tt REAL__CHI, REAL__REAL } the splines default values are 00324 * set to the splines averages. 00325 * 00326 * In all cases but look-up tables the bounds for the splines are set as specified in 00327 * the datafile if specified. 00328 * 00329 * Note: 00330 * The spline or value can be accessed 00331 * by the {\tt operator () } given __not__ the property-value, but the property name. 00332 * 00333 */ 00334 ShiftHyperSurface_(String filename, String atomtype, 00335 String firstproperty, String secondproperty, 00336 int verbosity = EmpiricalHSShiftProcessor::VERBOSITY_LEVEL_CRITICAL) 00337 throw(Exception::FileNotFound); 00338 00341 virtual ~ShiftHyperSurface_(); 00342 00352 float operator () (PropertiesForShift_& properties); 00353 00357 bool isvalid(){return !invalid_;} 00358 00359 // Returns the total average given in the input file. 00360 float getTotalAverage() {return average_;} 00361 00362 private: 00363 00364 // Computes the average of the look-up table values. 00365 float getTableAverage_(); 00366 00367 // Computes the row average of the look-up table given a row name. 00368 float getTableRowAverage_(const std::map<String, float>& row); 00369 00370 // Computes the column average of the look-up table given a column name. 00371 float getTableColumnAverage_(const String& name); 00372 00377 bool tableHasColumn_(const String& name) ; 00378 00398 void parseDataFile_(BALL::File& file, String filename) ; 00399 00400 // Method to convert a vector of strings into a vector of floats {/tt output}. 00401 void convertToReal_(const vector<String>& input, vector<float>& output); 00402 00406 void setType_(String firstproperty, String secondproperty); 00407 00408 // The type of the hypersurface. 00409 int type_; 00410 00411 // The properties of the hypersurface. 00412 String first_property_; 00413 String second_property_; 00414 00415 // The hypersurface can be a 2D spline, 1D spline or a look-up table. 00416 CubicSpline2D s2d_; 00417 std::map <String, CubicSpline1D > s1d_; 00418 // Note: access of the look--up table: first the discrete key x, second the numerical key y. 00419 std::map <String, std::map<String, float> > table_; 00420 00421 // The averages of the hypersurface as read from the file. 00422 // //TODO rename to row_defaults 00423 std::map <String, float> row_averages_; 00424 std::map <String, float> col_averages_; 00425 00426 // The spacing in x and y direction as read from the file. 00427 float row_spacing_; 00428 float col_spacing_; 00429 00430 // Flag to store whether the spline we created is valid. 00431 bool invalid_; 00432 00433 // The average over the complete hypersurface as read from the file. 00434 // Note: this average maybe weighted in non-obvious ways! 00435 float average_; 00436 00437 // verbosity of the method 00438 int verbosity_; 00439 00440 // The underlying data of the hypersurface as read from the file. 00441 vector<String> y_axis_values_; 00442 vector<vector<String> > x_axis_values_; 00443 vector<vector<float> > sample_values_; 00444 }; 00445 00446 00447 00448 00449 /*_ The target atoms collected by {\tt operator ()}. 00450 */ 00451 std::vector<PropertiesForShift_> targets_; 00452 00453 /*_ The target atom types stored as a vector of strings collected from the ini-file 00454 * by {\tt init ()}. 00455 */ 00456 vector<String> target_names_; 00457 00458 /*_ The target properties used for determine the 00459 * empirical hypersurface shifts. The properties are collected 00460 * from the ini-file by {\tt init ()} and are stored per target atom 00461 * in the same order as the target_names. 00462 */ 00463 vector< std::set<String> > target_property_names_; 00464 00465 /*_ The file names of the files storing the property-data-splines for computing the 00466 * shift contributions are stored in a map, whose key is the pair of 00467 * properties, to which the splines belong. 00468 * The maps are stored per target atom type in the same order as the target_names. 00469 * The files are specified in the section {\tt EmpiricalShiftHyperSurfaces} 00470 * of the file {\tt ShiftX.ini} and are collected by {\tt init ()}. 00471 */ 00472 vector< std::map< std::pair<String, String>, String > > property_files_; 00473 00474 /*_ The property pairs for each atom type are stored in this map. 00475 * The map is created in {\tt init ()}. 00476 **/ 00477 std::map< String, vector< std::pair<String, String> > > property_pairs_; 00478 00479 /*_ The hypersurfaces are precomputed by {\tt init()} 00480 * and then are stored per atom type in a map with key atom_type of 00481 * maps with the property pair as key. 00482 */ 00483 00484 std::map<String, std::map <std::pair<String, String>,EmpiricalHSShiftProcessor::ShiftHyperSurface_> > hypersurfaces_; 00485 00486 /*_ Option to exclude prolins from the shift computations. 00487 Default is false. 00488 */ 00489 bool exclude_prolins_; 00490 00491 // Map containing possible correction terms for ssbonds. 00492 std::map<String, float> ssbond_correction_; 00493 00494 private: 00495 00496 /*_ Some debugging functions printing parameter/effector/target information 00497 * to the Log stream. 00498 */ 00499 void printParameters_(); 00500 void printTargets_(); 00501 00502 /*_ A function to perform some ShiftX-y postprocessing: 00503 add for all CA-atoms 0.2 times the EF-shift-value of the bound HA-atoms. 00504 Due to some reason ShiftX does not perform this postprocessing 00505 for the empirical Hypersurface contributions. 00506 */ 00507 void postprocessing_(); 00508 00510 int verbosity_; 00511 00512 };// end of class 00513 } // end of namespace 00514 #endif // BALL_NMR_EMPIRICALHSSHIFTPROCESSOR_H