OpenMD
3.2
Molecular Dynamics in the Open
Toggle main menu visibility
Loading...
Searching...
No Matches
GenericData.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2004-present, The University of Notre Dame. All rights
3
* reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of the copyright holder nor the names of its
16
* contributors may be used to endorse or promote products derived from
17
* this software without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
30
*
31
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32
* research, please cite the following paper when you publish your work:
33
*
34
* [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35
*
36
* Good starting points for code and simulation methodology are:
37
*
38
* [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39
* [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40
* [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42
* [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43
* [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44
* [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45
* [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46
*/
47
48
/**
49
* @file GenericData.hpp
50
* @brief
51
* @author tlin
52
* @date 09/20/2004
53
* @version 1.0
54
*/
55
56
#ifndef UTIL_GENERICDATA_HPP
57
#define UTIL_GENERICDATA_HPP
58
59
#include <config.h>
60
61
#include <list>
62
#include <string>
63
#include <vector>
64
65
namespace
OpenMD
{
66
67
/**
68
* @ class GenericData GenericData.hpp "utils/GenericData.hpp"
69
* @brief Base class for generic data which is associated with an id
70
*/
71
class
GenericData {
72
public
:
73
GenericData() : id_(
"UndefinedGenericData"
) {}
74
75
GenericData(
const
std::string&
id
) {
setID
(
id
); }
76
77
/** virtual destructor */
78
virtual
~GenericData
() {}
79
80
/**
81
* Returns the id of this generic data
82
*
83
* @return the id of this generic data
84
*
85
* @see #setID
86
*/
87
const
std::string
getID
()
const
{
return
id_; }
88
89
/**
90
* Sets the id of this generic data
91
*
92
* @param id the id to be set
93
*
94
* @see #getID
95
*/
96
void
setID
(
const
std::string&
id
) { id_ = id; }
97
98
private
:
99
GenericData
(
const
GenericData
&);
100
GenericData
& operator=(
GenericData
&);
101
std::string id_;
102
};
103
104
/**
105
* @class SimpleTypeData
106
* @brief SimpleTypeData class is a POD repository class
107
* @warning ElemDataType must be copy constructible, and copy assignable
108
*/
109
template
<
typename
ElemDataType>
110
class
SimpleTypeData :
public
GenericData {
111
public
:
112
SimpleTypeData() : GenericData(), data_(ElemDataType()) {}
113
SimpleTypeData(
const
std::string&
id
) :
114
GenericData(
id
), data_(ElemDataType()) {}
115
SimpleTypeData(
const
std::string&
id
,
const
ElemDataType& data) :
116
GenericData(
id
), data_(data) {}
117
template
<
typename
T>
118
SimpleTypeData(
const
SimpleTypeData<T>& s) {
119
data_ = s.
getData
();
120
}
121
122
SimpleTypeData<ElemDataType>& operator=(
123
const
SimpleTypeData<ElemDataType>& s) {
124
if
(
this
== &s)
return
*
this
;
125
126
data_ = s.
getData
();
127
return
*
this
;
128
}
129
130
template
<
typename
T>
131
SimpleTypeData<ElemDataType>& operator=(
const
SimpleTypeData<T>& s) {
132
data_ = s.
getData
();
133
return
*
this
;
134
}
135
136
/** Returns POD data */
137
const
ElemDataType&
getData
()
const
{
return
data_; }
138
ElemDataType&
getData
() {
return
data_; }
139
/**
140
* Sets POD data
141
* @param data POD data to be set
142
*/
143
void
setData
(
const
ElemDataType& data) { data_ = data; }
144
145
private
:
146
ElemDataType data_;
147
};
148
149
/** BoolGenericData is a generic data type contains a bool variable */
150
using
BoolGenericData
=
SimpleTypeData<bool>
;
151
152
/** IntGenericData is a generic data type contains an integer variable */
153
using
IntGenericData
=
SimpleTypeData<int>
;
154
155
/** FloatGenericData is a generic data type contains a float variable */
156
using
FloatGenericData
=
SimpleTypeData<float>
;
157
158
/** DoubleGenericData is a generic data type contains a RealType variable */
159
using
DoubleGenericData
=
SimpleTypeData<RealType>
;
160
161
/**
162
* @typedef StringGenericData
163
* A generic data type contains a std::string variable
164
*
165
* @code
166
* StringGenericData* s = new StringGenericData("MyStringGenericData");
167
* PropertyMap propMap;
168
* GenericData* gdata;
169
*
170
* s->setData("OpenMD");
171
* propMap->addProperty(s);
172
*
173
* gdata = propMap->getPropertyByName("MyStringGenericData");
174
* if (gdata != NULL){
175
* s = dynamic_cast<StringGenericData*>(gdata);
176
* if (s != NULL)
177
* std::cout << s->getData() << std::endl;
178
* }
179
*
180
* @endcode
181
*/
182
using
StringGenericData
=
SimpleTypeData<std::string>
;
183
184
/**
185
* @class STLContainerTypeData
186
* @brief STL container type generic data which is associated with an id
187
*
188
* \tparam ContainerType
189
* \tparam ElemDataType
190
*/
191
template
<
typename
ElemDataType>
192
class
VectorTypeData :
public
GenericData {
193
public
:
194
using
SelfType = VectorTypeData<ElemDataType>;
195
196
VectorTypeData(
const
std::string&
id
) : GenericData(
id
) {}
197
198
VectorTypeData(
const
SelfType& s) : data_(s) {}
199
200
SelfType& operator=(
const
SelfType& s) {
201
if
(
this
== &s)
return
*
this
;
202
203
this->data_ = s.data_;
204
return
*
this
;
205
}
206
207
private
:
208
std::vector<ElemDataType> data_;
209
};
210
211
/**
212
* @typedef IntVectorGenericData
213
* A generic data type contains a std::vector<int> variable.
214
*/
215
using
IntVectorGenericData
=
VectorTypeData<int>
;
216
217
/**
218
* @typedef IntVectorGenericData
219
* A generic data type contains a std::vector<float> variable.
220
*/
221
using
FloatVectorGenericData =
VectorTypeData<float>
;
222
223
/**
224
* @typedef IntVectorGenericData
225
* A generic data type contains a std::vector<RealType> variable.
226
*/
227
using
DoubleVectorGenericData =
VectorTypeData<RealType>
;
228
229
/**
230
* @typedef StringVectorGenericData
231
* A generic data type contains a std::vector<string> variable.
232
*
233
* @code
234
* StringVectorGenericData* sv = new
235
* StringVectorGenericData("MyStringVector"); GenericData* gdata; PropertyMap
236
* propMap; std::vector<std::string>::iterator iter;
237
*
238
* sv->push_back("Hello World");
239
* sv->push_back("OpenMD");
240
*
241
* propMap.addProperty(sv);
242
*
243
* gdata = propMap.getPropertyByName("MyStringVector");
244
*
245
* if (gdata != NULL){
246
*
247
* sv = dynamic_cast<StringVectorGenericData*>(gdata);
248
*
249
* if (sv != NULL){
250
* for (iter = sv->begin(); iter != sv->end(); ++ iter)
251
* std::cout << *iter << std::endl;
252
* }
253
* }
254
* @endcode
255
*/
256
using
StringVectorGenericData
=
VectorTypeData<std::string>
;
257
}
// namespace OpenMD
258
259
#endif
// UTIL _GENERICDATA_HPP
OpenMD::GenericData
@ class GenericData GenericData.hpp "utils/GenericData.hpp"
Definition
GenericData.hpp:71
OpenMD::GenericData::setID
void setID(const std::string &id)
Sets the id of this generic data.
Definition
GenericData.hpp:96
OpenMD::GenericData::getID
const std::string getID() const
Returns the id of this generic data.
Definition
GenericData.hpp:87
OpenMD::GenericData::~GenericData
virtual ~GenericData()
virtual destructor
Definition
GenericData.hpp:78
OpenMD::SimpleTypeData
SimpleTypeData class is a POD repository class.
Definition
GenericData.hpp:110
OpenMD::SimpleTypeData::getData
const ElemDataType & getData() const
Returns POD data.
Definition
GenericData.hpp:137
OpenMD::SimpleTypeData::setData
void setData(const ElemDataType &data)
Sets POD data.
Definition
GenericData.hpp:143
OpenMD::VectorTypeData
Definition
GenericData.hpp:192
OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Definition
ActionCorrFunc.cpp:63
OpenMD::BoolGenericData
SimpleTypeData< bool > BoolGenericData
BoolGenericData is a generic data type contains a bool variable.
Definition
GenericData.hpp:150
OpenMD::FloatGenericData
SimpleTypeData< float > FloatGenericData
FloatGenericData is a generic data type contains a float variable.
Definition
GenericData.hpp:156
OpenMD::DoubleGenericData
SimpleTypeData< RealType > DoubleGenericData
DoubleGenericData is a generic data type contains a RealType variable.
Definition
GenericData.hpp:159
OpenMD::StringVectorGenericData
VectorTypeData< std::string > StringVectorGenericData
A generic data type contains a std::vector<string> variable.
Definition
GenericData.hpp:256
OpenMD::StringGenericData
SimpleTypeData< std::string > StringGenericData
A generic data type contains a std::string variable.
Definition
GenericData.hpp:182
OpenMD::IntVectorGenericData
VectorTypeData< int > IntVectorGenericData
A generic data type contains a std::vector<int> variable.
Definition
GenericData.hpp:215
OpenMD::IntGenericData
SimpleTypeData< int > IntGenericData
IntGenericData is a generic data type contains an integer variable.
Definition
GenericData.hpp:153
utils
GenericData.hpp
Generated on
for OpenMD by
1.17.0