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