Changeset b8d4a3
- Timestamp:
- May 2, 2010, 4:47:18 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:
- b9b604
- Parents:
- 4415da
- Location:
- src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TremoloParser.cpp
r4415da rb8d4a3 6 6 */ 7 7 8 #include "Helpers/Assert.hpp" 8 9 #include "TremoloParser.hpp" 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "element.hpp" 13 #include "bond.hpp" 12 14 #include "periodentafel.hpp" 15 #include "Descriptors/AtomIdDescriptor.hpp" 13 16 #include <map> 14 17 #include <vector> 15 18 19 16 20 using namespace std; 21 using namespace boost; 17 22 18 23 /** … … 20 25 */ 21 26 TremoloParser::TremoloParser() { 22 knownKeys[" "] = noKey; // so we can detect invalid keys 23 knownKeys["x"] = x; 24 knownKeys["u"] = u; 25 knownKeys["F"] = F; 26 knownKeys["stress"] = stress; 27 knownKeys["Id"] = Id; 28 knownKeys["neighbors"] = neighbors; 29 knownKeys["imprData"] = imprData; 30 knownKeys["GroupMeasureTypeNo"] = GroupMeasureTypeNo; 31 knownKeys["Type"] = Type; 32 knownKeys["extType"] = extType; 33 knownKeys["name"] = name; 34 knownKeys["resName"] = resName; 35 knownKeys["chainID"] = chainID; 36 knownKeys["resSeq"] = resSeq; 37 knownKeys["occupancy"] = occupancy; 38 knownKeys["tempFactor"] = tempFactor; 39 knownKeys["segID"] = segID; 40 knownKeys["Charge"] = Charge; 41 knownKeys["charge"] = charge; 42 knownKeys["GrpTypeNo"] = GrpTypeNo; 27 knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys 28 knownKeys["x"] = TremoloKey::x; 29 knownKeys["u"] = TremoloKey::u; 30 knownKeys["F"] = TremoloKey::F; 31 knownKeys["stress"] = TremoloKey::stress; 32 knownKeys["Id"] = TremoloKey::Id; 33 knownKeys["neighbors"] = TremoloKey::neighbors; 34 knownKeys["imprData"] = TremoloKey::imprData; 35 knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo; 36 knownKeys["Type"] = TremoloKey::Type; 37 knownKeys["extType"] = TremoloKey::extType; 38 knownKeys["name"] = TremoloKey::name; 39 knownKeys["resName"] = TremoloKey::resName; 40 knownKeys["chainID"] = TremoloKey::chainID; 41 knownKeys["resSeq"] = TremoloKey::resSeq; 42 knownKeys["occupancy"] = TremoloKey::occupancy; 43 knownKeys["tempFactor"] = TremoloKey::tempFactor; 44 knownKeys["segID"] = TremoloKey::segID; 45 knownKeys["Charge"] = TremoloKey::Charge; 46 knownKeys["charge"] = TremoloKey::charge; 47 knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo; 48 knownKeys["torsion"] = TremoloKey::torsion; 43 49 } 44 50 … … 47 53 */ 48 54 TremoloParser::~TremoloParser() { 49 } 50 51 /** 52 * Stores keys from the ATOMDATA line. 53 * 54 * \param line to parse the keys from 55 * \param with which offset the keys begin within the line 56 */ 57 void TremoloParser::parseAtomDataKeysLine(string line, int offset) { 58 string keyword; 59 stringstream lineStream; 60 61 lineStream << line.substr(offset); 62 while (lineStream.good()) { 63 lineStream >> keyword; 64 if (knownKeys[keyword.substr(0, keyword.find("="))] == noKey) { 65 // throw exception about unknown key 66 cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl; 67 break; 68 } 69 usedFields.push_back(keyword); 70 } 71 } 72 73 /** 74 * Reads one data line of a tremolo file and interprets it according to the keys 75 * obtained from the ATOMDATA line. 76 * 77 * \param line to parse as an atom 78 */ 79 void TremoloParser::readAtomDataLine(string line) { 80 vector<string>::iterator it; 81 stringstream lineStream; 82 atom* newAtom = World::getInstance().createAtom(); 83 TremoloAtomInfoContainer atomInfo = *(new TremoloAtomInfoContainer()); 84 atomDataKey currentField; 85 string word; 86 87 lineStream << line; 88 for (it=usedFields.begin(); it < usedFields.end(); it++) { 89 cout << *it << " -- " << it->substr(0, it->find("=")) << " -- " << knownKeys[it->substr(0, it->find("="))] << endl; 90 currentField = knownKeys[it->substr(0, it->find("="))]; 91 switch (currentField) { 92 case x : 93 // for the moment, assume there are always three dimensions 94 lineStream >> newAtom->x.x[0]; 95 lineStream >> newAtom->x.x[1]; 96 lineStream >> newAtom->x.x[2]; 97 break; 98 case u : 99 // for the moment, assume there are always three dimensions 100 lineStream >> newAtom->v.x[0]; 101 lineStream >> newAtom->v.x[1]; 102 lineStream >> newAtom->v.x[2]; 103 break; 104 case F : 105 lineStream >> word; 106 atomInfo.F = word; 107 break; 108 case stress : 109 lineStream >> word; 110 atomInfo.F = word; 111 break; 112 case Id : 113 // this ID is not used 114 break; 115 case neighbors : 116 // TODO neighbor information 117 lineStream >> word; 118 break; 119 case imprData : 120 lineStream >> word; 121 atomInfo.imprData = word; 122 break; 123 case GroupMeasureTypeNo : 124 lineStream >> word; 125 atomInfo.GroupMeasureTypeNo = word; 126 break; 127 case Type : 128 char type[3]; 129 lineStream >> type; 130 newAtom->setType(World::getInstance().getPeriode()->FindElement(type)); 131 break; 132 case extType : 133 lineStream >> word; 134 atomInfo.extType = word; 135 break; 136 case name : 137 lineStream >> word; 138 atomInfo.name = word; 139 break; 140 case resName : 141 lineStream >> word; 142 atomInfo.resName = word; 143 break; 144 case chainID : 145 lineStream >> word; 146 atomInfo.chainID = word; 147 break; 148 case resSeq : 149 lineStream >> word; 150 atomInfo.resSeq = word; 151 break; 152 case occupancy : 153 lineStream >> word; 154 atomInfo.occupancy = word; 155 break; 156 case tempFactor : 157 lineStream >> word; 158 atomInfo.segID = word; 159 break; 160 case segID : 161 lineStream >> word; 162 atomInfo.F = word; 163 break; 164 case Charge : 165 lineStream >> word; 166 atomInfo.Charge = word; 167 break; 168 case charge : 169 lineStream >> word; 170 atomInfo.charge = word; 171 break; 172 case GrpTypeNo : 173 lineStream >> word; 174 atomInfo.GrpTypeNo = word; 175 break; 176 default : 177 lineStream >> word; 178 cout << "Unknown key: " << *it << ", word: " << word << endl; 179 break; 180 } 181 } 182 moreData[newAtom->getId()] = atomInfo; 183 } 184 55 usedFields.clear(); 56 additionalAtomData.clear(); 57 atomIdMap.clear(); 58 knownKeys.clear(); 59 } 185 60 186 61 /** … … 206 81 } 207 82 } 83 84 processNeighborInformation(); 85 adaptImprData(); 86 adaptTorsion(); 208 87 } 209 88 … … 214 93 */ 215 94 void TremoloParser::save(ostream* file) { 216 /* 217 write header 218 for (each atom in world) { 219 write coordinates and additional data 220 } 221 */ 222 } 95 vector<atom*>::iterator atomIt; 96 vector<string>::iterator it; 97 98 *file << "# ATOMDATA"; 99 for (it=usedFields.begin(); it < usedFields.end(); it++) { 100 *file << "\t" << *it; 101 } 102 *file << endl; 103 vector<atom *> AtomList = World::getInstance().getAllAtoms(); 104 for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) { 105 saveLine(file, *atomIt); 106 } 107 } 108 109 /** 110 * Sets the keys for which data should be written to the stream when save is 111 * called. 112 * 113 * \param string of field names with the same syntax as for an ATOMDATA line 114 * but without the prexix "ATOMDATA" 115 */ 116 void TremoloParser::setFieldsForSave(std::string atomDataLine) { 117 parseAtomDataKeysLine(atomDataLine, 0); 118 } 119 120 121 /** 122 * Writes one line of tremolo-formatted data to the provided stream. 123 * 124 * \param stream where to write the line to 125 * \param reference to the atom of which information should be written 126 */ 127 void TremoloParser::saveLine(ostream* file, atom* currentAtom) { 128 vector<string>::iterator it; 129 TremoloKey::atomDataKey currentField; 130 131 for (it = usedFields.begin(); it != usedFields.end(); it++) { 132 currentField = knownKeys[it->substr(0, it->find("="))]; 133 switch (currentField) { 134 case TremoloKey::x : 135 // for the moment, assume there are always three dimensions 136 *file << currentAtom->x.x[0] << "\t"; 137 *file << currentAtom->x.x[1] << "\t"; 138 *file << currentAtom->x.x[2] << "\t"; 139 break; 140 case TremoloKey::u : 141 // for the moment, assume there are always three dimensions 142 *file << currentAtom->v.x[0] << "\t"; 143 *file << currentAtom->v.x[1] << "\t"; 144 *file << currentAtom->v.x[2] << "\t"; 145 break; 146 case TremoloKey::Type : 147 *file << currentAtom->getType()->getSymbol() << "\t"; 148 break; 149 case TremoloKey::Id : 150 *file << currentAtom->getId() << "\t"; 151 break; 152 case TremoloKey::neighbors : 153 writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom); 154 break; 155 default : 156 *file << (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end() 157 ? additionalAtomData[currentAtom->getId()].get(currentField) 158 : defaultAdditionalData.get(currentField)); 159 *file << "\t"; 160 break; 161 } 162 } 163 164 *file << endl; 165 } 166 167 /** 168 * Writes the neighbor information of one atom to the provided stream. 169 * 170 * \param stream where to write neighbor information to 171 * \param number of neighbors 172 * \param reference to the atom of which to take the neighbor information 173 */ 174 void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) { 175 BondList::iterator currentBond = currentAtom->ListOfBonds.begin(); 176 for (int i = 0; i < numberOfNeighbors; i++) { 177 *file << (currentBond != currentAtom->ListOfBonds.end() 178 ? (*currentBond)->GetOtherAtom(currentAtom)->getId() : 0) << "\t"; 179 } 180 } 181 182 /** 183 * Stores keys from the ATOMDATA line. 184 * 185 * \param line to parse the keys from 186 * \param with which offset the keys begin within the line 187 */ 188 void TremoloParser::parseAtomDataKeysLine(string line, int offset) { 189 string keyword; 190 stringstream lineStream; 191 192 lineStream << line.substr(offset); 193 while (lineStream.good()) { 194 lineStream >> keyword; 195 if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) { 196 // throw exception about unknown key 197 cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl; 198 break; 199 } 200 usedFields.push_back(keyword); 201 } 202 } 203 204 /** 205 * Reads one data line of a tremolo file and interprets it according to the keys 206 * obtained from the ATOMDATA line. 207 * 208 * \param line to parse as an atom 209 */ 210 void TremoloParser::readAtomDataLine(string line) { 211 vector<string>::iterator it; 212 stringstream lineStream; 213 atom* newAtom = World::getInstance().createAtom(); 214 TremoloAtomInfoContainer *atomInfo = NULL; 215 additionalAtomData[newAtom->getId()] = *(new TremoloAtomInfoContainer); 216 atomInfo = &additionalAtomData[newAtom->getId()]; 217 TremoloKey::atomDataKey currentField; 218 string word; 219 int oldId; 220 221 lineStream << line; 222 for (it = usedFields.begin(); it < usedFields.end(); it++) { 223 currentField = knownKeys[it->substr(0, it->find("="))]; 224 switch (currentField) { 225 case TremoloKey::x : 226 // for the moment, assume there are always three dimensions 227 lineStream >> newAtom->x.x[0]; 228 lineStream >> newAtom->x.x[1]; 229 lineStream >> newAtom->x.x[2]; 230 break; 231 case TremoloKey::u : 232 // for the moment, assume there are always three dimensions 233 lineStream >> newAtom->v.x[0]; 234 lineStream >> newAtom->v.x[1]; 235 lineStream >> newAtom->v.x[2]; 236 break; 237 case TremoloKey::Type : 238 char type[3]; 239 lineStream >> type; 240 newAtom->setType(World::getInstance().getPeriode()->FindElement(type)); 241 ASSERT(newAtom->getType(), "Type was not set for this atom"); 242 break; 243 case TremoloKey::Id : 244 lineStream >> oldId; 245 atomIdMap[oldId] = newAtom->getId(); 246 break; 247 case TremoloKey::neighbors : 248 readNeighbors(&lineStream, 249 atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId()); 250 break; 251 default : 252 lineStream >> word; 253 atomInfo->set(currentField, word); 254 break; 255 } 256 } 257 } 258 259 /** 260 * Reads neighbor information for one atom from the input. 261 * 262 * \param stream where to read the information from 263 * \param number of neighbors to read 264 * \param world id of the atom the information belongs to 265 */ 266 void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) { 267 int neighborId = 0; 268 for (int i = 0; i < numberOfNeighbors; i++) { 269 *line >> neighborId; 270 // 0 is used to fill empty neighbor positions in the tremolo file. 271 if (neighborId > 0) { 272 additionalAtomData[atomId].neighbors.push_back(neighborId); 273 } 274 } 275 } 276 277 /** 278 * Checks whether the provided name is within the list of used fields. 279 * 280 * \param field name to check 281 * 282 * \return true if the field name is used 283 */ 284 bool TremoloParser::isUsedField(string fieldName) { 285 bool fieldNameExists = false; 286 for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) { 287 if (usedField->substr(0, usedField->find("=")) == fieldName) 288 fieldNameExists = true; 289 } 290 291 return fieldNameExists; 292 } 293 294 295 /** 296 * Adds the collected neighbor information to the atoms in the world. The atoms 297 * are found by their current ID and mapped to the corresponding atoms with the 298 * Id found in the parsed file. 299 */ 300 void TremoloParser::processNeighborInformation() { 301 if (!isUsedField("neighbors")) { 302 return; 303 } 304 305 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin(); 306 currentInfo != additionalAtomData.end(); currentInfo++ 307 ) { 308 for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin(); 309 neighbor != currentInfo->second.neighbors.end(); neighbor++ 310 ) { 311 World::getInstance().getAtom(AtomById(currentInfo->first)) 312 ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor]))); 313 } 314 } 315 } 316 317 /** 318 * Replaces atom IDs read from the file by the corresponding world IDs. All IDs 319 * IDs of the input string will be replaced; expected separating characters are 320 * "-" and ",". 321 * 322 * \param string in which atom IDs should be adapted 323 * 324 * \return input string with modified atom IDs 325 */ 326 string TremoloParser::adaptIdDependentDataString(string data) { 327 // there might be no IDs 328 if (data == "-") { 329 return "-"; 330 } 331 332 char separator; 333 int id; 334 stringstream line, result; 335 line << data; 336 337 line >> id; 338 result << atomIdMap[id]; 339 while (line.good()) { 340 line >> separator >> id; 341 result << separator << atomIdMap[id]; 342 } 343 344 return result.str(); 345 } 346 347 /** 348 * Corrects the atom IDs in each imprData entry to the corresponding world IDs 349 * as they might differ from the originally read IDs. 350 */ 351 void TremoloParser::adaptImprData() { 352 if (!isUsedField("imprData")) { 353 return; 354 } 355 356 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin(); 357 currentInfo != additionalAtomData.end(); currentInfo++ 358 ) { 359 currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData); 360 } 361 } 362 363 /** 364 * Corrects the atom IDs in each torsion entry to the corresponding world IDs 365 * as they might differ from the originally read IDs. 366 */ 367 void TremoloParser::adaptTorsion() { 368 if (!isUsedField("torsion")) { 369 return; 370 } 371 372 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin(); 373 currentInfo != additionalAtomData.end(); currentInfo++ 374 ) { 375 currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion); 376 } 377 } 378 223 379 224 380 TremoloAtomInfoContainer::TremoloAtomInfoContainer() { 225 name = "none"; 226 /* Add suitable default values. 227 std::string F; 228 std::string stress; 229 std::string imprData; 230 std::string GroupMeasureTypeNo; 231 std::string extType; 232 std::string name; 233 std::string resName; 234 std::string chainID; 235 std::string resSeq; 236 std::string occupancy; 237 std::string tempFactor; 238 std::string segID; 239 std::string Charge; 240 std::string charge; 241 std::string GrpTypeNo; 242 */ 243 }; 381 F = "0"; 382 stress = "0"; 383 imprData = "-"; 384 GroupMeasureTypeNo = "0"; 385 extType = "-"; 386 name = "-"; 387 resName = "-"; 388 chainID = "0"; 389 resSeq = "0"; 390 occupancy = "0"; 391 tempFactor = "0"; 392 segID = "0"; 393 Charge = "0"; 394 charge = "0"; 395 GrpTypeNo = "0"; 396 torsion = "-"; 397 neighbors = vector<int>(0, 5); 398 } 399 400 void TremoloAtomInfoContainer::set(TremoloKey::atomDataKey key, string value) { 401 switch (key) { 402 case TremoloKey::F : 403 F = value; 404 break; 405 case TremoloKey::stress : 406 stress = value; 407 break; 408 case TremoloKey::imprData : 409 imprData = value; 410 break; 411 case TremoloKey::GroupMeasureTypeNo : 412 GroupMeasureTypeNo = value; 413 break; 414 case TremoloKey::extType : 415 extType = value; 416 break; 417 case TremoloKey::name : 418 name = value; 419 break; 420 case TremoloKey::resName : 421 resName = value; 422 break; 423 case TremoloKey::chainID : 424 chainID = value; 425 break; 426 case TremoloKey::resSeq : 427 resSeq = value; 428 break; 429 case TremoloKey::occupancy : 430 occupancy = value; 431 break; 432 case TremoloKey::tempFactor : 433 tempFactor = value; 434 break; 435 case TremoloKey::segID : 436 segID = value; 437 break; 438 case TremoloKey::Charge : 439 Charge = value; 440 break; 441 case TremoloKey::charge : 442 charge = value; 443 break; 444 case TremoloKey::GrpTypeNo : 445 GrpTypeNo = value; 446 break; 447 case TremoloKey::torsion : 448 torsion = value; 449 break; 450 default : 451 cout << "Unknown key: " << key << ", value: " << value << endl; 452 break; 453 } 454 } 455 456 string TremoloAtomInfoContainer::get(TremoloKey::atomDataKey key) { 457 switch (key) { 458 case TremoloKey::F : 459 return F; 460 case TremoloKey::stress : 461 return stress; 462 case TremoloKey::imprData : 463 return imprData; 464 case TremoloKey::GroupMeasureTypeNo : 465 return GroupMeasureTypeNo; 466 case TremoloKey::extType : 467 return extType; 468 case TremoloKey::name : 469 return name; 470 case TremoloKey::resName : 471 return resName; 472 case TremoloKey::chainID : 473 return chainID; 474 case TremoloKey::resSeq : 475 return resSeq; 476 case TremoloKey::occupancy : 477 return occupancy; 478 case TremoloKey::tempFactor : 479 return tempFactor; 480 case TremoloKey::segID : 481 return segID; 482 case TremoloKey::Charge : 483 return Charge; 484 case TremoloKey::charge : 485 return charge; 486 case TremoloKey::GrpTypeNo : 487 return GrpTypeNo; 488 case TremoloKey::torsion : 489 return torsion; 490 default : 491 cout << "Unknown key: " << key << endl; 492 return ""; 493 } 494 } 495 -
src/Parser/TremoloParser.hpp
r4415da rb8d4a3 13 13 14 14 /** 15 * Holds tremolo-specific information which is not store in the atom class.15 * Known keys for the ATOMDATA line. 16 16 */ 17 class Tremolo AtomInfoContainer{17 class TremoloKey { 18 18 public: 19 TremoloAtomInfoContainer();20 std::string F;21 std::string stress;22 std::string imprData;23 std::string GroupMeasureTypeNo;24 std::string extType;25 std::string name;26 std::string resName;27 std::string chainID;28 std::string resSeq;29 std::string occupancy;30 std::string tempFactor;31 std::string segID;32 std::string Charge;33 std::string charge;34 std::string GrpTypeNo;35 };36 37 /**38 * Loads a tremolo file into the World and saves the World as a tremolo file.39 */40 class TremoloParser:public FormatParser41 {42 public:43 TremoloParser();44 ~TremoloParser();45 void load(std::istream* file);46 void save(std::ostream* file);47 48 private:49 void readAtomDataLine(string line);50 void parseAtomDataKeysLine(string line, int offset);51 52 /**53 * Known keys for the ATOMDATA line.54 */55 19 enum atomDataKey { 56 20 noKey, … … 74 38 Charge, 75 39 charge, 76 GrpTypeNo 40 GrpTypeNo, 41 torsion 77 42 }; 43 }; 44 45 /** 46 * Holds tremolo-specific information which is not store in the atom class. 47 */ 48 class TremoloAtomInfoContainer { 49 public: 50 TremoloAtomInfoContainer(); 51 void set(TremoloKey::atomDataKey key, std::string value); 52 std::string get(TremoloKey::atomDataKey key); 53 std::string F; 54 std::string stress; 55 std::string imprData; 56 std::string GroupMeasureTypeNo; 57 std::string extType; 58 std::string name; 59 std::string resName; 60 std::string chainID; 61 std::string resSeq; 62 std::string occupancy; 63 std::string tempFactor; 64 std::string segID; 65 std::string Charge; 66 std::string charge; 67 std::string GrpTypeNo; 68 std::string torsion; 69 std::vector<int> neighbors; 70 }; 71 72 /** 73 * Loads a tremolo file into the World and saves the World as a tremolo file. 74 */ 75 class TremoloParser : public FormatParser 76 { 77 public: 78 TremoloParser(); 79 ~TremoloParser(); 80 void load(std::istream* file); 81 void save(std::ostream* file); 82 void setFieldsForSave(std::string atomDataLine); 83 84 85 private: 86 void readAtomDataLine(string line); 87 void parseAtomDataKeysLine(string line, int offset); 88 void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId); 89 void processNeighborInformation(); 90 void adaptImprData(); 91 void adaptTorsion(); 92 std::string adaptIdDependentDataString(std::string data); 93 bool isUsedField(std::string fieldName); 94 void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom); 95 void saveLine(std::ostream* file, atom* currentAtom); 78 96 79 97 /** 80 98 * Map to associate the known keys with numbers. 81 99 */ 82 std::map<std::string, atomDataKey> knownKeys;100 std::map<std::string, TremoloKey::atomDataKey> knownKeys; 83 101 84 102 /** … … 91 109 * file. 92 110 */ 93 std::map<int, TremoloAtomInfoContainer> moreData; 111 std::map<int, TremoloAtomInfoContainer> additionalAtomData; 112 113 /** 114 * Default additional atom data. 115 */ 116 TremoloAtomInfoContainer defaultAdditionalData; 117 118 /** 119 * Maps original atom IDs received from the parsed file to atom IDs in the 120 * world. 121 */ 122 std::map<int, int> atomIdMap; 94 123 }; 95 124 -
src/atom_bondedparticle.cpp
r4415da rb8d4a3 74 74 *BondFile << nr << "\t" << (*Runner)->GetOtherAtom(this)->nr << "\n"; 75 75 }; 76 77 /** 78 * Adds a bond between this bonded particle and another. Does nothing if this 79 * bond already exists. 80 * 81 * \param bonding partner 82 */ 83 void BondedParticle::addBond(BondedParticle* Partner) { 84 if (IsBondedTo(Partner)) { 85 return; 86 } 87 88 bond* newBond = new bond((atom*) this, (atom*) Partner, 1, 0); 89 RegisterBond(newBond); 90 Partner->RegisterBond(newBond); 91 } 76 92 77 93 /** Puts a given bond into atom::ListOfBonds. -
src/atom_bondedparticle.hpp
r4415da rb8d4a3 37 37 virtual ~BondedParticle(); 38 38 39 void addBond(BondedParticle* Partner); 39 40 bool RegisterBond(bond *Binder); 40 41 bool UnregisterBond(bond *Binder); -
src/atom_particleinfo.cpp
r4415da rb8d4a3 16 16 nr(pointer->nr), 17 17 Name(pointer->Name) 18 {} 18 { 19 if (Name == NULL) 20 Name = " "; 21 } 19 22 20 23 -
src/bond.cpp
r4415da rb8d4a3 15 15 /** Empty Constructor for class bond. 16 16 */ 17 bond::bond() : leftatom(NULL), rightatom(NULL), previous(NULL), next(NULL), HydrogenBond(0), BondDegree(0), nr(-1), Cyclic(false), Type(Undetermined), Used(white) 17 bond::bond() 18 : leftatom(NULL), rightatom(NULL), previous(NULL), next(NULL), HydrogenBond(0), 19 BondDegree(0), nr(-1), Cyclic(false), Type(Undetermined), Used(white) 18 20 { 19 21 }; … … 25 27 * \param number increasing index 26 28 */ 27 bond::bond(atom *left, atom *right, const int degree, const int number) : leftatom(left), rightatom(right), previous(NULL), next(NULL), HydrogenBond(0), BondDegree(degree), nr(number), Cyclic(false), Type(Undetermined), Used(white) 29 bond::bond(atom *left, atom *right, const int degree, const int number) 30 : leftatom(left), rightatom(right), previous(NULL), next(NULL), HydrogenBond(0), 31 BondDegree(degree), nr(number), Cyclic(false), Type(Undetermined), Used(white) 28 32 { 29 33 if ((left != NULL) && (right != NULL)) { -
src/tesselation.cpp
r4415da rb8d4a3 942 942 node = NULL; 943 943 nr = -1; 944 Name = NULL; 944 Name = Malloc<char> (1, "TesselPoint::TtesselPoint - Name"); 945 Name = strcpy(Name, "-"); 945 946 }; 946 947 -
src/unittests/ParserUnitTest.cpp
r4415da rb8d4a3 15 15 #include "Parser/TremoloParser.hpp" 16 16 #include "World.hpp" 17 #include "atom.hpp" 17 18 #include "element.hpp" 18 19 #include "periodentafel.hpp" 20 #include "Descriptors/AtomTypeDescriptor.hpp" 19 21 20 22 #ifdef HAVE_TESTRUNNER … … 41 43 42 44 void ParserUnitTest::tearDown() { 45 World::purgeInstance(); 43 46 } 44 47 … … 63 66 } 64 67 65 void ParserUnitTest::re writeTremoloTest() {68 void ParserUnitTest::readTremoloPreliminaryCommentsTest() { 66 69 cout << "Testing the tremolo parser." << endl; 67 70 TremoloParser* testParser = new TremoloParser(); 68 stringstream input; 71 stringstream input, output; 72 string waterTremolo; 69 73 70 74 // Atomdata beginning with "# ATOMDATA" 71 string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n";75 waterTremolo = "# ATOMDATA\tId\tname\tType\tx=3\n"; 72 76 input << waterTremolo; 73 77 testParser->load(&input); 78 testParser->save(&output); 79 CPPUNIT_ASSERT(waterTremolo == output.str()); 74 80 input.clear(); 81 output.clear(); 75 82 76 83 // Atomdata beginning with "#ATOMDATA" 77 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen3.0 4.5 0.1\n\n";84 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; 78 85 input << waterTremolo; 79 86 testParser->load(&input); 87 testParser->save(&output); 88 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos); 80 89 input.clear(); 81 82 // One simple data line 83 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n"; 84 input << waterTremolo; 85 testParser->load(&input); 86 input.clear(); 90 output.clear(); 87 91 88 92 // Invalid key in Atomdata line … … 90 94 input << waterTremolo; 91 95 testParser->load(&input); 96 //TODO: proove invalidity 92 97 input.clear(); 98 } 99 100 void ParserUnitTest::readTremoloCoordinatesTest() { 101 TremoloParser* testParser = new TremoloParser(); 102 stringstream input; 103 string waterTremolo; 104 105 // One simple data line 106 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; 107 input << waterTremolo; 108 testParser->load(&input); 109 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->x.x[0] == 3.0); 110 input.clear(); 111 } 112 113 void ParserUnitTest::readTremoloVelocityTest() { 114 TremoloParser* testParser = new TremoloParser(); 115 stringstream input; 116 string waterTremolo; 117 118 // One simple data line 119 waterTremolo = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; 120 input << waterTremolo; 121 testParser->load(&input); 122 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->v.x[0] == 3.0); 123 input.clear(); 124 } 125 126 void ParserUnitTest::readTremoloNeighborInformationTest() { 127 TremoloParser* testParser = new TremoloParser(); 128 stringstream input; 129 string waterTremolo; 130 131 // Neighbor data 132 waterTremolo = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n"; 133 input << waterTremolo; 134 testParser->load(&input); 135 136 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 137 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))-> 138 IsBondedTo(World::getInstance().getAtom(AtomByType(1)))); 139 input.clear(); 140 } 141 142 void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() { 143 TremoloParser* testParser = new TremoloParser(); 144 stringstream input, output; 145 string waterTremolo; 146 147 // Neighbor data 148 waterTremolo = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n"; 149 input << waterTremolo; 150 testParser->load(&input); 151 testParser->save(&output); 152 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 153 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); 154 input.clear(); 155 output.clear(); 156 } 157 158 void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() { 159 TremoloParser* testParser = new TremoloParser(); 160 stringstream input, output; 161 string waterTremolo; 162 163 // Neighbor data 164 waterTremolo = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n"; 165 input << waterTremolo; 166 testParser->load(&input); 167 testParser->save(&output); 168 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 169 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); 170 input.clear(); 171 output.clear(); 172 } 173 174 void ParserUnitTest::writeTremoloTest() { 175 TremoloParser* testParser = new TremoloParser(); 176 stringstream output; 177 178 // with the maximum number of fields and minimal information, default values are printed 179 atom* newAtom = World::getInstance().createAtom(); 180 newAtom->type = World::getInstance().getPeriode()->FindElement(1); 181 testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo Type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion"); 182 testParser->save(&output); 183 CPPUNIT_ASSERT(output.str() == "# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\tType\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n"); 93 184 94 185 cout << "testing the tremolo parser is done" << endl; -
src/unittests/ParserUnitTest.hpp
r4415da rb8d4a3 15 15 CPPUNIT_TEST_SUITE( ParserUnitTest ) ; 16 16 CPPUNIT_TEST ( rewriteAnXyzTest ); 17 CPPUNIT_TEST ( rewriteTremoloTest ); 17 CPPUNIT_TEST ( readTremoloPreliminaryCommentsTest ); 18 CPPUNIT_TEST ( readTremoloCoordinatesTest ); 19 CPPUNIT_TEST ( readTremoloVelocityTest ); 20 CPPUNIT_TEST ( readTremoloNeighborInformationTest ); 21 CPPUNIT_TEST ( readAndWriteTremoloImprDataInformationTest ); 22 CPPUNIT_TEST ( readAndWriteTremoloTorsionInformationTest ); 23 CPPUNIT_TEST ( writeTremoloTest ); 18 24 CPPUNIT_TEST_SUITE_END(); 19 25 … … 23 29 24 30 void rewriteAnXyzTest(); 25 void rewriteTremoloTest(); 31 void readTremoloPreliminaryCommentsTest(); 32 void readTremoloCoordinatesTest(); 33 void readTremoloVelocityTest(); 34 void readTremoloNeighborInformationTest(); 35 void readAndWriteTremoloImprDataInformationTest(); 36 void readAndWriteTremoloTorsionInformationTest(); 37 void writeTremoloTest(); 26 38 }; 27 39 -
src/unittests/SingletonTest.cpp
r4415da rb8d4a3 52 52 count1++; 53 53 } 54 // explicit copy constructor to catch if th siis ever called54 // explicit copy constructor to catch if this is ever called 55 55 SingletonStub2(const SingletonStub2&){ 56 56 CPPUNIT_FAIL ( "Copy constructor of Singleton called" );
Note:
See TracChangeset
for help on using the changeset viewer.