Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2018 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 "core/ActionSetup.h"
23 : #include "core/ActionRegister.h"
24 : #include "core/PlumedMain.h"
25 : #include "core/Atoms.h"
26 : #include "tools/Exception.h"
27 :
28 : using namespace std;
29 :
30 : namespace PLMD {
31 : namespace setup {
32 :
33 : //+PLUMEDOC GENERIC UNITS
34 : /*
35 : This command sets the internal units for the code. A new unit can be set by either
36 : specifying how to convert from the plumed default unit into that new unit or by using
37 : the shortcuts described below. This directive MUST appear at the BEGINNING of the
38 : plumed.dat file. The same units must be used througout the plumed.dat file.
39 :
40 : Notice that all input/output will then be made using the specified units.
41 : That is: all the input parameters, all the output files, etc. The only
42 : exceptions are file formats for which there is a specific convention concerning
43 : the units. For example, trajectories written in .gro format (with \ref DUMPATOMS)
44 : are going to be always in nm.
45 :
46 : \par Examples
47 :
48 : \verbatim
49 : # this is using nm - kj/mol - fs
50 : UNITS LENGTH=nm TIME=fs
51 : \endverbatim
52 : If a number, x, is found, the new unit is equal to x (default units)
53 : \verbatim
54 : # this is using nm - kj/mol - fs
55 : UNITS LENGTH=nm TIME=0.001
56 : \endverbatim
57 :
58 :
59 : */
60 : //+ENDPLUMEDOC
61 :
62 24 : class Units :
63 : public virtual ActionSetup
64 : {
65 : public:
66 : static void registerKeywords( Keywords& keys );
67 : explicit Units(const ActionOptions&ao);
68 : };
69 :
70 2535 : PLUMED_REGISTER_ACTION(Units,"UNITS")
71 :
72 13 : void Units::registerKeywords( Keywords& keys ) {
73 13 : ActionSetup::registerKeywords(keys);
74 13 : keys.add("optional","LENGTH","the units of lengths. Either specify a conversion factor from the default, nm, or A (for angstroms) or um");
75 13 : keys.add("optional","ENERGY","the units of energy. Either specify a conversion factor from the default, kj/mol, or use j/mol or kcal/mol");
76 13 : keys.add("optional","TIME","the units of time. Either specify a conversion factor from the default, ps, or use ns or fs");
77 13 : keys.add("optional","MASS","the units of masses. Specify a conversion factor from the default, amu");
78 13 : keys.add("optional","CHARGE","the units of charges. Specify a conversion factor from the default, e");
79 13 : keys.addFlag("NATURAL",false,"use natural units");
80 13 : }
81 :
82 12 : Units::Units(const ActionOptions&ao):
83 : Action(ao),
84 12 : ActionSetup(ao)
85 : {
86 12 : PLMD::Units u;
87 :
88 24 : std::string s;
89 :
90 12 : s="";
91 12 : parse("LENGTH",s);
92 12 : if(s.length()>0) u.setLength(s);
93 12 : if(u.getLengthString().length()>0) log.printf(" length: %s\n",u.getLengthString().c_str());
94 2 : else log.printf(" length: %f nm\n",u.getLength());
95 :
96 12 : s="";
97 12 : parse("ENERGY",s);
98 12 : if(s.length()>0) u.setEnergy(s);
99 12 : if(u.getEnergyString().length()>0) log.printf(" energy: %s\n",u.getEnergyString().c_str());
100 2 : else log.printf(" energy: %f kj/mol\n",u.getEnergy());
101 :
102 12 : s="";
103 12 : parse("TIME",s);
104 12 : if(s.length()>0) u.setTime(s);
105 12 : if(u.getTimeString().length()>0) log.printf(" time: %s\n",u.getTimeString().c_str());
106 2 : else log.printf(" time: %f ps\n",u.getTime());
107 :
108 12 : s="";
109 12 : parse("CHARGE",s);
110 12 : if(s.length()>0) u.setCharge(s);
111 12 : if(u.getChargeString().length()>0) log.printf(" charge: %s\n",u.getChargeString().c_str());
112 2 : else log.printf(" charge: %f e\n",u.getCharge());
113 :
114 12 : s="";
115 12 : parse("MASS",s);
116 12 : if(s.length()>0) u.setMass(s);
117 12 : if(u.getMassString().length()>0) log.printf(" mass: %s\n",u.getMassString().c_str());
118 1 : else log.printf(" mass: %f amu\n",u.getMass());
119 :
120 12 : bool natural=false;
121 12 : parseFlag("NATURAL",natural);
122 12 : plumed.getAtoms().setNaturalUnits(natural);
123 :
124 12 : checkRead();
125 :
126 12 : plumed.getAtoms().setUnits(u);
127 12 : if(natural) {
128 5 : log.printf(" using natural units\n");
129 : } else {
130 7 : log.printf(" using physical units\n");
131 : }
132 24 : log.printf(" inside PLUMED, Boltzmann constant is %f\n",plumed.getAtoms().getKBoltzmann());
133 12 : }
134 :
135 : }
136 2523 : }
137 :
|