- Timestamp:
- Mar 12, 2010, 1:16:01 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:
- 745a85
- Parents:
- c3dbe0
- Location:
- src
- Files:
-
- 1 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomsCalculation_impl.hpp
rc3dbe0 read4e6 19 19 AtomsCalculation<T>::AtomsCalculation(boost::function<T(atom*)> _op,std::string name,AtomDescriptor _descr) : 20 20 Calculation<std::vector<T> >(0,name,false), 21 op(_op),22 descr(_descr)21 descr(_descr), 22 op(_op) 23 23 {} 24 24 -
src/Actions/Calculation_impl.hpp
rc3dbe0 read4e6 16 16 Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister) : 17 17 Process(_maxSteps,_name,_doRegister), 18 done(false),19 result(0)18 result(0), 19 done(false) 20 20 {} 21 21 -
src/Descriptors/AtomTypeDescriptor.cpp
rc3dbe0 read4e6 13 13 #include "periodentafel.hpp" 14 14 15 AtomTypeDescriptor_impl::AtomTypeDescriptor_impl( element* _type) :15 AtomTypeDescriptor_impl::AtomTypeDescriptor_impl(const element* _type) : 16 16 type(_type) 17 17 {} … … 24 24 } 25 25 26 AtomDescriptor AtomByType( element *elem){26 AtomDescriptor AtomByType(const element *elem){ 27 27 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomTypeDescriptor_impl(elem))); 28 28 } 29 29 30 30 AtomDescriptor AtomByType(int Z){ 31 element * elem = World::getInstance().getPeriode()->FindElement(Z);31 const element * elem = World::getInstance().getPeriode()->FindElement(Z); 32 32 return AtomByType(elem); 33 33 } -
src/Descriptors/AtomTypeDescriptor.hpp
rc3dbe0 read4e6 13 13 class element; 14 14 15 AtomDescriptor AtomByType( element *);15 AtomDescriptor AtomByType(const element *); 16 16 AtomDescriptor AtomByType(int); 17 17 -
src/Descriptors/AtomTypeDescriptor_impl.hpp
rc3dbe0 read4e6 14 14 { 15 15 public: 16 AtomTypeDescriptor_impl( element* _type);16 AtomTypeDescriptor_impl(const element* _type); 17 17 virtual ~AtomTypeDescriptor_impl(); 18 18 19 19 bool predicate(std::pair<atomId_t,atom*> atom); 20 20 private: 21 element *type;21 const element * const type; 22 22 }; 23 23 -
src/Legacy/oldmenu.cpp
rc3dbe0 read4e6 748 748 int axis,faktor,count,j; 749 749 atom *first = NULL; 750 element **Elements;750 const element **Elements; 751 751 Vector x,y; 752 752 Vector **vectors; … … 764 764 if (mol->AtomCount != 0) { // if there is more than none 765 765 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]; 767 767 vectors = new Vector *[count]; 768 768 j = 0; -
src/World.hpp
rc3dbe0 read4e6 16 16 #include <boost/shared_ptr.hpp> 17 17 18 #include " defs.hpp"18 #include "types.hpp" 19 19 #include "Patterns/Observer.hpp" 20 20 #include "Patterns/Cacheable.hpp" -
src/atom.hpp
rc3dbe0 read4e6 28 28 #include "atom_trajectoryparticle.hpp" 29 29 #include "tesselation.hpp" 30 #include "types.hpp" 30 31 31 32 /****************************************** forward declarations *****************************/ -
src/atom_atominfo.cpp
rc3dbe0 read4e6 20 20 }; 21 21 22 element *AtomInfo::getType(){22 const element *AtomInfo::getType(){ 23 23 return type; 24 24 } 25 25 26 void AtomInfo::setType( element* _type) {26 void AtomInfo::setType(const element* _type) { 27 27 type = _type; 28 28 } 29 29 30 30 void AtomInfo::setType(int Z) { 31 element *elem = World::getInstance().getPeriode()->FindElement(Z);31 const element *elem = World::getInstance().getPeriode()->FindElement(Z); 32 32 setType(elem); 33 33 } -
src/atom_atominfo.hpp
rc3dbe0 read4e6 32 32 Vector v; //!< velocity vector of atom, giving last velocity within cell 33 33 Vector F; //!< Force vector of atom, giving last force within cell 34 element *type; //!< pointing to element34 const element *type; //!< pointing to element 35 35 36 36 AtomInfo(); 37 37 ~AtomInfo(); 38 38 39 element *getType();40 void setType( element *);39 const element *getType(); 40 void setType(const element *); 41 41 void setType(int); 42 42 -
src/builder.cpp
rc3dbe0 read4e6 1593 1593 } 1594 1594 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])); 1596 1596 FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL); 1597 1597 int ranges[NDIM] = {1,1,1}; … … 2070 2070 int faktor = atoi(argv[argptr++]); 2071 2071 int count; 2072 element ** Elements;2072 const element ** Elements; 2073 2073 Vector ** vectors; 2074 2074 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; 2076 2076 faktor = 1; 2077 2077 } … … 2079 2079 if (mol->AtomCount != 0) { // if there is more than none 2080 2080 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]; 2082 2082 vectors = new Vector *[count]; 2083 2083 j = 0; -
src/config.cpp
rc3dbe0 read4e6 675 675 { 676 676 int MaxTypes = 0; 677 element *elementhash[MAX_ELEMENTS];677 const element *elementhash[MAX_ELEMENTS]; 678 678 char name[MAX_ELEMENTS]; 679 679 char keyword[MAX_ELEMENTS]; … … 1107 1107 string zeile; 1108 1108 string dummy; 1109 element *elementhash[128];1109 const element *elementhash[128]; 1110 1110 int Z = -1; 1111 1111 int No = -1; -
src/defs.hpp
rc3dbe0 read4e6 33 33 enum Shading { white, lightgray, darkgray, black }; //!< color in Breadth-First-Search analysis 34 34 35 // some types that can stay abstract 36 typedef unsigned int moleculeId_t; 37 typedef unsigned int atomId_t; 35 38 36 39 37 //enum CutCyclicBond { KeepBond, SaturateBond }; //!< Saturation scheme either atom- or bondwise … … 85 83 #define STD_SEPERATOR_SPACER '-' 86 84 87 // some types used to set template parameters88 struct true_type{89 enum{value=1};90 };91 struct false_type{92 enum{value = 0};93 };94 95 85 #endif /*DEFS_HPP_*/ -
src/element.cpp
rc3dbe0 read4e6 9 9 10 10 #include "element.hpp" 11 12 using namespace std; 11 13 12 14 /************************************* Functions for class element **********************************/ … … 35 37 * \param *out outstream 36 38 */ 37 bool element::Output(o fstream * const out) const39 bool element::Output(ostream * const out) const 38 40 { 39 41 if (out != NULL) { … … 50 52 * \param NoOfAtoms total number of atom of this element type 51 53 */ 52 bool element::Checkout(o fstream * const out, const int Number, const int NoOfAtoms) const54 bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const 53 55 { 54 56 if (out != NULL) { … … 58 60 return false; 59 61 }; 62 63 atomicNumber_t element::getNumber() const{ 64 return Z; 65 } 66 67 string element::getSymbol() const{ 68 return string(symbol); 69 } -
src/element.hpp
rc3dbe0 read4e6 9 9 #define ELEMENT_HPP_ 10 10 11 using namespace std;12 13 11 /*********************************************** includes ***********************************/ 14 12 … … 19 17 20 18 #include <iostream> 19 #include <string> 21 20 22 21 #include "defs.hpp" 22 #include "types.hpp" 23 23 24 24 /********************************************** declarations *******************************/ … … 50 50 ~element(); 51 51 52 // accessor functions 53 atomicNumber_t getNumber() const; 54 std::string getSymbol() const; 55 52 56 //> 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; 55 59 56 60 private: -
src/leastsquaremin.hpp
rc3dbe0 read4e6 42 42 gsl_vector *x; 43 43 const molecule *mol; 44 element *type;44 const element *type; 45 45 }; 46 46 -
src/molecule.cpp
rc3dbe0 read4e6 99 99 100 100 std::string molecule::calcFormula(){ 101 int Counts[MAX_ELEMENTS];101 std::map<atomicNumber_t,unsigned int> counts; 102 102 stringstream sstr; 103 for (int j = 0; j<MAX_ELEMENTS;j++) 104 Counts[j] = 0; 103 periodentafel *periode = World::getInstance().getPeriode(); 105 104 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; 111 111 } 112 112 return sstr.str(); -
src/moleculelist.cpp
rc3dbe0 read4e6 141 141 void MoleculeListClass::Enumerate(ostream *out) 142 142 { 143 element* Elemental = NULL;144 143 atom *Walker = NULL; 145 int Counts[MAX_ELEMENTS]; 144 periodentafel *periode = World::getInstance().getPeriode(); 145 std::map<atomicNumber_t,unsigned int> counts; 146 146 double size=0; 147 147 Vector Origin; … … 155 155 Origin.Zero(); 156 156 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 157 // reset element counts158 for (int j = 0; j<MAX_ELEMENTS;j++)159 Counts[j] = 0;160 157 // count atoms per element and determine size of bounding sphere 161 158 size=0.; … … 163 160 while (Walker->next != (*ListRunner)->end) { 164 161 Walker = Walker->next; 165 Counts[Walker->type->Z]++;162 counts[Walker->type->getNumber()]++; 166 163 if (Walker->x.DistanceSquared(&Origin) > size) 167 164 size = Walker->x.DistanceSquared(&Origin); … … 169 166 // output Index, Name, number of atoms, chemical formula 170 167 (*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; 176 173 } 177 174 // Center and size … … 580 577 stringstream line; 581 578 atom *Walker = NULL; 582 element *runner = NULL;579 periodentafel *periode=World::getInstance().getPeriode(); 583 580 584 581 // open file for the force factors … … 590 587 //output << prefix << "Forces" << endl; 591 588 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 596 592 Walker = (*ListRunner)->start; 597 593 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element 598 594 Walker = Walker->next; 599 if (Walker->type-> Z == runner->Z) {595 if (Walker->type->getNumber() == (*elemIter).first) { 600 596 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea 601 597 //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it -
src/periodentafel.cpp
rc3dbe0 read4e6 10 10 #include <fstream> 11 11 #include <cstring> 12 #include <cassert> 12 13 13 14 #include "element.hpp" … … 18 19 #include "verbose.hpp" 19 20 21 using namespace std; 22 20 23 /************************************* Functions for class periodentafel ***************************/ 21 24 … … 23 26 * Initialises start and end of list and resets periodentafel::checkliste to false. 24 27 */ 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 }; 28 periodentafel::periodentafel() 29 {}; 32 30 33 31 /** destructor for class periodentafel … … 37 35 { 38 36 CleanupPeriodtable(); 39 delete(end);40 delete(start);41 37 }; 42 38 … … 45 41 * \return true - succeeded, false - does not occur 46 42 */ 47 bool periodentafel::AddElement(element * const pointer) 48 { 43 periodentafel::iterator periodentafel::AddElement(element * const pointer) 44 { 45 atomicNumber_t Z = pointer->getNumber(); 46 assert(!elements.count(Z)); 49 47 pointer->sort = &pointer->Z; 50 if (pointer-> Z < 1 && pointer->Z>= MAX_ELEMENTS)48 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS) 51 49 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; 53 52 }; 54 53 … … 57 56 * \return true - succeeded, false - element not found 58 57 */ 59 bool periodentafel::RemoveElement(element * const pointer) 60 { 61 return remove(pointer, start, end); 58 void periodentafel::RemoveElement(element * const pointer) 59 { 60 atomicNumber_t Z = pointer->getNumber(); 61 elements.erase(Z); 62 62 }; 63 63 … … 65 65 * \return true - succeeded, false - does not occur 66 66 */ 67 boolperiodentafel::CleanupPeriodtable()68 { 69 return cleanup(start,end);67 void periodentafel::CleanupPeriodtable() 68 { 69 elements.clear(); 70 70 }; 71 71 … … 75 75 * \return pointer to element or NULL if not found 76 76 */ 77 element * const periodentafel::FindElement(const int Z) const78 { 79 element *walker = find(&Z, start,end);80 return (walker);77 const element * periodentafel::FindElement(atomicNumber_t Z) const 78 { 79 const_iterator res = elements.find(Z); 80 return res!=elements.end()?((*res).second):0; 81 81 }; 82 82 … … 86 86 * \return pointer to element 87 87 */ 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); 88 const 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 } 95 96 } 96 return (NULL);97 return res; 97 98 }; 98 99 99 100 /** Asks for element number and returns pointer to element 100 101 */ 101 element * constperiodentafel::AskElement() const102 { 103 element *walker = NULL;102 const element * periodentafel::AskElement() const 103 { 104 const element *walker = NULL; 104 105 int Z; 105 106 do { … … 114 115 * \return pointer to either present or newly created element 115 116 */ 116 element * constperiodentafel::EnterElement()117 { 118 element *walker= NULL;119 int Z = -1;117 const element * periodentafel::EnterElement() 118 { 119 const element *res = NULL; 120 atomicNumber_t Z = 0; 120 121 Log() << Verbose(0) << "Atomic number: " << Z << endl; 121 122 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; 124 127 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; 127 130 Log() << Verbose(0) << "Mass: " << endl; 128 cin >> walker->mass;131 cin >> tmp->mass; 129 132 Log() << Verbose(0) << "Name [max 64 chars]: " << endl; 130 cin >> walker->name;133 cin >> tmp->name; 131 134 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; 134 138 } 135 return(walker); 136 }; 139 return res; 140 }; 141 142 143 /******************** Access to iterators ****************************/ 144 periodentafel::const_iterator periodentafel::begin(){ 145 return elements.begin(); 146 } 147 148 periodentafel::const_iterator periodentafel::end(){ 149 return elements.end(); 150 } 151 152 periodentafel::reverse_iterator periodentafel::rbegin(){ 153 return reverse_iterator(elements.end()); 154 } 155 156 periodentafel::reverse_iterator periodentafel::rend(){ 157 return reverse_iterator(elements.begin()); 158 } 137 159 138 160 /** Prints period table to given stream. 139 161 * \param output stream 140 162 */ 141 bool periodentafel::Output(o fstream * const output) const163 bool periodentafel::Output(ostream * const output) const 142 164 { 143 165 bool result = true; 144 element *walker = start;145 166 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); 149 169 } 150 170 return result; … … 157 177 * \param *checkliste elements table for this molecule 158 178 */ 159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const 160 { 161 element *walker = start; 179 bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const 180 { 162 181 bool result = true; 163 182 int No = 1; … … 166 185 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; 167 186 *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]); 173 191 } 174 192 } … … 184 202 { 185 203 ifstream infile; 186 double tmp;187 204 element *ptr; 205 map<atomicNumber_t,element*> parsedElems; 188 206 bool status = true; 189 207 bool otherstatus = true; … … 223 241 //neues->Output((ofstream *)&cout); 224 242 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) 225 p eriodentafel::AddElement(neues);243 parsedElems[neues->getNumber()] = neues; 226 244 else { 227 245 Log() << Verbose(0) << "Could not parse element: "; … … 243 261 if (infile != NULL) { 244 262 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; 248 267 infile >> ws; 249 268 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl; … … 261 280 if (infile != NULL) { 262 281 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; 266 286 infile >> ws; 267 287 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; … … 279 299 if (infile != NULL) { 280 300 while (!infile.eof()) { 281 infile >> tmp; 282 ptr = FindElement((int)tmp); 301 atomicNumber_t Z; 302 infile >> Z; 303 ptr = parsedElems[Z]; 283 304 infile >> ws; 284 305 infile >> ptr->HBondDistance[0]; … … 300 321 if (infile != NULL) { 301 322 while (!infile.eof()) { 302 infile >> tmp; 303 ptr = FindElement((int)tmp); 323 atomicNumber_t Z; 324 infile >> Z; 325 ptr = parsedElems[Z]; 304 326 infile >> ws; 305 327 infile >> ptr->HBondAngle[0]; … … 313 335 otherstatus = false; 314 336 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{ 316 344 eLog() << Verbose(2) << "Something went wrong while parsing the other databases!" << endl; 345 } 317 346 318 347 return status; … … 334 363 f << header1 << endl; 335 364 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); 340 367 } 341 368 f.close(); -
src/periodentafel.hpp
rc3dbe0 read4e6 1 1 #ifndef PERIODENTAFEL_HPP_ 2 2 #define PERIODENTAFEL_HPP_ 3 4 using namespace std;5 3 6 4 /*********************************************** includes ***********************************/ … … 12 10 13 11 #include <iostream> 12 #include <map> 13 #include <iterator> 14 14 15 15 #include "defs.hpp" 16 #include "types.hpp" 16 17 17 18 /****************************************** forward declarations *****************************/ … … 25 26 */ 26 27 class periodentafel { 28 /******* Types *********/ 29 private: 30 typedef std::map<atomicNumber_t,element*> elementSet; 27 31 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 30 37 char header1[MAXSTRINGSIZE]; //!< store first header line 31 38 char header2[MAXSTRINGSIZE]; //!< store second header line … … 34 41 ~periodentafel(); 35 42 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; 45 57 bool LoadPeriodentafel(const char * const path); 46 58 bool StorePeriodentafel(const char * const path) const; 47 59 48 60 private: 61 elementSet elements; 49 62 }; 50 63 -
src/unittests/AtomDescriptorTest.hpp
rc3dbe0 read4e6 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include " defs.hpp"13 #include "types.hpp" 14 14 15 15 #define ATOM_COUNT (10) -
src/unittests/CacheableTest.cpp
rc3dbe0 read4e6 27 27 class threeNumbers : public Observable { 28 28 public: 29 bool hasRecalced;30 29 int x; 31 30 int y; 32 31 int z; 32 Cacheable<int> sum; 33 bool hasRecalced; 33 34 34 35 void setX(int _x){ … … 54 55 55 56 threeNumbers(int _x,int _y, int _z) : 57 x(_x),y(_y),z(_z), 56 58 sum(this,boost::bind(&threeNumbers::calcSum,this)), 57 x(_x),y(_y),z(_z),58 59 hasRecalced(false) 59 60 {} 60 61 Cacheable<int> sum;62 61 }; 63 62 -
src/unittests/MoleculeDescriptorTest.hpp
rc3dbe0 read4e6 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include " defs.hpp"13 #include "types.hpp" 14 14 15 15 #define MOLECULE_COUNT (10) -
src/unittests/analysisbondsunittest.cpp
rc3dbe0 read4e6 53 53 strcpy(hydrogen->symbol, "H"); 54 54 carbon = new element; 55 carbon->Z = 1;55 carbon->Z = 2; 56 56 carbon->Valence = 4; 57 57 carbon->NoValenceOrbitals = 4; -
src/unittests/atomsCalculationTest.cpp
rc3dbe0 read4e6 31 31 CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest ); 32 32 33 // some stubs34 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 55 33 // set up and tear down 56 34 void atomsCalculationTest::setUp(){ 57 35 World::getInstance(); 58 36 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(); 61 39 } 62 40 } … … 67 45 68 46 // 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; 47 static 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; 73 52 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; 76 55 } 77 56 if(!res) { 78 cout << "Atom " << i << " missing in returned list" << endl;57 cout << "Atom " << id << " missing in returned list" << endl; 79 58 return false; 80 59 } … … 84 63 } 85 64 86 static bool hasNoDuplicates(std::vector< int> ids){87 std::set< int> found;88 std::vector< int>::iterator iter;65 static bool hasNoDuplicates(std::vector<atomId_t> ids){ 66 std::set<atomId_t> found; 67 std::vector<atomId_t>::iterator iter; 89 68 for(iter=ids.begin();iter!=ids.end();++iter){ 90 69 int id = (*iter); … … 97 76 98 77 void 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)); 102 81 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 103 82 } 104 83 105 84 void 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; 110 89 excluded_set.insert(excluded); 111 CPPUNIT_ASSERT(hasAll (allIds,0,ATOM_COUNT,excluded_set));90 CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set)); 112 91 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 113 92 CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size()); -
src/unittests/atomsCalculationTest.hpp
rc3dbe0 read4e6 12 12 13 13 #define ATOM_COUNT (10) 14 15 #include "types.hpp" 14 16 15 17 class atom; … … 31 33 private: 32 34 atom *atoms [ATOM_COUNT]; 33 int atomIds [ATOM_COUNT];35 atomId_t atomIds [ATOM_COUNT]; 34 36 }; 35 37 -
src/unittests/bondgraphunittest.cpp
rc3dbe0 read4e6 51 51 strcpy(hydrogen->symbol, "H"); 52 52 carbon = new element; 53 carbon->Z = 1;53 carbon->Z = 2; 54 54 strcpy(carbon->name, "carbon"); 55 55 strcpy(carbon->symbol, "C");
Note:
See TracChangeset
for help on using the changeset viewer.