OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
AtomType.cpp
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#include "types/AtomType.hpp"
49
50#include <cstdio>
51#include <cstdlib>
52#include <cstring>
53#include <iostream>
54
55#include "types/MultipoleAdapter.hpp"
56#include "types/StickyAdapter.hpp"
57
58using namespace std;
59
60namespace OpenMD {
61 AtomType::AtomType() {
62 // initially, all atom types are their own base types.
63 base_ = this;
64 hasBase_ = false;
65
66 // initialize to an error:
67 ident_ = -1;
68
69 // and massless:
70 mass_ = 0.0;
71 myResponsibilities_["mass"] = false;
72 }
73
74 void AtomType::useBase(AtomType* base) {
75 hasBase_ = true;
76 base_ = base;
77 base->addZig(this);
78 }
79
80 void AtomType::copyAllData(AtomType* orig) {
81 // makes an exact replica of another atom type down to the
82 // atom ID and any base attachments it may have.
83 // use with caution!
84
85 hasBase_ = orig->hasBase_;
86 base_ = orig->base_;
87 mass_ = orig->mass_;
88 name_ = string(orig->name_);
89 ident_ = orig->ident_;
90
91 map<string, bool>::iterator i;
92 ;
93 map<string, RealType>::iterator j;
94
95 for (i = orig->myResponsibilities_.begin();
96 i != orig->myResponsibilities_.end(); ++i) {
97 myResponsibilities_[(*i).first] = orig->myResponsibilities_[(*i).first];
98 }
99
100 for (j = orig->myValues_.begin(); j != orig->myValues_.end(); ++j) {
101 myValues_[(*j).first] = orig->myValues_[(*j).first];
102 }
103
104 std::vector<std::shared_ptr<GenericData>> oprops = orig->getProperties();
105 std::vector<std::shared_ptr<GenericData>>::iterator it;
106
107 for (it = oprops.begin(); it != oprops.end(); ++it) {
108 addProperty(*it);
109 }
110 }
111
112 void AtomType::addProperty(std::shared_ptr<GenericData> genData) {
113 myResponsibilities_[genData->getID()] = true;
114 properties_.addProperty(genData);
115 }
116
117 void AtomType::removeProperty(const string& propName) {
118 properties_.removeProperty(propName);
119 myResponsibilities_[propName] = false;
120 }
121
122 std::vector<string> AtomType::getPropertyNames() {
123 return properties_.getPropertyNames();
124 }
125
126 std::vector<std::shared_ptr<GenericData>> AtomType::getProperties() {
127 return properties_.getProperties();
128 }
129
130 bool AtomType::hasProperty(const string& propName) {
131 if (hasBase_ && !myResponsibilities_[propName]) {
132 return base_->hasProperty(propName);
133 } else
134 return properties_.hasProperty(propName);
135 }
136
137 std::shared_ptr<GenericData> AtomType::getPropertyByName(
138 const string& propName) {
139 if (hasBase_ && !myResponsibilities_[propName]) {
140 return base_->getPropertyByName(propName);
141 } else
142 return properties_.getPropertyByName(propName);
143 }
144
145 void AtomType::setMass(RealType m) {
146 myResponsibilities_["mass"] = true;
147 mass_ = m;
148 }
149
150 RealType AtomType::getMass(void) {
151 if (hasBase_ && !myResponsibilities_["mass"])
152 return base_->getMass();
153 else
154 return mass_;
155 }
156
157 void AtomType::setIdent(int id) { ident_ = id; }
158
159 int AtomType::getIdent() { return ident_; }
160
161 void AtomType::setName(const string& name) { name_ = name; }
162
163 string AtomType::getName() { return name_; }
164
165 bool AtomType::isLennardJones() { return hasProperty("LJ"); }
166
167 bool AtomType::isElectrostatic() { return isCharge() || isMultipole(); }
168
169 bool AtomType::isEAM() { return hasProperty("EAM"); }
170
171 bool AtomType::isCharge() { return isFixedCharge() || isFluctuatingCharge(); }
172
173 bool AtomType::isDirectional() { return hasProperty("Directional"); }
174
175 bool AtomType::isFluctuatingCharge() { return hasProperty("FlucQ"); }
176
177 bool AtomType::isFixedCharge() { return hasProperty("Charge"); }
178
179 bool AtomType::isDipole() {
180 MultipoleAdapter ma = MultipoleAdapter(this);
181 if (ma.isMultipole()) {
182 return ma.isDipole();
183 } else
184 return false;
185 }
186
187 bool AtomType::isQuadrupole() {
188 MultipoleAdapter ma = MultipoleAdapter(this);
189 if (ma.isMultipole()) {
190 return ma.isQuadrupole();
191 } else
192 return false;
193 }
194
195 bool AtomType::isMultipole() { return hasProperty("Multipole"); }
196
197 bool AtomType::isGayBerne() { return hasProperty("GB"); }
198
199 bool AtomType::isSticky() { return hasProperty("Sticky"); }
200
201 bool AtomType::isStickyPower() {
202 StickyAdapter sa = StickyAdapter(this);
203 return sa.isStickyPower();
204 }
205
206 bool AtomType::isShape() { return hasProperty("Shape"); }
207
208 bool AtomType::isSC() { return hasProperty("SC"); }
209
210 bool AtomType::isMetal() { return isSC() || isEAM(); }
211
212 std::vector<AtomType*> AtomType::allYourBase() {
213 std::vector<AtomType*> myChain;
214
215 if (hasBase_) {
216 myChain = base_->allYourBase();
217 myChain.insert(myChain.begin(), this);
218 } else {
219 myChain.push_back(this);
220 }
221
222 return myChain;
223 }
224
225} // namespace OpenMD
AtomType is what OpenMD looks to for unchanging data about an atom.
Definition AtomType.hpp:69
std::shared_ptr< GenericData > getPropertyByName(const string &propName)
Returns property.
Definition AtomType.cpp:137
std::vector< std::shared_ptr< GenericData > > getProperties()
Returns all of the properties in PropertyMap.
Definition AtomType.cpp:126
void removeProperty(const string &propName)
Removes property from PropertyMap by name.
Definition AtomType.cpp:117
bool hasProperty(const string &propName)
Checks if property is in this PropertyMap.
Definition AtomType.cpp:130
std::vector< string > getPropertyNames()
Returns all names of properties.
Definition AtomType.cpp:122
void addProperty(std::shared_ptr< GenericData > genData)
Adds property into property map.
Definition AtomType.cpp:112
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.