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
RevLine 
[bcf653]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
[cee0b57]8/*
9 * molecule_dynamics.cpp
10 *
11 * Created on: Oct 5, 2009
12 * Author: heber
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[ad011c]20#include "CodePatterns/MemDebug.hpp"
[112b09]21
[cbc5fb]22#include "World.hpp"
[f66195]23#include "atom.hpp"
[cee0b57]24#include "config.hpp"
[9e23a3]25#include "Dynamics/MinimiseConstrainedPotential.hpp"
26//#include "element.hpp"
[ad011c]27#include "CodePatterns/Info.hpp"
[9e23a3]28//#include "CodePatterns/Verbose.hpp"
29//#include "CodePatterns/Log.hpp"
[cee0b57]30#include "molecule.hpp"
[f66195]31#include "parser.hpp"
[9e23a3]32//#include "LinearAlgebra/Plane.hpp"
[a3fded]33#include "ThermoStatContainer.hpp"
[14c57a]34#include "Thermostats/Berendsen.hpp"
[cee0b57]35
[ad011c]36#include "CodePatterns/enumeration.hpp"
[a0064e]37
[cee0b57]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
[ef7d30]47 * \param offset offset in matrix file to the first force component
[cee0b57]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 */
[ef7d30]51bool molecule::VerletForceIntegration(char *file, config &configuration, const size_t offset)
[cee0b57]52{
[c7a473]53 Info FunctionInfo(__func__);
[cee0b57]54 string token;
55 stringstream item;
[4a7776a]56 double IonMass, ConstrainedPotentialEnergy, ActualTemp;
57 Vector Velocity;
[cee0b57]58 ForceMatrix Force;
59
[ef7d30]60 const int AtomCount = getAtomCount();
[4e855e]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();
[cee0b57]66 return false;
[4e855e]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];
[cee0b57]79 }
[4e855e]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);
[cee0b57]83 }
[4e855e]84 // solve a constrained potential if we are meant to
85 if (configuration.DoConstrainedMD) {
86 // calculate forces and potential
[e355762]87 std::map<atom*, atom *> PermutationMap;
88 MinimiseConstrainedPotential Minimiser(atoms, PermutationMap);
[9e23a3]89 //double ConstrainedPotentialEnergy =
[e355762]90 Minimiser(configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
[9e23a3]91 Minimiser.EvaluateConstrainedForces(&Force);
[cee0b57]92 }
[4e855e]93
94 // and perform Verlet integration for each atom with position, velocity and force vector
95 // check size of vectors
[6625c3]96 BOOST_FOREACH(atom *_atom, atoms) {
[735b1c]97 _atom->VelocityVerletUpdate(_atom->getNr(), MDSteps+1, &configuration, &Force, (const size_t) 0);
[6625c3]98 }
[4e855e]99
[cee0b57]100 // correct velocities (rather momenta) so that center of mass remains motionless
[259b2b]101 Velocity = atoms.totalMomentumAtStep(MDSteps+1);
102 IonMass = atoms.totalMass();
[4a7776a]103
[cee0b57]104 // correct velocities (rather momenta) so that center of mass remains motionless
[5cd333c]105 Velocity *= 1./IonMass;
[259b2b]106
107 atoms.addVelocityAtStep(-1*Velocity,MDSteps+1);
108 ActualTemp = atoms.totalTemperatureAtStep(MDSteps+1);
[14c57a]109 Berendsen berendsen = Berendsen();
[1bfc8e]110 berendsen.addToContainer(World::getInstance().getThermostats());
[14c57a]111 double ekin = berendsen.scaleAtoms(MDSteps,ActualTemp,atoms);
112 DoLog(1) && (Log() << Verbose(1) << "Kinetic energy is " << ekin << "." << endl);
[cee0b57]113 MDSteps++;
114
115 // exit
116 return true;
117};
Note: See TracBrowser for help on using the repository browser.