source: src/Parser/TremoloParser_ElementKeys.cpp@ b3d687

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 b3d687 was d9005c1, checked in by Frederik Heber <heber@…>, 13 years ago

Extracted TremoloParser::knownTypes into distinct class ElementKeys, and added ParserExceptions.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 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_ElementKeys.cpp
10 *
11 * Created on: Mar 12, 2012
12 * Author: heber
13 */
14
15
16// include config.h
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "CodePatterns/MemDebug.hpp"
22
23#include "TremoloParser_ElementKeys.hpp"
24
25#include <boost/tokenizer.hpp>
26#include <iostream>
27#include "CodePatterns/Log.hpp"
28
29#include "Element/element.hpp"
30#include "Element/periodentafel.hpp"
31#include "Parser/Exceptions.hpp"
32#include "World.hpp"
33
34/** Parses a .potentials file and creates from it the knownTypes file.
35 *
36 * @param file input stream of .potentials file
37 */
38void ElementKeys::parseKnownTypes(std::istream &file)
39{
40 const periodentafel *periode = World::getInstance().getPeriode();
41 // remove old mapping
42 clear();
43
44// LOG(3, "INFO: additionalAtomData contains: " << additionalAtomData);
45
46 // parse in file
47 typedef boost::tokenizer<boost::char_separator<char> >
48 tokenizer;
49 boost::char_separator<char> tokensep(":\t ,;");
50 boost::char_separator<char> equalitysep("\t =");
51 std::string line;
52 while (file.good()) {
53 std::getline( file, line );
54 LOG(4, "INFO: full line of parameters is '" << line << "'");
55 if (line.find("particle:") != string::npos) {
56 LOG(3, "INFO: found line '" << line << "' containing keyword 'particle:'.");
57 tokenizer tokens(line, tokensep);
58 ASSERT(tokens.begin() != tokens.end(),
59 "FormatParser< tremolo >::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
60 // look for particle_type
61 std::string particle_type("NULL");
62 std::string element_type("NULL");
63 for (tokenizer::iterator tok_iter = tokens.begin();
64 tok_iter != tokens.end();
65 ++tok_iter) {
66 if ((*tok_iter).find("particle_type") != string::npos) {
67 LOG(3, "INFO: found token '" << *tok_iter << "' containing keyword 'particle_type'.");
68 tokenizer token((*tok_iter), equalitysep);
69 ASSERT(token.begin() != token.end(),
70 "FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");
71 tokenizer::iterator particle_iter = token.begin();
72 particle_iter++;
73 particle_type = *particle_iter;
74 }
75 if ((*tok_iter).find("element_name") != string::npos) {
76 LOG(3, "INFO: found token '" << *tok_iter << "' containing keyword 'element_name'.");
77 tokenizer token((*tok_iter), equalitysep);
78 ASSERT(token.begin() != token.end(),
79 "FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");
80 tokenizer::iterator element_iter = token.begin();
81 element_iter++;
82 element_type = *element_iter;
83 }
84 }
85 if ((particle_type != "NULL") && (element_type != "NULL")) {
86 if (periode->FindElement(element_type) != NULL) {
87 LOG(1, "INFO: Added Type " << particle_type << " as reference to element " << element_type << ".");
88 setType(particle_type, element_type);
89 } else {
90 ELOG(1, "INFO: Either Type " << particle_type << " or " << element_type << " could not be recognized." );
91 }
92 } else {
93 ELOG(3, "Line does not contain both 'particle_type' and 'element_name' as keys." );
94 }
95 }
96 }
97}
98
99/** Creates knownTypes as the identity, e.g. H -> H, He -> He, ... .
100 *
101 */
102void ElementKeys::createKnownTypesByIdentity()
103{
104 // remove old mapping
105 clear();
106 // make knownTypes the identity mapping
107 const periodentafel *periode = World::getInstance().getPeriode();
108 for (periodentafel::const_iterator iter = periode->begin();
109 iter != periode->end();
110 ++iter) {
111 setType( iter->second->getSymbol(), iter->second->getSymbol());
112 }
113}
114
115/** Getter for value indexed by \a type.
116 *
117 * @param type key for map
118 * @return value stored under \a type
119 */
120const std::string &ElementKeys::getType(const std::string &type) const throw (IllegalParserKeyException)
121{
122 const_iterator iter = find(type);
123 if (iter == end()) {
124 throw IllegalParserKeyException() << ParserMapLookup(type);
125 } else
126 return iter->second;
127}
128
129/** Getter for value indexed by \a type.
130 *
131 * @param type key for map
132 * @return value stored under \a type
133 */
134void ElementKeys::setType(const std::string &type, const std::string &value) throw (IllegalParserKeyException)
135{
136 const_iterator iter = find(type);
137 if (iter != end()) {
138 throw IllegalParserKeyException() << ParserMapLookup(type);
139 } else {
140 insert( make_pair(type,value) );
141 LOG(3, "DEBUG: Key " << type << " refers to element " << at(type) << ".");
142 }
143}
Note: See TracBrowser for help on using the repository browser.