2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 #ifndef GMX_MATH_UNITS_H
38 #define GMX_MATH_UNITS_H
41 * Physical constants to be used in Gromacs.
42 * No constants (apart from 0, 1 or 2) should
43 * be anywhere else in the code.
46 #include "gromacs/math/utilities.h"
52 #define ANGSTROM (1e-10) /* Old... */
53 #define KILO (1e3) /* Thousand */
54 #define NANO (1e-9) /* A Number */
55 #define PICO (1e-12) /* A Number */
56 #define A2NM (ANGSTROM/NANO) /* NANO */
57 #define NM2A (NANO/ANGSTROM) /* 10.0 */
58 #define RAD2DEG (180.0/M_PI) /* Conversion */
59 #define DEG2RAD (M_PI/180.0) /* id */
60 #define CAL2JOULE (4.184) /* id */
61 #define E_CHARGE (1.602176565e-19) /* Coulomb, NIST 2010 CODATA */
63 #define AMU (1.660538921e-27) /* kg, NIST 2010 CODATA */
64 #define BOLTZMANN (1.3806488e-23) /* (J/K, NIST 2010 CODATA */
65 #define AVOGADRO (6.02214129e23) /* no unit, NIST 2010 CODATA */
66 #define RGAS (BOLTZMANN*AVOGADRO) /* (J/(mol K)) */
67 #define BOLTZ (RGAS/KILO) /* (kJ/(mol K)) */
68 #define FARADAY (E_CHARGE*AVOGADRO) /* (C/mol) */
69 #define ELECTRONVOLT (E_CHARGE*AVOGADRO/KILO) /* (kJ/mol) */
70 #define PLANCK1 (6.62606957e-34) /* J s, NIST 2010 CODATA */
71 #define PLANCK (PLANCK1*AVOGADRO/(PICO*KILO)) /* (kJ/mol) ps */
73 #define EPSILON0_SI (8.854187817e-12) /* F/m, NIST 2010 CODATA */
74 /* Epsilon in our MD units: (e^2 / Na (kJ nm)) == (e^2 mol/(kJ nm)) */
75 #define EPSILON0 (EPSILON0_SI*NANO*KILO)/(E_CHARGE*E_CHARGE*AVOGADRO)
77 #define SPEED_OF_LIGHT (2.99792458E05) /* nm/ps, NIST 2010 CODATA */
78 #define ATOMICMASS_keV (931494.061) /* Atomic mass in keV, NIST 2010 CODATA */
79 #define ELECTRONMASS_keV (510.998928) /* Electron mas in keV, NIST 2010 CODATA */
81 #define RYDBERG (1.0973731568539e-02) /* nm^-1, NIST 2010 CODATA */
83 #define ONE_4PI_EPS0 (1.0/(4.0*M_PI*EPSILON0))
84 #define FACEL 10.0*ONE_4PI_EPS0
86 /* Pressure in MD units is:
87 * 1 bar = 1e5 Pa = 1e5 kg m^-1 s^-2 = 1e-28 kg nm^-1 ps^-2 = 1e-28 / AMU amu nm^1 ps ^2
89 #define BAR_MDUNITS (1e5*NANO*PICO*PICO/AMU)
90 #define PRESFAC (1.0/BAR_MDUNITS)
92 /* DEBYE2ENM should be (1e-21*PICO)/(SPEED_OF_LIGHT*E_CHARGE*NANO*NANO),
93 * but we need to factor out some of the exponents to avoid single-precision overflows.
95 #define DEBYE2ENM (1e-15/(SPEED_OF_LIGHT*E_CHARGE))
96 #define ENM2DEBYE (1.0/DEBYE2ENM)
98 /* to convert from a acceleration in (e V)/(amu nm) */
99 /* FIELDFAC is also Faraday's constant and E_CHARGE/(1e6 AMU) */
100 #define FIELDFAC (FARADAY/KILO)
102 /* to convert AU to MD units: */
103 #define HARTREE2KJ ((2.0*RYDBERG*PLANCK*SPEED_OF_LIGHT)/AVOGADRO)
104 #define BOHR2NM (0.052917721092) /* nm^-1, NIST 2010 CODATA */
105 #define HARTREE_BOHR2MD (HARTREE2KJ*AVOGADRO/BOHR2NM)
108 /* The four basic units */
109 #define unit_length "nm"
110 #define unit_time "ps"
111 #define unit_mass "u"
112 #define unit_energy "kJ/mol"
114 /* Temperature unit, T in this unit times BOLTZ give energy in unit_energy */
115 #define unit_temp_K "K"
117 /* Charge unit, electron charge, involves ONE_4PI_EPS0 */
118 #define unit_charge_e "e"
120 /* Pressure unit, pressure in basic units times PRESFAC gives this unit */
121 #define unit_pres_bar "bar"
123 /* Dipole unit, debye, conversion from the unit_charge_e involves ENM2DEBYE */
124 #define unit_dipole_D "D"
126 /* Derived units from basic units only */
127 #define unit_vel unit_length "/" unit_time
128 #define unit_volume unit_length "^3"
129 #define unit_invtime "1/" unit_time
131 /* Other derived units */
132 #define unit_surft_bar unit_pres_bar " " unit_length
134 /* SI units, conversion from basic units involves NANO, PICO and AMU */
135 #define unit_length_SI "m"
136 #define unit_time_SI "s"
137 #define unit_mass_SI "kg"
139 #define unit_density_SI unit_mass_SI "/" unit_length_SI "^3"
140 #define unit_invvisc_SI unit_length_SI " " unit_time_SI "/" unit_mass_SI
142 /* The routines below can be used for converting units from or to GROMACS
145 eg2cAngstrom
, eg2cNm
, eg2cBohr
, eg2cKcal_Mole
,
146 eg2cHartree
, eg2cHartree_e
, eg2cAngstrom3
, eg2cCoulomb
,
147 eg2cDebye
, eg2cElectron
, eg2cBuckingham
, eg2cNR
150 /* Convert value x to GROMACS units. Energy -> Energy, Length -> Length etc.
151 The type of x is deduced from unit,
152 which should be taken from the enum above. */
153 extern double convert2gmx(double x
, int unit
);
155 /* Convert value x from GROMACS units to the desired one.
156 The type of return value is deduced from unit, see above */
157 extern double gmx2convert(double x
, int unit
);
159 /* Convert the string to one of the units supported. Returns -1 if not found. */
160 extern int string2unit(char *string
);
162 /* Convert the unit to a string. Return NULL when unit is out of range. */
163 extern const char *unit2string(int unit
);