[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] | 51 | bool 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 | };
|
---|