Debian Codegraph @

avogadro/core/avogadrocore.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CORE_H
7 #define AVOGADRO_CORE_H
8
9 #include <cstddef>
10 #include <limits>
11
12 /** Prevent compiler error when using std::numeric_limits<T>::max() */
13 #if defined(_MSC_VER) && defined(max)
14 #undef max
15 #endif
16
17 /**
18 * This macro marks a parameter as unused. Its purpose is to disable the
19 * compiler from emitting unused parameter warnings.
20 */
21 #define AVO_UNUSED(variable) (void)variable
22
23 /**
24 * This macro marks a class as not copyable. It should be used in the private
25 * section of a class's declaration.
26 */
27 #define AVO_DISABLE_COPY(Class) \
28 Class(const Class&); \
29 Class& operator=(const Class&);
30
31 namespace Avogadro {
32
33 /** Typedef for a real number. */
34 using Real = double;
35
36 /** Typedef for indices and sizes. */
37 using Index = size_t;
38 inline constexpr Index MaxIndex = std::numeric_limits<Index>::max();
39
40 /** Used to represent an invalid atomic number. */
41 constexpr unsigned char InvalidElement = 255;
42
43 /**
44 * Minimum value for atomic numbers that represent custom, non-elemental
45 * particles. */
46 constexpr unsigned char CustomElementMin = 128;
47
48 /**
49 * Maximum value for atomic numbers that represent custom, non-elemental
50 * particles. */
51 constexpr unsigned char CustomElementMax = 254;
52
53 /**
54 * Count of atomic number values that are used to represent custom,
55 * non-elemental particles. */
56 inline constexpr unsigned char CustomElementCount =
57 CustomElementMax - CustomElementMin + 1;
58
59 namespace Core {
60 /**
61 * @return True if @a atomicNumber denotes a custom element type.
62 */
63 constexpr bool isCustomElement(unsigned char atomicNumber)
64 {
65 return atomicNumber >= CustomElementMin && atomicNumber <= CustomElementMax;
66 }
67 } // namespace Core
68
69 /** Unit conversion factors. @{ */
70 constexpr double PI_D = 3.141592653589793238462643;
71 constexpr float PI_F = static_cast<float>(PI_D);
72 constexpr Real PI = static_cast<Real>(PI_D);
73
74 constexpr double DEG_TO_RAD_D = PI_D / 180.0;
75 constexpr float DEG_TO_RAD_F = static_cast<float>(DEG_TO_RAD_D);
76 constexpr Real DEG_TO_RAD = static_cast<Real>(DEG_TO_RAD_D);
77
78 constexpr double RAD_TO_DEG_D = 180.0 / PI_D;
79 constexpr float RAD_TO_DEG_F = static_cast<float>(RAD_TO_DEG_D);
80 constexpr Real RAD_TO_DEG = static_cast<Real>(RAD_TO_DEG_D);
81
82 // from NIST
83 constexpr double BOHR_TO_ANGSTROM_D = 0.529177210544;
84 constexpr float BOHR_TO_ANGSTROM_F = static_cast<float>(BOHR_TO_ANGSTROM_D);
85 constexpr Real BOHR_TO_ANGSTROM = static_cast<Real>(BOHR_TO_ANGSTROM_D);
86
87 constexpr double ANGSTROM_TO_BOHR_D = 1.0 / BOHR_TO_ANGSTROM_D;
88 constexpr float ANGSTROM_TO_BOHR_F = static_cast<float>(ANGSTROM_TO_BOHR_D);
89 constexpr Real ANGSTROM_TO_BOHR = static_cast<Real>(ANGSTROM_TO_BOHR_D);
90
91 constexpr double HARTREE_TO_EV_D = 27.211386245981;
92 constexpr float HARTREE_TO_EV_F = static_cast<float>(HARTREE_TO_EV_D);
93 constexpr Real HARTREE_TO_EV = static_cast<Real>(HARTREE_TO_EV_D);
94 /** @} */
95
96 } // namespace Avogadro
97
98 #endif // AVOGADRO_CORE_H