source: src/Potentials/TremoloPotentialFileParser.cpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest 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 StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef was a44d70, checked in by Frederik Heber <heber@…>, 9 years ago

Placed all TREMOLO Potential parsing into distinct structure.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2016 Frederik Heber. 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 * TremoloPotentialFileParser.cpp
25 *
26 * Created on: Mar 9, 2016
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 "TremoloPotentialFileParser.hpp"
39
40#include <string>
41
42#include <boost/assign.hpp>
43
44#include "CodePatterns/Log.hpp"
45#include "CodePatterns/Registry.hpp"
46
47#include "Potentials/EmpiricalPotential.hpp"
48#include "Potentials/Exceptions.hpp"
49#include "Potentials/Particles/Particle.hpp"
50#include "Potentials/Particles/ParticleFactory.hpp"
51#include "Potentials/Particles/ParticleRegistry.hpp"
52#include "Potentials/PotentialFactory.hpp"
53#include "Potentials/PotentialRegistry.hpp"
54#include "Potentials/RegistryDeserializer.hpp"
55#include "Potentials/StreamFactory.hpp"
56#include "Potentials/TremoloPotentialTypes.hpp"
57
58static TremoloPotentialFileParser::allowed_types_t potential_types =
59 boost::assign::list_of< TremoloPotentialTypes::tokentype_t >
60 ( TremoloPotentialTypes::bonds)
61 ( TremoloPotentialTypes::angles)
62 ( TremoloPotentialTypes::torsions)
63 ( TremoloPotentialTypes::impropers)
64 ( TremoloPotentialTypes::nonbonded_2body_potentials);
65
66static TremoloPotentialFileParser::allowed_types_t particle_types =
67 boost::assign::list_of< TremoloPotentialTypes::tokentype_t >
68 ( TremoloPotentialTypes::particles);
69
70template <class T>
71bool parseItems(std::istream &_serialized,
72 StreamFactory<T> &_factory,
73 Registry<T> &_registry,
74 const std::string _name,
75 const TremoloPotentialFileParser::allowed_types_t &_allowed_types)
76{
77 std::string linestring;
78 std::string token;
79 while (_serialized.good()) {
80 getline(_serialized, linestring);
81 const std::string comment("#");
82 if (linestring.find(comment) != std::string::npos) {
83 LOG(4, "DEBUG: Skipping comment line:"+linestring);
84 continue;
85 }
86 const std::string whitespace(" \t");
87 const size_t strBegin = linestring.find_first_not_of(whitespace);
88 const size_t curlyopenpos = linestring.find("{");
89 const size_t curlyclosedpos = linestring.find("}");
90 if (curlyopenpos != std::string::npos) {
91 // begin of new type section
92 token = linestring.substr(strBegin, curlyopenpos);
93 const size_t tokenEnd = token.find_first_of(whitespace);
94 token = token.substr(0, tokenEnd);
95 LOG(1, "INFO: Token is " << token);
96 const TremoloPotentialTypes::tokentype_t tokentype =
97 TremoloPotentialTypes::getTokenTypeFromType(token);
98 // get either particles {} or potentials {}
99 if (_allowed_types.count(tokentype)) {
100 try {
101 RegistryDeserializer<T> deserialize(
102 _serialized,
103 _factory,
104 _registry,
105 _name);
106 deserialize();
107 } catch (SerializerMissingValueException &e) {
108 if (const std::string *key = boost::get_error_info<SerializerKey>(e))
109 ELOG(0, "Missing value when parsing information for particle "+*key+".");
110 else
111 ELOG(0, "Missing value parsing information for particle with unknown key.");
112 return false;
113 } catch (SerializerIllegalKeyException &e) {
114 if (const std::string *key = boost::get_error_info<SerializerKey>(e))
115 ELOG(0, "Illegal key parsing information for particle "+*key+".");
116 else
117 ELOG(0, "Illegal key parsing information for particle with unknown key.");
118 return false;
119 }
120 }
121 } else if (curlyclosedpos != std::string::npos) {
122 // section end encountered, just read next line
123 } else {
124 // skipping a section we do not parse
125 }
126 }
127 return true;
128}
129
130bool TremoloPotentialFileParser::parseParticles(
131 std::istream &_stream)
132{
133 if (!parseItems<Particle>(
134 _stream,
135 ParticleFactory::getInstance(),
136 ParticleRegistry::getInstance(),
137 std::string("particle"),
138 particle_types))
139 return false;
140 return true;
141}
142
143
144bool TremoloPotentialFileParser::parsePotentials(std::istream &_stream)
145{
146 if (!parseItems<EmpiricalPotential>(
147 _stream,
148 PotentialFactory::getInstance(),
149 PotentialRegistry::getInstance(),
150 std::string("potential"),
151 potential_types))
152 return false;
153 return true;
154}
Note: See TracBrowser for help on using the repository browser.