Enable clang-tidy for headers
[alexxy/gromacs.git] / src / gromacs / math / units.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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,2018, 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #ifndef GMX_MATH_UNITS_H
38 #define GMX_MATH_UNITS_H
39
40 /*
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.
44  */
45
46 #include "gromacs/math/utilities.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
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 */
62
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 */
72
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))
76
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  */
80
81 #define RYDBERG          (1.0973731568539e-02)             /* nm^-1, NIST 2010 CODATA */
82
83 #define ONE_4PI_EPS0     (1.0/(4.0*M_PI*EPSILON0))
84 #define FACEL            (10.0*ONE_4PI_EPS0)
85
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
88  */
89 #define BAR_MDUNITS      (1e5*NANO*PICO*PICO/AMU)
90 #define PRESFAC          (1.0/BAR_MDUNITS)
91
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.
94  */
95 #define DEBYE2ENM        (1e-15/(SPEED_OF_LIGHT*E_CHARGE))
96 #define ENM2DEBYE        (1.0/DEBYE2ENM)
97
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)
101
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)
106
107
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"
113
114 /* Temperature unit, T in this unit times BOLTZ give energy in unit_energy */
115 #define unit_temp_K   "K"
116
117 /* Charge unit, electron charge, involves ONE_4PI_EPS0 */
118 #define unit_charge_e "e"
119
120 /* Pressure unit, pressure in basic units times PRESFAC gives this unit */
121 #define unit_pres_bar "bar"
122
123 /* Dipole unit, debye, conversion from the unit_charge_e involves ENM2DEBYE */
124 #define unit_dipole_D "D"
125
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
130
131 /* Other derived units */
132 #define unit_surft_bar unit_pres_bar " " unit_length
133
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"
138
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
141
142 /* The routines below can be used for converting units from or to GROMACS
143    internal units. */
144 enum {
145     eg2cAngstrom, eg2cNm, eg2cBohr, eg2cKcal_Mole,
146     eg2cHartree, eg2cHartree_e, eg2cAngstrom3, eg2cCoulomb,
147     eg2cDebye, eg2cElectron, eg2cBuckingham, eg2cNR
148 };
149
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);
154
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);
158
159 /* Convert the string to one of the units supported. Returns -1 if not found. */
160 extern int string2unit(char *string);
161
162 /* Convert the unit to a string. Return NULL when unit is out of range. */
163 extern const char *unit2string(int unit);
164
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif