| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2012 University of Bonn. 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 | * Values.cpp | 
|---|
| 25 | * | 
|---|
| 26 | *  Created on: Feb 10, 2011 | 
|---|
| 27 | *      Author: heber | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | // include config.h | 
|---|
| 31 | #ifdef HAVE_CONFIG_H | 
|---|
| 32 | #include <config.h> | 
|---|
| 33 | #endif | 
|---|
| 34 |  | 
|---|
| 35 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| 36 |  | 
|---|
| 37 | #include "CodePatterns/Assert.hpp" | 
|---|
| 38 |  | 
|---|
| 39 | #include <boost/lexical_cast.hpp> | 
|---|
| 40 | #include <boost/tokenizer.hpp> | 
|---|
| 41 |  | 
|---|
| 42 | #include "Box.hpp" | 
|---|
| 43 | #include "LinearAlgebra/BoxVector.hpp" | 
|---|
| 44 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 45 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 46 |  | 
|---|
| 47 | #include "Values.hpp" | 
|---|
| 48 |  | 
|---|
| 49 | static const Vector parseAsVector(const std::string &_string) | 
|---|
| 50 | { | 
|---|
| 51 | Vector temp; | 
|---|
| 52 | // dissect by "," | 
|---|
| 53 | typedef boost::tokenizer<boost::char_separator<char> > tokenizer; | 
|---|
| 54 | boost::char_separator<char> value_separator(",)("); | 
|---|
| 55 |  | 
|---|
| 56 | bool status = true; | 
|---|
| 57 | tokenizer tokens(_string, value_separator); | 
|---|
| 58 | if (!_string.empty()) { | 
|---|
| 59 | tokenizer::iterator tok_iter = tokens.begin(); | 
|---|
| 60 | for (size_t i=0;i<NDIM;++i) { | 
|---|
| 61 | if (tok_iter == tokens.end()) { | 
|---|
| 62 | status = false; | 
|---|
| 63 | break; | 
|---|
| 64 | } | 
|---|
| 65 | temp[i] = boost::lexical_cast<double>(*(tok_iter++)); | 
|---|
| 66 | } | 
|---|
| 67 | } | 
|---|
| 68 | if (!status) | 
|---|
| 69 | temp.Zero(); | 
|---|
| 70 |  | 
|---|
| 71 | return temp; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | Vector VectorValue::toVector() const | 
|---|
| 75 | { | 
|---|
| 76 | Vector returnVector = parseAsVector(vectorstring); | 
|---|
| 77 |  | 
|---|
| 78 | return returnVector; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | BoxVector VectorValue::toBoxVector(Box &_box) const | 
|---|
| 82 | { | 
|---|
| 83 | BoxVector returnVector; | 
|---|
| 84 | static_cast<Vector>(returnVector) = parseAsVector(vectorstring); // under its hood it's still a Vector | 
|---|
| 85 |  | 
|---|
| 86 | ASSERT(_box.isValid(returnVector), | 
|---|
| 87 | "VectorValue::toBoxVector() - vector "+toString(toVector())+" does not lie within box "+toString(_box)+"."); | 
|---|
| 88 |  | 
|---|
| 89 | return returnVector; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | RealSpaceMatrix RealSpaceMatrixValue::toRealSpaceMatrix() const | 
|---|
| 93 | { | 
|---|
| 94 | RealSpaceMatrix returnMatrix(ReturnFullMatrixforSymmetric(matrix)); | 
|---|
| 95 |  | 
|---|
| 96 | return returnMatrix; | 
|---|
| 97 | } | 
|---|