Changeset ead4e6 for src


Ignore:
Timestamp:
Mar 12, 2010, 1:16:01 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:
745a85
Parents:
c3dbe0
Message:

Made the periodentafel use STL-containers instead of custom llists

Location:
src
Files:
1 added
27 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AtomsCalculation_impl.hpp

    rc3dbe0 read4e6  
    1919AtomsCalculation<T>::AtomsCalculation(boost::function<T(atom*)> _op,std::string name,AtomDescriptor _descr) :
    2020  Calculation<std::vector<T> >(0,name,false),
    21   op(_op),
    22   descr(_descr)
     21  descr(_descr),
     22  op(_op)
    2323{}
    2424
  • src/Actions/Calculation_impl.hpp

    rc3dbe0 read4e6  
    1616Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister) :
    1717  Process(_maxSteps,_name,_doRegister),
    18   done(false),
    19   result(0)
     18  result(0),
     19  done(false)
    2020{}
    2121
  • src/Descriptors/AtomTypeDescriptor.cpp

    rc3dbe0 read4e6  
    1313#include "periodentafel.hpp"
    1414
    15 AtomTypeDescriptor_impl::AtomTypeDescriptor_impl(element* _type) :
     15AtomTypeDescriptor_impl::AtomTypeDescriptor_impl(const element* _type) :
    1616  type(_type)
    1717{}
     
    2424}
    2525
    26 AtomDescriptor AtomByType(element *elem){
     26AtomDescriptor AtomByType(const element *elem){
    2727  return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomTypeDescriptor_impl(elem)));
    2828}
    2929
    3030AtomDescriptor AtomByType(int Z){
    31   element * elem = World::getInstance().getPeriode()->FindElement(Z);
     31  const element * elem = World::getInstance().getPeriode()->FindElement(Z);
    3232  return AtomByType(elem);
    3333}
  • src/Descriptors/AtomTypeDescriptor.hpp

    rc3dbe0 read4e6  
    1313class element;
    1414
    15 AtomDescriptor AtomByType(element *);
     15AtomDescriptor AtomByType(const element *);
    1616AtomDescriptor AtomByType(int);
    1717
  • src/Descriptors/AtomTypeDescriptor_impl.hpp

    rc3dbe0 read4e6  
    1414{
    1515public:
    16   AtomTypeDescriptor_impl(element* _type);
     16  AtomTypeDescriptor_impl(const element* _type);
    1717  virtual ~AtomTypeDescriptor_impl();
    1818
    1919  bool predicate(std::pair<atomId_t,atom*> atom);
    2020private:
    21   element *type;
     21  const element * const type;
    2222};
    2323
  • src/Legacy/oldmenu.cpp

    rc3dbe0 read4e6  
    748748  int axis,faktor,count,j;
    749749  atom *first = NULL;
    750   element **Elements;
     750  const element **Elements;
    751751  Vector x,y;
    752752  Vector **vectors;
     
    764764    if (mol->AtomCount != 0) {  // if there is more than none
    765765      count = mol->AtomCount;  // is changed becausing of adding, thus has to be stored away beforehand
    766       Elements = new element *[count];
     766      Elements = new const element *[count];
    767767      vectors = new Vector *[count];
    768768      j = 0;
  • src/World.hpp

    rc3dbe0 read4e6  
    1616#include <boost/shared_ptr.hpp>
    1717
    18 #include "defs.hpp"
     18#include "types.hpp"
    1919#include "Patterns/Observer.hpp"
    2020#include "Patterns/Cacheable.hpp"
  • src/atom.hpp

    rc3dbe0 read4e6  
    2828#include "atom_trajectoryparticle.hpp"
    2929#include "tesselation.hpp"
     30#include "types.hpp"
    3031
    3132/****************************************** forward declarations *****************************/
  • src/atom_atominfo.cpp

    rc3dbe0 read4e6  
    2020};
    2121
    22 element *AtomInfo::getType(){
     22const element *AtomInfo::getType(){
    2323  return type;
    2424}
    2525
    26 void AtomInfo::setType(element* _type) {
     26void AtomInfo::setType(const element* _type) {
    2727  type = _type;
    2828}
    2929
    3030void AtomInfo::setType(int Z) {
    31   element *elem = World::getInstance().getPeriode()->FindElement(Z);
     31  const element *elem = World::getInstance().getPeriode()->FindElement(Z);
    3232  setType(elem);
    3333}
  • src/atom_atominfo.hpp

    rc3dbe0 read4e6  
    3232  Vector v;       //!< velocity vector of atom, giving last velocity within cell
    3333  Vector F;       //!< Force vector of atom, giving last force within cell
    34   element *type;  //!< pointing to element
     34  const element *type;  //!< pointing to element
    3535
    3636  AtomInfo();
    3737  ~AtomInfo();
    3838
    39   element *getType();
    40   void setType(element *);
     39  const element *getType();
     40  void setType(const element *);
    4141  void setType(int);
    4242
  • src/builder.cpp

    rc3dbe0 read4e6  
    15931593                }
    15941594                LCList = new LinkedCell(Boundary, 2.*radius);
    1595                 element *elemental = periode->FindElement((const int) atoi(argv[argptr]));
     1595                const element *elemental = periode->FindElement((atomicNumber_t) atoi(argv[argptr]));
    15961596                FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
    15971597                int ranges[NDIM] = {1,1,1};
     
    20702070                  int faktor = atoi(argv[argptr++]);
    20712071                  int count;
    2072                   element ** Elements;
     2072                  const element ** Elements;
    20732073                  Vector ** vectors;
    20742074                  if (faktor < 1) {
    2075                     eLog() << Verbose(1) << "Repetition factor mus be greater than 1!" << endl;
     2075                    eLog() << Verbose(1) << "Repetition factor must be greater than 1!" << endl;
    20762076                    faktor = 1;
    20772077                  }
     
    20792079                  if (mol->AtomCount != 0) {  // if there is more than none
    20802080                    count = mol->AtomCount;   // is changed becausing of adding, thus has to be stored away beforehand
    2081                     Elements = new element *[count];
     2081                    Elements = new const element *[count];
    20822082                    vectors = new Vector *[count];
    20832083                    j = 0;
  • src/config.cpp

    rc3dbe0 read4e6  
    675675{
    676676  int MaxTypes = 0;
    677   element *elementhash[MAX_ELEMENTS];
     677  const element *elementhash[MAX_ELEMENTS];
    678678  char name[MAX_ELEMENTS];
    679679  char keyword[MAX_ELEMENTS];
     
    11071107  string zeile;
    11081108  string dummy;
    1109   element *elementhash[128];
     1109  const element *elementhash[128];
    11101110  int Z = -1;
    11111111  int No = -1;
  • src/defs.hpp

    rc3dbe0 read4e6  
    3333enum Shading { white, lightgray, darkgray, black };  //!< color in Breadth-First-Search analysis
    3434
    35 // some types that can stay abstract
    36 typedef unsigned int moleculeId_t;
    37 typedef unsigned int atomId_t;
     35
    3836
    3937//enum CutCyclicBond { KeepBond,  SaturateBond }; //!< Saturation scheme either atom- or bondwise
     
    8583#define STD_SEPERATOR_SPACER '-'
    8684
    87 // some types used to set template parameters
    88 struct true_type{
    89   enum{value=1};
    90 };
    91 struct false_type{
    92   enum{value = 0};
    93 };
    94 
    9585#endif /*DEFS_HPP_*/
  • src/element.cpp

    rc3dbe0 read4e6  
    99
    1010#include "element.hpp"
     11
     12using namespace std;
    1113
    1214/************************************* Functions for class element **********************************/
     
    3537 * \param *out outstream
    3638 */
    37 bool element::Output(ofstream * const out) const
     39bool element::Output(ostream * const out) const
    3840{
    3941  if (out != NULL) {
     
    5052 * \param NoOfAtoms total number of atom of this element type
    5153 */
    52 bool element::Checkout(ofstream * const out, const int Number, const int NoOfAtoms) const
     54bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const
    5355{
    5456  if (out != NULL) {
     
    5860    return false;
    5961};
     62
     63atomicNumber_t element::getNumber() const{
     64  return Z;
     65}
     66
     67string element::getSymbol() const{
     68  return string(symbol);
     69}
  • src/element.hpp

    rc3dbe0 read4e6  
    99#define ELEMENT_HPP_
    1010
    11 using namespace std;
    12 
    1311/*********************************************** includes ***********************************/
    1412
     
    1917
    2018#include <iostream>
     19#include <string>
    2120
    2221#include "defs.hpp"
     22#include "types.hpp"
    2323
    2424/********************************************** declarations *******************************/
     
    5050  ~element();
    5151
     52  // accessor functions
     53  atomicNumber_t getNumber() const;
     54  std::string getSymbol() const;
     55
    5256  //> print element entries to screen
    53   bool Output(ofstream * const out) const;
    54   bool Checkout(ofstream * const out, const int No, const int NoOfAtoms) const;
     57  bool Output(std::ostream * const out) const;
     58  bool Checkout(std::ostream * const out, const int No, const int NoOfAtoms) const;
    5559
    5660  private:
  • src/leastsquaremin.hpp

    rc3dbe0 read4e6  
    4242  gsl_vector *x;
    4343  const molecule *mol;
    44   element *type;
     44  const element *type;
    4545};
    4646
  • src/molecule.cpp

    rc3dbe0 read4e6  
    9999
    100100std::string molecule::calcFormula(){
    101   int Counts[MAX_ELEMENTS];
     101  std::map<atomicNumber_t,unsigned int> counts;
    102102  stringstream sstr;
    103   for (int j = 0; j<MAX_ELEMENTS;j++)
    104     Counts[j] = 0;
     103  periodentafel *periode = World::getInstance().getPeriode();
    105104  for(atom *Walker = start; Walker != end; Walker = Walker->next) {
    106     Counts[Walker->type->Z]++;
    107   }
    108   for(element* Elemental = elemente->end; Elemental != elemente->start; Elemental = Elemental->previous) {
    109     if (Counts[Elemental->Z] != 0)
    110       sstr << Elemental->symbol << Counts[Elemental->Z];
     105    counts[Walker->type->getNumber()]++;
     106  }
     107  std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
     108  for(iter = counts.rbegin(); iter != counts.rend(); ++iter) {
     109    atomicNumber_t Z = (*iter).first;
     110    sstr << periode->FindElement(Z)->symbol << (*iter).second;
    111111  }
    112112  return sstr.str();
  • src/moleculelist.cpp

    rc3dbe0 read4e6  
    141141void MoleculeListClass::Enumerate(ostream *out)
    142142{
    143   element* Elemental = NULL;
    144143  atom *Walker = NULL;
    145   int Counts[MAX_ELEMENTS];
     144  periodentafel *periode = World::getInstance().getPeriode();
     145  std::map<atomicNumber_t,unsigned int> counts;
    146146  double size=0;
    147147  Vector Origin;
     
    155155    Origin.Zero();
    156156    for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    157       // reset element counts
    158       for (int j = 0; j<MAX_ELEMENTS;j++)
    159         Counts[j] = 0;
    160157      // count atoms per element and determine size of bounding sphere
    161158      size=0.;
     
    163160      while (Walker->next != (*ListRunner)->end) {
    164161        Walker = Walker->next;
    165         Counts[Walker->type->Z]++;
     162        counts[Walker->type->getNumber()]++;
    166163        if (Walker->x.DistanceSquared(&Origin) > size)
    167164          size = Walker->x.DistanceSquared(&Origin);
     
    169166      // output Index, Name, number of atoms, chemical formula
    170167      (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
    171       Elemental = (*ListRunner)->elemente->end;
    172       while(Elemental->previous != (*ListRunner)->elemente->start) {
    173         Elemental = Elemental->previous;
    174         if (Counts[Elemental->Z] != 0)
    175           (*out) << Elemental->symbol << Counts[Elemental->Z];
     168
     169      std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
     170      for(iter=counts.rbegin(); iter!=counts.rend();++iter){
     171        atomicNumber_t Z =(*iter).first;
     172        (*out) << periode->FindElement(Z)->getSymbol() << (*iter).second;
    176173      }
    177174      // Center and size
     
    580577  stringstream line;
    581578  atom *Walker = NULL;
    582   element *runner = NULL;
     579  periodentafel *periode=World::getInstance().getPeriode();
    583580
    584581  // open file for the force factors
     
    590587    //output << prefix << "Forces" << endl;
    591588    for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    592       runner = (*ListRunner)->elemente->start;
    593       while (runner->next != (*ListRunner)->elemente->end) { // go through every element
    594         runner = runner->next;
    595         if ((*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms
     589      periodentafel::const_iterator elemIter;
     590      for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){
     591          if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms
    596592          Walker = (*ListRunner)->start;
    597593          while (Walker->next != (*ListRunner)->end) { // go through every atom of this element
    598594            Walker = Walker->next;
    599             if (Walker->type->Z == runner->Z) {
     595            if (Walker->type->getNumber() == (*elemIter).first) {
    600596              if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea
    601597                //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it
  • src/periodentafel.cpp

    rc3dbe0 read4e6  
    1010#include <fstream>
    1111#include <cstring>
     12#include <cassert>
    1213
    1314#include "element.hpp"
     
    1819#include "verbose.hpp"
    1920
     21using namespace std;
     22
    2023/************************************* Functions for class periodentafel ***************************/
    2124
     
    2326 * Initialises start and end of list and resets periodentafel::checkliste to false.
    2427 */
    25 periodentafel::periodentafel() : start(new element), end(new element)
    26 {
    27   start->previous = NULL;
    28   start->next = end;
    29   end->previous = start;
    30   end->next = NULL;
    31 };
     28periodentafel::periodentafel()
     29{};
    3230
    3331/** destructor for class periodentafel
     
    3735{
    3836  CleanupPeriodtable();
    39   delete(end);
    40   delete(start);
    4137};
    4238
     
    4541 * \return true - succeeded, false - does not occur
    4642 */
    47 bool periodentafel::AddElement(element * const pointer)
    48 {
     43periodentafel::iterator periodentafel::AddElement(element * const pointer)
     44{
     45  atomicNumber_t Z = pointer->getNumber();
     46  assert(!elements.count(Z));
    4947  pointer->sort = &pointer->Z;
    50   if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)
     48  if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS)
    5149    Log() << Verbose(0) << "Invalid Z number!\n";
    52   return add(pointer, end);
     50  pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer));
     51  return res.first;
    5352};
    5453
     
    5756 * \return true - succeeded, false - element not found
    5857 */
    59 bool periodentafel::RemoveElement(element * const pointer)
    60 {
    61   return remove(pointer, start, end);
     58void periodentafel::RemoveElement(element * const pointer)
     59{
     60  atomicNumber_t Z = pointer->getNumber();
     61  elements.erase(Z);
    6262};
    6363
     
    6565 * \return true - succeeded, false - does not occur
    6666 */
    67 bool periodentafel::CleanupPeriodtable()
    68 {
    69   return cleanup(start,end);
     67void periodentafel::CleanupPeriodtable()
     68{
     69  elements.clear();
    7070};
    7171
     
    7575 * \return pointer to element or NULL if not found
    7676 */
    77 element * const periodentafel::FindElement(const int Z) const
    78 {
    79   element *walker = find(&Z, start,end);
    80   return(walker);
     77const element * periodentafel::FindElement(atomicNumber_t Z) const
     78{
     79  const_iterator res = elements.find(Z);
     80  return res!=elements.end()?((*res).second):0;
    8181};
    8282
     
    8686 * \return pointer to element
    8787 */
    88 element * const periodentafel::FindElement(const char * const shorthand) const
    89 {
    90   element *walker =  periodentafel::start;
    91   while (walker->next != periodentafel::end) {
    92     walker = walker->next;
    93     if (strncmp(walker->symbol, shorthand, 3) == 0)
    94       return(walker);
     88const element * periodentafel::FindElement(const char * const shorthand) const
     89{
     90  element *res = 0;
     91  for(const_iterator iter=elements.begin();iter!=elements.end();++iter) {
     92    if((*iter).second->getSymbol() == shorthand){
     93      res = (*iter).second;
     94      break;
     95    }
    9596  }
    96   return (NULL);
     97  return res;
    9798};
    9899
    99100/** Asks for element number and returns pointer to element
    100101 */
    101 element * const periodentafel::AskElement() const
    102 {
    103   element *walker = NULL;
     102const element * periodentafel::AskElement() const
     103{
     104  const element *walker = NULL;
    104105  int Z;
    105106  do {
     
    114115 * \return pointer to either present or newly created element
    115116 */
    116 element * const periodentafel::EnterElement()
    117 {
    118   element *walker = NULL;
    119   int Z = -1;
     117const element * periodentafel::EnterElement()
     118{
     119  const element *res = NULL;
     120  atomicNumber_t Z = 0;
    120121  Log() << Verbose(0) << "Atomic number: " << Z << endl;
    121122  cin >> Z;
    122   walker = FindElement(Z);
    123   if (walker == NULL) {
     123  res = FindElement(Z);
     124  if (!res) {
     125    // TODO: make this using the constructor
     126    element *tmp;
    124127    Log() << Verbose(0) << "Element not found in database, please enter." << endl;
    125     walker = new element;
    126     walker->Z = Z;
     128    tmp = new element;
     129    tmp->Z = Z;
    127130    Log() << Verbose(0) << "Mass: " << endl;
    128     cin >> walker->mass;
     131    cin >> tmp->mass;
    129132    Log() << Verbose(0) << "Name [max 64 chars]: " << endl;
    130     cin >> walker->name;
     133    cin >> tmp->name;
    131134    Log() << Verbose(0) << "Short form [max 3 chars]: " << endl;
    132     cin >> walker->symbol;
    133     periodentafel::AddElement(walker);
     135    cin >> tmp->symbol;
     136    AddElement(tmp);
     137    res = tmp;
    134138  }
    135   return(walker);
    136 };
     139  return res;
     140};
     141
     142
     143/******************** Access to iterators ****************************/
     144periodentafel::const_iterator periodentafel::begin(){
     145  return elements.begin();
     146}
     147
     148periodentafel::const_iterator periodentafel::end(){
     149  return elements.end();
     150}
     151
     152periodentafel::reverse_iterator periodentafel::rbegin(){
     153  return reverse_iterator(elements.end());
     154}
     155
     156periodentafel::reverse_iterator periodentafel::rend(){
     157  return reverse_iterator(elements.begin());
     158}
    137159
    138160/** Prints period table to given stream.
    139161 * \param output stream
    140162 */
    141 bool periodentafel::Output(ofstream * const output) const
     163bool periodentafel::Output(ostream * const output) const
    142164{
    143165  bool result = true;
    144   element *walker = start;
    145166  if (output != NULL) {
    146     while (walker->next != end) {
    147       walker = walker->next;
    148       result = result && walker->Output(output);
     167    for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){
     168      result = result && (*iter).second->Output(output);
    149169    }
    150170    return result;
     
    157177 * \param *checkliste elements table for this molecule
    158178 */
    159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const
    160 {
    161   element *walker = start;
     179bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const
     180{
    162181  bool result = true;
    163182  int No = 1;
     
    166185    *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl;
    167186    *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl;
    168     while (walker->next != end) {
    169       walker = walker->next;
    170       if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) {
    171         walker->No = No;
    172         result = result && walker->Checkout(output, No++, checkliste[walker->Z]);
     187    for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){
     188      if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) {
     189        (*iter).second->No = No;
     190        result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]);
    173191      }
    174192    }
     
    184202{
    185203  ifstream infile;
    186   double tmp;
    187204  element *ptr;
     205  map<atomicNumber_t,element*> parsedElems;
    188206  bool status = true;
    189207  bool otherstatus = true;
     
    223241      //neues->Output((ofstream *)&cout);
    224242      if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
    225         periodentafel::AddElement(neues);
     243        parsedElems[neues->getNumber()] = neues;
    226244      else {
    227245        Log() << Verbose(0) << "Could not parse element: ";
     
    243261  if (infile != NULL) {
    244262    while (!infile.eof()) {
    245       infile >> tmp;
    246       infile >> ws;
    247       infile >> FindElement((int)tmp)->Valence;
     263      atomicNumber_t Z;
     264      infile >> Z;
     265      infile >> ws;
     266      infile >> parsedElems[Z]->Valence;
    248267      infile >> ws;
    249268      //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
     
    261280  if (infile != NULL) {
    262281    while (!infile.eof()) {
    263       infile >> tmp;
    264       infile >> ws;
    265       infile >> FindElement((int)tmp)->NoValenceOrbitals;
     282      atomicNumber_t Z;
     283      infile >> Z;
     284      infile >> ws;
     285      infile >> parsedElems[Z]->NoValenceOrbitals;
    266286      infile >> ws;
    267287      //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     
    279299  if (infile != NULL) {
    280300    while (!infile.eof()) {
    281       infile >> tmp;
    282       ptr = FindElement((int)tmp);
     301      atomicNumber_t Z;
     302      infile >> Z;
     303      ptr = parsedElems[Z];
    283304      infile >> ws;
    284305      infile >> ptr->HBondDistance[0];
     
    300321  if (infile != NULL) {
    301322    while (!infile.eof()) {
    302       infile >> tmp;
    303       ptr = FindElement((int)tmp);
     323      atomicNumber_t Z;
     324      infile >> Z;
     325      ptr = parsedElems[Z];
    304326      infile >> ws;
    305327      infile >> ptr->HBondAngle[0];
     
    313335    otherstatus = false;
    314336
    315   if (!otherstatus)
     337  if (otherstatus){
     338    map<atomicNumber_t,element*>::iterator iter;
     339    for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){
     340      AddElement((*iter).second);
     341    }
     342  }
     343  else{
    316344    eLog() << Verbose(2) << "Something went wrong while parsing the other databases!" << endl;
     345  }
    317346
    318347  return status;
     
    334363    f << header1 << endl;
    335364    f << header2 << endl;
    336     element *walker = periodentafel::start;
    337     while (walker->next != periodentafel::end) {
    338       walker = walker->next;
    339       result = result && walker->Output(&f);
     365    for(const_iterator iter=elements.begin();iter!=elements.end();++iter){
     366         result = result && (*iter).second->Output(&f);
    340367    }
    341368    f.close();
  • src/periodentafel.hpp

    rc3dbe0 read4e6  
    11#ifndef PERIODENTAFEL_HPP_
    22#define PERIODENTAFEL_HPP_
    3 
    4 using namespace std;
    53
    64/*********************************************** includes ***********************************/
     
    1210
    1311#include <iostream>
     12#include <map>
     13#include <iterator>
    1414
    1515#include "defs.hpp"
     16#include "types.hpp"
    1617
    1718/****************************************** forward declarations *****************************/
     
    2526 */
    2627class periodentafel {
     28  /******* Types *********/
     29  private:
     30    typedef std::map<atomicNumber_t,element*> elementSet;
    2731  public:
    28     element *start; //!< start of element list
    29     element *end;   //!< end of element list
     32    typedef elementSet::iterator iterator;
     33    typedef elementSet::const_iterator const_iterator;
     34    typedef std::reverse_iterator<const_iterator> reverse_iterator;
     35  public:
     36
    3037    char header1[MAXSTRINGSIZE]; //!< store first header line
    3138    char header2[MAXSTRINGSIZE]; //!< store second header line
     
    3441  ~periodentafel();
    3542
    36   bool AddElement(element * const pointer);
    37   bool RemoveElement(element * const pointer);
    38   bool CleanupPeriodtable();
    39   element * const FindElement(const int Z) const;
    40   element * const FindElement(const char * const shorthand) const;
    41   element * const AskElement() const;
    42   element * const EnterElement();
    43   bool Output(ofstream * const output) const;
    44   bool Checkout(ofstream * const output, const int * const checkliste) const;
     43  iterator AddElement(element * const pointer);
     44  void RemoveElement(element * const pointer);
     45  void CleanupPeriodtable();
     46  const element *FindElement(atomicNumber_t) const;
     47  const element *FindElement(const char * const shorthand) const;
     48  const element *AskElement() const;
     49  const element *EnterElement();
     50
     51  const_iterator begin();
     52  const_iterator end();
     53  reverse_iterator rbegin();
     54  reverse_iterator rend();
     55  bool Output(std::ostream * const output) const;
     56  bool Checkout(std::ostream * const output, const int * const checkliste) const;
    4557  bool LoadPeriodentafel(const char * const path);
    4658  bool StorePeriodentafel(const char * const path) const;
    4759
    4860  private:
     61    elementSet elements;
    4962};
    5063
  • src/unittests/AtomDescriptorTest.hpp

    rc3dbe0 read4e6  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "defs.hpp"
     13#include "types.hpp"
    1414
    1515#define ATOM_COUNT (10)
  • src/unittests/CacheableTest.cpp

    rc3dbe0 read4e6  
    2727class threeNumbers : public Observable {
    2828public:
    29   bool hasRecalced;
    3029  int x;
    3130  int y;
    3231  int z;
     32  Cacheable<int> sum;
     33  bool hasRecalced;
    3334
    3435  void setX(int _x){
     
    5455
    5556  threeNumbers(int _x,int _y, int _z) :
     57    x(_x),y(_y),z(_z),
    5658    sum(this,boost::bind(&threeNumbers::calcSum,this)),
    57     x(_x),y(_y),z(_z),
    5859    hasRecalced(false)
    5960  {}
    60 
    61   Cacheable<int> sum;
    6261};
    6362
  • src/unittests/MoleculeDescriptorTest.hpp

    rc3dbe0 read4e6  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "defs.hpp"
     13#include "types.hpp"
    1414
    1515#define MOLECULE_COUNT (10)
  • src/unittests/analysisbondsunittest.cpp

    rc3dbe0 read4e6  
    5353  strcpy(hydrogen->symbol, "H");
    5454  carbon = new element;
    55   carbon->Z = 1;
     55  carbon->Z = 2;
    5656  carbon->Valence = 4;
    5757  carbon->NoValenceOrbitals = 4;
  • src/unittests/atomsCalculationTest.cpp

    rc3dbe0 read4e6  
    3131CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest );
    3232
    33 // some stubs
    34 class AtomStub : public atom {
    35 public:
    36   AtomStub(atomId_t _id) :
    37   atom(),
    38   id(_id),
    39   manipulated(false)
    40   {}
    41 
    42   virtual atomId_t getId(){
    43     return id;
    44   }
    45 
    46   virtual void doSomething(){
    47     manipulated = true;
    48   }
    49 
    50   bool manipulated;
    51 private:
    52   atomId_t id;
    53 };
    54 
    5533// set up and tear down
    5634void atomsCalculationTest::setUp(){
    5735  World::getInstance();
    5836  for(int i=0;i<ATOM_COUNT;++i){
    59     atoms[i]= new AtomStub(i);
    60     World::getInstance().registerAtom(atoms[i]);
     37    atoms[i]= World::getInstance().createAtom();
     38    atomIds[i]= atoms[i]->getId();
    6139  }
    6240}
     
    6745
    6846// some helper functions
    69 static bool hasAll(std::vector<int> ids,int min, int max, std::set<int> excluded = std::set<int>()){
    70   for(int i=min;i<max;++i){
    71     if(!excluded.count(i)){
    72       std::vector<int>::iterator iter;
     47static bool hasAllIds(std::vector<atomId_t> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){
     48  for(int i=0;i<ATOM_COUNT;++i){
     49    atomId_t id = ids[i];
     50    if(!excluded.count(id)){
     51      std::vector<atomId_t>::iterator iter;
    7352      bool res=false;
    74       for(iter=ids.begin();iter!=ids.end();++iter){
    75         res |= (*iter) == i;
     53      for(iter=atoms.begin();iter!=atoms.end();++iter){
     54        res |= (*iter) == id;
    7655      }
    7756      if(!res) {
    78         cout << "Atom " << i << " missing in returned list" << endl;
     57        cout << "Atom " << id << " missing in returned list" << endl;
    7958        return false;
    8059      }
     
    8463}
    8564
    86 static bool hasNoDuplicates(std::vector<int> ids){
    87   std::set<int> found;
    88   std::vector<int>::iterator iter;
     65static bool hasNoDuplicates(std::vector<atomId_t> ids){
     66  std::set<atomId_t> found;
     67  std::vector<atomId_t>::iterator iter;
    8968  for(iter=ids.begin();iter!=ids.end();++iter){
    9069    int id = (*iter);
     
    9776
    9877void atomsCalculationTest::testCalculateSimple(){
    99   AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
    100   std::vector<int> allIds = (*calc)();
    101   CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT));
     78  AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
     79  std::vector<atomId_t> allIds = (*calc)();
     80  CPPUNIT_ASSERT(hasAllIds(allIds,atomIds));
    10281  CPPUNIT_ASSERT(hasNoDuplicates(allIds));
    10382}
    10483
    10584void atomsCalculationTest::testCalculateExcluded(){
    106   int excluded = ATOM_COUNT/2;
    107   AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
    108   std::vector<int> allIds = (*calc)();
    109   std::set<int> excluded_set;
     85  atomId_t excluded = atomIds[ATOM_COUNT/2];
     86  AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
     87  std::vector<atomId_t> allIds = (*calc)();
     88  std::set<atomId_t> excluded_set;
    11089  excluded_set.insert(excluded);
    111   CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT,excluded_set));
     90  CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set));
    11291  CPPUNIT_ASSERT(hasNoDuplicates(allIds));
    11392  CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size());
  • src/unittests/atomsCalculationTest.hpp

    rc3dbe0 read4e6  
    1212
    1313#define ATOM_COUNT (10)
     14
     15#include "types.hpp"
    1416
    1517class atom;
     
    3133private:
    3234  atom *atoms [ATOM_COUNT];
    33   int atomIds [ATOM_COUNT];
     35  atomId_t atomIds [ATOM_COUNT];
    3436};
    3537
  • src/unittests/bondgraphunittest.cpp

    rc3dbe0 read4e6  
    5151  strcpy(hydrogen->symbol, "H");
    5252  carbon = new element;
    53   carbon->Z = 1;
     53  carbon->Z = 2;
    5454  strcpy(carbon->name, "carbon");
    5555  strcpy(carbon->symbol, "C");
Note: See TracChangeset for help on using the changeset viewer.