Changeset 99593f


Ignore:
Timestamp:
Nov 4, 2009, 5:34: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:
7ea9e6
Parents:
c9bce3e
Message:

Extension to the periodic boundary case for analysis_correlation.cpp

other stuff:

Location:
src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    rc9bce3e r99593f  
    5252                if (Walker->nr < OtherWalker->nr)
    5353                  if ((type2 == NULL) || (OtherWalker->type == type2)) {
    54                     distance = Walker->node->Distance(OtherWalker->node);
     54                    distance = Walker->node->PeriodicDistance(OtherWalker->node, (*MolWalker)->cell_size);
    5555                    //*out << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    5656                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    9090        *out << Verbose(3) << "Current atom is " << *Walker << "." << endl;
    9191        if ((type == NULL) || (Walker->type == type)) {
    92           distance = Walker->node->Distance(point);
     92          distance = Walker->node->PeriodicDistance(point, (*MolWalker)->cell_size);
    9393          *out << Verbose(4) << "Current distance is " << distance << "." << endl;
    9494          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     
    111111{
    112112  CorrelationToSurfaceMap *outmap = NULL;
    113   double distance = 0.;
     113  double distance = 0;
    114114  class BoundaryTriangleSet *triangle = NULL;
    115115  Vector centroid;
     116  int ranges[NDIM] = {1, 1, 1};
     117  int n[NDIM];
     118  Vector periodicX;
     119  Vector checkX;
    116120
    117121  if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
     
    122126  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    123127    if ((*MolWalker)->ActiveFlag) {
     128      const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
     129      const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
    124130      *out << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    125131      atom *Walker = (*MolWalker)->start;
     
    128134        *out << Verbose(3) << "Current atom is " << *Walker << "." << endl;
    129135        if ((type == NULL) || (Walker->type == type)) {
    130           triangle = Surface->FindClosestTriangleToPoint(out, Walker->node, LC );
    131           if (triangle != NULL) {
    132             distance = DistanceToTrianglePlane(out, Walker->node, triangle);
    133             outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     136          periodicX.CopyVector(Walker->node);
     137          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     138          // go through every range in xyz and get distance
     139          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     140            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     141              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     142                checkX.Init(n[0], n[1], n[2]);
     143                checkX.AddVector(&periodicX);
     144                checkX.MatrixMultiplication(FullMatrix);
     145                triangle = Surface->FindClosestTriangleToPoint(out, &checkX, LC );
     146                if (triangle != NULL) {
     147                  distance = DistanceToTrianglePlane(out, &checkX, triangle);
     148                  outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     149                }
    134150          }
    135151        }
  • src/atom_bondedparticle.cpp

    rc9bce3e r99593f  
    126126  bond *CandidateBond = NULL;
    127127
    128   *out << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     128  //*out << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    129129  NoBonds = CountBonds();
    130130  if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
     
    132132      OtherWalker = (*Runner)->GetOtherAtom(this);
    133133      OtherNoBonds = OtherWalker->CountBonds();
    134       *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     134      //*out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    135135      if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate
    136136        if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
    137137          CandidateBond = (*Runner);
    138           *out << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
     138          //*out << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
    139139        }
    140140      }
     
    144144      *out << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
    145145    } else {
    146       *out << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
     146      //*out << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
    147147      FalseBondDegree++;
    148148    }
  • src/helpers.cpp

    rc9bce3e r99593f  
    133133 * \return allocated NDIM*NDIM array with the symmetric matrix
    134134 */
    135 double * ReturnFullMatrixforSymmetric(double *symm)
     135double * ReturnFullMatrixforSymmetric(const double * const symm)
    136136{
    137137  double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
     
    148148};
    149149
     150/** Calculate the inverse of a 3x3 matrix.
     151 * \param *matrix NDIM_NDIM array
     152 */
     153double * InverseMatrix( const double * const A)
     154{
     155  double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B");
     156  double detA = RDET3(A);
     157  double detAReci;
     158
     159  for (int i=0;i<NDIM*NDIM;++i)
     160    B[i] = 0.;
     161  // calculate the inverse B
     162  if (fabs(detA) > MYEPSILON) {;  // RDET3(A) yields precisely zero if A irregular
     163    detAReci = 1./detA;
     164    B[0] =  detAReci*RDET2(A[4],A[5],A[7],A[8]);    // A_11
     165    B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]);    // A_12
     166    B[2] =  detAReci*RDET2(A[1],A[2],A[4],A[5]);    // A_13
     167    B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]);    // A_21
     168    B[4] =  detAReci*RDET2(A[0],A[2],A[6],A[8]);    // A_22
     169    B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]);    // A_23
     170    B[6] =  detAReci*RDET2(A[3],A[4],A[6],A[7]);    // A_31
     171    B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]);    // A_32
     172    B[8] =  detAReci*RDET2(A[0],A[1],A[3],A[4]);    // A_33
     173  }
     174  return B;
     175};
     176
     177/** hard-coded determinant of a 3x3 matrix.
     178 * \param a[9] matrix
     179 * \return \f$det(a)\f$
     180 */
     181double RDET3(const double a[NDIM*NDIM])
     182{
     183  return ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]);
     184};
     185
     186/** hard-coded determinant of a 2x2 matrix.
     187 * \param a[4] matrix
     188 * \return \f$det(a)\f$
     189 */
     190double RDET2(const double a[4])
     191{
     192  return ((a[0])*(a[3])-(a[1])*(a[2]));
     193};
     194
     195/** hard-coded determinant of a 2x2 matrix.
     196 * \param a0 (0,0) entry of matrix
     197 * \param a1 (0,1) entry of matrix
     198 * \param a2 (1,0) entry of matrix
     199 * \param a3 (1,1) entry of matrix
     200 * \return \f$det(a)\f$
     201 */
     202double RDET2(const double a0, const double a1, const double a2, const double a3)
     203{
     204  return ((a0)*(a3)-(a1)*(a2));
     205};
     206
    150207/** Comparison function for GSL heapsort on distances in two molecules.
    151208 * \param *a
  • src/helpers.hpp

    rc9bce3e r99593f  
    1818#include <fstream>
    1919
     20#include "defs.hpp"
    2021#include "memoryallocator.hpp"
     22
     23/********************************************** definitions *********************************/
     24
     25// some algebraic matrix stuff
     26double RDET3(const double a[NDIM*NDIM]);
     27double RDET2(const double a[4]);
     28double RDET2(const double a0, const double a1, const double a2, const double a3);
    2129
    2230/********************************************** helpful functions *********************************/
     
    4957bool IsValidNumber( const char *string);
    5058int CompareDoubles (const void * a, const void * b);
    51 double * ReturnFullMatrixforSymmetric(double *cell_size);
     59double * ReturnFullMatrixforSymmetric(const double * const cell_size);
     60double * InverseMatrix(const double * const A);
    5261void performCriticalExit();
    5362
  • src/molecule_geometry.cpp

    rc9bce3e r99593f  
    2424{
    2525  bool status = true;
    26   Vector x;
    2726  const Vector *Center = DetermineCenterOfAll(out);
    2827  double *M = ReturnFullMatrixforSymmetric(cell_size);
    29   double *Minv = x.InverseMatrix(M);
     28  double *Minv = InverseMatrix(M);
    3029
    3130  // go through all atoms
     
    4645{
    4746  bool status = true;
    48   Vector x;
    4947  double *M = ReturnFullMatrixforSymmetric(cell_size);
    50   double *Minv = x.InverseMatrix(M);
     48  double *Minv = InverseMatrix(M);
    5149
    5250  // go through all atoms
     
    231229void molecule::TranslatePeriodically(const Vector *trans)
    232230{
    233   Vector x;
    234231  double *M = ReturnFullMatrixforSymmetric(cell_size);
    235   double *Minv = x.InverseMatrix(M);
     232  double *Minv = InverseMatrix(M);
    236233
    237234  // go through all atoms
  • src/molecule_graph.cpp

    rc9bce3e r99593f  
    221221int molecule::CorrectBondDegree(ofstream *out) const
    222222{
    223   int No = 0;
     223  int No = 0, OldNo = -1;
    224224
    225225  if (BondCount != 0) {
    226226    *out << Verbose(1) << "Correcting Bond degree of each bond ... " << endl;
    227227    do {
     228      OldNo = No;
    228229      No = SumPerAtom(&atom::CorrectBondDegree, out);
    229     } while (No);
     230    } while (OldNo != No);
    230231    *out << " done." << endl;
    231232  } else {
     
    418419  if (!DFS.BackStepping) { // coming from (8) want to go to (3)
    419420    // (9) remove all from stack till Walker (including), these and Root form a component
    420     DFS.AtomStack->Output(out);
     421    //DFS.AtomStack->Output(out);
    421422    mol->SetNextComponentNumber(DFS.Root, DFS.ComponentNumber);
    422423    *out << Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;
     
    881882  InitializeBFSAccounting(out, BFS, AtomCount);
    882883
    883   *out << Verbose(1) << "Back edge list - ";
    884   BackEdgeStack->Output(out);
     884  //*out << Verbose(1) << "Back edge list - ";
     885  //BackEdgeStack->Output(out);
    885886
    886887  *out << Verbose(1) << "Analysing cycles ... " << endl;
  • src/tesselation.cpp

    rc9bce3e r99593f  
    25382538  } else {
    25392539    list<TesselPoint*> *connectedClosestPoints = GetCircleOfConnectedPoints(out, trianglePoints[0], x);
    2540     trianglePoints[1] = connectedClosestPoints->front();
    2541     trianglePoints[2] = connectedClosestPoints->back();
    2542     for (int i=0;i<3;i++) {
    2543       if (trianglePoints[i] == NULL) {
    2544         *out << Verbose(1) << "ERROR: IsInnerPoint encounters serious error, point " << i << " not found." << endl;
     2540    if (connectedClosestPoints != NULL) {
     2541      trianglePoints[1] = connectedClosestPoints->front();
     2542      trianglePoints[2] = connectedClosestPoints->back();
     2543      for (int i=0;i<3;i++) {
     2544        if (trianglePoints[i] == NULL) {
     2545          *out << Verbose(1) << "ERROR: IsInnerPoint encounters serious error, point " << i << " not found." << endl;
     2546        }
     2547        //*out << Verbose(2) << "List of triangle points:" << endl;
     2548        //*out << Verbose(3) << *trianglePoints[i] << endl;
    25452549      }
    2546       //*out << Verbose(2) << "List of triangle points:" << endl;
    2547       //*out << Verbose(3) << *trianglePoints[i] << endl;
    2548     }
    2549 
    2550     triangles = FindTriangles(trianglePoints);
    2551     *out << Verbose(2) << "List of possible triangles:" << endl;
    2552     for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    2553       *out << Verbose(3) << **Runner << endl;
    2554 
    2555     delete(connectedClosestPoints);
     2550
     2551      triangles = FindTriangles(trianglePoints);
     2552      *out << Verbose(2) << "List of possible triangles:" << endl;
     2553      for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
     2554        *out << Verbose(3) << **Runner << endl;
     2555
     2556      delete(connectedClosestPoints);
     2557    } else {
     2558      triangles = NULL;
     2559      *out << Verbose(1) << "There is no circle of connected points!" << endl;
     2560    }
    25562561  }
    25572562 
    2558   if (triangles->empty()) {
     2563  if ((triangles == NULL) || (triangles->empty())) {
    25592564    *out << Verbose(0) << "ERROR: There is no nearest triangle. Please check the tesselation structure.";
    25602565    delete(triangles);
     
    27242729  Vector helper;
    27252730
     2731  if (connectedPoints == NULL) {
     2732    *out << Verbose(2) << "Could not find any connected points!" << endl;
     2733    delete(connectedCircle);
     2734    return NULL;
     2735  }
    27262736  *out << Verbose(2) << "Begin of GetCircleOfConnectedPoints" << endl;
    27272737
  • src/vector.cpp

    rc9bce3e r99593f  
    275275  temp.AddVector(this);
    276276  temp.SubtractVector(PlaneOffset);
    277 
    278   return temp.Norm();
     277  double sign = temp.ScalarProduct(PlaneNormal);
     278  sign /= fabs(sign);
     279
     280  return (temp.Norm()*sign);
    279281};
    280282
     
    713715  for (int i=NDIM;i--;)
    714716    x[i] = C.x[i];
    715 };
    716 
    717 /** Calculate the inverse of a 3x3 matrix.
    718  * \param *matrix NDIM_NDIM array
    719  */
    720 double * Vector::InverseMatrix( const double * const A)
    721 {
    722   double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B");
    723   double detA = RDET3(A);
    724   double detAReci;
    725 
    726   for (int i=0;i<NDIM*NDIM;++i)
    727     B[i] = 0.;
    728   // calculate the inverse B
    729   if (fabs(detA) > MYEPSILON) {;  // RDET3(A) yields precisely zero if A irregular
    730     detAReci = 1./detA;
    731     B[0] =  detAReci*RDET2(A[4],A[5],A[7],A[8]);    // A_11
    732     B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]);    // A_12
    733     B[2] =  detAReci*RDET2(A[1],A[2],A[4],A[5]);    // A_13
    734     B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]);    // A_21
    735     B[4] =  detAReci*RDET2(A[0],A[2],A[6],A[8]);    // A_22
    736     B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]);    // A_23
    737     B[6] =  detAReci*RDET2(A[3],A[4],A[6],A[7]);    // A_31
    738     B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]);    // A_32
    739     B[8] =  detAReci*RDET2(A[0],A[1],A[3],A[4]);    // A_33
    740   }
    741   return B;
    742717};
    743718
  • src/vector.hpp

    rc9bce3e r99593f  
    6262  void Scale(const double factor);
    6363  void MatrixMultiplication(const double * const M);
    64   double * InverseMatrix(const double * const A);
    6564  void InverseMatrixMultiplication(const double * const M);
    6665  void KeepPeriodic(ofstream *out, const double * const matrix);
     
    9190Vector& operator-(const Vector& a, const Vector& b);
    9291
    93 // some algebraic matrix stuff
    94 #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
    95 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
    96 
    97 
    9892
    9993#endif /*VECTOR_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.