| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [6bc51d] | 8 | /*
 | 
|---|
 | 9 |  * TremoloParser.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Mar 2, 2010
 | 
|---|
 | 12 |  *      Author: metzler
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 21 | 
 | 
|---|
| [ad011c] | 22 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 23 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [4d4d33] | 24 | #include "CodePatterns/toString.hpp"
 | 
|---|
| [ad011c] | 25 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [9131f3] | 26 | #include "TremoloParser.hpp"
 | 
|---|
 | 27 | #include "World.hpp"
 | 
|---|
| [9d83b6] | 28 | #include "WorldTime.hpp"
 | 
|---|
| [9131f3] | 29 | #include "atom.hpp"
 | 
|---|
| [129204] | 30 | #include "Bond/bond.hpp"
 | 
|---|
| [dc1d9e] | 31 | #include "element.hpp"
 | 
|---|
 | 32 | #include "molecule.hpp"
 | 
|---|
| [9131f3] | 33 | #include "periodentafel.hpp"
 | 
|---|
| [b8d4a3] | 34 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [9131f3] | 35 | #include <map>
 | 
|---|
 | 36 | #include <vector>
 | 
|---|
 | 37 | 
 | 
|---|
| [72d108] | 38 | #include <boost/tokenizer.hpp>
 | 
|---|
| [74a444] | 39 | #include <iostream>
 | 
|---|
 | 40 | #include <iomanip>
 | 
|---|
| [b8d4a3] | 41 | 
 | 
|---|
| [9131f3] | 42 | using namespace std;
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | /**
 | 
|---|
 | 45 |  * Constructor.
 | 
|---|
 | 46 |  */
 | 
|---|
 | 47 | TremoloParser::TremoloParser() {
 | 
|---|
| [b8d4a3] | 48 |   knownKeys["x"] = TremoloKey::x;
 | 
|---|
 | 49 |   knownKeys["u"] = TremoloKey::u;
 | 
|---|
 | 50 |   knownKeys["F"] = TremoloKey::F;
 | 
|---|
 | 51 |   knownKeys["stress"] = TremoloKey::stress;
 | 
|---|
 | 52 |   knownKeys["Id"] = TremoloKey::Id;
 | 
|---|
 | 53 |   knownKeys["neighbors"] = TremoloKey::neighbors;
 | 
|---|
 | 54 |   knownKeys["imprData"] = TremoloKey::imprData;
 | 
|---|
 | 55 |   knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo;
 | 
|---|
| [305e7e] | 56 |   knownKeys["type"] = TremoloKey::type;
 | 
|---|
| [b8d4a3] | 57 |   knownKeys["extType"] = TremoloKey::extType;
 | 
|---|
 | 58 |   knownKeys["name"] = TremoloKey::name;
 | 
|---|
 | 59 |   knownKeys["resName"] = TremoloKey::resName;
 | 
|---|
 | 60 |   knownKeys["chainID"] = TremoloKey::chainID;
 | 
|---|
 | 61 |   knownKeys["resSeq"] = TremoloKey::resSeq;
 | 
|---|
 | 62 |   knownKeys["occupancy"] = TremoloKey::occupancy;
 | 
|---|
 | 63 |   knownKeys["tempFactor"] = TremoloKey::tempFactor;
 | 
|---|
 | 64 |   knownKeys["segID"] = TremoloKey::segID;
 | 
|---|
 | 65 |   knownKeys["Charge"] = TremoloKey::Charge;
 | 
|---|
 | 66 |   knownKeys["charge"] = TremoloKey::charge;
 | 
|---|
 | 67 |   knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo;
 | 
|---|
 | 68 |   knownKeys["torsion"] = TremoloKey::torsion;
 | 
|---|
| [52baf9] | 69 | 
 | 
|---|
| [4d4d33] | 70 |   createKnownTypesByIdentity();
 | 
|---|
 | 71 | 
 | 
|---|
| [52baf9] | 72 |   // default behavior: use all possible keys on output
 | 
|---|
 | 73 |   for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter)
 | 
|---|
 | 74 |     usedFields.push_back(iter->first);
 | 
|---|
| [ff3c40] | 75 | 
 | 
|---|
 | 76 |   // and noKey afterwards(!) such that it is not used in usedFields
 | 
|---|
 | 77 |   knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys
 | 
|---|
| [4d4d33] | 78 | 
 | 
|---|
 | 79 |   // invert knownKeys for debug output
 | 
|---|
 | 80 |   for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter)
 | 
|---|
 | 81 |     knownKeyNames.insert( make_pair( iter->second, iter->first) );
 | 
|---|
 | 82 | 
 | 
|---|
 | 83 |   additionalAtomData.clear();
 | 
|---|
| [9131f3] | 84 | }
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | /**
 | 
|---|
 | 87 |  * Destructor.
 | 
|---|
 | 88 |  */
 | 
|---|
 | 89 | TremoloParser::~TremoloParser() {
 | 
|---|
| [2e352f] | 90 |         std::cerr << "Clearing usedFields." << std::endl;
 | 
|---|
| [b8d4a3] | 91 |   usedFields.clear();
 | 
|---|
 | 92 |   additionalAtomData.clear();
 | 
|---|
 | 93 |   atomIdMap.clear();
 | 
|---|
 | 94 |   knownKeys.clear();
 | 
|---|
 | 95 | }
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | /**
 | 
|---|
 | 98 |  * Loads atoms from a tremolo-formatted file.
 | 
|---|
 | 99 |  *
 | 
|---|
 | 100 |  * \param tremolo file
 | 
|---|
 | 101 |  */
 | 
