Changeset 51cdfd


Ignore:
Timestamp:
Aug 20, 2014, 12:58:28 PM (10 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:
442495
Parents:
343c5a
git-author:
Frederik Heber <heber@…> (08/20/14 12:50:41)
git-committer:
Frederik Heber <heber@…> (08/20/14 12:58:28)
Message:

Extracted common functions from VerletForceIntegration into AtomicForceManipulator.

Location:
src
Files:
1 added
5 edited

Legend:

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

    r343c5a r51cdfd  
    5858/** =========== define the function ====================== */
    5959ActionState::ptr MoleculeVerletIntegrationAction::performCall() {
    60   // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
    6160  AtomSetMixin<std::vector<atom *> > set(World::getInstance().getSelectedAtoms());
     61  if (set.empty()) {
     62    LOG(0, "STATUS: No atoms selected.");
     63    return Action::failure;
     64  }
    6265  // we always operate relative to current time step
    6366  size_t CurrentStep = WorldTime::getInstance().getTime();
     
    7275  }
    7376  // perform velocity verlet update
    74   LOG(1, "Verlet integrating.");
    75   if (!Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get()))
     77  bool status = Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get());
     78  if (!status) {
    7679    ELOG(1, "Velocity verlet failed.");
    77   else
     80    return Action::failure;
     81  } else {
    7882    LOG(2, "DEBUG: Successfully performed updates on velocity and position.");
    79   // increment to next time step
    80   World::getInstance().setTime(CurrentStep+1);
    81 
     83    // increment to next time step
     84    World::getInstance().setTime(CurrentStep+1);
     85  }
    8286  return Action::success;
    8387}
  • src/Dynamics/MinimiseConstrainedPotential.cpp

    r343c5a r51cdfd  
    176176
    177177  return ConstrainedPotential();
    178 };
     178}
    179179
    180180void MinimiseConstrainedPotential::FillDistanceList()
  • src/Dynamics/MinimiseConstrainedPotential.hpp

    r343c5a r51cdfd  
    4141  ~MinimiseConstrainedPotential();
    4242
    43   /** Minimises the extra potential for constrained molecular dynamics and gives forces and the constrained potential energy.
     43  /** Minimizes the extra potential for constrained molecular dynamics and gives forces and the constrained potential energy.
    4444   * We do the following:
    4545   *  -# Generate a distance list from all source to all target points
  • src/Dynamics/VerletForceIntegration.hpp

    r343c5a r51cdfd  
    2020#include "CodePatterns/Log.hpp"
    2121#include "CodePatterns/Verbose.hpp"
    22 #include "Dynamics/MinimiseConstrainedPotential.hpp"
     22#include "Dynamics/AtomicForceManipulator.hpp"
    2323#include "Fragmentation/ForceMatrix.hpp"
    2424#include "Helpers/helpers.hpp"
     
    3030
    3131template <class T>
    32 class VerletForceIntegration
     32class VerletForceIntegration : public AtomicForceManipulator<T>
    3333{
    3434public:
     
    4040   */
    4141  VerletForceIntegration(AtomSetMixin<T> &_atoms, double _Deltat, bool _IsAngstroem) :
    42     Deltat(_Deltat),
    43     IsAngstroem(_IsAngstroem),
    44     atoms(_atoms)
     42    AtomicForceManipulator<T>(_atoms, _Deltat, _IsAngstroem)
    4543  {}
    4644  /** Destructor of class VerletForceIntegration.
     
    4947  ~VerletForceIntegration()
    5048  {}
    51 
    52   /** Parses nuclear forces from file.
    53    * Forces are stored in the time step \a TimeStep in the atomicForces in \a atoms.
    54    * \param *file filename
    55    * \param TimeStep time step to parse forces file into
    56    * \return true - file parsed, false - file not found or imparsable
    57    */
    58   bool parseForcesFile(const char *file, const int TimeStep)
    59   {
    60     Info FunctionInfo(__func__);
    61     ForceMatrix Force;
    62 
    63     // parse file into ForceMatrix
    64     std::ifstream input(file);
    65     if ((input.good()) && (!Force.ParseMatrix(input, 0,0,0))) {
    66       ELOG(0, "Could not parse Force Matrix file " << file << ".");
    67       return false;
    68     }
    69     input.close();
    70     if (Force.RowCounter[0] != (int)atoms.size()) {
    71       ELOG(0, "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << atoms.size() << ".");
    72       return false;
    73     }
    74 
    75     addForceMatrixToAtomicForce(Force, TimeStep, 1);
    76     return true;
    77   }
    7849
    7950  /** Performs Verlet integration.
     
    9465    Info FunctionInfo(__func__);
    9566
    96     // check that atoms are present at all
    97     if (atoms.size() == 0) {
    98       ELOG(2, "VerletForceIntegration::operator() - no atoms to integrate.");
    99       return false;
    100     }
    101 
    10267    // make sum of forces equal zero
    10368    if (FixedCenterOfMass)
    104       correctForceMatrixForFixedCenterOfMass(offset,NextStep-1);
     69      AtomicForceManipulator<T>::correctForceMatrixForFixedCenterOfMass(offset,NextStep-1);
    10570
    10671    // solve a constrained potential if we are meant to
    107     if (DoConstrainedMD)
    108       performConstraintMinimization(DoConstrainedMD,NextStep-1);
     72//    if (DoConstrainedMD)
     73//      performConstraintMinimization(DoConstrainedMD,NextStep-1);
    10974
    11075    if (NextStep > 0) {
    111       for(typename AtomSetMixin<T>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
     76      for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
     77          iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
    11278        //std::cout << "Id of atom is " << (*iter)->getId() << std::endl;
    113         (*iter)->VelocityVerletUpdateU((*iter)->getId(), NextStep-1, Deltat, IsAngstroem);
     79        (*iter)->VelocityVerletUpdateU(
     80            (*iter)->getId(),
     81            NextStep-1,
     82            AtomicForceManipulator<T>::Deltat,
     83            AtomicForceManipulator<T>::IsAngstroem);
    11484      }
    11585
    11686      // make sum of velocities equal zero
    11787      if (FixedCenterOfMass)
    118         correctVelocitiesForFixedCenterOfMass(NextStep-1);
     88        AtomicForceManipulator<T>::correctVelocitiesForFixedCenterOfMass(NextStep-1);
    11989
    12090      // thermostat
    121       performThermostatControl(NextStep-1);
     91      AtomicForceManipulator<T>::performThermostatControl(NextStep-1);
    12292    }
    12393
     
    12595    // and perform Verlet integration for each atom with position, velocity and force vector
    12696    // check size of vectors
    127     for(typename AtomSetMixin<T>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
     97    for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
     98        iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
    12899      //std::cout << "Id of atom is " << (*iter)->getId() << std::endl;
    129       (*iter)->VelocityVerletUpdateX((*iter)->getId(), NextStep, Deltat, IsAngstroem);
     100      (*iter)->VelocityVerletUpdateX(
     101          (*iter)->getId(),
     102          NextStep,
     103          AtomicForceManipulator<T>::Deltat,
     104          AtomicForceManipulator<T>::IsAngstroem);
    130105    }
    131106
    132107    // exit
    133108    return true;
    134   };
    135 
    136 private:
    137   void addForceMatrixToAtomicForce(const ForceMatrix &Force, const int &TimeStep, const int offset)
    138   {
    139     // place forces from matrix into atoms
    140     Vector tempVector;
    141     size_t i=0;
    142     for(typename AtomSetMixin<T>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter,++i) {
    143       for(size_t d=0;d<NDIM;d++) {
    144         tempVector[d] = Force.Matrix[0][i][d+offset]*(IsAngstroem ? AtomicLengthToAngstroem : 1.);
    145       }
    146       tempVector += (*iter)->getAtomicForceAtStep(TimeStep);
    147       (*iter)->setAtomicForceAtStep(TimeStep, tempVector);
    148     }
    149109  }
    150 
    151   void correctForceMatrixForFixedCenterOfMass(const size_t offset, const int &TimeStep) {
    152     Vector ForceVector;
    153     // correct Forces
    154     //std::cout << "Force before correction, " << Force << std::endl;
    155     ForceVector.Zero();
    156     for(typename AtomSetMixin<T>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
    157       ForceVector += (*iter)->getAtomicForceAtStep(TimeStep);
    158     }
    159     ForceVector.Scale(1./(double)atoms.size());
    160     //std::cout << "Force before second correction, " << Force << std::endl;
    161     for(typename AtomSetMixin<T>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
    162       const Vector tempVector = (*iter)->getAtomicForceAtStep(TimeStep) - ForceVector;
    163       (*iter)->setAtomicForceAtStep(TimeStep, tempVector);
    164     }
    165     LOG(3, "INFO: forces correct by " << ForceVector << "each.");
    166   }
    167 
    168   void correctVelocitiesForFixedCenterOfMass(const int &TimeStep) {
    169     Vector Velocity;
    170     double IonMass;
    171     // correct velocities (rather momenta) so that center of mass remains motionless
    172     Velocity = atoms.totalMomentumAtStep(TimeStep);
    173     IonMass = atoms.totalMass();
    174 
    175     // correct velocities (rather momenta) so that center of mass remains motionless
    176     Velocity *= 1./IonMass;
    177     atoms.addVelocityAtStep(-1.*Velocity,TimeStep);
    178 
    179     LOG(3, "INFO: Velocities corrected by " << Velocity << " each.");
    180   }
    181 
    182   void performConstraintMinimization(const int &DoConstrainedMD, const int &TimeStep) {
    183     // calculate forces and potential
    184     ForceMatrix Force;
    185     std::map<atom *, atom*> PermutationMap;
    186     MinimiseConstrainedPotential Minimiser(atoms, PermutationMap);
    187     //double ConstrainedPotentialEnergy =
    188     Minimiser(DoConstrainedMD, 0, IsAngstroem);
    189     Minimiser.EvaluateConstrainedForces(&Force);
    190     addForceMatrixToAtomicForce(Force, TimeStep, 1);
    191   }
    192 
    193   void performThermostatControl(const int &TimeStep) {
    194     double ActualTemp;
    195 
    196     // calculate current temperature
    197     ActualTemp = atoms.totalTemperatureAtStep(TimeStep);
    198     LOG(3, "INFO: Current temperature is " << ActualTemp);
    199 
    200     // rescale to desired value
    201     double ekin = World::getInstance().getThermostats()->getActive()->scaleAtoms(TimeStep,ActualTemp,atoms);
    202     ActualTemp = atoms.totalTemperatureAtStep(TimeStep);
    203     LOG(3, "INFO: New temperature after thermostat is " << ActualTemp);
    204     LOG(1, "Kinetic energy is " << ekin << ".");
    205   }
    206 
    207 private:
    208   double Deltat;
    209   bool IsAngstroem;
    210   AtomSetMixin<T> atoms;
    211110};
    212111
  • src/Makefile.am

    r343c5a r51cdfd  
    122122
    123123DYNAMICSHEADER = \
     124        Dynamics/AtomicForceManipulator.hpp \
    124125        Dynamics/LinearInterpolationBetweenSteps.hpp \
    125126        Dynamics/MinimiseConstrainedPotential.hpp \
Note: See TracChangeset for help on using the changeset viewer.