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