source: src/Parser/TremoloParser.cpp@ 4d4d33

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 Candidate_v1.7.0 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 4d4d33 was 4d4d33, checked in by Frederik Heber <heber@…>, 15 years ago

Added tremolo's potential file parsing, reported by Daniel Dueck.

TremoloParser cannot interpret Type with HLA2 because it lacks mapping of the
value to an element. Hence, ...

  • new Action ParseTremoloPotentialsAction.
  • TremoloParser::knownTypes new map to contain: HLA2 -> H, ... map.
  • TremoloParser::createKnownTypesByIdentity() creates identity mapping.
  • TremoloParser::parseKnownTypes() parses potentials file.
  • Property mode set to 100644
File size: 22.4 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 *file << "# ATOMDATA";
143 for (it=usedFields.begin(); it < usedFields.end(); it++) {
144 *file << "\t" << *it;
145 }
146 *file << endl;
147 for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
148 saveLine(file, *atomIt);
149 }
150}
151
152/**
153 * Sets the keys for which data should be written to the stream when save is
154 * called.
155 *
156 * \param string of field names with the same syntax as for an ATOMDATA line
157 * but without the prexix "ATOMDATA"
158 */
159void TremoloParser::setFieldsForSave(std::string atomDataLine) {
160 parseAtomDataKeysLine(atomDataLine, 0);
161}
162
163
164/**
165 * Writes one line of tremolo-formatted data to the provided stream.
166 *
167 * \param stream where to write the line to
168 * \param reference to the atom of which information should be written
169 */
170void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
171 vector<string>::iterator it;
172 TremoloKey::atomDataKey currentField;
173
174 DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
175
176 for (it = usedFields.begin(); it != usedFields.end(); it++) {
177 currentField = knownKeys[it->substr(0, it->find("="))];
178 switch (currentField) {
179 case TremoloKey::x :
180 // for the moment, assume there are always three dimensions
181 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getPosition() << std::endl);
182 *file << currentAtom->at(0) << "\t";
183 *file << currentAtom->at(1) << "\t";
184 *file << currentAtom->at(2) << "\t";
185 break;
186 case TremoloKey::u :
187 // for the moment, assume there are always three dimensions
188 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->AtomicVelocity << std::endl);
189 *file << currentAtom->AtomicVelocity[0] << "\t";
190 *file << currentAtom->AtomicVelocity[1] << "\t";
191 *file << currentAtom->AtomicVelocity[2] << "\t";
192 break;
193 case TremoloKey::Type :
194 if ((!additionalAtomData.count(currentAtom->getId())) || (additionalAtomData[currentAtom->getId()].get(currentField) == "-")) {
195 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << currentAtom->getType()->getSymbol() << std::endl);
196 *file << currentAtom->getType()->getSymbol() << "\t";
197 } else {
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 }
201 break;
202 case TremoloKey::Id :
203 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getId()+1 << std::endl);
204 *file << currentAtom->getId()+1 << "\t";
205 break;
206 case TremoloKey::neighbors :
207 DoLog(3) && (Log() << Verbose(3) << "Writing type " << knownKeyNames[currentField] << std::endl);
208 writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
209 break;
210 case TremoloKey::resSeq :
211 if (additionalAtomData.count(currentAtom->getId())) {
212 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
213 *file << additionalAtomData[currentAtom->getId()].get(currentField);
214 } else if (currentAtom->getMolecule() != NULL) {
215 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " its own id: " << currentAtom->getMolecule()->getId()+1 << std::endl);
216 *file << setw(4) << currentAtom->getMolecule()->getId()+1;
217 } else {
218 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << defaultAdditionalData.get(currentField) << std::endl);
219 *file << defaultAdditionalData.get(currentField);
220 }
221 *file << "\t";
222 break;
223 default :
224 if (additionalAtomData.count(currentAtom->getId())) {
225 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl);
226 *file << additionalAtomData[currentAtom->getId()].get(currentField);
227 } else if (additionalAtomData.count(currentAtom->GetTrueFather()->getId())) {
228 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " stuff from father: " << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << std::endl);
229 *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField);
230 } else {
231 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " the default: " << defaultAdditionalData.get(currentField) << std::endl);
232 *file << defaultAdditionalData.get(currentField);
233 }
234 *file << "\t";
235 break;
236 }
237 }
238
239 *file << endl;
240}
241
242/**
243 * Writes the neighbor information of one atom to the provided stream.
244 *
245 * \param stream where to write neighbor information to
246 * \param number of neighbors
247 * \param reference to the atom of which to take the neighbor information
248 */
249void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
250 BondList::iterator currentBond = currentAtom->ListOfBonds.begin();
251 for (int i = 0; i < numberOfNeighbors; i++) {
252 *file << (currentBond != currentAtom->ListOfBonds.end()
253 ? (*currentBond)->GetOtherAtom(currentAtom)->getId()+1 : 0) << "\t";
254 if (currentBond != currentAtom->ListOfBonds.end())
255 ++currentBond;
256 }
257}
258
259/**
260 * Stores keys from the ATOMDATA line.
261 *
262 * \param line to parse the keys from
263 * \param with which offset the keys begin within the line
264 */
265void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
266 string keyword;
267 stringstream lineStream;
268
269 lineStream << line.substr(offset);
270 usedFields.clear();
271 while (lineStream.good()) {
272 lineStream >> keyword;
273 if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
274 // TODO: throw exception about unknown key
275 cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
276 break;
277 }
278 usedFields.push_back(keyword);
279 }
280 //DoLog(1) && (Log() << Verbose(1) << "INFO: " << usedFields << std::endl);
281}
282
283/**
284 * Reads one data line of a tremolo file and interprets it according to the keys
285 * obtained from the ATOMDATA line.
286 *
287 * \param line to parse as an atom
288 * \param *newmol molecule to add atom to
289 */
290void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) {
291 vector<string>::iterator it;
292 stringstream lineStream;
293 atom* newAtom = World::getInstance().createAtom();
294 TremoloAtomInfoContainer *atomInfo = NULL;
295 additionalAtomData[newAtom->getId()] = TremoloAtomInfoContainer(); // fill with default values
296 atomInfo = &additionalAtomData[newAtom->getId()];
297 TremoloKey::atomDataKey currentField;
298 ConvertTo<double> toDouble;
299 ConvertTo<int> toInt;
300
301 // setup tokenizer, splitting up white-spaced entries
302 typedef boost::tokenizer<boost::char_separator<char> >
303 tokenizer;
304 boost::char_separator<char> whitespacesep(" \t");
305 tokenizer tokens(line, whitespacesep);
306 ASSERT(tokens.begin() != tokens.end(),
307 "TremoloParser::readAtomDataLine - empty string, need at least ' '!");
308 tokenizer::iterator tok_iter = tokens.begin();
309 // then associate each token to each file
310 for (it = usedFields.begin(); it < usedFields.end(); it++) {
311 const std::string keyName = it->substr(0, it->find("="));
312 currentField = knownKeys[keyName];
313 const string word = *tok_iter;
314 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with remaining data " << word << std::endl);
315 switch (currentField) {
316 case TremoloKey::x :
317 // for the moment, assume there are always three dimensions
318 for (int i=0;i<NDIM;i++) {
319 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for x["+toString(i)+"]!");
320 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
321 newAtom->set(i, toDouble(*tok_iter));
322 tok_iter++;
323 }
324 break;
325 case TremoloKey::u :
326 // for the moment, assume there are always three dimensions
327 for (int i=0;i<NDIM;i++) {
328 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for u["+toString(i)+"]!");
329 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
330 newAtom->AtomicVelocity[i] = toDouble(*tok_iter);
331 tok_iter++;
332 }
333 break;
334 case TremoloKey::Type :
335 {
336 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
337 DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
338 std::string element(knownTypes[(*tok_iter)]);
339 // put type name into container for later use
340 atomInfo->set(currentField, *tok_iter);
341 DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing element " << (*tok_iter) << " as " << element << " according to KnownTypes." << std::endl);
342 tok_iter++;
343 newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
344 ASSERT(newAtom->getType(), "Type was not set for this atom");
345 break;
346 }
347 case TremoloKey::Id :
348 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
349 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
350 atomIdMap[toInt(*tok_iter)] = newAtom->getId();
351 tok_iter++;
352 break;
353 case TremoloKey::neighbors :
354 for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) {
355 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
356 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
357 lineStream << *tok_iter << "\t";
358 tok_iter++;
359 }
360 readNeighbors(&lineStream,
361 atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
362 break;
363 default :
364 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
365 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
366 atomInfo->set(currentField, *tok_iter);
367 tok_iter++;
368 break;
369 }
370 }
371 if (newmol != NULL) {
372 //DoLog(0) && (Log() << Verbose(0) << "New Atom: " << *newAtom << " with type " << newAtom->getType()->getName() << std::endl);
373 newmol->AddAtom(newAtom);
374 }
375}
376
377/**
378 * Reads neighbor information for one atom from the input.
379 *
380 * \param line stream where to read the information from
381 * \param numberOfNeighbors number of neighbors to read
382 * \param atomid world id of the atom the information belongs to
383 */
384void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
385 int neighborId = 0;
386 for (int i = 0; i < numberOfNeighbors; i++) {
387 *line >> neighborId;
388 // 0 is used to fill empty neighbor positions in the tremolo file.
389 if (neighborId > 0) {
390// DoLog(1) && (Log() << Verbose(1)
391// << "Atom with global id " << atomId
392// << " has neighbour with serial " << neighborId
393// << std::endl);
394 additionalAtomData[atomId].neighbors.push_back(neighborId);
395 }
396 }
397}
398
399/**
400 * Checks whether the provided name is within the list of used fields.
401 *
402 * \param field name to check
403 *
404 * \return true if the field name is used
405 */
406bool TremoloParser::isUsedField(string fieldName) {
407 bool fieldNameExists = false;
408 for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
409 if (usedField->substr(0, usedField->find("=")) == fieldName)
410 fieldNameExists = true;
411 }
412
413 return fieldNameExists;
414}
415
416
417/**
418 * Adds the collected neighbor information to the atoms in the world. The atoms
419 * are found by their current ID and mapped to the corresponding atoms with the
420 * Id found in the parsed file.
421 */
422void TremoloParser::processNeighborInformation() {
423 if (!isUsedField("neighbors")) {
424 return;
425 }
426
427 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
428 currentInfo != additionalAtomData.end(); currentInfo++
429 ) {
430 if (!currentInfo->second.neighbors_processed) {
431 for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
432 neighbor != currentInfo->second.neighbors.end(); neighbor++
433 ) {
434// DoLog(1) && (Log() << Verbose(1) << "Creating bond between ("
435// << currentInfo->first
436// << ") and ("
437// << atomIdMap[*neighbor] << "|" << *neighbor << ")" << std::endl);
438 World::getInstance().getAtom(AtomById(currentInfo->first))
439 ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
440 }
441 currentInfo->second.neighbors_processed = true;
442 }
443 }
444}
445
446/**
447 * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
448 * IDs of the input string will be replaced; expected separating characters are
449 * "-" and ",".
450 *
451 * \param string in which atom IDs should be adapted
452 *
453 * \return input string with modified atom IDs
454 */
455string TremoloParser::adaptIdDependentDataString(string data) {
456 // there might be no IDs
457 if (data == "-") {
458 return "-";
459 }
460
461 char separator;
462 int id;
463 stringstream line, result;
464 line << data;
465
466 line >> id;
467 result << atomIdMap[id];
468 while (line.good()) {
469 line >> separator >> id;
470 result << separator << atomIdMap[id];
471 }
472
473 return result.str();
474}
475
476/**
477 * Corrects the atom IDs in each imprData entry to the corresponding world IDs
478 * as they might differ from the originally read IDs.
479 */
480void TremoloParser::adaptImprData() {
481 if (!isUsedField("imprData")) {
482 return;
483 }
484
485 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
486 currentInfo != additionalAtomData.end(); currentInfo++
487 ) {
488 currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData);
489 }
490}
491
492/**
493 * Corrects the atom IDs in each torsion entry to the corresponding world IDs
494 * as they might differ from the originally read IDs.
495 */
496void TremoloParser::adaptTorsion() {
497 if (!isUsedField("torsion")) {
498 return;
499 }
500
501 for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
502 currentInfo != additionalAtomData.end(); currentInfo++
503 ) {
504 currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion);
505 }
506}
507
508/** Creates knownTypes as the identity, e.g. H -> H, He -> He, ... .
509 *
510 */
511void TremoloParser::createKnownTypesByIdentity()
512{
513 // remove old mapping
514 knownTypes.clear();
515 // make knownTypes the identity mapping
516 const periodentafel *periode = World::getInstance().getPeriode();
517 for (periodentafel::const_iterator iter = periode->begin();
518 iter != periode->end();
519 ++iter) {
520 knownTypes.insert( make_pair(iter->second->getSymbol(), iter->second->getSymbol()) );
521 }
522}
523
524/** Parses a .potentials file and creates from it the knownTypes file.
525 *
526 * @param file input stream of .potentials file
527 */
528void TremoloParser::parseKnownTypes(std::istream &file)
529{
530 const periodentafel *periode = World::getInstance().getPeriode();
531 // remove old mapping
532 knownTypes.clear();
533
534 DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl);
535
536 // parse in file
537 typedef boost::tokenizer<boost::char_separator<char> >
538 tokenizer;
539 boost::char_separator<char> tokensep(":\t ,;");
540 boost::char_separator<char> equalitysep("\t =");
541 std::string line;
542 while (file.good()) {
543 std::getline( file, line );
544 DoLog(4) && (Log() << Verbose(4) << "INFO: full line of parameters is '" << line << "'" << std::endl);
545 if (line.find("particle:") != string::npos) {
546 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle:'." << std::endl);
547 tokenizer tokens(line, tokensep);
548 ASSERT(tokens.begin() != tokens.end(),
549 "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
550 // look for particle_type
551 std::string particle_type("NULL");
552 std::string element_type("NULL");
553 for (tokenizer::iterator tok_iter = tokens.begin();
554 tok_iter != tokens.end();
555 ++tok_iter) {
556 if ((*tok_iter).find("particle_type") != string::npos) {
557 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle_type'." << std::endl);
558 tokenizer token((*tok_iter), equalitysep);
559 ASSERT(token.begin() != token.end(),
560 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
561 tokenizer::iterator particle_iter = token.begin();
562 particle_iter++;
563 particle_type = *particle_iter;
564 }
565 if ((*tok_iter).find("element_name") != string::npos) {
566 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'element_name'." << std::endl);
567 tokenizer token((*tok_iter), equalitysep);
568 ASSERT(token.begin() != token.end(),
569 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
570 tokenizer::iterator element_iter = token.begin();
571 element_iter++;
572 element_type = *element_iter;
573 }
574 }
575 if ((particle_type != "NULL") && (element_type != "NULL")) {
576 if (periode->FindElement(element_type) != NULL) {
577 DoLog(1) && (Log() << Verbose(1) << "INFO: Added Type " << particle_type << " as reference to element " << element_type << "." << std::endl);
578 knownTypes.insert( make_pair (particle_type, element_type) );
579 } else {
580 DoeLog(1) && (Log() << Verbose(1) << "INFO: Either Type " << particle_type << " or " << element_type << " could not be recognized." << std::endl);
581 }
582 } else {
583 DoeLog(1) && (Log() << Verbose(1) << "INFO: Desired element " << element_type << " is not known." << std::endl);
584 }
585 }
586 }
587
588}
Note: See TracBrowser for help on using the repository browser.