Changeset 435065 for src


Ignore:
Timestamp:
Mar 2, 2011, 9:48:20 PM (14 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
341f22
Parents:
eb33c4
Message:

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).
Location:
src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/VerletIntegrationAction.cpp

    reb33c4 r435065  
    2020#include "CodePatterns/MemDebug.hpp"
    2121
     22#include "atom.hpp"
     23#include "AtomSet.hpp"
    2224#include "CodePatterns/Log.hpp"
     25#include "CodePatterns/Verbose.hpp"
     26#include "Dynamics/VerletForceIntegration.hpp"
    2327#include "molecule.hpp"
    24 #include "CodePatterns/Verbose.hpp"
    2528#include "World.hpp"
    2629
     30#include <vector>
    2731#include <iostream>
    2832#include <fstream>
     
    3842/** =========== define the function ====================== */
    3943Action::state_ptr MoleculeVerletIntegrationAction::performCall() {
    40   molecule *mol = NULL;
    41 
    4244  // obtain information
    4345  getParametersfromValueStorage();
    4446
    45   for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
    46     mol = iter->second;
    47     DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl);
    48     // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
    49     char outputname[MAXSTRINGSIZE];
    50     strcpy(outputname, params.forcesfile.string().c_str());
    51     if (!mol->VerletForceIntegration(outputname, *(World::getInstance().getConfig()), 0))
     47
     48  DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl);
     49  // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
     50  char outputname[MAXSTRINGSIZE];
     51  strcpy(outputname, params.forcesfile.string().c_str());
     52  AtomSetMixin<std::vector<atom *> > set(World::getInstance().getSelectedAtoms());
     53  for (int step = 0; step < params.MDSteps; ++step) {
     54    VerletForceIntegration<std::vector<atom *> > Verlet(set, params.Deltat, step, false);
     55    if (!Verlet(outputname, 1, 0, params.FixedCenterOfMass))
    5256      DoLog(2) && (Log() << Verbose(2) << "File " << params.forcesfile << " not found." << endl);
    5357    else
    5458      DoLog(2) && (Log() << Verbose(2) << "File " << params.forcesfile << " found and parsed." << endl);
    5559  }
     60
    5661  return Action::success;
    5762}
  • src/Actions/MoleculeAction/VerletIntegrationAction.def

    reb33c4 r435065  
    1212// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1313// "undefine" if no parameters are required, use (NODEFAULT) for each (undefined) default value
    14 #define paramtypes (boost::filesystem::path)
    15 #define paramtokens ("verlet-integration")
    16 #define paramdescriptions ("perform verlet integration of a given force file")
     14#define paramtypes (boost::filesystem::path)(double)(int)(bool)
     15#define paramtokens ("verlet-integration")("deltat")("MDSteps")("keep-fixed-CenterOfMass")
     16#define paramdescriptions ("perform verlet integration of a given force file")("time step width")("number of MDSteps to integrate")("whether forces and velocities shall be corrected such that center of mass remains at rest")
    1717#undef paramdefaults
    18 #define paramreferences (forcesfile)
     18#define paramreferences (forcesfile)(Deltat)(MDSteps)(FixedCenterOfMass)
    1919
    2020#undef statetypes
  • src/Makefile.am

    reb33c4 r435065  
    125125        Dynamics/LinearInterpolationBetweenSteps.hpp \
    126126        Dynamics/MinimiseConstrainedPotential.hpp \
    127         Dynamics/OutputTemperature.hpp
     127        Dynamics/OutputTemperature.hpp \
     128        Dynamics/VerletForceIntegration.hpp
    128129
    129130GRAPHSOURCE = \
  • src/atom_atominfo.cpp

    reb33c4 r435065  
    3030#include "atom_atominfo.hpp"
    3131
     32#include <iomanip>
     33
    3234/** Constructor of class AtomInfo.
    3335 */
     
    492494 * Parameters are according to those in configuration class.
    493495 * \param NextStep index of sequential step to set
    494  * \param *configuration pointer to configuration with parameters
     496 * \param Deltat time step width
     497 * \param IsAngstroem whether the force's underlying unit of length is angstroem or bohr radii
    495498 * \param *Force matrix with forces
    496499 */
    497 void AtomInfo::VelocityVerletUpdate(int nr, const unsigned int NextStep, config *configuration, ForceMatrix *Force, const size_t offset)
    498 {
     500void AtomInfo::VelocityVerletUpdate(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem, ForceMatrix *Force, const size_t offset)
     501{
     502  LOG(2, "INFO: Particle that currently " << *this);
     503  LOG(2, "INFO: Integrating with mass=" << getMass() << " and Deltat="
     504      << Deltat << " at NextStep=" << NextStep);
    499505  // update force
    500506  // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a
    501507  Vector tempVector;
    502   for (int d=0; d<NDIM; d++)
    503     tempVector[d] = -Force->Matrix[0][nr][d+offset]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);
     508  for (int d=0; d<NDIM; d++) {
     509    ASSERT(Force->RowCounter[0] > nr,
     510        "AtomInfo::VelocityVerletUpdate() - "+toString(nr)
     511        +" out of bounds [0,"+toString(Force->RowCounter[0])
     512        +"] access on force matrix.");
     513    ASSERT(Force->ColumnCounter[0] > d+offset,
     514        "AtomInfo::VelocityVerletUpdate() - "+toString(d+offset)
     515        +" out of bounds [0,"+toString(Force->ColumnCounter[0])
     516        +"] access on force matrix.");
     517    tempVector[d] = -Force->Matrix[0][nr][d+offset]*(IsAngstroem ? AtomicLengthToAngstroem : 1.);
     518  }
     519  LOG(3, "INFO: Force at step " << NextStep << " set to " << tempVector);
    504520  setAtomicForceAtStep(NextStep, tempVector);
    505521
    506522  // update position
    507523  tempVector = getPositionAtStep(NextStep-1);
    508   tempVector += configuration->Deltat*(getAtomicVelocityAtStep(NextStep-1));     // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
    509   tempVector += 0.5*configuration->Deltat*configuration->Deltat*(getAtomicForceAtStep(NextStep))*(1./getMass());     // F = m * a and s =
     524  LOG(4, "INFO: initial position from last step " << setprecision(4) << tempVector);
     525  tempVector += Deltat*(getAtomicVelocityAtStep(NextStep-1));     // s(t) = s(0) + v * deltat + 1/2 a * deltat^2
     526  LOG(4, "INFO: position with velocity " << getAtomicVelocityAtStep(NextStep-1) << " from last step " << tempVector);
     527  tempVector += 0.5*Deltat*Deltat*(getAtomicForceAtStep(NextStep))*(1./getMass());     // F = m * a and s =
     528  LOG(4, "INFO: position with force " << getAtomicForceAtStep(NextStep) << " from last step " << tempVector);
    510529  setPositionAtStep(NextStep, tempVector);
     530  LOG(3, "INFO: Position at step " << NextStep << " set to " << tempVector);
    511531
    512532  // Update U
    513533  tempVector = getAtomicVelocityAtStep(NextStep-1);
    514   tempVector += configuration->Deltat * (getAtomicForceAtStep(NextStep)+getAtomicForceAtStep(NextStep-1))*(1./getMass()); // v = F/m * t
     534  LOG(4, "INFO: initial velocity from last step " << tempVector);
     535  tempVector += Deltat * (getAtomicForceAtStep(NextStep)+getAtomicForceAtStep(NextStep-1))*(1./getMass()); // v = F/m * t
     536  LOG(4, "INFO: Velocity with force from last " << getAtomicForceAtStep(NextStep-1)
     537      << " and present " << getAtomicForceAtStep(NextStep) << " step " << tempVector);
    515538  setAtomicVelocityAtStep(NextStep, tempVector);
    516 
    517   // some info for debugging
    518   DoLog(2) && (Log() << Verbose(2)
    519       << "Integrated position&velocity of step " << (NextStep) << ": ("
    520       << getPositionAtStep(NextStep) << ")\t("
    521       << getAtomicVelocityAtStep(NextStep) << ")" << std::endl);
     539  LOG(3, "INFO: Velocity at step " << NextStep << " set to " << tempVector);
    522540};
    523541
  • src/atom_atominfo.hpp

    reb33c4 r435065  
    2727
    2828class AtomInfo;
    29 class config;
    3029class element;
    3130class ForceMatrix;
     
    242241  size_t getTrajectorySize() const;
    243242  void CopyStepOnStep(const unsigned int dest, const unsigned int src);
    244   void VelocityVerletUpdate(int nr, const unsigned int MDSteps, config *configuration, ForceMatrix *Force, const size_t offset);
     243  void VelocityVerletUpdate(int nr, const unsigned int NextStep, double Deltat, bool IsAngstroem, ForceMatrix *Force, const size_t offset);
    245244  double getKineticEnergy(const unsigned int step) const;
    246245  Vector getMomentum(const unsigned int step) const;
  • src/molecule.hpp

    reb33c4 r435065  
    176176  void SetBoxDimension(Vector *dim);
    177177  bool ScanForPeriodicCorrection();
    178   bool VerletForceIntegration(char *file, config &configuration, const size_t offset);
    179178  double VolumeOfConvexEnvelope(bool IsAngstroem);
    180179  RealSpaceMatrix getInertiaTensor() const;
  • src/molecule_dynamics.cpp

    reb33c4 r435065  
    3939
    4040
    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  */
    51 bool 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 TracChangeset for help on using the changeset viewer.