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 |
|
---|
29 | PdbAtomInfoContainer::knownDataKeysMap PdbAtomInfoContainer::knownDataKeys;
|
---|
30 | bool PdbAtomInfoContainer::knownDataKeys_Filled = false;
|
---|
31 |
|
---|
32 | PdbAtomInfoContainer::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 |
|
---|
51 | PdbAtomInfoContainer::~PdbAtomInfoContainer()
|
---|
52 | {}
|
---|
53 |
|
---|
54 | void 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 |
|
---|
75 | void PdbAtomInfoContainer::clearknownDataKeys()
|
---|
76 | {
|
---|
77 | knownDataKeys.clear();
|
---|
78 | knownDataKeys_Filled = false;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void 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 |
|
---|
138 | template <>
|
---|
139 | std::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 |
|
---|
180 | template <>
|
---|
181 | int 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 |
|
---|
198 | template <>
|
---|
199 | double 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 |
|
---|
218 | const 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 |
|
---|
228 | std::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 | }
|
---|