source: src/Parser/PdbAtomInfoContainer.cpp@ 873037

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

Refined static filling of PdbAtomInfoContainer::knownDataKeys.

  • have static bool which says whether map is filled or not.
  • static clearknownDataKeys() called by PdbParser's dstor.
  • Property mode set to 100644
File size: 7.0 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 * PdbAtomInfoContainer.cpp
10 *
11 * Created on: Dec 4, 2010
12 * Author: heber
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 "LinearAlgebra/Vector.hpp"
27#include "PdbAtomInfoContainer.hpp"
28
29PdbAtomInfoContainer::knownDataKeysMap PdbAtomInfoContainer::knownDataKeys;
30bool PdbAtomInfoContainer::knownDataKeys_Filled = false;
31
32PdbAtomInfoContainer::PdbAtomInfoContainer() :
33 token("ATOM"),
34 serial(0),
35 name("-"),
36 altLoc('0'),
37 resName("-"),
38 chainID('0'),
39 resSeq(0),
40 iCode(' '),
41 occupancy(0.),
42 tempFactor(0.),
43 element(""),
44 charge(0),
45 timestep(0)
46{
47 if (!knownDataKeys_Filled)
48 fillknownDataKeys();
49}
50
51PdbAtomInfoContainer::~PdbAtomInfoContainer()
52{}
53
54void PdbAtomInfoContainer::fillknownDataKeys()
55{
56 knownDataKeys[PdbKey::token] = "token";
57 knownDataKeys[PdbKey::serial] = "serial";
58 knownDataKeys[PdbKey::name] = "name";
59 knownDataKeys[PdbKey::altLoc] = "altLoc";
60 knownDataKeys[PdbKey::resName] = "resName";
61 knownDataKeys[PdbKey::chainID] = "chainID";
62 knownDataKeys[PdbKey::resSeq] = "resSeq";
63 knownDataKeys[PdbKey::iCode] = "iCode";
64 knownDataKeys[PdbKey::X] = "X";
65 knownDataKeys[PdbKey::Y] = "Y";
66 knownDataKeys[PdbKey::Z] = "Z";
67 knownDataKeys[PdbKey::occupancy] = "occupancy";
68 knownDataKeys[PdbKey::tempFactor] = "tempFactor";
69 knownDataKeys[PdbKey::element] = "element";
70 knownDataKeys[PdbKey::charge] = "charge";
71 knownDataKeys[PdbKey::timestep] = "timestep";
72 knownDataKeys_Filled = true;
73}
74
75void PdbAtomInfoContainer::clearknownDataKeys()
76{
77 knownDataKeys.clear();
78 knownDataKeys_Filled = false;
79}
80
81void PdbAtomInfoContainer::set(const PdbKey::PdbDataKey key, std::string value)
82{
83 switch (key) {
84 case PdbKey::token :
85 ScanKey(token, value);
86 break;
87 case PdbKey::serial :
88 ScanKey(serial, value);
89 break;
90 case PdbKey::name :
91 ScanKey(name, value);
92 break;
93 case PdbKey::altLoc :
94 ScanKey(altLoc, value);
95 break;
96 case PdbKey::resName :
97 ScanKey(resName, value);
98 break;
99 case PdbKey::chainID :
100 ScanKey(chainID, value);
101 break;
102 case PdbKey::resSeq :
103 ScanKey(resSeq, value);
104 break;
105 case PdbKey::iCode :
106 ScanKey(iCode, value);
107 break;
108 case PdbKey::X :
109 ScanKey(XYZ[0], value);
110 break;
111 case PdbKey::Y :
112 ScanKey(XYZ[1], value);
113 break;
114 case PdbKey::Z :
115 ScanKey(XYZ[2], value);
116 break;
117 case PdbKey::occupancy :
118 ScanKey(occupancy, value);
119 break;
120 case PdbKey::tempFactor :
121 ScanKey(tempFactor, value);
122 break;
123 case PdbKey::element :
124 ScanKey(element, value);
125 break;
126 case PdbKey::charge :
127 ScanKey(charge, value);
128 break;
129 case PdbKey::timestep :
130 ScanKey(timestep, value);
131 break;
132 default :
133 std::cout << "Unknown key: " << key << ", value: " << value << std::endl;
134 break;
135 }
136}
137
138template <>
139std::string PdbAtomInfoContainer::get<std::string>(const PdbKey::PdbDataKey key) const
140{
141 switch (key) {
142 case PdbKey::token :
143 return toString(token);
144 case PdbKey::serial :
145 return toString(serial);
146 case PdbKey::name :
147 return toString(name);
148 case PdbKey::altLoc :
149 return toString(altLoc);
150 case PdbKey::resName :
151 return toString(resName);
152 case PdbKey::chainID :
153 return toString(chainID);
154 case PdbKey::resSeq :
155 return toString(resSeq);
156 case PdbKey::iCode :
157 return toString(iCode);
158 case PdbKey::X :
159 return toString(XYZ[0]);
160 case PdbKey::Y :
161 return toString(XYZ[1]);
162 case PdbKey::Z :
163 return toString(XYZ[2]);
164 case PdbKey::occupancy :
165 return toString(occupancy);
166 case PdbKey::tempFactor :
167 return toString(tempFactor);
168 case PdbKey::element :
169 return toString(element);
170 case PdbKey::charge :
171 return toString(charge);
172 case PdbKey::timestep :
173 return toString(timestep);
174 default :
175 std::cout << "Unknown key: " << key << std::endl;
176 return "";
177 }
178}
179
180template <>
181int PdbAtomInfoContainer::get<int>(const PdbKey::PdbDataKey key) const
182{
183 switch (key) {
184 case PdbKey::serial :
185 return serial;
186 case PdbKey::resSeq :
187 return resSeq;
188 case PdbKey::charge :
189 return charge;
190 case PdbKey::timestep :
191 return timestep;
192 default :
193 std::cout << "Unknown key or not presentable as int: " << key << std::endl;
194 return 0;
195 }
196}
197
198template <>
199double PdbAtomInfoContainer::get<double>(const PdbKey::PdbDataKey key) const
200{
201 switch (key) {
202 case PdbKey::X :
203 return XYZ[0];
204 case PdbKey::Y :
205 return XYZ[1];
206 case PdbKey::Z :
207 return XYZ[2];
208 case PdbKey::occupancy :
209 return occupancy;
210 case PdbKey::tempFactor :
211 return tempFactor;
212 default :
213 std::cout << "Unknown key or not presentable as double: " << key << std::endl;
214 return 0.;
215 }
216}
217
218const std::string& PdbAtomInfoContainer::getDataKey(PdbKey::PdbDataKey key) const
219{
220 knownDataKeysMap::const_iterator iter;
221 iter = knownDataKeys.find(key);
222 ASSERT(iter != knownDataKeys.end(),
223 "PdbAtomInfoContainer::getDataKey() - unknown key "
224 +toString(key)+" request, did someone add a key to PdbKey?");
225 return iter->second;
226}
227
228std::ostream& operator<<(std::ostream &ost, const PdbAtomInfoContainer& m)
229{
230 ost << m.getDataKey(PdbKey::token) << "(" << m.get<std::string>(PdbKey::token) <<") ";
231 ost << m.getDataKey(PdbKey::serial) << "(" << m.get<std::string>(PdbKey::serial) <<") ";
232 ost << m.getDataKey(PdbKey::name) << "(" << m.get<std::string>(PdbKey::name) <<") ";
233 ost << m.getDataKey(PdbKey::altLoc) << "(" << m.get<std::string>(PdbKey::altLoc) <<") ";
234 ost << m.getDataKey(PdbKey::resName) << "(" << m.get<std::string>(PdbKey::resName) <<") ";
235 ost << m.getDataKey(PdbKey::chainID) << "(" << m.get<std::string>(PdbKey::chainID) <<") ";
236 ost << m.getDataKey(PdbKey::resSeq) << "(" << m.get<std::string>(PdbKey::resSeq) <<") ";
237 ost << m.getDataKey(PdbKey::iCode) << "(" << m.get<std::string>(PdbKey::iCode) <<") ";
238 ost << m.getDataKey(PdbKey::X) << "(" << m.get<std::string>(PdbKey::X) <<") ";
239 ost << m.getDataKey(PdbKey::Y) << "(" << m.get<std::string>(PdbKey::Y) <<") ";
240 ost << m.getDataKey(PdbKey::Z) << "(" << m.get<std::string>(PdbKey::Z) <<") ";
241 ost << m.getDataKey(PdbKey::occupancy) << "(" << m.get<std::string>(PdbKey::occupancy) <<") ";
242 ost << m.getDataKey(PdbKey::tempFactor) << "(" << m.get<std::string>(PdbKey::tempFactor) <<") ";
243 ost << m.getDataKey(PdbKey::element) << "(" << m.get<std::string>(PdbKey::element) <<") ";
244 ost << m.getDataKey(PdbKey::charge) << "(" << m.get<std::string>(PdbKey::charge) <<") ";
245 ost << m.getDataKey(PdbKey::timestep) << "(" << m.get<std::string>(PdbKey::timestep) <<") ";
246 return ost;
247}
Note: See TracBrowser for help on using the repository browser.