Move physics.* to math/units.*
[gromacs.git] / src / gromacs / math / units.h
blob4859f52e377973711f1df52bd33a891762b2a3fd
1 /*
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, 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 "utilities.h"
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
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.60217733e-19) /* Coulomb */
63 #define AMU (1.6605402e-27) /* kg */
64 #define BOLTZMANN (1.380658e-23) /* (J/K) */
65 #define AVOGADRO (6.0221367e23) /* () */
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.6262e-34) /* J s */
71 #define PLANCK (6.6262e-34*AVOGADRO/(PICO*KILO)) /* (kJ/mol) ps */
73 #define EPSILON0 (5.72765E-4) /* (e^2 / Na (kJ nm))
74 == (e^2 mol/(kJ nm)) */
76 #define SPEED_OF_LIGHT (2.9979245800E05) /* nm/ps */
77 #define ATOMICMASS_keV (940000.0) /* Atomic mass in keV */
78 #define ELECTRONMASS_keV (512.0) /* Electron mas in keV */
80 /* Improved accuracy (PL & EL, 20090421) */
81 #define FACEL (332.0636930*CAL2JOULE) /* (10 * (ONE_4PI_EPS0)) */
82 #define ONE_4PI_EPS0 (FACEL*0.1) /* 1/(4*pi*e0)*/
83 #define PRESFAC (16.6054) /* bar / pressure unity */
84 #define ENM2DEBYE 48.0321 /* Convert electron nm *
85 * to debye */
86 #define DEBYE2ENM 0.02081941
87 /* to convert from a acceleration in (e V)/(amu nm) */
88 /* FIELDFAC is also Faraday's constant and E_CHARGE/(1e6 AMU) */
89 #define FIELDFAC (FARADAY/KILO)
91 /* to convert AU to MD units: */
92 #define HARTREE2KJ 4.3597482e-21
93 #define BOHR2NM 0.0529177249
94 #define HARTREE_BOHR2MD (HARTREE2KJ*AVOGADRO/BOHR2NM)
97 /* The four basic units */
98 #define unit_length "nm"
99 #define unit_time "ps"
100 #define unit_mass "u"
101 #define unit_energy "kJ/mol"
103 /* Temperature unit, T in this unit times BOLTZ give energy in unit_energy */
104 #define unit_temp_K "K"
106 /* Charge unit, electron charge, involves ONE_4PI_EPS0 */
107 #define unit_charge_e "e"
109 /* Pressure unit, pressure in basic units times PRESFAC gives this unit */
110 #define unit_pres_bar "bar"
112 /* Dipole unit, debye, conversion from the unit_charge_e involves ENM2DEBYE */
113 #define unit_dipole_D "D"
115 /* Derived units from basic units only */
116 #define unit_vel unit_length "/" unit_time
117 #define unit_volume unit_length "^3"
118 #define unit_invtime "1/" unit_time
120 /* Other derived units */
121 #define unit_surft_bar unit_pres_bar " " unit_length
123 /* SI units, conversion from basic units involves NANO, PICO and AMU */
124 #define unit_length_SI "m"
125 #define unit_time_SI "s"
126 #define unit_mass_SI "kg"
128 #define unit_density_SI unit_mass_SI "/" unit_length_SI "^3"
129 #define unit_invvisc_SI unit_length_SI " " unit_time_SI "/" unit_mass_SI
131 /* The routines below can be used for converting units from or to GROMACS
132 internal units. */
133 enum {
134 eg2cAngstrom, eg2cNm, eg2cBohr, eg2cKcal_Mole,
135 eg2cHartree, eg2cHartree_e, eg2cAngstrom3, eg2cCoulomb,
136 eg2cDebye, eg2cElectron, eg2cBuckingham, eg2cNR
139 /* Convert value x to GROMACS units. Energy -> Energy, Length -> Length etc.
140 The type of x is deduced from unit,
141 which should be taken from the enum above. */
142 extern double convert2gmx(double x, int unit);
144 /* Convert value x from GROMACS units to the desired one.
145 The type of return value is deduced from unit, see above */
146 extern double gmx2convert(double x, int unit);
148 /* Convert the string to one of the units supported. Returns -1 if not found. */
149 extern int string2unit(char *string);
151 /* Convert the unit to a string. Return NULL when unit is out of range. */
152 extern const char *unit2string(int unit);
154 #ifdef __cplusplus
156 #endif
158 #endif