Changeset 706d48
- Timestamp:
- May 18, 2016, 10:03:09 PM (9 years ago)
- Children:
- c9b843
- Parents:
- 00ea61
- git-author:
- Frederik Heber <heber@…> (03/10/16 14:40:45)
- git-committer:
- Frederik Heber <heber@…> (05/18/16 22:03:09)
- Location:
- src/Fragmentation/Exporters
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Exporters/SaturatedFragment.cpp
r00ea61 r706d48 38 38 #include "SaturatedFragment.hpp" 39 39 40 #include <algorithm> 40 41 #include <cmath> 41 42 #include <iostream> 43 44 #include <boost/bind.hpp> 45 #include <boost/function.hpp> 42 46 43 47 #include "CodePatterns/Assert.hpp" … … 608 612 return AllWentWell; 609 613 }; 614 615 #ifdef HAVE_INLINE 616 inline 617 #else 618 static 619 #endif 620 void updateVector(Vector &_first, const Vector &_second, 621 const boost::function<const double& (const double &, const double &)> &_comparator) 622 { 623 for (size_t i=0;i<NDIM;++i) 624 _first[i] = _comparator(_first[i], _second[i]); 625 } 626 627 std::pair<Vector, Vector> SaturatedFragment::getRoughBoundingBox() const 628 { 629 typedef boost::function<const double& (const double &, const double &)> comparator_t; 630 static const comparator_t minimizer = boost::bind(&std::min<double>, _1, _2); 631 static const comparator_t maximizer = boost::bind(&std::max<double>, _1, _2); 632 // initialize return values 633 Vector minimum; 634 Vector maximum; 635 for (size_t i=0;i<NDIM;++i) { 636 minimum[i] = std::numeric_limits<double>::max(); 637 maximum[i] = -std::numeric_limits<double>::max(); 638 } 639 640 // go through all "core" atoms of the fragment 641 const std::vector<atom *> atoms = gatherAllAtoms(FullMolecule); 642 for (std::vector<atom *>::const_iterator iter = atoms.begin(); 643 iter != atoms.end(); ++iter) { 644 const Vector &position = (*iter)->getPosition(); 645 updateVector(minimum, position, minimizer); 646 updateVector(maximum, position, maximizer); 647 } 648 649 // go through each atom of the fragment and gather all cut bonds in list 650 const CutBonds_t CutBonds = gatherCutBonds(atoms, set, treatment); 651 for (CutBonds_t::const_iterator atomiter = CutBonds.begin(); 652 atomiter != CutBonds.end(); ++atomiter) { 653 const atom * const walker = atomiter->first; 654 const BondList &cutbonds = atomiter->second; 655 for (BondList::const_iterator bonditer = cutbonds.begin(); 656 bonditer != cutbonds.end(); ++bonditer) { 657 const atom * const OtherWalker = (*bonditer)->GetOtherAtom(walker); 658 const Vector &position = OtherWalker->getPosition(); 659 updateVector(minimum, position, minimizer); 660 updateVector(maximum, position, maximizer); 661 } 662 } 663 664 return std::make_pair(minimum, maximum); 665 } -
src/Fragmentation/Exporters/SaturatedFragment.hpp
r00ea61 r706d48 99 99 return SaturationHydrogens; 100 100 } 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; 101 108 102 109 /** Prints the config of the fragment of \a _type to \a out. -
src/Fragmentation/Exporters/unittests/SaturatedFragmentUnitTest.cpp
r00ea61 r706d48 50 50 #include "CodePatterns/Assert.hpp" 51 51 52 #include "Atom/atom.hpp" 53 #include "Atom/AtomObserver.hpp" 54 #include "Element/element.hpp" 55 #include "Element/periodentafel.hpp" 52 56 #include "Fragmentation/HydrogenSaturation_enum.hpp" 57 #include "molecule.hpp" 58 #include "World.hpp" 59 #include "WorldTime.hpp" 53 60 54 61 #ifdef HAVE_TESTRUNNER … … 69 76 ASSERT_DO(Assert::Throw); 70 77 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 71 103 SaturatedFragment::GlobalSaturationPositions_t globalpositions; 72 104 set = new KeySet; 105 set->insert(0); 106 set->insert(1); 107 set->insert(2); 73 108 fragment = new SaturatedFragment( 74 109 *set, … … 78 113 DoSaturate, 79 114 globalpositions); 115 80 116 } 81 117 … … 85 121 delete fragment; 86 122 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(); 87 133 } 88 134 … … 93 139 CPPUNIT_ASSERT_EQUAL( *set, fragment->getKeySet() ); 94 140 } 141 142 /** UnitTest for getRoughBoundingBox() 143 */ 144 void 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
r00ea61 r706d48 20 20 #include "Fragmentation/Exporters/SaturatedFragment.hpp" 21 21 22 class element; 22 23 class KeySet; 24 class molecule; 23 25 24 26 /********************************************** Test classes **************************************/ … … 28 30 CPPUNIT_TEST_SUITE( SaturatedFragmentTest) ; 29 31 CPPUNIT_TEST ( getKeySet_Test ); 32 CPPUNIT_TEST ( getRoughBoundingBox ); 30 33 CPPUNIT_TEST_SUITE_END(); 31 34 … … 34 37 void tearDown(); 35 38 void getKeySet_Test(); 39 void getRoughBoundingBox(); 36 40 37 41 private: … … 40 44 KeySet *set; 41 45 SaturatedFragment *fragment; 46 47 molecule *TestMolecule; 48 const element *hydrogen; 49 const element *oxygen; 42 50 }; 43 51
Note:
See TracChangeset
for help on using the changeset viewer.