Changeset a58c16 for src/Descriptors


Ignore:
Timestamp:
Jul 24, 2015, 4:44:35 PM (9 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:
99db9b
Parents:
f01769
git-author:
Frederik Heber <heber@…> (06/01/15 19:16:02)
git-committer:
Frederik Heber <heber@…> (07/24/15 16:44:35)
Message:

Replaced World::getAllAtoms() by const version where possible.

Location:
src/Descriptors
Files:
3 added
1 edited

Legend:

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

    rf01769 ra58c16  
    7676
    7777// some helper functions
    78 static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>())
     78static bool hasAllAtoms(
     79    std::vector<const atom*> atoms,
     80    atomId_t ids[ATOM_COUNT],
     81    std::set<atomId_t> excluded = std::set<atomId_t>())
    7982{
    8083  for(int i=0;i<ATOM_COUNT;++i){
    8184    atomId_t id = ids[i];
    8285    if(!excluded.count(id)){
    83       std::vector<atom*>::iterator iter;
     86      std::vector<const atom*>::const_iterator iter;
    8487      bool res=false;
    8588      for(iter=atoms.begin();iter!=atoms.end();++iter){
     
    9598}
    9699
    97 static bool hasNoDuplicateAtoms(std::vector<atom*> atoms)
     100static bool hasNoDuplicateAtoms(std::vector<const atom*> atoms)
    98101{
    99102  std::set<atomId_t> found;
    100   std::vector<atom*>::iterator iter;
     103  std::vector<const atom*>::const_iterator iter;
    101104  for(iter=atoms.begin();iter!=atoms.end();++iter){
    102105    int id = (*iter)->getId();
     
    111114void AtomDescriptorTest::AtomBaseSetsTest()
    112115{
    113   std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
     116  std::vector<const atom*> allAtoms = const_cast<const World &>(World::getInstance()).
     117      getAllAtoms(AllAtoms());
    114118  CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
    115119  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
    116120
    117   std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms());
     121  std::vector<const atom*> noAtoms = const_cast<const World &>(World::getInstance()).
     122      getAllAtoms(NoAtoms());
    118123  CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
    119124}
     
    166171
    167172  // get atom by descriptor
    168   World::AtomComposite atoms = World::getInstance().getAllAtoms(AtomOfMolecule(newmol->getId()));
     173  World::ConstAtomComposite atoms = const_cast<const World &>(World::getInstance()).
     174      getAllAtoms(AtomOfMolecule(newmol->getId()));
    169175  CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
    170176  CPPUNIT_ASSERT_EQUAL( (*atoms.begin())->getId(), testAtom->getId() );
     
    213219
    214220
    215 std::set<atomId_t> getIdList(const World::AtomComposite &list)
     221std::set<atomId_t> getIdList(const World::ConstAtomComposite &list)
    216222{
    217223  std::set<atomId_t> testlist;
    218   for (World::AtomComposite::const_iterator iter = list.begin();
     224  for (World::ConstAtomComposite::const_iterator iter = list.begin();
    219225      iter != list.end(); ++iter)
    220226    testlist.insert( (*iter)->getId() );
     
    236242//    Vector position(0.,0.,0.);
    237243//    Shape s = Sphere(position, distance);
    238 //    World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsByShape(s));
     244//    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
     245//        getAllAtoms(AtomsByShape(s));
    239246//    CPPUNIT_ASSERT_EQUAL( (size_t)2, atomlist.size() );
    240247//    std::set<atomId_t> reflist = getDistanceList(distance, position, atoms);
     
    247254//    Vector position(4.,0.,0.);
    248255//    Shape s = Sphere(position, distance);
    249 //    World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsByShape(s));
     256//    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
     257//        getAllAtoms(AtomsByShape(s));
    250258//    CPPUNIT_ASSERT_EQUAL( (size_t)5, atomlist.size() );
    251259//    std::set<atomId_t> reflist = getDistanceList(distance, position, atoms);
     
    258266//    Vector *position = new Vector(10.,0.,0.);
    259267//    Shape s = Sphere(position, distance);
    260 //    World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsByShape(s));
     268//    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
     269//        getAllAtoms(AtomsByShape(s));
    261270//    CPPUNIT_ASSERT_EQUAL( (size_t)1, atomlist.size() );
    262271//    std::set<atomId_t> reflist = getDistanceList(distance, *position, atoms);
     
    280289    const double distance = 1.5;
    281290    Vector position(0.,0.,0.);
    282     World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsWithinDistanceOf(distance, position));
     291    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
     292        getAllAtoms(AtomsWithinDistanceOf(distance, position));
    283293    CPPUNIT_ASSERT_EQUAL( (size_t)2, atomlist.size() );
    284294    std::set<atomId_t> reflist = getDistanceList(distance, position, atoms);
     
    289299  {
    290300    const double distance = 2.9;
    291     World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsWithinDistanceOf(distance, Vector(4.,0.,0.)));
     301    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
     302        getAllAtoms(AtomsWithinDistanceOf(distance, Vector(4.,0.,0.)));
    292303    CPPUNIT_ASSERT_EQUAL( (size_t)5, atomlist.size() );
    293304    std::set<atomId_t> reflist = getDistanceList(distance, Vector(4.,0.,0.), atoms);
     
    299310    const double distance = 1.5;
    300311    Vector *position = new Vector(10.,0.,0.);
    301     World::AtomComposite atomlist = World::getInstance().getAllAtoms(AtomsWithinDistanceOf(distance, *position));
     312    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
     313        getAllAtoms(AtomsWithinDistanceOf(distance, *position));
    302314    CPPUNIT_ASSERT_EQUAL( (size_t)1, atomlist.size() );
    303315    std::set<atomId_t> reflist = getDistanceList(distance, *position, atoms);
     
    312324  // test some elementary set operations
    313325  {
    314     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms());
     326    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     327        getAllAtoms(AllAtoms()||NoAtoms());
    315328    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    316329    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    318331
    319332  {
    320     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms());
     333    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     334        getAllAtoms(NoAtoms()||AllAtoms());
    321335    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    322336    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    324338
    325339  {
    326     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms());
     340    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     341        getAllAtoms(NoAtoms()&&AllAtoms());
    327342    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    328343  }
    329344
    330345  {
    331     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms());
     346    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     347        getAllAtoms(AllAtoms()&&NoAtoms());
    332348    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    333349  }
    334350
    335351  {
    336     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms());
     352    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     353        getAllAtoms(!AllAtoms());
    337354    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    338355  }
    339356
    340357  {
    341     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms());
     358    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     359        getAllAtoms(!NoAtoms());
    342360    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    343361    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    345363  // exclude and include some atoms
    346364  {
    347     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
     365    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     366        getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    348367    std::set<atomId_t> excluded;
    349368    excluded.insert(atomIds[ATOM_COUNT/2]);
     
    354373
    355374  {
    356     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
     375    std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
     376        getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
    357377    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    358378    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
Note: See TracChangeset for help on using the changeset viewer.