source: src/unittests/MoleculeUnitTest.cpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures 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_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex 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_IntegrationTest 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_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef was aeb694, checked in by Frederik Heber <heber@…>, 11 years ago

Added molecule::getBoundingShape() (renamed old to ...Sphere()).

  • renamed molecule::getBoundingShape() to molecule::getBoundingSphere().
  • new molecule::getBoundingShape() creates vdW spheres around every atom.
  • for this to be any fast we require the Cacheable change for And and OrShapes.
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * MoleculeUnitTest.cpp
25 *
26 * Created on: Mar 19, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
39#include <algorithm>
40
41#include "Atom/atom.hpp"
42#include "CodePatterns/Assert.hpp"
43#include "Element/element.hpp"
44#include "Element/periodentafel.hpp"
45#include "molecule.hpp"
46
47#include "MoleculeUnitTest.hpp"
48
49
50#ifdef HAVE_TESTRUNNER
51#include "UnitTestMain.hpp"
52#endif /*HAVE_TESTRUNNER*/
53
54/********************************************** Test classes **************************************/
55
56// Registers the fixture into the 'registry'
57CPPUNIT_TEST_SUITE_REGISTRATION( MoleculeUnittest );
58
59size_t MoleculeUnittest::MaxAtoms = 6;
60
61void MoleculeUnittest::setUp(){
62 // failing asserts should be thrown
63 ASSERT_DO(Assert::Throw);
64
65 atomVector.resize((size_t)MaxAtoms);
66 std::generate_n(atomVector.begin(), MaxAtoms,
67 boost::bind(&World::createAtom, boost::ref(World::getInstance())));
68 std::for_each(atomVector.begin(), atomVector.end(),
69 boost::bind(static_cast<void (AtomInfo::*)(int)>(&AtomInfo::setType), _1, (atomicNumber_t)1));
70
71 mol = new molecule;
72 std::for_each(atomVector.begin(), atomVector.end(),
73 boost::bind(&molecule::AddAtom, boost::ref(mol), _1));
74}
75
76void MoleculeUnittest::tearDown()
77{
78 delete mol;
79 World::purgeInstance();
80}
81
82/** Unit test for molecule::getBoundingSphere() with a linear chain
83 *
84 */
85void MoleculeUnittest::getBoundingSphereTest_linearchain()
86{
87 // prepare a chain of atoms
88 double offset = 0.;
89 BOOST_FOREACH(atom *_atom, atomVector) {
90 _atom->setPosition( Vector(offset, 0., 0.) );
91 offset += 1.;
92 }
93
94 {
95 // get bounding shape
96 Shape s = mol->getBoundingSphere();
97
98 // check that each atom is truely inside the shape
99 BOOST_FOREACH(atom *_atom, atomVector) {
100 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
101 }
102 }
103}
104
105/** Unit test for molecule::getBoundingSphere() with a v-shaped molecule.
106 *
107 */
108void MoleculeUnittest::getBoundingSphereTest_vshaped()
109{
110 double xoffset = -2.5;
111 double yoffset = -2.5;
112 double yadder = -1;
113 BOOST_FOREACH(atom *_atom, atomVector) {
114 _atom->setPosition( Vector(xoffset, yoffset, 0.) );
115 xoffset += 1.;
116 yoffset -= yadder;
117 if (yoffset <= 0) {
118 yadder = 1.;
119 }
120 }
121
122 {
123 // get bounding shape
124 Shape s = mol->getBoundingSphere();
125
126 // check that each atom is truely inside the shape
127 BOOST_FOREACH(atom *_atom, atomVector) {
128 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
129 }
130 }
131}
132
133/** Unit test for molecule::getBoundingShape() with a linear chain
134 *
135 */
136void MoleculeUnittest::getBoundingShapeTest_linearchain()
137{
138 // prepare a chain of atoms
139 double offset = 0.;
140 BOOST_FOREACH(atom *_atom, atomVector) {
141 _atom->setPosition( Vector(offset, 0., 0.) );
142 offset += 1.;
143 }
144
145 {
146 // get bounding shape
147 Shape s = mol->getBoundingShape();
148
149 // check that each atom is truely inside the shape
150 BOOST_FOREACH(atom *_atom, atomVector) {
151 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
152 }
153 }
154}
155
156/** Unit test for molecule::getBoundingShape() with a v-shaped molecule.
157 *
158 */
159void MoleculeUnittest::getBoundingShapeTest_vshaped()
160{
161 double xoffset = -2.5;
162 double yoffset = -2.5;
163 double yadder = -1;
164 BOOST_FOREACH(atom *_atom, atomVector) {
165 _atom->setPosition( Vector(xoffset, yoffset, 0.) );
166 xoffset += 1.;
167 yoffset -= yadder;
168 if (yoffset <= 0) {
169 yadder = 1.;
170 }
171 }
172
173 {
174 // get bounding shape
175 Shape s = mol->getBoundingShape();
176
177 // check that each atom is truely inside the shape
178 BOOST_FOREACH(atom *_atom, atomVector) {
179 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
180 }
181 }
182}
Note: See TracBrowser for help on using the repository browser.