source: src/Dynamics/ForceAnnealing.hpp@ 7f833c

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 7f833c was 7f833c, checked in by Frederik Heber <heber@…>, 10 years ago

Giving the maximum components over all force vectors in ForceAnnealing.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * ForceAnnealing.hpp
3 *
4 * Created on: Aug 02, 2014
5 * Author: heber
6 */
7
8#ifndef FORCEANNEALING_HPP_
9#define FORCEANNEALING_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include "Atom/atom.hpp"
17#include "Atom/AtomSet.hpp"
18#include "CodePatterns/Assert.hpp"
19#include "CodePatterns/Info.hpp"
20#include "CodePatterns/Log.hpp"
21#include "CodePatterns/Verbose.hpp"
22#include "Dynamics/AtomicForceManipulator.hpp"
23#include "Fragmentation/ForceMatrix.hpp"
24#include "Helpers/helpers.hpp"
25#include "Helpers/defs.hpp"
26#include "LinearAlgebra/Vector.hpp"
27#include "Thermostats/ThermoStatContainer.hpp"
28#include "Thermostats/Thermostat.hpp"
29#include "World.hpp"
30
31/** This class is the essential build block for performing structual optimization.
32 *
33 * Sadly, we have to use some static instances as so far values cannot be passed
34 * between actions. Hence, we need to store the current step and the adaptive
35 * step width (we cannot perform a linesearch, as we have no control over the
36 * calculation of the forces).
37 */
38template <class T>
39class ForceAnnealing : public AtomicForceManipulator<T>
40{
41public:
42 /** Constructor of class ForceAnnealing.
43 *
44 * \param _atoms set of atoms to integrate
45 * \param _Deltat time step width in atomic units
46 * \param _IsAngstroem whether length units are in angstroem or bohr radii
47 * \param _maxSteps number of optimization steps to perform
48 */
49 ForceAnnealing(
50 AtomSetMixin<T> &_atoms,
51 double _Deltat,
52 bool _IsAngstroem,
53 const size_t _maxSteps) :
54 AtomicForceManipulator<T>(_atoms, _Deltat, _IsAngstroem),
55 maxSteps(_maxSteps)
56 {}
57 /** Destructor of class ForceAnnealing.
58 *
59 */
60 ~ForceAnnealing()
61 {}
62
63 /** Performs Gradient optimization.
64 *
65 * We assume that forces have just been calculated.
66 *
67 *
68 * \param NextStep current time step (i.e. \f$ t + \Delta t \f$ in the sense of the velocity verlet)
69 * \param offset offset in matrix file to the first force component
70 * \todo This is not yet checked if it is correctly working with DoConstrainedMD set >0.
71 */
72 void operator()(const int NextStep, const size_t offset)
73 {
74 // make sum of forces equal zero
75 AtomicForceManipulator<T>::correctForceMatrixForFixedCenterOfMass(offset,NextStep);
76
77 // are we in initial step? Then set static entities
78 if (currentStep == 0) {
79 currentDeltat = AtomicForceManipulator<T>::Deltat;
80 currentStep = 1;
81 LOG(2, "DEBUG: Initial step, setting values, current step is #" << currentStep);
82 } else {
83 ++currentStep;
84 LOG(2, "DEBUG: current step is #" << currentStep);
85 }
86
87 // are we in initial step? Then don't check against velocity
88 Vector maxComponents(zeroVec);
89 for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
90 iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
91 // atom's force vector gives steepest descent direction
92 const Vector currentPosition = (*iter)->getPosition();
93 const Vector currentGradient = (*iter)->getAtomicForce();
94 LOG(4, "DEBUG: Force for atom " << **iter << " is " << currentGradient);
95 Vector PositionUpdate = currentDeltat * currentGradient;
96 LOG(3, "DEBUG: Update would be " << PositionUpdate);
97
98 // extract largest components for showing progress of annealing
99 for(size_t i=0;i<NDIM;++i)
100 if (currentGradient[i] > maxComponents[i])
101 maxComponents[i] = currentGradient[i];
102
103 // update with currentDelta tells us how the current gradient relates to
104 // the last one: If it has become larger, reduce currentDelta
105 if ((currentStep > 1) && (!(*iter)->getAtomicVelocity().IsZero()))
106 if ((PositionUpdate.ScalarProduct((*iter)->getAtomicVelocity()) < 0)
107 && (currentDeltat > MinimumDeltat)) {
108 currentDeltat = .5*currentDeltat;
109 LOG(2, "DEBUG: Upgrade in other direction: " << PositionUpdate.NormSquared()
110 << " > " << (*iter)->getAtomicVelocity().NormSquared()
111 << ", decreasing deltat: " << currentDeltat);
112 PositionUpdate = currentDeltat * currentGradient;
113 }
114
115 // finally set new values
116 (*iter)->setPosition(currentPosition + PositionUpdate);
117 (*iter)->setAtomicVelocity(PositionUpdate);
118 //std::cout << "Id of atom is " << (*iter)->getId() << std::endl;
119// (*iter)->VelocityVerletUpdateU((*iter)->getId(), NextStep-1, Deltat, IsAngstroem);
120
121 // reset force vector for next step except on final one
122 if (currentStep != maxSteps)
123 (*iter)->setAtomicForce(zeroVec);
124 }
125
126 LOG(1, "STATUS: Largest remaining force components at step #"
127 << currentStep << " are " << maxComponents);
128
129 // are we in final step? Remember to reset static entities
130 if (currentStep == maxSteps) {
131 LOG(2, "DEBUG: Final step, resetting values");
132 currentDeltat = 0.;
133 currentStep = 0;
134
135 // reset (artifical) velocities
136 for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
137 iter != AtomicForceManipulator<T>::atoms.end(); ++iter)
138 (*iter)->setAtomicVelocity(zeroVec);
139 }
140 }
141
142private:
143 //!> contains the current step in relation to maxsteps
144 static size_t currentStep;
145 //!> contains the maximum number of steps, determines initial and final step with currentStep
146 size_t maxSteps;
147 static double currentDeltat;
148 //!> minimum deltat for internal while loop (adaptive step width)
149 static double MinimumDeltat;
150};
151
152template <class T>
153double ForceAnnealing<T>::currentDeltat = 0.;
154template <class T>
155size_t ForceAnnealing<T>::currentStep = 0;
156template <class T>
157double ForceAnnealing<T>::MinimumDeltat = 1e-8;
158
159#endif /* FORCEANNEALING_HPP_ */
Note: See TracBrowser for help on using the repository browser.