Ignore:
Timestamp:
Sep 14, 2016, 7:02:33 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
Children:
1af2ae
Parents:
36bd59
git-author:
Frederik Heber <heber@…> (07/12/14 19:07:44)
git-committer:
Frederik Heber <heber@…> (09/14/16 07:02:33)
Message:

recurseMatching() now takes connections into account.

  • matchSphericalPointDistribution() replaced by getRemainingPoints() as that describes what it does. match...() sounds symmetrical which the function is no longer as connection is associated with former _newpolygon.
  • SphericalPointDistribution now has internal points and adjacency, initialized by initSelf().
  • findBestMatching() and getRemainingPoints() are no longer static functions.
  • all unit tests are working again, including the .._multiple() that tests for joint points due to bond degree greater than 1.
  • the huge case switch in SaturatedFragment::saturateAtom() now resides in initSelf().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/SphericalPointDistribution.cpp

    r36bd59 rfe90ab  
    480480      for (IndexList_t::iterator iter = _indices.begin();
    481481          (iter != _indices.end()) && (!_MCS.foundflag);) {
     482
    482483        // check whether we can stay in the current bin or have to move on to next one
    483484        if (*_remainiter == 0) {
     
    490491          }
    491492        }
    492         // advance in matching to same position
     493
     494        // advance in matching to current bin to fill in
    493495        const size_t OldIndex = std::distance(_remainingweights.begin(), _remainiter);
    494496        while (_matching.size() <= OldIndex) { // add empty lists of new bin is opened
     
    498500        IndexTupleList_t::iterator filliniter = _matching.begin();
    499501        std::advance(filliniter, OldIndex);
     502
     503        // check whether connection between bins' indices and candidate is satisfied
     504        {
     505          adjacency_t::const_iterator finder = _MCS.adjacency.find(*iter);
     506          ASSERT( finder != _MCS.adjacency.end(),
     507              "recurseMatchings() - "+toString(*iter)+" is not in adjacency list.");
     508          if ((!filliniter->empty())
     509              && (finder->second.find(*filliniter->begin()) == finder->second.end())) {
     510            LOG(5, "DEBUG; Skipping index " << *iter
     511                << " as is not connected to current set." << *filliniter << ".");
     512            ++iter; // note that for loop does not contain incrementor
     513            continue;
     514          }
     515        }
     516
    500517        // add index to matching
    501518        filliniter->push_back(*iter);
     
    532549}
    533550
     551SphericalPointDistribution::MatchingControlStructure::MatchingControlStructure(
     552    const adjacency_t &_adjacency,
     553    const VectorArray_t &_oldpoints,
     554    const VectorArray_t &_newpoints,
     555    const WeightsArray_t &_weights
     556    ) :
     557  foundflag(false),
     558  bestL2(std::numeric_limits<double>::max()),
     559  adjacency(_adjacency),
     560  oldpoints(_oldpoints),
     561  newpoints(_newpoints),
     562  weights(_weights)
     563{}
     564
    534565/** Finds combinatorially the best matching between points in \a _polygon
    535566 * and \a _newpolygon.
     
    551582 */
    552583SphericalPointDistribution::IndexList_t SphericalPointDistribution::findBestMatching(
    553     const WeightedPolygon_t &_polygon,
    554     Polygon_t &_newpolygon
     584    const WeightedPolygon_t &_polygon
    555585    )
    556586{
    557   MatchingControlStructure MCS;
    558   MCS.foundflag = false;
    559   MCS.bestL2 = std::numeric_limits<double>::max();
    560587  // transform lists into arrays
     588  VectorArray_t oldpoints;
     589  VectorArray_t newpoints;
     590  WeightsArray_t weights;
    561591  for (WeightedPolygon_t::const_iterator iter = _polygon.begin();
    562592      iter != _polygon.end(); ++iter) {
    563     MCS.oldpoints.push_back(iter->first);
    564     MCS.weights.push_back(iter->second);
    565   }
    566   MCS.newpoints.insert(MCS.newpoints.begin(), _newpolygon.begin(),_newpolygon.end() );
     593    oldpoints.push_back(iter->first);
     594    weights.push_back(iter->second);
     595  }
     596  newpoints.insert(newpoints.begin(), points.begin(), points.end() );
     597  MatchingControlStructure MCS(adjacency, oldpoints, newpoints, weights);
    567598
    568599  // search for bestmatching combinatorially
    569600  {
    570601    // translate polygon into vector to enable index addressing
    571     IndexList_t indices(_newpolygon.size());
     602    IndexList_t indices(points.size());
    572603    std::generate(indices.begin(), indices.end(), UniqueNumber);
    573604    IndexTupleList_t matching;
     
    594625  // combine multiple points and create simple IndexList from IndexTupleList
    595626  const SphericalPointDistribution::IndexList_t IndexList =
    596       joinPoints(_newpolygon, MCS.newpoints, MCS.bestmatching);
     627      joinPoints(points, MCS.newpoints, MCS.bestmatching);
    597628
    598629  return IndexList;
     
    781812}
    782813
     814void SphericalPointDistribution::initSelf(const int _NumberOfPoints)
     815{
     816  switch (_NumberOfPoints)
     817  {
     818    case 0:
     819      points = get<0>();
     820      adjacency = getConnections<0>();
     821      break;
     822    case 1:
     823      points = get<1>();
     824      adjacency = getConnections<1>();
     825      break;
     826    case 2:
     827      points = get<2>();
     828      adjacency = getConnections<2>();
     829      break;
     830    case 3:
     831      points = get<3>();
     832      adjacency = getConnections<3>();
     833      break;
     834    case 4:
     835      points = get<4>();
     836      adjacency = getConnections<4>();
     837      break;
     838    case 5:
     839      points = get<5>();
     840      adjacency = getConnections<5>();
     841      break;
     842    case 6:
     843      points = get<6>();
     844      adjacency = getConnections<6>();
     845      break;
     846    case 7:
     847      points = get<7>();
     848      adjacency = getConnections<7>();
     849      break;
     850    case 8:
     851      points = get<8>();
     852      adjacency = getConnections<8>();
     853      break;
     854    case 9:
     855      points = get<9>();
     856      adjacency = getConnections<9>();
     857      break;
     858    case 10:
     859      points = get<10>();
     860      adjacency = getConnections<10>();
     861      break;
     862    case 11:
     863      points = get<11>();
     864      adjacency = getConnections<11>();
     865      break;
     866    case 12:
     867      points = get<12>();
     868      adjacency = getConnections<12>();
     869      break;
     870    case 14:
     871      points = get<14>();
     872      adjacency = getConnections<14>();
     873      break;
     874    default:
     875      ASSERT(0, "SphericalPointDistribution::initSelf() - cannot deal with the case "
     876          +toString(_NumberOfPoints)+".");
     877  }
     878  LOG(3, "DEBUG: Ideal polygon is " << points);
     879}
    783880
    784881SphericalPointDistribution::Polygon_t
    785 SphericalPointDistribution::matchSphericalPointDistributions(
    786     const SphericalPointDistribution::WeightedPolygon_t &_polygon,
    787     SphericalPointDistribution::Polygon_t &_newpolygon
    788     )
     882SphericalPointDistribution::getRemainingPoints(
     883    const WeightedPolygon_t &_polygon,
     884    const int _N)
    789885{
    790886  SphericalPointDistribution::Polygon_t remainingpoints;
    791887
     888  // initialze to given number of points
     889  initSelf(_N);
    792890  LOG(2, "INFO: Matching old polygon " << _polygon
    793       << " with new polygon " << _newpolygon);
    794 
    795   if (_polygon.size() == _newpolygon.size()) {
    796     // same number of points desired as are present? Do nothing
    797     LOG(2, "INFO: There are no vacant points to return.");
     891      << " with new polygon " << points);
     892
     893  // check whether any points will remain vacant
     894  int RemainingPoints = _N;
     895  for (WeightedPolygon_t::const_iterator iter = _polygon.begin();
     896      iter != _polygon.end(); ++iter)
     897    RemainingPoints -= iter->second;
     898  if (RemainingPoints == 0)
    798899    return remainingpoints;
    799   }
    800 
    801   if (_polygon.size() > 0) {
    802     IndexList_t bestmatching = findBestMatching(_polygon, _newpolygon);
     900
     901  if (_N > 0) {
     902    IndexList_t bestmatching = findBestMatching(_polygon);
    803903    LOG(2, "INFO: Best matching is " << bestmatching);
    804904
     
    819919    newSet.indices.resize(NumberIds, -1);
    820920    std::copy(beginiter, enditer, newSet.indices.begin());
    821     std::copy(_newpolygon.begin(),_newpolygon.end(), std::back_inserter(newSet.polygon));
     921    std::copy(points.begin(),points.end(), std::back_inserter(newSet.polygon));
    822922
    823923    // determine rotation angles to align the two point distributions with
     
    9271027    return remainingpoints;
    9281028  } else
    929     return _newpolygon;
    930 }
     1029    return points;
     1030}
Note: See TracChangeset for help on using the changeset viewer.