|---|
 | 102 | void TremoloParser::load(istream* file) {
 | 
|---|
 | 103 |   string line;
 | 
|---|
 | 104 |   string::size_type location;
 | 
|---|
 | 105 | 
 | 
|---|
| [0bbfa1] | 106 |   // reset atomIdMap, for we now get new serials
 | 
|---|
 | 107 |   atomIdMap.clear();
 | 
|---|
| [2e352f] | 108 |         std::cerr << "Clearing usedFields." << std::endl;
 | 
|---|
| [b8d4a3] | 109 |   usedFields.clear();
 | 
|---|
| [0bbfa1] | 110 | 
 | 
|---|
| [dc1d9e] | 111 |   molecule *newmol = World::getInstance().createMolecule();
 | 
|---|
| [bd2390] | 112 |   newmol->ActiveFlag = true;
 | 
|---|
 | 113 |   // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
 | 
|---|
 | 114 |   World::getInstance().getMolecules()->insert(newmol);
 | 
|---|
| [b8d4a3] | 115 |   while (file->good()) {
 | 
|---|
 | 116 |     std::getline(*file, line, '\n');
 | 
|---|
 | 117 |     if (usedFields.empty()) {
 | 
|---|
 | 118 |       location = line.find("ATOMDATA", 0);
 | 
|---|
 | 119 |       if (location != string::npos) {
 | 
|---|
 | 120 |        parseAtomDataKeysLine(line, location + 8);
 | 
|---|
 | 121 |       }
 | 
|---|
 | 122 |     }
 | 
|---|
 | 123 |     if (line.length() > 0 && line.at(0) != '#') {
 | 
|---|
| [dc1d9e] | 124 |       readAtomDataLine(line, newmol);
 | 
|---|
| [b8d4a3] | 125 |     }
 | 
|---|
 | 126 |   }
 | 
|---|
| [4afa46] | 127 |   // refresh atom::nr and atom::name
 | 
|---|
 | 128 |   newmol->getAtomCount();
 | 
|---|
| [b8d4a3] | 129 | 
 | 
|---|
| [2e352f] | 130 |   DoLog(3) && (Log() << Verbose(3) << "usedFields after load contains: " << usedFields << std::endl);
 | 
|---|
 | 131 | 
 | 
|---|
| [b8d4a3] | 132 |   processNeighborInformation();
 | 
|---|
 | 133 |   adaptImprData();
 | 
|---|
 | 134 |   adaptTorsion();
 | 
|---|
 | 135 | }
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 | /**
 | 
|---|
| [73916f] | 138 |  * Saves the \a atoms into as a tremolo file.
 | 
|---|
| [b8d4a3] | 139 |  *
 | 
|---|
 | 140 |  * \param file where to save the state
 | 
|---|
| [73916f] | 141 |  * \param atoms atoms to store
 | 
|---|
| [b8d4a3] | 142 |  */
 | 
|---|
| [73916f] | 143 | void TremoloParser::save(ostream* file, const std::vector<atom *> &AtomList) {
 | 
|---|
| [e97a44] | 144 |   DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
 | 
|---|
 | 145 | 
 | 
|---|
| [73916f] | 146 |   vector<atom*>::const_iterator atomIt;
 | 
|---|
| [2e352f] | 147 |   /*vector<string>::iterator it;*/
 | 
|---|
 | 148 |   vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 |   DoLog(3) && (Log() << Verbose(3) << "usedFields before save contains: " << usedFields << std::endl);
 | 
|---|
 | 152 | 
 | 
|---|
 | 153 |   DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
 | 
|---|
| [b8d4a3] | 154 | 
 | 
|---|
| [acd638] | 155 |   DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
 | 
|---|
 | 156 | 
 | 
|---|
| [b8d4a3] | 157 |   *file << "# ATOMDATA";
 | 
|---|
 | 158 |   for (it=usedFields.begin(); it < usedFields.end(); it++) {
 | 
|---|
 | 159 |     *file << "\t" << *it;
 | 
|---|
 | 160 |   }
 | 
|---|
 | 161 |   *file << endl;
 | 
|---|
 | 162 |   for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
 | 
|---|
 | 163 |     saveLine(file, *atomIt);
 | 
|---|
 | 164 |   }
 | 
|---|
 | 165 | }
 | 
|---|
 | 166 | 
 | 
|---|
| [6bc86c] | 167 | /** Add default info, when new atom is added to World.
 | 
|---|
 | 168 |  *
 | 
|---|
 | 169 |  * @param id of atom
 | 
|---|
 | 170 |  */
 | 
|---|
 | 171 | void TremoloParser::AtomInserted(atomId_t id)
 | 
|---|
 | 172 | {
 | 
|---|
 | 173 |   std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
 | 
|---|
 | 174 |   ASSERT(iter == additionalAtomData.end(),
 | 
|---|
 | 175 |       "TremoloParser::AtomInserted() - additionalAtomData already present for newly added atom "
 | 
|---|
 | 176 |       +toString(id)+".");
 | 
|---|
 | 177 |   // don't add entry, as this gives a default resSeq of 0 not the molecule id
 | 
|---|
 | 178 |   // additionalAtomData.insert( std::make_pair(id, TremoloAtomInfoContainer()) );
 | 
|---|
 | 179 | }
 | 
|---|
 | 180 | 
 | 
|---|
 | 181 | /** Remove additional AtomData info, when atom has been removed from World.
 | 
|---|
 | 182 |  *
 | 
|---|
 | 183 |  * @param id of atom
 | 
|---|
 | 184 |  */
 | 
|---|
 | 185 | void TremoloParser::AtomRemoved(atomId_t id)
 | 
