Changeset 46d958
- Timestamp:
- Feb 24, 2010, 4:21:12 PM (15 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:
- 02ee15
- Parents:
- b54ac8
- git-author:
- Tillmann Crueger <crueger@…> (02/24/10 15:29:12)
- git-committer:
- Tillmann Crueger <crueger@…> (02/24/10 16:21:12)
- Location:
- src
- Files:
-
- 1 added
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Legacy/oldmenu.cpp
rb54ac8 r46d958 9 9 #include "Legacy/oldmenu.hpp" 10 10 #include "analysis_correlation.hpp" 11 #include "World.hpp" 11 12 #include "atom.hpp" 12 13 #include "bond.hpp" … … 77 78 case 'a': // absolute coordinates of atom 78 79 Log() << Verbose(0) << "Enter absolute coordinates." << endl; 79 first = new atom;80 first = World::get()->createAtom(); 80 81 first->x.AskPosition(mol->cell_size, false); 81 82 first->type = periode->AskElement(); // give type … … 84 85 85 86 case 'b': // relative coordinates of atom wrt to reference point 86 first = new atom;87 first = World::get()->createAtom(); 87 88 valid = true; 88 89 do { … … 100 101 101 102 case 'c': // relative coordinates of atom wrt to already placed atom 102 first = new atom;103 first = World::get()->createAtom(); 103 104 valid = true; 104 105 do { … … 116 117 117 118 case 'd': // two atoms, two angles and a distance 118 first = new atom;119 first = World::get()->createAtom(); 119 120 valid = true; 120 121 do { … … 216 217 217 218 case 'e': // least square distance position to a set of atoms 218 first = new atom;219 first = World::get()->createAtom(); 219 220 atoms = new (Vector*[128]); 220 221 valid = true; … … 238 239 mol->AddAtom(first); // add to molecule 239 240 } else { 240 delete first;241 World::get()->destroyAtom(first); 241 242 Log() << Verbose(0) << "Please enter at least two vectors!\n"; 242 243 } … … 781 782 x.AddVector(&y); // per factor one cell width further 782 783 for (int k=count;k--;) { // go through every atom of the original cell 783 first = new atom(); // create a new body784 first = World::get()->createAtom(); // create a new body 784 785 first->x.CopyVector(vectors[k]); // use coordinate of original atom 785 786 first->x.AddVector(&x); // translate the coordinates -
src/Makefile.am
rb54ac8 r46d958 32 32 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp 33 33 34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp l og.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp 35 35 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 36 36 -
src/World.cpp
rb54ac8 r46d958 51 51 52 52 53 atom *World::createAtom(){ 54 OBSERVE; 55 atom *res = NewAtom(); 56 res->setId(currAtomId++); 57 res->setWorld(this); 58 atoms[res->getId()] = res; 59 return res; 60 } 61 62 int World::registerAtom(atom *atom){ 63 OBSERVE; 64 atom->setId(currAtomId++); 65 atom->setWorld(this); 66 atoms[atom->getId()] = atom; 67 return atom->getId(); 68 } 69 70 void World::destroyAtom(atom* atom){ 71 OBSERVE; 72 int id = atom->getId(); 73 destroyAtom(id); 74 } 75 76 void World::destroyAtom(int id) { 77 OBSERVE; 78 atom *atom = atoms[id]; 79 assert(atom); 80 DeleteAtom(atom); 81 atoms.erase(id); 82 } 83 53 84 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ 54 85 return new ManipulateAtomsProcess(op, descr,name,true); … … 160 191 161 192 World::World() : 162 dummyId(0),193 currAtomId(0), 163 194 periode(new periodentafel), 164 195 molecules_deprecated(new MoleculeListClass), … … 170 201 World::~World() 171 202 { 203 delete molecules_deprecated; 172 204 delete periode; 205 AtomList::iterator iter; 206 for(iter=atoms.begin();iter!=atoms.end();++iter){ 207 DeleteAtom((*iter).second); 208 } 209 atoms.clear(); 173 210 } 174 211 … … 183 220 184 221 void World::destroy(){ 185 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise186 theWorld->destroyLegacy();187 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.188 189 222 // boost supports RAII-Style locking, so we don't need to unlock 190 223 boost::mutex::scoped_lock guard(worldLock); … … 194 227 195 228 World* World::reset(){ 196 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise197 theWorld->destroyLegacy();198 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.199 200 229 World* oldWorld = 0; 201 230 { … … 224 253 return molecules_deprecated; 225 254 } 226 227 // some legacy stuff to let the World know about items created outside228 void World::registerAtom(atom *theAtom){229 OBSERVE;230 atoms[dummyId++] = theAtom;231 }232 233 void World::destroyLegacy(){234 //delete molecules_deprecated;235 }236 237 void World::unregisterAtom(atom *theAtom){238 OBSERVE;239 atoms.erase(theAtom->getId());240 } -
src/World.hpp
rb54ac8 r46d958 58 58 /***** Methods to work with the World *****/ 59 59 molecule *createMolecule(); 60 atom *createAtom(); 61 int registerAtom(atom*); 62 void destroyAtom(atom*); 63 void destroyAtom(int); 60 64 61 65 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor); … … 95 99 periodentafel *periode; 96 100 AtomList atoms; 101 int currAtomId; //!< stores the next available Id for atoms 97 102 std::set<molecule*> molecules; 98 103 … … 120 125 MoleculeListClass *&getMolecules(); 121 126 122 // functions used for the WorldContent template mechanism123 void registerAtom(atom *theAtom);124 void unregisterAtom(atom *theAtom);125 127 private: 126 // this function cleans up anything that cannot be cleaned while the lock is active127 // at a later point all these cleanups have to be moved to the World Class so the deadlock and128 // race condition can both be avoided.129 void destroyLegacy();130 131 128 MoleculeListClass *molecules_deprecated; 132 133 // this is needed to assign unique IDs to atoms... so far134 // IDs are not assigned upon Atom creation, so we cannot query the ID135 // during construction. By using the dummy ID we can make sure all atoms136 // are actually stored in the map and don't overwrite each other.137 int dummyId;138 129 }; 139 130 -
src/atom.cpp
rb54ac8 r46d958 20 20 /** Constructor of class atom. 21 21 */ 22 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr)23 { 24 World::get()->registerAtom(this); 22 atom::atom() : 23 previous(NULL), next(NULL), father(this), sort(&nr) 24 { 25 25 node = &x; // TesselPoint::x can only be referenced from here 26 26 }; … … 28 28 /** Constructor of class atom. 29 29 */ 30 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr) 31 { 32 World::get()->registerAtom(this); 30 atom::atom(atom *pointer) : 31 ParticleInfo(pointer), 32 previous(NULL), next(NULL), father(pointer), sort(&nr) 33 { 33 34 type = pointer->type; // copy element of atom 34 35 x.CopyVector(&pointer->x); // copy coordination … … 38 39 }; 39 40 41 atom *atom::clone(){ 42 atom *res = new atom(); 43 res->previous=0; 44 res->next=0; 45 res->father = this; 46 res->sort = &nr; 47 res->type = type; 48 res->x.CopyVector(&this->x); 49 res->v.CopyVector(&this->v); 50 res->FixedIon = FixedIon; 51 res->node = &x; 52 World::get()->registerAtom(res); 53 return res; 54 } 55 40 56 41 57 /** Destructor of class atom. … … 43 59 atom::~atom() 44 60 { 45 World::get()->unregisterAtom(this);46 61 unlink(this); 47 62 }; … … 267 282 }; 268 283 284 World *atom::getWorld(){ 285 return world; 286 } 287 288 void atom::setWorld(World* _world){ 289 world = _world; 290 } 291 292 void atom::setId(int _id) { 293 id=_id; 294 } 295 296 int atom::getId() { 297 return id; 298 } 299 300 atom* NewAtom(){ 301 return new atom(); 302 } 303 304 void DeleteAtom(atom* atom){ 305 delete atom; 306 } -
src/atom.hpp
rb54ac8 r46d958 32 32 33 33 class Vector; 34 class World; 34 35 35 36 /********************************************** declarations *******************************/ … … 39 40 */ 40 41 class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo { 42 friend atom* NewAtom(); 43 friend void DeleteAtom(atom*); 41 44 public: 42 45 atom *previous; //!< previous atom in molecule list … … 45 48 int *sort; //!< sort criteria 46 49 47 atom(); 48 atom(class atom *pointer); 49 virtual ~atom(); 50 virtual atom *clone(); 50 51 51 52 bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const; … … 67 68 bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const; 68 69 70 // getter and setter 71 72 /** 73 * returns the World that contains this atom. 74 * Use this if you need to get the world without locking 75 * the singleton for example. 76 * 77 */ 78 World *getWorld(); 79 void setWorld(World*); 80 81 virtual int getId(); 82 virtual void setId(int); 83 protected: 84 /** 85 * Protected constructor to ensure construction of atoms through the world. 86 * see World::createAtom() 87 */ 88 atom(); 89 90 /** 91 * Protected copy-constructor to ensure construction of atoms by cloning. 92 * see atom::clone() 93 */ 94 atom(class atom *pointer); 95 96 /** 97 * Protected destructor to ensure destruction of atoms through the world. 98 * see World::destroyAtom() 99 */ 100 virtual ~atom(); 69 101 private: 102 World* world; 103 int id; 70 104 }; 71 105 106 /** 107 * internal method used by the world. Do not use if you don't know what you are doing. 108 * You might get burned... 109 * Use World::createAtom() instead. 110 */ 111 atom* NewAtom(); 112 113 /** 114 * internal method used by the world. Do not use if you don't know what you are doing. 115 * You might get burned... 116 * Use World::destroyAtom() instead. 117 */ 118 void DeleteAtom(atom*); 119 120 72 121 #endif /* ATOM_HPP_ */ -
src/atom_particleinfo.cpp
rb54ac8 r46d958 13 13 ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {}; 14 14 15 ParticleInfo::ParticleInfo(ParticleInfo *pointer) : 16 Name(pointer->Name), 17 nr(pointer->nr) 18 {} 19 20 15 21 /** Destructor of ParticleInfo. 16 22 */ … … 19 25 Free(&Name); 20 26 }; 21 22 int ParticleInfo::getId() {23 return nr;24 }25 27 26 28 ostream & operator << (ostream &ost, const ParticleInfo &a) -
src/atom_particleinfo.hpp
rb54ac8 r46d958 31 31 32 32 ParticleInfo(); 33 ParticleInfo(ParticleInfo*); 33 34 ~ParticleInfo(); 34 35 35 36 ostream & operator << (ostream &ost) const; 36 37 virtual int getId();38 37 39 38 private: -
src/boundary.cpp
rb54ac8 r46d958 887 887 Walker = Walker->next; 888 888 // copy atom ... 889 CopyAtoms[Walker->nr] = new atom(Walker);889 CopyAtoms[Walker->nr] = Walker->clone(); 890 890 891 891 // create atomic random translation vector ... -
src/builder.cpp
rb54ac8 r46d958 1481 1481 SaveFlag = true; 1482 1482 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; 1483 first = new atom;1483 first = World::get()->createAtom(); 1484 1484 first->type = periode->FindElement(atoi(argv[argptr])); 1485 1485 if (first->type != NULL) … … 1641 1641 // first->x.Zero(); 1642 1642 // filler->AddAtom(first); 1643 first = new atom();1643 first = World::get()->createAtom(); 1644 1644 first->type = periode->FindElement(1); 1645 1645 first->x.Init(0.441, -0.143, 0.); 1646 1646 filler->AddAtom(first); 1647 second = new atom();1647 second = World::get()->createAtom(); 1648 1648 second->type = periode->FindElement(1); 1649 1649 second->x.Init(-0.464, 1.137, 0.0); 1650 1650 filler->AddAtom(second); 1651 third = new atom();1651 third = World::get()->createAtom(); 1652 1652 third->type = periode->FindElement(8); 1653 1653 third->x.Init(-0.464, 0.177, 0.); … … 2097 2097 x.AddVector(&y); // per factor one cell width further 2098 2098 for (int k=count;k--;) { // go through every atom of the original cell 2099 first = new atom(); // create a new body2099 first = World::get()->createAtom(); // create a new body 2100 2100 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2101 2101 first->x.AddVector(&x); // translate the coordinates -
src/config.cpp
rb54ac8 r46d958 8 8 #include <cstring> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 732 733 sprintf(keyword,"%s_%i",name, j+1); 733 734 if (repetition == 0) { 734 neues = new atom();735 neues = World::get()->createAtom(); 735 736 AtomList[i][j] = neues; 736 737 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 811 812 sprintf(keyword,"%s_%i",name, j+1); 812 813 if (repetition == 0) { 813 neues = new atom();814 neues = World::get()->createAtom(); 814 815 AtomList[i][j] = neues; 815 816 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 1287 1288 } 1288 1289 istringstream input2(zeile); 1289 atom *neues = new atom();1290 atom *neues = World::get()->createAtom(); 1290 1291 input2 >> neues->x.x[0]; // x 1291 1292 input2 >> neues->x.x[1]; // y -
src/lists.hpp
rb54ac8 r46d958 9 9 #define LISTS_HPP_ 10 10 11 class atom; 12 11 13 /******************************** Some templates for list management ***********************************/ 12 14 … … 18 20 { 19 21 X *vorher = end->previous; 20 if (vorher != NULL)22 if (vorher != 0) 21 23 vorher->next = walker; 22 24 end->previous = walker; … … 31 33 template <typename X> void unlink(X *walker) 32 34 { 33 if (walker->next != NULL)35 if (walker->next != 0) 34 36 walker->next->previous = walker->previous; 35 if (walker->previous != NULL)37 if (walker->previous != 0) 36 38 walker->previous->next = walker->next; 37 walker->next = NULL;38 walker->previous= NULL;39 walker->next = 0; 40 walker->previous= 0; 39 41 }; 40 42 … … 46 48 template <typename X> bool add(X *pointer, X *end) 47 49 { 48 if (end != NULL) {50 if (end != 0) { 49 51 link(pointer, end); 50 52 } else { 51 pointer->previous = NULL;52 pointer->next = NULL;53 pointer->previous = 0; 54 pointer->next = 0; 53 55 } 54 56 return true; … … 59 61 * \param *start begin of list 60 62 * \param *end end of list 61 * \return X - if found, NULL- if not found63 * \return X - if found, 0 - if not found 62 64 */ 63 65 template <typename X, typename Y> X * find(Y *suche, X *start, X *end) … … 68 70 if (*walker->sort == *suche) return (walker); 69 71 } 70 return NULL;72 return 0; 71 73 }; 72 74 … … 77 79 template <typename X> void removewithoutcheck(X *walker) 78 80 { 79 if (walker != NULL) {81 if (walker != 0) { 80 82 unlink(walker); 81 83 delete(walker); 82 walker = NULL;84 walker = 0; 83 85 } 84 86 }; 87 88 /** Removes an item from the list without check. 89 * specialized for atoms, because these have to be removed from the world as well 90 * the implementation for this declaration is in lists.cpp 91 * \param *walker item to be removed 92 * \return true - removing succeeded, false - given item not found in list 93 */ 94 template <> void removewithoutcheck<atom>(atom *walker); 85 95 86 96 /** Removes an item from the list, checks if exists. … … 99 109 }*/ 100 110 // atom found, now unlink 101 if (walker != NULL)111 if (walker != 0) 102 112 removewithoutcheck(walker); 103 113 else … … 114 124 { 115 125 X *pointer = start->next; 116 X *walker = NULL;126 X *walker = 0; 117 127 while (pointer != end) { // go through list 118 128 walker = pointer; // mark current … … 131 141 { 132 142 X *Binder = me; 133 while(Binder->previous != NULL)143 while(Binder->previous != 0) 134 144 Binder = Binder->previous; 135 145 return Binder; … … 143 153 { 144 154 X *Binder = me; 145 while(Binder->next != NULL)155 while(Binder->next != 0) 146 156 Binder = Binder->next; 147 157 return Binder; -
src/molecule.cpp
rb54ac8 r46d958 8 8 #include <boost/bind.hpp> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 30 31 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 31 32 */ 32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start( new atom), end(new atom),33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()), 33 34 first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0), 34 35 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), … … 60 61 delete(first); 61 62 delete(last); 62 delete(end);63 delete(start);63 end->getWorld()->destroyAtom(end); 64 start->getWorld()->destroyAtom(start); 64 65 }; 65 66 … … 135 136 OBSERVE; 136 137 if (pointer != NULL) { 137 atom *walker = new atom(pointer);138 atom *walker = pointer->clone(); 138 139 walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name"); 139 140 strcpy (walker->Name, pointer->Name); … … 242 243 switch(TopBond->BondDegree) { 243 244 case 1: 244 FirstOtherAtom = new atom(); // new atom245 FirstOtherAtom = World::get()->createAtom(); // new atom 245 246 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 246 247 FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity … … 299 300 300 301 // create the two Hydrogens ... 301 FirstOtherAtom = new atom();302 SecondOtherAtom = new atom();302 FirstOtherAtom = World::get()->createAtom(); 303 SecondOtherAtom = World::get()->createAtom(); 303 304 FirstOtherAtom->type = elemente->FindElement(1); 304 305 SecondOtherAtom->type = elemente->FindElement(1); … … 354 355 case 3: 355 356 // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid) 356 FirstOtherAtom = new atom();357 SecondOtherAtom = new atom();358 ThirdOtherAtom = new atom();357 FirstOtherAtom = World::get()->createAtom(); 358 SecondOtherAtom = World::get()->createAtom(); 359 ThirdOtherAtom = World::get()->createAtom(); 359 360 FirstOtherAtom->type = elemente->FindElement(1); 360 361 SecondOtherAtom->type = elemente->FindElement(1); … … 475 476 MDSteps++; 476 477 for(i=0;i<NumberOfAtoms;i++){ 477 Walker = new atom;478 Walker = World::get()->createAtom(); 478 479 getline(xyzfile,line,'\n'); 479 480 istringstream *item = new istringstream(line); -
src/moleculelist.cpp
rb54ac8 r46d958 342 342 Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl; 343 343 if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) { 344 CopyAtoms[Walker->nr] = new atom(Walker);344 CopyAtoms[Walker->nr] = Walker->clone(); 345 345 mol->AddAtom(CopyAtoms[Walker->nr]); 346 346 nr++; -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
rb54ac8 r46d958 17 17 #include "AnalysisCorrelationToPointUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 56 57 // construct molecule (tetraeder of hydrogens) 57 58 TestMolecule = new molecule(tafel); 58 Walker = new atom();59 Walker = World::get()->createAtom(); 59 60 Walker->type = hydrogen; 60 61 Walker->node->Init(1., 0., 1. ); 61 62 TestMolecule->AddAtom(Walker); 62 Walker = new atom();63 Walker = World::get()->createAtom(); 63 64 Walker->type = hydrogen; 64 65 Walker->node->Init(0., 1., 1. ); 65 66 TestMolecule->AddAtom(Walker); 66 Walker = new atom();67 Walker = World::get()->createAtom(); 67 68 Walker->type = hydrogen; 68 69 Walker->node->Init(1., 1., 0. ); 69 70 TestMolecule->AddAtom(Walker); 70 Walker = new atom();71 Walker = World::get()->createAtom(); 71 72 Walker->type = hydrogen; 72 73 Walker->node->Init(0., 0., 0. ); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
rb54ac8 r46d958 17 17 #include "AnalysisCorrelationToSurfaceUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 61 62 // construct molecule (tetraeder of hydrogens) base 62 63 TestMolecule = new molecule(tafel); 63 Walker = new atom();64 Walker = World::get()->createAtom(); 64 65 Walker->type = hydrogen; 65 66 Walker->node->Init(1., 0., 1. ); 66 67 TestMolecule->AddAtom(Walker); 67 Walker = new atom();68 Walker = World::get()->createAtom(); 68 69 Walker->type = hydrogen; 69 70 Walker->node->Init(0., 1., 1. ); 70 71 TestMolecule->AddAtom(Walker); 71 Walker = new atom();72 Walker = World::get()->createAtom(); 72 73 Walker->type = hydrogen; 73 74 Walker->node->Init(1., 1., 0. ); 74 75 TestMolecule->AddAtom(Walker); 75 Walker = new atom();76 Walker = World::get()->createAtom(); 76 77 Walker->type = hydrogen; 77 78 Walker->node->Init(0., 0., 0. ); … … 94 95 95 96 // add outer atoms 96 Walker = new atom();97 Walker = World::get()->createAtom(); 97 98 Walker->type = carbon; 98 99 Walker->node->Init(4., 0., 4. ); 99 100 TestMolecule->AddAtom(Walker); 100 Walker = new atom();101 Walker = World::get()->createAtom(); 101 102 Walker->type = carbon; 102 103 Walker->node->Init(0., 4., 4. ); 103 104 TestMolecule->AddAtom(Walker); 104 Walker = new atom();105 Walker = World::get()->createAtom(); 105 106 Walker->type = carbon; 106 107 Walker->node->Init(4., 4., 0. ); 107 108 TestMolecule->AddAtom(Walker); 108 109 // add inner atoms 109 Walker = new atom();110 Walker = World::get()->createAtom(); 110 111 Walker->type = carbon; 111 112 Walker->node->Init(0.5, 0.5, 0.5 ); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
rb54ac8 r46d958 17 17 #include "AnalysisPairCorrelationUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 55 56 // construct molecule (tetraeder of hydrogens) 56 57 TestMolecule = new molecule(tafel); 57 Walker = new atom();58 Walker = World::get()->createAtom(); 58 59 Walker->type = hydrogen; 59 60 Walker->node->Init(1., 0., 1. ); 60 61 TestMolecule->AddAtom(Walker); 61 Walker = new atom();62 Walker = World::get()->createAtom(); 62 63 Walker->type = hydrogen; 63 64 Walker->node->Init(0., 1., 1. ); 64 65 TestMolecule->AddAtom(Walker); 65 Walker = new atom();66 Walker = World::get()->createAtom(); 66 67 Walker->type = hydrogen; 67 68 Walker->node->Init(1., 1., 0. ); 68 69 TestMolecule->AddAtom(Walker); 69 Walker = new atom();70 Walker = World::get()->createAtom(); 70 71 Walker->type = hydrogen; 71 72 Walker->node->Init(0., 0., 0. ); -
src/unittests/DescriptorUnittest.cpp
rb54ac8 r46d958 22 22 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest ); 23 23 24 // some stubs25 class AtomStub : public atom {26 public:27 AtomStub(int _id) :28 atom(),29 id(_id)30 {}31 32 virtual int getId(){33 return id;34 }35 36 private:37 int id;38 };39 40 41 24 // set up and tear down 42 25 void DescriptorUnittest::setUp(){ 43 26 World::get(); 44 27 for(int i=0;i<ATOM_COUNT;++i){ 45 atoms[i]= new AtomStub(i); 28 atoms[i]= World::get()->createAtom(); 29 atomIds[i] = atoms[i]->getId(); 46 30 } 47 31 } 48 32 void DescriptorUnittest::tearDown(){ 49 33 World::destroy(); 50 for(int i=0;i<ATOM_COUNT;++i){51 delete atoms[i];52 }53 34 } 54 35 55 36 // some helper functions 56 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){ 57 for(int i=min;i<max;++i){ 58 if(!excluded.count(i)){ 37 bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){ 38 for(int i=0;i<ATOM_COUNT;++i){ 39 int id = ids[i]; 40 if(!excluded.count(id)){ 59 41 std::vector<atom*>::iterator iter; 60 42 bool res=false; 61 43 for(iter=atoms.begin();iter!=atoms.end();++iter){ 62 res |= (*iter)->getId() == i ;44 res |= (*iter)->getId() == id; 63 45 } 64 46 if(!res) { 65 cout << "Atom " << i << " missing in returned list" << endl;47 cout << "Atom " << id << " missing in returned list" << endl; 66 48 return false; 67 49 } … … 86 68 void DescriptorUnittest::AtomBaseSetsTest(){ 87 69 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms()); 88 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms, 0,ATOM_COUNT));70 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds)); 89 71 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms)); 90 72 … … 95 77 // test Atoms from boundaries and middle of the set 96 78 atom* testAtom; 97 testAtom = World::get()->getAtom(AtomById(0)); 98 CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId()); 99 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2)); 100 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId()); 101 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1)); 102 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId()); 79 testAtom = World::get()->getAtom(AtomById(atomIds[0])); 80 CPPUNIT_ASSERT(testAtom); 81 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId()); 82 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2])); 83 CPPUNIT_ASSERT(testAtom); 84 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId()); 85 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1])); 86 CPPUNIT_ASSERT(testAtom); 87 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId()); 103 88 89 // find some ID that has not been created 90 int outsideId =-1; 91 bool res = false; 92 while(!res) { 93 ++outsideId; 94 res = true; 95 for(int i = 0; i < ATOM_COUNT; ++i){ 96 res &= atomIds[i]!=outsideId; 97 } 98 } 104 99 // test from outside of set 105 testAtom = World::get()->getAtom(AtomById( ATOM_COUNT));100 testAtom = World::get()->getAtom(AtomById(outsideId)); 106 101 CPPUNIT_ASSERT(!testAtom); 107 102 } … … 110 105 { 111 106 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms()); 112 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));107 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 113 108 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 114 109 } … … 116 111 { 117 112 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms()); 118 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));113 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 119 114 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 120 115 } … … 137 132 { 138 133 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms()); 139 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));134 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 140 135 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 141 136 } … … 143 138 // exclude and include some atoms 144 139 { 145 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById( ATOM_COUNT/2)));140 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2]))); 146 141 std::set<int> excluded; 147 excluded.insert( ATOM_COUNT/2);148 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT,excluded));142 excluded.insert(atomIds[ATOM_COUNT/2]); 143 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded)); 149 144 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 150 145 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); … … 152 147 153 148 { 154 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById( ATOM_COUNT/2)));149 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2]))); 155 150 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 156 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());151 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId()); 157 152 } 158 153 } -
src/unittests/DescriptorUnittest.hpp
rb54ac8 r46d958 33 33 private: 34 34 atom *atoms [ATOM_COUNT]; 35 int atomIds [ATOM_COUNT]; 35 36 }; 36 37 -
src/unittests/Makefile.am
rb54ac8 r46d958 30 30 CacheableTest \ 31 31 DescriptorUnittest \ 32 manipulateAtomsTest \ 32 manipulateAtomsTest \ 33 33 atomsCalculationTest \ 34 ${MENUTESTS} 35 34 ${MENUTESTS} 35 36 37 36 38 37 39 check_PROGRAMS = $(TESTS) -
src/unittests/analysisbondsunittest.cpp
rb54ac8 r46d958 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "analysis_bonds.hpp" 19 20 #include "analysisbondsunittest.hpp" … … 62 63 // construct molecule (tetraeder of hydrogens) 63 64 TestMolecule = new molecule(tafel); 64 Walker = new atom();65 Walker = World::get()->createAtom(); 65 66 Walker->type = hydrogen; 66 67 Walker->node->Init(1.5, 0., 1.5 ); 67 68 TestMolecule->AddAtom(Walker); 68 Walker = new atom();69 Walker = World::get()->createAtom(); 69 70 Walker->type = hydrogen; 70 71 Walker->node->Init(0., 1.5, 1.5 ); 71 72 TestMolecule->AddAtom(Walker); 72 Walker = new atom();73 Walker = World::get()->createAtom(); 73 74 Walker->type = hydrogen; 74 75 Walker->node->Init(1.5, 1.5, 0. ); 75 76 TestMolecule->AddAtom(Walker); 76 Walker = new atom();77 Walker = World::get()->createAtom(); 77 78 Walker->type = hydrogen; 78 79 Walker->node->Init(0., 0., 0. ); 79 80 TestMolecule->AddAtom(Walker); 80 Walker = new atom();81 Walker = World::get()->createAtom(); 81 82 Walker->type = carbon; 82 83 Walker->node->Init(0.5, 0.5, 0.5 ); -
src/unittests/atomsCalculationTest.cpp
rb54ac8 r46d958 54 54 for(int i=0;i<ATOM_COUNT;++i){ 55 55 atoms[i]= new AtomStub(i); 56 World::get()->registerAtom(atoms[i]); 56 57 } 57 58 } 58 59 void atomsCalculationTest::tearDown(){ 59 60 World::destroy(); 60 for(int i=0;i<ATOM_COUNT;++i){61 delete atoms[i];62 }63 61 ActionRegistry::purgeRegistry(); 64 62 } -
src/unittests/atomsCalculationTest.hpp
rb54ac8 r46d958 31 31 private: 32 32 atom *atoms [ATOM_COUNT]; 33 int atomIds [ATOM_COUNT]; 33 34 }; 34 35 -
src/unittests/bondgraphunittest.cpp
rb54ac8 r46d958 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 57 58 // construct molecule (tetraeder of hydrogens) 58 59 TestMolecule = new molecule(tafel); 59 Walker = new atom();60 Walker = World::get()->createAtom(); 60 61 Walker->type = hydrogen; 61 62 Walker->node->Init(1., 0., 1. ); 62 63 TestMolecule->AddAtom(Walker); 63 Walker = new atom();64 Walker = World::get()->createAtom(); 64 65 Walker->type = hydrogen; 65 66 Walker->node->Init(0., 1., 1. ); 66 67 TestMolecule->AddAtom(Walker); 67 Walker = new atom();68 Walker = World::get()->createAtom(); 68 69 Walker->type = hydrogen; 69 70 Walker->node->Init(1., 1., 0. ); 70 71 TestMolecule->AddAtom(Walker); 71 Walker = new atom();72 Walker = World::get()->createAtom(); 72 73 Walker->type = hydrogen; 73 74 Walker->node->Init(0., 0., 0. ); -
src/unittests/listofbondsunittest.cpp
rb54ac8 r46d958 16 16 #include "listofbondsunittest.hpp" 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 50 51 // construct molecule (tetraeder of hydrogens) 51 52 TestMolecule = new molecule(tafel); 52 Walker = new atom();53 Walker = World::get()->createAtom(); 53 54 Walker->type = hydrogen; 54 55 Walker->node->Init(1., 0., 1. ); 55 56 TestMolecule->AddAtom(Walker); 56 Walker = new atom();57 Walker = World::get()->createAtom(); 57 58 Walker->type = hydrogen; 58 59 Walker->node->Init(0., 1., 1. ); 59 60 TestMolecule->AddAtom(Walker); 60 Walker = new atom();61 Walker = World::get()->createAtom(); 61 62 Walker->type = hydrogen; 62 63 Walker->node->Init(1., 1., 0. ); 63 64 TestMolecule->AddAtom(Walker); 64 Walker = new atom();65 Walker = World::get()->createAtom(); 65 66 Walker->type = hydrogen; 66 67 Walker->node->Init(0., 0., 0. ); … … 242 243 243 244 // remove atom2 244 delete(atom2);245 World::get()->destroyAtom(atom2); 245 246 246 247 // check bond if removed from other atom -
src/unittests/manipulateAtomsTest.cpp
rb54ac8 r46d958 69 69 for(int i=0;i<ATOM_COUNT;++i){ 70 70 atoms[i]= new AtomStub(i); 71 World::get()->registerAtom(atoms[i]); 71 72 } 72 73 } 73 74 void manipulateAtomsTest::tearDown(){ 74 75 World::destroy(); 75 for(int i=0;i<ATOM_COUNT;++i){76 delete atoms[i];77 }78 76 ActionRegistry::purgeRegistry(); 79 77 }
Note:
See TracChangeset
for help on using the changeset viewer.