source: src/Descriptors/unittests/AtomDescriptorUnitTest.cpp@ b49568

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
Last change on this file since b49568 was b49568, checked in by Frederik Heber <heber@…>, 13 years ago

Added new descriptor AtomOfMolecule.

  • also added new unit test function.
  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[d103d3]4 * Copyright (C) 2010-2011 University of Bonn. All rights reserved.
[bcf653]5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[7a1ce5]8/*
[d766b5]9 * AtomDescriptorUnitTest.cpp
[7a1ce5]10 *
11 * Created on: Feb 9, 2010
12 * Author: crueger
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[d766b5]20#include "AtomDescriptorUnitTest.hpp"
[7a1ce5]21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25#include <iostream>
26
27#include <Descriptors/AtomDescriptor.hpp>
28#include <Descriptors/AtomIdDescriptor.hpp>
[b49568]29#include <Descriptors/AtomOfMoleculeDescriptor.hpp>
[7a1ce5]30
31#include "World.hpp"
[6f0841]32#include "Atom/atom.hpp"
[b49568]33#include "molecule.hpp"
[7a1ce5]34
[9b6b2f]35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39/********************************************** Test classes **************************************/
[7a1ce5]40// Registers the fixture into the 'registry'
[57adc7]41CPPUNIT_TEST_SUITE_REGISTRATION( AtomDescriptorTest );
[7a1ce5]42
43// set up and tear down
[57adc7]44void AtomDescriptorTest::setUp(){
[23b547]45 World::getInstance();
[7a1ce5]46 for(int i=0;i<ATOM_COUNT;++i){
[23b547]47 atoms[i]= World::getInstance().createAtom();
[57adc7]48 atomIds[i]= atoms[i]->getId();
[7a1ce5]49 }
50}
[57adc7]51
52void AtomDescriptorTest::tearDown(){
[23b547]53 World::purgeInstance();
[7a1ce5]54}
55
56// some helper functions
[57adc7]57static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){
[46d958]58 for(int i=0;i<ATOM_COUNT;++i){
[57adc7]59 atomId_t id = ids[i];
[46d958]60 if(!excluded.count(id)){
[7a1ce5]61 std::vector<atom*>::iterator iter;
62 bool res=false;
63 for(iter=atoms.begin();iter!=atoms.end();++iter){
[46d958]64 res |= (*iter)->getId() == id;
[7a1ce5]65 }
66 if(!res) {
[46d958]67 cout << "Atom " << id << " missing in returned list" << endl;
[7a1ce5]68 return false;
69 }
70 }
71 }
72 return true;
73}
74
[57adc7]75static bool hasNoDuplicateAtoms(std::vector<atom*> atoms){
76 std::set<atomId_t> found;
[7a1ce5]77 std::vector<atom*>::iterator iter;
78 for(iter=atoms.begin();iter!=atoms.end();++iter){
79 int id = (*iter)->getId();
80 if(found.count(id))
81 return false;
82 found.insert(id);
83 }
84 return true;
85}
86
87
[57adc7]88void AtomDescriptorTest::AtomBaseSetsTest(){
[23b547]89 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
[57adc7]90 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
91 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
[7a1ce5]92
[23b547]93 std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms());
[7a1ce5]94 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
95}
[57adc7]96void AtomDescriptorTest::AtomIdTest(){
[7a1ce5]97 // test Atoms from boundaries and middle of the set
98 atom* testAtom;
[23b547]99 testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
[46d958]100 CPPUNIT_ASSERT(testAtom);
101 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
[23b547]102 testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT/2]));
[46d958]103 CPPUNIT_ASSERT(testAtom);
104 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
[23b547]105 testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT-1]));
[46d958]106 CPPUNIT_ASSERT(testAtom);
107 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
108
109 // find some ID that has not been created
[57adc7]110 atomId_t outsideId=0;
[46d958]111 bool res = false;
[57adc7]112 for(outsideId=0;!res;++outsideId) {
[46d958]113 res = true;
114 for(int i = 0; i < ATOM_COUNT; ++i){
115 res &= atomIds[i]!=outsideId;
116 }
117 }
[7a1ce5]118 // test from outside of set
[23b547]119 testAtom = World::getInstance().getAtom(AtomById(outsideId));
[7a1ce5]120 CPPUNIT_ASSERT(!testAtom);
121}
[b49568]122void AtomDescriptorTest::AtomOfMoleculeTest(){
123 // test Atoms from boundaries and middle of the set
124 atom* testAtom;
125 testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
126 CPPUNIT_ASSERT(testAtom);
127 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
128
129 // create some molecule and associate atom to it
130 testAtom->setType(1);
131 molecule * newmol = World::getInstance().createMolecule();
132 newmol->AddAtom(testAtom);
133 CPPUNIT_ASSERT_EQUAL(newmol->getId(), testAtom->getMolecule()->getId());
134
135 // get atom by descriptor
136 World::AtomComposite atoms = World::getInstance().getAllAtoms(AtomOfMolecule(newmol->getId()));
137 CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
138 CPPUNIT_ASSERT_EQUAL( (*atoms.begin())->getId(), testAtom->getId() );
139
140 // remove molecule again
141 World::getInstance().destroyMolecule(newmol);
142}
[57adc7]143void AtomDescriptorTest::AtomCalcTest(){
[7a1ce5]144 // test some elementary set operations
145 {
[23b547]146 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms());
[57adc7]147 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
148 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
[7a1ce5]149 }
150
151 {
[23b547]152 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms());
[57adc7]153 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
154 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
[7a1ce5]155 }
156
157 {
[23b547]158 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms());
[7a1ce5]159 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
160 }
161
162 {
[23b547]163 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms());
[7a1ce5]164 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
165 }
166
167 {
[23b547]168 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms());
[7a1ce5]169 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
170 }
171
172 {
[23b547]173 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms());
[57adc7]174 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
175 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
[7a1ce5]176 }
177 // exclude and include some atoms
178 {
[23b547]179 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
[57adc7]180 std::set<atomId_t> excluded;
[46d958]181 excluded.insert(atomIds[ATOM_COUNT/2]);
[57adc7]182 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds,excluded));
183 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
[7a1ce5]184 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
185 }
186
187 {
[23b547]188 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
[7a1ce5]189 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
[46d958]190 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
[7a1ce5]191 }
192}
Note: See TracBrowser for help on using the repository browser.