|---|
 | 186 | {
 | 
|---|
 | 187 |   std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
 | 
|---|
 | 188 |   // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
 | 
|---|
 | 189 | //  ASSERT(iter != additionalAtomData.end(),
 | 
|---|
 | 190 | //      "TremoloParser::AtomRemoved() - additionalAtomData is not present for atom "
 | 
|---|
 | 191 | //      +toString(id)+" to remove.");
 | 
|---|
 | 192 |   if (iter != additionalAtomData.end())
 | 
|---|
 | 193 |     additionalAtomData.erase(iter);
 | 
|---|
 | 194 | }
 | 
|---|
 | 195 | 
 | 
|---|
| [b8d4a3] | 196 | /**
 | 
|---|
 | 197 |  * Sets the keys for which data should be written to the stream when save is
 | 
|---|
 | 198 |  * called.
 | 
|---|
 | 199 |  *
 | 
|---|
 | 200 |  * \param string of field names with the same syntax as for an ATOMDATA line
 | 
|---|
 | 201 |  *        but without the prexix "ATOMDATA"
 | 
|---|
 | 202 |  */
 | 
|---|
 | 203 | void TremoloParser::setFieldsForSave(std::string atomDataLine) {
 | 
|---|
 | 204 |   parseAtomDataKeysLine(atomDataLine, 0);
 | 
|---|
 | 205 | }
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 | 
 | 
|---|
 | 208 | /**
 | 
|---|
 | 209 |  * Writes one line of tremolo-formatted data to the provided stream.
 | 
|---|
 | 210 |  *
 | 
|---|
 | 211 |  * \param stream where to write the line to
 | 
|---|
 | 212 |  * \param reference to the atom of which information should be written
 | 
|---|
 | 213 |  */
 | 
|---|
 | 214 | void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
 | 
|---|
| [2e352f] | 215 |  /* vector<string>::iterator it;*/
 | 
|---|
 | 216 |         vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector
 | 
|---|
 | 217 | 
 | 
|---|
| [b8d4a3] | 218 |   TremoloKey::atomDataKey currentField;
 | 
|---|
 | 219 | 
 | 
|---|
| [acd638] | 220 |   DoLog(4) && (Log() << Verbose(4) << "INFO: Saving atom " << *currentAtom << ", its father id is " << currentAtom->GetTrueFather()->getId() << std::endl);
 | 
|---|
| [4d4d33] | 221 | 
 | 
|---|
| [b8d4a3] | 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
 | 
|---|
| [4d4d33] | 227 |         DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getPosition() << std::endl);
 | 
|---|
| [d74077] | 228 |         *file << currentAtom->at(0) << "\t";
 | 
|---|
 | 229 |         *file << currentAtom->at(1) << "\t";
 | 
|---|
 | 230 |         *file << currentAtom->at(2) << "\t";
 | 
|---|
| [b8d4a3] | 231 |         break;
 | 
|---|
 | 232 |       case TremoloKey::u :
 | 
|---|
 | 233 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [bce72c] | 234 |         DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getAtomicVelocity() << std::endl);
 | 
|---|
 | 235 |         *file << currentAtom->getAtomicVelocity()[0] << "\t";
 | 
|---|
 | 236 |         *file << currentAtom->getAtomicVelocity()[1] << "\t";
 | 
|---|
 | 237 |         *file << currentAtom->getAtomicVelocity()[2] << "\t";
 | 
|---|
| [b8d4a3] | 238 |         break;
 | 
|---|
| [305e7e] | 239 |       case TremoloKey::type :
 | 
|---|
| [acd638] | 240 |         if (additionalAtomData.count(currentAtom->getId())) {
 | 
|---|
 | 241 |           if (additionalAtomData[currentAtom->getId()].get(currentField) != "-") {
 | 
|---|
 | 242 |             DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
 | 
|---|
 | 243 |             *file << additionalAtomData[currentAtom->getId()].get(currentField) << "\t";
 | 
|---|
 | 244 |           } else {
 | 
|---|
 | 245 |             DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << currentAtom->getType()->getSymbol() << std::endl);
 | 
|---|
 | 246 |             *file << currentAtom->getType()->getSymbol() << "\t";
 | 
|---|
 | 247 |           }
 | 
|---|
 | 248 |         } else if (additionalAtomData.count(currentAtom->GetTrueFather()->getId())) {
 | 
|---|
 | 249 |           if (additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) != "-") {
 | 
|---|
 | 250 |             DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " stuff from father: " << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << std::endl);
 | 
|---|
 | 251 |             *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << "\t";
 | 
|---|
 | 252 |           } else {
 | 
|---|
 | 253 |             DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value from father: " << currentAtom->GetTrueFather()->getType()->getSymbol() << std::endl);
 | 
|---|
 | 254 |             *file << currentAtom->GetTrueFather()->getType()->getSymbol() << "\t";
 | 
|---|
 | 255 |           }
 | 
|---|
| [4d4d33] | 256 |         } else {
 | 
|---|
| [acd638] | 257 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " its default value: " << currentAtom->getType()->getSymbol() << std::endl);
 | 
|---|
 | 258 |           *file << currentAtom->getType()->getSymbol() << "\t";
 | 
|---|
| [4d4d33] | 259 |         }
 | 
|---|
| [b8d4a3] | 260 |         break;
 | 
|---|
 | 261 |       case TremoloKey::Id :
 | 
|---|
| [4d4d33] | 262 |         DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getId()+1 << std::endl);
 | 
|---|
| [dc1d9e] | 263 |         *file << currentAtom->getId()+1 << "\t";
 | 
|---|
| [b8d4a3] | 264 |         break;
 | 
|---|
 | 265 |       case TremoloKey::neighbors :
 | 
|---|
| [4d4d33] | 266 |         DoLog(3) && (Log() << Verbose(3) << "Writing type " << knownKeyNames[currentField] << std::endl);
 | 
|---|
| [b8d4a3] | 267 |         writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
 | 
|---|
 | 268 |         break;
 | 
