Changeset 21c017 for src


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)
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    ra37350 r21c017  
    10101010      // set new box dimensions
    10111011      *out << Verbose(0) << "Translating to box with these boundaries." << endl;
    1012       mol->CenterInBox((ofstream *) &cout, &BoxLengths);
     1012      mol->SetBoxDimension(&BoxLengths);
     1013      mol->CenterInBox((ofstream *) &cout);
    10131014    }
    10141015  // update Box of atoms by boundary
  • src/builder.cpp

    ra37350 r21c017  
    308308                        }
    309309                        // center
    310                         mol->CenterInBox((ofstream *)&cout, &x);
     310                        mol->CenterInBox((ofstream *)&cout);
    311311                        // update Box of atoms by boundary
    312312                        mol->SetBoxDimension(&x);
     
    12451245                                                cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
    12461246                                                cout << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl;
    1247                                                 cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
     1247                                                cout << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
    12481248                                                cout << "\t-B <basis>\tSetting basis to store to MPQC config files." << endl;
    12491249                                                cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
     
    12631263                                                cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
    12641264                                                cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
    1265                                                 cout << "\t-T <file> Store temperatures from the config file in <file>." << endl;
     1265            cout << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl;
     1266                                                cout << "\t-S <file> Store temperatures from the config file in <file>." << endl;
    12661267                                                cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
    12671268                                                cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
     
    14861487                                                        }
    14871488                                                        break;
    1488                                                 case 'T':
     1489                                                case 'S':
    14891490                                                        ExitFlag = 1;
    14901491                                                        if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    14911492                                                                ExitFlag = 255;
    1492                                                                 cerr << "Not enough or invalid arguments given for storing tempature: -T <temperature file>" << endl;
     1493                                                                cerr << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl;
    14931494                                                        } else {
    14941495                                                                cout << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl;
     
    15331534                                                        }
    15341535                                                        break;
     1536            case 'T':
     1537              ExitFlag = 1;
     1538              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
     1539                ExitFlag = 255;
     1540                cerr << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl;
     1541              } else {
     1542                ExitFlag = 1;
     1543                SaveFlag = true;
     1544                cout << Verbose(1) << "Translating all ions periodically to new origin." << endl;
     1545                for (int i=NDIM;i--;)
     1546                  x.x[i] = atof(argv[argptr+i]);
     1547                mol->TranslatePeriodically((const Vector *)&x);
     1548                argptr+=3;
     1549              }
     1550              break;
    15351551                                                case 's':
    15361552                                                        ExitFlag = 1;
     
    15621578                                                case 'b':
    15631579                                                        ExitFlag = 1;
    1564                                                         if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
     1580                                                        if ((argptr+5 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
    15651581                                                                ExitFlag = 255;
    1566                                                                 cerr << "Not enough or invalid arguments given for centering in box: -b <length_x> <length_y> <length_z>" << endl;
     1582                                                                cerr << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
    15671583                                                        } else {
    15681584                                                                SaveFlag = true;
    1569                                                                 j = -1;
    15701585                                                                cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
    1571                                                                 j=-1;
    1572                                                                 for (int i=0;i<NDIM;i++) {
    1573                                                                         j += i+1;
    1574                                                                         x.x[i] = atof(argv[argptr++]);
    1575                                                                         mol->cell_size[j] += x.x[i]*2.;
     1586                                                                for (int i=0;i<6;i++) {
     1587                                                                        mol->cell_size[i] = atof(argv[argptr+i]);
    15761588                                                                }
    15771589                                                                // center
    1578                                                                 mol->CenterInBox((ofstream *)&cout, &x);
    1579                                                                 // update Box of atoms by boundary
    1580                                                                 mol->SetBoxDimension(&x);
     1590                                                                mol->CenterInBox((ofstream *)&cout);
     1591                argptr+=6;
    15811592                                                        }
    15821593                                                        break;
     
    16021613                                                                }
    16031614                                                                mol->Translate((const Vector *)&x);
     1615                argptr+=3;
    16041616                                                        }
    16051617                                                        break;
     
    16101622                                                        mol->CenterOrigin((ofstream *)&cout, &x);
    16111623                                                        mol->SetBoxDimension(&x);
     1624              argptr+=0;
    16121625                                                        break;
    16131626                                                case 'r':
  • 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];
  • src/molecules.hpp

    ra37350 r21c017  
    252252        void CountElements();
    253253        void CalculateOrbitals(class config &configuration);
    254         bool CenterInBox(ofstream *out, Vector *BoxLengths);
     254        bool CenterInBox(ofstream *out);
    255255        void CenterEdge(ofstream *out, Vector *max);
    256256        void CenterOrigin(ofstream *out, Vector *max);
    257257        void CenterGravity(ofstream *out, Vector *max);
    258258        void Translate(const Vector *x);
     259        void TranslatePeriodically(const Vector *trans);
    259260        void Mirror(const Vector *x);
    260261        void Align(Vector *n);
  • src/vector.cpp

    ra37350 r21c017  
    413413        for (int i=NDIM;i--;)
    414414                x[i] = C.x[i];
     415};
     416
     417/** Calculate the inverse of a 3x3 matrix.
     418 * \param *matrix NDIM_NDIM array
     419 */
     420double * Vector::InverseMatrix(double *A)
     421{
     422  double *B = (double *) Malloc(sizeof(double)*NDIM*NDIM, "Vector::InverseMatrix: *B");
     423  double detA = RDET3(A);
     424  double detAReci;
     425
     426  for (int i=0;i<NDIM*NDIM;++i)
     427    B[i] = 0.;
     428  // calculate the inverse B
     429  if (fabs(detA) > MYEPSILON) {;  // RDET3(A) yields precisely zero if A irregular
     430    detAReci = 1./detA;
     431    B[0] =  detAReci*RDET2(A[4],A[5],A[7],A[8]);    // A_11
     432    B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]);    // A_12
     433    B[2] =  detAReci*RDET2(A[1],A[2],A[4],A[5]);    // A_13
     434    B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]);    // A_21
     435    B[4] =  detAReci*RDET2(A[0],A[2],A[6],A[8]);    // A_22
     436    B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]);    // A_23
     437    B[6] =  detAReci*RDET2(A[3],A[4],A[6],A[7]);    // A_31
     438    B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]);    // A_32
     439    B[8] =  detAReci*RDET2(A[0],A[1],A[3],A[4]);    // A_33
     440  }
     441  return B;
    415442};
    416443
  • src/vector.hpp

    ra37350 r21c017  
    4040        void Scale(double factor);
    4141        void MatrixMultiplication(double *M);
     42        double * InverseMatrix(double *A);
    4243        void InverseMatrixMultiplication(double *M);
    4344        void KeepPeriodic(ofstream *out, double *matrix);
Note: See TracChangeset for help on using the changeset viewer.