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