37 |
|
namespace oopse { |
38 |
|
|
39 |
|
Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp, int stampId, int globalIndex) { |
40 |
< |
Molecule* mol = new Molecule(stampId, globalIndex); |
40 |
> |
Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getID()); |
41 |
|
|
42 |
|
//create atoms |
43 |
|
Atom* atom; |
101 |
|
mol->addCutoffGroup(cutoffGroup); |
102 |
|
} |
103 |
|
|
104 |
+ |
//every free atom is a cutoff group |
105 |
+ |
std::set<Atom*> allAtoms; |
106 |
+ |
typename Molecule::AtomIterator ai; |
107 |
+ |
|
108 |
+ |
//add all atoms into allAtoms set |
109 |
+ |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
110 |
+ |
allAtoms.insert(atom); |
111 |
+ |
} |
112 |
+ |
|
113 |
+ |
typename Molecule::CutoffGroupIterator ci; |
114 |
+ |
CutoffGroup* cg; |
115 |
+ |
std::set<Atom*> cutoffAtoms; |
116 |
+ |
|
117 |
+ |
//add all of the atoms belong to cutoff groups into cutoffAtoms set |
118 |
+ |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
119 |
+ |
|
120 |
+ |
for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
121 |
+ |
cutoffAtoms.insert(atom); |
122 |
+ |
} |
123 |
+ |
|
124 |
+ |
} |
125 |
+ |
|
126 |
+ |
//find all free atoms (which do not belong to cutoff groups) |
127 |
+ |
//performs the "difference" operation from set theory, the output range contains a copy of every |
128 |
+ |
//element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in |
129 |
+ |
//[cutoffAtoms.begin(), cutoffAtoms.end()). |
130 |
+ |
std::vector<Atom*> freeAtoms; |
131 |
+ |
std::set_difference(allAtoms.begin(), allAtoms.end(), cutoffAtoms.begin(), cutoffAtoms.end(), |
132 |
+ |
std::back_inserter(freeAtoms.end())); |
133 |
+ |
|
134 |
+ |
if (freeAtoms.size() != allAtoms.size() - cutoffAtoms.size()) { |
135 |
+ |
//Some atoms in rigidAtoms are not in allAtoms, something must be wrong |
136 |
+ |
sprintf(painCave.errMsg, "Atoms in cutoff groups are not in the atom list of the same molecule"); |
137 |
+ |
|
138 |
+ |
painCave.isFatal = 1; |
139 |
+ |
simError(); |
140 |
+ |
} |
141 |
+ |
|
142 |
+ |
//loop over the free atoms and then create one cutoff group for every single free atom |
143 |
+ |
std::vector<Atom*>::iterator fai; |
144 |
+ |
|
145 |
+ |
for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) { |
146 |
+ |
createCutoffGroup(mol, *fai); |
147 |
+ |
mol->addCutoffGroup(cutoffGroup); |
148 |
+ |
} |
149 |
|
//create constraints |
150 |
|
|
151 |
|
//the construction of this molecule is finished |
162 |
|
|
163 |
|
atomType = ff->getAtomType(stamp->getType()); |
164 |
|
|
165 |
+ |
if (bondType == NULL) { |
166 |
+ |
sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", |
167 |
+ |
stamp->getType()); |
168 |
+ |
|
169 |
+ |
painCave.isFatal = 1; |
170 |
+ |
simError(); |
171 |
+ |
} |
172 |
+ |
|
173 |
|
//below code still have some kind of hard-coding smell |
174 |
|
if (stamp->haveOrientation()){ |
175 |
|
DirectionalAtom* dAtom; |
205 |
|
Vector3d refCoor; |
206 |
|
AtomStamp* atomStamp; |
207 |
|
|
208 |
< |
nAtoms = stamp->getNMembers(); |
208 |
> |
nAtoms = molStamp->getNMembers(); |
209 |
|
|
210 |
|
RigidBody* rb = new RigidBody(); |
211 |
|
|
216 |
|
atomStamp= molStamp->molStamp->getAtom(rbStamp->getMember(i)); |
217 |
|
rb->addAtom(atom, atomStamp); |
218 |
|
} |
219 |
< |
|
219 |
> |
|
220 |
> |
//after all of the atoms are added, we need to calculate the reference coordinates |
221 |
|
rb->calcRefCoords(); |
222 |
+ |
|
223 |
+ |
//set the local index of this rigid body, global index will be set later |
224 |
|
rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex()); |
225 |
< |
rb->setType(mol->getType() + "_" + itoa(mol.getNRigidBodies())); |
225 |
> |
|
226 |
> |
//the rule for naming rigidbody MoleculeName_RB_Integer |
227 |
> |
//The first part is the name of the molecule |
228 |
> |
//The second part is alway fixed as "RB" |
229 |
> |
//The third part is the index of the rigidbody defined in meta-data file |
230 |
> |
//For example, Butane_RB_0 is a valid rigid body name of butane molecule |
231 |
> |
rb->setType(mol->getType() + "_RB_" + itoa(mol.getNRigidBodies())); |
232 |
|
|
233 |
|
return rb; |
234 |
|
} |
245 |
|
|
246 |
|
bondType = ff->getBondType(atomA, atomB); |
247 |
|
|
248 |
+ |
if (bondType == NULL) { |
249 |
+ |
sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", |
250 |
+ |
atomA->getType().c_str(), |
251 |
+ |
atomB->getType().c_str()); |
252 |
+ |
|
253 |
+ |
painCave.isFatal = 1; |
254 |
+ |
simError(); |
255 |
+ |
} |
256 |
|
return new Bond(atomA, atomB, bondType); |
257 |
|
} |
258 |
|
|
259 |
|
Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) { |
260 |
< |
BendType* benType; |
260 |
> |
BendType* bendType; |
261 |
|
Atom* atomA; |
262 |
|
Atom* atomB; |
263 |
|
Atom* atomC; |
269 |
|
|
270 |
|
assert( atomA && atomB && atomC); |
271 |
|
|
272 |
< |
benType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType()); |
272 |
> |
bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType()); |
273 |
|
|
274 |
< |
return new Bond(atomA, atomB, benType); |
274 |
> |
if (bendType == NULL) { |
275 |
> |
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
276 |
> |
atomA->getType().c_str(), |
277 |
> |
atomB->getType().c_str(), |
278 |
> |
atomC->getType().c_str()); |
279 |
|
|
280 |
+ |
painCave.isFatal = 1; |
281 |
+ |
simError(); |
282 |
+ |
} |
283 |
+ |
|
284 |
+ |
return new Bond(atomA, atomB, bendType); |
285 |
+ |
|
286 |
|
} |
287 |
|
|
288 |
|
Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) { |
302 |
|
torsionType = ff->getTosionType(atomA->getType(), atomB->getType(), |
303 |
|
atomC->getType(), atomD->getType()); |
304 |
|
|
305 |
+ |
if (torsionType == NULL) { |
306 |
+ |
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
307 |
+ |
atomA->getType().c_str(), |
308 |
+ |
atomB->getType().c_str(), |
309 |
+ |
atomC->getType().c_str(), |
310 |
+ |
atomD->getType().c_str()); |
311 |
+ |
|
312 |
+ |
painCave.isFatal = 1; |
313 |
+ |
simError(); |
314 |
+ |
} |
315 |
+ |
|
316 |
|
return new Torsion(atomA, atomB, torsionType); |
317 |
|
} |
318 |
|
|
332 |
|
return cg; |
333 |
|
} |
334 |
|
|
335 |
+ |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) { |
336 |
+ |
CutoffGroup* cg; |
337 |
+ |
cg = new CutoffGroup(); |
338 |
+ |
cg->addAtom(); |
339 |
+ |
return cg; |
340 |
+ |
} |
341 |
|
//Constraint* MoleculeCreator::createConstraint() { |
342 |
|
|
343 |
|
//} |