1 |
gezelter |
507 |
/* |
2 |
gezelter |
246 |
* 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 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
10 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
gezelter |
1390 |
* |
32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
|
|
* research, please cite the appropriate papers when you publish your |
34 |
|
|
* work. Good starting points are: |
35 |
|
|
* |
36 |
|
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
|
|
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
gezelter |
1665 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
gezelter |
246 |
*/ |
42 |
|
|
|
43 |
gezelter |
507 |
/** |
44 |
|
|
* @file MoleculeCreator.cpp |
45 |
|
|
* @author tlin |
46 |
|
|
* @date 11/04/2004 |
47 |
|
|
* @time 13:44am |
48 |
|
|
* @version 1.0 |
49 |
|
|
*/ |
50 |
gezelter |
246 |
|
51 |
|
|
#include <cassert> |
52 |
gezelter |
809 |
#include <typeinfo> |
53 |
gezelter |
246 |
#include <set> |
54 |
|
|
|
55 |
|
|
#include "brains/MoleculeCreator.hpp" |
56 |
|
|
#include "primitives/GhostBend.hpp" |
57 |
tim |
273 |
#include "primitives/GhostTorsion.hpp" |
58 |
gezelter |
1710 |
#include "types/AtomType.hpp" |
59 |
gezelter |
246 |
#include "types/FixedBondType.hpp" |
60 |
|
|
#include "utils/simError.h" |
61 |
|
|
#include "utils/StringUtils.hpp" |
62 |
|
|
|
63 |
gezelter |
1390 |
namespace OpenMD { |
64 |
tim |
647 |
|
65 |
gezelter |
1277 |
Molecule* MoleculeCreator::createMolecule(ForceField* ff, |
66 |
|
|
MoleculeStamp *molStamp, |
67 |
|
|
int stampId, int globalIndex, |
68 |
|
|
LocalIndexManager* localIndexMan) { |
69 |
tim |
770 |
Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName()); |
70 |
gezelter |
1715 |
|
71 |
gezelter |
246 |
//create atoms |
72 |
|
|
Atom* atom; |
73 |
|
|
AtomStamp* currentAtomStamp; |
74 |
|
|
int nAtom = molStamp->getNAtoms(); |
75 |
|
|
for (int i = 0; i < nAtom; ++i) { |
76 |
tim |
770 |
currentAtomStamp = molStamp->getAtomStamp(i); |
77 |
gezelter |
507 |
atom = createAtom(ff, mol, currentAtomStamp, localIndexMan); |
78 |
|
|
mol->addAtom(atom); |
79 |
gezelter |
246 |
} |
80 |
|
|
|
81 |
|
|
//create rigidbodies |
82 |
|
|
RigidBody* rb; |
83 |
|
|
RigidBodyStamp * currentRigidBodyStamp; |
84 |
|
|
int nRigidbodies = molStamp->getNRigidBodies(); |
85 |
|
|
|
86 |
|
|
for (int i = 0; i < nRigidbodies; ++i) { |
87 |
tim |
770 |
currentRigidBodyStamp = molStamp->getRigidBodyStamp(i); |
88 |
gezelter |
1277 |
rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, |
89 |
|
|
localIndexMan); |
90 |
gezelter |
507 |
mol->addRigidBody(rb); |
91 |
gezelter |
246 |
} |
92 |
gezelter |
1277 |
|
93 |
gezelter |
246 |
//create bonds |
94 |
|
|
Bond* bond; |
95 |
|
|
BondStamp* currentBondStamp; |
96 |
|
|
int nBonds = molStamp->getNBonds(); |
97 |
|
|
|
98 |
|
|
for (int i = 0; i < nBonds; ++i) { |
99 |
tim |
770 |
currentBondStamp = molStamp->getBondStamp(i); |
100 |
gezelter |
507 |
bond = createBond(ff, mol, currentBondStamp); |
101 |
|
|
mol->addBond(bond); |
102 |
gezelter |
246 |
} |
103 |
|
|
|
104 |
|
|
//create bends |
105 |
|
|
Bend* bend; |
106 |
|
|
BendStamp* currentBendStamp; |
107 |
|
|
int nBends = molStamp->getNBends(); |
108 |
|
|
for (int i = 0; i < nBends; ++i) { |
109 |
tim |
770 |
currentBendStamp = molStamp->getBendStamp(i); |
110 |
gezelter |
507 |
bend = createBend(ff, mol, currentBendStamp); |
111 |
|
|
mol->addBend(bend); |
112 |
gezelter |
246 |
} |
113 |
|
|
|
114 |
|
|
//create torsions |
115 |
|
|
Torsion* torsion; |
116 |
|
|
TorsionStamp* currentTorsionStamp; |
117 |
|
|
int nTorsions = molStamp->getNTorsions(); |
118 |
|
|
for (int i = 0; i < nTorsions; ++i) { |
119 |
tim |
770 |
currentTorsionStamp = molStamp->getTorsionStamp(i); |
120 |
gezelter |
507 |
torsion = createTorsion(ff, mol, currentTorsionStamp); |
121 |
|
|
mol->addTorsion(torsion); |
122 |
gezelter |
246 |
} |
123 |
|
|
|
124 |
gezelter |
1277 |
//create inversions |
125 |
|
|
Inversion* inversion; |
126 |
|
|
InversionStamp* currentInversionStamp; |
127 |
|
|
int nInversions = molStamp->getNInversions(); |
128 |
|
|
for (int i = 0; i < nInversions; ++i) { |
129 |
|
|
currentInversionStamp = molStamp->getInversionStamp(i); |
130 |
|
|
inversion = createInversion(ff, mol, currentInversionStamp); |
131 |
|
|
if (inversion != NULL ) { |
132 |
|
|
mol->addInversion(inversion); |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
gezelter |
246 |
//create cutoffGroups |
137 |
|
|
CutoffGroup* cutoffGroup; |
138 |
|
|
CutoffGroupStamp* currentCutoffGroupStamp; |
139 |
|
|
int nCutoffGroups = molStamp->getNCutoffGroups(); |
140 |
|
|
for (int i = 0; i < nCutoffGroups; ++i) { |
141 |
tim |
770 |
currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i); |
142 |
gezelter |
1540 |
cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp, localIndexMan); |
143 |
gezelter |
507 |
mol->addCutoffGroup(cutoffGroup); |
144 |
gezelter |
246 |
} |
145 |
|
|
|
146 |
|
|
//every free atom is a cutoff group |
147 |
tim |
647 |
std::vector<Atom*> freeAtoms; |
148 |
|
|
std::vector<Atom*>::iterator ai; |
149 |
|
|
std::vector<Atom*>::iterator fai; |
150 |
gezelter |
246 |
|
151 |
|
|
//add all atoms into allAtoms set |
152 |
tim |
647 |
for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) { |
153 |
|
|
freeAtoms.push_back(atom); |
154 |
gezelter |
246 |
} |
155 |
|
|
|
156 |
|
|
Molecule::CutoffGroupIterator ci; |
157 |
|
|
CutoffGroup* cg; |
158 |
|
|
|
159 |
gezelter |
1277 |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; |
160 |
|
|
cg = mol->nextCutoffGroup(ci)) { |
161 |
|
|
|
162 |
gezelter |
507 |
for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
163 |
gezelter |
1277 |
//erase the atoms belong to cutoff groups from freeAtoms vector |
164 |
|
|
freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom), |
165 |
|
|
freeAtoms.end()); |
166 |
|
|
} |
167 |
gezelter |
246 |
} |
168 |
|
|
|
169 |
gezelter |
1277 |
// loop over the free atoms and then create one cutoff group for |
170 |
|
|
// every single free atom |
171 |
tim |
647 |
|
172 |
gezelter |
246 |
for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) { |
173 |
gezelter |
1540 |
cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan); |
174 |
gezelter |
507 |
mol->addCutoffGroup(cutoffGroup); |
175 |
gezelter |
246 |
} |
176 |
|
|
//create constraints |
177 |
|
|
createConstraintPair(mol); |
178 |
|
|
createConstraintElem(mol); |
179 |
|
|
|
180 |
gezelter |
1715 |
// Does this molecule stamp define a total constrained charge value? |
181 |
|
|
// If so, let the created molecule know about it. |
182 |
|
|
|
183 |
|
|
if (molStamp->haveConstrainedCharge() ) { |
184 |
|
|
mol->setConstrainedCharge( molStamp->getConstrainedCharge() ); |
185 |
|
|
} |
186 |
|
|
|
187 |
gezelter |
246 |
//the construction of this molecule is finished |
188 |
|
|
mol->complete(); |
189 |
gezelter |
1277 |
|
190 |
gezelter |
246 |
return mol; |
191 |
gezelter |
507 |
} |
192 |
gezelter |
246 |
|
193 |
|
|
|
194 |
gezelter |
1277 |
Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, |
195 |
|
|
AtomStamp* stamp, |
196 |
|
|
LocalIndexManager* localIndexMan) { |
197 |
gezelter |
246 |
AtomType * atomType; |
198 |
|
|
Atom* atom; |
199 |
|
|
|
200 |
|
|
atomType = ff->getAtomType(stamp->getType()); |
201 |
gezelter |
1277 |
|
202 |
gezelter |
246 |
if (atomType == NULL) { |
203 |
gezelter |
507 |
sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", |
204 |
tim |
770 |
stamp->getType().c_str()); |
205 |
gezelter |
246 |
|
206 |
gezelter |
507 |
painCave.isFatal = 1; |
207 |
|
|
simError(); |
208 |
gezelter |
246 |
} |
209 |
|
|
|
210 |
|
|
//below code still have some kind of hard-coding smell |
211 |
|
|
if (atomType->isDirectional()){ |
212 |
gezelter |
507 |
DirectionalAtom* dAtom; |
213 |
gezelter |
1710 |
dAtom = new DirectionalAtom(atomType); |
214 |
gezelter |
507 |
atom = dAtom; |
215 |
gezelter |
246 |
} |
216 |
|
|
else{ |
217 |
gezelter |
507 |
atom = new Atom(atomType); |
218 |
gezelter |
246 |
} |
219 |
|
|
|
220 |
|
|
atom->setLocalIndex(localIndexMan->getNextAtomIndex()); |
221 |
|
|
|
222 |
|
|
return atom; |
223 |
gezelter |
507 |
} |
224 |
gezelter |
1277 |
|
225 |
|
|
RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, |
226 |
|
|
Molecule* mol, |
227 |
gezelter |
507 |
RigidBodyStamp* rbStamp, |
228 |
|
|
LocalIndexManager* localIndexMan) { |
229 |
gezelter |
246 |
Atom* atom; |
230 |
|
|
int nAtoms; |
231 |
|
|
Vector3d refCoor; |
232 |
|
|
AtomStamp* atomStamp; |
233 |
|
|
|
234 |
|
|
RigidBody* rb = new RigidBody(); |
235 |
|
|
nAtoms = rbStamp->getNMembers(); |
236 |
|
|
for (int i = 0; i < nAtoms; ++i) { |
237 |
gezelter |
1277 |
//rbStamp->getMember(i) return the local index of current atom |
238 |
|
|
//inside the molecule. It is not the same as local index of |
239 |
|
|
//atom which is the index of atom at DataStorage class |
240 |
tim |
770 |
atom = mol->getAtomAt(rbStamp->getMemberAt(i)); |
241 |
|
|
atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i)); |
242 |
gezelter |
507 |
rb->addAtom(atom, atomStamp); |
243 |
gezelter |
246 |
} |
244 |
|
|
|
245 |
gezelter |
1277 |
//after all of the atoms are added, we need to calculate the |
246 |
|
|
//reference coordinates |
247 |
gezelter |
246 |
rb->calcRefCoords(); |
248 |
|
|
|
249 |
|
|
//set the local index of this rigid body, global index will be set later |
250 |
|
|
rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex()); |
251 |
|
|
|
252 |
|
|
//the rule for naming rigidbody MoleculeName_RB_Integer |
253 |
|
|
//The first part is the name of the molecule |
254 |
|
|
//The second part is alway fixed as "RB" |
255 |
|
|
//The third part is the index of the rigidbody defined in meta-data file |
256 |
|
|
//For example, Butane_RB_0 is a valid rigid body name of butane molecule |
257 |
|
|
/**@todo replace itoa by lexi_cast */ |
258 |
gezelter |
1390 |
std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10); |
259 |
gezelter |
403 |
rb->setType(mol->getType() + "_RB_" + s.c_str()); |
260 |
tim |
292 |
|
261 |
gezelter |
246 |
return rb; |
262 |
gezelter |
507 |
} |
263 |
gezelter |
246 |
|
264 |
gezelter |
1277 |
Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, |
265 |
|
|
BondStamp* stamp) { |
266 |
gezelter |
246 |
BondType* bondType; |
267 |
|
|
Atom* atomA; |
268 |
|
|
Atom* atomB; |
269 |
gezelter |
1277 |
|
270 |
gezelter |
246 |
atomA = mol->getAtomAt(stamp->getA()); |
271 |
|
|
atomB = mol->getAtomAt(stamp->getB()); |
272 |
gezelter |
1277 |
|
273 |
gezelter |
246 |
assert( atomA && atomB); |
274 |
|
|
|
275 |
|
|
bondType = ff->getBondType(atomA->getType(), atomB->getType()); |
276 |
|
|
|
277 |
|
|
if (bondType == NULL) { |
278 |
gezelter |
507 |
sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", |
279 |
|
|
atomA->getType().c_str(), |
280 |
|
|
atomB->getType().c_str()); |
281 |
gezelter |
1277 |
|
282 |
gezelter |
507 |
painCave.isFatal = 1; |
283 |
|
|
simError(); |
284 |
gezelter |
246 |
} |
285 |
|
|
return new Bond(atomA, atomB, bondType); |
286 |
gezelter |
507 |
} |
287 |
gezelter |
1277 |
|
288 |
|
|
Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, |
289 |
|
|
BendStamp* stamp) { |
290 |
tim |
770 |
Bend* bend = NULL; |
291 |
|
|
std::vector<int> bendAtoms = stamp->getMembers(); |
292 |
|
|
if (bendAtoms.size() == 3) { |
293 |
|
|
Atom* atomA = mol->getAtomAt(bendAtoms[0]); |
294 |
|
|
Atom* atomB = mol->getAtomAt(bendAtoms[1]); |
295 |
|
|
Atom* atomC = mol->getAtomAt(bendAtoms[2]); |
296 |
gezelter |
1277 |
|
297 |
tim |
770 |
assert( atomA && atomB && atomC); |
298 |
gezelter |
1277 |
|
299 |
|
|
BendType* bendType = ff->getBendType(atomA->getType().c_str(), |
300 |
|
|
atomB->getType().c_str(), |
301 |
|
|
atomC->getType().c_str()); |
302 |
|
|
|
303 |
tim |
770 |
if (bendType == NULL) { |
304 |
|
|
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
305 |
|
|
atomA->getType().c_str(), |
306 |
|
|
atomB->getType().c_str(), |
307 |
|
|
atomC->getType().c_str()); |
308 |
gezelter |
1277 |
|
309 |
tim |
770 |
painCave.isFatal = 1; |
310 |
|
|
simError(); |
311 |
gezelter |
507 |
} |
312 |
gezelter |
1277 |
|
313 |
tim |
770 |
bend = new Bend(atomA, atomB, atomC, bendType); |
314 |
|
|
} else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) { |
315 |
|
|
int ghostIndex = stamp->getGhostVectorSource(); |
316 |
|
|
int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1]; |
317 |
gezelter |
507 |
Atom* normalAtom = mol->getAtomAt(normalIndex) ; |
318 |
|
|
DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex)); |
319 |
|
|
if (ghostAtom == NULL) { |
320 |
|
|
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
321 |
|
|
painCave.isFatal = 1; |
322 |
|
|
simError(); |
323 |
|
|
} |
324 |
gezelter |
246 |
|
325 |
gezelter |
507 |
BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST"); |
326 |
gezelter |
246 |
|
327 |
gezelter |
507 |
if (bendType == NULL) { |
328 |
|
|
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
329 |
|
|
normalAtom->getType().c_str(), |
330 |
|
|
ghostAtom->getType().c_str(), |
331 |
|
|
"GHOST"); |
332 |
gezelter |
246 |
|
333 |
gezelter |
507 |
painCave.isFatal = 1; |
334 |
|
|
simError(); |
335 |
|
|
} |
336 |
gezelter |
1277 |
|
337 |
tim |
770 |
bend = new GhostBend(normalAtom, ghostAtom, bendType); |
338 |
gezelter |
1277 |
|
339 |
tim |
770 |
} |
340 |
|
|
|
341 |
|
|
return bend; |
342 |
|
|
} |
343 |
gezelter |
246 |
|
344 |
gezelter |
1277 |
Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, |
345 |
|
|
TorsionStamp* stamp) { |
346 |
gezelter |
246 |
|
347 |
tim |
770 |
Torsion* torsion = NULL; |
348 |
|
|
std::vector<int> torsionAtoms = stamp->getMembers(); |
349 |
|
|
if (torsionAtoms.size() < 3) { |
350 |
|
|
return torsion; |
351 |
gezelter |
246 |
} |
352 |
|
|
|
353 |
tim |
770 |
Atom* atomA = mol->getAtomAt(torsionAtoms[0]); |
354 |
|
|
Atom* atomB = mol->getAtomAt(torsionAtoms[1]); |
355 |
|
|
Atom* atomC = mol->getAtomAt(torsionAtoms[2]); |
356 |
gezelter |
246 |
|
357 |
tim |
770 |
if (torsionAtoms.size() == 4) { |
358 |
|
|
Atom* atomD = mol->getAtomAt(torsionAtoms[3]); |
359 |
gezelter |
246 |
|
360 |
gezelter |
507 |
assert(atomA && atomB && atomC && atomD); |
361 |
tim |
273 |
|
362 |
gezelter |
1277 |
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), |
363 |
|
|
atomB->getType(), |
364 |
|
|
atomC->getType(), |
365 |
|
|
atomD->getType()); |
366 |
gezelter |
507 |
if (torsionType == NULL) { |
367 |
|
|
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
368 |
|
|
atomA->getType().c_str(), |
369 |
|
|
atomB->getType().c_str(), |
370 |
|
|
atomC->getType().c_str(), |
371 |
|
|
atomD->getType().c_str()); |
372 |
gezelter |
1277 |
|
373 |
gezelter |
507 |
painCave.isFatal = 1; |
374 |
|
|
simError(); |
375 |
|
|
} |
376 |
gezelter |
1277 |
|
377 |
gezelter |
507 |
torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType); |
378 |
gezelter |
246 |
} |
379 |
tim |
273 |
else { |
380 |
gezelter |
1277 |
|
381 |
tim |
770 |
DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource())); |
382 |
gezelter |
507 |
if (dAtom == NULL) { |
383 |
|
|
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
384 |
|
|
painCave.isFatal = 1; |
385 |
|
|
simError(); |
386 |
|
|
} |
387 |
gezelter |
1277 |
|
388 |
gezelter |
507 |
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), |
389 |
|
|
atomC->getType(), "GHOST"); |
390 |
gezelter |
1277 |
|
391 |
gezelter |
507 |
if (torsionType == NULL) { |
392 |
|
|
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
393 |
|
|
atomA->getType().c_str(), |
394 |
|
|
atomB->getType().c_str(), |
395 |
|
|
atomC->getType().c_str(), |
396 |
|
|
"GHOST"); |
397 |
gezelter |
1277 |
|
398 |
gezelter |
507 |
painCave.isFatal = 1; |
399 |
|
|
simError(); |
400 |
|
|
} |
401 |
gezelter |
1277 |
|
402 |
gezelter |
507 |
torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType); |
403 |
tim |
273 |
} |
404 |
gezelter |
1277 |
|
405 |
tim |
273 |
return torsion; |
406 |
gezelter |
507 |
} |
407 |
gezelter |
246 |
|
408 |
gezelter |
1277 |
Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol, |
409 |
|
|
InversionStamp* stamp) { |
410 |
|
|
|
411 |
|
|
Inversion* inversion = NULL; |
412 |
|
|
int center = stamp->getCenter(); |
413 |
|
|
std::vector<int> satellites = stamp->getSatellites(); |
414 |
|
|
if (satellites.size() != 3) { |
415 |
|
|
return inversion; |
416 |
|
|
} |
417 |
|
|
|
418 |
|
|
Atom* atomA = mol->getAtomAt(center); |
419 |
|
|
Atom* atomB = mol->getAtomAt(satellites[0]); |
420 |
|
|
Atom* atomC = mol->getAtomAt(satellites[1]); |
421 |
|
|
Atom* atomD = mol->getAtomAt(satellites[2]); |
422 |
|
|
|
423 |
|
|
assert(atomA && atomB && atomC && atomD); |
424 |
|
|
|
425 |
|
|
InversionType* inversionType = ff->getInversionType(atomA->getType(), |
426 |
|
|
atomB->getType(), |
427 |
|
|
atomC->getType(), |
428 |
|
|
atomD->getType()); |
429 |
|
|
|
430 |
|
|
if (inversionType == NULL) { |
431 |
|
|
sprintf(painCave.errMsg, "No Matching Inversion Type for[%s, %s, %s, %s]\n" |
432 |
|
|
"\t(May not be a problem: not all inversions are parametrized)\n", |
433 |
|
|
atomA->getType().c_str(), |
434 |
|
|
atomB->getType().c_str(), |
435 |
|
|
atomC->getType().c_str(), |
436 |
|
|
atomD->getType().c_str()); |
437 |
|
|
|
438 |
|
|
painCave.isFatal = 0; |
439 |
gezelter |
1390 |
painCave.severity = OPENMD_INFO; |
440 |
gezelter |
1277 |
simError(); |
441 |
|
|
return NULL; |
442 |
|
|
} else { |
443 |
|
|
|
444 |
|
|
inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType); |
445 |
|
|
return inversion; |
446 |
|
|
} |
447 |
|
|
} |
448 |
|
|
|
449 |
|
|
|
450 |
gezelter |
1540 |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, |
451 |
|
|
CutoffGroupStamp* stamp, |
452 |
|
|
LocalIndexManager* localIndexMan) { |
453 |
gezelter |
246 |
int nAtoms; |
454 |
|
|
CutoffGroup* cg; |
455 |
|
|
Atom* atom; |
456 |
|
|
cg = new CutoffGroup(); |
457 |
|
|
|
458 |
|
|
nAtoms = stamp->getNMembers(); |
459 |
|
|
for (int i =0; i < nAtoms; ++i) { |
460 |
tim |
770 |
atom = mol->getAtomAt(stamp->getMemberAt(i)); |
461 |
gezelter |
507 |
assert(atom); |
462 |
|
|
cg->addAtom(atom); |
463 |
gezelter |
246 |
} |
464 |
gezelter |
1540 |
|
465 |
|
|
//set the local index of this cutoffGroup, global index will be set later |
466 |
|
|
cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex()); |
467 |
|
|
|
468 |
gezelter |
246 |
return cg; |
469 |
gezelter |
507 |
} |
470 |
gezelter |
1540 |
|
471 |
|
|
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom, |
472 |
|
|
LocalIndexManager* localIndexMan) { |
473 |
gezelter |
246 |
CutoffGroup* cg; |
474 |
|
|
cg = new CutoffGroup(); |
475 |
|
|
cg->addAtom(atom); |
476 |
gezelter |
1540 |
|
477 |
|
|
//set the local index of this cutoffGroup, global index will be set later |
478 |
|
|
cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex()); |
479 |
|
|
|
480 |
gezelter |
246 |
return cg; |
481 |
gezelter |
507 |
} |
482 |
gezelter |
246 |
|
483 |
gezelter |
507 |
void MoleculeCreator::createConstraintPair(Molecule* mol) { |
484 |
gezelter |
246 |
|
485 |
|
|
//add bond constraints |
486 |
|
|
Molecule::BondIterator bi; |
487 |
|
|
Bond* bond; |
488 |
|
|
for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) { |
489 |
|
|
|
490 |
gezelter |
507 |
BondType* bt = bond->getBondType(); |
491 |
gezelter |
246 |
|
492 |
gezelter |
507 |
//class Parent1 {}; |
493 |
|
|
//class Child1 : public Parent {}; |
494 |
|
|
//class Child2 : public Parent {}; |
495 |
|
|
//Child1* ch1 = new Child1(); |
496 |
|
|
//Child2* ch2 = dynamic_cast<Child2*>(ch1); |
497 |
|
|
//the dynamic_cast is succeed in above line. A compiler bug? |
498 |
gezelter |
246 |
|
499 |
gezelter |
507 |
if (typeid(FixedBondType) == typeid(*bt)) { |
500 |
|
|
FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); |
501 |
gezelter |
246 |
|
502 |
gezelter |
507 |
ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA()); |
503 |
|
|
ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB()); |
504 |
|
|
ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength()); |
505 |
|
|
mol->addConstraintPair(consPair); |
506 |
|
|
} |
507 |
gezelter |
246 |
} |
508 |
|
|
|
509 |
|
|
//rigidbody -- rigidbody constraint is not support yet |
510 |
gezelter |
507 |
} |
511 |
gezelter |
246 |
|
512 |
gezelter |
507 |
void MoleculeCreator::createConstraintElem(Molecule* mol) { |
513 |
gezelter |
246 |
|
514 |
|
|
ConstraintPair* consPair; |
515 |
|
|
Molecule::ConstraintPairIterator cpi; |
516 |
|
|
std::set<StuntDouble*> sdSet; |
517 |
|
|
for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) { |
518 |
|
|
|
519 |
gezelter |
507 |
StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble(); |
520 |
|
|
if (sdSet.find(sdA) == sdSet.end()){ |
521 |
|
|
sdSet.insert(sdA); |
522 |
|
|
mol->addConstraintElem(new ConstraintElem(sdA)); |
523 |
|
|
} |
524 |
gezelter |
246 |
|
525 |
gezelter |
507 |
StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble(); |
526 |
|
|
if (sdSet.find(sdB) == sdSet.end()){ |
527 |
|
|
sdSet.insert(sdB); |
528 |
|
|
mol->addConstraintElem(new ConstraintElem(sdB)); |
529 |
|
|
} |
530 |
gezelter |
246 |
|
531 |
|
|
} |
532 |
|
|
|
533 |
gezelter |
507 |
} |
534 |
gezelter |
246 |
|
535 |
|
|
} |