1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2 * $Id: molprop_util.c,v 1.51 2009/06/01 06:13:18 spoel Exp $
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2008, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Groningen Machine for Chemical Simulation
40 double convert2gmx(double x, int unit)
53 return x*ONE_4PI_EPS0/BOHR2NM;
55 return x*ONE_4PI_EPS0/BOHR2NM;
57 return x*A2NM*A2NM*A2NM;
65 return x*A2NM*DEBYE2ENM;
67 fprintf(stderr, "Unknown unit %d, not converting.\n", unit);
72 double gmx2convert(double x, int unit)
85 return x/(ONE_4PI_EPS0/BOHR2NM);
87 return x/(ONE_4PI_EPS0/BOHR2NM);
89 return x/(A2NM*A2NM*A2NM);
97 return x/(A2NM*DEBYE2ENM);
99 fprintf(stderr, "Unknown unit %d, not converting.\n", unit);
104 /* This has to have the same order as the enums. */
105 static const char *eg2c_names[eg2cNR] = {
106 "Angstrom", "Nm", "Bohr", "Kcal_Mole",
107 "Hartree", "Hartree_e", "Angstrom3", "Coulomb",
108 "Debye", "Electron", "Buckingham"
111 int string2unit(char *string)
115 for (i = 0; (i < eg2cNR); i++)
117 if (gmx_strcasecmp(string, eg2c_names[i]) == 0)
125 const char *unit2string(int unit)
127 if ((unit >= 0) && (unit < eg2cNR))
129 return eg2c_names[unit];