Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2019 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 : #include "Units.h"
23 : #include "Tools.h"
24 :
25 : using namespace std;
26 :
27 : namespace PLMD {
28 :
29 5001 : 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 : charge(1.0),
37 : chargeString("e"),
38 : mass(1.0),
39 5001 : massString("amu")
40 : {
41 5001 : }
42 :
43 5 : void Units::setEnergy(const std::string &s) {
44 5 : energyString=s;
45 5 : if(s=="kj/mol") {
46 3 : energy=1.0;
47 2 : } else if(s=="kcal/mol") {
48 0 : energy=4.184;
49 2 : } else if(s=="j/mol") {
50 0 : energy=0.001;
51 2 : } else if(s=="eV") {
52 0 : energy=96.48530749925792;
53 : } else {
54 2 : energy=-1.0;
55 : energyString="";
56 2 : Tools::convert(s,energy);
57 2 : plumed_massert(energy>0.0,"energy units should be positive");
58 : }
59 5 : }
60 :
61 26 : void Units::setLength(const std::string &s) {
62 26 : lengthString=s;
63 26 : if(s=="nm") {
64 2 : length=1.0;
65 24 : } else if(s=="A") {
66 18 : length=0.1;
67 6 : } else if(s=="um") {
68 0 : length=1000.0;
69 : } else {
70 6 : length=-1.0;
71 : lengthString="";
72 6 : Tools::convert(s,length);
73 6 : plumed_massert(length>0.0,"length units should be positive");
74 : }
75 26 : }
76 :
77 2 : void Units::setTime(const std::string &s) {
78 2 : timeString=s;
79 2 : if(s=="ps") {
80 0 : time=1.0;
81 2 : } else if(s=="ns") {
82 0 : time=1000.0;
83 2 : } else if(s=="fs") {
84 0 : time=0.001;
85 : } else {
86 2 : time=-1.0;
87 : timeString="";
88 2 : Tools::convert(s,time);
89 2 : plumed_massert(time>0.0,"time units should be positive");
90 : }
91 2 : }
92 :
93 3 : void Units::setCharge(const std::string &s) {
94 3 : chargeString=s;
95 3 : if(s=="e") {
96 0 : charge=1.0;
97 : } else {
98 3 : charge=-1.0;
99 : chargeString="";
100 3 : Tools::convert(s,charge);
101 3 : plumed_massert(charge>0.0,"charge units should be positive");
102 : }
103 3 : }
104 :
105 2 : void Units::setMass(const std::string &s) {
106 2 : massString=s;
107 2 : if(s=="amu") {
108 0 : mass=1.0;
109 : } else {
110 2 : mass=-1.0;
111 : massString="";
112 2 : Tools::convert(s,mass);
113 2 : plumed_massert(mass>0.0,"mass units should be positive");
114 : }
115 2 : }
116 :
117 37 : void Units::setEnergy(const double s) {
118 37 : energyString="";
119 37 : energy=s;
120 37 : }
121 :
122 512 : void Units::setLength(const double s) {
123 512 : lengthString="";
124 512 : length=s;
125 512 : }
126 :
127 0 : void Units::setTime(const double s) {
128 0 : timeString="";
129 0 : time=s;
130 0 : }
131 :
132 512 : void Units::setCharge(const double s) {
133 512 : chargeString="";
134 512 : charge=s;
135 512 : }
136 :
137 512 : void Units::setMass(const double s) {
138 512 : massString="";
139 512 : mass=s;
140 512 : }
141 :
142 :
143 :
144 : }
145 :
|