|---|
| [74a444] | 269 |       case TremoloKey::resSeq :
 | 
|---|
| [4d4d33] | 270 |         if (additionalAtomData.count(currentAtom->getId())) {
 | 
|---|
 | 271 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
 | 
|---|
| [74a444] | 272 |           *file << additionalAtomData[currentAtom->getId()].get(currentField);
 | 
|---|
 | 273 |         } else if (currentAtom->getMolecule() != NULL) {
 | 
|---|
| [4d4d33] | 274 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " its own id: " << currentAtom->getMolecule()->getId()+1 << std::endl);
 | 
|---|
| [74a444] | 275 |           *file << setw(4) << currentAtom->getMolecule()->getId()+1;
 | 
|---|
 | 276 |         } else {
 | 
|---|
| [4d4d33] | 277 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << defaultAdditionalData.get(currentField) << std::endl);
 | 
|---|
| [74a444] | 278 |           *file << defaultAdditionalData.get(currentField);
 | 
|---|
 | 279 |         }
 | 
|---|
 | 280 |         *file << "\t";
 | 
|---|
| [4d4d33] | 281 |         break;
 | 
|---|
| [b8d4a3] | 282 |       default :
 | 
|---|
| [4d4d33] | 283 |         if (additionalAtomData.count(currentAtom->getId())) {
 | 
|---|
 | 284 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
 | 
|---|
| [74a444] | 285 |           *file << additionalAtomData[currentAtom->getId()].get(currentField);
 | 
|---|
| [4d4d33] | 286 |         } else if (additionalAtomData.count(currentAtom->GetTrueFather()->getId())) {
 | 
|---|
 | 287 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " stuff from father: " << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << std::endl);
 | 
|---|
| [74a444] | 288 |           *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField);
 | 
|---|
 | 289 |         } else {
 | 
|---|
| [4d4d33] | 290 |           DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " the default: " << defaultAdditionalData.get(currentField) << std::endl);
 | 
|---|
| [74a444] | 291 |           *file << defaultAdditionalData.get(currentField);
 | 
|---|
 | 292 |         }
 | 
|---|
| [b8d4a3] | 293 |         *file << "\t";
 | 
|---|
 | 294 |         break;
 | 
|---|
 | 295 |     }
 | 
|---|
 | 296 |   }
 | 
|---|
 | 297 | 
 | 
|---|
 | 298 |   *file << endl;
 | 
|---|
 | 299 | }
 | 
|---|
 | 300 | 
 | 
|---|
 | 301 | /**
 | 
|---|
 | 302 |  * Writes the neighbor information of one atom to the provided stream.
 | 
|---|
 | 303 |  *
 | 
|---|
| [9d83b6] | 304 |  * Note that ListOfBonds of WorldTime::CurrentTime is used.
 | 
|---|
 | 305 |  *
 | 
|---|
| [b8d4a3] | 306 |  * \param stream where to write neighbor information to
 | 
|---|
 | 307 |  * \param number of neighbors
 | 
|---|
 | 308 |  * \param reference to the atom of which to take the neighbor information
 | 
|---|
 | 309 |  */
 | 
|---|
 | 310 | void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
 | 
|---|
| [9d83b6] | 311 |   const BondList& ListOfBonds = currentAtom->getListOfBonds();
 | 
|---|
| [ca2cfa] | 312 |   // sort bonded indices
 | 
|---|
 | 313 |   typedef std::set<atomId_t> sortedIndices;
 | 
|---|
 | 314 |   sortedIndices sortedBonds;
 | 
|---|
 | 315 |   for (BondList::const_iterator iter = ListOfBonds.begin();
 | 
|---|
 | 316 |       iter != ListOfBonds.end(); ++iter)
 | 
|---|
 | 317 |     sortedBonds.insert((*iter)->GetOtherAtom(currentAtom)->getId());
 | 
|---|
 | 318 |   // print indices
 | 
|---|
 | 319 |   sortedIndices::const_iterator currentBond = sortedBonds.begin();
 | 
|---|
| [b8d4a3] | 320 |   for (int i = 0; i < numberOfNeighbors; i++) {
 | 
|---|
| [ca2cfa] | 321 |     *file << (currentBond != sortedBonds.end() ? (*currentBond)+1 : 0) << "\t";
 | 
|---|
 | 322 |     if (currentBond != sortedBonds.end())
 | 
|---|
| [0bbfa1] | 323 |       ++currentBond;
 | 
|---|
| [b8d4a3] | 324 |   }
 | 
|---|
| [9131f3] | 325 | }
 | 
|---|
 | 326 | 
 | 
|---|
 | 327 | /**
 | 
|---|
 | 328 |  * Stores keys from the ATOMDATA line.
 | 
|---|
 | 329 |  *
 | 
|---|
 | 330 |  * \param line to parse the keys from
 | 
|---|
 | 331 |  * \param with which offset the keys begin within the line
 | 
|---|
 | 332 |  */
 | 
|---|
 | 333 | void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
 | 
|---|
 | 334 |   string keyword;
 | 
|---|
 | 335 |   stringstream lineStream;
 | 
|---|
 | 336 | 
 | 
|---|
 | 337 |   lineStream << line.substr(offset);
 | 
|---|
| [2e352f] | 338 |         std::cerr << "Clearing usedFields in parseAtomDataKeysLine." << std::endl;
 | 
|---|
| [52baf9] | 339 |   usedFields.clear();
 | 
|---|
| [9131f3] | 340 |   while (lineStream.good()) {
 | 
|---|
 | 341 |     lineStream >> keyword;
 | 
|---|
| [b8d4a3] | 342 |     if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
 | 
|---|
| [ecb799] | 343 |       // TODO: throw exception about unknown key
 | 
|---|
| [4415da] | 344 |       cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
 | 
|---|
 | 345 |       break;
 | 
|---|
 | 346 |     }
 | 
