| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [5aaa43] | 5 | * Copyright (C)  2013 Frederik Heber. All rights reserved. | 
|---|
| [94d5ac6] | 6 | * | 
|---|
|  | 7 | * | 
|---|
|  | 8 | *   This file is part of MoleCuilder. | 
|---|
|  | 9 | * | 
|---|
|  | 10 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 11 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 12 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 13 | *    (at your option) any later version. | 
|---|
|  | 14 | * | 
|---|
|  | 15 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 16 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 17 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 18 | *    GNU General Public License for more details. | 
|---|
|  | 19 | * | 
|---|
|  | 20 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 21 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| [bcf653] | 22 | */ | 
|---|
|  | 23 |  | 
|---|
| [6bc51d] | 24 | /* | 
|---|
|  | 25 | * TremoloParser.cpp | 
|---|
|  | 26 | * | 
|---|
|  | 27 | *  Created on: Mar 2, 2010 | 
|---|
|  | 28 | *      Author: metzler | 
|---|
|  | 29 | */ | 
|---|
|  | 30 |  | 
|---|
| [bf3817] | 31 | // include config.h | 
|---|
|  | 32 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 33 | #include <config.h> | 
|---|
|  | 34 | #endif | 
|---|
|  | 35 |  | 
|---|
| [9eb71b3] | 36 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| [112b09] | 37 |  | 
|---|
| [ad011c] | 38 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 39 | #include "CodePatterns/Log.hpp" | 
|---|
| [4d4d33] | 40 | #include "CodePatterns/toString.hpp" | 
|---|
| [ad011c] | 41 | #include "CodePatterns/Verbose.hpp" | 
|---|
| [42127c] | 42 |  | 
|---|
| [9131f3] | 43 | #include "TremoloParser.hpp" | 
|---|
| [42127c] | 44 |  | 
|---|
| [6f0841] | 45 | #include "Atom/atom.hpp" | 
|---|
| [129204] | 46 | #include "Bond/bond.hpp" | 
|---|
| [ccb487] | 47 | #include "Box.hpp" | 
|---|
| [42127c] | 48 | #include "Descriptors/AtomIdDescriptor.hpp" | 
|---|
| [3bdb6d] | 49 | #include "Element/element.hpp" | 
|---|
|  | 50 | #include "Element/periodentafel.hpp" | 
|---|
| [ed8a68] | 51 | #include "Parser/Exceptions.hpp" | 
|---|
|  | 52 | #include "Potentials/Particles/ParticleRegistry.hpp" | 
|---|
| [ccb487] | 53 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| [740f9f] | 54 | #include "Potentials/Particles/ParticleRegistry.hpp" | 
|---|
| [42127c] | 55 | #include "molecule.hpp" | 
|---|
|  | 56 | #include "World.hpp" | 
|---|
|  | 57 | #include "WorldTime.hpp" | 
|---|
|  | 58 |  | 
|---|
| [9131f3] | 59 |  | 
|---|
| [9f8b01] | 60 | #include <algorithm> | 
|---|
| [05e2ed] | 61 | #include <boost/bind.hpp> | 
|---|
| [4795cd] | 62 | #include <boost/function.hpp> | 
|---|
| [ca331c] | 63 | #include <boost/lambda/lambda.hpp> | 
|---|
| [2034f3] | 64 | #include <boost/lexical_cast.hpp> | 
|---|
| [72d108] | 65 | #include <boost/tokenizer.hpp> | 
|---|
| [74a444] | 66 | #include <iostream> | 
|---|
|  | 67 | #include <iomanip> | 
|---|
| [8bf9c6] | 68 | #include <map> | 
|---|
|  | 69 | #include <sstream> | 
|---|
| [ca331c] | 70 | #include <string> | 
|---|
| [8bf9c6] | 71 | #include <vector> | 
|---|
| [9131f3] | 72 |  | 
|---|
| [5a667d] | 73 | #include <boost/assign/list_of.hpp> // for 'map_list_of()' | 
|---|
|  | 74 | #include <boost/assert.hpp> | 
|---|
|  | 75 |  | 
|---|
| [765f16] | 76 | // declare specialized static variables | 
|---|
|  | 77 | const std::string FormatParserTrait<tremolo>::name = "tremolo"; | 
|---|
|  | 78 | const std::string FormatParserTrait<tremolo>::suffix = "data"; | 
|---|
|  | 79 | const ParserTypes FormatParserTrait<tremolo>::type = tremolo; | 
|---|
|  | 80 |  | 
|---|
| [5a667d] | 81 | // static instances | 
|---|
|  | 82 | std::map<std::string, TremoloKey::atomDataKey> FormatParser<tremolo>::knownKeys = | 
|---|
|  | 83 | boost::assign::map_list_of("x",TremoloKey::x) | 
|---|
|  | 84 | ("u",TremoloKey::u) | 
|---|
|  | 85 | ("F",TremoloKey::F) | 
|---|
|  | 86 | ("stress",TremoloKey::stress) | 
|---|
|  | 87 | ("Id",TremoloKey::Id) | 
|---|
|  | 88 | ("neighbors",TremoloKey::neighbors) | 
|---|
|  | 89 | ("imprData",TremoloKey::imprData) | 
|---|
|  | 90 | ("GroupMeasureTypeNo",TremoloKey::GroupMeasureTypeNo) | 
|---|
|  | 91 | ("type",TremoloKey::type) | 
|---|
|  | 92 | ("extType",TremoloKey::extType) | 
|---|
|  | 93 | ("name",TremoloKey::name) | 
|---|
|  | 94 | ("resName",TremoloKey::resName) | 
|---|
|  | 95 | ("chainID",TremoloKey::chainID) | 
|---|
|  | 96 | ("resSeq",TremoloKey::resSeq) | 
|---|
|  | 97 | ("occupancy",TremoloKey::occupancy) | 
|---|
|  | 98 | ("tempFactor",TremoloKey::tempFactor) | 
|---|
|  | 99 | ("segID",TremoloKey::segID) | 
|---|
|  | 100 | ("Charge",TremoloKey::Charge) | 
|---|
|  | 101 | ("charge",TremoloKey::charge) | 
|---|
|  | 102 | ("GrpTypeNo",TremoloKey::GrpTypeNo) | 
|---|
|  | 103 | ("torsion",TremoloKey::torsion) | 
|---|
|  | 104 | (" ",TremoloKey::noKey); // with this we can detect invalid keys | 
|---|
|  | 105 |  | 
|---|
| [9131f3] | 106 | /** | 
|---|
|  | 107 | * Constructor. | 
|---|
|  | 108 | */ | 
|---|
| [765f16] | 109 | FormatParser< tremolo >::FormatParser()  : | 
|---|
| [05e2ed] | 110 | FormatParser_common(NULL), | 
|---|
|  | 111 | idglobalizer(boost::bind(&FormatParser< tremolo >::getGlobalId, this, _1)), | 
|---|
|  | 112 | idlocalizer(boost::bind(&FormatParser< tremolo >::getLocalId, this, _1)) | 
|---|
| [765f16] | 113 | { | 
|---|
| [4d4d33] | 114 | // invert knownKeys for debug output | 
|---|
|  | 115 | for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter) | 
|---|
|  | 116 | knownKeyNames.insert( make_pair( iter->second, iter->first) ); | 
|---|
|  | 117 |  | 
|---|
|  | 118 | additionalAtomData.clear(); | 
|---|
| [9131f3] | 119 | } | 
|---|
|  | 120 |  | 
|---|
| [5a667d] | 121 |  | 
|---|
| [9131f3] | 122 | /** | 
|---|
|  | 123 | * Destructor. | 
|---|
|  | 124 | */ | 
|---|
| [765f16] | 125 | FormatParser< tremolo >::~FormatParser() | 
|---|
|  | 126 | { | 
|---|
| [23fd43] | 127 | usedFields_save.clear(); | 
|---|
| [b8d4a3] | 128 | additionalAtomData.clear(); | 
|---|
|  | 129 | } | 
|---|
|  | 130 |  | 
|---|
|  | 131 | /** | 
|---|
|  | 132 | * Loads atoms from a tremolo-formatted file. | 
|---|
|  | 133 | * | 
|---|
|  | 134 | * \param tremolo file | 
|---|
|  | 135 | */ | 
|---|
| [765f16] | 136 | void FormatParser< tremolo >::load(istream* file) { | 
|---|
| [8bf9c6] | 137 | std::string line; | 
|---|
|  | 138 | std::string::size_type location; | 
|---|
| [b8d4a3] | 139 |  | 
|---|
| [c0e28c] | 140 | // reset the id maps | 
|---|
|  | 141 | resetIdAssociations(); | 
|---|
|  | 142 |  | 
|---|
| [dc1d9e] | 143 | molecule *newmol = World::getInstance().createMolecule(); | 
|---|
| [bd2390] | 144 | newmol->ActiveFlag = true; | 
|---|
| [220d2c] | 145 | usedFields_t usedFields_temp; | 
|---|
|  | 146 | size_t timestep = 0; | 
|---|
|  | 147 | atom *addedatom = NULL; | 
|---|
| [33af20] | 148 | std::list<atom *> addedatoms; | 
|---|
|  | 149 | std::list<atom *>::iterator atomiter = addedatoms.begin(); | 
|---|
| [b8d4a3] | 150 | while (file->good()) { | 
|---|
|  | 151 | std::getline(*file, line, '\n'); | 
|---|
| [23fd43] | 152 | // we only parse in the first ATOMDATA line | 
|---|
| [220d2c] | 153 | location = line.find("ATOMDATA", 0); | 
|---|
|  | 154 | if (location != string::npos) { | 
|---|
|  | 155 | parseAtomDataKeysLine(line, location + 8, usedFields_temp); | 
|---|
|  | 156 | if (usedFields_load.empty()) { | 
|---|
|  | 157 | // first ATOMDATA: use this line | 
|---|
|  | 158 | usedFields_load.insert(usedFields_load.end(), usedFields_temp.begin(), usedFields_temp.end()); | 
|---|
|  | 159 | LOG(3, "DEBUG: Local usedFields is: " << usedFields_load); | 
|---|
|  | 160 | } else { | 
|---|
|  | 161 | // following ATOMDATA: check against present | 
|---|
|  | 162 | LOG(3, "DEBUG: Parsed check usedFields is: " << usedFields_temp); | 
|---|
|  | 163 | if (usedFields_load != usedFields_temp) { | 
|---|
|  | 164 | ELOG(1, "File contains multiple time steps with differing ATOMDATA line, parsing only first time step."); | 
|---|
|  | 165 | break; | 
|---|
|  | 166 | } else { | 
|---|
|  | 167 | // update time step | 
|---|
|  | 168 | ++timestep; | 
|---|
|  | 169 | atomiter = addedatoms.begin(); | 
|---|
|  | 170 | } | 
|---|
|  | 171 | } | 
|---|
|  | 172 | usedFields_temp.clear(); | 
|---|
|  | 173 | } else { | 
|---|
|  | 174 | if (line.length() > 0 && line.at(0) != '#') { | 
|---|
|  | 175 | if (timestep != 0) { | 
|---|
|  | 176 | ASSERT( atomiter != addedatoms.end(), | 
|---|
|  | 177 | "FormatParser< tremolo >::load() - timesteps contains more atoms than first one."); | 
|---|
|  | 178 | addedatom = *atomiter++; | 
|---|
|  | 179 | } | 
|---|
|  | 180 | readAtomDataLine(line, newmol, timestep, addedatom); | 
|---|
|  | 181 | if (timestep == 0) | 
|---|
|  | 182 | addedatoms.push_back(addedatom); | 
|---|
| [b8d4a3] | 183 | } | 
|---|
|  | 184 | } | 
|---|
|  | 185 | } | 
|---|
| [220d2c] | 186 | ASSERT( addedatoms.size() == newmol->size(), | 
|---|
|  | 187 | "FormatParser< tremolo >::load() - number of atoms in mol and addedatoms differ."); | 
|---|
| [2e352f] | 188 |  | 
|---|
| [9f8b01] | 189 | // refresh atom::nr and atom::name | 
|---|
|  | 190 | std::vector<atomId_t> atoms(newmol->getAtomCount()); | 
|---|
|  | 191 | std::transform(newmol->begin(), newmol->end(), atoms.begin(), | 
|---|
|  | 192 | boost::bind(&atom::getId, _1)); | 
|---|
|  | 193 | processNeighborInformation(atoms); | 
|---|
| [05e2ed] | 194 | adaptImprData(atoms); | 
|---|
|  | 195 | adaptTorsion(atoms); | 
|---|
| [23fd43] | 196 |  | 
|---|
|  | 197 | // append usedFields to global usedFields, is made unique on save, clear after use | 
|---|
|  | 198 | usedFields_save.insert(usedFields_save.end(), usedFields_load.begin(), usedFields_load.end()); | 
|---|
|  | 199 | usedFields_load.clear(); | 
|---|
| [b8d4a3] | 200 | } | 
|---|
|  | 201 |  | 
|---|
|  | 202 | /** | 
|---|
| [73916f] | 203 | * Saves the \a atoms into as a tremolo file. | 
|---|
| [b8d4a3] | 204 | * | 
|---|
|  | 205 | * \param file where to save the state | 
|---|
| [73916f] | 206 | * \param atoms atoms to store | 
|---|
| [b8d4a3] | 207 | */ | 
|---|
| [fac58f] | 208 | void FormatParser< tremolo >::save( | 
|---|
|  | 209 | std::ostream* file, | 
|---|
|  | 210 | const std::vector<const atom *> &AtomList) { | 
|---|
| [830b3e] | 211 | LOG(2, "DEBUG: Saving changes to tremolo."); | 
|---|
| [e97a44] | 212 |  | 
|---|
| [23fd43] | 213 | // install default usedFields if empty so far | 
|---|
|  | 214 | if (usedFields_save.empty()) { | 
|---|
|  | 215 | // default behavior: use all possible keys on output | 
|---|
|  | 216 | for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); | 
|---|
|  | 217 | iter != knownKeys.end(); ++iter) | 
|---|
|  | 218 | if (iter->second != TremoloKey::noKey) // don't add noKey | 
|---|
|  | 219 | usedFields_save.push_back(iter->first); | 
|---|
|  | 220 | } | 
|---|
|  | 221 | // make present usedFields_save unique | 
|---|
|  | 222 | makeUsedFieldsUnique(usedFields_save); | 
|---|
| [a86cda] | 223 | LOG(1, "INFO: Global (with unique entries) usedFields_save is: " << usedFields_save); | 
|---|
| [23fd43] | 224 |  | 
|---|
|  | 225 | // distribute ids continuously | 
|---|
|  | 226 | distributeContinuousIds(AtomList); | 
|---|
|  | 227 |  | 
|---|
| [33af20] | 228 | std::pair<size_t, size_t> minmax_trajectories = | 
|---|
|  | 229 | getMinMaxTrajectories(AtomList); | 
|---|
|  | 230 | LOG(2, "INFO: There are " << minmax_trajectories.second << " steps to save."); | 
|---|
| [23fd43] | 231 |  | 
|---|
| [33af20] | 232 | for (size_t step = 0; (step < minmax_trajectories.second) || (step == 0); ++step) { | 
|---|
|  | 233 | // store atomdata | 
|---|
|  | 234 | save_AtomDataLine(file); | 
|---|
| [b8d4a3] | 235 |  | 
|---|
| [33af20] | 236 | // store box only on first step | 
|---|
|  | 237 | if (step == 0) | 
|---|
|  | 238 | save_BoxLine(file); | 
|---|
|  | 239 |  | 
|---|
|  | 240 | // store particles | 
|---|
|  | 241 | for (std::vector<const atom*>::const_iterator  atomIt = AtomList.begin(); | 
|---|
|  | 242 | atomIt != AtomList.end(); ++atomIt) | 
|---|
|  | 243 | saveLine(file, *atomIt, step); | 
|---|
|  | 244 | } | 
|---|
| [23fd43] | 245 | } | 
|---|
| [acd638] | 246 |  | 
|---|
| [5b0581] | 247 | struct usedFieldsWeakComparator | 
|---|
|  | 248 | { | 
|---|
|  | 249 | /** Special comparator regards "neighbors=4" and "neighbors=2" as equal | 
|---|
|  | 250 | * | 
|---|
|  | 251 | * \note This one is used for making usedFields unique, i.e. throwing out the "smaller" | 
|---|
|  | 252 | * neighbors. | 
|---|
|  | 253 | */ | 
|---|
|  | 254 | bool operator()(const std::string &a, const std::string &b) const | 
|---|
|  | 255 | { | 
|---|
|  | 256 | // only compare up to first equality sign | 
|---|
|  | 257 | return (a.substr(0, a.find_first_of('=')) == b.substr(0, b.find_first_of('='))); | 
|---|
|  | 258 | } | 
|---|
|  | 259 | }; | 
|---|
|  | 260 |  | 
|---|
|  | 261 | struct usedFieldsSpecialOrderer | 
|---|
|  | 262 | { | 
|---|
|  | 263 | /** Special string comparator that regards "neighbors=4" < "neighbors=2" as true and | 
|---|
|  | 264 | * the other way round as false. | 
|---|
|  | 265 | * | 
|---|
|  | 266 | * Here, we implement the operator "\a < \b" in a special way to allow the | 
|---|
|  | 267 | * above. | 
|---|
|  | 268 | * | 
|---|
|  | 269 | * \note This one is used for sorting usedFields in preparation for making it unique. | 
|---|
|  | 270 | */ | 
|---|
|  | 271 | bool operator()(const std::string &a, const std::string &b) const | 
|---|
|  | 272 | { | 
|---|
|  | 273 | // only compare up to first equality sign | 
|---|
|  | 274 | size_t a_equality = a.find_first_of('='); | 
|---|
|  | 275 | size_t b_equality = b.find_first_of('='); | 
|---|
|  | 276 | // if key before equality is not equal, return whether it is smaller or not | 
|---|
|  | 277 | if (a.substr(0, a_equality) != b.substr(0, b_equality)) { | 
|---|
|  | 278 | return a.substr(0, a_equality) < b.substr(0, b_equality); | 
|---|
|  | 279 | } else { // now we know that the key before equality is the same in either string | 
|---|
|  | 280 | // if one of them has no equality, the one with equality must go before | 
|---|
|  | 281 | if ((a_equality != std::string::npos) && (b_equality == std::string::npos)) | 
|---|
|  | 282 | return true; | 
|---|
|  | 283 | if ((a_equality == std::string::npos) && (b_equality != std::string::npos)) | 
|---|
|  | 284 | return false; | 
|---|
|  | 285 | // if both don't have equality (and the token before is equal), it is not "<" but "==" | 
|---|
|  | 286 | if ((a_equality == std::string::npos) && (b_equality == std::string::npos)) | 
|---|
|  | 287 | return false; | 
|---|
|  | 288 | // if now both have equality sign, the larger value after it, must come first | 
|---|
|  | 289 | return a.substr(a_equality, std::string::npos) > b.substr(b_equality, std::string::npos); | 
|---|
|  | 290 | } | 
|---|
|  | 291 | } | 
|---|
|  | 292 | }; | 
|---|
|  | 293 |  | 
|---|
| [23fd43] | 294 | /** Helper function to make \given fields unique while preserving the order of first appearance. | 
|---|
|  | 295 | * | 
|---|
|  | 296 | * As std::unique only removes element if equal to predecessor, a vector is only | 
|---|
|  | 297 | * made unique if sorted beforehand. But sorting would destroy order of first | 
|---|
|  | 298 | * appearance, hence we do the sorting on a temporary field and add the unique | 
|---|
|  | 299 | * elements in the order as in \a fields. | 
|---|
|  | 300 | * | 
|---|
|  | 301 | * @param fields usedFields to make unique while preserving order of appearance | 
|---|
|  | 302 | */ | 
|---|
| [27cfde] | 303 | void FormatParser< tremolo >::makeUsedFieldsUnique(usedFields_t &fields) const | 
|---|
| [23fd43] | 304 | { | 
|---|
|  | 305 | // std::unique only removes if predecessor is equal, not over whole range, hence do it manually | 
|---|
| [27cfde] | 306 | usedFields_t temp_fields(fields); | 
|---|
| [5b0581] | 307 | usedFieldsSpecialOrderer SpecialOrderer; | 
|---|
|  | 308 | usedFieldsWeakComparator WeakComparator; | 
|---|
|  | 309 | std::sort(temp_fields.begin(), temp_fields.end(), SpecialOrderer); | 
|---|
| [23fd43] | 310 | usedFields_t::iterator it = | 
|---|
| [5b0581] | 311 | std::unique(temp_fields.begin(), temp_fields.end(), WeakComparator); | 
|---|
| [23fd43] | 312 | temp_fields.erase(it, temp_fields.end()); | 
|---|
| [27cfde] | 313 | usedFields_t usedfields(fields); | 
|---|
|  | 314 | fields.clear(); | 
|---|
|  | 315 | fields.reserve(temp_fields.size()); | 
|---|
| [23fd43] | 316 | // now go through each usedFields entry, check if in temp_fields and remove there on first occurence | 
|---|
|  | 317 | for (usedFields_t::const_iterator iter = usedfields.begin(); | 
|---|
|  | 318 | iter != usedfields.end(); ++iter) { | 
|---|
|  | 319 | usedFields_t::iterator uniqueiter = | 
|---|
|  | 320 | std::find(temp_fields.begin(), temp_fields.end(), *iter); | 
|---|
|  | 321 | if (uniqueiter != temp_fields.end()) { | 
|---|
| [27cfde] | 322 | fields.push_back(*iter); | 
|---|
| [23fd43] | 323 | // add only once to ATOMDATA | 
|---|
|  | 324 | temp_fields.erase(uniqueiter); | 
|---|
|  | 325 | } | 
|---|
|  | 326 | } | 
|---|
|  | 327 | ASSERT( temp_fields.empty(), | 
|---|
|  | 328 | "FormatParser< tremolo >::save() - still unique entries left in temp_fields after unique?"); | 
|---|
|  | 329 | } | 
|---|
|  | 330 |  | 
|---|
|  | 331 |  | 
|---|
|  | 332 | /** Resets and distributes the indices continuously. | 
|---|
|  | 333 | * | 
|---|
|  | 334 | * \param atoms atoms to store | 
|---|
|  | 335 | */ | 
|---|
| [fac58f] | 336 | void FormatParser< tremolo >::distributeContinuousIds( | 
|---|
|  | 337 | const std::vector<const atom *> &AtomList) | 
|---|
| [23fd43] | 338 | { | 
|---|
| [812155] | 339 | resetIdAssociations(); | 
|---|
|  | 340 | atomId_t lastid = 0; | 
|---|
| [fac58f] | 341 | for (std::vector<const atom*>::const_iterator atomIt = AtomList.begin(); | 
|---|
| [23fd43] | 342 | atomIt != AtomList.end(); ++atomIt) | 
|---|
| [812155] | 343 | associateLocaltoGlobalId(++lastid, (*atomIt)->getId()); | 
|---|
| [23fd43] | 344 | } | 
|---|
| [812155] | 345 |  | 
|---|
| [23fd43] | 346 | /** Store Atomdata line to \a file. | 
|---|
|  | 347 | * | 
|---|
|  | 348 | * @param file output stream | 
|---|
|  | 349 | */ | 
|---|
|  | 350 | void FormatParser< tremolo >::save_AtomDataLine(std::ostream* file) const | 
|---|
|  | 351 | { | 
|---|
| [b8d4a3] | 352 | *file << "# ATOMDATA"; | 
|---|
| [23fd43] | 353 | for (usedFields_t::const_iterator it=usedFields_save.begin(); | 
|---|
|  | 354 | it != usedFields_save.end(); ++it) | 
|---|
| [b8d4a3] | 355 | *file << "\t" << *it; | 
|---|
| [23fd43] | 356 | *file << std::endl; | 
|---|
|  | 357 | } | 
|---|
| [ccb487] | 358 |  | 
|---|
| [23fd43] | 359 | /** Store Box info to \a file | 
|---|
|  | 360 | * | 
|---|
|  | 361 | * @param file output stream | 
|---|
|  | 362 | */ | 
|---|
|  | 363 | void FormatParser< tremolo >::save_BoxLine(std::ostream* file) const | 
|---|
|  | 364 | { | 
|---|
| [ccb487] | 365 | *file << "# Box"; | 
|---|
|  | 366 | const RealSpaceMatrix &M = World::getInstance().getDomain().getM(); | 
|---|
|  | 367 | for (size_t i=0; i<NDIM;++i) | 
|---|
|  | 368 | for (size_t j=0; j<NDIM;++j) | 
|---|
|  | 369 | *file << "\t" << M.at(i,j); | 
|---|
|  | 370 | *file << std::endl; | 
|---|
| [b8d4a3] | 371 | } | 
|---|
|  | 372 |  | 
|---|
| [6bc86c] | 373 | /** Add default info, when new atom is added to World. | 
|---|
|  | 374 | * | 
|---|
|  | 375 | * @param id of atom | 
|---|
|  | 376 | */ | 
|---|
| [765f16] | 377 | void FormatParser< tremolo >::AtomInserted(atomId_t id) | 
|---|
| [6bc86c] | 378 | { | 
|---|
| [8bf9c6] | 379 | std::map<const atomId_t, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id); | 
|---|
| [6bc86c] | 380 | ASSERT(iter == additionalAtomData.end(), | 
|---|
| [765f16] | 381 | "FormatParser< tremolo >::AtomInserted() - additionalAtomData already present for newly added atom " | 
|---|
| [6bc86c] | 382 | +toString(id)+"."); | 
|---|
|  | 383 | // don't add entry, as this gives a default resSeq of 0 not the molecule id | 
|---|
|  | 384 | // additionalAtomData.insert( std::make_pair(id, TremoloAtomInfoContainer()) ); | 
|---|
|  | 385 | } | 
|---|
|  | 386 |  | 
|---|
|  | 387 | /** Remove additional AtomData info, when atom has been removed from World. | 
|---|
|  | 388 | * | 
|---|
|  | 389 | * @param id of atom | 
|---|
|  | 390 | */ | 
|---|
| [765f16] | 391 | void FormatParser< tremolo >::AtomRemoved(atomId_t id) | 
|---|
| [6bc86c] | 392 | { | 
|---|
| [8bf9c6] | 393 | std::map<const atomId_t, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id); | 
|---|
| [6bc86c] | 394 | // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence | 
|---|
|  | 395 | //  ASSERT(iter != additionalAtomData.end(), | 
|---|
| [765f16] | 396 | //      "FormatParser< tremolo >::AtomRemoved() - additionalAtomData is not present for atom " | 
|---|
| [6bc86c] | 397 | //      +toString(id)+" to remove."); | 
|---|
|  | 398 | if (iter != additionalAtomData.end()) | 
|---|
|  | 399 | additionalAtomData.erase(iter); | 
|---|
|  | 400 | } | 
|---|
|  | 401 |  | 
|---|
| [4795cd] | 402 | template <class T> | 
|---|
|  | 403 | T NoOp(const atom * const) | 
|---|
|  | 404 | { | 
|---|
|  | 405 | return T(); | 
|---|
|  | 406 | } | 
|---|
|  | 407 |  | 
|---|
|  | 408 | template <class T> | 
|---|
|  | 409 | void writeEntryFromAdditionalAtomData_ifpresent( | 
|---|
|  | 410 | std::map<const atomId_t, TremoloAtomInfoContainer> &_additionalAtomData, | 
|---|
|  | 411 | std::map<TremoloKey::atomDataKey, std::string> &_knownKeyNames, | 
|---|
|  | 412 | std::ostream* _file, | 
|---|
|  | 413 | const atom * const _currentAtom, | 
|---|
|  | 414 | const TremoloKey::atomDataKey _currentField, | 
|---|
|  | 415 | const typename boost::function<T (const atom * const)> _getter) | 
|---|
|  | 416 | { | 
|---|
|  | 417 | if (_additionalAtomData.count(_currentAtom->getId())) { | 
|---|
|  | 418 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << ": " | 
|---|
|  | 419 | << _additionalAtomData[_currentAtom->getId()].get(_currentField)); | 
|---|
|  | 420 | *_file << _additionalAtomData[_currentAtom->getId()].get(_currentField); | 
|---|
|  | 421 | } else if (_additionalAtomData.count(_currentAtom->GetTrueFather()->getId())) { | 
|---|
|  | 422 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " stuff from father: " | 
|---|
|  | 423 | << _additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField)); | 
|---|
|  | 424 | *_file << _additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField); | 
|---|
|  | 425 | } else { | 
|---|
|  | 426 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " its default value: " | 
|---|
|  | 427 | << _getter(_currentAtom)); | 
|---|
|  | 428 | *_file << _getter(_currentAtom); | 
|---|
|  | 429 | } | 
|---|
|  | 430 | *_file << "\t"; | 
|---|
|  | 431 | } | 
|---|
|  | 432 |  | 
|---|
|  | 433 | template <class T> | 
|---|
|  | 434 | void writeAdditionalAtomDataEntry( | 
|---|
|  | 435 | std::map<const atomId_t, TremoloAtomInfoContainer> &_additionalAtomData, | 
|---|
|  | 436 | std::map<TremoloKey::atomDataKey, std::string> &_knownKeyNames, | 
|---|
|  | 437 | TremoloAtomInfoContainer &_defaultAdditionalData, | 
|---|
|  | 438 | std::ostream* _file, | 
|---|
|  | 439 | const atom * const _currentAtom, | 
|---|
|  | 440 | const TremoloKey::atomDataKey _currentField) | 
|---|
|  | 441 | { | 
|---|
|  | 442 | if (_additionalAtomData.count(_currentAtom->getId())) { | 
|---|
|  | 443 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << ": " | 
|---|
|  | 444 | << _additionalAtomData[_currentAtom->getId()].get(_currentField)); | 
|---|
|  | 445 | *_file << _additionalAtomData[_currentAtom->getId()].get(_currentField); | 
|---|
|  | 446 | } else if (_additionalAtomData.count(_currentAtom->GetTrueFather()->getId())) { | 
|---|
|  | 447 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " stuff from father: " | 
|---|
|  | 448 | << _additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField)); | 
|---|
|  | 449 | *_file << _additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField); | 
|---|
|  | 450 | } else { | 
|---|
|  | 451 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " its default value: " | 
|---|
|  | 452 | << _defaultAdditionalData.get(_currentField)); | 
|---|
|  | 453 | *_file << _defaultAdditionalData.get(_currentField); | 
|---|
|  | 454 | } | 
|---|
|  | 455 | *_file << "\t"; | 
|---|
|  | 456 | } | 
|---|
|  | 457 |  | 
|---|
|  | 458 | template <class T> | 
|---|
|  | 459 | void writeEntryFromAdditionalAtomData_ifnotempty( | 
|---|
|  | 460 | std::map<const atomId_t, TremoloAtomInfoContainer> &_additionalAtomData, | 
|---|
|  | 461 | std::map<TremoloKey::atomDataKey, std::string> &_knownKeyNames, | 
|---|
|  | 462 | TremoloAtomInfoContainer &_defaultAdditionalData, | 
|---|
|  | 463 | std::ostream* _file, | 
|---|
|  | 464 | const atom * const _currentAtom, | 
|---|
|  | 465 | const TremoloKey::atomDataKey _currentField, | 
|---|
|  | 466 | const typename boost::function<T (const atom * const)> _getter) | 
|---|
|  | 467 | { | 
|---|
|  | 468 | if (_additionalAtomData.count(_currentAtom->getId())) { | 
|---|
|  | 469 | if (_additionalAtomData[_currentAtom->getId()].get(_currentField) != "-") { | 
|---|
|  | 470 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << ": " | 
|---|
|  | 471 | << _additionalAtomData[_currentAtom->getId()].get(_currentField)); | 
|---|
|  | 472 | *_file << _additionalAtomData[_currentAtom->getId()].get(_currentField); | 
|---|
|  | 473 | } else { | 
|---|
|  | 474 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " default value: " | 
|---|
|  | 475 | << _getter(_currentAtom)); | 
|---|
|  | 476 | *_file << _getter(_currentAtom); | 
|---|
|  | 477 | } | 
|---|
|  | 478 | } else if (_additionalAtomData.count(_currentAtom->GetTrueFather()->getId())) { | 
|---|
|  | 479 | if (_additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField) != "-") { | 
|---|
|  | 480 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " stuff from father: " | 
|---|
|  | 481 | << _additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField)); | 
|---|
|  | 482 | *_file << _additionalAtomData[_currentAtom->GetTrueFather()->getId()].get(_currentField); | 
|---|
|  | 483 | } else { | 
|---|
|  | 484 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " default value from father: " | 
|---|
|  | 485 | << _getter(_currentAtom->GetTrueFather())); | 
|---|
|  | 486 | *_file << _getter(_currentAtom->GetTrueFather()); | 
|---|
|  | 487 | } | 
|---|
|  | 488 | } else { | 
|---|
|  | 489 | LOG(3, "Writing for type " << _knownKeyNames[_currentField] << " its default value: " | 
|---|
|  | 490 | << _getter(_currentAtom)); | 
|---|
|  | 491 | *_file << _getter(_currentAtom); | 
|---|
|  | 492 | } | 
|---|
|  | 493 | *_file << "\t"; | 
|---|
|  | 494 | } | 
|---|
|  | 495 |  | 
|---|
| [b8d4a3] | 496 | /** | 
|---|
|  | 497 | * Writes one line of tremolo-formatted data to the provided stream. | 
|---|
|  | 498 | * | 
|---|
|  | 499 | * \param stream where to write the line to | 
|---|
|  | 500 | * \param reference to the atom of which information should be written | 
|---|
|  | 501 | */ | 
|---|
| [fac58f] | 502 | void FormatParser< tremolo >::saveLine( | 
|---|
|  | 503 | std::ostream* file, | 
|---|
| [33af20] | 504 | const atom * const currentAtom, | 
|---|
|  | 505 | const size_t _timestep) | 
|---|
| [23fd43] | 506 | { | 
|---|
| [b8d4a3] | 507 | TremoloKey::atomDataKey currentField; | 
|---|
|  | 508 |  | 
|---|
| [33af20] | 509 | LOG(4, "INFO: Saving atom " << *currentAtom << ", its father id is " | 
|---|
|  | 510 | << currentAtom->GetTrueFather()->getId() << " at time step " << _timestep); | 
|---|
| [4d4d33] | 511 |  | 
|---|
| [fba720] | 512 | // note down default precision | 
|---|
|  | 513 | std::streamsize defaultprecision=file->precision(); | 
|---|
|  | 514 | std::streamsize highprecision=10; | 
|---|
|  | 515 |  | 
|---|
| [23fd43] | 516 | for (usedFields_t::iterator it = usedFields_save.begin(); it != usedFields_save.end(); it++) { | 
|---|
| [b8d4a3] | 517 | currentField = knownKeys[it->substr(0, it->find("="))]; | 
|---|
|  | 518 | switch (currentField) { | 
|---|
|  | 519 | case TremoloKey::x : | 
|---|
|  | 520 | // for the moment, assume there are always three dimensions | 
|---|
| [33af20] | 521 | LOG(3, "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getPositionAtStep(_timestep)); | 
|---|
| [fba720] | 522 | file->precision(highprecision); | 
|---|
| [33af20] | 523 | *file << currentAtom->atStep(0, _timestep) << "\t"; | 
|---|
|  | 524 | *file << currentAtom->atStep(1, _timestep) << "\t"; | 
|---|
|  | 525 | *file << currentAtom->atStep(2, _timestep) << "\t"; | 
|---|
| [fba720] | 526 | file->precision(defaultprecision); | 
|---|
| [b8d4a3] | 527 | break; | 
|---|
|  | 528 | case TremoloKey::u : | 
|---|
|  | 529 | // for the moment, assume there are always three dimensions | 
|---|
| [33af20] | 530 | LOG(3, "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getAtomicVelocityAtStep(_timestep)); | 
|---|
| [fba720] | 531 | file->precision(highprecision); | 
|---|
| [33af20] | 532 | *file << currentAtom->getAtomicVelocityAtStep(_timestep)[0] << "\t"; | 
|---|
|  | 533 | *file << currentAtom->getAtomicVelocityAtStep(_timestep)[1] << "\t"; | 
|---|
|  | 534 | *file << currentAtom->getAtomicVelocityAtStep(_timestep)[2] << "\t"; | 
|---|
| [fba720] | 535 | file->precision(defaultprecision); | 
|---|
| [b8d4a3] | 536 | break; | 
|---|
| [e6e4a0] | 537 | case TremoloKey::F : | 
|---|
|  | 538 | // for the moment, assume there are always three dimensions | 
|---|
| [33af20] | 539 | LOG(3, "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getAtomicForceAtStep(_timestep)); | 
|---|
| [fba720] | 540 | file->precision(highprecision); | 
|---|
| [33af20] | 541 | *file << currentAtom->getAtomicForceAtStep(_timestep)[0] << "\t"; | 
|---|
|  | 542 | *file << currentAtom->getAtomicForceAtStep(_timestep)[1] << "\t"; | 
|---|
|  | 543 | *file << currentAtom->getAtomicForceAtStep(_timestep)[2] << "\t"; | 
|---|
| [fba720] | 544 | file->precision(defaultprecision); | 
|---|
| [e6e4a0] | 545 | break; | 
|---|
| [305e7e] | 546 | case TremoloKey::type : | 
|---|
| [4795cd] | 547 | writeEntryFromAdditionalAtomData_ifnotempty<std::string>( | 
|---|
|  | 548 | additionalAtomData, | 
|---|
|  | 549 | knownKeyNames, | 
|---|
|  | 550 | defaultAdditionalData, | 
|---|
|  | 551 | file, | 
|---|
|  | 552 | currentAtom, | 
|---|
|  | 553 | currentField, | 
|---|
|  | 554 | boost::bind(&element::getSymbol, boost::bind(&AtomInfo::getType, _1))); | 
|---|
| [b8d4a3] | 555 | break; | 
|---|
|  | 556 | case TremoloKey::Id : | 
|---|
| [47d041] | 557 | LOG(3, "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getId()+1); | 
|---|
| [812155] | 558 | *file << getLocalId(currentAtom->getId()) << "\t"; | 
|---|
| [b8d4a3] | 559 | break; | 
|---|
|  | 560 | case TremoloKey::neighbors : | 
|---|
| [47d041] | 561 | LOG(3, "Writing type " << knownKeyNames[currentField]); | 
|---|
| [b8d4a3] | 562 | writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom); | 
|---|
|  | 563 | break; | 
|---|
| [05e2ed] | 564 | case TremoloKey::imprData : | 
|---|
|  | 565 | case TremoloKey::torsion : | 
|---|
|  | 566 | LOG(3, "Writing type " << knownKeyNames[currentField]); | 
|---|
|  | 567 | *file << adaptIdDependentDataString( | 
|---|
|  | 568 | additionalAtomData[currentAtom->getId()].get(currentField), | 
|---|
|  | 569 | idlocalizer) | 
|---|
|  | 570 | << "\t"; | 
|---|
|  | 571 | break; | 
|---|
| [74a444] | 572 | case TremoloKey::resSeq : | 
|---|
| [4d4d33] | 573 | if (additionalAtomData.count(currentAtom->getId())) { | 
|---|
| [47d041] | 574 | LOG(3, "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField)); | 
|---|
| [74a444] | 575 | *file << additionalAtomData[currentAtom->getId()].get(currentField); | 
|---|
|  | 576 | } else if (currentAtom->getMolecule() != NULL) { | 
|---|
| [47d041] | 577 | LOG(3, "Writing for type " << knownKeyNames[currentField] << " its own id: " << currentAtom->getMolecule()->getId()+1); | 
|---|
| [67ab71] | 578 | *file << setw(4) << currentAtom->getMolecule()->getId(); | 
|---|
| [74a444] | 579 | } else { | 
|---|
| [47d041] | 580 | LOG(3, "Writing for type " << knownKeyNames[currentField] << " default value: " << defaultAdditionalData.get(currentField)); | 
|---|
| [74a444] | 581 | *file << defaultAdditionalData.get(currentField); | 
|---|
|  | 582 | } | 
|---|
|  | 583 | *file << "\t"; | 
|---|
| [4d4d33] | 584 | break; | 
|---|
| [2034f3] | 585 | case TremoloKey::charge : | 
|---|
|  | 586 | if (currentAtom->getCharge() == 0.) { | 
|---|
| [4795cd] | 587 | writeEntryFromAdditionalAtomData_ifpresent<double>( | 
|---|
|  | 588 | additionalAtomData, | 
|---|
|  | 589 | knownKeyNames, | 
|---|
|  | 590 | file, | 
|---|
|  | 591 | currentAtom, | 
|---|
|  | 592 | currentField, | 
|---|
|  | 593 | boost::bind(&AtomInfo::getCharge, _1)); | 
|---|
| [2034f3] | 594 | } else { | 
|---|
|  | 595 | LOG(3, "Writing for type " << knownKeyNames[currentField] << " AtomInfo::charge : " << currentAtom->getCharge()); | 
|---|
| [4795cd] | 596 | *file << currentAtom->getCharge() << "\t"; | 
|---|
| [2034f3] | 597 | } | 
|---|
|  | 598 | break; | 
|---|
| [b8d4a3] | 599 | default : | 
|---|
| [4795cd] | 600 | writeAdditionalAtomDataEntry<std::string>( | 
|---|
|  | 601 | additionalAtomData, | 
|---|
|  | 602 | knownKeyNames, | 
|---|
|  | 603 | defaultAdditionalData, | 
|---|
|  | 604 | file, | 
|---|
|  | 605 | currentAtom, | 
|---|
|  | 606 | currentField); | 
|---|
| [b8d4a3] | 607 | break; | 
|---|
|  | 608 | } | 
|---|
|  | 609 | } | 
|---|
|  | 610 |  | 
|---|
| [23fd43] | 611 | *file << std::endl; | 
|---|
| [b8d4a3] | 612 | } | 
|---|
|  | 613 |  | 
|---|
|  | 614 | /** | 
|---|
|  | 615 | * Writes the neighbor information of one atom to the provided stream. | 
|---|
|  | 616 | * | 
|---|
| [9d83b6] | 617 | * Note that ListOfBonds of WorldTime::CurrentTime is used. | 
|---|
|  | 618 | * | 
|---|
| [b8d4a3] | 619 | * \param stream where to write neighbor information to | 
|---|
|  | 620 | * \param number of neighbors | 
|---|
|  | 621 | * \param reference to the atom of which to take the neighbor information | 
|---|
|  | 622 | */ | 
|---|
| [fac58f] | 623 | void FormatParser< tremolo >::writeNeighbors( | 
|---|
|  | 624 | std::ostream* file, | 
|---|
|  | 625 | const int numberOfNeighbors, | 
|---|
|  | 626 | const atom * const currentAtom) { | 
|---|
| [9d83b6] | 627 | const BondList& ListOfBonds = currentAtom->getListOfBonds(); | 
|---|
| [ca2cfa] | 628 | // sort bonded indices | 
|---|
|  | 629 | typedef std::set<atomId_t> sortedIndices; | 
|---|
|  | 630 | sortedIndices sortedBonds; | 
|---|
|  | 631 | for (BondList::const_iterator iter = ListOfBonds.begin(); | 
|---|
|  | 632 | iter != ListOfBonds.end(); ++iter) | 
|---|
| [812155] | 633 | sortedBonds.insert(getLocalId((*iter)->GetOtherAtom(currentAtom)->getId())); | 
|---|
| [ca2cfa] | 634 | // print indices | 
|---|
|  | 635 | sortedIndices::const_iterator currentBond = sortedBonds.begin(); | 
|---|
| [b8d4a3] | 636 | for (int i = 0; i < numberOfNeighbors; i++) { | 
|---|
| [812155] | 637 | *file << (currentBond != sortedBonds.end() ? (*currentBond) : 0) << "\t"; | 
|---|
| [ca2cfa] | 638 | if (currentBond != sortedBonds.end()) | 
|---|
| [0bbfa1] | 639 | ++currentBond; | 
|---|
| [b8d4a3] | 640 | } | 
|---|
| [9131f3] | 641 | } | 
|---|
|  | 642 |  | 
|---|
|  | 643 | /** | 
|---|
| [23fd43] | 644 | * Stores keys from the ATOMDATA line in \a fields. | 
|---|
| [9131f3] | 645 | * | 
|---|
|  | 646 | * \param line to parse the keys from | 
|---|
| [23fd43] | 647 | * \param offset with which offset the keys begin within the line | 
|---|
|  | 648 | * \param fields which usedFields to use | 
|---|
| [9131f3] | 649 | */ | 
|---|
| [23fd43] | 650 | void FormatParser< tremolo >::parseAtomDataKeysLine( | 
|---|
|  | 651 | const std::string &line, | 
|---|
|  | 652 | const int offset, | 
|---|
|  | 653 | usedFields_t &fields) { | 
|---|
| [8bf9c6] | 654 | std::string keyword; | 
|---|
|  | 655 | std::stringstream lineStream; | 
|---|
| [9131f3] | 656 |  | 
|---|
|  | 657 | lineStream << line.substr(offset); | 
|---|
| [a86cda] | 658 | lineStream >> ws; | 
|---|
| [9131f3] | 659 | while (lineStream.good()) { | 
|---|
|  | 660 | lineStream >> keyword; | 
|---|
| [b8d4a3] | 661 | if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) { | 
|---|
| [ecb799] | 662 | // TODO: throw exception about unknown key | 
|---|
| [5a667d] | 663 | cout << "Unknown key: " << keyword.substr(0, keyword.find("=")) << " is not part of the tremolo format specification." << endl; | 
|---|
|  | 664 | throw IllegalParserKeyException(); | 
|---|
| [4415da] | 665 | break; | 
|---|
|  | 666 | } | 
|---|
| [23fd43] | 667 | fields.push_back(keyword); | 
|---|
| [a86cda] | 668 | lineStream >> ws; | 
|---|
| [9131f3] | 669 | } | 
|---|
| [a86cda] | 670 | LOG(2, "INFO: " << fields); | 
|---|
| [9131f3] | 671 | } | 
|---|
|  | 672 |  | 
|---|
| [5a667d] | 673 | /** | 
|---|
|  | 674 | * Tests whether the keys from the ATOMDATA line can be read correctly. | 
|---|
|  | 675 | * | 
|---|
|  | 676 | * \param line to parse the keys from | 
|---|
|  | 677 | */ | 
|---|
|  | 678 | bool FormatParser< tremolo >::testParseAtomDataKeysLine( | 
|---|
|  | 679 | const std::string &line) { | 
|---|
|  | 680 | std::string keyword; | 
|---|
|  | 681 | std::stringstream lineStream; | 
|---|
|  | 682 |  | 
|---|
|  | 683 | // check string after ATOMDATA | 
|---|
|  | 684 | const std::string AtomData("ATOMDATA"); | 
|---|
|  | 685 | const size_t AtomDataOffset = line.find(AtomData, 0); | 
|---|
|  | 686 | if (AtomDataOffset == std::string::npos) | 
|---|
|  | 687 | lineStream << line; | 
|---|
|  | 688 | else | 
|---|
|  | 689 | lineStream << line.substr(AtomDataOffset + AtomData.length()); | 
|---|
|  | 690 | while (lineStream.good()) { | 
|---|
|  | 691 | lineStream >> keyword; | 
|---|
|  | 692 | //LOG(2, "DEBUG: Checking key " << keyword.substr(0, keyword.find("=")) << "."); | 
|---|
|  | 693 | if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) | 
|---|
|  | 694 | return false; | 
|---|
|  | 695 | } | 
|---|
|  | 696 | //LOG(1, "INFO: " << fields); | 
|---|
|  | 697 | return true; | 
|---|
|  | 698 | } | 
|---|
|  | 699 |  | 
|---|
| [ca331c] | 700 | std::string FormatParser< tremolo >::getAtomData() const | 
|---|
|  | 701 | { | 
|---|
|  | 702 | std::stringstream output; | 
|---|
|  | 703 | std::for_each(usedFields_save.begin(), usedFields_save.end(), | 
|---|
|  | 704 | output << boost::lambda::_1 << " "); | 
|---|
|  | 705 | const std::string returnstring(output.str()); | 
|---|
|  | 706 | return returnstring.substr(0, returnstring.find_last_of(" ")); | 
|---|
|  | 707 | } | 
|---|
|  | 708 |  | 
|---|
|  | 709 | /** Appends the properties per atom to print to .data file by parsing line from | 
|---|
|  | 710 | *  \a atomdata_string. | 
|---|
|  | 711 | * | 
|---|
|  | 712 | *  We just call \sa  FormatParser< tremolo >::parseAtomDataKeysLine(). | 
|---|
|  | 713 | * | 
|---|
|  | 714 | * @param atomdata_string line to parse with space-separated values | 
|---|
|  | 715 | */ | 
|---|
|  | 716 | void FormatParser< tremolo >::setAtomData(const std::string &atomdata_string) | 
|---|
|  | 717 | { | 
|---|
|  | 718 | parseAtomDataKeysLine(atomdata_string, 0, usedFields_save); | 
|---|
|  | 719 | } | 
|---|
|  | 720 |  | 
|---|
| [81c980b] | 721 | /** Sets the properties per atom to print to .data file by parsing line from | 
|---|
|  | 722 | *  \a atomdata_string. | 
|---|
|  | 723 | * | 
|---|
| [23fd43] | 724 | *  We just call \sa  FormatParser< tremolo >::parseAtomDataKeysLine(), however | 
|---|
|  | 725 | *  we clear FormatParser< tremolo >::usedFields_save. | 
|---|
| [81c980b] | 726 | * | 
|---|
|  | 727 | * @param atomdata_string line to parse with space-separated values | 
|---|
|  | 728 | */ | 
|---|
| [ca331c] | 729 | void FormatParser< tremolo >::resetAtomData(const std::string &atomdata_string) | 
|---|
| [81c980b] | 730 | { | 
|---|
| [23fd43] | 731 | usedFields_save.clear(); | 
|---|
|  | 732 | parseAtomDataKeysLine(atomdata_string, 0, usedFields_save); | 
|---|
| [81c980b] | 733 | } | 
|---|
|  | 734 |  | 
|---|
|  | 735 |  | 
|---|
| [9131f3] | 736 | /** | 
|---|
|  | 737 | * Reads one data line of a tremolo file and interprets it according to the keys | 
|---|
|  | 738 | * obtained from the ATOMDATA line. | 
|---|
|  | 739 | * | 
|---|
|  | 740 | * \param line to parse as an atom | 
|---|
| [dc1d9e] | 741 | * \param *newmol molecule to add atom to | 
|---|
| [220d2c] | 742 | * \param _timestep time step to parse to | 
|---|
|  | 743 | * \param _addedatom ref to added atom | 
|---|
| [9131f3] | 744 | */ | 
|---|
| [220d2c] | 745 | void FormatParser< tremolo >::readAtomDataLine( | 
|---|
|  | 746 | const std::string &line, | 
|---|
|  | 747 | molecule *newmol, | 
|---|
|  | 748 | const size_t _timestep, | 
|---|
|  | 749 | atom *&_addedatoms) | 
|---|
|  | 750 | { | 
|---|
| [8bf9c6] | 751 | std::stringstream lineStream; | 
|---|
| [220d2c] | 752 | atom* newAtom = NULL; | 
|---|
|  | 753 | atomId_t atomid = -1; | 
|---|
|  | 754 | if (_timestep == 0) { | 
|---|
|  | 755 | newAtom = World::getInstance().createAtom(); | 
|---|
|  | 756 | _addedatoms = newAtom; | 
|---|
|  | 757 | atomid = newAtom->getId(); | 
|---|
|  | 758 | additionalAtomData[atomid] = TremoloAtomInfoContainer(); // fill with default values | 
|---|
|  | 759 | } else { | 
|---|
|  | 760 | newAtom = _addedatoms; | 
|---|
|  | 761 | atomid = newAtom->getId(); | 
|---|
|  | 762 | } | 
|---|
| [89a31d] | 763 | TremoloAtomInfoContainer *atomInfo = &additionalAtomData[atomid]; | 
|---|
| [b8d4a3] | 764 | TremoloKey::atomDataKey currentField; | 
|---|
| [72d108] | 765 | ConvertTo<double> toDouble; | 
|---|
|  | 766 | ConvertTo<int> toInt; | 
|---|
| [056e70] | 767 | Vector tempVector; | 
|---|
| [740f9f] | 768 | const ParticleRegistry& registry = ParticleRegistry::getConstInstance(); | 
|---|
|  | 769 | const periodentafel& periode = *World::getInstance().getPeriode(); | 
|---|
| [72d108] | 770 |  | 
|---|
|  | 771 | // setup tokenizer, splitting up white-spaced entries | 
|---|
|  | 772 | typedef boost::tokenizer<boost::char_separator<char> > | 
|---|
|  | 773 | tokenizer; | 
|---|
|  | 774 | boost::char_separator<char> whitespacesep(" \t"); | 
|---|
|  | 775 | tokenizer tokens(line, whitespacesep); | 
|---|
|  | 776 | ASSERT(tokens.begin() != tokens.end(), | 
|---|
| [765f16] | 777 | "FormatParser< tremolo >::readAtomDataLine - empty string, need at least ' '!"); | 
|---|
| [fc41df] | 778 | tokenizer::const_iterator tok_iter = tokens.begin(); | 
|---|
| [72d108] | 779 | // then associate each token to each file | 
|---|
| [fc41df] | 780 | for (usedFields_t::const_iterator it = usedFields_load.begin(); it != usedFields_load.end(); it++) { | 
|---|
| [72d108] | 781 | const std::string keyName = it->substr(0, it->find("=")); | 
|---|
|  | 782 | currentField = knownKeys[keyName]; | 
|---|
| [fc41df] | 783 | ASSERT(tok_iter != tokens.end(), | 
|---|
|  | 784 | "FormatParser< tremolo >::readAtomDataLine - too few entries in line '"+line+"'!"); | 
|---|
|  | 785 | const std::string &word = *tok_iter; | 
|---|
| [47d041] | 786 | LOG(4, "INFO: Parsing key " << keyName << " with remaining data " << word); | 
|---|
| [4415da] | 787 | switch (currentField) { | 
|---|
| [b8d4a3] | 788 | case TremoloKey::x : | 
|---|
| [4415da] | 789 | // for the moment, assume there are always three dimensions | 
|---|
| [d74077] | 790 | for (int i=0;i<NDIM;i++) { | 
|---|
| [765f16] | 791 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for x["+toString(i)+"]!"); | 
|---|
| [220d2c] | 792 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
|  | 793 | newAtom->setAtStep(i, _timestep, toDouble(word)); | 
|---|
| [72d108] | 794 | tok_iter++; | 
|---|
| [d74077] | 795 | } | 
|---|
| [4415da] | 796 | break; | 
|---|
| [b8d4a3] | 797 | case TremoloKey::u : | 
|---|
| [4415da] | 798 | // for the moment, assume there are always three dimensions | 
|---|
| [72d108] | 799 | for (int i=0;i<NDIM;i++) { | 
|---|
| [765f16] | 800 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for u["+toString(i)+"]!"); | 
|---|
| [220d2c] | 801 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
| [fc41df] | 802 | tempVector[i] = toDouble(word); | 
|---|
| [72d108] | 803 | tok_iter++; | 
|---|
|  | 804 | } | 
|---|
| [220d2c] | 805 | newAtom->setAtomicVelocityAtStep(_timestep, tempVector); | 
|---|
| [4415da] | 806 | break; | 
|---|
| [e6e4a0] | 807 | case TremoloKey::F : | 
|---|
|  | 808 | // for the moment, assume there are always three dimensions | 
|---|
|  | 809 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 810 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for F["+toString(i)+"]!"); | 
|---|
| [220d2c] | 811 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
| [fc41df] | 812 | tempVector[i] = toDouble(word); | 
|---|
| [e6e4a0] | 813 | tok_iter++; | 
|---|
|  | 814 | } | 
|---|
| [220d2c] | 815 | newAtom->setAtomicForceAtStep(_timestep, tempVector); | 
|---|
| [e6e4a0] | 816 | break; | 
|---|
| [305e7e] | 817 | case TremoloKey::type : | 
|---|
| [4d4d33] | 818 | { | 
|---|
| [765f16] | 819 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); | 
|---|
| [220d2c] | 820 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
| [740f9f] | 821 | std::string elementname; | 
|---|
|  | 822 | const element * elem = NULL; | 
|---|
|  | 823 | if (!registry.isPresentByName(word)) { | 
|---|
|  | 824 | std::string lowercase_word(word); | 
|---|
|  | 825 | std::transform(word.begin()+1, word.end(), lowercase_word.begin()+1, ::tolower); | 
|---|
|  | 826 | elem = periode.FindElement(lowercase_word); | 
|---|
|  | 827 | if (elem == NULL) { | 
|---|
|  | 828 | // clean up | 
|---|
|  | 829 | World::getInstance().destroyAtom(newAtom); | 
|---|
|  | 830 | // give an error | 
|---|
|  | 831 | ELOG(0, "TremoloParser: tokens " << word << "/" << lowercase_word | 
|---|
|  | 832 | << " is unknown to neither ParticleRegistry nor Periodentafel."); | 
|---|
|  | 833 | return; | 
|---|
|  | 834 | } else { | 
|---|
|  | 835 | elementname = elem->getSymbol(); | 
|---|
|  | 836 | } | 
|---|
|  | 837 | } else { | 
|---|
|  | 838 | const Particle * const p = registry.getByName(word); | 
|---|
|  | 839 | elementname = p->getElement(); | 
|---|
|  | 840 | elem = periode.FindElement(elementname); | 
|---|
| [a275b3] | 841 | } | 
|---|
| [4d4d33] | 842 | // put type name into container for later use | 
|---|
| [fc41df] | 843 | atomInfo->set(currentField, word); | 
|---|
| [740f9f] | 844 | LOG(4, "INFO: Parsing element " << (word) << " as " << elementname << " according to KnownTypes."); | 
|---|
| [72d108] | 845 | tok_iter++; | 
|---|
| [740f9f] | 846 | newAtom->setType(elem); | 
|---|
| [b8d4a3] | 847 | ASSERT(newAtom->getType(), "Type was not set for this atom"); | 
|---|
| [4415da] | 848 | break; | 
|---|
| [4d4d33] | 849 | } | 
|---|
| [b8d4a3] | 850 | case TremoloKey::Id : | 
|---|
| [765f16] | 851 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); | 
|---|
| [220d2c] | 852 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
|  | 853 | if (_timestep == 0) { | 
|---|
|  | 854 | associateLocaltoGlobalId(toInt(word), atomid); | 
|---|
|  | 855 | } else { | 
|---|
|  | 856 | // check association is the same | 
|---|
|  | 857 | ASSERT( (atomId_t)getGlobalId(toInt(word)) == atomid, | 
|---|
|  | 858 | "FormatParser< tremolo >::readAtomDataLine() - differing global id "+toString(atomid) | 
|---|
|  | 859 | +" on timestep "+toString(_timestep)); | 
|---|
|  | 860 | ASSERT( getLocalId(atomid) == toInt(word), | 
|---|
|  | 861 | "FormatParser< tremolo >::readAtomDataLine() - differing local id "+toString(toInt(word)) | 
|---|
|  | 862 | +" on timestep "+toString(_timestep)); | 
|---|
|  | 863 | } | 
|---|
| [72d108] | 864 | tok_iter++; | 
|---|
| [4415da] | 865 | break; | 
|---|
| [b8d4a3] | 866 | case TremoloKey::neighbors : | 
|---|
| [72d108] | 867 | for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) { | 
|---|
| [220d2c] | 868 | ASSERT(tok_iter != tokens.end(), | 
|---|
|  | 869 | "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); | 
|---|
|  | 870 | if (_timestep == 0) | 
|---|
|  | 871 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
| [fc41df] | 872 | lineStream << word << "\t"; | 
|---|
| [72d108] | 873 | tok_iter++; | 
|---|
|  | 874 | } | 
|---|
| [220d2c] | 875 | if (_timestep == 0) { | 
|---|
|  | 876 | readNeighbors(&lineStream, | 
|---|
|  | 877 | atoi(it->substr(it->find("=") + 1, 1).c_str()), atomid); | 
|---|
|  | 878 | } | 
|---|
| [9131f3] | 879 | break; | 
|---|
| [2034f3] | 880 | case TremoloKey::charge : | 
|---|
|  | 881 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); | 
|---|
| [220d2c] | 882 | if (_timestep == 0) { | 
|---|
|  | 883 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
|  | 884 | atomInfo->set(currentField, word); | 
|---|
|  | 885 | newAtom->setCharge(boost::lexical_cast<double>(word)); | 
|---|
|  | 886 | } | 
|---|
| [2034f3] | 887 | tok_iter++; | 
|---|
|  | 888 | break; | 
|---|
| [9131f3] | 889 | default : | 
|---|
| [765f16] | 890 | ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); | 
|---|
| [220d2c] | 891 | if (_timestep == 0) { | 
|---|
|  | 892 | LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); | 
|---|
|  | 893 | atomInfo->set(currentField, word); | 
|---|
|  | 894 | } | 
|---|
| [72d108] | 895 | tok_iter++; | 
|---|
| [9131f3] | 896 | break; | 
|---|
|  | 897 | } | 
|---|
|  | 898 | } | 
|---|
| [89a31d] | 899 | LOG(3, "INFO: Parsed atom " << atomid << "."); | 
|---|
|  | 900 | if (newmol != NULL) | 
|---|
| [dc1d9e] | 901 | newmol->AddAtom(newAtom); | 
|---|
| [6bc51d] | 902 | } | 
|---|
| [9131f3] | 903 |  | 
|---|
| [99db9b] | 904 | bool FormatParser< tremolo >::saveAtomsInExttypes( | 
|---|
|  | 905 | std::ostream &output, | 
|---|
|  | 906 | const std::vector<const atom*> &atoms, | 
|---|
|  | 907 | const int id) const | 
|---|
| [531f27] | 908 | { | 
|---|
|  | 909 | bool status = true; | 
|---|
|  | 910 | // parse the file | 
|---|
| [99db9b] | 911 | for (std::vector<const atom *>::const_iterator iter = atoms.begin(); | 
|---|
| [531f27] | 912 | iter != atoms.end(); ++iter) { | 
|---|
|  | 913 | const int atomicid = getLocalId((*iter)->getId()); | 
|---|
|  | 914 | if (atomicid == -1) | 
|---|
|  | 915 | status = false; | 
|---|
|  | 916 | output << atomicid << "\t" << id << std::endl; | 
|---|
|  | 917 | } | 
|---|
|  | 918 |  | 
|---|
|  | 919 | return status; | 
|---|
|  | 920 | } | 
|---|
|  | 921 |  | 
|---|
| [b8d4a3] | 922 | /** | 
|---|
|  | 923 | * Reads neighbor information for one atom from the input. | 
|---|
|  | 924 | * | 
|---|
| [0bbfa1] | 925 | * \param line stream where to read the information from | 
|---|
|  | 926 | * \param numberOfNeighbors number of neighbors to read | 
|---|
|  | 927 | * \param atomid world id of the atom the information belongs to | 
|---|
| [b8d4a3] | 928 | */ | 
|---|
| [fac58f] | 929 | void FormatParser< tremolo >::readNeighbors( | 
|---|
|  | 930 | std::stringstream* line, | 
|---|
|  | 931 | const int numberOfNeighbors, | 
|---|
|  | 932 | const int atomId) { | 
|---|
| [b8d4a3] | 933 | int neighborId = 0; | 
|---|
|  | 934 | for (int i = 0; i < numberOfNeighbors; i++) { | 
|---|
|  | 935 | *line >> neighborId; | 
|---|
|  | 936 | // 0 is used to fill empty neighbor positions in the tremolo file. | 
|---|
|  | 937 | if (neighborId > 0) { | 
|---|
| [47d041] | 938 | LOG(4, "INFO: Atom with global id " << atomId | 
|---|
|  | 939 | << " has neighbour with serial " << neighborId); | 
|---|
| [b8d4a3] | 940 | additionalAtomData[atomId].neighbors.push_back(neighborId); | 
|---|
|  | 941 | } | 
|---|
|  | 942 | } | 
|---|
|  | 943 | } | 
|---|
| [9131f3] | 944 |  | 
|---|
|  | 945 | /** | 
|---|
| [23fd43] | 946 | * Checks whether the provided name is within \a fields. | 
|---|
| [b8d4a3] | 947 | * | 
|---|
| [23fd43] | 948 | * \param fields which usedFields to use | 
|---|
|  | 949 | * \param fieldName name to check | 
|---|
| [b8d4a3] | 950 | * \return true if the field name is used | 
|---|
| [9131f3] | 951 | */ | 
|---|
| [fac58f] | 952 | bool FormatParser< tremolo >::isUsedField( | 
|---|
|  | 953 | const usedFields_t &fields, | 
|---|
|  | 954 | const std::string &fieldName) const | 
|---|
| [23fd43] | 955 | { | 
|---|
| [b8d4a3] | 956 | bool fieldNameExists = false; | 
|---|
| [23fd43] | 957 | for (usedFields_t::const_iterator usedField = fields.begin(); | 
|---|
|  | 958 | usedField != fields.end(); usedField++) { | 
|---|
| [b8d4a3] | 959 | if (usedField->substr(0, usedField->find("=")) == fieldName) | 
|---|
|  | 960 | fieldNameExists = true; | 
|---|
|  | 961 | } | 
|---|
| [9131f3] | 962 |  | 
|---|
| [b8d4a3] | 963 | return fieldNameExists; | 
|---|
|  | 964 | } | 
|---|
|  | 965 |  | 
|---|
|  | 966 |  | 
|---|
|  | 967 | /** | 
|---|
|  | 968 | * Adds the collected neighbor information to the atoms in the world. The atoms | 
|---|
|  | 969 | * are found by their current ID and mapped to the corresponding atoms with the | 
|---|
|  | 970 | * Id found in the parsed file. | 
|---|
| [9f8b01] | 971 | * | 
|---|
|  | 972 | * @param atoms vector with all newly added (global) atomic ids | 
|---|
| [b8d4a3] | 973 | */ | 
|---|
| [fac58f] | 974 | void FormatParser< tremolo >::processNeighborInformation( | 
|---|
|  | 975 | const std::vector<atomId_t> &atoms) { | 
|---|
| [23fd43] | 976 | if (!isUsedField(usedFields_load, "neighbors")) { | 
|---|
| [b8d4a3] | 977 | return; | 
|---|
|  | 978 | } | 
|---|
|  | 979 |  | 
|---|
| [9f8b01] | 980 | for (std::vector<atomId_t>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { | 
|---|
|  | 981 | ASSERT(additionalAtomData.count(*iter) != 0, | 
|---|
|  | 982 | "FormatParser< tremolo >::processNeighborInformation() - global id " | 
|---|
|  | 983 | +toString(*iter)+" unknown in additionalAtomData."); | 
|---|
|  | 984 | TremoloAtomInfoContainer ¤tInfo = additionalAtomData[*iter]; | 
|---|
|  | 985 | ASSERT (!currentInfo.neighbors_processed, | 
|---|
|  | 986 | "FormatParser< tremolo >::processNeighborInformation() - neighbors of new atom " | 
|---|
|  | 987 | +toString(*iter)+" are already processed."); | 
|---|
|  | 988 | for(std::vector<int>::const_iterator neighbor = currentInfo.neighbors.begin(); | 
|---|
|  | 989 | neighbor != currentInfo.neighbors.end(); neighbor++ | 
|---|
|  | 990 | ) { | 
|---|
|  | 991 | LOG(3, "INFO: Creating bond between (" | 
|---|
|  | 992 | << *iter | 
|---|
|  | 993 | << ") and (" | 
|---|
|  | 994 | << getGlobalId(*neighbor) << "|" << *neighbor << ")"); | 
|---|
|  | 995 | ASSERT(getGlobalId(*neighbor) != -1, | 
|---|
|  | 996 | "FormatParser< tremolo >::processNeighborInformation() - global id to local id " | 
|---|
|  | 997 | +toString(*neighbor)+" is unknown."); | 
|---|
|  | 998 | World::getInstance().getAtom(AtomById(*iter)) | 
|---|
|  | 999 | ->addBond(WorldTime::getTime(), World::getInstance().getAtom(AtomById(getGlobalId(*neighbor)))); | 
|---|
| [9131f3] | 1000 | } | 
|---|
| [9f8b01] | 1001 | currentInfo.neighbors_processed = true; | 
|---|
| [9131f3] | 1002 | } | 
|---|
| [6bc51d] | 1003 | } | 
|---|
|  | 1004 |  | 
|---|
| [9131f3] | 1005 | /** | 
|---|
| [b8d4a3] | 1006 | * Replaces atom IDs read from the file by the corresponding world IDs. All IDs | 
|---|
|  | 1007 | * IDs of the input string will be replaced; expected separating characters are | 
|---|
|  | 1008 | * "-" and ",". | 
|---|
| [9131f3] | 1009 | * | 
|---|
| [b8d4a3] | 1010 | * \param string in which atom IDs should be adapted | 
|---|
| [05e2ed] | 1011 | * \param idgetter function pointer to change the id | 
|---|
| [b8d4a3] | 1012 | * | 
|---|
|  | 1013 | * \return input string with modified atom IDs | 
|---|
| [9131f3] | 1014 | */ | 
|---|
| [05e2ed] | 1015 | std::string FormatParser< tremolo >::adaptIdDependentDataString( | 
|---|
|  | 1016 | const std::string &data, | 
|---|
|  | 1017 | const boost::function<int (const int)> &idgetter | 
|---|
|  | 1018 | ) { | 
|---|
| [b8d4a3] | 1019 | // there might be no IDs | 
|---|
|  | 1020 | if (data == "-") { | 
|---|
|  | 1021 | return "-"; | 
|---|
|  | 1022 | } | 
|---|
|  | 1023 |  | 
|---|
|  | 1024 | char separator; | 
|---|
|  | 1025 | int id; | 
|---|
| [8bf9c6] | 1026 | std::stringstream line, result; | 
|---|
| [b8d4a3] | 1027 | line << data; | 
|---|
|  | 1028 |  | 
|---|
|  | 1029 | line >> id; | 
|---|
| [05e2ed] | 1030 | result << idgetter(id); | 
|---|
| [b8d4a3] | 1031 | while (line.good()) { | 
|---|
|  | 1032 | line >> separator >> id; | 
|---|
| [05e2ed] | 1033 | result << separator << idgetter(id); | 
|---|
| [b8d4a3] | 1034 | } | 
|---|
|  | 1035 |  | 
|---|
|  | 1036 | return result.str(); | 
|---|
| [6bc51d] | 1037 | } | 
|---|
| [b8d4a3] | 1038 |  | 
|---|
| [05e2ed] | 1039 | /** Corrects the atom IDs in each imprData entry to the corresponding world IDs | 
|---|
| [b8d4a3] | 1040 | * as they might differ from the originally read IDs. | 
|---|
| [05e2ed] | 1041 | * | 
|---|
|  | 1042 | * \param atoms currently parsed in atoms | 
|---|
| [b8d4a3] | 1043 | */ | 
|---|
| [05e2ed] | 1044 | void FormatParser< tremolo >::adaptImprData(const std::vector<atomId_t> &atoms) { | 
|---|
| [23fd43] | 1045 | if (!isUsedField(usedFields_load, "imprData")) { | 
|---|
| [b8d4a3] | 1046 | return; | 
|---|
|  | 1047 | } | 
|---|
|  | 1048 |  | 
|---|
| [05e2ed] | 1049 | for (std::vector<atomId_t>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { | 
|---|
|  | 1050 | ASSERT(additionalAtomData.count(*iter) != 0, | 
|---|
|  | 1051 | "FormatParser< tremolo >::processNeighborInformation() - global id " | 
|---|
|  | 1052 | +toString(*iter)+" unknown in additionalAtomData."); | 
|---|
|  | 1053 | TremoloAtomInfoContainer ¤tInfo = additionalAtomData[*iter]; | 
|---|
|  | 1054 | currentInfo.imprData = adaptIdDependentDataString(currentInfo.imprData, idglobalizer); | 
|---|
| [b8d4a3] | 1055 | } | 
|---|
| [6bc51d] | 1056 | } | 
|---|
| [4415da] | 1057 |  | 
|---|
| [05e2ed] | 1058 | /** Corrects the atom IDs in each torsion entry to the corresponding world IDs | 
|---|
| [b8d4a3] | 1059 | * as they might differ from the originally read IDs. | 
|---|
| [05e2ed] | 1060 | * | 
|---|
|  | 1061 | * \param atoms currently parsed in atoms | 
|---|
| [b8d4a3] | 1062 | */ | 
|---|
| [05e2ed] | 1063 | void FormatParser< tremolo >::adaptTorsion(const std::vector<atomId_t> &atoms) { | 
|---|
| [23fd43] | 1064 | if (!isUsedField(usedFields_load, "torsion")) { | 
|---|
| [b8d4a3] | 1065 | return; | 
|---|
|  | 1066 | } | 
|---|
|  | 1067 |  | 
|---|
| [05e2ed] | 1068 | for (std::vector<atomId_t>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { | 
|---|
|  | 1069 | ASSERT(additionalAtomData.count(*iter) != 0, | 
|---|
|  | 1070 | "FormatParser< tremolo >::processNeighborInformation() - global id " | 
|---|
|  | 1071 | +toString(*iter)+" unknown in additionalAtomData."); | 
|---|
|  | 1072 | TremoloAtomInfoContainer ¤tInfo = additionalAtomData[*iter]; | 
|---|
|  | 1073 | currentInfo.torsion = adaptIdDependentDataString(currentInfo.torsion, idglobalizer); | 
|---|
| [b8d4a3] | 1074 | } | 
|---|
|  | 1075 | } | 
|---|
|  | 1076 |  | 
|---|