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