source: src/Dynamics/VerletForceIntegration.hpp@ 5605793

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 5605793 was 435065, checked in by Frederik Heber <heber@…>, 14 years ago

Rewrote VerletForceIntegration into a functor in Dynamics/.

  • we now have the regression test working with checking against an integrated file which has not been checked though (just by eye and logged output to make sense, not against other code).
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * VerletForceIntegration.hpp
3 *
4 * Created on: Feb 23, 2011
5 * Author: heber
6 */
7
8#ifndef VERLETFORCEINTEGRATION_HPP_
9#define VERLETFORCEINTEGRATION_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include "atom.hpp"
17#include "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/MinimiseConstrainedPotential.hpp"
23#include "LinearAlgebra/Vector.hpp"
24#include "parser.hpp"
25#include "ThermoStatContainer.hpp"
26#include "Thermostats/Berendsen.hpp"
27#include "World.hpp"
28
29template <class T>
30class VerletForceIntegration
31{
32public:
33 VerletForceIntegration(AtomSetMixin<T> &_atoms, double _Deltat, int _startstep, bool _IsAngstroem) :
34 Deltat(_Deltat),
35 IsAngstroem(_IsAngstroem),
36 atoms(_atoms),
37 MDSteps(_startstep)
38 {}
39 ~VerletForceIntegration()
40 {}
41
42 /** Parses nuclear forces from file and performs Verlet integration.
43 * Note that we assume the parsed forces to be in atomic units (hence, if coordinates are in angstroem, we
44 * have to transform them).
45 * This adds a new MD step to the config file.
46 * \param *file filename
47 * \param offset offset in matrix file to the first force component
48 * \param DoConstrainedMD whether a constrained MD shall be done
49 * \param FixedCenterOfMass whether forces and velocities are correct to have fixed center of mass
50 * \return true - file found and parsed, false - file not found or imparsable
51 * \todo This is not yet checked if it is correctly working with DoConstrainedMD set >0.
52 */
53 bool operator()(char *file, const size_t offset, int DoConstrainedMD, bool FixedCenterOfMass)
54 {
55 Info FunctionInfo(__func__);
56 string token;
57 stringstream item;
58 double IonMass, ActualTemp;
59 ForceMatrix Force;
60
61 const int AtomCount = atoms.size();
62 ASSERT(AtomCount != 0, "VerletForceIntegration::operator() - no atoms to integrate.");
63 // parse file into ForceMatrix
64 std::ifstream input(file);
65 if ((input.good()) && (!Force.ParseMatrix(input, 0,0,0))) {
66 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse Force Matrix file " << file << "." << endl);
67 performCriticalExit();
68 return false;
69 }
70 input.close();
71 if (Force.RowCounter[0] != AtomCount) {
72 DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << atoms.size() << "." << endl);
73 performCriticalExit();
74 return false;
75 }
76
77 if (FixedCenterOfMass) {
78 Vector ForceVector;
79 // correct Forces
80 //std::cout << "Force before correction, " << Force << std::endl;
81 ForceVector.Zero();
82 for(int i=0;i<AtomCount;i++)
83 for(int d=0;d<NDIM;d++) {
84 ForceVector[d] += Force.Matrix[0][i][d+offset];
85 }
86 ForceVector.Scale(1./static_cast<double>(AtomCount));
87 //std::cout << "Force before second correction, " << Force << std::endl;
88 for(int i=0;i<AtomCount;i++)
89 for(int d=0;d<NDIM;d++) {
90 Force.Matrix[0][i][d+offset] -= ForceVector[d];
91 }
92 LOG(3, "INFO: forces correct by " << ForceVector << "each.");
93 }
94
95 // solve a constrained potential if we are meant to
96 if (DoConstrainedMD) {
97 // calculate forces and potential
98 std::map<atom *, atom*> PermutationMap;
99 molecule::atomSet atoms_list;
100 copy(atoms.begin(), atoms.end(), atoms_list.begin());
101 MinimiseConstrainedPotential Minimiser(atoms_list, PermutationMap);
102 //double ConstrainedPotentialEnergy =
103 Minimiser(DoConstrainedMD, 0, IsAngstroem);
104 Minimiser.EvaluateConstrainedForces(&Force);
105 }
106
107 //std::cout << "Force before velocity verlet, " << Force << std::endl;
108 // and perform Verlet integration for each atom with position, velocity and force vector
109 // check size of vectors
110 for(typename AtomSetMixin<T>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
111 //std::cout << "Id of atom is " << (*iter)->getId() << std::endl;
112 (*iter)->VelocityVerletUpdate((*iter)->getId(), MDSteps+1, Deltat, IsAngstroem, &Force, (const size_t) 1);
113 }
114
115 if (FixedCenterOfMass) {
116 Vector Velocity;
117 // correct velocities (rather momenta) so that center of mass remains motionless
118 Velocity = atoms.totalMomentumAtStep(MDSteps+1);
119 IonMass = atoms.totalMass();
120
121 // correct velocities (rather momenta) so that center of mass remains motionless
122 Velocity *= 1./IonMass;
123 atoms.addVelocityAtStep(-1.*Velocity,MDSteps+1);
124
125 LOG(3, "INFO: Velocities corrected by " << Velocity << " each.");
126 }
127
128 // thermostat
129 ActualTemp = atoms.totalTemperatureAtStep(MDSteps+1);
130 LOG(3, "INFO: Current temperature is " << ActualTemp);
131 Berendsen berendsen = Berendsen();
132 berendsen.addToContainer(World::getInstance().getThermostats());
133 double ekin = berendsen.scaleAtoms(MDSteps,ActualTemp,atoms);
134 ActualTemp = atoms.totalTemperatureAtStep(MDSteps+1);
135 LOG(3, "INFO: New temperature after thermostat is " << ActualTemp);
136 DoLog(1) && (Log() << Verbose(1) << "Kinetic energy is " << ekin << "." << endl);
137
138 // next step
139 MDSteps++;
140
141 // exit
142 return true;
143 };
144
145private:
146 double Deltat;
147 bool IsAngstroem;
148 AtomSetMixin<T> atoms;
149 int MDSteps;
150};
151
152#endif /* VERLETFORCEINTEGRATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.