| 48 |
|
*/ |
| 49 |
|
|
| 50 |
|
#include <cassert> |
| 51 |
+ |
#include <typeinfo> |
| 52 |
|
#include <set> |
| 53 |
|
|
| 54 |
|
#include "brains/MoleculeCreator.hpp" |
| 64 |
|
Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp, |
| 65 |
|
int stampId, int globalIndex, LocalIndexManager* localIndexMan) { |
| 66 |
|
|
| 67 |
< |
Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getID()); |
| 67 |
> |
Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName()); |
| 68 |
|
|
| 69 |
|
//create atoms |
| 70 |
|
Atom* atom; |
| 71 |
|
AtomStamp* currentAtomStamp; |
| 72 |
|
int nAtom = molStamp->getNAtoms(); |
| 73 |
|
for (int i = 0; i < nAtom; ++i) { |
| 74 |
< |
currentAtomStamp = molStamp->getAtom(i); |
| 74 |
> |
currentAtomStamp = molStamp->getAtomStamp(i); |
| 75 |
|
atom = createAtom(ff, mol, currentAtomStamp, localIndexMan); |
| 76 |
|
mol->addAtom(atom); |
| 77 |
|
} |
| 82 |
|
int nRigidbodies = molStamp->getNRigidBodies(); |
| 83 |
|
|
| 84 |
|
for (int i = 0; i < nRigidbodies; ++i) { |
| 85 |
< |
currentRigidBodyStamp = molStamp->getRigidBody(i); |
| 85 |
> |
currentRigidBodyStamp = molStamp->getRigidBodyStamp(i); |
| 86 |
|
rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan); |
| 87 |
|
mol->addRigidBody(rb); |
| 88 |
|
} |
| 93 |
|
int nBonds = molStamp->getNBonds(); |
| 94 |
|
|
| 95 |
|
for (int i = 0; i < nBonds; ++i) { |
| 96 |
< |
currentBondStamp = molStamp->getBond(i); |
| 96 |
> |
currentBondStamp = molStamp->getBondStamp(i); |
| 97 |
|
bond = createBond(ff, mol, currentBondStamp); |
| 98 |
|
mol->addBond(bond); |
| 99 |
|
} |
| 103 |
|
BendStamp* currentBendStamp; |
| 104 |
|
int nBends = molStamp->getNBends(); |
| 105 |
|
for (int i = 0; i < nBends; ++i) { |
| 106 |
< |
currentBendStamp = molStamp->getBend(i); |
| 106 |
> |
currentBendStamp = molStamp->getBendStamp(i); |
| 107 |
|
bend = createBend(ff, mol, currentBendStamp); |
| 108 |
|
mol->addBend(bend); |
| 109 |
|
} |
| 113 |
|
TorsionStamp* currentTorsionStamp; |
| 114 |
|
int nTorsions = molStamp->getNTorsions(); |
| 115 |
|
for (int i = 0; i < nTorsions; ++i) { |
| 116 |
< |
currentTorsionStamp = molStamp->getTorsion(i); |
| 116 |
> |
currentTorsionStamp = molStamp->getTorsionStamp(i); |
| 117 |
|
torsion = createTorsion(ff, mol, currentTorsionStamp); |
| 118 |
|
mol->addTorsion(torsion); |
| 119 |
|
} |
| 123 |
|
CutoffGroupStamp* currentCutoffGroupStamp; |
| 124 |
|
int nCutoffGroups = molStamp->getNCutoffGroups(); |
| 125 |
|
for (int i = 0; i < nCutoffGroups; ++i) { |
| 126 |
< |
currentCutoffGroupStamp = molStamp->getCutoffGroup(i); |
| 126 |
> |
currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i); |
| 127 |
|
cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp); |
| 128 |
|
mol->addCutoffGroup(cutoffGroup); |
| 129 |
|
} |
| 176 |
|
|
| 177 |
|
if (atomType == NULL) { |
| 178 |
|
sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", |
| 179 |
< |
stamp->getType()); |
| 179 |
> |
stamp->getType().c_str()); |
| 180 |
|
|
| 181 |
|
painCave.isFatal = 1; |
| 182 |
|
simError(); |
| 220 |
|
for (int i = 0; i < nAtoms; ++i) { |
| 221 |
|
//rbStamp->getMember(i) return the local index of current atom inside the molecule. |
| 222 |
|
//It is not the same as local index of atom which is the index of atom at DataStorage class |
| 223 |
< |
atom = mol->getAtomAt(rbStamp->getMember(i)); |
| 224 |
< |
atomStamp= molStamp->getAtom(rbStamp->getMember(i)); |
| 223 |
> |
atom = mol->getAtomAt(rbStamp->getMemberAt(i)); |
| 224 |
> |
atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i)); |
| 225 |
|
rb->addAtom(atom, atomStamp); |
| 226 |
|
} |
| 227 |
|
|
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) { |
| 270 |
< |
bool isGhostBend = false; |
| 271 |
< |
int ghostIndex; |
| 270 |
> |
Bend* bend = NULL; |
| 271 |
> |
std::vector<int> bendAtoms = stamp->getMembers(); |
| 272 |
> |
if (bendAtoms.size() == 3) { |
| 273 |
> |
Atom* atomA = mol->getAtomAt(bendAtoms[0]); |
| 274 |
> |
Atom* atomB = mol->getAtomAt(bendAtoms[1]); |
| 275 |
> |
Atom* atomC = mol->getAtomAt(bendAtoms[2]); |
| 276 |
|
|
| 277 |
< |
|
| 278 |
< |
// |
| 279 |
< |
if (stamp->haveExtras()){ |
| 275 |
< |
LinkedAssign* extras = stamp->getExtras(); |
| 276 |
< |
LinkedAssign* currentExtra = extras; |
| 277 |
> |
assert( atomA && atomB && atomC); |
| 278 |
> |
|
| 279 |
> |
BendType* bendType = ff->getBendType(atomA->getType().c_str(), atomB->getType().c_str(), atomC->getType().c_str()); |
| 280 |
|
|
| 281 |
< |
while (currentExtra != NULL){ |
| 282 |
< |
if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){ |
| 283 |
< |
switch (currentExtra->getType()){ |
| 284 |
< |
case 0: |
| 285 |
< |
ghostIndex = currentExtra->getInt(); |
| 283 |
< |
isGhostBend = true; |
| 284 |
< |
break; |
| 281 |
> |
if (bendType == NULL) { |
| 282 |
> |
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
| 283 |
> |
atomA->getType().c_str(), |
| 284 |
> |
atomB->getType().c_str(), |
| 285 |
> |
atomC->getType().c_str()); |
| 286 |
|
|
| 287 |
< |
default: |
| 288 |
< |
sprintf(painCave.errMsg, |
| 288 |
< |
"SimSetup Error: ghostVectorSource must be an int.\n"); |
| 289 |
< |
painCave.isFatal = 1; |
| 290 |
< |
simError(); |
| 291 |
< |
} |
| 292 |
< |
} else{ |
| 293 |
< |
sprintf(painCave.errMsg, |
| 294 |
< |
"SimSetup Error: unhandled bend assignment:\n"); |
| 295 |
< |
painCave.isFatal = 1; |
| 296 |
< |
simError(); |
| 297 |
< |
} |
| 298 |
< |
currentExtra = currentExtra->getNext(); |
| 299 |
< |
} |
| 300 |
< |
|
| 301 |
< |
} |
| 302 |
< |
|
| 303 |
< |
if (isGhostBend) { |
| 304 |
< |
|
| 305 |
< |
int indexA = stamp->getA(); |
| 306 |
< |
int indexB= stamp->getB(); |
| 307 |
< |
|
| 308 |
< |
assert(indexA != indexB); |
| 309 |
< |
|
| 310 |
< |
int normalIndex; |
| 311 |
< |
if (indexA == ghostIndex) { |
| 312 |
< |
normalIndex = indexB; |
| 313 |
< |
} else if (indexB == ghostIndex) { |
| 314 |
< |
normalIndex = indexA; |
| 287 |
> |
painCave.isFatal = 1; |
| 288 |
> |
simError(); |
| 289 |
|
} |
| 290 |
< |
|
| 290 |
> |
|
| 291 |
> |
bend = new Bend(atomA, atomB, atomC, bendType); |
| 292 |
> |
} else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) { |
| 293 |
> |
int ghostIndex = stamp->getGhostVectorSource(); |
| 294 |
> |
int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1]; |
| 295 |
|
Atom* normalAtom = mol->getAtomAt(normalIndex) ; |
| 296 |
|
DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex)); |
| 297 |
|
if (ghostAtom == NULL) { |
| 312 |
|
simError(); |
| 313 |
|
} |
| 314 |
|
|
| 315 |
< |
return new GhostBend(normalAtom, ghostAtom, bendType); |
| 315 |
> |
bend = new GhostBend(normalAtom, ghostAtom, bendType); |
| 316 |
|
|
| 317 |
< |
} else { |
| 318 |
< |
|
| 319 |
< |
Atom* atomA = mol->getAtomAt(stamp->getA()); |
| 342 |
< |
Atom* atomB = mol->getAtomAt(stamp->getB()); |
| 343 |
< |
Atom* atomC = mol->getAtomAt(stamp->getC()); |
| 344 |
< |
|
| 345 |
< |
assert( atomA && atomB && atomC); |
| 346 |
< |
|
| 347 |
< |
BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType()); |
| 348 |
< |
|
| 349 |
< |
if (bendType == NULL) { |
| 350 |
< |
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
| 351 |
< |
atomA->getType().c_str(), |
| 352 |
< |
atomB->getType().c_str(), |
| 353 |
< |
atomC->getType().c_str()); |
| 354 |
< |
|
| 355 |
< |
painCave.isFatal = 1; |
| 356 |
< |
simError(); |
| 357 |
< |
} |
| 358 |
< |
|
| 359 |
< |
return new Bend(atomA, atomB, atomC, bendType); |
| 360 |
< |
} |
| 317 |
> |
} |
| 318 |
> |
|
| 319 |
> |
return bend; |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) { |
| 323 |
|
|
| 324 |
< |
Atom* atomA = mol->getAtomAt(stamp->getA()); |
| 325 |
< |
Atom* atomB = mol->getAtomAt(stamp->getB()); |
| 326 |
< |
Atom* atomC = mol->getAtomAt(stamp->getC()); |
| 327 |
< |
Torsion* torsion; |
| 324 |
> |
Torsion* torsion = NULL; |
| 325 |
> |
std::vector<int> torsionAtoms = stamp->getMembers(); |
| 326 |
> |
if (torsionAtoms.size() < 3) { |
| 327 |
> |
return torsion; |
| 328 |
> |
} |
| 329 |
|
|
| 330 |
< |
if (stamp->getD() != -1) { |
| 331 |
< |
Atom* atomD = mol->getAtomAt(stamp->getD()); |
| 330 |
> |
Atom* atomA = mol->getAtomAt(torsionAtoms[0]); |
| 331 |
> |
Atom* atomB = mol->getAtomAt(torsionAtoms[1]); |
| 332 |
> |
Atom* atomC = mol->getAtomAt(torsionAtoms[2]); |
| 333 |
|
|
| 334 |
+ |
if (torsionAtoms.size() == 4) { |
| 335 |
+ |
Atom* atomD = mol->getAtomAt(torsionAtoms[3]); |
| 336 |
+ |
|
| 337 |
|
assert(atomA && atomB && atomC && atomD); |
| 338 |
|
|
| 339 |
|
TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), |
| 354 |
|
} |
| 355 |
|
else { |
| 356 |
|
|
| 357 |
< |
DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(atomC); |
| 357 |
> |
DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource())); |
| 358 |
|
if (dAtom == NULL) { |
| 359 |
|
sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); |
| 360 |
|
painCave.isFatal = 1; |
| 389 |
|
|
| 390 |
|
nAtoms = stamp->getNMembers(); |
| 391 |
|
for (int i =0; i < nAtoms; ++i) { |
| 392 |
< |
atom = mol->getAtomAt(stamp->getMember(i)); |
| 392 |
> |
atom = mol->getAtomAt(stamp->getMemberAt(i)); |
| 393 |
|
assert(atom); |
| 394 |
|
cg->addAtom(atom); |
| 395 |
|
} |