|---|
| [9131f3] | 347 |     usedFields.push_back(keyword);
 | 
|---|
 | 348 |   }
 | 
|---|
| [72d108] | 349 |   //DoLog(1) && (Log() << Verbose(1) << "INFO: " << usedFields << std::endl);
 | 
|---|
| [9131f3] | 350 | }
 | 
|---|
 | 351 | 
 | 
|---|
| [81c980b] | 352 | /** Sets the properties per atom to print to .data file by parsing line from
 | 
|---|
 | 353 |  *  \a atomdata_string.
 | 
|---|
 | 354 |  *
 | 
|---|
 | 355 |  *  We just call \sa TremoloParser::parseAtomDataKeysLine() which is left
 | 
|---|
 | 356 |  *  private.,
 | 
|---|
 | 357 |  *
 | 
|---|
 | 358 |  * @param atomdata_string line to parse with space-separated values
 | 
|---|
 | 359 |  */
 | 
|---|
 | 360 | void TremoloParser::setAtomData(const std::string &atomdata_string)
 | 
|---|
 | 361 | {
 | 
|---|
 | 362 |   parseAtomDataKeysLine(atomdata_string, 0);
 | 
|---|
 | 363 | }
 | 
|---|
 | 364 | 
 | 
|---|
 | 365 | 
 | 
|---|
| [9131f3] | 366 | /**
 | 
|---|
 | 367 |  * Reads one data line of a tremolo file and interprets it according to the keys
 | 
|---|
 | 368 |  * obtained from the ATOMDATA line.
 | 
|---|
 | 369 |  *
 | 
|---|
 | 370 |  * \param line to parse as an atom
 | 
|---|
| [dc1d9e] | 371 |  * \param *newmol molecule to add atom to
 | 
|---|
| [9131f3] | 372 |  */
 | 
|---|
| [dc1d9e] | 373 | void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) {
 | 
|---|
| [9131f3] | 374 |   vector<string>::iterator it;
 | 
|---|
 | 375 |   stringstream lineStream;
 | 
|---|
| [4415da] | 376 |   atom* newAtom = World::getInstance().createAtom();
 | 
|---|
| [b8d4a3] | 377 |   TremoloAtomInfoContainer *atomInfo = NULL;
 | 
|---|
| [24f128] | 378 |   additionalAtomData[newAtom->getId()] = TremoloAtomInfoContainer(); // fill with default values
 | 
|---|
| [b8d4a3] | 379 |   atomInfo = &additionalAtomData[newAtom->getId()];
 | 
|---|
 | 380 |   TremoloKey::atomDataKey currentField;
 | 
|---|
| [72d108] | 381 |   ConvertTo<double> toDouble;
 | 
|---|
 | 382 |   ConvertTo<int> toInt;
 | 
|---|
| [056e70] | 383 |   Vector tempVector;
 | 
|---|
| [72d108] | 384 | 
 | 
|---|
 | 385 |   // setup tokenizer, splitting up white-spaced entries
 | 
|---|
 | 386 |   typedef boost::tokenizer<boost::char_separator<char> >
 | 
|---|
 | 387 |       tokenizer;
 | 
|---|
 | 388 |   boost::char_separator<char> whitespacesep(" \t");
 | 
|---|
 | 389 |   tokenizer tokens(line, whitespacesep);
 | 
|---|
 | 390 |   ASSERT(tokens.begin() != tokens.end(),
 | 
|---|
 | 391 |       "TremoloParser::readAtomDataLine - empty string, need at least ' '!");
 | 
|---|
 | 392 |   tokenizer::iterator tok_iter = tokens.begin();
 | 
|---|
 | 393 |   // then associate each token to each file
 | 
|---|
| [b8d4a3] | 394 |   for (it = usedFields.begin(); it < usedFields.end(); it++) {
 | 
|---|
| [72d108] | 395 |     const std::string keyName = it->substr(0, it->find("="));
 | 
|---|
 | 396 |     currentField = knownKeys[keyName];
 | 
|---|
 | 397 |     const string word = *tok_iter;
 | 
|---|
| [056e70] | 398 |     DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with remaining data " << word << std::endl);
 | 
|---|
| [4415da] | 399 |     switch (currentField) {
 | 
|---|
| [b8d4a3] | 400 |       case TremoloKey::x :
 | 
|---|
| [4415da] | 401 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [d74077] | 402 |         for (int i=0;i<NDIM;i++) {
 | 
|---|
| [72d108] | 403 |           ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for x["+toString(i)+"]!");
 | 
|---|
| [056e70] | 404 |           DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
 | 
|---|
| [72d108] | 405 |           newAtom->set(i, toDouble(*tok_iter));
 | 
|---|
 | 406 |           tok_iter++;
 | 
|---|
| [d74077] | 407 |         }
 | 
|---|
| [4415da] | 408 |         break;
 | 
|---|
| [b8d4a3] | 409 |       case TremoloKey::u :
 | 
|---|
| [4415da] | 410 |         // for the moment, assume there are always three dimensions
 | 
|---|
| [72d108] | 411 |         for (int i=0;i<NDIM;i++) {
 | 
|---|
 | 412 |           ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for u["+toString(i)+"]!");
 | 
|---|
| [056e70] | 413 |           DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
 | 
|---|
 | 414 |           tempVector[i] = toDouble(*tok_iter);
 | 
|---|
| [72d108] | 415 |           tok_iter++;
 | 
|---|
 | 416 |         }
 | 
|---|
| [056e70] | 417 |         newAtom->setAtomicVelocity(tempVector);
 | 
|---|
| [4415da] | 418 |         break;
 | 
|---|
| [305e7e] | 419 |       case TremoloKey::type :
 | 
|---|
| [4d4d33] | 420 |       {
 | 
|---|
| [72d108] | 421 |         ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
 | 
|---|
| [056e70] | 422 |         DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
 | 
|---|
| [4d4d33] | 423 |         std::string element(knownTypes[(*tok_iter)]);
 | 
|---|
 | 424 |         // put type name into container for later use
 | 
|---|
 | 425 |         atomInfo->set(currentField, *tok_iter);
 | 
|---|
| [056e70] | 426 |         DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing element " << (*tok_iter) << " as " << element << " according to KnownTypes." << std::endl);
 | 
|---|
| [72d108] | 427 |         tok_iter++;
 | 
|---|
| [4d4d33] | 428 |         newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
 | 
|---|
| [b8d4a3] | 429 |         ASSERT(newAtom->getType(), "Type was not set for this atom");
 | 
|---|
| [4415da] | 430 |         break;
 | 
|---|
| [4d4d33] | 431 |       }
 | 
|---|
| [b8d4a3] | 432 |       case TremoloKey::Id :
 | 
|---|
| [72d108] | 433 |         ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
 | 
|---|
| [056e70] | 434 |         DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
 | 
|---|
| [72d108] | 435 |         atomIdMap[toInt(*tok_iter)] = newAtom->getId();
 | 
|---|
 | 436 |         tok_iter++;
 | 
|---|
| [4415da] | 437 |         break;
 | 
|---|
| [b8d4a3] | 438 |       case TremoloKey::neighbors :
 | 
|---|
| [72d108] | 439 |         for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) {
 | 
|---|
 | 440 |           ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
 | 
|---|
| [056e70] | 441 |           DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
 | 
|---|
| [72d108] | 442 |           lineStream << *tok_iter << "\t";
 | 
|---|
 | 443 |           tok_iter++;
 | 
|---|
 | 444 |         }
 | 
|---|
| [b8d4a3] | 445 |         readNeighbors(&lineStream,
 | 
|---|
 | 446 |             atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
 | 
|---|
| [9131f3] | 447 |         break;
 | 
|---|
 | 448 |       default :
 | 
|---|
| [72d108] | 449 |         ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
 | 
|---|
| [056e70] | 450 |         DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
 | 
|---|
| [72d108] | 451 |         atomInfo->set(currentField, *tok_iter);
 | 
|---|
 | 452 |         tok_iter++;
 | 
|---|
| [9131f3] | 453 |         break;
 | 
|---|
 | 454 |     }
 | 
|---|
 | 455 |   }
 | 
|---|
| [72d108] | 456 |   if (newmol != NULL) {
 | 
|---|
 | 457 |     //DoLog(0) && (Log() << Verbose(0) << "New Atom: " << *newAtom << " with type " << newAtom->getType()->getName() << std::endl);
 | 
|---|
| [dc1d9e] | 458 |     newmol->AddAtom(newAtom);
 | 
|---|
| [72d108] | 459 |   }
 | 
|---|
| [6bc51d] | 460 | }
 | 
