Changeset 21c017 for src/molecules.cpp


Ignore:
Timestamp:
Jul 10, 2009, 12:48:05 PM (16 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:
5466f3
Parents:
a37350
Message:

molecule::CenterInBox puts atoms now periodically into the given box, new function molecule::TranslatePeriodically, BUGFIX: molecule::ReturnFullMatrixforSymmetrical()

  • molecule::CenterInBox() has no more a vector as a parameter, but instead enforces the periodicity of the simulation box, i.e. all atoms out of bounds are put back in with wrap-around at boundaries. Call of function was changed in everywhere.
  • in ParseCommandLineParameters() a SetBoxDimension was missing in certain Center...() commands.
  • new function molecule::TranslatePeriodically translates all atoms of a molecule while adhering to the periodicity of the domain
  • new function vector::InverseMatrix() returns the hard-encoded inverse of 3x3 real matrix
  • BUGFIX: molecule::ReturnFullMatrixforSymmetrical()'s assignment from 6-doubles to 9-doubles was all wrong (symmetric to full 3x3 matrix)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    ra37350 r21c017  
    629629/** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths.
    630630 * \param *out output stream for debugging
    631  * \param *BoxLengths box lengths
    632  */
    633 bool molecule::CenterInBox(ofstream *out, Vector *BoxLengths)
     631 */
     632bool molecule::CenterInBox(ofstream *out)
    634633{
    635634        bool status = true;
    636635        atom *ptr = NULL;
    637         Vector *min = new Vector;
    638         Vector *max = new Vector;
    639 
    640         // gather min and max for each axis
    641         ptr = start->next;      // start at first in list
    642         if (ptr != end) {        //list not empty?
    643                 for (int i=NDIM;i--;) {
    644                         max->x[i] = ptr->x.x[i];
    645                         min->x[i] = ptr->x.x[i];
    646                 }
    647                 while (ptr->next != end) {      // continue with second if present
    648                         ptr = ptr->next;
    649                         //ptr->Output(1,1,out);
    650                         for (int i=NDIM;i--;) {
    651                                 max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
    652                                 min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
    653                         }
    654                 }
    655         }
    656         // sanity check
    657         for(int i=NDIM;i--;) {
    658                 if (max->x[i] - min->x[i] > BoxLengths->x[i])
    659                         status = false;
    660         }
    661         // warn if check failed
    662         if (!status)
    663                 *out << "WARNING: molecule is bigger than defined box!" << endl;
    664         else {  // else center in box
    665                 max->AddVector(min);
    666                 max->Scale(-1.);
    667                 max->AddVector(BoxLengths);
    668                 max->Scale(0.5);
    669                 Translate(max);
    670         }
    671 
    672         // free and exit
    673         delete(min);
    674         delete(max);
     636        Vector x;
     637        double *M = ReturnFullMatrixforSymmetric(cell_size);
     638  double *Minv = x.InverseMatrix(M);
     639        double value;
     640
     641//      cout << "The box matrix is :" << endl;
     642//  for (int i=0;i<NDIM;++i) {
     643//    for (int j=0;j<NDIM;++j)
     644//      cout << M[i*NDIM+j] << "\t";
     645//    cout << endl;
     646//  }
     647//  cout << "And its inverse is :" << endl;
     648//  for (int i=0;i<NDIM;++i) {
     649//    for (int j=0;j<NDIM;++j)
     650//      cout << Minv[i*NDIM+j] << "\t";
     651//    cout << endl;
     652//  }
     653        // go through all atoms
     654  ptr = start->next;  // start at first in list
     655  if (ptr != end) {  //list not empty?
     656    while (ptr->next != end) {  // continue with second if present
     657      ptr = ptr->next;
     658      //ptr->Output(1,1,out);
     659      // multiply its vector with matrix inverse
     660      x.CopyVector(&ptr->x);
     661      x.MatrixMultiplication(Minv);
     662      // truncate to [0,1] for each axis
     663      for (int i=0;i<NDIM;i++) {
     664        value = floor(x.x[i]);  // next lower integer
     665        if (x.x[i] >=0) {
     666          x.x[i] -= value;
     667        } else {
     668          x.x[i] += value+1;
     669        }
     670      }
     671      // matrix multiply
     672      x.MatrixMultiplication(M);
     673      ptr->x.CopyVector(&x);
     674    }
     675  }
     676  delete(M);
     677  delete(Minv);
    675678        return status;
    676679};
     
    836839        }
    837840};
     841
     842/** Translate the molecule periodically in the box.
     843 * \param trans[] translation vector.
     844 */
     845void molecule::TranslatePeriodically(const Vector *trans)
     846{
     847  atom *ptr = NULL;
     848  Vector x;
     849  double *M = ReturnFullMatrixforSymmetric(cell_size);
     850  double *Minv = x.InverseMatrix(M);
     851  double value;
     852
     853  // go through all atoms
     854  ptr = start->next;  // start at first in list
     855  if (ptr != end) {  //list not empty?
     856    while (ptr->next != end) {  // continue with second if present
     857      ptr = ptr->next;
     858      //ptr->Output(1,1,out);
     859      // multiply its vector with matrix inverse
     860      x.CopyVector(&ptr->x);
     861      x.Translate(trans);
     862      x.MatrixMultiplication(Minv);
     863      // truncate to [0,1] for each axis
     864      for (int i=0;i<NDIM;i++) {
     865        value = floor(fabs(x.x[i]));  // next lower integer
     866        if (x.x[i] >=0) {
     867          x.x[i] -= value;
     868        } else {
     869          x.x[i] += value+1;
     870        }
     871      }
     872      // matrix multiply
     873      x.MatrixMultiplication(M);
     874      ptr->x.CopyVector(&x);
     875      for (int j=0;j<MDSteps;j++) {
     876        x.CopyVector(&Trajectories[ptr].R.at(j));
     877        x.Translate(trans);
     878        x.MatrixMultiplication(Minv);
     879        // truncate to [0,1] for each axis
     880        for (int i=0;i<NDIM;i++) {
     881          value = floor(x.x[i]);  // next lower integer
     882          if (x.x[i] >=0) {
     883            x.x[i] -= value;
     884          } else {
     885            x.x[i] += value+1;
     886          }
     887        }
     888        // matrix multiply
     889        x.MatrixMultiplication(M);
     890        Trajectories[ptr].R.at(j).CopyVector(&x);
     891      }
     892    }
     893  }
     894  delete(M);
     895  delete(Minv);
     896};
     897
    838898
    839899/** Mirrors all atoms against a given plane.
     
    41304190        matrix[0] = symm[0];
    41314191        matrix[1] = symm[1];
    4132         matrix[2] = symm[3];
     4192        matrix[2] = symm[2];
    41334193        matrix[3] = symm[1];
    4134         matrix[4] = symm[2];
     4194        matrix[4] = symm[3];
    41354195        matrix[5] = symm[4];
    4136         matrix[6] = symm[3];
     4196        matrix[6] = symm[2];
    41374197        matrix[7] = symm[4];
    41384198        matrix[8] = symm[5];
Note: See TracChangeset for help on using the changeset viewer.