OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
FluctuatingChargeAdapter.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/FluctuatingChargeAdapter.hpp"
49
50#include <config.h>
51
52#include <cstdio>
53#include <memory>
54
55#include "nonbonded/SlaterIntegrals.hpp"
56#include "utils/simError.h"
57
58namespace OpenMD {
59
60 bool FluctuatingChargeAdapter::isFluctuatingCharge() {
61 return at_->hasProperty(FQtypeID);
62 }
63
65 FluctuatingChargeAdapter::getFluctuatingChargeParam() {
66 if (!isFluctuatingCharge()) {
67 snprintf(
68 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
69 "FluctuatingChargeAdapter::getFluctuatingChargeParam was passed an "
70 "atomType "
71 "(%s)\n"
72 "\tthat does not appear to be a fluctuating charge atom.\n",
73 at_->getName().c_str());
74 painCave.severity = OPENMD_ERROR;
75 painCave.isFatal = 1;
76 simError();
77 }
78
79 std::shared_ptr<GenericData> data = at_->getPropertyByName(FQtypeID);
80 if (data == nullptr) {
81 snprintf(
82 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
83 "FluctuatingChargeAdapter::getFluctuatingChargeParam could not find "
84 "fluctuating charge\n"
85 "\tparameters for atomType %s.\n",
86 at_->getName().c_str());
87 painCave.severity = OPENMD_ERROR;
88 painCave.isFatal = 1;
89 simError();
90 }
91
92 std::shared_ptr<FluctuatingAtypeData> fqData =
93 std::dynamic_pointer_cast<FluctuatingAtypeData>(data);
94 if (fqData == nullptr) {
95 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
96 "FluctuatingChargeAdapter::getFluctuatingChargeParam could not "
97 "convert\n"
98 "\tGenericData to FluctuatingAtypeData for atom type %s\n",
99 at_->getName().c_str());
100 painCave.severity = OPENMD_ERROR;
101 painCave.isFatal = 1;
102 simError();
103 }
104
105 return fqData->getData();
106 }
107
108 bool FluctuatingChargeAdapter::isMetallic() {
109 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
110 return fqParam.isMetallic;
111 }
112 bool FluctuatingChargeAdapter::usesSlaterIntramolecular() {
113 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
114 return fqParam.usesSlaterIntramolecular;
115 }
116 RealType FluctuatingChargeAdapter::getChargeMass() {
117 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
118 return fqParam.chargeMass;
119 }
120 RealType FluctuatingChargeAdapter::getElectronegativity() {
121 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
122 return fqParam.electronegativity;
123 }
124 RealType FluctuatingChargeAdapter::getHardness() {
125 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
126 return fqParam.hardness;
127 }
128 int FluctuatingChargeAdapter::getSlaterN() {
129 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
130 return fqParam.slaterN;
131 }
132 RealType FluctuatingChargeAdapter::getNValence() {
133 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
134 return fqParam.nValence;
135 }
136 RealType FluctuatingChargeAdapter::getNMobile() {
137 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
138 return fqParam.nMobile;
139 }
140 RealType FluctuatingChargeAdapter::getSlaterZeta() {
141 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
142 return fqParam.slaterZeta;
143 }
144 DoublePolynomial FluctuatingChargeAdapter::getSelfPolynomial() {
145 FluctuatingAtypeParameters fqParam = getFluctuatingChargeParam();
146 return fqParam.vself;
147 }
148
149 void FluctuatingChargeAdapter::makeFluctuatingCharge(
150 RealType chargeMass, RealType electronegativity, RealType hardness,
151 int slaterN, RealType slaterZeta) {
152 if (isFluctuatingCharge()) { at_->removeProperty(FQtypeID); }
153
154 FluctuatingAtypeParameters fqParam {};
155 fqParam.chargeMass = chargeMass;
156 fqParam.usesSlaterIntramolecular = true;
157
158 fqParam.electronegativity = electronegativity;
159 fqParam.hardness = hardness;
160 fqParam.slaterN = slaterN;
161 fqParam.slaterZeta = slaterZeta;
162
163 fqParam.vself.setCoefficient(1, electronegativity);
164 fqParam.vself.setCoefficient(2, 0.5 * hardness);
165
166 at_->addProperty(std::make_shared<FluctuatingAtypeData>(FQtypeID, fqParam));
167 }
168
169 void FluctuatingChargeAdapter::makeFluctuatingCharge(RealType chargeMass,
170 RealType nValence,
171 DoublePolynomial vs) {
172 if (isFluctuatingCharge()) { at_->removeProperty(FQtypeID); }
173
174 FluctuatingAtypeParameters fqParam {};
175
176 fqParam.chargeMass = chargeMass;
177 fqParam.usesSlaterIntramolecular = false;
178
179 // old-style EAMPoly has nV = nM
180 fqParam.isMetallic = true;
181 fqParam.nValence = nValence;
182 fqParam.nMobile = nValence;
183
184 fqParam.vself = vs;
185
186 at_->addProperty(std::make_shared<FluctuatingAtypeData>(FQtypeID, fqParam));
187 }
188
189 void FluctuatingChargeAdapter::makeFluctuatingCharge(RealType chargeMass,
190 RealType nValence,
191 RealType nMobile,
192 DoublePolynomial vs) {
193 if (isFluctuatingCharge()) { at_->removeProperty(FQtypeID); }
194
195 FluctuatingAtypeParameters fqParam {};
196
197 fqParam.chargeMass = chargeMass;
198 fqParam.usesSlaterIntramolecular = false;
199 fqParam.isMetallic = true;
200 fqParam.nValence = nValence;
201 fqParam.nMobile = nMobile;
202
203 fqParam.vself = vs;
204
205 at_->addProperty(std::make_shared<FluctuatingAtypeData>(FQtypeID, fqParam));
206 }
207} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.