Changeset 7ea9e6


Ignore:
Timestamp:
Nov 4, 2009, 6:15:10 PM (15 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:
7326b2
Parents:
99593f
git-author:
Frederik Heber <heber@…> (11/04/09 18:11:09)
git-committer:
Frederik Heber <heber@…> (11/04/09 18:15:10)
Message:

Periodic variants of AnalysisPair...() implemented.

  • BUGFIX: Vector::DistanceToPlane() - we did not check whether sign is 0.
  • NOTE: Due to changes in Vector::DistanceToPlane() with sign, Unit test AnalysisCorrelationToSurfaceUnitTest had to be changed:
    • we now have bin -0.5 filled with 1 (instead of 0.) and -0.288 instead of 0.288
    • find() replaced by lower_bound
  • new functions: PeriodicPairCorrelation(), PeriodicCorrelationToPoint(), PeriodicCorrelationToSurface()
    • each has a ranges[NDIM] argument with specifies the neighbours to scan: [ -ranges[i], ranges[i] ]
    • the atom::node is periodically translated to each periodic cell and the distance calculated.
  • NOTE: make check was broken before due to implementation of Periodic variants as normal ones (yielding more points that expected in unit test).

Signed-off-by: Frederik Heber <heber@…>

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    r99593f r7ea9e6  
    6565};
    6666
     67/** Calculates the pair correlation between given elements.
     68 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
     69 * \param *out output stream for debugging
     70 * \param *molecules list of molecules structure
     71 * \param *type1 first element or NULL (if any element)
     72 * \param *type2 second element or NULL (if any element)
     73 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
     74 * \return Map of doubles with values the pair of the two atoms.
     75 */
     76PairCorrelationMap *PeriodicPairCorrelation( ofstream * const out, MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
     77{
     78  PairCorrelationMap *outmap = NULL;
     79  double distance = 0.;
     80  int n[NDIM];
     81  Vector checkX;
     82  Vector periodicX;
     83  int Othern[NDIM];
     84  Vector checkOtherX;
     85  Vector periodicOtherX;
     86
     87  if (molecules->ListOfMolecules.empty()) {
     88    cerr << Verbose(1) <<"No molecule given." << endl;
     89    return outmap;
     90  }
     91  outmap = new PairCorrelationMap;
     92  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
     93    if ((*MolWalker)->ActiveFlag) {
     94      const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
     95      const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
     96      cerr << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     97      atom *Walker = (*MolWalker)->start;
     98      while (Walker->next != (*MolWalker)->end) {
     99        Walker = Walker->next;
     100        *out << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     101        if ((type1 == NULL) || (Walker->type == type1)) {
     102          periodicX.CopyVector(Walker->node);
     103          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     104          // go through every range in xyz and get distance
     105          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     106            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     107              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     108                checkX.Init(n[0], n[1], n[2]);
     109                checkX.AddVector(&periodicX);
     110                checkX.MatrixMultiplication(FullMatrix);
     111                for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
     112                  if ((*MolOtherWalker)->ActiveFlag) {
     113                    *out << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
     114                    atom *OtherWalker = (*MolOtherWalker)->start;
     115                    while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
     116                      OtherWalker = OtherWalker->next;
     117                      *out << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
     118                      if (Walker->nr < OtherWalker->nr)
     119                        if ((type2 == NULL) || (OtherWalker->type == type2)) {
     120                          periodicOtherX.CopyVector(OtherWalker->node);
     121                          periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     122                          // go through every range in xyz and get distance
     123                          for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
     124                            for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
     125                              for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
     126                                checkOtherX.Init(Othern[0], Othern[1], Othern[2]);
     127                                checkOtherX.AddVector(&periodicOtherX);
     128                                checkOtherX.MatrixMultiplication(FullMatrix);
     129                                distance = checkX.Distance(&checkOtherX);
     130                                //*out << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
     131                                outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     132                              }
     133                        }
     134                  }
     135              }
     136            }
     137        }
     138      }
     139    }
     140
     141  return outmap;
     142};
     143
    67144/** Calculates the distance (pair) correlation between a given element and a point.
    68145 * \param *out output stream for debugging
     
    100177};
    101178
     179/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
     180 * \param *out output stream for debugging
     181 * \param *molecules list of molecules structure
     182 * \param *type element or NULL (if any element)
     183 * \param *point vector to the correlation point
     184 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
     185 * \return Map of dobules with values as pairs of atom and the vector
     186 */
     187CorrelationToPointMap *PeriodicCorrelationToPoint(  ofstream * const out, MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
     188{
     189  CorrelationToPointMap *outmap = NULL;
     190  double distance = 0.;
     191  int n[NDIM];
     192  Vector periodicX;
     193  Vector checkX;
     194
     195  if (molecules->ListOfMolecules.empty()) {
     196    *out << Verbose(1) <<"No molecule given." << endl;
     197    return outmap;
     198  }
     199  outmap = new CorrelationToPointMap;
     200  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
     201    if ((*MolWalker)->ActiveFlag) {
     202      const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
     203      const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
     204      *out << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     205      atom *Walker = (*MolWalker)->start;
     206      while (Walker->next != (*MolWalker)->end) {
     207        Walker = Walker->next;
     208        *out << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     209        if ((type == NULL) || (Walker->type == type)) {
     210          periodicX.CopyVector(Walker->node);
     211          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     212          // go through every range in xyz and get distance
     213          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     214            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     215              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     216                checkX.Init(n[0], n[1], n[2]);
     217                checkX.AddVector(&periodicX);
     218                checkX.MatrixMultiplication(FullMatrix);
     219                distance = checkX.Distance(point);
     220                *out << Verbose(4) << "Current distance is " << distance << "." << endl;
     221                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     222              }
     223        }
     224      }
     225    }
     226
     227  return outmap;
     228};
     229
    102230/** Calculates the distance (pair) correlation between a given element and a surface.
    103231 * \param *out output stream for debugging
     
    114242  class BoundaryTriangleSet *triangle = NULL;
    115243  Vector centroid;
    116   int ranges[NDIM] = {1, 1, 1};
     244
     245  if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
     246    *out << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
     247    return outmap;
     248  }
     249  outmap = new CorrelationToSurfaceMap;
     250  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
     251    if ((*MolWalker)->ActiveFlag) {
     252      *out << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     253      atom *Walker = (*MolWalker)->start;
     254      while (Walker->next != (*MolWalker)->end) {
     255        Walker = Walker->next;
     256        *out << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     257        if ((type == NULL) || (Walker->type == type)) {
     258          triangle = Surface->FindClosestTriangleToPoint(out, Walker->node, LC );
     259          if (triangle != NULL) {
     260            distance = DistanceToTrianglePlane(out, Walker->node, triangle);
     261            outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     262          }
     263        }
     264      }
     265    }
     266
     267  return outmap;
     268};
     269
     270/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
     271 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
     272 * I.e. We multiply the atom::node with the inverse of the domain matrix, i.e. transform it to \f$[0,0^3\f$, then add per
     273 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
     274 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
     275 * \param *out output stream for debugging
     276 * \param *molecules list of molecules structure
     277 * \param *type element or NULL (if any element)
     278 * \param *Surface pointer to Tesselation class surface
     279 * \param *LC LinkedCell structure to quickly find neighbouring atoms
     280 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
     281 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
     282 */
     283CorrelationToSurfaceMap *PeriodicCorrelationToSurface( ofstream * const out, MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
     284{
     285  CorrelationToSurfaceMap *outmap = NULL;
     286  double distance = 0;
     287  class BoundaryTriangleSet *triangle = NULL;
     288  Vector centroid;
    117289  int n[NDIM];
    118290  Vector periodicX;
  • src/analysis_correlation.hpp

    r99593f r7ea9e6  
    4848CorrelationToPointMap *CorrelationToPoint( ofstream * const out, MoleculeListClass * const &molecules, const element * const type, const Vector *point );
    4949CorrelationToSurfaceMap *CorrelationToSurface( ofstream * const out, MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC );
     50PairCorrelationMap *PeriodicPairCorrelation( ofstream * const out, MoleculeListClass * const &molecules, const element * const type1, const element * const  type2, const int ranges[NDIM] );
     51CorrelationToPointMap *PeriodicCorrelationToPoint( ofstream * const out, MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] );
     52CorrelationToSurfaceMap *PeriodicCorrelationToSurface( ofstream * const out, MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
    5053double GetBin ( const double value, const double BinWidth, const double BinStart );
    5154void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
  • src/builder.cpp

    r99593f r7ea9e6  
    16321632                element *elemental = periode->FindElement((const int) atoi(argv[argptr]));
    16331633                FindNonConvexBorder((ofstream *)&cout, Boundary, TesselStruct, LCList, radius, NULL);
    1634                 CorrelationToSurfaceMap *surfacemap = CorrelationToSurface( (ofstream *)&cout, molecules, elemental, TesselStruct, LCList );
     1634                int ranges[NDIM] = {1,1,1};
     1635                CorrelationToSurfaceMap *surfacemap = PeriodicCorrelationToSurface( (ofstream *)&cout, molecules, elemental, TesselStruct, LCList, ranges );
    16351636                BinPairMap *binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 0. );
    16361637                OutputCorrelation ( &binoutput, binmap );
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r99593f r7ea9e6  
    186186  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    187187  // inner point
    188   tester = binmap->lower_bound(0.);
     188  tester = binmap->lower_bound(-0.5);
    189189  CPPUNIT_ASSERT( tester != binmap->end() );
    190190  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
     
    200200  OutputCorrelation ( (ofstream *)&cout, binmap );
    201201  // three outside points
    202   tester = binmap->find(3.);
     202  tester = binmap->lower_bound(3.);
    203203  CPPUNIT_ASSERT( tester != binmap->end() );
    204204  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    205205  // inner point
    206   tester = binmap->find(0.);
     206  tester = binmap->lower_bound(-0.5);
    207207  CPPUNIT_ASSERT( tester != binmap->end() );
    208208  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
  • src/vector.cpp

    r99593f r7ea9e6  
    276276  temp.SubtractVector(PlaneOffset);
    277277  double sign = temp.ScalarProduct(PlaneNormal);
    278   sign /= fabs(sign);
     278  if (fabs(sign) > MYEPSILON)
     279    sign /= fabs(sign);
     280  else
     281    sign = 0.;
    279282
    280283  return (temp.Norm()*sign);
Note: See TracChangeset for help on using the changeset viewer.