Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2020 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 5755 : 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 5755 : massString("amu")
40 : {
41 5755 : }
42 :
43 7 : void Units::setEnergy(const std::string &s) {
44 7 : energyString=s;
45 7 : if(s=="kj/mol") {
46 4 : energy=1.0;
47 3 : } else if(s=="kcal/mol") {
48 0 : energy=4.184;
49 3 : } else if(s=="j/mol") {
50 0 : energy=0.001;
51 3 : } else if(s=="eV") {
52 0 : energy=96.48530749925792;
53 3 : } else if(s =="Ha") {
54 1 : energy=2625.499638;
55 : } else {
56 2 : energy=-1.0;
57 : energyString="";
58 2 : if(!Tools::convert(s,energy)) {
59 0 : plumed_merror("problem with setting the energy unit, either use give an numerical value or use one of the defined units: kj/mol, kcal/mol, j/mol, eV, Ha (case senstive)");
60 : }
61 2 : plumed_massert(energy>0.0,"energy unit should be positive");
62 : }
63 7 : }
64 :
65 29 : void Units::setLength(const std::string &s) {
66 29 : lengthString=s;
67 29 : if(s=="nm") {
68 2 : length=1.0;
69 27 : } else if(s=="A") {
70 20 : length=0.1;
71 7 : } else if(s=="um") {
72 0 : length=1000.0;
73 7 : } else if(s=="Bohr") {
74 1 : length=0.052917721067;
75 : } else {
76 6 : length=-1.0;
77 : lengthString="";
78 6 : if(!Tools::convert(s,length)) {
79 0 : plumed_merror("problem with setting the length unit, either use a numerical value or use one of the defined units: nm, A, um, Bohr (case sensitive)");
80 : }
81 6 : plumed_massert(length>0.0,"length unit should be positive");
82 : }
83 29 : }
84 :
85 3 : void Units::setTime(const std::string &s) {
86 3 : timeString=s;
87 3 : if(s=="ps") {
88 0 : time=1.0;
89 3 : } else if(s=="ns") {
90 0 : time=1000.0;
91 3 : } else if(s=="fs") {
92 0 : time=0.001;
93 3 : } else if(s=="atomic") {
94 1 : time=2.418884326509e-5;
95 : } else {
96 2 : time=-1.0;
97 : timeString="";
98 2 : if(!Tools::convert(s,time)) {
99 0 : plumed_merror("problem with setting the time unit, either use a numerical value or use one of the defined units: ps, fs, atomic (case sensitive)");
100 : }
101 2 : plumed_massert(time>0.0,"time unit should be positive");
102 : }
103 3 : }
104 :
105 4 : void Units::setCharge(const std::string &s) {
106 4 : chargeString=s;
107 4 : if(s=="e") {
108 1 : charge=1.0;
109 : } else {
110 3 : charge=-1.0;
111 : chargeString="";
112 3 : if(!Tools::convert(s,charge)) {
113 0 : plumed_merror("problem with setting the charge unit, either use a numerical value or use one of the defined units: e (case sensitive)");
114 : }
115 3 : plumed_massert(charge>0.0,"charge unit should be positive");
116 : }
117 4 : }
118 :
119 3 : void Units::setMass(const std::string &s) {
120 3 : massString=s;
121 3 : if(s=="amu") {
122 1 : mass=1.0;
123 : } else {
124 2 : mass=-1.0;
125 : massString="";
126 2 : if(!Tools::convert(s,mass)) {
127 0 : plumed_merror("problem with setting the mass unit, either use a numerical value or use one of the defined units: amu (case sensitive)");
128 : }
129 2 : plumed_massert(mass>0.0,"mass unit should be positive");
130 : }
131 3 : }
132 :
133 43 : void Units::setEnergy(const double s) {
134 43 : energyString="";
135 43 : energy=s;
136 43 : }
137 :
138 584 : void Units::setLength(const double s) {
139 584 : lengthString="";
140 584 : length=s;
141 584 : }
142 :
143 5 : void Units::setTime(const double s) {
144 5 : timeString="";
145 5 : time=s;
146 5 : }
147 :
148 584 : void Units::setCharge(const double s) {
149 584 : chargeString="";
150 584 : charge=s;
151 584 : }
152 :
153 584 : void Units::setMass(const double s) {
154 584 : massString="";
155 584 : mass=s;
156 584 : }
157 :
158 :
159 :
160 : }
|