00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef BALL_MOLMEC_MINIMIZATION_ENERGYMINIMIZER_H
00010 #define BALL_MOLMEC_MINIMIZATION_ENERGYMINIMIZER_H
00011
00012 #ifndef BALL_DATATYPE_OPTIONS_H
00013 # include <BALL/DATATYPE/options.h>
00014 #endif
00015
00016 #ifndef BALL_MOLMEC_COMMON_GRADIENT_H
00017 # include <BALL/MOLMEC/COMMON/gradient.h>
00018 #endif
00019
00020 namespace BALL
00021 {
00022 class ForceField;
00023 class SnapShotManager;
00024
00029 class BALL_EXPORT EnergyMinimizer
00030 {
00031 public:
00032
00036
00039 struct BALL_EXPORT Option
00040 {
00043 static const char* MAXIMAL_NUMBER_OF_ITERATIONS;
00044
00047 static const char* ENERGY_OUTPUT_FREQUENCY;
00048
00051 static const char* SNAPSHOT_FREQUENCY;
00052
00055 static const char* NUMBER_OF_ITERATION;
00056
00059 static const char* ENERGY_DIFFERENCE_BOUND;
00060
00064 static const char* MAX_SAME_ENERGY;
00065
00069 static const char* MAX_GRADIENT;
00070
00073 static const char* MAXIMUM_DISPLACEMENT;
00074 };
00075
00076 struct BALL_EXPORT Default
00077 {
00080 static Size MAXIMAL_NUMBER_OF_ITERATIONS;
00081
00084 static Size ENERGY_OUTPUT_FREQUENCY;
00085
00088 static Size SNAPSHOT_FREQUENCY;
00089
00092 static Size NUMBER_OF_ITERATION;
00093
00097 static float ENERGY_DIFFERENCE_BOUND;
00098
00103 static Size MAX_SAME_ENERGY;
00104
00108 static float MAX_GRADIENT;
00109
00112 static float MAXIMUM_DISPLACEMENT;
00113 };
00114
00116
00119
00120 BALL_CREATE(EnergyMinimizer)
00121
00122
00124 EnergyMinimizer();
00125
00128 EnergyMinimizer(ForceField& force_field);
00129
00132 EnergyMinimizer(ForceField& force_field, const Options& options);
00133
00136 EnergyMinimizer(const EnergyMinimizer& energy_minimizer);
00137
00140 virtual ~EnergyMinimizer();
00141
00143
00146
00149 const EnergyMinimizer& operator=(const EnergyMinimizer& energy_minimizer);
00150
00152
00155 bool operator == (const EnergyMinimizer& energy_minimizer) ;
00156
00160
00163 bool isValid() const;
00164
00166
00169
00172 bool setup(ForceField& force_field);
00173
00176 bool setup(ForceField& force_field, SnapShotManager *ssm);
00177
00180 bool setup(ForceField& force_field,
00181 SnapShotManager *ssm, const Options& options);
00182
00185 bool setup(ForceField& force_field, const Options& options);
00186
00189 virtual bool specificSetup();
00190
00192
00195
00208 virtual bool isConverged() const;
00209
00218 virtual double findStep();
00219
00224 virtual void updateDirection();
00225
00230 virtual double updateEnergy();
00231
00236 virtual void updateForces();
00237
00243 void storeGradientEnergy();
00244
00252 virtual void printEnergy() const;
00253
00262 virtual void takeSnapShot() const;
00263
00282 virtual void finishIteration();
00283
00286 Size getNumberOfIterations() const;
00287
00290 Gradient& getDirection();
00291
00294 Gradient& getGradient();
00295
00298 Gradient& getInitialGradient();
00299
00302 double getEnergy() const;
00303
00306 double& getEnergy();
00307
00310 double getInitialEnergy() const;
00311
00314 double& getInitialEnergy();
00315
00318 void setNumberOfIterations(Size number_of_iterations);
00319
00322 Size getMaxNumberOfIterations() const;
00323
00326 void setMaxNumberOfIterations(Size number_of_iterations);
00327
00331 void setMaxSameEnergy(Size number);
00332
00336 Size getMaxSameEnergy() const;
00337
00340 void setEnergyOutputFrequency(Size energy_output_frequency);
00341
00344 Size getEnergyOutputFrequency() const;
00345
00348 void setEnergyDifferenceBound(float energy_difference_bound);
00349
00352 float getEnergyDifferenceBound() const;
00353
00357 void setMaxGradient(float max_gradient);
00358
00362 float getMaxGradient() const;
00363
00367 void setMaximumDisplacement(float maximum_displacement);
00368
00371 float getMaximumDisplacement() const;
00372
00375 void setSnapShotFrequency(Size snapshot_frequency);
00376
00379 Size getSnapShotFrequency() const;
00380
00383 ForceField* getForceField();
00384
00387 Size getForceUpdateCounter() const ;
00388
00391 Size getEnergyUpdateCounter() const ;
00392
00404 virtual bool minimize(Size steps = 0, bool resume = false);
00405
00408 void enableEnergyAbortCondition(bool state);
00409
00411 bool energyAbortConditionEnabled() const;
00412
00417 void setEnergyToAbort(float value);
00418
00420 float getEnergyToAbort() const;
00421
00425 bool wasAborted() const ;
00426
00428
00431
00434 Options options;
00436
00437 protected:
00438
00442
00445 Gradient initial_grad_;
00446
00449 Gradient current_grad_;
00450
00453 double initial_energy_;
00454
00457 double current_energy_;
00458
00461 Gradient old_grad_;
00462
00465 double old_energy_;
00466
00469 Gradient direction_;
00470
00473 bool valid_;
00474
00477 SnapShotManager* snapshot_;
00478
00483 ForceField* force_field_;
00484
00487 Size number_of_iterations_;
00488
00491 Size maximal_number_of_iterations_;
00492
00495 Size energy_output_frequency_;
00496
00499 Size snapshot_frequency_;
00500
00504 double energy_difference_bound_;
00505
00508 double max_gradient_;
00509
00514 Size max_same_energy_;
00515
00518 Size same_energy_counter_;
00519
00522 float maximum_displacement_;
00523
00527 Size force_update_counter_;
00528
00532 Size energy_update_counter_;
00533
00537 float cutlo_;
00538
00542 double step_;
00543
00544
00545 bool abort_by_energy_enabled_;
00546
00547
00548 float abort_energy_;
00549
00550
00551 bool aborted_;
00552
00553
00554 };
00555
00556 }
00557
00558 #endif // BALL_MOLMEC_MINIMIZATION_ENERGYMINIMIZER_H