Changeset cbc5fb for src


Ignore:
Timestamp:
Feb 25, 2010, 4:43:02 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
cf1a07
Parents:
244d26
Message:

Made the world solely responsible for creating and erasing molecules.

Location:
src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • src/Legacy/oldmenu.cpp

    r244d26 rcbc5fb  
    10931093    A++;
    10941094  }
    1095   delete(mol);
     1095  World::get()->destroyMolecule(mol);
    10961096};
    10971097
  • src/World.cpp

    r244d26 rcbc5fb  
    4747  OBSERVE;
    4848  molecule *mol = NULL;
    49   mol = new molecule(periode);
    50   molecules_deprecated->insert(mol);
     49  mol = NewMolecule();
    5150  assert(!molecules.count(currMoleculeId));
     51  mol->setId(currMoleculeId++);
    5252  // store the molecule by ID
    53   molecules[currMoleculeId++] = mol;
     53  molecules[mol->getId()] = mol;
    5454  mol->signOn(this);
    5555  return mol;
     56}
     57
     58void World::destroyMolecule(molecule* mol){
     59  OBSERVE;
     60  destroyMolecule(mol->getId());
     61}
     62
     63void World::destroyMolecule(moleculeId_t id){
     64  OBSERVE;
     65  molecule *mol = molecules[id];
     66  assert(mol);
     67  DeleteMolecule(mol);
     68  molecules.erase(id);
    5669}
    5770
     
    8396}
    8497
    85 void World::destroyAtom(int id) {
     98void World::destroyAtom(atomId_t id) {
    8699  OBSERVE;
    87100  atom *atom = atoms[id];
     
    134147    currMoleculeId(0),
    135148    periode(new periodentafel),
    136     molecules_deprecated(new MoleculeListClass),
     149    molecules_deprecated(new MoleculeListClass(this)),
    137150    atoms(),
    138151    molecules()
     
    145158  delete molecules_deprecated;
    146159  delete periode;
    147   AtomSet::iterator iter;
    148   for(iter=atoms.begin();iter!=atoms.end();++iter){
    149     DeleteAtom((*iter).second);
     160  MoleculeSet::iterator molIter;
     161  for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
     162    DeleteMolecule((*molIter).second);
     163  }
     164  molecules.clear();
     165  AtomSet::iterator atIter;
     166  for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
     167    DeleteAtom((*atIter).second);
    150168  }
    151169  atoms.clear();
  • src/World.hpp

    r244d26 rcbc5fb  
    1616#include <boost/shared_ptr.hpp>
    1717
    18 
     18#include "defs.hpp"
    1919#include "Patterns/Observer.hpp"
    2020#include "Patterns/Cacheable.hpp"
     
    4040friend class ManipulateAtomsProcess;
    4141template<typename> friend class AtomsCalculation;
    42 
    43 typedef std::map<int,atom*> AtomSet;
    44 typedef std::map<int,molecule*> MoleculeSet;
     42typedef std::map<atomId_t,atom*> AtomSet;
     43typedef std::map<moleculeId_t,molecule*> MoleculeSet;
    4544public:
    4645
     
    9089  molecule *createMolecule();
    9190
     91  void destroyMolecule(molecule*);
     92  void destroyMolecule(moleculeId_t);
     93
    9294  /**
    9395   * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
     
    112114   * atom directly since this will leave the pointer inside the world.
    113115   */
    114   void destroyAtom(int);
     116  void destroyAtom(atomId_t);
    115117
    116118  /**
     
    166168  periodentafel *periode;
    167169  AtomSet atoms;
    168   int currAtomId; //!< stores the next available Id for atoms
     170  atomId_t currAtomId; //!< stores the next available Id for atoms
    169171  MoleculeSet molecules;
    170   int currMoleculeId;
     172  moleculeId_t currMoleculeId;
    171173
    172174
  • src/boundary.cpp

    r244d26 rcbc5fb  
    44 */
    55
     6#include "World.hpp"
    67#include "atom.hpp"
    78#include "bond.hpp"
     
    800801{
    801802        Info FunctionInfo(__func__);
    802   molecule *Filling = new molecule(filler->elemente);
     803  molecule *Filling = World::get()->createMolecule();
    803804  Vector CurrentPosition;
    804805  int N[NDIM];
  • src/builder.cpp

    r244d26 rcbc5fb  
    14321432     }
    14331433     if (mol == NULL) {
    1434        mol = new molecule(periode);
     1434       mol = World::get()->createMolecule();
    14351435       mol->ActiveFlag = true;
    14361436       if (ConfigFileName != NULL)
     
    16341634                Log() << Verbose(1) << "Filling Box with water molecules." << endl;
    16351635                // construct water molecule
    1636                 molecule *filler = new molecule(periode);
     1636                molecule *filler = World::get()->createMolecule();
    16371637                molecule *Filling = NULL;
    16381638                atom *second = NULL, *third = NULL;
     
    16641664                  molecules->insert(Filling);
    16651665                }
    1666                 delete(filler);
     1666                World::get()->destroyMolecule(filler);
    16671667                argptr+=6;
    16681668              }
     
    22032203    if(World::get()->numMolecules() == 0){
    22042204        mol = World::get()->createMolecule();
     2205        World::get()->getMolecules()->insert(mol);
     2206        cout << "Molecule created" << endl;
    22052207        if(mol->cell_size[0] == 0.){
    22062208            Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
  • src/config.cpp

    r244d26 rcbc5fb  
    851851void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    852852{
    853   molecule *mol = new molecule(periode);
     853  molecule *mol = World::get()->createMolecule();
    854854  ifstream *file = new ifstream(filename);
    855855  if (file == NULL) {
     
    10891089void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    10901090{
    1091   molecule *mol = new molecule(periode);
     1091  molecule *mol = World::get()->createMolecule();
    10921092  ifstream *file = new ifstream(filename);
    10931093  if (file == NULL) {
     
    17881788  char filename[MAXSTRINGSIZE];
    17891789  ofstream output;
    1790   molecule *mol = new molecule(periode);
     1790  molecule *mol = World::get()->createMolecule();
    17911791  mol->SetNameFromFilename(ConfigFileName);
    17921792
     
    18991899  }
    19001900
    1901   delete(mol);
     1901  World::get()->destroyMolecule(mol);
    19021902};
    19031903
  • src/defs.hpp

    r244d26 rcbc5fb  
    3232
    3333enum Shading { white, lightgray, darkgray, black };  //!< color in Breadth-First-Search analysis
     34
     35// some types that can stay abstract
     36typedef unsigned int moleculeId_t;
     37typedef int atomId_t;
    3438
    3539//enum CutCyclicBond { KeepBond,  SaturateBond }; //!< Saturation scheme either atom- or bondwise
  • src/molecule.cpp

    r244d26 rcbc5fb  
    5353};
    5454
     55molecule *NewMolecule(){
     56  return new molecule(World::get()->getPeriode());
     57}
     58
    5559/** Destructor of class molecule.
    5660 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
     
    6670
    6771
     72void DeleteMolecule(molecule *mol){
     73  delete mol;
     74}
     75
    6876// getter and setter
    6977const std::string molecule::getName(){
     
    7482  OBSERVE;
    7583  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
     84}
     85
     86moleculeId_t molecule::getId(){
     87  return id;
     88}
     89
     90void molecule::setId(moleculeId_t _id){
     91  id =_id;
    7692}
    7793
  • src/molecule.hpp

    r244d26 rcbc5fb  
    2929#include <string>
    3030
     31#include "defs.hpp"
    3132#include "graph.hpp"
    3233#include "stackclass.hpp"
     
    8586 */
    8687class molecule : public PointCloud , public Observable {
     88  friend molecule *NewMolecule();
     89  friend void DeleteMolecule(molecule *);
    8790  public:
    8891    double cell_size[6];//!< cell size
     
    108111  private:
    109112    Cacheable<string> formula;
     113    moleculeId_t id;
     114  protected:
     115    molecule(const periodentafel * const teil);
     116    virtual ~molecule();
     117
    110118
    111119public:
    112   molecule(const periodentafel * const teil);
    113   virtual ~molecule();
    114 
    115120  //getter and setter
    116121  const std::string getName();
     122  moleculeId_t getId();
     123  void setId(moleculeId_t);
    117124  void setName(const std::string);
    118125  const std::string getFormula();
    119126  std::string calcFormula();
     127
    120128
    121129  // re-definition of virtual functions from PointCloud
     
    321329};
    322330
     331molecule *NewMolecule();
     332void DeleteMolecule(molecule* mol);
     333
    323334#include "molecule_template.hpp"
    324335
     
    330341    int MaxIndex;
    331342
    332   MoleculeListClass();
     343  MoleculeListClass(World *world);
    333344  ~MoleculeListClass();
    334345
     
    363374
    364375  private:
     376  World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
    365377};
    366378
  • src/molecule_dynamics.cpp

    r244d26 rcbc5fb  
    66 */
    77
     8#include "World.hpp"
    89#include "atom.hpp"
    910#include "config.hpp"
     
    485486  bool status = true;
    486487  int MaxSteps = configuration.MaxOuterStep;
    487   MoleculeListClass *MoleculePerStep = new MoleculeListClass();
     488  MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::get());
    488489  // Get the Permutation Map by MinimiseConstrainedPotential
    489490  atom **PermutationMap = NULL;
     
    505506  Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl;
    506507  for (int step = 0; step <= MaxSteps; step++) {
    507     mol = new molecule(elemente);
     508    mol = World::get()->createMolecule();
    508509    MoleculePerStep->insert(mol);
    509510    Walker = start;
  • src/molecule_fragmentation.cpp

    r244d26 rcbc5fb  
    88#include <cstring>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    675676  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    676677  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    677   BondFragments = new MoleculeListClass();
     678  BondFragments = new MoleculeListClass(World::get());
    678679  int k=0;
    679680  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     
    926927{
    927928  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    928   molecule *Leaf = new molecule(elemente);
     929  molecule *Leaf = World::get()->createMolecule();
    929930
    930931//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
  • src/moleculelist.cpp

    r244d26 rcbc5fb  
    77#include <cstring>
    88
     9#include "World.hpp"
    910#include "atom.hpp"
    1011#include "bond.hpp"
     
    2425/** Constructor for MoleculeListClass.
    2526 */
    26 MoleculeListClass::MoleculeListClass()
     27MoleculeListClass::MoleculeListClass(World *_world) :
     28  world(_world)
    2729{
    2830  // empty lists
     
    3840  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    3941    Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl;
    40     delete (*ListRunner);
     42    world->destroyMolecule(*ListRunner);
    4143  }
    4244  Log() << Verbose(4) << "Freeing ListOfMolecules." << endl;
     
    213215  // remove src
    214216  ListOfMolecules.remove(srcmol);
    215   delete(srcmol);
     217  World::get()->destroyMolecule(srcmol);
    216218  return true;
    217219};
     
    748750void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
    749751{
    750   molecule *mol = new molecule(periode);
     752  molecule *mol = World::get()->createMolecule();
    751753  atom *Walker = NULL;
    752754  atom *Advancer = NULL;
     
    773775    }
    774776    // remove the molecule
    775     delete(*MolRunner);
     777    World::get()->destroyMolecule(*MolRunner);
    776778    ListOfMolecules.erase(MolRunner);
    777779  }
     
    795797  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    796798  for (int i=0;i<MolCount;i++) {
    797     molecules[i] = (molecule*) new molecule(mol->elemente);
     799    molecules[i] = World::get()->createMolecule();
    798800    molecules[i]->ActiveFlag = true;
    799801    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     
    893895  OBSERVE;
    894896  molecule *mol = NULL;
    895   mol = new molecule(periode);
     897  mol = World::get()->createMolecule();
    896898  insert(mol);
    897899};
     
    902904  char filename[MAXSTRINGSIZE];
    903905  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
    904   mol = new molecule(periode);
     906  mol = World::get()->createMolecule();
    905907  do {
    906908    Log() << Verbose(0) << "Enter file name: ";
     
    960962      mol = *ListRunner;
    961963      ListOfMolecules.erase(ListRunner);
    962       delete(mol);
     964      World::get()->destroyMolecule(mol);
    963965      break;
    964966    }
     
    10071009  // remove the leaf itself
    10081010  if (Leaf != NULL) {
    1009     delete (Leaf);
     1011    World::get()->destroyMolecule(Leaf);
    10101012    Leaf = NULL;
    10111013  }
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r244d26 rcbc5fb  
    5252
    5353  // construct periodentafel
    54   tafel = new periodentafel;
     54  tafel = World::get()->getPeriode();
    5555  tafel->AddElement(hydrogen);
    5656
    5757  // construct molecule (tetraeder of hydrogens)
    58   TestMolecule = new molecule(tafel);
     58  TestMolecule = World::get()->createMolecule();
    5959  Walker = World::get()->createAtom();
    6060  Walker->type = hydrogen;
     
    7777  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    7878
    79   TestList = new MoleculeListClass;
     79  TestList = World::get()->getMolecules();
    8080  TestMolecule->ActiveFlag = true;
    8181  TestList->insert(TestMolecule);
     
    9898    delete(binmap);
    9999
    100   // remove
    101   delete(TestList);
    102   // note that all the atoms are cleaned by TestMolecule
    103100  delete(point);
    104   delete(tafel);
    105   // note that element is cleaned by periodentafel
     101  World::destroy();
    106102};
    107103
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r244d26 rcbc5fb  
    5656
    5757  // construct periodentafel
    58   tafel = new periodentafel;
     58  tafel = World::get()->getPeriode();
    5959  tafel->AddElement(hydrogen);
    6060  tafel->AddElement(carbon);
    6161
    6262  // construct molecule (tetraeder of hydrogens) base
    63   TestMolecule = new molecule(tafel);
     63  TestMolecule = World::get()->createMolecule();
    6464  Walker = World::get()->createAtom();
    6565  Walker->type = hydrogen;
     
    8282  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8383
    84   TestList = new MoleculeListClass;
     84  TestList = World::get()->getMolecules();
    8585  TestMolecule->ActiveFlag = true;
    8686  TestList->insert(TestMolecule);
     
    127127    delete(binmap);
    128128
    129   // remove
    130   delete(TestList);
    131129  delete(Surface);
    132130  // note that all the atoms are cleaned by TestMolecule
    133131  delete(LC);
    134   delete(tafel);
    135   // note that element is cleaned by periodentafel
     132  World::destroy();
    136133};
    137134
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r244d26 rcbc5fb  
    5151
    5252  // construct periodentafel
    53   tafel = new periodentafel;
     53  tafel = World::get()->getPeriode();
    5454  tafel->AddElement(hydrogen);
    5555
    5656  // construct molecule (tetraeder of hydrogens)
    57   TestMolecule = new molecule(tafel);
     57  TestMolecule = World::get()->createMolecule();
    5858  Walker = World::get()->createAtom();
    5959  Walker->type = hydrogen;
     
    7676  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    7777
    78   TestList = new MoleculeListClass;
     78  TestList = World::get()->getMolecules();
    7979  TestMolecule->ActiveFlag = true;
    8080  TestList->insert(TestMolecule);
     
    9494    delete(binmap);
    9595
    96   // remove
    97   delete(TestList);
    9896  // note that all the atoms are cleaned by TestMolecule
    99   delete(tafel);
    100   // note that element is cleaned by periodentafel
     97  World::destroy();
    10198};
    10299
  • src/unittests/Makefile.am

    r244d26 rcbc5fb  
    3030  CacheableTest \
    3131  DescriptorUnittest \
    32   manipulateAtomsTest \ 
     32  manipulateAtomsTest \
    3333  atomsCalculationTest \
    3434  ${MENUTESTS}
  • src/unittests/analysisbondsunittest.cpp

    r244d26 rcbc5fb  
    5757
    5858  // construct periodentafel
    59   tafel = new periodentafel;
     59  tafel = World::get()->getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161  tafel->AddElement(carbon);
    6262
    6363  // construct molecule (tetraeder of hydrogens)
    64   TestMolecule = new molecule(tafel);
     64  TestMolecule = World::get()->createMolecule();
    6565  Walker = World::get()->createAtom();
    6666  Walker->type = hydrogen;
     
    113113
    114114  // remove molecule
    115   delete(TestMolecule);
     115  World::get()->destroyMolecule(TestMolecule);
    116116  // note that all the atoms are cleaned by TestMolecule
    117   delete(tafel);
    118   // note that element is cleaned by periodentafel
     117  World::destroy();
    119118};
    120119
  • src/unittests/bondgraphunittest.cpp

    r244d26 rcbc5fb  
    5252
    5353  // construct periodentafel
    54   tafel = new periodentafel;
     54  tafel = World::get()->getPeriode();
    5555  tafel->AddElement(hydrogen);
    5656  tafel->AddElement(carbon);
    5757
    5858  // construct molecule (tetraeder of hydrogens)
    59   TestMolecule = new molecule(tafel);
     59  TestMolecule = World::get()->createMolecule();
    6060  Walker = World::get()->createAtom();
    6161  Walker->type = hydrogen;
     
    9797
    9898  // remove molecule
    99   delete(TestMolecule);
     99  World::get()->destroyMolecule(TestMolecule);
    100100  // note that all the atoms are cleaned by TestMolecule
    101   delete(tafel);
    102   // note that element is cleaned by periodentafel
     101  World::destroy();
    103102};
    104103
  • src/unittests/listofbondsunittest.cpp

    r244d26 rcbc5fb  
    4646
    4747  // construct periodentafel
    48   tafel = new periodentafel;
     48  tafel = World::get()->getPeriode();
    4949  tafel->AddElement(hydrogen);
    5050
    5151  // construct molecule (tetraeder of hydrogens)
    52   TestMolecule = new molecule(tafel);
     52  TestMolecule = World::get()->createMolecule();
    5353  Walker = World::get()->createAtom();
    5454  Walker->type = hydrogen;
     
    7777{
    7878  // remove
    79   delete(TestMolecule);
     79  World::get()->destroyMolecule(TestMolecule);
    8080  // note that all the atoms are cleaned by TestMolecule
    81   delete(tafel);
    82   // note that element is cleaned by periodentafel
     81  World::destroy();
    8382};
    8483
Note: See TracChangeset for help on using the changeset viewer.