Changeset bbab87


Ignore:
Timestamp:
Jan 2, 2012, 1:34:29 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Added test for new descriptor AtomsWithinDistanceOf to AtomDescriptorUnitTest.

  • in AtomDescriptorTest::AtomsWithinDistanceOfTest(): ids must not necessarily be in order, added functions that make comparison based on simple N2 search and helper functions.
Location:
src/Descriptors/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Descriptors/unittests/AtomDescriptorUnitTest.cpp

    r7afb77 rbbab87  
    2828#include <Descriptors/AtomIdDescriptor.hpp>
    2929#include <Descriptors/AtomOfMoleculeDescriptor.hpp>
     30#include <Descriptors/AtomsWithinDistanceOfDescriptor.hpp>
    3031
    3132#include "World.hpp"
    3233#include "Atom/atom.hpp"
    3334#include "molecule.hpp"
     35#include "LinearAlgebra/Vector.hpp"
    3436
    3537#ifdef HAVE_TESTRUNNER
     
    4244
    4345// set up and tear down
    44 void AtomDescriptorTest::setUp(){
     46void AtomDescriptorTest::setUp()
     47{
    4548  World::getInstance();
    4649  for(int i=0;i<ATOM_COUNT;++i){
     
    5053}
    5154
    52 void AtomDescriptorTest::tearDown(){
     55void AtomDescriptorTest::tearDown()
     56{
    5357  World::purgeInstance();
    5458}
    5559
    5660// 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>()){
     61static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>())
     62{
    5863  for(int i=0;i<ATOM_COUNT;++i){
    5964    atomId_t id = ids[i];
     
    7378}
    7479
    75 static bool hasNoDuplicateAtoms(std::vector<atom*> atoms){
     80static bool hasNoDuplicateAtoms(std::vector<atom*> atoms)
     81{
    7682  std::set<atomId_t> found;
    7783  std::vector<atom*>::iterator iter;
     
    8692
    8793
    88 void AtomDescriptorTest::AtomBaseSetsTest(){
     94void AtomDescriptorTest::AtomBaseSetsTest()
     95{
    8996  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    9097  CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
     
    94101  CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
    95102}
    96 void AtomDescriptorTest::AtomIdTest(){
     103
     104void AtomDescriptorTest::AtomIdTest()
     105{
    97106  // test Atoms from boundaries and middle of the set
    98107  atom* testAtom;
     
    120129  CPPUNIT_ASSERT(!testAtom);
    121130}
    122 void AtomDescriptorTest::AtomOfMoleculeTest(){
     131
     132void AtomDescriptorTest::AtomOfMoleculeTest()
     133{
    123134  // test Atoms from boundaries and middle of the set
    124135  atom* testAtom;
     
    141152  World::getInstance().destroyMolecule(newmol);
    142153}
    143 void AtomDescriptorTest::AtomCalcTest(){
     154
     155std::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
     166std::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
     175void 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
     216void AtomDescriptorTest::AtomCalcTest()
     217{
    144218  // test some elementary set operations
    145219  {
  • src/Descriptors/unittests/AtomDescriptorUnitTest.hpp

    r7afb77 rbbab87  
    3030  CPPUNIT_TEST ( AtomIdTest );
    3131  CPPUNIT_TEST ( AtomOfMoleculeTest );
     32  CPPUNIT_TEST ( AtomsWithinDistanceOfTest );
    3233  CPPUNIT_TEST ( AtomCalcTest );
    3334  CPPUNIT_TEST_SUITE_END();
     
    4041  void AtomOfMoleculeTest();
    4142  void AtomIdTest();
     43  void AtomsWithinDistanceOfTest();
    4244  void AtomCalcTest();
    4345
Note: See TracChangeset for help on using the changeset viewer.