|---|
| [9131f3] | 461 | 
 | 
|---|
| [b8d4a3] | 462 | /**
 | 
|---|
 | 463 |  * Reads neighbor information for one atom from the input.
 | 
|---|
 | 464 |  *
 | 
|---|
| [0bbfa1] | 465 |  * \param line stream where to read the information from
 | 
|---|
 | 466 |  * \param numberOfNeighbors number of neighbors to read
 | 
|---|
 | 467 |  * \param atomid world id of the atom the information belongs to
 | 
|---|
| [b8d4a3] | 468 |  */
 | 
|---|
 | 469 | void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
 | 
|---|
 | 470 |   int neighborId = 0;
 | 
|---|
 | 471 |   for (int i = 0; i < numberOfNeighbors; i++) {
 | 
|---|
 | 472 |     *line >> neighborId;
 | 
|---|
 | 473 |     // 0 is used to fill empty neighbor positions in the tremolo file.
 | 
|---|
 | 474 |     if (neighborId > 0) {
 | 
|---|
| [056e70] | 475 |       DoLog(4) && (Log() << Verbose(4)
 | 
|---|
 | 476 |           << "Atom with global id " << atomId
 | 
|---|
 | 477 |           << " has neighbour with serial " << neighborId
 | 
|---|
 | 478 |           << std::endl);
 | 
|---|
| [b8d4a3] | 479 |       additionalAtomData[atomId].neighbors.push_back(neighborId);
 | 
|---|
 | 480 |     }
 | 
|---|
 | 481 |   }
 | 
|---|
 | 482 | }
 | 
|---|
| [9131f3] | 483 | 
 | 
|---|
 | 484 | /**
 | 
|---|
| [b8d4a3] | 485 |  * Checks whether the provided name is within the list of used fields.
 | 
|---|
| [9131f3] | 486 |  *
 | 
|---|
| [b8d4a3] | 487 |  * \param field name to check
 | 
|---|
 | 488 |  *
 | 
|---|
 | 489 |  * \return true if the field name is used
 | 
|---|
| [9131f3] | 490 |  */
 | 
|---|
| [b8d4a3] | 491 | bool TremoloParser::isUsedField(string fieldName) {
 | 
|---|
 | 492 |   bool fieldNameExists = false;
 | 
|---|
 | 493 |   for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
 | 
|---|
 | 494 |     if (usedField->substr(0, usedField->find("=")) == fieldName)
 | 
|---|
 | 495 |       fieldNameExists = true;
 | 
|---|
 | 496 |   }
 | 
|---|
| [9131f3] | 497 | 
 | 
|---|
| [b8d4a3] | 498 |   return fieldNameExists;
 | 
|---|
 | 499 | }
 | 
|---|
 | 500 | 
 | 
|---|
 | 501 | 
 | 
