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