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