1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Acknowledgement of the program authors must be made in any |
10 |
* publication of scientific results based in part on use of the |
11 |
* program. An acceptable form of acknowledgement is citation of |
12 |
* the article in which the program was described (Matthew |
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
* |
18 |
* 2. Redistributions of source code must retain the above copyright |
19 |
* notice, this list of conditions and the following disclaimer. |
20 |
* |
21 |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
* notice, this list of conditions and the following disclaimer in the |
23 |
* documentation and/or other materials provided with the |
24 |
* distribution. |
25 |
* |
26 |
* This software is provided "AS IS," without a warranty of any |
27 |
* kind. All express or implied conditions, representations and |
28 |
* warranties, including any implied warranty of merchantability, |
29 |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
* be liable for any damages suffered by licensee as a result of |
32 |
* using, modifying or distributing the software or its |
33 |
* derivatives. In no event will the University of Notre Dame or its |
34 |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
* direct, indirect, special, consequential, incidental or punitive |
36 |
* damages, however caused and regardless of the theory of liability, |
37 |
* arising out of the use of or inability to use software, even if the |
38 |
* University of Notre Dame has been advised of the possibility of |
39 |
* such damages. |
40 |
*/ |
41 |
|
42 |
#include <stdlib.h> |
43 |
#include <stdio.h> |
44 |
#include <string.h> |
45 |
#include <iostream> |
46 |
|
47 |
#include "types/AtomType.hpp" |
48 |
#include "utils/simError.h" |
49 |
#define __C |
50 |
#include "UseTheForce/DarkSide/atype_interface.h" |
51 |
#include "UseTheForce/DarkSide/lj_interface.h" |
52 |
#include "UseTheForce/DarkSide/eam_interface.h" |
53 |
#include "UseTheForce/DarkSide/electrostatic_interface.h" |
54 |
namespace oopse { |
55 |
AtomType::AtomType(){ |
56 |
|
57 |
// initialize to an error: |
58 |
atp.ident = -1; |
59 |
|
60 |
// and mass_less: |
61 |
mass_ = 0.0; |
62 |
|
63 |
// atom type is a Tabula Rasa: |
64 |
atp.is_Directional = 0; |
65 |
atp.is_LennardJones = 0; |
66 |
atp.is_Charge = 0; |
67 |
atp.is_Dipole = 0; |
68 |
atp.is_SplitDipole = 0; |
69 |
atp.is_Quadrupole = 0; |
70 |
atp.is_Sticky = 0; |
71 |
atp.is_StickyPower = 0; |
72 |
atp.is_GayBerne = 0; |
73 |
atp.is_EAM = 0; |
74 |
atp.is_Shape = 0; |
75 |
atp.is_FLARB = 0; |
76 |
atp.is_SuttonChen = 0; |
77 |
atp.is_MEAM = 0; |
78 |
} |
79 |
|
80 |
void AtomType::makeFortranAtomType() { |
81 |
|
82 |
int status; |
83 |
|
84 |
if (name_.empty()) { |
85 |
sprintf( painCave.errMsg, |
86 |
"Attempting to complete an AtomType without giving " |
87 |
"it a name_!\n"); |
88 |
painCave.severity = OOPSE_ERROR; |
89 |
painCave.isFatal = 1; |
90 |
simError(); |
91 |
} |
92 |
|
93 |
if (atp.ident == -1) { |
94 |
sprintf( painCave.errMsg, |
95 |
"Attempting to complete AtomType %s without setting the" |
96 |
" ident!/n", name_.c_str()); |
97 |
painCave.severity = OOPSE_ERROR; |
98 |
painCave.isFatal = 1; |
99 |
simError(); |
100 |
} |
101 |
|
102 |
status = 0; |
103 |
|
104 |
makeAtype(&atp, &status); |
105 |
|
106 |
if (status != 0) { |
107 |
sprintf( painCave.errMsg, |
108 |
"Fortran rejected AtomType %s!\n", name_.c_str()); |
109 |
painCave.severity = OOPSE_ERROR; |
110 |
painCave.isFatal = 1; |
111 |
simError(); |
112 |
} |
113 |
} |
114 |
|
115 |
|
116 |
void AtomType::complete() { |
117 |
int isError; |
118 |
GenericData* data; |
119 |
|
120 |
//notify a new LJtype atom type is created |
121 |
if (isLennardJones()) { |
122 |
data = getPropertyByName("LennardJones"); |
123 |
if (data != NULL) { |
124 |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
125 |
|
126 |
if (ljData != NULL) { |
127 |
LJParam ljParam = ljData->getData(); |
128 |
|
129 |
newLJtype(&atp.ident, &ljParam.sigma, &ljParam.epsilon, &ljParam.soft_pot, |
130 |
&isError); |
131 |
|
132 |
if (isError != 0) { |
133 |
sprintf( painCave.errMsg, |
134 |
"Fortran rejected newLJtype\n"); |
135 |
painCave.severity = OOPSE_ERROR; |
136 |
painCave.isFatal = 1; |
137 |
simError(); |
138 |
} |
139 |
|
140 |
} else { |
141 |
sprintf( painCave.errMsg, |
142 |
"Can not cast GenericData to LJParam\n"); |
143 |
painCave.severity = OOPSE_ERROR; |
144 |
painCave.isFatal = 1; |
145 |
simError(); |
146 |
} |
147 |
} else { |
148 |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
149 |
painCave.severity = OOPSE_ERROR; |
150 |
painCave.isFatal = 1; |
151 |
simError(); |
152 |
} |
153 |
} |
154 |
|
155 |
if (isElectrostatic()) { |
156 |
newElectrostaticType(&atp, &isError); |
157 |
if (isError != 0) { |
158 |
sprintf( painCave.errMsg, |
159 |
"Fortran rejected newElectrostaticType\n"); |
160 |
painCave.severity = OOPSE_ERROR; |
161 |
painCave.isFatal = 1; |
162 |
simError(); |
163 |
} |
164 |
} |
165 |
|
166 |
if (isCharge()) { |
167 |
data = getPropertyByName("Charge"); |
168 |
if (data != NULL) { |
169 |
DoubleGenericData* doubleData= dynamic_cast<DoubleGenericData*>(data); |
170 |
|
171 |
if (doubleData != NULL) { |
172 |
double charge = doubleData->getData(); |
173 |
setCharge(&atp.ident, &charge, &isError); |
174 |
|
175 |
if (isError != 0) { |
176 |
sprintf( painCave.errMsg, |
177 |
"Fortran rejected setCharge\n"); |
178 |
painCave.severity = OOPSE_ERROR; |
179 |
painCave.isFatal = 1; |
180 |
simError(); |
181 |
} |
182 |
} else { |
183 |
sprintf( painCave.errMsg, |
184 |
"Can not cast GenericData to DoubleGenericData\n"); |
185 |
painCave.severity = OOPSE_ERROR; |
186 |
painCave.isFatal = 1; |
187 |
simError(); |
188 |
} |
189 |
} else { |
190 |
sprintf( painCave.errMsg, "Can not find Charge Parameters\n"); |
191 |
painCave.severity = OOPSE_ERROR; |
192 |
painCave.isFatal = 1; |
193 |
simError(); |
194 |
} |
195 |
} |
196 |
|
197 |
if (isEAM()) { |
198 |
data = getPropertyByName("EAM"); |
199 |
if (data != NULL) { |
200 |
EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data); |
201 |
|
202 |
if (eamData != NULL) { |
203 |
|
204 |
EAMParam eamParam = eamData->getData(); |
205 |
|
206 |
|
207 |
newEAMtype(&eamParam.latticeConstant, &eamParam.nrho, &eamParam.drho, |
208 |
&eamParam.nr, &eamParam.dr, &eamParam.rcut, &eamParam.rvals[0], |
209 |
&eamParam.rhovals[0], &eamParam.Frhovals[0], &atp.ident, |
210 |
&isError ); |
211 |
|
212 |
if (isError != 0) { |
213 |
sprintf( painCave.errMsg, |
214 |
"Fortran rejected newEAMtype\n"); |
215 |
painCave.severity = OOPSE_ERROR; |
216 |
painCave.isFatal = 1; |
217 |
simError(); |
218 |
} |
219 |
} else { |
220 |
sprintf( painCave.errMsg, |
221 |
"Can not cast GenericData to EAMParam\n"); |
222 |
painCave.severity = OOPSE_ERROR; |
223 |
painCave.isFatal = 1; |
224 |
simError(); |
225 |
} |
226 |
} else { |
227 |
sprintf( painCave.errMsg, "Can not find EAM Parameters\n"); |
228 |
painCave.severity = OOPSE_ERROR; |
229 |
painCave.isFatal = 1; |
230 |
simError(); |
231 |
} |
232 |
} |
233 |
|
234 |
|
235 |
} |
236 |
|
237 |
void AtomType::addProperty(GenericData* genData) { |
238 |
properties_.addProperty(genData); |
239 |
} |
240 |
|
241 |
void AtomType::removeProperty(const std::string& propName) { |
242 |
properties_.removeProperty(propName); |
243 |
} |
244 |
|
245 |
void AtomType::clearProperties() { |
246 |
properties_.clearProperties(); |
247 |
} |
248 |
|
249 |
std::vector<std::string> AtomType::getPropertyNames() { |
250 |
return properties_.getPropertyNames(); |
251 |
} |
252 |
|
253 |
std::vector<GenericData*> AtomType::getProperties() { |
254 |
return properties_.getProperties(); |
255 |
} |
256 |
|
257 |
GenericData* AtomType::getPropertyByName(const std::string& propName) { |
258 |
return properties_.getPropertyByName(propName); |
259 |
} |
260 |
} |