- Timestamp:
- Mar 2, 2011, 9:48:20 PM (14 years ago)
- 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
- Location:
- src
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/MoleculeAction/VerletIntegrationAction.cpp
reb33c4 r435065 20 20 #include "CodePatterns/MemDebug.hpp" 21 21 22 #include "atom.hpp" 23 #include "AtomSet.hpp" 22 24 #include "CodePatterns/Log.hpp" 25 #include "CodePatterns/Verbose.hpp" 26 #include "Dynamics/VerletForceIntegration.hpp" 23 27 #include "molecule.hpp" 24 #include "CodePatterns/Verbose.hpp"25 28 #include "World.hpp" 26 29 30 #include <vector> 27 31 #include <iostream> 28 32 #include <fstream> … … 38 42 /** =========== define the function ====================== */ 39 43 Action::state_ptr MoleculeVerletIntegrationAction::performCall() { 40 molecule *mol = NULL;41 42 44 // obtain information 43 45 getParametersfromValueStorage(); 44 46 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)) 52 56 DoLog(2) && (Log() << Verbose(2) << "File " << params.forcesfile << " not found." << endl); 53 57 else 54 58 DoLog(2) && (Log() << Verbose(2) << "File " << params.forcesfile << " found and parsed." << endl); 55 59 } 60 56 61 return Action::success; 57 62 } -
src/Actions/MoleculeAction/VerletIntegrationAction.def
reb33c4 r435065 12 12 // ValueStorage by the token "Z" -> first column: int, Z, "Z" 13 13 // "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") 17 17 #undef paramdefaults 18 #define paramreferences (forcesfile) 18 #define paramreferences (forcesfile)(Deltat)(MDSteps)(FixedCenterOfMass) 19 19 20 20 #undef statetypes -
src/Makefile.am
reb33c4 r435065 125 125 Dynamics/LinearInterpolationBetweenSteps.hpp \ 126 126 Dynamics/MinimiseConstrainedPotential.hpp \ 127 Dynamics/OutputTemperature.hpp 127 Dynamics/OutputTemperature.hpp \ 128 Dynamics/VerletForceIntegration.hpp 128 129 129 130 GRAPHSOURCE = \ -
src/atom_atominfo.cpp
reb33c4 r435065 30 30 #include "atom_atominfo.hpp" 31 31 32 #include <iomanip> 33 32 34 /** Constructor of class AtomInfo. 33 35 */ … … 492 494 * Parameters are according to those in configuration class. 493 495 * \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 495 498 * \param *Force matrix with forces 496 499 */ 497 void AtomInfo::VelocityVerletUpdate(int nr, const unsigned int NextStep, config *configuration, ForceMatrix *Force, const size_t offset) 498 { 500 void 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); 499 505 // update force 500 506 // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a 501 507 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); 504 520 setAtomicForceAtStep(NextStep, tempVector); 505 521 506 522 // update position 507 523 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); 510 529 setPositionAtStep(NextStep, tempVector); 530 LOG(3, "INFO: Position at step " << NextStep << " set to " << tempVector); 511 531 512 532 // Update U 513 533 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); 515 538 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); 522 540 }; 523 541 -
src/atom_atominfo.hpp
reb33c4 r435065 27 27 28 28 class AtomInfo; 29 class config;30 29 class element; 31 30 class ForceMatrix; … … 242 241 size_t getTrajectorySize() const; 243 242 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); 245 244 double getKineticEnergy(const unsigned int step) const; 246 245 Vector getMomentum(const unsigned int step) const; -
src/molecule.hpp
reb33c4 r435065 176 176 void SetBoxDimension(Vector *dim); 177 177 bool ScanForPeriodicCorrection(); 178 bool VerletForceIntegration(char *file, config &configuration, const size_t offset);179 178 double VolumeOfConvexEnvelope(bool IsAngstroem); 180 179 RealSpaceMatrix getInertiaTensor() const; -
src/molecule_dynamics.cpp
reb33c4 r435065 39 39 40 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, we43 * have to transform them).44 * This adds a new MD step to the config file.45 * \param *file filename46 * \param config structure with config::Deltat, config::IsAngstroem, config::DoConstrained47 * \param offset offset in matrix file to the first force component48 * \return true - file found and parsed, false - file not found or imparsable49 * \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 ForceMatrix62 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 Forces75 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 to85 if (configuration.DoConstrainedMD) {86 // calculate forces and potential87 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 vector95 // check size of vectors96 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 motionless101 Velocity = atoms.totalMomentumAtStep(MDSteps+1);102 IonMass = atoms.totalMass();103 104 // correct velocities (rather momenta) so that center of mass remains motionless105 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 // exit116 return true;117 };
Note:
See TracChangeset
for help on using the changeset viewer.