source: src/Parser/TremoloParser_ElementKeys.cpp@ 740f9f

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests 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_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 FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks 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 740f9f was 045228, checked in by Frederik Heber <heber@…>, 9 years ago

TremoloParser's ElementKeys now registers types also with ParticleRegistry.

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