Changeset bbab87
- Timestamp:
- Jan 2, 2012, 1:34:29 PM (13 years ago)
- 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:
- db8960
- Parents:
- 7afb77
- git-author:
- Frederik Heber <heber@…> (12/19/11 21:57:06)
- git-committer:
- Frederik Heber <heber@…> (01/02/12 13:34:29)
- Location:
- src/Descriptors/unittests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Descriptors/unittests/AtomDescriptorUnitTest.cpp
r7afb77 rbbab87 28 28 #include <Descriptors/AtomIdDescriptor.hpp> 29 29 #include <Descriptors/AtomOfMoleculeDescriptor.hpp> 30 #include <Descriptors/AtomsWithinDistanceOfDescriptor.hpp> 30 31 31 32 #include "World.hpp" 32 33 #include "Atom/atom.hpp" 33 34 #include "molecule.hpp" 35 #include "LinearAlgebra/Vector.hpp" 34 36 35 37 #ifdef HAVE_TESTRUNNER … … 42 44 43 45 // set up and tear down 44 void AtomDescriptorTest::setUp(){ 46 void AtomDescriptorTest::setUp() 47 { 45 48 World::getInstance(); 46 49 for(int i=0;i<ATOM_COUNT;++i){ … … 50 53 } 51 54 52 void AtomDescriptorTest::tearDown(){ 55 void AtomDescriptorTest::tearDown() 56 { 53 57 World::purgeInstance(); 54 58 } 55 59 56 60 // some helper functions 57 static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){ 61 static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()) 62 { 58 63 for(int i=0;i<ATOM_COUNT;++i){ 59 64 atomId_t id = ids[i]; … … 73 78 } 74 79 75 static bool hasNoDuplicateAtoms(std::vector<atom*> atoms){ 80 static bool hasNoDuplicateAtoms(std::vector<atom*> atoms) 81 { 76 82 std::set<atomId_t> found; 77 83 std::vector<atom*>::iterator iter; … … 86 92 87 93 88 void AtomDescriptorTest::AtomBaseSetsTest(){ 94 void AtomDescriptorTest::AtomBaseSetsTest() 95 { 89 96 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 90 97 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds)); … … 94 101 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty()); 95 102 } 96 void AtomDescriptorTest::AtomIdTest(){ 103 104 void AtomDescriptorTest::AtomIdTest() 105 { 97 106 // test Atoms from boundaries and middle of the set 98 107 atom* testAtom; … … 120 129 CPPUNIT_ASSERT(!testAtom); 121 130 } 122 void AtomDescriptorTest::AtomOfMoleculeTest(){ 131 132 void AtomDescriptorTest::AtomOfMoleculeTest() 133 { 123 134 // test Atoms from boundaries and middle of the set 124 135 atom* testAtom; … … 141 152 World::getInstance().destroyMolecule(newmol); 142 153 } 143 void AtomDescriptorTest::AtomCalcTest(){ 154 155 std::set<atomId_t> getDistanceList(const double distance, const Vector &position, atom **list) 156 { 157 const double distanceSquared = distance*distance; 158 std::set<atomId_t> reflist; 159 for (size_t i=0; i<ATOM_COUNT;++i) 160 if (list[i]->getPosition().DistanceSquared(position) < distanceSquared) 161 reflist.insert ( list[i]->getId() ); 162 return reflist; 163 } 164 165 166 std::set<atomId_t> getIdList(const World::AtomComposite &list) 167 { 168 std::set<atomId_t> testlist; 169 for (World::AtomComposite::const_iterator iter = list.begin(); 170 iter != list.end(); ++iter) 171 testlist.insert( (*iter)->getId() ); 172 return testlist; 173 } 174 175 void AtomDescriptorTest::AtomsWithinDistanceOfTest() 176 { 177 // align atoms along an axis 178 for(int i=0;i<ATOM_COUNT;++i) { 179 atoms[i]->setPosition(Vector((double)i, 0., 0.)); 180 //std::cout << "atoms[" << i << "]: " << atoms[i]->getId() << " at " << atoms[i]->getPosition() << std::endl; 181 } 182 183 // get atom by descriptor ... 184 // ... from origin up to 2.5 185 { 186 const double distance = 1.5; 187 Vector position(0.,0.,0.); 188 World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsWithinDistanceOf(distance, position)); 189 CPPUNIT_ASSERT_EQUAL( (size_t)2, atomlist.size() ); 190 std::set<atomId_t> reflist = getDistanceList(distance, position, atoms); 191 std::set<atomId_t> testlist = getIdList(atomlist); 192 CPPUNIT_ASSERT_EQUAL( reflist, testlist ); 193 } 194 // ... from (4,0,0) up to 2.9 (i.e. more shells or different view) 195 { 196 const double distance = 2.9; 197 World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsWithinDistanceOf(distance, Vector(4.,0.,0.))); 198 CPPUNIT_ASSERT_EQUAL( (size_t)5, atomlist.size() ); 199 std::set<atomId_t> reflist = getDistanceList(distance, Vector(4.,0.,0.), atoms); 200 std::set<atomId_t> testlist = getIdList(atomlist); 201 CPPUNIT_ASSERT_EQUAL( reflist, testlist ); 202 } 203 // ... from (10,0,0) up to 1.5 204 { 205 const double distance = 1.5; 206 Vector *position = new Vector(10.,0.,0.); 207 World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsWithinDistanceOf(distance, *position)); 208 CPPUNIT_ASSERT_EQUAL( (size_t)1, atomlist.size() ); 209 std::set<atomId_t> reflist = getDistanceList(distance, *position, atoms); 210 std::set<atomId_t> testlist = getIdList(atomlist); 211 CPPUNIT_ASSERT_EQUAL( reflist, testlist ); 212 delete position; 213 } 214 } 215 216 void AtomDescriptorTest::AtomCalcTest() 217 { 144 218 // test some elementary set operations 145 219 { -
src/Descriptors/unittests/AtomDescriptorUnitTest.hpp
r7afb77 rbbab87 30 30 CPPUNIT_TEST ( AtomIdTest ); 31 31 CPPUNIT_TEST ( AtomOfMoleculeTest ); 32 CPPUNIT_TEST ( AtomsWithinDistanceOfTest ); 32 33 CPPUNIT_TEST ( AtomCalcTest ); 33 34 CPPUNIT_TEST_SUITE_END(); … … 40 41 void AtomOfMoleculeTest(); 41 42 void AtomIdTest(); 43 void AtomsWithinDistanceOfTest(); 42 44 void AtomCalcTest(); 43 45
Note:
See TracChangeset
for help on using the changeset viewer.