Changeset e08f45 for molecuilder/src/periodentafel.cpp
- Timestamp:
- Feb 9, 2009, 5:24:10 PM (17 years ago)
- Children:
- 451d7a
- Parents:
- 4aef8a
- git-author:
- Frederik Heber <heber@…> (02/09/09 15:55:37)
- git-committer:
- Frederik Heber <heber@…> (02/09/09 17:24:10)
- File:
-
- 1 edited
-
molecuilder/src/periodentafel.cpp (modified) (11 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/periodentafel.cpp
-
Property mode
changed from
100644to100755
r4aef8a re08f45 1 1 /** \file periodentafel.cpp 2 * 2 * 3 3 * Function implementations for the class periodentafel. 4 * 4 * 5 5 */ 6 6 … … 14 14 * Initialises start and end of list and resets periodentafel::checkliste to false. 15 15 */ 16 periodentafel::periodentafel() 17 { 18 start = new element; 19 end = new element; 20 start->previous = NULL; 21 start->next = end; 22 end->previous = start; 23 end->next = NULL;16 periodentafel::periodentafel() 17 { 18 start = new element; 19 end = new element; 20 start->previous = NULL; 21 start->next = end; 22 end->previous = start; 23 end->next = NULL; 24 24 }; 25 25 … … 27 27 * Removes every element and afterwards deletes start and end of list. 28 28 */ 29 periodentafel::~periodentafel() 30 { 31 CleanupPeriodtable(); 32 delete(end); 33 delete(start); 34 }; 29 periodentafel::~periodentafel() 30 { 31 CleanupPeriodtable(); 32 delete(end); 33 delete(start); 34 }; 35 35 36 36 /** Adds element to period table list … … 38 38 * \return true - succeeded, false - does not occur 39 39 */ 40 bool periodentafel::AddElement(element *pointer) 41 { 42 pointer->sort = &pointer->Z;43 if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)44 cout << Verbose(0) << "Invalid Z number!\n";45 return add(pointer, end); 40 bool periodentafel::AddElement(element *pointer) 41 { 42 pointer->sort = &pointer->Z; 43 if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS) 44 cout << Verbose(0) << "Invalid Z number!\n"; 45 return add(pointer, end); 46 46 }; 47 47 … … 50 50 * \return true - succeeded, false - element not found 51 51 */ 52 bool periodentafel::RemoveElement(element *pointer) 53 { 54 return remove(pointer, start, end); 52 bool periodentafel::RemoveElement(element *pointer) 53 { 54 return remove(pointer, start, end); 55 55 }; 56 56 … … 58 58 * \return true - succeeded, false - does not occur 59 59 */ 60 bool periodentafel::CleanupPeriodtable() 61 { 62 return cleanup(start,end); 60 bool periodentafel::CleanupPeriodtable() 61 { 62 return cleanup(start,end); 63 63 }; 64 64 … … 70 70 element * periodentafel::FindElement(int Z) 71 71 { 72 element *walker = find(&Z, start,end);73 if (walker == NULL) { // not found: enter and put into db74 cout << Verbose(0) << "Element not found in database, please enter." << endl;75 walker = new element;76 cout << Verbose(0) << "Mass: " << endl;77 cin >> walker->mass;78 walker->Z = Z; 79 cout << Verbose(0) << "Atomic number: " << walker->Z << endl; 80 cout << Verbose(0) << "Name [max 64 chars]: " << endl;81 cin >> walker->name;82 cout << Verbose(0) << "Short form [max 3 chars]: " << endl;83 cin >> walker->symbol;84 periodentafel::AddElement(walker);85 }86 return(walker);72 element *walker = find(&Z, start,end); 73 if (walker == NULL) { // not found: enter and put into db 74 cout << Verbose(0) << "Element not found in database, please enter." << endl; 75 walker = new element; 76 cout << Verbose(0) << "Mass: " << endl; 77 cin >> walker->mass; 78 walker->Z = Z; 79 cout << Verbose(0) << "Atomic number: " << walker->Z << endl; 80 cout << Verbose(0) << "Name [max 64 chars]: " << endl; 81 cin >> walker->name; 82 cout << Verbose(0) << "Short form [max 3 chars]: " << endl; 83 cin >> walker->symbol; 84 periodentafel::AddElement(walker); 85 } 86 return(walker); 87 87 }; 88 88 … … 94 94 element * periodentafel::FindElement(char *shorthand) const 95 95 { 96 element *walker =periodentafel::start;97 while (walker->next != periodentafel::end) {98 walker = walker->next;99 if (strncmp(walker->symbol, shorthand, 3) == 0)100 return(walker);101 }102 return (NULL);96 element *walker = periodentafel::start; 97 while (walker->next != periodentafel::end) { 98 walker = walker->next; 99 if (strncmp(walker->symbol, shorthand, 3) == 0) 100 return(walker); 101 } 102 return (NULL); 103 103 }; 104 104 105 105 /** Asks for element number and returns pointer to element 106 106 */ 107 element * periodentafel::AskElement() 108 { 109 element *walker = NULL; 110 int Z; 111 do { 112 cout << Verbose(0) << "Atomic number Z: "; 113 cin >> Z; 114 walker = this->FindElement(Z); // give type 115 } while (walker == NULL); 116 return walker; 117 }; 118 107 element * periodentafel::AskElement() 108 { 109 element *walker = NULL; 110 int Z; 111 do { 112 cout << Verbose(0) << "Atomic number Z: "; 113 cin >> Z; 114 walker = this->FindElement(Z); // give type 115 } while (walker == NULL); 116 return walker; 117 }; 119 118 120 119 /** Prints period table to given stream. 121 120 * \param output stream 122 */ 121 */ 123 122 bool periodentafel::Output(ofstream *output) const 124 123 { 125 bool result = true;126 element *walker = start;127 if (output != NULL) {128 while (walker->next != end) {129 walker = walker->next;130 result = result && walker->Output(output);131 }132 return result;133 } else 134 return false;124 bool result = true; 125 element *walker = start; 126 if (output != NULL) { 127 while (walker->next != end) { 128 walker = walker->next; 129 result = result && walker->Output(output); 130 } 131 return result; 132 } else 133 return false; 135 134 }; 136 135 … … 138 137 * \param *output output stream 139 138 * \param *checkliste elements table for this molecule 140 */ 139 */ 141 140 bool periodentafel::Checkout(ofstream *output, const int *checkliste) const 142 141 { 143 element *walker = start; 144 bool result = true; 145 int No = 1; 146 147 if (output != NULL) { 148 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; 149 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl; 150 while (walker->next != end) { 151 walker = walker->next; 152 if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) { 153 walker->No = No; 154 result = result && walker->Checkout(output, No++, checkliste[walker->Z]); 155 } 156 } 157 return result; 158 } else 159 return false; 160 }; 161 142 element *walker = start; 143 bool result = true; 144 int No = 1; 145 146 if (output != NULL) { 147 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; 148 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl; 149 while (walker->next != end) { 150 walker = walker->next; 151 if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) { 152 walker->No = No; 153 result = result && walker->Checkout(output, No++, checkliste[walker->Z]); 154 } 155 } 156 return result; 157 } else 158 return false; 159 }; 162 160 163 161 /** Loads element list from file. … … 166 164 bool periodentafel::LoadPeriodentafel(char *path) 167 165 { 168 ifstream infile;169 double tmp;170 element *ptr;171 bool status = true;172 bool otherstatus = true;173 char *filename = new char[MAXSTRINGSIZE];174 175 // fill elements DB176 strncpy(filename, path, MAXSTRINGSIZE);177 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));178 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));179 infile.open(filename);180 if (infile != NULL) {181 infile.getline(header1, MAXSTRINGSIZE);182 infile.getline(header2, MAXSTRINGSIZE); // skip first two header lines183 cout <<"Parsed elements:";184 while (!infile.eof()) {185 element *neues = new element;186 infile >> neues->name;187 //infile >> ws;188 infile >> neues->symbol;189 //infile >> ws;190 infile >> neues->period;191 //infile >> ws;192 infile >> neues->group;193 //infile >> ws;194 infile >> neues->block;195 //infile >> ws;196 infile >> neues->Z;197 //infile >> ws;198 infile >> neues->mass;199 //infile >> ws;200 infile >> neues->CovalentRadius;201 //infile >> ws;202 infile >> neues->VanDerWaalsRadius;203 //infile >> ws;204 infile >> ws;205 cout << " " << neues->symbol;206 //neues->Output((ofstream *)&cout);207 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))208 periodentafel::AddElement(neues);209 else {210 cout << "Could not parse element: ";211 neues->Output((ofstream *)&cout);212 }213 }214 cout << endl;215 infile.close();216 infile.clear();217 } else218 status = false;219 220 // fill valence DB per element221 strncpy(filename, path, MAXSTRINGSIZE);222 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));223 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));224 infile.open(filename);225 if (infile != NULL) {226 while (!infile.eof()) {227 infile >> tmp;228 infile >> ws;229 infile >> FindElement((int)tmp)->Valence;230 infile >> ws;231 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;232 }233 infile.close();234 infile.clear();235 } else236 otherstatus = false;237 238 // fill valence DB per element239 strncpy(filename, path, MAXSTRINGSIZE);240 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));241 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));242 infile.open(filename);243 if (infile != NULL) {244 while (!infile.eof()) {245 infile >> tmp;246 infile >> ws;247 infile >> FindElement((int)tmp)->NoValenceOrbitals;248 infile >> ws;249 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;250 }251 infile.close();252 infile.clear();253 } else254 otherstatus = false;255 256 // fill H-BondDistance DB per element257 strncpy(filename, path, MAXSTRINGSIZE);258 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));259 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));260 infile.open(filename);261 if (infile != NULL) {262 while (!infile.eof()) {263 infile >> tmp;264 ptr = FindElement((int)tmp);265 infile >> ws;266 infile >> ptr->HBondDistance[0];267 infile >> ptr->HBondDistance[1];268 infile >> ptr->HBondDistance[2];269 infile >> ws;270 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;271 }272 infile.close();273 infile.clear();274 } else275 otherstatus = false;276 277 // fill H-BondAngle DB per element278 strncpy(filename, path, MAXSTRINGSIZE);279 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));280 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));281 infile.open(filename);282 if (infile != NULL) {283 while (!infile.eof()) {284 infile >> tmp;285 ptr = FindElement((int)tmp);286 infile >> ws;287 infile >> ptr->HBondAngle[0];288 infile >> ptr->HBondAngle[1];289 infile >> ptr->HBondAngle[2];290 infile >> ws;291 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondAngle[0] << ", " << FindElement((int)tmp)->HBondAngle[1] << ", " << FindElement((int)tmp)->HBondAngle[2] << " degrees bond angle for one, two, three connected hydrogens." << endl;292 }293 infile.close();294 } else295 otherstatus = false;296 297 if (!otherstatus)298 cerr << "WARNING: Something went wrong while parsing the other databases!" << endl;299 300 return status;166 ifstream infile; 167 double tmp; 168 element *ptr; 169 bool status = true; 170 bool otherstatus = true; 171 char filename[255]; 172 173 // fill elements DB 174 strncpy(filename, path, MAXSTRINGSIZE); 175 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 176 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); 177 infile.open(filename); 178 if (infile != NULL) { 179 infile.getline(header1, MAXSTRINGSIZE); 180 infile.getline(header2, MAXSTRINGSIZE); // skip first two header lines 181 cout << "Parsed elements:"; 182 while (!infile.eof()) { 183 element *neues = new element; 184 infile >> neues->name; 185 //infile >> ws; 186 infile >> neues->symbol; 187 //infile >> ws; 188 infile >> neues->period; 189 //infile >> ws; 190 infile >> neues->group; 191 //infile >> ws; 192 infile >> neues->block; 193 //infile >> ws; 194 infile >> neues->Z; 195 //infile >> ws; 196 infile >> neues->mass; 197 //infile >> ws; 198 infile >> neues->CovalentRadius; 199 //infile >> ws; 200 infile >> neues->VanDerWaalsRadius; 201 //infile >> ws; 202 infile >> ws; 203 cout << " " << neues->symbol; 204 //neues->Output((ofstream *)&cout); 205 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) 206 periodentafel::AddElement(neues); 207 else { 208 cout << "Could not parse element: "; 209 neues->Output((ofstream *)&cout); 210 } 211 } 212 cout << endl; 213 infile.close(); 214 infile.clear(); 215 } else 216 status = false; 217 218 // fill valence DB per element 219 strncpy(filename, path, MAXSTRINGSIZE); 220 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 221 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); 222 infile.open(filename); 223 if (infile != NULL) { 224 while (!infile.eof()) { 225 infile >> tmp; 226 infile >> ws; 227 infile >> FindElement((int)tmp)->Valence; 228 infile >> ws; 229 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl; 230 } 231 infile.close(); 232 infile.clear(); 233 } else 234 otherstatus = false; 235 236 // fill valence DB per element 237 strncpy(filename, path, MAXSTRINGSIZE); 238 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 239 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); 240 infile.open(filename); 241 if (infile != NULL) { 242 while (!infile.eof()) { 243 infile >> tmp; 244 infile >> ws; 245 infile >> FindElement((int)tmp)->NoValenceOrbitals; 246 infile >> ws; 247 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; 248 } 249 infile.close(); 250 infile.clear(); 251 } else 252 otherstatus = false; 253 254 // fill H-BondDistance DB per element 255 strncpy(filename, path, MAXSTRINGSIZE); 256 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 257 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); 258 infile.open(filename); 259 if (infile != NULL) { 260 while (!infile.eof()) { 261 infile >> tmp; 262 ptr = FindElement((int)tmp); 263 infile >> ws; 264 infile >> ptr->HBondDistance[0]; 265 infile >> ptr->HBondDistance[1]; 266 infile >> ptr->HBondDistance[2]; 267 infile >> ws; 268 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl; 269 } 270 infile.close(); 271 infile.clear(); 272 } else 273 otherstatus = false; 274 275 // fill H-BondAngle DB per element 276 strncpy(filename, path, MAXSTRINGSIZE); 277 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 278 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); 279 infile.open(filename); 280 if (infile != NULL) { 281 while (!infile.eof()) { 282 infile >> tmp; 283 ptr = FindElement((int)tmp); 284 infile >> ws; 285 infile >> ptr->HBondAngle[0]; 286 infile >> ptr->HBondAngle[1]; 287 infile >> ptr->HBondAngle[2]; 288 infile >> ws; 289 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondAngle[0] << ", " << FindElement((int)tmp)->HBondAngle[1] << ", " << FindElement((int)tmp)->HBondAngle[2] << " degrees bond angle for one, two, three connected hydrogens." << endl; 290 } 291 infile.close(); 292 } else 293 otherstatus = false; 294 295 if (!otherstatus) 296 cerr << "WARNING: Something went wrong while parsing the other databases!" << endl; 297 298 return status; 301 299 }; 302 300 … … 305 303 bool periodentafel::StorePeriodentafel(char *path) const 306 304 { 307 bool result = true;308 ofstream f;309 char filename[MAXSTRINGSIZE];310 311 strncpy(filename, path, MAXSTRINGSIZE);312 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));313 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));314 f.open(filename);315 if (f != NULL) {316 f << header1 << endl;317 f << header2 << endl;318 element *walker = periodentafel::start;319 while (walker->next != periodentafel::end) {320 walker = walker->next;321 result = result && walker->Output(&f);322 }323 f.close();324 } else325 result = false;326 return result;327 }; 305 bool result = true; 306 ofstream f; 307 char filename[MAXSTRINGSIZE]; 308 309 strncpy(filename, path, MAXSTRINGSIZE); 310 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 311 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); 312 f.open(filename); 313 if (f != NULL) { 314 f << header1 << endl; 315 f << header2 << endl; 316 element *walker = periodentafel::start; 317 while (walker->next != periodentafel::end) { 318 walker = walker->next; 319 result = result && walker->Output(&f); 320 } 321 f.close(); 322 } else 323 result = false; 324 return result; 325 }; -
Property mode
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
