1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2    Copyright (c) 2011-2021 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.org for more information.
6 
7    This file is part of plumed, version 2.
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 #ifndef __PLUMED_tools_Units_h
23 #define __PLUMED_tools_Units_h
24 
25 #include <string>
26 
27 namespace PLMD {
28 
29 /**
30 \ingroup TOOLBOX
31 Small utility class that contains information about units.
32 
33 This class can be used to contain in a single place all the
34 information about units. Units are expressed in terms of
35 standard PLUMED units, i.e. kj/mol, nm, and ps.
36 Units can be set as double or as string. In the latter case,
37 one can also use strings such as kcal/mol.
38 
39 
40 */
41 class Units {
42 /// Units for energy, expressed in kj/mol (e.g. 4.184 means kcal/mol)
43   double energy;
44   std::string energyString;
45 /// Units for length, expressed in nm (e.g. 0.1 means A)
46   double length;
47   std::string lengthString;
48 /// Units for time, expressed in ps (e.g. 0.001 means fs)
49   double time;
50   std::string timeString;
51 /// Units for charges, expressed in proton charge (e.g. 1./18.2223 are sqrt(kcal/mol*A), as used in Amber)
52   double charge;
53   std::string chargeString;
54 /// Units for masses, expressed in amu
55   double mass;
56   std::string massString;
57 public:
58 /// Constructor, setting default values (1.0)
59   Units();
60 /// Set energy units from string.
61 /// Also understands the following strings:
62 /// kj/mol, kcal/mol, j/mol, eV, and Ha.
63   void setEnergy(const std::string &);
64 /// Set time units from string.
65 /// Also understands the following strings:
66 /// ps, ns, fs, and atomic.
67   void setTime(const std::string &);
68 /// Set length units from string.
69 /// Also understands the following strings:
70 /// nm, A, um, and Bohr.
71   void setLength(const std::string &);
72 /// Set charge units from string.
73   void setCharge(const std::string &);
74 /// Set mass units from string.
75   void setMass(const std::string &);
76 /// Set energy units from double.
77 /// Should be specified in units of kj/mol (e.g. 4.184 means kcal/mol)
78   void setEnergy(double);
79 /// Set time units from double.
80 /// Should be specified in units of ps (e.g. 0.001 means fs)
81   void setTime(double);
82 /// Set length units from double.
83 /// Should be specified in units of nm (e.g. 0.1 means A)
84   void setLength(double);
85 /// Set charge units from double.
86 /// Should be specified in units of proton charge.
87   void setCharge(double);
88 /// Set mass units from double.
89 /// Should be specified in units of amu.
90   void setMass(double);
91 /// Get energy units as double.
92   const double & getEnergy()const;
93 /// Get length units as double.
94   const double & getLength()const;
95 /// Get time units as double.
96   const double & getTime()const;
97 /// Get charge units as double.
98   const double & getCharge()const;
99 /// Get mass units as double.
100   const double & getMass()const;
101 /// Get energy units as string.
102   const std::string & getEnergyString()const;
103 /// Get length units as string.
104   const std::string & getLengthString()const;
105 /// Get time units as string.
106   const std::string & getTimeString()const;
107 /// Get charge units as string.
108   const std::string & getChargeString()const;
109 /// Get mass units as string.
110   const std::string & getMassString()const;
111 };
112 
113 inline
getEnergy()114 const double & Units::getEnergy()const {
115   return energy;
116 }
117 
118 inline
getLength()119 const double & Units::getLength()const {
120   return length;
121 }
122 
123 inline
getTime()124 const double & Units::getTime()const {
125   return time;
126 }
127 
128 inline
getCharge()129 const double & Units::getCharge()const {
130   return charge;
131 }
132 
133 inline
getMass()134 const double & Units::getMass()const {
135   return mass;
136 }
137 
138 inline
getEnergyString()139 const std::string & Units::getEnergyString()const {
140   return energyString;
141 }
142 
143 inline
getLengthString()144 const std::string & Units::getLengthString()const {
145   return lengthString;
146 }
147 
148 inline
getTimeString()149 const std::string & Units::getTimeString()const {
150   return timeString;
151 }
152 
153 inline
getChargeString()154 const std::string & Units::getChargeString()const {
155   return chargeString;
156 }
157 
158 inline
getMassString()159 const std::string & Units::getMassString()const {
160   return massString;
161 }
162 
163 
164 
165 }
166 
167 #endif
168