-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geometry.hh
205 lines (187 loc) · 4.94 KB
/
Geometry.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef GEOMETRY_HH
#define GEOMETRY_HH
/*!
* \file Geometry.hh
* \brief Definition of the Geometry class
*/
#include <vector>
#include <Eigen/Core>
#include "io/JobIStream.hh"
/*!
* \brief The geometry of the system
*
* Class Geometry hold the positions and atom types of the nuclei in the
* system.
*/
class Geometry
{
public:
/*!
* \brief Constructor
*
* Create a new, empty Geometry
*/
Geometry(): _positions(), _masses(), _charges(), _symbols() {}
//! Return the number of atoms in the Geometry
int size() const { return _positions.cols(); }
//! Return the element symbol of atom \a idx
const std::string& symbol(int idx) const
{
checkIndex(idx);
return _symbols[idx];
}
//! Return the nuclear charges of the atoms
const Eigen::VectorXd& charges() const
{
return _charges;
}
//! Return the total charge of the the nuclei
double totalCharge() const
{
return _charges.sum();
}
//! Return the energy due to mutual repulsion of the nuclei
double nuclearRepulsion() const;
//! Return the masses of the atoms
const Eigen::VectorXd& masses() const
{
return _masses;
}
//! Return the position of atom \a idx
Eigen::Vector3d position(int idx) const
{
checkIndex(idx);
return _positions.col(idx);
}
//! Return tthe positions of the atoms
const Eigen::MatrixXd& positions() const
{
return _positions;
}
//! Compute the moment of inertia tensor for this molecule
Eigen::Matrix3d inertia() const;
/*!
* \brief Change the size of the Geometry
*
* Change the number of atoms in the Geometry to \a n. Any information
* currently in the Geometry will be lost.
*/
void resize(int n)
{
_positions.resize(3, n);
_masses.resize(n);
_charges.resize(n);
_symbols.resize(n);
}
/*!
* \brief Set an atom
*
* On position \a idx in this Geometry, place an atom with element symbol
* \a symbol at position (\a x, \a y, \a z). Any previous atom with the
* same index will be overwritten.
* \param idx The index of the atom in this Geometry
* \param symbol The element symbol of the atom
* \param x The x-coordinate of the atom
* \param y The y-coordinate of the atom
* \param z The z-coordinate of the atom
* \exception UnknownElement throw when the element symbol
* cannot be found in the periodic table.
*/
void setAtom(int idx, const std::string& symbol, double x, double y,
double z);
/*!
* \brief Update the position of an atom
*
* Set the position of the atom at index \a idx to \a pos.
* \param idx The index of the atom in this Geometry
* \param pos The new position of the atom
*/
void setPosition(int idx, const Eigen::Vector3d& pos)
{
checkIndex(idx);
_positions.col(idx) = pos;
}
/*!
* \brief Rotate to a principal axis frame
*
* Shift and rotate the system so that its center of mass is located at
* the origin, and its principal axes align with the \f$x\f$, \f$y\f$
* and \f$z\f$ axes.
*/
void toPrincipalAxes();
/*!
* \brief print this Geometry
*
* Write a textual representation of this Geometry to output stream
* \a os.
* \param os The output stream to write to
* \return The updated output stream
*/
std::ostream& print(std::ostream& os) const;
/*!
* \brief Read a Geometry
*
* Read a description of this geometry from input stream \a is. The
* geometry can be given either in XYZ coordinates, or in Z-matrix
* format.
* \param is The input stream to read from
* \return The updated input stream
*/
JobIStream& scan(JobIStream& is);
private:
//! The positions of the atoms
Eigen::MatrixXd _positions;
//! The mass of the atoms
Eigen::VectorXd _masses;
//! The charges of the atoms
Eigen::VectorXd _charges;
//! The atom symbols
std::vector<std::string> _symbols;
/*!
* \brief Check if an atom index is valid
*
* Check if \a idx is a valid atom index in this Geometry. The check is
* only performed if the program is compiled with the DEBUG symbol
* defined.
* \param idx The atom index to check
* \exception InvalidIndex thrown when the index is out of bounds
*/
#ifdef DEBUG
void checkIndex(int idx) const
{
if (idx < 0 || idx >= size())
throw InvalidIndex(idx);
}
#else
void checkIndex(int) const {}
#endif
};
namespace {
/*!
* \brief print a Geometry
*
* Write a textual representation of Geometry \a geom to output stream \a os.
* \param os The output stream to write to
* \param geom The Geometry to print
* \return The updated output stream
*/
inline std::ostream& operator<<(std::ostream& os, const Geometry& geom)
{
return geom.print(os);
}
/*!
* \brief Read a Geometry
*
* Read a description of a geometry from input stream \a is and store it
* in \a geom. The geometry can be given either in XYZ coordinates, or in
* Z-matrix format.
* \param is The input stream to read from
* \param geom The Geomtery to read
* \return The updated input stream
*/
inline JobIStream& operator>>(JobIStream& is, Geometry& geom)
{
return geom.scan(is);
}
} // namespace
#endif // GEOMETRY_HH