source: src/molecule_dynamics.cpp@ e355762

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

Rewrote MinimiseConstrainedPotential to just use std::map instead of arrays.

  • MinimiseConstrainedPotential::operator() needs std::Map<atom*,atom*> as parameter for PermutationMap.
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * molecule_dynamics.cpp
10 *
11 * Created on: Oct 5, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "World.hpp"
23#include "atom.hpp"
24#include "config.hpp"
25#include "Dynamics/MinimiseConstrainedPotential.hpp"
26//#include "element.hpp"
27#include "CodePatterns/Info.hpp"
28//#include "CodePatterns/Verbose.hpp"
29//#include "CodePatterns/Log.hpp"
30#include "molecule.hpp"
31#include "parser.hpp"
32//#include "LinearAlgebra/Plane.hpp"
33#include "ThermoStatContainer.hpp"
34#include "Thermostats/Berendsen.hpp"
35
36#include "CodePatterns/enumeration.hpp"
37
38/************************************* Functions for class molecule *********************************/
39
40
41/** Parses nuclear forces from file and performs Verlet integration.
42 * Note that we assume the parsed forces to be in atomic units (hence, if coordinates are in angstroem, we
43 * have to transform them).
44 * This adds a new MD step to the config file.
45 * \param *file filename
46 * \param config structure with config::Deltat, config::IsAngstroem, config::DoConstrained
47 * \param offset offset in matrix file to the first force component
48 * \return true - file found and parsed, false - file not found or imparsable
49 * \todo This is not yet checked if it is correctly working with DoConstrained set to true.
50 */
51bool molecule::VerletForceIntegration(char *file, config &configuration, const size_t offset)
52{
53 Info FunctionInfo(__func__);
54 string token;
55 stringstream item;
56 double IonMass, ConstrainedPotentialEnergy, ActualTemp;
57 Vector Velocity;
58 ForceMatrix Force;
59
60 const int AtomCount = getAtomCount();
61 // parse file into ForceMatrix
62 std::ifstream input(file);
63 if ((input.good()) && (!Force.ParseMatrix(input, 0,0,0))) {
64 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse Force Matrix file " << file << "." << endl);
65 performCriticalExit();
66 return false;
67 }
68 input.close();
69 if (Force.RowCounter[0] != AtomCount) {
70 DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << getAtomCount() << "." << endl);
71 performCriticalExit();
72 return false;
73 }
74 // correct Forces
75 Velocity.Zero();
76 for(int i=0;i<AtomCount;i++)
77 for(int d=0;d<NDIM;d++) {
78 Velocity[d] += Force.Matrix[0][i][d+offset];
79 }
80 for(int i=0;i<AtomCount;i++)
81 for(int d=0;d<NDIM;d++) {
82 Force.Matrix[0][i][d+offset] -= Velocity[d]/static_cast<double>(AtomCount);
83 }
84 // solve a constrained potential if we are meant to
85 if (configuration.DoConstrainedMD) {
86 // calculate forces and potential
87 std::map<atom*, atom *> PermutationMap;
88 MinimiseConstrainedPotential Minimiser(atoms, PermutationMap);
89 //double ConstrainedPotentialEnergy =
90 Minimiser(configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
91 Minimiser.EvaluateConstrainedForces(&Force);
92 }
93
94 // and perform Verlet integration for each atom with position, velocity and force vector
95 // check size of vectors
96 BOOST_FOREACH(atom *_atom, atoms) {
97 _atom->VelocityVerletUpdate(_atom->getNr(), MDSteps+1, &configuration, &Force, (const size_t) 0);
98 }
99
100 // correct velocities (rather momenta) so that center of mass remains motionless
101 Velocity = atoms.totalMomentumAtStep(MDSteps+1);
102 IonMass = atoms.totalMass();
103
104 // correct velocities (rather momenta) so that center of mass remains motionless
105 Velocity *= 1./IonMass;
106
107 atoms.addVelocityAtStep(-1*Velocity,MDSteps+1);
108 ActualTemp = atoms.totalTemperatureAtStep(MDSteps+1);
109 Berendsen berendsen = Berendsen();
110 berendsen.addToContainer(World::getInstance().getThermostats());
111 double ekin = berendsen.scaleAtoms(MDSteps,ActualTemp,atoms);
112 DoLog(1) && (Log() << Verbose(1) << "Kinetic energy is " << ekin << "." << endl);
113 MDSteps++;
114
115 // exit
116 return true;
117};
Note: See TracBrowser for help on using the repository browser.