| [528b3e] | 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/>. | 
|---|
| [528b3e] | 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 |  | 
|---|
| [9eb71b3] | 35 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| [528b3e] | 36 |  | 
|---|
|  | 37 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 38 |  | 
|---|
| [cb5231] | 39 | #include <boost/lexical_cast.hpp> | 
|---|
|  | 40 | #include <boost/tokenizer.hpp> | 
|---|
|  | 41 |  | 
|---|
| [33e801] | 42 | #include "Box.hpp" | 
|---|
| [528b3e] | 43 | #include "LinearAlgebra/BoxVector.hpp" | 
|---|
|  | 44 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
|  | 45 | #include "LinearAlgebra/Vector.hpp" | 
|---|
|  | 46 |  | 
|---|
|  | 47 | #include "Values.hpp" | 
|---|
|  | 48 |  | 
|---|
| [cb5231] | 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 |  | 
|---|
| [528b3e] | 74 | Vector VectorValue::toVector() const | 
|---|
|  | 75 | { | 
|---|
| [cb5231] | 76 | Vector returnVector = parseAsVector(vectorstring); | 
|---|
| [528b3e] | 77 |  | 
|---|
|  | 78 | return returnVector; | 
|---|
|  | 79 | } | 
|---|
|  | 80 |  | 
|---|
|  | 81 | BoxVector VectorValue::toBoxVector(Box &_box) const | 
|---|
|  | 82 | { | 
|---|
|  | 83 | BoxVector returnVector; | 
|---|
| [cb5231] | 84 | static_cast<Vector>(returnVector) = parseAsVector(vectorstring); // under its hood it's still a Vector | 
|---|
| [528b3e] | 85 |  | 
|---|
| [2a0271] | 86 | ASSERT(_box.isValid(returnVector), | 
|---|
| [528b3e] | 87 | "VectorValue::toBoxVector() - vector "+toString(toVector())+" does not lie within box "+toString(_box)+"."); | 
|---|
|  | 88 |  | 
|---|
|  | 89 | return returnVector; | 
|---|
|  | 90 | } | 
|---|
|  | 91 |  | 
|---|
| [7d9416] | 92 | RealSpaceMatrix RealSpaceMatrixValue::toRealSpaceMatrix() const | 
|---|
| [528b3e] | 93 | { | 
|---|
| [7d9416] | 94 | RealSpaceMatrix returnMatrix(ReturnFullMatrixforSymmetric(matrix)); | 
|---|
| [528b3e] | 95 |  | 
|---|
| [7d9416] | 96 | return returnMatrix; | 
|---|
| [528b3e] | 97 | } | 
|---|