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 | {
|
---|
46 | if (!knownDataKeys_Filled)
|
---|
47 | fillknownDataKeys();
|
---|
48 | }
|
---|
49 |
|
---|
50 | PdbAtomInfoContainer::~PdbAtomInfoContainer()
|
---|
51 | {}
|
---|
52 |
|
---|
53 | void PdbAtomInfoContainer::fillknownDataKeys()
|
---|
54 | {
|
---|
55 | knownDataKeys[PdbKey::token] = "token";
|
---|
56 | knownDataKeys[PdbKey::serial] = "serial";
|
---|
57 | knownDataKeys[PdbKey::name] = "name";
|
---|
58 | knownDataKeys[PdbKey::altLoc] = "altLoc";
|
---|
59 | knownDataKeys[PdbKey::resName] = "resName";
|
---|
60 | knownDataKeys[PdbKey::chainID] = "chainID";
|
---|
61 | knownDataKeys[PdbKey::resSeq] = "resSeq";
|
---|
62 | knownDataKeys[PdbKey::iCode] = "iCode";
|
---|
63 | knownDataKeys[PdbKey::X] = "X";
|
---|
64 | knownDataKeys[PdbKey::Y] = "Y";
|
---|
65 | knownDataKeys[PdbKey::Z] = "Z";
|
---|
66 | knownDataKeys[PdbKey::occupancy] = "occupancy";
|
---|
67 | knownDataKeys[PdbKey::tempFactor] = "tempFactor";
|
---|
68 | knownDataKeys[PdbKey::element] = "element";
|
---|
69 | knownDataKeys[PdbKey::charge] = "charge";
|
---|
70 | knownDataKeys_Filled = true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | void PdbAtomInfoContainer::clearknownDataKeys()
|
---|
74 | {
|
---|
75 | knownDataKeys.clear();
|
---|
76 | knownDataKeys_Filled = false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | void PdbAtomInfoContainer::set(const PdbKey::PdbDataKey key, std::string value)
|
---|
80 | {
|
---|
81 | switch (key) {
|
---|
82 | case PdbKey::token :
|
---|
83 | ScanKey(token, value);
|
---|
84 | break;
|
---|
85 | case PdbKey::serial :
|
---|
86 | ScanKey(serial, value);
|
---|
87 | break;
|
---|
88 | case PdbKey::name :
|
---|
89 | ScanKey(name, value);
|
---|
90 | break;
|
---|
91 | case PdbKey::altLoc :
|
---|
92 | ScanKey(altLoc, value);
|
---|
93 | break;
|
---|
94 | case PdbKey::resName :
|
---|
95 | ScanKey(resName, value);
|
---|
96 | break;
|
---|
97 | case PdbKey::chainID :
|
---|
98 | ScanKey(chainID, value);
|
---|
99 | break;
|
---|
100 | case PdbKey::resSeq :
|
---|
101 | ScanKey(resSeq, value);
|
---|
102 | break;
|
---|
103 | case PdbKey::iCode :
|
---|
104 | ScanKey(iCode, value);
|
---|
105 | break;
|
---|
106 | case PdbKey::X :
|
---|
107 | ScanKey(XYZ[0], value);
|
---|
108 | break;
|
---|
109 | case PdbKey::Y :
|
---|
110 | ScanKey(XYZ[1], value);
|
---|
111 | break;
|
---|
112 | case PdbKey::Z :
|
---|
113 | ScanKey(XYZ[2], value);
|
---|
114 | break;
|
---|
115 | case PdbKey::occupancy :
|
---|
116 | ScanKey(occupancy, value);
|
---|
117 | break;
|
---|
118 | case PdbKey::tempFactor :
|
---|
119 | ScanKey(tempFactor, value);
|
---|
120 | break;
|
---|
121 | case PdbKey::element :
|
---|
122 | ScanKey(element, value);
|
---|
123 | break;
|
---|
124 | case PdbKey::charge :
|
---|
125 | ScanKey(charge, value);
|
---|
126 | break;
|
---|
127 | default :
|
---|
128 | std::cout << "Unknown key: " << key << ", value: " << value << std::endl;
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | template <>
|
---|
134 | std::string PdbAtomInfoContainer::get<std::string>(const PdbKey::PdbDataKey key) const
|
---|
135 | {
|
---|
136 | switch (key) {
|
---|
137 | case PdbKey::token :
|
---|
138 | return toString(token);
|
---|
139 | case PdbKey::serial :
|
---|
140 | return toString(serial);
|
---|
141 | case PdbKey::name :
|
---|
142 | return toString(name);
|
---|
143 | case PdbKey::altLoc :
|
---|
144 | return toString(altLoc);
|
---|
145 | case PdbKey::resName :
|
---|
146 | return toString(resName);
|
---|
147 | case PdbKey::chainID :
|
---|
148 | return toString(chainID);
|
---|
149 | case PdbKey::resSeq :
|
---|
150 | return toString(resSeq);
|
---|
151 | case PdbKey::iCode :
|
---|
152 | return toString(iCode);
|
---|
153 | case PdbKey::X :
|
---|
154 | return toString(XYZ[0]);
|
---|
155 | case PdbKey::Y :
|
---|
156 | return toString(XYZ[1]);
|
---|
157 | case PdbKey::Z :
|
---|
158 | return toString(XYZ[2]);
|
---|
159 | case PdbKey::occupancy :
|
---|
160 | return toString(occupancy);
|
---|
161 | case PdbKey::tempFactor :
|
---|
162 | return toString(tempFactor);
|
---|
163 | case PdbKey::element :
|
---|
164 | return toString(element);
|
---|
165 | case PdbKey::charge :
|
---|
166 | return toString(charge);
|
---|
167 | default :
|
---|
168 | std::cout << "Unknown key: " << key << std::endl;
|
---|
169 | return "";
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | template <>
|
---|
174 | int PdbAtomInfoContainer::get<int>(const PdbKey::PdbDataKey key) const
|
---|
175 | {
|
---|
176 | switch (key) {
|
---|
177 | case PdbKey::serial :
|
---|
178 | return serial;
|
---|
179 | case PdbKey::resSeq :
|
---|
180 | return resSeq;
|
---|
181 | case PdbKey::charge :
|
---|
182 | return charge;
|
---|
183 | default :
|
---|
184 | std::cout << "Unknown key or not presentable as int: " << key << std::endl;
|
---|
185 | return 0;
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | template <>
|
---|
190 | double PdbAtomInfoContainer::get<double>(const PdbKey::PdbDataKey key) const
|
---|
191 | {
|
---|
192 | switch (key) {
|
---|
193 | case PdbKey::X :
|
---|
194 | return XYZ[0];
|
---|
195 | case PdbKey::Y :
|
---|
196 | return XYZ[1];
|
---|
197 | case PdbKey::Z :
|
---|
198 | return XYZ[2];
|
---|
199 | case PdbKey::occupancy :
|
---|
200 | return occupancy;
|
---|
201 | case PdbKey::tempFactor :
|
---|
202 | return tempFactor;
|
---|
203 | default :
|
---|
204 | std::cout << "Unknown key or not presentable as double: " << key << std::endl;
|
---|
205 | return 0.;
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | const std::string& PdbAtomInfoContainer::getDataKey(PdbKey::PdbDataKey key) const
|
---|
210 | {
|
---|
211 | knownDataKeysMap::const_iterator iter;
|
---|
212 | iter = knownDataKeys.find(key);
|
---|
213 | ASSERT(iter != knownDataKeys.end(),
|
---|
214 | "PdbAtomInfoContainer::getDataKey() - unknown key "
|
---|
215 | +toString(key)+" request, did someone add a key to PdbKey?");
|
---|
216 | return iter->second;
|
---|
217 | }
|
---|
218 |
|
---|
219 | std::ostream& operator<<(std::ostream &ost, const PdbAtomInfoContainer& m)
|
---|
220 | {
|
---|
221 | ost << m.getDataKey(PdbKey::token) << "(" << m.get<std::string>(PdbKey::token) <<") ";
|
---|
222 | ost << m.getDataKey(PdbKey::serial) << "(" << m.get<std::string>(PdbKey::serial) <<") ";
|
---|
223 | ost << m.getDataKey(PdbKey::name) << "(" << m.get<std::string>(PdbKey::name) <<") ";
|
---|
224 | ost << m.getDataKey(PdbKey::altLoc) << "(" << m.get<std::string>(PdbKey::altLoc) <<") ";
|
---|
225 | ost << m.getDataKey(PdbKey::resName) << "(" << m.get<std::string>(PdbKey::resName) <<") ";
|
---|
226 | ost << m.getDataKey(PdbKey::chainID) << "(" << m.get<std::string>(PdbKey::chainID) <<") ";
|
---|
227 | ost << m.getDataKey(PdbKey::resSeq) << "(" << m.get<std::string>(PdbKey::resSeq) <<") ";
|
---|
228 | ost << m.getDataKey(PdbKey::iCode) << "(" << m.get<std::string>(PdbKey::iCode) <<") ";
|
---|
229 | ost << m.getDataKey(PdbKey::X) << "(" << m.get<std::string>(PdbKey::X) <<") ";
|
---|
230 | ost << m.getDataKey(PdbKey::Y) << "(" << m.get<std::string>(PdbKey::Y) <<") ";
|
---|
231 | ost << m.getDataKey(PdbKey::Z) << "(" << m.get<std::string>(PdbKey::Z) <<") ";
|
---|
232 | ost << m.getDataKey(PdbKey::occupancy) << "(" << m.get<std::string>(PdbKey::occupancy) <<") ";
|
---|
233 | ost << m.getDataKey(PdbKey::tempFactor) << "(" << m.get<std::string>(PdbKey::tempFactor) <<") ";
|
---|
234 | ost << m.getDataKey(PdbKey::element) << "(" << m.get<std::string>(PdbKey::element) <<") ";
|
---|
235 | ost << m.getDataKey(PdbKey::charge) << "(" << m.get<std::string>(PdbKey::charge) <<") ";
|
---|
236 | return ost;
|
---|
237 | }
|
---|