source: src/Dynamics/VerletForceIntegration.hpp@ a9b86d

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

Split up modules parser.[ch]pp into one module per class.

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