6134f954b5d0faa87c8338356343e59ef7cfe2f5
[alexxy/gromacs.git] / src / gromacs / legacyheaders / physics.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, 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
38 #ifndef _physics_h
39 #define _physics_h
40
41 /*
42  * Physical constants to be used in Gromacs.
43  * No constants (apart from 0, 1 or 2) should
44  * be anywhere else in the code.
45  */
46
47 #include "../math/utilities.h"
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 #define ANGSTROM     (1e-10)                               /* Old...    */
54 #define KILO         (1e3)                                 /* Thousand  */
55 #define NANO         (1e-9)                                /* A Number  */
56 #define PICO         (1e-12)                               /* A Number  */
57 #define A2NM         (ANGSTROM/NANO)                       /* NANO              */
58 #define NM2A         (NANO/ANGSTROM)                       /* 10.0              */
59 #define RAD2DEG      (180.0/M_PI)                          /* Conversion        */
60 #define DEG2RAD      (M_PI/180.0)                          /* id                */
61 #define CAL2JOULE    (4.184)                               /* id                */
62 #define E_CHARGE         (1.60217733e-19)                  /* Coulomb   */
63
64 #define AMU              (1.6605402e-27)                   /* kg           */
65 #define BOLTZMANN    (1.380658e-23)                        /* (J/K)     */
66 #define AVOGADRO     (6.0221367e23)                        /* ()                */
67 #define RGAS             (BOLTZMANN*AVOGADRO)              /* (J/(mol K))  */
68 #define BOLTZ            (RGAS/KILO)                       /* (kJ/(mol K)) */
69 #define FARADAY          (E_CHARGE*AVOGADRO)               /* (C/mol)      */
70 #define ELECTRONVOLT     (E_CHARGE*AVOGADRO/KILO)          /* (kJ/mol)   */
71 #define PLANCK1          (6.6262e-34)                      /* J s */
72 #define PLANCK           (6.6262e-34*AVOGADRO/(PICO*KILO)) /* (kJ/mol) ps */
73
74 #define EPSILON0     (5.72765E-4)                          /* (e^2 / Na (kJ nm))
75                                                               == (e^2 mol/(kJ nm)) */
76
77 #define SPEED_OF_LIGHT   (2.9979245800E05)                 /* nm/ps                */
78 #define ATOMICMASS_keV   (940000.0)                        /* Atomic mass in keV   */
79 #define ELECTRONMASS_keV (512.0)                           /* Electron mas in keV  */
80
81 /* Improved accuracy (PL & EL, 20090421) */
82 #define FACEL        (332.0636930*CAL2JOULE) /* (10 * (ONE_4PI_EPS0)) */
83 #define ONE_4PI_EPS0     (FACEL*0.1)         /* 1/(4*pi*e0)*/
84 #define PRESFAC           (16.6054)          /* bar / pressure unity */
85 #define ENM2DEBYE         48.0321            /* Convert electron nm  *
86                                               * to debye             */
87 #define DEBYE2ENM         0.02081941
88 /* to convert from a acceleration in (e V)/(amu nm) */
89 /* FIELDFAC is also Faraday's constant and E_CHARGE/(1e6 AMU) */
90 #define FIELDFAC          (FARADAY/KILO)
91
92 /* to convert AU to MD units: */
93 #define HARTREE2KJ        4.3597482e-21
94 #define BOHR2NM           0.0529177249
95 #define HARTREE_BOHR2MD   (HARTREE2KJ*AVOGADRO/BOHR2NM)
96
97
98 /* The four basic units */
99 #define unit_length   "nm"
100 #define unit_time     "ps"
101 #define unit_mass     "u"
102 #define unit_energy   "kJ/mol"
103
104 /* Temperature unit, T in this unit times BOLTZ give energy in unit_energy */
105 #define unit_temp_K   "K"
106
107 /* Charge unit, electron charge, involves ONE_4PI_EPS0 */
108 #define unit_charge_e "e"
109
110 /* Pressure unit, pressure in basic units times PRESFAC gives this unit */
111 #define unit_pres_bar "bar"
112
113 /* Dipole unit, debye, conversion from the unit_charge_e involves ENM2DEBYE */
114 #define unit_dipole_D "D"
115
116 /* Derived units from basic units only */
117 #define unit_vel      unit_length "/" unit_time
118 #define unit_volume   unit_length "^3"
119 #define unit_invtime  "1/" unit_time
120
121 /* Other derived units */
122 #define unit_surft_bar unit_pres_bar " " unit_length
123
124 /* SI units, conversion from basic units involves NANO, PICO and AMU */
125 #define unit_length_SI  "m"
126 #define unit_time_SI    "s"
127 #define unit_mass_SI    "kg"
128
129 #define unit_density_SI unit_mass_SI "/" unit_length_SI "^3"
130 #define unit_invvisc_SI unit_length_SI " " unit_time_SI "/" unit_mass_SI
131
132 /* The routines below can be used for converting units from or to GROMACS
133    internal units. */
134 enum {
135     eg2cAngstrom, eg2cNm, eg2cBohr, eg2cKcal_Mole,
136     eg2cHartree, eg2cHartree_e, eg2cAngstrom3, eg2cCoulomb,
137     eg2cDebye, eg2cElectron, eg2cBuckingham, eg2cNR
138 };
139
140 /* Convert value x to GROMACS units. Energy -> Energy, Length -> Length etc.
141    The type of x is deduced from unit,
142    which should be taken from the enum above. */
143 extern double convert2gmx(double x, int unit);
144
145 /* Convert value x from GROMACS units to the desired one.
146    The type of return value is deduced from unit, see above */
147 extern double gmx2convert(double x, int unit);
148
149 /* Convert the string to one of the units supported. Returns -1 if not found. */
150 extern int string2unit(char *string);
151
152 /* Convert the unit to a string. Return NULL when unit is out of range. */
153 extern const char *unit2string(int unit);
154
155 #ifdef __cplusplus
156 }
157 #endif
158
159
160 #endif  /* _physics_h */