All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Units.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed 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 Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #include "Units.h"
23 #include "Tools.h"
24 
25 using namespace std;
26 
27 namespace PLMD{
28 
29 Units::Units():
30  energy(1.0),
31  energyString("kj/mol"),
32  length(1.0),
33  lengthString("nm"),
34  time(1.0),
35  timeString("ps")
36 {
37 }
38 
39 void Units::setEnergy(const std::string &s){
40  energyString=s;
41  if(s=="kj/mol"){
42  energy=1.0;
43  } else if(s=="kcal/mol"){
44  energy=4.184;
45  } else if(s=="j/mol"){
46  energy=0.001;
47  } else if(s=="eV"){
48  energy=96.48530749925792;
49  } else {
50  energy=-1.0;
51  energyString="";
53  plumed_massert(energy>0.0,"energy units should be positive");
54  }
55 }
56 
57 void Units::setLength(const std::string &s){
58  lengthString=s;
59  if(s=="nm"){
60  length=1.0;
61  } else if(s=="A"){
62  length=0.1;
63  } else if(s=="um"){
64  length=1000.0;
65  } else {
66  length=-1.0;
67  lengthString="";
69  plumed_massert(length>0.0,"length units should be positive");
70  }
71 }
72 
73 void Units::setTime(const std::string &s){
74  timeString=s;
75  if(s=="ps"){
76  time=1.0;
77  } else if(s=="ns"){
78  time=1000.0;
79  } else if(s=="fs"){
80  time=0.001;
81  } else {
82  time=-1.0;
83  timeString="";
85  plumed_massert(time>0.0,"time units should be positive");
86  }
87 }
88 
89 void Units::setEnergy(const double s){
90  energyString="";
91  energy=s;
92 }
93 
94 void Units::setLength(const double s){
95  lengthString="";
96  length=s;
97 }
98 
99 void Units::setTime(const double s){
100  timeString="";
101  time=s;
102 }
103 
104 }
105 
void setTime(const std::string &)
Set time units from string.
Definition: Units.cpp:73
void setLength(const std::string &)
Set lengh units from string.
Definition: Units.cpp:57
static bool convert(const std::string &str, double &t)
Convert a string to a double, reading it.
Definition: Tools.cpp:74
STL namespace.
double length
Units for length, expressed in nm (e.g. 0.1 means A)
Definition: Units.h:46
std::string lengthString
Definition: Units.h:47
double energy
Units for energy, expressed in kj/mol (e.g. 4.184 means kcal/mol)
Definition: Units.h:43
void setEnergy(const std::string &)
Set energy units from string.
Definition: Units.cpp:39
std::string timeString
Definition: Units.h:50
std::string energyString
Definition: Units.h:44
double time
Units for time, expressed in ps (e.g. 0.001 means fs)
Definition: Units.h:49