Changeset c6ddcb for src/Fragmentation


Ignore:
Timestamp:
Sep 14, 2016, 6:42:52 PM (8 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, 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:
028790
Parents:
c24071
git-author:
Frederik Heber <heber@…> (03/10/16 14:40:45)
git-committer:
Frederik Heber <heber@…> (09/14/16 18:42:52)
Message:

Added getRoughBoundingBox to SaturatedFragment.

Location:
src/Fragmentation/Exporters
Files:
4 edited

Legend:

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

    rc24071 rc6ddcb  
    3838#include "SaturatedFragment.hpp"
    3939
     40#include <algorithm>
    4041#include <cmath>
    4142#include <iostream>
     43
     44#include <boost/bind.hpp>
     45#include <boost/function.hpp>
    4246
    4347#include "CodePatterns/Assert.hpp"
     
    611615  return AllWentWell;
    612616};
     617
     618#ifdef HAVE_INLINE
     619inline
     620#else
     621static
     622#endif
     623void updateVector(Vector &_first, const Vector &_second,
     624    const boost::function<const double& (const double &, const double &)> &_comparator)
     625{
     626  for (size_t i=0;i<NDIM;++i)
     627    _first[i] = _comparator(_first[i], _second[i]);
     628}
     629
     630std::pair<Vector, Vector> SaturatedFragment::getRoughBoundingBox() const
     631{
     632  typedef boost::function<const double& (const double &, const double &)> comparator_t;
     633  static const comparator_t minimizer = boost::bind(&std::min<double>, _1, _2);
     634  static const comparator_t maximizer = boost::bind(&std::max<double>, _1, _2);
     635  // initialize return values
     636  Vector minimum;
     637  Vector maximum;
     638  for (size_t i=0;i<NDIM;++i) {
     639    minimum[i] = std::numeric_limits<double>::max();
     640    maximum[i] = -std::numeric_limits<double>::max();
     641  }
     642
     643  // go through all "core" atoms of the fragment
     644  const std::vector<atom *> atoms = gatherAllAtoms(FullMolecule);
     645  for (std::vector<atom *>::const_iterator iter = atoms.begin();
     646      iter != atoms.end(); ++iter) {
     647    const Vector &position = (*iter)->getPosition();
     648    updateVector(minimum, position, minimizer);
     649    updateVector(maximum, position, maximizer);
     650  }
     651
     652  // go through each atom of the fragment and gather all cut bonds in list
     653  const CutBonds_t CutBonds = gatherCutBonds(atoms, set, treatment);
     654  for (CutBonds_t::const_iterator atomiter = CutBonds.begin();
     655      atomiter != CutBonds.end(); ++atomiter) {
     656    const atom * const walker = atomiter->first;
     657    const BondList &cutbonds = atomiter->second;
     658    for (BondList::const_iterator bonditer = cutbonds.begin();
     659        bonditer != cutbonds.end(); ++bonditer) {
     660      const atom * const OtherWalker = (*bonditer)->GetOtherAtom(walker);
     661      const Vector &position = OtherWalker->getPosition();
     662      updateVector(minimum, position, minimizer);
     663      updateVector(maximum, position, maximizer);
     664    }
     665  }
     666
     667  return std::make_pair(minimum, maximum);
     668}
  • src/Fragmentation/Exporters/SaturatedFragment.hpp

    rc24071 rc6ddcb  
    9999    return SaturationHydrogens;
    100100  }
     101
     102  /** Determines the bounding box of the fragment without performing the hydrogen
     103   * saturation but by simply using the atoms whose bonds are cut.
     104   *
     105   * \return pair of Vector with min and max coordinates
     106   */
     107  std::pair<Vector, Vector> getRoughBoundingBox() const;
    101108
    102109  /** Prints the config of the fragment of \a _type to \a out.
  • src/Fragmentation/Exporters/unittests/SaturatedFragmentUnitTest.cpp

    rc24071 rc6ddcb  
    5050#include "CodePatterns/Assert.hpp"
    5151
     52#include "Atom/atom.hpp"
     53#include "Atom/AtomObserver.hpp"
     54#include "Element/element.hpp"
     55#include "Element/periodentafel.hpp"
    5256#include "Fragmentation/HydrogenSaturation_enum.hpp"
     57#include "molecule.hpp"
     58#include "World.hpp"
     59#include "WorldTime.hpp"
    5360
    5461#ifdef HAVE_TESTRUNNER
     
    6976  ASSERT_DO(Assert::Throw);
    7077
     78  // construct element
     79  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     80  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
     81  oxygen = World::getInstance().getPeriode()->FindElement(8);
     82  CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
     83
     84  // construct molecule (tetraeder of hydrogens)
     85  TestMolecule = World::getInstance().createMolecule();
     86  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
     87  atom * Walker = World::getInstance().createAtom();
     88  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     89  Walker->setType(oxygen);
     90  Walker->setPosition(Vector(1., 0., 1. ));
     91  TestMolecule->AddAtom(Walker);
     92  Walker = World::getInstance().createAtom();
     93  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     94  Walker->setType(hydrogen);
     95  Walker->setPosition(Vector(0., 1., 1. ));
     96  TestMolecule->AddAtom(Walker);
     97  Walker = World::getInstance().createAtom();
     98  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     99  Walker->setType(hydrogen);
     100  Walker->setPosition(Vector(1., 1., 0. ));
     101
     102  // construct fragment keyset
    71103  SaturatedFragment::GlobalSaturationPositions_t globalpositions;
    72104  set = new KeySet;
     105  set->insert(0);
     106  set->insert(1);
     107  set->insert(2);
    73108  fragment = new SaturatedFragment(
    74109      *set,
     
    78113      DoSaturate,
    79114      globalpositions);
     115
    80116}
    81117
     
    85121  delete fragment;
    86122  delete set;
     123
     124  // remove
     125  World::getInstance().destroyMolecule(TestMolecule);
     126  // note that all the atoms, molecules, the tafel and the elements
     127  // are all cleaned when the world is destroyed
     128  World::purgeInstance();
     129  AtomObserver::purgeInstance();
     130  logger::purgeInstance();
     131  errorLogger::purgeInstance();
     132  WorldTime::purgeInstance();
    87133}
    88134
     
    93139  CPPUNIT_ASSERT_EQUAL( *set, fragment->getKeySet() );
    94140}
     141
     142/** UnitTest for getRoughBoundingBox()
     143 */
     144void SaturatedFragmentTest::getRoughBoundingBox()
     145{
     146  const std::pair<Vector, Vector> minmax = fragment->getRoughBoundingBox();
     147  for (size_t i=0;i<NDIM;++i) {
     148    CPPUNIT_ASSERT( minmax.first[i] >= 0. );
     149    CPPUNIT_ASSERT( minmax.second[i] <= 1. );
     150  }
     151}
  • src/Fragmentation/Exporters/unittests/SaturatedFragmentUnitTest.hpp

    rc24071 rc6ddcb  
    2020#include "Fragmentation/Exporters/SaturatedFragment.hpp"
    2121
     22class element;
    2223class KeySet;
     24class molecule;
    2325
    2426/********************************************** Test classes **************************************/
     
    2830    CPPUNIT_TEST_SUITE( SaturatedFragmentTest) ;
    2931    CPPUNIT_TEST ( getKeySet_Test );
     32    CPPUNIT_TEST ( getRoughBoundingBox );
    3033    CPPUNIT_TEST_SUITE_END();
    3134
     
    3437      void tearDown();
    3538      void getKeySet_Test();
     39      void getRoughBoundingBox();
    3640
    3741private:
     
    4044      KeySet *set;
    4145      SaturatedFragment *fragment;
     46
     47      molecule *TestMolecule;
     48      const element *hydrogen;
     49      const element *oxygen;
    4250};
    4351
Note: See TracChangeset for help on using the changeset viewer.