|---|
 | 502 | /**
 | 
|---|
 | 503 |  * Adds the collected neighbor information to the atoms in the world. The atoms
 | 
|---|
 | 504 |  * are found by their current ID and mapped to the corresponding atoms with the
 | 
|---|
 | 505 |  * Id found in the parsed file.
 | 
|---|
 | 506 |  */
 | 
|---|
 | 507 | void TremoloParser::processNeighborInformation() {
 | 
|---|
 | 508 |   if (!isUsedField("neighbors")) {
 | 
|---|
 | 509 |     return;
 | 
|---|
 | 510 |   }
 | 
|---|
 | 511 | 
 | 
|---|
 | 512 |   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
 | 
|---|
 | 513 |     currentInfo != additionalAtomData.end(); currentInfo++
 | 
|---|
 | 514 |   ) {
 | 
|---|
| [0bbfa1] | 515 |     if (!currentInfo->second.neighbors_processed) {
 | 
|---|
 | 516 |       for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
 | 
|---|
 | 517 |         neighbor != currentInfo->second.neighbors.end(); neighbor++
 | 
|---|
 | 518 |       ) {
 | 
|---|
| [72d108] | 519 | //        DoLog(1) && (Log() << Verbose(1) << "Creating bond between ("
 | 
|---|
| [0bbfa1] | 520 | //            << currentInfo->first
 | 
|---|
 | 521 | //            << ") and ("
 | 
|---|
| [72d108] | 522 | //            << atomIdMap[*neighbor] << "|" << *neighbor << ")" << std::endl);
 | 
|---|
| [0bbfa1] | 523 |         World::getInstance().getAtom(AtomById(currentInfo->first))
 | 
|---|
| [073a9e4] | 524 |             ->addBond(WorldTime::getTime(), World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
 | 
|---|
| [0bbfa1] | 525 |       }
 | 
|---|
 | 526 |       currentInfo->second.neighbors_processed = true;
 | 
|---|
| [9131f3] | 527 |     }
 | 
|---|
 | 528 |   }
 | 
|---|
| [6bc51d] | 529 | }
 | 
|---|
 | 530 | 
 | 
|---|
| [9131f3] | 531 | /**
 | 
|---|
| [b8d4a3] | 532 |  * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
 | 
|---|
 | 533 |  * IDs of the input string will be replaced; expected separating characters are
 | 
|---|
 | 534 |  * "-" and ",".
 | 
|---|
| [9131f3] | 535 |  *
 | 
|---|
| [b8d4a3] | 536 |  * \param string in which atom IDs should be adapted
 | 
|---|
 | 537 |  *
 | 
|---|
 | 538 |  * \return input string with modified atom IDs
 | 
|---|
| [9131f3] | 539 |  */
 | 
|---|
| [b8d4a3] | 540 | string TremoloParser::adaptIdDependentDataString(string data) {
 | 
|---|
 | 541 |   // there might be no IDs
 | 
|---|
 | 542 |   if (data == "-") {
 | 
|---|
 | 543 |     return "-";
 | 
|---|
 | 544 |   }
 | 
|---|
 | 545 | 
 | 
|---|
 | 546 |   char separator;
 | 
|---|
 | 547 |   int id;
 | 
|---|
 | 548 |   stringstream line, result;
 | 
|---|
 | 549 |   line << data;
 | 
|---|
 | 550 | 
 | 
|---|
 | 551 |   line >> id;
 | 
|---|
 | 552 |   result << atomIdMap[id];
 | 
|---|
 | 553 |   while (line.good()) {
 | 
|---|
 | 554 |     line >> separator >> id;
 | 
|---|
 | 555 |     result << separator << atomIdMap[id];
 | 
|---|
 | 556 |   }
 | 
|---|
 | 557 | 
 | 
|---|
 | 558 |   return result.str();
 | 
|---|
| [6bc51d] | 559 | }
 | 
|---|
| [b8d4a3] | 560 | 
 | 
|---|
 | 561 | /**
 | 
|---|
 | 562 |  * Corrects the atom IDs in each imprData entry to the corresponding world IDs
 | 
|---|
 | 563 |  * as they might differ from the originally read IDs.
 | 
|---|
 | 564 |  */
 | 
|---|
 | 565 | void TremoloParser::adaptImprData() {
 | 
|---|
 | 566 |   if (!isUsedField("imprData")) {
 | 
|---|
 | 567 |     return;
 | 
|---|
 | 568 |   }
 | 
|---|
 | 569 | 
 | 
|---|
 | 570 |   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
 | 
|---|
 | 571 |     currentInfo != additionalAtomData.end(); currentInfo++
 | 
|---|
 | 572 |   ) {
 | 
|---|
 | 573 |     currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData);
 | 
|---|
 | 574 |   }
 | 
|---|
| [6bc51d] | 575 | }
 | 
|---|
| [4415da] | 576 | 
 | 
|---|
| [b8d4a3] | 577 | /**
 | 
|---|
 | 578 |  * Corrects the atom IDs in each torsion entry to the corresponding world IDs
 | 
|---|
 | 579 |  * as they might differ from the originally read IDs.
 | 
|---|
 | 580 |  */
 | 
|---|
 | 581 | void TremoloParser::adaptTorsion() {
 | 
|---|
 | 582 |   if (!isUsedField("torsion")) {
 | 
|---|
 | 583 |     return;
 | 
|---|
 | 584 |   }
 | 
|---|
 | 585 | 
 | 
|---|
 | 586 |   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
 | 
|---|
 | 587 |     currentInfo != additionalAtomData.end(); currentInfo++
 | 
|---|
 | 588 |   ) {
 | 
|---|
 | 589 |     currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion);
 | 
|---|
 | 590 |   }
 | 
|---|
 | 591 | }
 | 
|---|
 | 592 | 
 | 
