source: src/Parser/TremoloParser.cpp@ 54b42e

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 54b42e was bce72c, checked in by Frederik Heber <heber@…>, 14 years ago

AtomicInfo::AtomicVelocity and ::AtomicForce are now private.

  • Access is granted via getters and setters.
  • Property mode set to 100644
File size: 23.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * TremoloParser.cpp
10 *
11 * Created on: Mar 2, 2010
12 * Author: metzler
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "CodePatterns/Assert.hpp"
23#include "CodePatterns/Log.hpp"
24#include "CodePatterns/toString.hpp"
25#include "CodePatterns/Verbose.hpp"
26#include "TremoloParser.hpp"
27#include "World.hpp"
28#include "atom.hpp"
29#include "bond.hpp"
30#include "element.hpp"
31#include "molecule.hpp"
32#include "periodentafel.hpp"
33#include "Descriptors/AtomIdDescriptor.hpp"
34#include <map>
35#include <vector>
36
37#include <boost/tokenizer.hpp>
38#include <iostream>
39#include <iomanip>
40
41using namespace std;
42
43/**
44 * Constructor.
45 */
46TremoloParser::TremoloParser() {
47 knownKeys["x"] = TremoloKey::x;
48 knownKeys["u"] = TremoloKey::u;
49 knownKeys["F"] = TremoloKey::F;
50 knownKeys["stress"] = TremoloKey::stress;
51 knownKeys["Id"] = TremoloKey::Id;
52 knownKeys["neighbors"] = TremoloKey::neighbors;
53 knownKeys["imprData"] = TremoloKey::imprData;
54 knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo;
55 knownKeys["Type"] = TremoloKey::Type;
56 knownKeys["extType"] = TremoloKey::extType;
57 knownKeys["name"] = TremoloKey::name;
58 knownKeys["resName"] = TremoloKey::resName;
59 knownKeys["chainID"] = TremoloKey::chainID;
60 knownKeys["resSeq"] = TremoloKey::resSeq;
61 knownKeys["occupancy"] = TremoloKey::occupancy;
62 knownKeys["tempFactor"] = TremoloKey::tempFactor;
63 knownKeys["segID"] = TremoloKey::segID;
64 knownKeys["Charge"] = TremoloKey::Charge;
65 knownKeys["charge"] = TremoloKey::charge;
66 knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo;
67 knownKeys["torsion"] = TremoloKey::torsion;
68
69 createKnownTypesByIdentity();
70
71 // default behavior: use all possible keys on output
72 for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter)
73 usedFields.push_back(iter->first);
74
75 // and noKey afterwards(!) such that it is not used in usedFields
76 knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys
77
78 // invert knownKeys for debug output
79 for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter)
80 knownKeyNames.insert( make_pair( iter->second, iter->first) );
81
82 additionalAtomData.clear();
83}
84
85/**
86 * Destructor.
87 */
88TremoloParser::~TremoloParser() {
89 usedFields.clear();
90 additionalAtomData.clear();
91 atomIdMap.clear();
92 knownKeys.clear();
93}
94
95/**
96 * Loads atoms from a tremolo-formatted file.
97 *
98 * \param tremolo file
99 */
100void TremoloParser::load(istream* file) {
101 string line;
102 string::size_type location;
103
104 // reset atomIdMap, for we now get new serials
105 atomIdMap.clear();
106 usedFields.clear();
107
108 molecule *newmol = World::getInstance().createMolecule();
109 newmol->ActiveFlag = true;
110 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
111 World::getInstance().getMolecules()->insert(newmol);
112 while (file->good()) {
113 std::getline(*file, line, '\n');
114 if (usedFields.empty()) {
115 location = line.find("ATOMDATA", 0);
116 if (location != string::npos) {
117 parseAtomDataKeysLine(line, location + 8);
118 }
119 }
120 if (line.length() > 0 && line.at(0) != '#') {
121 readAtomDataLine(line, newmol);
122 }
123 }
124
125 processNeighborInformation();
126 adaptImprData();
127 adaptTorsion();
128}
129
130/**
131 * Saves the \a atoms into as a tremolo file.
132 *
133 * \param file where to save the state
134 * \param atoms atoms to store
135 */
136void TremoloParser::save(ostream* file, const std::vector<atom *> &AtomList) {
137 DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
138
139 vector<atom*>::const_iterator atomIt;
140 vector<string>::iterator it;
141
142 DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
143
144 *file << "# ATOMDATA";
145 for (it=usedFields.begin(); it < usedFields.end(); it++) {
146 *file << "\t" << *it;
147 }
148 *file << endl;
149 for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
150 saveLine(file, *atomIt);
151 }
152}
153
154/**
155 * Sets the keys for which data should be written to the stream when save is
156 * called.
157 *
158 * \param string of field names with the same syntax as for an ATOMDATA line
159 * but without the prexix "ATOMDATA"
160 */
161void TremoloParser::setFieldsForSave(std::string atomDataLine) {
162 parseAtomDataKeysLine(atomDataLine, 0);
163}
164
165
166/**
167 * Writes one line of tremolo-formatted data to the provided stream.
168 *
169 * \param stream where to write the line to
170 * \param reference to the atom of which information should be written
171 */
172void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
173 vector<string>::iterator it;
174 TremoloKey::atomDataKey currentField;
175
176 DoLog(4) && (Log() << Verbose(4) << "INFO: Saving atom " << *currentAtom << ", its father id is " << currentAtom->GetTrueFather()->getId() << std::endl);
177
178 for (it = usedFields.begin(); it != usedFields.end(); it++) {
179 currentField = knownKeys[it->substr(0, it->find("="))];
180 switch (currentField) {
181 case TremoloKey::x :
182 // for the moment, assume there are always three dimensions
183 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getPosition() << std::endl);
184 *file << currentAtom->at(0) << "\t";
185 *file << currentAtom->at(1) << "\t";
186 *file << currentAtom->at(2) << "\t";
187 break;
188 case TremoloKey::u :
189 // for the moment, assume there are always three dimensions
190 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getAtomicVelocity() << std::endl);
191 *file << currentAtom->getAtomicVelocity()[0] << "\t";
192 *file << currentAtom->getAtomicVelocity()[1] << "\t";
193 *file << currentAtom->getAtomicVelocity()[2] << "\t";
194 break;
195 case TremoloKey::Type :
196 if (additionalAtomData.count(currentAtom->getId())) {
197 if (additionalAtomData[currentAtom->getId()].get(currentField) != "-") {
198 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
199 *file << additionalAtomData[currentAtom->getId()].get(currentField) << "\t";
200 } else {
201 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << currentAtom->getType()->getSymbol() << std::endl);
202 *file << currentAtom->getType()->getSymbol() << "\t";
203 }
204 } else if (additionalAtomData.count(currentAtom->GetTrueFather()->getId())) {
205 if (additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) != "-") {
206 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " stuff from father: " << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << std::endl);
207 *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << "\t";
208 } else {
209 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value from father: " << currentAtom->GetTrueFather()->getType()->getSymbol() << std::endl);
210 *file << currentAtom->GetTrueFather()->getType()->getSymbol() << "\t";
211 }
212 } else {
213 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " its default value: " << currentAtom->getType()->getSymbol() << std::endl);
214 *file << currentAtom->getType()->getSymbol() << "\t";
215 }
216 break;
217 case TremoloKey::Id :
218 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getId()+1 << std::endl);
219 *file << currentAtom->getId()+1 << "\t";
220 break;
221 case TremoloKey::neighbors :
222 DoLog(3) && (Log() << Verbose(3) << "Writing type " << knownKeyNames[currentField] << std::endl);
223 writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
224 break;
225 case TremoloKey::resSeq :
226 if (additionalAtomData.count(currentAtom->getId())) {
227 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
228 *file << additionalAtomData[currentAtom->getId()].get(currentField);
229 } else if (currentAtom->getMolecule() != NULL) {
230 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " its own id: " << currentAtom->getMolecule()->getId()+1 << std::endl);
231 *file << setw(4) << currentAtom->getMolecule()->getId()+1;
232 } else {
233 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << defaultAdditionalData.get(currentField) << std::endl);
234 *file << defaultAdditionalData.get(currentField);
235 }
236 *file << "\t";
237 break;
238 default :
239 if (additionalAtomData.count(currentAtom->getId())) {
240 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
241 *file << additionalAtomData[currentAtom->getId()].get(currentField);
242 } else if (additionalAtomData.count(currentAtom->GetTrueFather()->getId())) {
243 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " stuff from father: " << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << std::endl);
244 *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField);
245 } else {
246 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " the default: " << defaultAdditionalData.get(currentField) << std::endl);
247 *file << defaultAdditionalData.get(currentField);
248 }
249 *file << "\t";
250 break;
251 }
252 }
253
254 *file << endl;
255}
256
257/**
258 * Writes the neighbor information of one atom to the provided stream.
259 *
260 * \param stream where to write neighbor information to
261 * \param number of neighbors
262 * \param reference to the atom of which to take the neighbor information
263 */
264void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
265 BondList::iterator currentBond = currentAtom->ListOfBonds.begin();
266 for (int i = 0; i < numberOfNeighbors; i++) {
267 *file << (currentBond != currentAtom->ListOfBonds.end()
268 ? (*currentBond)->GetOtherAtom(currentAtom)->getId()+1 : 0) << "\t";
269 if (currentBond != currentAtom->ListOfBonds.end())
270 ++currentBond;
271 }
272}
273
274/**
275 * Stores keys from the ATOMDATA line.
276 *
277 * \param line to parse the keys from
278 * \param with which offset the keys begin within the line
279 */
280void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
281 string keyword;
282 stringstream lineStream;
283
284 lineStream << line.substr(offset);
285 usedFields.clear();
286 while (lineStream.good()) {
287 lineStream >> keyword;
288 if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
289 // TODO: throw exception about unknown key
290 cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
291 break;
292 }
293 usedFields.push_back(keyword);
294 }
295 //DoLog(1) && (Log() << Verbose(1) << "INFO: " << usedFields << std::endl);
296}
297
298/**
299 * Reads one data line of a tremolo file and interprets it according to the keys
300 * obtained from the ATOMDATA line.
301 *
302 * \param line to parse as an atom
303 * \param *newmol molecule to add atom to
304 */
305void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) {
306 vector<string>::iterator it;
307 stringstream lineStream;
308 atom* newAtom = World::getInstance().createAtom();
309 TremoloAtomInfoContainer *atomInfo = NULL;
310 additionalAtomData[newAtom->getId()] = TremoloAtomInfoContainer(); // fill with default values
311 atomInfo = &additionalAtomData[newAtom->getId()];
312 TremoloKey::atomDataKey currentField;
313 ConvertTo<double> toDouble;
314 ConvertTo<int> toInt;
315
316 // setup tokenizer, splitting up white-spaced entries
317 typedef boost::tokenizer<boost::char_separator<char> >
318 tokenizer;
319 boost::char_separator<char> whitespacesep(" \t");
320 tokenizer tokens(line, whitespacesep);
321 ASSERT(tokens.begin() != tokens.end(),
322 "TremoloParser::readAtomDataLine - empty string, need at least ' '!");
323 tokenizer::iterator tok_iter = tokens.begin();
324 // then associate each token to each file
325 for (it = usedFields.begin(); it < usedFields.end(); it++) {
326 const std::string keyName = it->substr(0, it->find("="));
327 currentField = knownKeys[keyName];
328 const string word = *tok_iter;
329 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with remaining data " << word << std::endl);
330 switch (currentField) {
331 case TremoloKey::x :
332 // for the moment, assume there are always three dimensions
333 for (int i=0;i<NDIM;i++) {
334 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for x["+toString(i)+"]!");
335 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
336 newAtom->set(i, toDouble(*tok_iter));
337 tok_iter++;
338 }
339 break;
340 case TremoloKey::u :
341 // for the moment, assume there are always three dimensions
342 for (int i=0;i<NDIM;i++) {
343 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for u["+toString(i)+"]!");
344 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
345 newAtom->getAtomicVelocity()[i] = toDouble(*tok_iter);
346 tok_iter++;
347 }
348 break;
349 case TremoloKey::Type :
350 {
351 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
352 DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
353 std::string element(knownTypes[(*tok_iter)]);
354 // put type name into container for later use
355 atomInfo->set(currentField, *tok_iter);
356 DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing element " << (*tok_iter) << " as " << element << " according to KnownTypes." << std::endl);
357 tok_iter++;
358 newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
359 ASSERT(newAtom->getType(), "Type was not set for this atom");
360 break;
361 }
362 case TremoloKey::Id :
363 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
364 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
365 atomIdMap[toInt(*tok_iter)] = newAtom->getId();
366 tok_iter++;
367 break;
368 case TremoloKey::neighbors :
369 for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) {
370 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
371 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
372 lineStream << *tok_iter << "\t";
373 tok_iter++;
374 }
375 readNeighbors(&lineStream,
376 atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
377 break;
378 default :
379 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
380 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
381 atomInfo->set(currentField, *tok_iter);
382 tok_iter++;
383 break;
384 }
385 }
386 if (newmol != NULL) {
387 //DoLog(0) && (Log() << Verbose(0) << "New Atom: " << *newAtom << " with type " << newAtom->getType()->getName() << std::endl);
388 newmol->AddAtom(newAtom);
389 }
390}
391
392/**
393 * Reads neighbor information for one atom from the input.
394 *
395 * \param line stream where to read the information from
396 * \param numberOfNeighbors number of neighbors to read
397 * \param atomid world id of the atom the information belongs to
398 */
399void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
400 int neighborId = 0;
401 for (int i = 0; i < numberOfNeighbors; i++) {
402 *line >> neighborId;
403 // 0 is used to fill empty neighbor positions in the tremolo file.
404 if (neighborId > 0) {
405// DoLog(1) && (Log() << Verbose(1)
406// << "Atom with global id " << atomId
407// << " has neighbour with serial " << neighborId
408// << std::endl);
409 additionalAtomData[atomId].neighbors.push_back(neighborId);
410 }
411 }
412}
413
414/**
415 * Checks whether the provided name is within the list of used fields.
416 *
417 * \param field name to check
418 *
419 * \return true if the field name is used
420 */
421bool TremoloParser::isUsedField(string fieldName) {
422 bool fieldNameExists = false;
423 for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
424 if (usedField->substr(0, usedField->find("=")) == fieldName)
425 fieldNameExists = true;
426 }
427
428 return fieldNameExists;
429}
430
431
432/**
433 * Adds the collected neighbor information to the atoms in the world. The atoms
434 * are found by their current ID and mapped to the corresponding atoms with the
435 * Id found in the parsed file.
436 */
437void TremoloParser::processNeighborInformation() {
438 if (!isUsedField("neighbors")) {
439 return;
440 }
441
442 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
443 currentInfo != additionalAtomData.end(); currentInfo++
444 ) {
445 if (!currentInfo->second.neighbors_processed) {
446 for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
447 neighbor != currentInfo->second.neighbors.end(); neighbor++
448 ) {
449// DoLog(1) && (Log() << Verbose(1) << "Creating bond between ("
450// << currentInfo->first
451// << ") and ("
452// << atomIdMap[*neighbor] << "|" << *neighbor << ")" << std::endl);
453 World::getInstance().getAtom(AtomById(currentInfo->first))
454 ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
455 }
456 currentInfo->second.neighbors_processed = true;
457 }
458 }
459}
460
461/**
462 * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
463 * IDs of the input string will be replaced; expected separating characters are
464 * "-" and ",".
465 *
466 * \param string in which atom IDs should be adapted
467 *
468 * \return input string with modified atom IDs
469 */
470string TremoloParser::adaptIdDependentDataString(string data) {
471 // there might be no IDs
472 if (data == "-") {
473 return "-";
474 }
475
476 char separator;
477 int id;
478 stringstream line, result;
479 line << data;
480
481 line >> id;
482 result << atomIdMap[id];
483 while (line.good()) {
484 line >> separator >> id;
485 result << separator << atomIdMap[id];
486 }
487
488 return result.str();
489}
490
491/**
492 * Corrects the atom IDs in each imprData entry to the corresponding world IDs
493 * as they might differ from the originally read IDs.
494 */
495void TremoloParser::adaptImprData() {
496 if (!isUsedField("imprData")) {
497 return;
498 }
499
500 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
501 currentInfo != additionalAtomData.end(); currentInfo++
502 ) {
503 currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData);
504 }
505}
506
507/**
508 * Corrects the atom IDs in each torsion entry to the corresponding world IDs
509 * as they might differ from the originally read IDs.
510 */
511void TremoloParser::adaptTorsion() {
512 if (!isUsedField("torsion")) {
513 return;
514 }
515
516 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
517 currentInfo != additionalAtomData.end(); currentInfo++
518 ) {
519 currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion);
520 }
521}
522
523/** Creates knownTypes as the identity, e.g. H -> H, He -> He, ... .
524 *
525 */
526void TremoloParser::createKnownTypesByIdentity()
527{
528 // remove old mapping
529 knownTypes.clear();
530 // make knownTypes the identity mapping
531 const periodentafel *periode = World::getInstance().getPeriode();
532 for (periodentafel::const_iterator iter = periode->begin();
533 iter != periode->end();
534 ++iter) {
535 knownTypes.insert( make_pair(iter->second->getSymbol(), iter->second->getSymbol()) );
536 }
537}
538
539/** Parses a .potentials file and creates from it the knownTypes file.
540 *
541 * @param file input stream of .potentials file
542 */
543void TremoloParser::parseKnownTypes(std::istream &file)
544{
545 const periodentafel *periode = World::getInstance().getPeriode();
546 // remove old mapping
547 knownTypes.clear();
548
549 DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
550
551 // parse in file
552 typedef boost::tokenizer<boost::char_separator<char> >
553 tokenizer;
554 boost::char_separator<char> tokensep(":\t ,;");
555 boost::char_separator<char> equalitysep("\t =");
556 std::string line;
557 while (file.good()) {
558 std::getline( file, line );
559 DoLog(4) && (Log() << Verbose(4) << "INFO: full line of parameters is '" << line << "'" << std::endl);
560 if (line.find("particle:") != string::npos) {
561 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle:'." << std::endl);
562 tokenizer tokens(line, tokensep);
563 ASSERT(tokens.begin() != tokens.end(),
564 "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
565 // look for particle_type
566 std::string particle_type("NULL");
567 std::string element_type("NULL");
568 for (tokenizer::iterator tok_iter = tokens.begin();
569 tok_iter != tokens.end();
570 ++tok_iter) {
571 if ((*tok_iter).find("particle_type") != string::npos) {
572 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle_type'." << std::endl);
573 tokenizer token((*tok_iter), equalitysep);
574 ASSERT(token.begin() != token.end(),
575 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
576 tokenizer::iterator particle_iter = token.begin();
577 particle_iter++;
578 particle_type = *particle_iter;
579 }
580 if ((*tok_iter).find("element_name") != string::npos) {
581 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'element_name'." << std::endl);
582 tokenizer token((*tok_iter), equalitysep);
583 ASSERT(token.begin() != token.end(),
584 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
585 tokenizer::iterator element_iter = token.begin();
586 element_iter++;
587 element_type = *element_iter;
588 }
589 }
590 if ((particle_type != "NULL") && (element_type != "NULL")) {
591 if (periode->FindElement(element_type) != NULL) {
592 DoLog(1) && (Log() << Verbose(1) << "INFO: Added Type " << particle_type << " as reference to element " << element_type << "." << std::endl);
593 knownTypes.insert( make_pair (particle_type, element_type) );
594 } else {
595 DoeLog(1) && (Log() << Verbose(1) << "INFO: Either Type " << particle_type << " or " << element_type << " could not be recognized." << std::endl);
596 }
597 } else {
598 DoeLog(1) && (Log() << Verbose(1) << "INFO: Desired element " << element_type << " is not known." << std::endl);
599 }
600 }
601 }
602
603}
Note: See TracBrowser for help on using the repository browser.