1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
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 |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
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 |
+ |
* |
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, 234107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
< |
/** |
44 |
< |
* @file MoleculeCreator.cpp |
45 |
< |
* @author tlin |
46 |
< |
* @date 11/04/2004 |
47 |
< |
* @time 13:44am |
48 |
< |
* @version 1.0 |
48 |
< |
*/ |
43 |
> |
/** |
44 |
> |
* @file MoleculeCreator.cpp |
45 |
> |
* @author tlin |
46 |
> |
* @date 11/04/2004 |
47 |
> |
* @version 1.0 |
48 |
> |
*/ |
49 |
|
|
50 |
|
#include <cassert> |
51 |
+ |
#include <typeinfo> |
52 |
|
#include <set> |
53 |
|
|
54 |
|
#include "brains/MoleculeCreator.hpp" |
55 |
|
#include "primitives/GhostBend.hpp" |
56 |
|
#include "primitives/GhostTorsion.hpp" |
57 |
< |
#include "types/DirectionalAtomType.hpp" |
57 |
> |
#include "types/AtomType.hpp" |
58 |
|
#include "types/FixedBondType.hpp" |
59 |
|
#include "utils/simError.h" |
60 |
|
#include "utils/StringUtils.hpp" |
61 |
|
|
62 |
< |
namespace oopse { |
62 |
> |
namespace OpenMD { |
63 |
> |
|
64 |
> |
Molecule* MoleculeCreator::createMolecule(ForceField* ff, |
65 |
> |
MoleculeStamp *molStamp, |
66 |
> |
int stampId, int globalIndex, |
67 |
> |
LocalIndexManager* localIndexMan) { |
68 |
> |
Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName(), |
69 |
> |
molStamp->getRegion() ); |
70 |
|
|
63 |
– |
Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp, |
64 |
– |
int stampId, int globalIndex, LocalIndexManager* localIndexMan) { |
65 |
– |
|
66 |
– |
Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getID()); |
67 |
– |
|
71 |
|
//create atoms |
72 |
|
Atom* atom; |
73 |
|
AtomStamp* currentAtomStamp; |
74 |
|
int nAtom = molStamp->getNAtoms(); |
75 |
|
for (int i = 0; i < nAtom; ++i) { |
76 |
< |
currentAtomStamp = molStamp->getAtom(i); |
77 |
< |
atom = createAtom(ff, mol, currentAtomStamp, localIndexMan); |
78 |
< |
mol->addAtom(atom); |
76 |
> |
currentAtomStamp = molStamp->getAtomStamp(i); |
77 |
> |
atom = createAtom(ff, mol, currentAtomStamp, localIndexMan); |
78 |
> |
mol->addAtom(atom); |
79 |
|
} |
80 |
|
|
81 |
|
//create rigidbodies |
84 |
|
int nRigidbodies = molStamp->getNRigidBodies(); |
85 |
|
|
86 |
|
for (int i = 0; i < nRigidbodies; ++i) { |
87 |
< |
currentRigidBodyStamp = molStamp->getRigidBody(i); |
88 |
< |
rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan); |
89 |
< |
mol->addRigidBody(rb); |
87 |
> |
currentRigidBodyStamp = molStamp->getRigidBodyStamp(i); |
88 |
> |
rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, |
89 |
> |
localIndexMan); |
90 |
> |
mol->addRigidBody(rb); |
91 |
|
} |
92 |
< |
|
92 |
> |
|
93 |
|
//create bonds |
94 |
|
Bond* bond; |
95 |
|
BondStamp* currentBondStamp; |
96 |
|
int nBonds = molStamp->getNBonds(); |
97 |
|
|
98 |
|
for (int i = 0; i < nBonds; ++i) { |
99 |
< |
currentBondStamp = molStamp->getBond(i); |
100 |
< |
bond = createBond(ff, mol, currentBondStamp); |
101 |
< |
mol->addBond(bond); |
99 |
> |
currentBondStamp = molStamp->getBondStamp(i); |
100 |
> |
bond = createBond(ff, mol, currentBondStamp, localIndexMan); |
101 |
> |
mol->addBond(bond); |
102 |
|
} |
103 |
|
|
104 |
|
//create bends |
106 |
|
BendStamp* currentBendStamp; |
107 |
|
int nBends = molStamp->getNBends(); |
108 |
|
for (int i = 0; i < nBends; ++i) { |
109 |
< |
currentBendStamp = molStamp->getBend(i); |
110 |
< |
bend = createBend(ff, mol, currentBendStamp); |
111 |
< |
mol->addBend(bend); |
109 |
> |
currentBendStamp = molStamp->getBendStamp(i); |
110 |
> |
bend = createBend(ff, mol, currentBendStamp, localIndexMan); |
111 |
> |
mol->addBend(bend); |
112 |
|
} |
113 |
|
|
114 |
|
//create torsions |
116 |
|
TorsionStamp* currentTorsionStamp; |
117 |
|
int nTorsions = molStamp->getNTorsions(); |
118 |
|
for (int i = 0; i < nTorsions; ++i) { |
119 |
< |
currentTorsionStamp = molStamp->getTorsion(i); |
120 |
< |
torsion = createTorsion(ff, mol, currentTorsionStamp); |
121 |
< |
mol->addTorsion(torsion); |
119 |
> |
currentTorsionStamp = molStamp->getTorsionStamp(i); |
120 |
> |
torsion = createTorsion(ff, mol, currentTorsionStamp, localIndexMan); |
121 |
> |
mol->addTorsion(torsion); |
122 |
|
} |
123 |
|
|
124 |
+ |
//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 |
+ |
localIndexMan); |
132 |
+ |
if (inversion != NULL ) { |
133 |
+ |
mol->addInversion(inversion); |
134 |
+ |
} |
135 |
+ |
} |
136 |
+ |
|
137 |
|
//create cutoffGroups |
138 |
|
CutoffGroup* cutoffGroup; |
139 |
|
CutoffGroupStamp* currentCutoffGroupStamp; |
140 |
|
int nCutoffGroups = molStamp->getNCutoffGroups(); |
141 |
|
for (int i = 0; i < nCutoffGroups; ++i) { |
142 |
< |
currentCutoffGroupStamp = molStamp->getCutoffGroup(i); |
143 |
< |
cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp); |
144 |
< |
mol->addCutoffGroup(cutoffGroup); |
142 |
> |
currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i); |
143 |
> |
cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp, |
144 |
> |
localIndexMan); |
145 |
> |
mol->addCutoffGroup(cutoffGroup); |
146 |
|
} |
147 |
|
|
148 |
|
//every free atom is a cutoff group |
149 |
< |
std::set<Atom*> allAtoms; |
150 |
< |
Molecule::AtomIterator ai; |
149 |
> |
std::vector<Atom*> freeAtoms; |
150 |
> |
std::vector<Atom*>::iterator ai; |
151 |
> |
std::vector<Atom*>::iterator fai; |
152 |
|
|
153 |
|
//add all atoms into allAtoms set |
154 |
< |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
155 |
< |
allAtoms.insert(atom); |
154 |
> |
for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) { |
155 |
> |
freeAtoms.push_back(atom); |
156 |
|
} |
157 |
|
|
158 |
|
Molecule::CutoffGroupIterator ci; |
159 |
|
CutoffGroup* cg; |
141 |
– |
std::set<Atom*> cutoffAtoms; |
160 |
|
|
161 |
< |
//add all of the atoms belong to cutoff groups into cutoffAtoms set |
162 |
< |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
163 |
< |
|
164 |
< |
for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
165 |
< |
cutoffAtoms.insert(atom); |
166 |
< |
} |
167 |
< |
|
161 |
> |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; |
162 |
> |
cg = mol->nextCutoffGroup(ci)) { |
163 |
> |
|
164 |
> |
for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
165 |
> |
//erase the atoms belong to cutoff groups from freeAtoms vector |
166 |
> |
freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom), |
167 |
> |
freeAtoms.end()); |
168 |
> |
} |
169 |
|
} |
170 |
|
|
171 |
< |
//find all free atoms (which do not belong to cutoff groups) |
172 |
< |
//performs the "difference" operation from set theory, the output range contains a copy of every |
173 |
< |
//element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in |
155 |
< |
//[cutoffAtoms.begin(), cutoffAtoms.end()). |
156 |
< |
std::vector<Atom*> freeAtoms; |
157 |
< |
std::set_difference(allAtoms.begin(), allAtoms.end(), cutoffAtoms.begin(), cutoffAtoms.end(), |
158 |
< |
std::back_inserter(freeAtoms)); |
159 |
< |
|
160 |
< |
if (freeAtoms.size() != allAtoms.size() - cutoffAtoms.size()) { |
161 |
< |
//Some atoms in rigidAtoms are not in allAtoms, something must be wrong |
162 |
< |
sprintf(painCave.errMsg, "Atoms in cutoff groups are not in the atom list of the same molecule"); |
163 |
< |
|
164 |
< |
painCave.isFatal = 1; |
165 |
< |
simError(); |
166 |
< |
} |
167 |
< |
|
168 |
< |
//loop over the free atoms and then create one cutoff group for every single free atom |
169 |
< |
std::vector<Atom*>::iterator fai; |
170 |
< |
|
171 |
> |
// loop over the free atoms and then create one cutoff group for |
172 |
> |
// every single free atom |
173 |
> |
|
174 |
|
for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) { |
175 |
< |
cutoffGroup = createCutoffGroup(mol, *fai); |
176 |
< |
mol->addCutoffGroup(cutoffGroup); |
175 |
> |
cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan); |
176 |
> |
mol->addCutoffGroup(cutoffGroup); |
177 |
|
} |
178 |
|
//create constraints |
179 |
|
createConstraintPair(mol); |
180 |
|
createConstraintElem(mol); |
181 |
|
|
182 |
+ |
// Does this molecule stamp define a total constrained charge value? |
183 |
+ |
// If so, let the created molecule know about it. |
184 |
+ |
|
185 |
+ |
if (molStamp->haveConstrainTotalCharge() ) { |
186 |
+ |
mol->setConstrainTotalCharge( molStamp->getConstrainTotalCharge() ); |
187 |
+ |
} |
188 |
+ |
|
189 |
|
//the construction of this molecule is finished |
190 |
|
mol->complete(); |
191 |
< |
|
191 |
> |
|
192 |
|
return mol; |
193 |
< |
} |
193 |
> |
} |
194 |
|
|
195 |
|
|
196 |
< |
Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp, |
197 |
< |
LocalIndexManager* localIndexMan) { |
196 |
> |
Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, |
197 |
> |
AtomStamp* stamp, |
198 |
> |
LocalIndexManager* localIndexMan) { |
199 |
|
AtomType * atomType; |
200 |
|
Atom* atom; |
201 |
|
|
202 |
|
atomType = ff->getAtomType(stamp->getType()); |
203 |
< |
|
203 |
> |
|
204 |
|
if (atomType == NULL) { |
205 |
< |
sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", |
206 |
< |
stamp->getType()); |
205 |
> |
sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", |
206 |
> |
stamp->getType().c_str()); |
207 |
|
|
208 |
< |
painCave.isFatal = 1; |
209 |
< |
simError(); |
208 |
> |
painCave.isFatal = 1; |
209 |
> |
simError(); |
210 |
|
} |
211 |
< |
|
211 |
> |
|
212 |
|
//below code still have some kind of hard-coding smell |
213 |
|
if (atomType->isDirectional()){ |
203 |
– |
|
204 |
– |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
205 |
– |
|
206 |
– |
if (dAtomType == NULL) { |
207 |
– |
sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType"); |
214 |
|
|
215 |
< |
painCave.isFatal = 1; |
216 |
< |
simError(); |
217 |
< |
} |
212 |
< |
|
213 |
< |
DirectionalAtom* dAtom; |
214 |
< |
dAtom = new DirectionalAtom(dAtomType); |
215 |
< |
atom = dAtom; |
215 |
> |
DirectionalAtom* dAtom; |
216 |
> |
dAtom = new DirectionalAtom(atomType); |
217 |
> |
atom = dAtom; |
218 |
|
} |
219 |
|
else{ |
220 |
< |
atom = new Atom(atomType); |
220 |
> |
atom = new Atom(atomType); |
221 |
|
} |
222 |
|
|
223 |
|
atom->setLocalIndex(localIndexMan->getNextAtomIndex()); |
224 |
|
|
225 |
|
return atom; |
226 |
< |
} |
227 |
< |
|
228 |
< |
RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol, |
229 |
< |
RigidBodyStamp* rbStamp, |
230 |
< |
LocalIndexManager* localIndexMan) { |
226 |
> |
} |
227 |
> |
|
228 |
> |
RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, |
229 |
> |
Molecule* mol, |
230 |
> |
RigidBodyStamp* rbStamp, |
231 |
> |
LocalIndexManager* localIndexMan){ |
232 |
|
Atom* atom; |
233 |
|
int nAtoms; |
234 |
|
Vector3d refCoor; |
237 |
|
RigidBody* rb = new RigidBody(); |
238 |
|
nAtoms = rbStamp->getNMembers(); |
239 |
|
for (int i = 0; i < nAtoms; ++i) { |
240 |
< |
//rbStamp->getMember(i) return the local index of current atom inside the molecule. |
241 |
< |
//It is not the same as local index of atom which is the index of atom at DataStorage class |
242 |
< |
atom = mol->getAtomAt(rbStamp->getMember(i)); |
243 |
< |
atomStamp= molStamp->getAtom(rbStamp->getMember(i)); |
244 |
< |
rb->addAtom(atom, atomStamp); |
240 |
> |
//rbStamp->getMember(i) return the local index of current atom |
241 |
> |
//inside the molecule. It is not the same as local index of |
242 |
> |
//atom which is the index of atom at DataStorage class |
243 |
> |
atom = mol->getAtomAt(rbStamp->getMemberAt(i)); |
244 |
> |
atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i)); |
245 |
> |
rb->addAtom(atom, atomStamp); |
246 |
|
} |
247 |
|
|
248 |
< |
//after all of the atoms are added, we need to calculate the reference coordinates |
248 |
> |
//after all of the atoms are added, we need to calculate the |
249 |
> |
//reference coordinates |
250 |
|
rb->calcRefCoords(); |
251 |
|
|
252 |
|
//set the local index of this rigid body, global index will be set later |
253 |
|
rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex()); |
254 |
|
|
255 |
< |
//the rule for naming rigidbody MoleculeName_RB_Integer |
256 |
< |
//The first part is the name of the molecule |
257 |
< |
//The second part is alway fixed as "RB" |
258 |
< |
//The third part is the index of the rigidbody defined in meta-data file |
259 |
< |
//For example, Butane_RB_0 is a valid rigid body name of butane molecule |
255 |
< |
/**@todo replace itoa by lexi_cast */ |
256 |
< |
std::string s = OOPSE_itoa(mol->getNRigidBodies(), 10); |
257 |
< |
rb->setType(mol->getType() + "_RB_" + s.c_str()); |
255 |
> |
// The rule for naming a rigidbody is: MoleculeName_RB_Integer |
256 |
> |
// The first part is the name of the molecule |
257 |
> |
// The second part is always fixed as "RB" |
258 |
> |
// The third part is the index of the rigidbody defined in meta-data file |
259 |
> |
// For example, Butane_RB_0 is a valid rigid body name of butane molecule |
260 |
|
|
261 |
+ |
std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10); |
262 |
+ |
rb->setType(mol->getType() + "_RB_" + s.c_str()); |
263 |
|
return rb; |
264 |
< |
} |
264 |
> |
} |
265 |
|
|
266 |
< |
Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) { |
266 |
> |
Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, |
267 |
> |
BondStamp* stamp, |
268 |
> |
LocalIndexManager* localIndexMan) { |
269 |
|
BondType* bondType; |
270 |
|
Atom* atomA; |
271 |
|
Atom* atomB; |
272 |
< |
|
272 |
> |
|
273 |
|
atomA = mol->getAtomAt(stamp->getA()); |
274 |
|
atomB = mol->getAtomAt(stamp->getB()); |
275 |
< |
|
275 |
> |
|
276 |
|
assert( atomA && atomB); |
277 |
|
|
278 |
|
bondType = ff->getBondType(atomA->getType(), atomB->getType()); |
279 |
|
|
280 |
|
if (bondType == NULL) { |
281 |
< |
sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", |
282 |
< |
atomA->getType().c_str(), |
283 |
< |
atomB->getType().c_str()); |
281 |
> |
sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", |
282 |
> |
atomA->getType().c_str(), |
283 |
> |
atomB->getType().c_str()); |
284 |
> |
|
285 |
> |
painCave.isFatal = 1; |
286 |
> |
simError(); |
287 |
> |
} |
288 |
> |
Bond* bond = new Bond(atomA, atomB, bondType); |
289 |
|
|
290 |
+ |
//set the local index of this bond, the global index will be set later |
291 |
+ |
bond->setLocalIndex(localIndexMan->getNextBondIndex()); |
292 |
+ |
|
293 |
+ |
// The rule for naming a bond is: MoleculeName_Bond_Integer |
294 |
+ |
// The first part is the name of the molecule |
295 |
+ |
// The second part is always fixed as "Bond" |
296 |
+ |
// The third part is the index of the bond defined in meta-data file |
297 |
+ |
// For example, Butane_bond_0 is a valid Bond name in a butane molecule |
298 |
+ |
|
299 |
+ |
std::string s = OpenMD_itoa(mol->getNBonds(), 10); |
300 |
+ |
bond->setName(mol->getType() + "_Bond_" + s.c_str()); |
301 |
+ |
return bond; |
302 |
+ |
} |
303 |
+ |
|
304 |
+ |
Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, |
305 |
+ |
BendStamp* stamp, |
306 |
+ |
LocalIndexManager* localIndexMan) { |
307 |
+ |
Bend* bend = NULL; |
308 |
+ |
std::vector<int> bendAtoms = stamp->getMembers(); |
309 |
+ |
if (bendAtoms.size() == 3) { |
310 |
+ |
Atom* atomA = mol->getAtomAt(bendAtoms[0]); |
311 |
+ |
Atom* atomB = mol->getAtomAt(bendAtoms[1]); |
312 |
+ |
Atom* atomC = mol->getAtomAt(bendAtoms[2]); |
313 |
+ |
|
314 |
+ |
assert( atomA && atomB && atomC); |
315 |
+ |
|
316 |
+ |
BendType* bendType = ff->getBendType(atomA->getType().c_str(), |
317 |
+ |
atomB->getType().c_str(), |
318 |
+ |
atomC->getType().c_str()); |
319 |
+ |
|
320 |
+ |
if (bendType == NULL) { |
321 |
+ |
sprintf(painCave.errMsg, |
322 |
+ |
"Can not find Matching Bend Type for[%s, %s, %s]", |
323 |
+ |
atomA->getType().c_str(), |
324 |
+ |
atomB->getType().c_str(), |
325 |
+ |
atomC->getType().c_str()); |
326 |
+ |
|
327 |
|
painCave.isFatal = 1; |
328 |
|
simError(); |
329 |
< |
} |
330 |
< |
return new Bond(atomA, atomB, bondType); |
331 |
< |
} |
329 |
> |
} |
330 |
> |
|
331 |
> |
bend = new Bend(atomA, atomB, atomC, bendType); |
332 |
> |
} else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) { |
333 |
> |
int ghostIndex = stamp->getGhostVectorSource(); |
334 |
> |
int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1]; |
335 |
> |
Atom* normalAtom = mol->getAtomAt(normalIndex) ; |
336 |
> |
DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex)); |
337 |
> |
if (ghostAtom == NULL) { |
338 |
> |
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
339 |
> |
painCave.isFatal = 1; |
340 |
> |
simError(); |
341 |
> |
} |
342 |
> |
|
343 |
> |
BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST"); |
344 |
|
|
345 |
< |
Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) { |
346 |
< |
bool isGhostBend = false; |
347 |
< |
int ghostIndex; |
345 |
> |
if (bendType == NULL) { |
346 |
> |
sprintf(painCave.errMsg, |
347 |
> |
"Can not find Matching Bend Type for[%s, %s, %s]", |
348 |
> |
normalAtom->getType().c_str(), |
349 |
> |
ghostAtom->getType().c_str(), |
350 |
> |
"GHOST"); |
351 |
|
|
352 |
< |
|
353 |
< |
// |
354 |
< |
if (stamp->haveExtras()){ |
355 |
< |
LinkedAssign* extras = stamp->getExtras(); |
356 |
< |
LinkedAssign* currentExtra = extras; |
352 |
> |
painCave.isFatal = 1; |
353 |
> |
simError(); |
354 |
> |
} |
355 |
> |
|
356 |
> |
bend = new GhostBend(normalAtom, ghostAtom, bendType); |
357 |
> |
|
358 |
> |
} |
359 |
|
|
360 |
< |
while (currentExtra != NULL){ |
361 |
< |
if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){ |
297 |
< |
switch (currentExtra->getType()){ |
298 |
< |
case 0: |
299 |
< |
ghostIndex = currentExtra->getInt(); |
300 |
< |
isGhostBend = true; |
301 |
< |
break; |
360 |
> |
//set the local index of this bend, the global index will be set later |
361 |
> |
bend->setLocalIndex(localIndexMan->getNextBendIndex()); |
362 |
|
|
363 |
< |
default: |
364 |
< |
sprintf(painCave.errMsg, |
365 |
< |
"SimSetup Error: ghostVectorSource must be an int.\n"); |
366 |
< |
painCave.isFatal = 1; |
367 |
< |
simError(); |
308 |
< |
} |
309 |
< |
} else{ |
310 |
< |
sprintf(painCave.errMsg, |
311 |
< |
"SimSetup Error: unhandled bend assignment:\n"); |
312 |
< |
painCave.isFatal = 1; |
313 |
< |
simError(); |
314 |
< |
} |
315 |
< |
currentExtra = currentExtra->getNext(); |
316 |
< |
} |
317 |
< |
|
318 |
< |
} |
363 |
> |
// The rule for naming a bend is: MoleculeName_Bend_Integer |
364 |
> |
// The first part is the name of the molecule |
365 |
> |
// The second part is always fixed as "Bend" |
366 |
> |
// The third part is the index of the bend defined in meta-data file |
367 |
> |
// For example, Butane_Bend_0 is a valid Bend name in a butane molecule |
368 |
|
|
369 |
< |
if (isGhostBend) { |
369 |
> |
std::string s = OpenMD_itoa(mol->getNBends(), 10); |
370 |
> |
bend->setName(mol->getType() + "_Bend_" + s.c_str()); |
371 |
> |
return bend; |
372 |
> |
} |
373 |
|
|
374 |
< |
int indexA = stamp->getA(); |
375 |
< |
int indexB= stamp->getB(); |
374 |
> |
Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, |
375 |
> |
TorsionStamp* stamp, |
376 |
> |
LocalIndexManager* localIndexMan) { |
377 |
|
|
378 |
< |
assert(indexA != indexB); |
378 |
> |
Torsion* torsion = NULL; |
379 |
> |
std::vector<int> torsionAtoms = stamp->getMembers(); |
380 |
> |
if (torsionAtoms.size() < 3) { |
381 |
> |
return torsion; |
382 |
> |
} |
383 |
|
|
384 |
< |
int normalIndex; |
385 |
< |
if (indexA == ghostIndex) { |
386 |
< |
normalIndex = indexB; |
330 |
< |
} else if (indexB == ghostIndex) { |
331 |
< |
normalIndex = indexA; |
332 |
< |
} |
333 |
< |
|
334 |
< |
Atom* normalAtom = mol->getAtomAt(normalIndex) ; |
335 |
< |
DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex)); |
336 |
< |
if (ghostAtom == NULL) { |
337 |
< |
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
338 |
< |
painCave.isFatal = 1; |
339 |
< |
simError(); |
340 |
< |
} |
341 |
< |
|
342 |
< |
BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST"); |
384 |
> |
Atom* atomA = mol->getAtomAt(torsionAtoms[0]); |
385 |
> |
Atom* atomB = mol->getAtomAt(torsionAtoms[1]); |
386 |
> |
Atom* atomC = mol->getAtomAt(torsionAtoms[2]); |
387 |
|
|
388 |
< |
if (bendType == NULL) { |
389 |
< |
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
346 |
< |
normalAtom->getType().c_str(), |
347 |
< |
ghostAtom->getType().c_str(), |
348 |
< |
"GHOST"); |
388 |
> |
if (torsionAtoms.size() == 4) { |
389 |
> |
Atom* atomD = mol->getAtomAt(torsionAtoms[3]); |
390 |
|
|
391 |
< |
painCave.isFatal = 1; |
351 |
< |
simError(); |
352 |
< |
} |
391 |
> |
assert(atomA && atomB && atomC && atomD); |
392 |
|
|
393 |
< |
return new GhostBend(normalAtom, ghostAtom, bendType); |
394 |
< |
|
395 |
< |
} else { |
396 |
< |
|
397 |
< |
Atom* atomA = mol->getAtomAt(stamp->getA()); |
398 |
< |
Atom* atomB = mol->getAtomAt(stamp->getB()); |
399 |
< |
Atom* atomC = mol->getAtomAt(stamp->getC()); |
400 |
< |
|
401 |
< |
assert( atomA && atomB && atomC); |
393 |
> |
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), |
394 |
> |
atomB->getType(), |
395 |
> |
atomC->getType(), |
396 |
> |
atomD->getType()); |
397 |
> |
if (torsionType == NULL) { |
398 |
> |
sprintf(painCave.errMsg, |
399 |
> |
"Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
400 |
> |
atomA->getType().c_str(), |
401 |
> |
atomB->getType().c_str(), |
402 |
> |
atomC->getType().c_str(), |
403 |
> |
atomD->getType().c_str()); |
404 |
|
|
405 |
< |
BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType()); |
405 |
> |
painCave.isFatal = 1; |
406 |
> |
simError(); |
407 |
> |
} |
408 |
> |
|
409 |
> |
torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType); |
410 |
> |
} |
411 |
> |
else { |
412 |
> |
|
413 |
> |
DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource())); |
414 |
> |
if (dAtom == NULL) { |
415 |
> |
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
416 |
> |
painCave.isFatal = 1; |
417 |
> |
simError(); |
418 |
> |
} |
419 |
> |
|
420 |
> |
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), |
421 |
> |
atomC->getType(), "GHOST"); |
422 |
> |
|
423 |
> |
if (torsionType == NULL) { |
424 |
> |
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
425 |
> |
atomA->getType().c_str(), |
426 |
> |
atomB->getType().c_str(), |
427 |
> |
atomC->getType().c_str(), |
428 |
> |
"GHOST"); |
429 |
> |
|
430 |
> |
painCave.isFatal = 1; |
431 |
> |
simError(); |
432 |
> |
} |
433 |
> |
|
434 |
> |
torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType); |
435 |
> |
} |
436 |
|
|
437 |
< |
if (bendType == NULL) { |
438 |
< |
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
439 |
< |
atomA->getType().c_str(), |
440 |
< |
atomB->getType().c_str(), |
441 |
< |
atomC->getType().c_str()); |
437 |
> |
//set the local index of this torsion, the global index will be set later |
438 |
> |
torsion->setLocalIndex(localIndexMan->getNextTorsionIndex()); |
439 |
> |
|
440 |
> |
// The rule for naming a torsion is: MoleculeName_Torsion_Integer |
441 |
> |
// The first part is the name of the molecule |
442 |
> |
// The second part is always fixed as "Torsion" |
443 |
> |
// The third part is the index of the torsion defined in meta-data file |
444 |
> |
// For example, Butane_Torsion_0 is a valid Torsion name in a |
445 |
> |
// butane molecule |
446 |
|
|
447 |
< |
painCave.isFatal = 1; |
448 |
< |
simError(); |
449 |
< |
} |
447 |
> |
std::string s = OpenMD_itoa(mol->getNTorsions(), 10); |
448 |
> |
torsion->setName(mol->getType() + "_Torsion_" + s.c_str()); |
449 |
> |
return torsion; |
450 |
> |
} |
451 |
|
|
452 |
< |
return new Bend(atomA, atomB, atomC, bendType); |
452 |
> |
Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol, |
453 |
> |
InversionStamp* stamp, |
454 |
> |
LocalIndexManager* localIndexMan) { |
455 |
> |
|
456 |
> |
Inversion* inversion = NULL; |
457 |
> |
int center = stamp->getCenter(); |
458 |
> |
std::vector<int> satellites = stamp->getSatellites(); |
459 |
> |
if (satellites.size() != 3) { |
460 |
> |
return inversion; |
461 |
|
} |
378 |
– |
} |
462 |
|
|
463 |
< |
Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) { |
463 |
> |
Atom* atomA = mol->getAtomAt(center); |
464 |
> |
Atom* atomB = mol->getAtomAt(satellites[0]); |
465 |
> |
Atom* atomC = mol->getAtomAt(satellites[1]); |
466 |
> |
Atom* atomD = mol->getAtomAt(satellites[2]); |
467 |
> |
|
468 |
> |
assert(atomA && atomB && atomC && atomD); |
469 |
> |
|
470 |
> |
InversionType* inversionType = ff->getInversionType(atomA->getType(), |
471 |
> |
atomB->getType(), |
472 |
> |
atomC->getType(), |
473 |
> |
atomD->getType()); |
474 |
|
|
475 |
< |
Atom* atomA = mol->getAtomAt(stamp->getA()); |
476 |
< |
Atom* atomB = mol->getAtomAt(stamp->getB()); |
477 |
< |
Atom* atomC = mol->getAtomAt(stamp->getC()); |
478 |
< |
Torsion* torsion; |
475 |
> |
if (inversionType == NULL) { |
476 |
> |
sprintf(painCave.errMsg, "No Matching Inversion Type for[%s, %s, %s, %s]\n" |
477 |
> |
"\t(May not be a problem: not all inversions are parametrized)\n", |
478 |
> |
atomA->getType().c_str(), |
479 |
> |
atomB->getType().c_str(), |
480 |
> |
atomC->getType().c_str(), |
481 |
> |
atomD->getType().c_str()); |
482 |
> |
|
483 |
> |
painCave.isFatal = 0; |
484 |
> |
painCave.severity = OPENMD_INFO; |
485 |
> |
simError(); |
486 |
> |
return NULL; |
487 |
> |
} else { |
488 |
> |
|
489 |
> |
inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType); |
490 |
|
|
491 |
< |
if (stamp->getD() != -1) { |
492 |
< |
Atom* atomD = mol->getAtomAt(stamp->getD()); |
491 |
> |
// set the local index of this inversion, the global index will |
492 |
> |
// be set later |
493 |
> |
inversion->setLocalIndex(localIndexMan->getNextInversionIndex()); |
494 |
|
|
495 |
< |
assert(atomA && atomB && atomC && atomD); |
496 |
< |
|
497 |
< |
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), |
498 |
< |
atomC->getType(), atomD->getType()); |
495 |
> |
// The rule for naming an inversion is: MoleculeName_Inversion_Integer |
496 |
> |
// The first part is the name of the molecule |
497 |
> |
// The second part is always fixed as "Inversion" |
498 |
> |
// The third part is the index of the inversion defined in meta-data file |
499 |
> |
// For example, Benzene_Inversion_0 is a valid Inversion name in a |
500 |
> |
// Benzene molecule |
501 |
|
|
502 |
< |
if (torsionType == NULL) { |
503 |
< |
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
504 |
< |
atomA->getType().c_str(), |
398 |
< |
atomB->getType().c_str(), |
399 |
< |
atomC->getType().c_str(), |
400 |
< |
atomD->getType().c_str()); |
401 |
< |
|
402 |
< |
painCave.isFatal = 1; |
403 |
< |
simError(); |
404 |
< |
} |
405 |
< |
|
406 |
< |
torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType); |
502 |
> |
std::string s = OpenMD_itoa(mol->getNInversions(), 10); |
503 |
> |
inversion->setName(mol->getType() + "_Inversion_" + s.c_str()); |
504 |
> |
return inversion; |
505 |
|
} |
506 |
< |
else { |
506 |
> |
} |
507 |
> |
|
508 |
|
|
509 |
< |
DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(atomC); |
510 |
< |
if (dAtom == NULL) { |
511 |
< |
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
413 |
< |
painCave.isFatal = 1; |
414 |
< |
simError(); |
415 |
< |
} |
416 |
< |
|
417 |
< |
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), |
418 |
< |
atomC->getType(), "GHOST"); |
419 |
< |
|
420 |
< |
if (torsionType == NULL) { |
421 |
< |
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
422 |
< |
atomA->getType().c_str(), |
423 |
< |
atomB->getType().c_str(), |
424 |
< |
atomC->getType().c_str(), |
425 |
< |
"GHOST"); |
426 |
< |
|
427 |
< |
painCave.isFatal = 1; |
428 |
< |
simError(); |
429 |
< |
} |
430 |
< |
|
431 |
< |
torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType); |
432 |
< |
} |
433 |
< |
|
434 |
< |
return torsion; |
435 |
< |
} |
436 |
< |
|
437 |
< |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) { |
509 |
> |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, |
510 |
> |
CutoffGroupStamp* stamp, |
511 |
> |
LocalIndexManager* localIndexMan) { |
512 |
|
int nAtoms; |
513 |
|
CutoffGroup* cg; |
514 |
|
Atom* atom; |
516 |
|
|
517 |
|
nAtoms = stamp->getNMembers(); |
518 |
|
for (int i =0; i < nAtoms; ++i) { |
519 |
< |
atom = mol->getAtomAt(stamp->getMember(i)); |
520 |
< |
assert(atom); |
521 |
< |
cg->addAtom(atom); |
519 |
> |
atom = mol->getAtomAt(stamp->getMemberAt(i)); |
520 |
> |
assert(atom); |
521 |
> |
cg->addAtom(atom); |
522 |
|
} |
523 |
< |
|
523 |
> |
|
524 |
> |
//set the local index of this cutoffGroup, global index will be set later |
525 |
> |
cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex()); |
526 |
> |
|
527 |
|
return cg; |
528 |
< |
} |
529 |
< |
|
530 |
< |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) { |
528 |
> |
} |
529 |
> |
|
530 |
> |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom, |
531 |
> |
LocalIndexManager* localIndexMan) { |
532 |
|
CutoffGroup* cg; |
533 |
|
cg = new CutoffGroup(); |
534 |
|
cg->addAtom(atom); |
535 |
+ |
|
536 |
+ |
//set the local index of this cutoffGroup, global index will be set later |
537 |
+ |
cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex()); |
538 |
+ |
|
539 |
|
return cg; |
540 |
< |
} |
540 |
> |
} |
541 |
|
|
542 |
< |
void MoleculeCreator::createConstraintPair(Molecule* mol) { |
542 |
> |
void MoleculeCreator::createConstraintPair(Molecule* mol) { |
543 |
|
|
544 |
|
//add bond constraints |
545 |
|
Molecule::BondIterator bi; |
546 |
|
Bond* bond; |
547 |
|
for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) { |
548 |
|
|
549 |
< |
BondType* bt = bond->getBondType(); |
549 |
> |
BondType* bt = bond->getBondType(); |
550 |
|
|
551 |
< |
//class Parent1 {}; |
552 |
< |
//class Child1 : public Parent {}; |
471 |
< |
//class Child2 : public Parent {}; |
472 |
< |
//Child1* ch1 = new Child1(); |
473 |
< |
//Child2* ch2 = dynamic_cast<Child2*>(ch1); |
474 |
< |
//the dynamic_cast is succeed in above line. A compiler bug? |
551 |
> |
if (typeid(FixedBondType) == typeid(*bt)) { |
552 |
> |
FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); |
553 |
|
|
554 |
< |
if (typeid(FixedBondType) == typeid(*bt)) { |
555 |
< |
FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); |
556 |
< |
|
557 |
< |
ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA()); |
558 |
< |
ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB()); |
481 |
< |
ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength()); |
482 |
< |
mol->addConstraintPair(consPair); |
483 |
< |
} |
554 |
> |
ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA()); |
555 |
> |
ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB()); |
556 |
> |
ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength()); |
557 |
> |
mol->addConstraintPair(consPair); |
558 |
> |
} |
559 |
|
} |
560 |
|
|
561 |
|
//rigidbody -- rigidbody constraint is not support yet |
562 |
< |
} |
562 |
> |
} |
563 |
|
|
564 |
< |
void MoleculeCreator::createConstraintElem(Molecule* mol) { |
564 |
> |
void MoleculeCreator::createConstraintElem(Molecule* mol) { |
565 |
|
|
566 |
|
ConstraintPair* consPair; |
567 |
|
Molecule::ConstraintPairIterator cpi; |
568 |
|
std::set<StuntDouble*> sdSet; |
569 |
|
for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) { |
570 |
|
|
571 |
< |
StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble(); |
572 |
< |
if (sdSet.find(sdA) == sdSet.end()){ |
573 |
< |
sdSet.insert(sdA); |
574 |
< |
mol->addConstraintElem(new ConstraintElem(sdA)); |
575 |
< |
} |
571 |
> |
StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble(); |
572 |
> |
if (sdSet.find(sdA) == sdSet.end()){ |
573 |
> |
sdSet.insert(sdA); |
574 |
> |
mol->addConstraintElem(new ConstraintElem(sdA)); |
575 |
> |
} |
576 |
|
|
577 |
< |
StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble(); |
578 |
< |
if (sdSet.find(sdB) == sdSet.end()){ |
579 |
< |
sdSet.insert(sdB); |
580 |
< |
mol->addConstraintElem(new ConstraintElem(sdB)); |
581 |
< |
} |
577 |
> |
StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble(); |
578 |
> |
if (sdSet.find(sdB) == sdSet.end()){ |
579 |
> |
sdSet.insert(sdB); |
580 |
> |
mol->addConstraintElem(new ConstraintElem(sdB)); |
581 |
> |
} |
582 |
|
|
583 |
|
} |
584 |
|
|
585 |
< |
} |
585 |
> |
} |
586 |
|
|
587 |
|
} |