Changeset 4a7776a for src/molecule_dynamics.cpp
- Timestamp:
- Oct 12, 2009, 10:30:02 AM (16 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, Candidate_v1.7.0, 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:
- 5034e1
- Parents:
- ccd9f5
- File:
-
- 1 edited
-
src/molecule_dynamics.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_dynamics.cpp
rccd9f5 r4a7776a 497 497 else { 498 498 PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap"); 499 Walker = start; 500 while (Walker->next != end) { 501 Walker = Walker->next; 502 PermutationMap[Walker->nr] = Walker; // always pick target with the smallest distance 503 } 499 SetIndexedArrayForEachAtomTo( PermutationMap, &atom::nr ); 504 500 } 505 501 506 502 // check whether we have sufficient space in Trajectories for each atom 507 Walker = start; 508 while (Walker->next != end) { 509 Walker = Walker->next; 510 if (Walker->Trajectory.R.size() <= (unsigned int)(MaxSteps)) { 511 //cout << "Increasing size for trajectory array of " << keyword << " to " << (MaxSteps+1) << "." << endl; 512 Walker->Trajectory.R.resize(MaxSteps+1); 513 Walker->Trajectory.U.resize(MaxSteps+1); 514 Walker->Trajectory.F.resize(MaxSteps+1); 515 } 516 } 503 ActOnAllAtoms( &atom::ResizeTrajectory, MaxSteps ); 517 504 // push endstep to last one 518 Walker = start; 519 while (Walker->next != end) { // remove the endstep (is now the very last one) 520 Walker = Walker->next; 521 for (int n=NDIM;n--;) { 522 Walker->Trajectory.R.at(MaxSteps).x[n] = Walker->Trajectory.R.at(endstep).x[n]; 523 Walker->Trajectory.U.at(MaxSteps).x[n] = Walker->Trajectory.U.at(endstep).x[n]; 524 Walker->Trajectory.F.at(MaxSteps).x[n] = Walker->Trajectory.F.at(endstep).x[n]; 525 } 526 } 505 ActOnAllAtoms( &atom::CopyStepOnStep, MaxSteps, endstep ); 527 506 endstep = MaxSteps; 528 507 … … 578 557 bool molecule::VerletForceIntegration(ofstream *out, char *file, config &configuration) 579 558 { 580 atom *walker = NULL;581 559 ifstream input(file); 582 560 string token; 583 561 stringstream item; 584 double IonMass, Vector[NDIM], ConstrainedPotentialEnergy, ActualTemp; 562 double IonMass, ConstrainedPotentialEnergy, ActualTemp; 563 Vector Velocity; 585 564 ForceMatrix Force; 586 565 … … 601 580 } 602 581 // correct Forces 603 for(int d=0;d<NDIM;d++) 604 Vector[d] = 0.; 582 Velocity.Zero(); 605 583 for(int i=0;i<AtomCount;i++) 606 584 for(int d=0;d<NDIM;d++) { 607 Ve ctor[d] += Force.Matrix[0][i][d+5];585 Velocity.x[d] += Force.Matrix[0][i][d+5]; 608 586 } 609 587 for(int i=0;i<AtomCount;i++) 610 588 for(int d=0;d<NDIM;d++) { 611 Force.Matrix[0][i][d+5] -= Ve ctor[d]/(double)AtomCount;589 Force.Matrix[0][i][d+5] -= Velocity.x[d]/(double)AtomCount; 612 590 } 613 591 // solve a constrained potential if we are meant to … … 621 599 622 600 // and perform Verlet integration for each atom with position, velocity and force vector 623 walker = start; 624 while (walker->next != end) { // go through every atom of this element 625 walker = walker->next; 626 //a = configuration.Deltat*0.5/walker->type->mass; // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a 627 // check size of vectors 628 if (walker->Trajectory.R.size() <= (unsigned int)(MDSteps)) { 629 //out << "Increasing size for trajectory array of " << *walker << " to " << (size+10) << "." << endl; 630 walker->Trajectory.R.resize(MDSteps+10); 631 walker->Trajectory.U.resize(MDSteps+10); 632 walker->Trajectory.F.resize(MDSteps+10); 633 } 634 635 // Update R (and F) 636 for (int d=0; d<NDIM; d++) { 637 walker->Trajectory.F.at(MDSteps).x[d] = -Force.Matrix[0][walker->nr][d+5]*(configuration.GetIsAngstroem() ? AtomicLengthToAngstroem : 1.); 638 walker->Trajectory.R.at(MDSteps).x[d] = walker->Trajectory.R.at(MDSteps-1).x[d]; 639 walker->Trajectory.R.at(MDSteps).x[d] += configuration.Deltat*(walker->Trajectory.U.at(MDSteps-1).x[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2 640 walker->Trajectory.R.at(MDSteps).x[d] += 0.5*configuration.Deltat*configuration.Deltat*(walker->Trajectory.F.at(MDSteps).x[d]/walker->type->mass); // F = m * a and s = 0.5 * F/m * t^2 = F * a * t 641 } 642 // Update U 643 for (int d=0; d<NDIM; d++) { 644 walker->Trajectory.U.at(MDSteps).x[d] = walker->Trajectory.U.at(MDSteps-1).x[d]; 645 walker->Trajectory.U.at(MDSteps).x[d] += configuration.Deltat * (walker->Trajectory.F.at(MDSteps).x[d]+walker->Trajectory.F.at(MDSteps-1).x[d]/walker->type->mass); // v = F/m * t 646 } 647 // out << "Integrated position&velocity of step " << (MDSteps) << ": ("; 648 // for (int d=0;d<NDIM;d++) 649 // out << walker->Trajectory.R.at(MDSteps).x[d] << " "; // next step 650 // out << ")\t("; 651 // for (int d=0;d<NDIM;d++) 652 // cout << walker->Trajectory.U.at(MDSteps).x[d] << " "; // next step 653 // out << ")" << endl; 654 // next atom 655 } 601 // check size of vectors 602 ActOnAllAtoms( &atom::ResizeTrajectory, MDSteps+10 ); 603 604 ActOnAllAtoms( &atom::VelocityVerletUpdate, MDSteps, &configuration, &Force); 656 605 } 657 606 // correct velocities (rather momenta) so that center of mass remains motionless 658 for(int d=0;d<NDIM;d++) 659 Vector[d] = 0.; 607 Velocity.Zero(); 660 608 IonMass = 0.; 661 walker = start; 662 while (walker->next != end) { // go through every atom 663 walker = walker->next; 664 IonMass += walker->type->mass; // sum up total mass 665 for(int d=0;d<NDIM;d++) { 666 Vector[d] += walker->Trajectory.U.at(MDSteps).x[d]*walker->type->mass; 667 } 668 } 609 ActOnAllAtoms ( &atom::SumUpKineticEnergy, MDSteps, &IonMass, &Velocity ); 610 669 611 // correct velocities (rather momenta) so that center of mass remains motionless 670 for(int d=0;d<NDIM;d++) 671 Vector[d] /= IonMass; 612 Velocity.Scale(1./IonMass); 672 613 ActualTemp = 0.; 673 walker = start; 674 while (walker->next != end) { // go through every atom of this element 675 walker = walker->next; 676 for(int d=0;d<NDIM;d++) { 677 walker->Trajectory.U.at(MDSteps).x[d] -= Vector[d]; 678 ActualTemp += 0.5 * walker->type->mass * walker->Trajectory.U.at(MDSteps).x[d] * walker->Trajectory.U.at(MDSteps).x[d]; 679 } 680 } 614 ActOnAllAtoms ( &atom::CorrectVelocity, &ActualTemp, MDSteps, &Velocity ); 681 615 Thermostats(configuration, ActualTemp, Berendsen); 682 616 MDSteps++; 683 684 617 685 618 // exit … … 712 645 double delta_alpha = 0.; 713 646 double ScaleTempFactor; 714 double sigma;715 double IonMass;716 int d;717 647 gsl_rng * r; 718 648 const gsl_rng_type * T; 719 double *U = NULL, *F = NULL, FConstraint[NDIM];720 atom *walker = NULL;721 649 722 650 // calculate scale configuration … … 731 659 if ((configuration.ScaleTempStep > 0) && ((MDSteps-1) % configuration.ScaleTempStep == 0)) { 732 660 cout << Verbose(2) << "Applying Woodcock thermostat..." << endl; 733 walker = start; 734 while (walker->next != end) { // go through every atom of this element 735 walker = walker->next; 736 IonMass = walker->type->mass; 737 U = walker->Trajectory.U.at(MDSteps).x; 738 if (walker->FixedIon == 0) // even FixedIon moves, only not by other's forces 739 for (d=0; d<NDIM; d++) { 740 U[d] *= sqrt(ScaleTempFactor); 741 ekin += 0.5*IonMass * U[d]*U[d]; 742 } 743 } 661 ActOnAllAtoms( &atom::Thermostat_Woodcock, sqrt(ScaleTempFactor), MDSteps, &ekin ); 744 662 } 745 663 break; 746 664 case Gaussian: 747 665 cout << Verbose(2) << "Applying Gaussian thermostat..." << endl; 748 walker = start; 749 while (walker->next != end) { // go through every atom of this element 750 walker = walker->next; 751 IonMass = walker->type->mass; 752 U = walker->Trajectory.U.at(MDSteps).x; 753 F = walker->Trajectory.F.at(MDSteps).x; 754 if (walker->FixedIon == 0) // even FixedIon moves, only not by other's forces 755 for (d=0; d<NDIM; d++) { 756 G += U[d] * F[d]; 757 E += U[d]*U[d]*IonMass; 758 } 759 } 666 ActOnAllAtoms( &atom::Thermostat_Gaussian_init, MDSteps, &G, &E ); 667 760 668 cout << Verbose(1) << "Gaussian Least Constraint constant is " << G/E << "." << endl; 761 walker = start; 762 while (walker->next != end) { // go through every atom of this element 763 walker = walker->next; 764 IonMass = walker->type->mass; 765 U = walker->Trajectory.U.at(MDSteps).x; 766 F = walker->Trajectory.F.at(MDSteps).x; 767 if (walker->FixedIon == 0) // even FixedIon moves, only not by other's forces 768 for (d=0; d<NDIM; d++) { 769 FConstraint[d] = (G/E) * (U[d]*IonMass); 770 U[d] += configuration.Deltat/IonMass * (FConstraint[d]); 771 ekin += IonMass * U[d]*U[d]; 772 } 773 } 669 ActOnAllAtoms( &atom::Thermostat_Gaussian_least_constraint, MDSteps, G/E, &ekin, &configuration); 670 774 671 break; 775 672 case Langevin: … … 780 677 r = gsl_rng_alloc (T); 781 678 // Go through each ion 782 walker = start; 783 while (walker->next != end) { // go through every atom of this element 784 walker = walker->next; 785 IonMass = walker->type->mass; 786 sigma = sqrt(configuration.TargetTemp/IonMass); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime) 787 U = walker->Trajectory.U.at(MDSteps).x; 788 F = walker->Trajectory.F.at(MDSteps).x; 789 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 790 // throw a dice to determine whether it gets hit by a heat bath particle 791 if (((((rand()/(double)RAND_MAX))*configuration.TempFrequency) < 1.)) { 792 cout << Verbose(3) << "Particle " << *walker << " was hit (sigma " << sigma << "): " << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << " -> "; 793 // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis 794 for (d=0; d<NDIM; d++) { 795 U[d] = gsl_ran_gaussian (r, sigma); 796 } 797 cout << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << endl; 798 } 799 for (d=0; d<NDIM; d++) 800 ekin += 0.5*IonMass * U[d]*U[d]; 801 } 802 } 679 ActOnAllAtoms( &atom::Thermostat_Langevin, MDSteps, r, &ekin, &configuration ); 803 680 break; 681 804 682 case Berendsen: 805 683 cout << Verbose(2) << "Applying Berendsen-VanGunsteren thermostat..." << endl; 806 walker = start; 807 while (walker->next != end) { // go through every atom of this element 808 walker = walker->next; 809 IonMass = walker->type->mass; 810 U = walker->Trajectory.U.at(MDSteps).x; 811 F = walker->Trajectory.F.at(MDSteps).x; 812 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 813 for (d=0; d<NDIM; d++) { 814 U[d] *= sqrt(1+(configuration.Deltat/configuration.TempFrequency)*(ScaleTempFactor-1)); 815 ekin += 0.5*IonMass * U[d]*U[d]; 816 } 817 } 818 } 684 ActOnAllAtoms( &atom::Thermostat_Berendsen, MDSteps, ScaleTempFactor, &ekin, &configuration ); 819 685 break; 686 820 687 case NoseHoover: 821 688 cout << Verbose(2) << "Applying Nose-Hoover thermostat..." << endl; 822 689 // dynamically evolve alpha (the additional degree of freedom) 823 690 delta_alpha = 0.; 824 walker = start; 825 while (walker->next != end) { // go through every atom of this element 826 walker = walker->next; 827 IonMass = walker->type->mass; 828 U = walker->Trajectory.U.at(MDSteps).x; 829 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 830 for (d=0; d<NDIM; d++) { 831 delta_alpha += U[d]*U[d]*IonMass; 832 } 833 } 834 } 691 ActOnAllAtoms( &atom::Thermostat_NoseHoover_init, MDSteps, &delta_alpha ); 835 692 delta_alpha = (delta_alpha - (3.*AtomCount+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass); 836 693 configuration.alpha += delta_alpha*configuration.Deltat; 837 694 cout << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl; 838 695 // apply updated alpha as additional force 839 walker = start; 840 while (walker->next != end) { // go through every atom of this element 841 walker = walker->next; 842 IonMass = walker->type->mass; 843 U = walker->Trajectory.U.at(MDSteps).x; 844 if (walker->FixedIon == 0) { // even FixedIon moves, only not by other's forces 845 for (d=0; d<NDIM; d++) { 846 FConstraint[d] = - configuration.alpha * (U[d] * IonMass); 847 U[d] += configuration.Deltat/IonMass * (FConstraint[d]); 848 ekin += (0.5*IonMass) * U[d]*U[d]; 849 } 850 } 851 } 696 ActOnAllAtoms( &atom::Thermostat_NoseHoover_scale, MDSteps, &ekin, &configuration ); 852 697 break; 853 698 }
Note:
See TracChangeset
for help on using the changeset viewer.