|---|
| [4d4d33] | 593 | /** Creates knownTypes as the identity, e.g. H -> H, He -> He, ... .
 | 
|---|
 | 594 |  *
 | 
|---|
 | 595 |  */
 | 
|---|
 | 596 | void TremoloParser::createKnownTypesByIdentity()
 | 
|---|
 | 597 | {
 | 
|---|
 | 598 |   // remove old mapping
 | 
|---|
 | 599 |   knownTypes.clear();
 | 
|---|
 | 600 |   // make knownTypes the identity mapping
 | 
|---|
 | 601 |   const periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
 | 602 |   for (periodentafel::const_iterator iter = periode->begin();
 | 
|---|
 | 603 |       iter != periode->end();
 | 
|---|
 | 604 |       ++iter) {
 | 
|---|
 | 605 |     knownTypes.insert( make_pair(iter->second->getSymbol(), iter->second->getSymbol()) );
 | 
|---|
 | 606 |   }
 | 
|---|
 | 607 | }
 | 
|---|
 | 608 | 
 | 
|---|
 | 609 | /** Parses a .potentials file and creates from it the knownTypes file.
 | 
|---|
 | 610 |  *
 | 
|---|
 | 611 |  * @param file input stream of .potentials file
 | 
|---|
 | 612 |  */
 | 
|---|
 | 613 | void TremoloParser::parseKnownTypes(std::istream &file)
 | 
|---|
 | 614 | {
 | 
|---|
 | 615 |   const periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
 | 616 |   // remove old mapping
 | 
|---|
 | 617 |   knownTypes.clear();
 | 
|---|
 | 618 | 
 | 
|---|
 | 619 |   DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
 | 
|---|
 | 620 | 
 | 
|---|
 | 621 |   // parse in file
 | 
|---|
 | 622 |   typedef boost::tokenizer<boost::char_separator<char> >
 | 
|---|
 | 623 |       tokenizer;
 | 
|---|
 | 624 |   boost::char_separator<char> tokensep(":\t ,;");
 | 
|---|
 | 625 |   boost::char_separator<char> equalitysep("\t =");
 | 
|---|
 | 626 |   std::string line;
 | 
|---|
 | 627 |   while (file.good()) {
 | 
|---|
 | 628 |     std::getline( file, line );
 | 
|---|
 | 629 |     DoLog(4) && (Log() << Verbose(4) << "INFO: full line of parameters is '" << line << "'" << std::endl);
 | 
|---|
 | 630 |     if (line.find("particle:") != string::npos) {
 | 
|---|
 | 631 |       DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle:'." << std::endl);
 | 
|---|
 | 632 |       tokenizer tokens(line, tokensep);
 | 
|---|
 | 633 |       ASSERT(tokens.begin() != tokens.end(),
 | 
|---|
 | 634 |           "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
 | 
|---|
 | 635 |       // look for particle_type
 | 
|---|
 | 636 |       std::string particle_type("NULL");
 | 
|---|
 | 637 |       std::string element_type("NULL");
 | 
|---|
 | 638 |       for (tokenizer::iterator tok_iter = tokens.begin();
 | 
|---|
 | 639 |           tok_iter != tokens.end();
 | 
|---|
 | 640 |           ++tok_iter) {
 | 
|---|
 | 641 |         if ((*tok_iter).find("particle_type") != string::npos) {
 | 
|---|
 | 642 |           DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle_type'." << std::endl);
 | 
|---|
 | 643 |           tokenizer token((*tok_iter), equalitysep);
 | 
|---|
 | 644 |           ASSERT(token.begin() != token.end(),
 | 
|---|
 | 645 |                     "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
 | 
|---|
 | 646 |           tokenizer::iterator particle_iter = token.begin();
 | 
|---|
 | 647 |           particle_iter++;
 | 
|---|
 | 648 |           particle_type = *particle_iter;
 | 
|---|
 | 649 |         }
 | 
|---|
 | 650 |         if ((*tok_iter).find("element_name") != string::npos) {
 | 
|---|
 | 651 |           DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'element_name'." << std::endl);
 | 
|---|
 | 652 |           tokenizer token((*tok_iter), equalitysep);
 | 
|---|
 | 653 |           ASSERT(token.begin() != token.end(),
 | 
|---|
 | 654 |                     "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
 | 
|---|
 | 655 |           tokenizer::iterator element_iter = token.begin();
 | 
|---|
 | 656 |           element_iter++;
 | 
|---|
 | 657 |           element_type = *element_iter;
 | 
|---|
 | 658 |         }
 | 
|---|
 | 659 |       }
 | 
|---|
 | 660 |       if ((particle_type != "NULL") && (element_type != "NULL")) {
 | 
|---|
 | 661 |         if (periode->FindElement(element_type) != NULL) {
 | 
|---|
 | 662 |           DoLog(1) && (Log() << Verbose(1) << "INFO: Added Type " << particle_type << " as reference to element " << element_type << "." << std::endl);
 | 
|---|
 | 663 |           knownTypes.insert( make_pair (particle_type, element_type) );
 | 
|---|
 | 664 |         } else {
 | 
|---|
 | 665 |           DoeLog(1) && (Log() << Verbose(1) << "INFO: Either Type " << particle_type << " or " << element_type << " could not be recognized." << std::endl);
 | 
|---|
 | 666 |         }
 | 
|---|
 | 667 |       } else {
 | 
|---|
 | 668 |         DoeLog(1) && (Log() << Verbose(1) << "INFO: Desired element " << element_type << " is not known." << std::endl);
 | 
|---|
 | 669 |       }
 | 
|---|
 | 670 |     }
 | 
|---|
 | 671 |   }
 | 
|---|
 | 672 | 
 | 
|---|
 | 673 | }
 | 
|---|