| 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 |  |  | * 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 | gezelter | 507 | /** | 
| 43 |  |  | * @file MoleculeCreator.cpp | 
| 44 |  |  | * @author tlin | 
| 45 |  |  | * @date 11/04/2004 | 
| 46 |  |  | * @time 13:44am | 
| 47 |  |  | * @version 1.0 | 
| 48 |  |  | */ | 
| 49 | gezelter | 246 |  | 
| 50 |  |  | #include <cassert> | 
| 51 |  |  | #include <set> | 
| 52 |  |  |  | 
| 53 |  |  | #include "brains/MoleculeCreator.hpp" | 
| 54 |  |  | #include "primitives/GhostBend.hpp" | 
| 55 | tim | 273 | #include "primitives/GhostTorsion.hpp" | 
| 56 | gezelter | 246 | #include "types/DirectionalAtomType.hpp" | 
| 57 |  |  | #include "types/FixedBondType.hpp" | 
| 58 |  |  | #include "utils/simError.h" | 
| 59 |  |  | #include "utils/StringUtils.hpp" | 
| 60 |  |  |  | 
| 61 |  |  | namespace oopse { | 
| 62 | tim | 647 |  | 
| 63 | gezelter | 507 | Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp, | 
| 64 |  |  | int stampId, int globalIndex, LocalIndexManager* localIndexMan) { | 
| 65 | gezelter | 246 |  | 
| 66 | tim | 770 | Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName()); | 
| 67 | gezelter | 246 |  | 
| 68 |  |  | //create atoms | 
| 69 |  |  | Atom* atom; | 
| 70 |  |  | AtomStamp* currentAtomStamp; | 
| 71 |  |  | int nAtom = molStamp->getNAtoms(); | 
| 72 |  |  | for (int i = 0; i < nAtom; ++i) { | 
| 73 | tim | 770 | currentAtomStamp = molStamp->getAtomStamp(i); | 
| 74 | gezelter | 507 | atom = createAtom(ff, mol, currentAtomStamp, localIndexMan); | 
| 75 |  |  | mol->addAtom(atom); | 
| 76 | gezelter | 246 | } | 
| 77 |  |  |  | 
| 78 |  |  | //create rigidbodies | 
| 79 |  |  | RigidBody* rb; | 
| 80 |  |  | RigidBodyStamp * currentRigidBodyStamp; | 
| 81 |  |  | int nRigidbodies = molStamp->getNRigidBodies(); | 
| 82 |  |  |  | 
| 83 |  |  | for (int i = 0; i < nRigidbodies; ++i) { | 
| 84 | tim | 770 | currentRigidBodyStamp = molStamp->getRigidBodyStamp(i); | 
| 85 | gezelter | 507 | rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan); | 
| 86 |  |  | mol->addRigidBody(rb); | 
| 87 | gezelter | 246 | } | 
| 88 |  |  |  | 
| 89 |  |  | //create bonds | 
| 90 |  |  | Bond* bond; | 
| 91 |  |  | BondStamp* currentBondStamp; | 
| 92 |  |  | int nBonds = molStamp->getNBonds(); | 
| 93 |  |  |  | 
| 94 |  |  | for (int i = 0; i < nBonds; ++i) { | 
| 95 | tim | 770 | currentBondStamp = molStamp->getBondStamp(i); | 
| 96 | gezelter | 507 | bond = createBond(ff, mol, currentBondStamp); | 
| 97 |  |  | mol->addBond(bond); | 
| 98 | gezelter | 246 | } | 
| 99 |  |  |  | 
| 100 |  |  | //create bends | 
| 101 |  |  | Bend* bend; | 
| 102 |  |  | BendStamp* currentBendStamp; | 
| 103 |  |  | int nBends = molStamp->getNBends(); | 
| 104 |  |  | for (int i = 0; i < nBends; ++i) { | 
| 105 | tim | 770 | currentBendStamp = molStamp->getBendStamp(i); | 
| 106 | gezelter | 507 | bend = createBend(ff, mol, currentBendStamp); | 
| 107 |  |  | mol->addBend(bend); | 
| 108 | gezelter | 246 | } | 
| 109 |  |  |  | 
| 110 |  |  | //create torsions | 
| 111 |  |  | Torsion* torsion; | 
| 112 |  |  | TorsionStamp* currentTorsionStamp; | 
| 113 |  |  | int nTorsions = molStamp->getNTorsions(); | 
| 114 |  |  | for (int i = 0; i < nTorsions; ++i) { | 
| 115 | tim | 770 | currentTorsionStamp = molStamp->getTorsionStamp(i); | 
| 116 | gezelter | 507 | torsion = createTorsion(ff, mol, currentTorsionStamp); | 
| 117 |  |  | mol->addTorsion(torsion); | 
| 118 | gezelter | 246 | } | 
| 119 |  |  |  | 
| 120 |  |  | //create cutoffGroups | 
| 121 |  |  | CutoffGroup* cutoffGroup; | 
| 122 |  |  | CutoffGroupStamp* currentCutoffGroupStamp; | 
| 123 |  |  | int nCutoffGroups = molStamp->getNCutoffGroups(); | 
| 124 |  |  | for (int i = 0; i < nCutoffGroups; ++i) { | 
| 125 | tim | 770 | currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i); | 
| 126 | gezelter | 507 | cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp); | 
| 127 |  |  | mol->addCutoffGroup(cutoffGroup); | 
| 128 | gezelter | 246 | } | 
| 129 |  |  |  | 
| 130 |  |  | //every free atom is a cutoff group | 
| 131 | tim | 647 | std::vector<Atom*> freeAtoms; | 
| 132 |  |  | std::vector<Atom*>::iterator ai; | 
| 133 |  |  | std::vector<Atom*>::iterator fai; | 
| 134 | gezelter | 246 |  | 
| 135 |  |  | //add all atoms into allAtoms set | 
| 136 | tim | 647 | for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) { | 
| 137 |  |  | freeAtoms.push_back(atom); | 
| 138 | gezelter | 246 | } | 
| 139 |  |  |  | 
| 140 |  |  | Molecule::CutoffGroupIterator ci; | 
| 141 |  |  | CutoffGroup* cg; | 
| 142 |  |  |  | 
| 143 |  |  | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 144 |  |  |  | 
| 145 | gezelter | 507 | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { | 
| 146 | tim | 647 | //erase the atoms belong to cutoff groups from freeAtoms vector | 
| 147 |  |  | freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom), freeAtoms.end()); | 
| 148 | gezelter | 507 | } | 
| 149 | gezelter | 246 |  | 
| 150 |  |  | } | 
| 151 |  |  |  | 
| 152 |  |  | //loop over the free atoms and then create one cutoff group for every single free atom | 
| 153 | tim | 647 |  | 
| 154 | gezelter | 246 | for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) { | 
| 155 | gezelter | 507 | cutoffGroup = createCutoffGroup(mol, *fai); | 
| 156 |  |  | mol->addCutoffGroup(cutoffGroup); | 
| 157 | gezelter | 246 | } | 
| 158 |  |  | //create constraints | 
| 159 |  |  | createConstraintPair(mol); | 
| 160 |  |  | createConstraintElem(mol); | 
| 161 |  |  |  | 
| 162 |  |  | //the construction of this molecule is finished | 
| 163 |  |  | mol->complete(); | 
| 164 |  |  |  | 
| 165 |  |  | return mol; | 
| 166 | gezelter | 507 | } | 
| 167 | gezelter | 246 |  | 
| 168 |  |  |  | 
| 169 | gezelter | 507 | Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp, | 
| 170 |  |  | LocalIndexManager* localIndexMan) { | 
| 171 | gezelter | 246 | AtomType * atomType; | 
| 172 |  |  | Atom* atom; | 
| 173 |  |  |  | 
| 174 |  |  | atomType =  ff->getAtomType(stamp->getType()); | 
| 175 |  |  |  | 
| 176 |  |  | if (atomType == NULL) { | 
| 177 | gezelter | 507 | sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", | 
| 178 | tim | 770 | stamp->getType().c_str()); | 
| 179 | gezelter | 246 |  | 
| 180 | gezelter | 507 | painCave.isFatal = 1; | 
| 181 |  |  | simError(); | 
| 182 | gezelter | 246 | } | 
| 183 |  |  |  | 
| 184 |  |  | //below code still have some kind of hard-coding smell | 
| 185 |  |  | if (atomType->isDirectional()){ | 
| 186 |  |  |  | 
| 187 | gezelter | 507 | DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); | 
| 188 | gezelter | 246 |  | 
| 189 | gezelter | 507 | if (dAtomType == NULL) { | 
| 190 |  |  | sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType"); | 
| 191 | gezelter | 246 |  | 
| 192 | gezelter | 507 | painCave.isFatal = 1; | 
| 193 |  |  | simError(); | 
| 194 |  |  | } | 
| 195 | gezelter | 246 |  | 
| 196 | gezelter | 507 | DirectionalAtom* dAtom; | 
| 197 |  |  | dAtom = new DirectionalAtom(dAtomType); | 
| 198 |  |  | atom = dAtom; | 
| 199 | gezelter | 246 | } | 
| 200 |  |  | else{ | 
| 201 | gezelter | 507 | atom = new Atom(atomType); | 
| 202 | gezelter | 246 | } | 
| 203 |  |  |  | 
| 204 |  |  | atom->setLocalIndex(localIndexMan->getNextAtomIndex()); | 
| 205 |  |  |  | 
| 206 |  |  | return atom; | 
| 207 | gezelter | 507 | } | 
| 208 | gezelter | 246 |  | 
| 209 | gezelter | 507 | RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol, | 
| 210 |  |  | RigidBodyStamp* rbStamp, | 
| 211 |  |  | LocalIndexManager* localIndexMan) { | 
| 212 | gezelter | 246 | Atom* atom; | 
| 213 |  |  | int nAtoms; | 
| 214 |  |  | Vector3d refCoor; | 
| 215 |  |  | AtomStamp* atomStamp; | 
| 216 |  |  |  | 
| 217 |  |  | RigidBody* rb = new RigidBody(); | 
| 218 |  |  | nAtoms = rbStamp->getNMembers(); | 
| 219 |  |  | for (int i = 0; i < nAtoms; ++i) { | 
| 220 | gezelter | 507 | //rbStamp->getMember(i) return the local index of current atom inside the molecule. | 
| 221 |  |  | //It is not the same as local index of atom which is the index of atom at DataStorage class | 
| 222 | tim | 770 | atom = mol->getAtomAt(rbStamp->getMemberAt(i)); | 
| 223 |  |  | atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i)); | 
| 224 | gezelter | 507 | rb->addAtom(atom, atomStamp); | 
| 225 | gezelter | 246 | } | 
| 226 |  |  |  | 
| 227 |  |  | //after all of the atoms are added, we need to calculate the reference coordinates | 
| 228 |  |  | rb->calcRefCoords(); | 
| 229 |  |  |  | 
| 230 |  |  | //set the local index of this rigid body, global index will be set later | 
| 231 |  |  | rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex()); | 
| 232 |  |  |  | 
| 233 |  |  | //the rule for naming rigidbody MoleculeName_RB_Integer | 
| 234 |  |  | //The first part is the name of the molecule | 
| 235 |  |  | //The second part is alway fixed as "RB" | 
| 236 |  |  | //The third part is the index of the rigidbody defined in meta-data file | 
| 237 |  |  | //For example, Butane_RB_0 is a valid rigid body name of butane molecule | 
| 238 |  |  | /**@todo replace itoa by lexi_cast */ | 
| 239 | gezelter | 403 | std::string s = OOPSE_itoa(mol->getNRigidBodies(), 10); | 
| 240 |  |  | rb->setType(mol->getType() + "_RB_" + s.c_str()); | 
| 241 | tim | 292 |  | 
| 242 | gezelter | 246 | return rb; | 
| 243 | gezelter | 507 | } | 
| 244 | gezelter | 246 |  | 
| 245 | gezelter | 507 | Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) { | 
| 246 | gezelter | 246 | BondType* bondType; | 
| 247 |  |  | Atom* atomA; | 
| 248 |  |  | Atom* atomB; | 
| 249 |  |  |  | 
| 250 |  |  | atomA = mol->getAtomAt(stamp->getA()); | 
| 251 |  |  | atomB = mol->getAtomAt(stamp->getB()); | 
| 252 |  |  |  | 
| 253 |  |  | assert( atomA && atomB); | 
| 254 |  |  |  | 
| 255 |  |  | bondType = ff->getBondType(atomA->getType(), atomB->getType()); | 
| 256 |  |  |  | 
| 257 |  |  | if (bondType == NULL) { | 
| 258 | gezelter | 507 | sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", | 
| 259 |  |  | atomA->getType().c_str(), | 
| 260 |  |  | atomB->getType().c_str()); | 
| 261 | gezelter | 246 |  | 
| 262 | gezelter | 507 | painCave.isFatal = 1; | 
| 263 |  |  | simError(); | 
| 264 | gezelter | 246 | } | 
| 265 |  |  | return new Bond(atomA, atomB, bondType); | 
| 266 | gezelter | 507 | } | 
| 267 | gezelter | 246 |  | 
| 268 | gezelter | 507 | Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) { | 
| 269 | tim | 770 | Bend* bend = NULL; | 
| 270 |  |  | std::vector<int> bendAtoms = stamp->getMembers(); | 
| 271 |  |  | if (bendAtoms.size() == 3) { | 
| 272 |  |  | Atom* atomA = mol->getAtomAt(bendAtoms[0]); | 
| 273 |  |  | Atom* atomB = mol->getAtomAt(bendAtoms[1]); | 
| 274 |  |  | Atom* atomC = mol->getAtomAt(bendAtoms[2]); | 
| 275 | gezelter | 246 |  | 
| 276 | tim | 770 | assert( atomA && atomB && atomC); | 
| 277 | gezelter | 246 |  | 
| 278 | tim | 770 | BendType* bendType = ff->getBendType(atomA->getType().c_str(), atomB->getType().c_str(), atomC->getType().c_str()); | 
| 279 | gezelter | 246 |  | 
| 280 | tim | 770 | if (bendType == NULL) { | 
| 281 |  |  | sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", | 
| 282 |  |  | atomA->getType().c_str(), | 
| 283 |  |  | atomB->getType().c_str(), | 
| 284 |  |  | atomC->getType().c_str()); | 
| 285 |  |  |  | 
| 286 |  |  | painCave.isFatal = 1; | 
| 287 |  |  | simError(); | 
| 288 | gezelter | 507 | } | 
| 289 | gezelter | 246 |  | 
| 290 | tim | 770 | bend = new Bend(atomA, atomB, atomC, bendType); | 
| 291 |  |  | } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) { | 
| 292 |  |  | int ghostIndex = stamp->getGhostVectorSource(); | 
| 293 |  |  | int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1]; | 
| 294 | gezelter | 507 | Atom* normalAtom = mol->getAtomAt(normalIndex) ; | 
| 295 |  |  | DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex)); | 
| 296 |  |  | if (ghostAtom == NULL) { | 
| 297 |  |  | sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); | 
| 298 |  |  | painCave.isFatal = 1; | 
| 299 |  |  | simError(); | 
| 300 |  |  | } | 
| 301 | gezelter | 246 |  | 
| 302 | gezelter | 507 | BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST"); | 
| 303 | gezelter | 246 |  | 
| 304 | gezelter | 507 | if (bendType == NULL) { | 
| 305 |  |  | sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", | 
| 306 |  |  | normalAtom->getType().c_str(), | 
| 307 |  |  | ghostAtom->getType().c_str(), | 
| 308 |  |  | "GHOST"); | 
| 309 | gezelter | 246 |  | 
| 310 | gezelter | 507 | painCave.isFatal = 1; | 
| 311 |  |  | simError(); | 
| 312 |  |  | } | 
| 313 | gezelter | 246 |  | 
| 314 | tim | 770 | bend = new GhostBend(normalAtom, ghostAtom, bendType); | 
| 315 | gezelter | 246 |  | 
| 316 | tim | 770 | } | 
| 317 |  |  |  | 
| 318 |  |  | return bend; | 
| 319 |  |  | } | 
| 320 | gezelter | 246 |  | 
| 321 | tim | 770 | Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) { | 
| 322 | gezelter | 246 |  | 
| 323 | tim | 770 | Torsion* torsion = NULL; | 
| 324 |  |  | std::vector<int> torsionAtoms = stamp->getMembers(); | 
| 325 |  |  | if (torsionAtoms.size() < 3) { | 
| 326 |  |  | return torsion; | 
| 327 | gezelter | 246 | } | 
| 328 |  |  |  | 
| 329 | tim | 770 | Atom* atomA = mol->getAtomAt(torsionAtoms[0]); | 
| 330 |  |  | Atom* atomB = mol->getAtomAt(torsionAtoms[1]); | 
| 331 |  |  | Atom* atomC = mol->getAtomAt(torsionAtoms[2]); | 
| 332 | gezelter | 246 |  | 
| 333 | tim | 770 | if (torsionAtoms.size() == 4) { | 
| 334 |  |  | Atom* atomD = mol->getAtomAt(torsionAtoms[3]); | 
| 335 | gezelter | 246 |  | 
| 336 | gezelter | 507 | assert(atomA && atomB && atomC && atomD); | 
| 337 | tim | 273 |  | 
| 338 | gezelter | 507 | TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), | 
| 339 |  |  | atomC->getType(), atomD->getType()); | 
| 340 | gezelter | 246 |  | 
| 341 | gezelter | 507 | if (torsionType == NULL) { | 
| 342 |  |  | sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", | 
| 343 |  |  | atomA->getType().c_str(), | 
| 344 |  |  | atomB->getType().c_str(), | 
| 345 |  |  | atomC->getType().c_str(), | 
| 346 |  |  | atomD->getType().c_str()); | 
| 347 | tim | 273 |  | 
| 348 | gezelter | 507 | painCave.isFatal = 1; | 
| 349 |  |  | simError(); | 
| 350 |  |  | } | 
| 351 | tim | 273 |  | 
| 352 | gezelter | 507 | torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType); | 
| 353 | gezelter | 246 | } | 
| 354 | tim | 273 | else { | 
| 355 |  |  |  | 
| 356 | tim | 770 | DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource())); | 
| 357 | gezelter | 507 | if (dAtom == NULL) { | 
| 358 |  |  | sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); | 
| 359 |  |  | painCave.isFatal = 1; | 
| 360 |  |  | simError(); | 
| 361 |  |  | } | 
| 362 | tim | 273 |  | 
| 363 | gezelter | 507 | TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), | 
| 364 |  |  | atomC->getType(), "GHOST"); | 
| 365 | tim | 273 |  | 
| 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 |  |  | "GHOST"); | 
| 372 | tim | 273 |  | 
| 373 | gezelter | 507 | painCave.isFatal = 1; | 
| 374 |  |  | simError(); | 
| 375 |  |  | } | 
| 376 | tim | 273 |  | 
| 377 | gezelter | 507 | torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType); | 
| 378 | tim | 273 | } | 
| 379 |  |  |  | 
| 380 |  |  | return torsion; | 
| 381 | gezelter | 507 | } | 
| 382 | gezelter | 246 |  | 
| 383 | gezelter | 507 | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) { | 
| 384 | gezelter | 246 | int nAtoms; | 
| 385 |  |  | CutoffGroup* cg; | 
| 386 |  |  | Atom* atom; | 
| 387 |  |  | cg = new CutoffGroup(); | 
| 388 |  |  |  | 
| 389 |  |  | nAtoms = stamp->getNMembers(); | 
| 390 |  |  | for (int i =0; i < nAtoms; ++i) { | 
| 391 | tim | 770 | atom = mol->getAtomAt(stamp->getMemberAt(i)); | 
| 392 | gezelter | 507 | assert(atom); | 
| 393 |  |  | cg->addAtom(atom); | 
| 394 | gezelter | 246 | } | 
| 395 |  |  |  | 
| 396 |  |  | return cg; | 
| 397 | gezelter | 507 | } | 
| 398 | gezelter | 246 |  | 
| 399 | gezelter | 507 | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) { | 
| 400 | gezelter | 246 | CutoffGroup* cg; | 
| 401 |  |  | cg  = new CutoffGroup(); | 
| 402 |  |  | cg->addAtom(atom); | 
| 403 |  |  | return cg; | 
| 404 | gezelter | 507 | } | 
| 405 | gezelter | 246 |  | 
| 406 | gezelter | 507 | void MoleculeCreator::createConstraintPair(Molecule* mol) { | 
| 407 | gezelter | 246 |  | 
| 408 |  |  | //add bond constraints | 
| 409 |  |  | Molecule::BondIterator bi; | 
| 410 |  |  | Bond* bond; | 
| 411 |  |  | for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) { | 
| 412 |  |  |  | 
| 413 | gezelter | 507 | BondType* bt = bond->getBondType(); | 
| 414 | gezelter | 246 |  | 
| 415 | gezelter | 507 | //class Parent1 {}; | 
| 416 |  |  | //class Child1 : public Parent {}; | 
| 417 |  |  | //class Child2 : public Parent {}; | 
| 418 |  |  | //Child1* ch1 = new Child1(); | 
| 419 |  |  | //Child2* ch2 = dynamic_cast<Child2*>(ch1); | 
| 420 |  |  | //the dynamic_cast is succeed in above line. A compiler bug? | 
| 421 | gezelter | 246 |  | 
| 422 | gezelter | 507 | if (typeid(FixedBondType) == typeid(*bt)) { | 
| 423 |  |  | FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); | 
| 424 | gezelter | 246 |  | 
| 425 | gezelter | 507 | ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA()); | 
| 426 |  |  | ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB()); | 
| 427 |  |  | ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength()); | 
| 428 |  |  | mol->addConstraintPair(consPair); | 
| 429 |  |  | } | 
| 430 | gezelter | 246 | } | 
| 431 |  |  |  | 
| 432 |  |  | //rigidbody -- rigidbody constraint is not support yet | 
| 433 | gezelter | 507 | } | 
| 434 | gezelter | 246 |  | 
| 435 | gezelter | 507 | void MoleculeCreator::createConstraintElem(Molecule* mol) { | 
| 436 | gezelter | 246 |  | 
| 437 |  |  | ConstraintPair* consPair; | 
| 438 |  |  | Molecule::ConstraintPairIterator cpi; | 
| 439 |  |  | std::set<StuntDouble*> sdSet; | 
| 440 |  |  | for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) { | 
| 441 |  |  |  | 
| 442 | gezelter | 507 | StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble(); | 
| 443 |  |  | if (sdSet.find(sdA) == sdSet.end()){ | 
| 444 |  |  | sdSet.insert(sdA); | 
| 445 |  |  | mol->addConstraintElem(new ConstraintElem(sdA)); | 
| 446 |  |  | } | 
| 447 | gezelter | 246 |  | 
| 448 | gezelter | 507 | StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble(); | 
| 449 |  |  | if (sdSet.find(sdB) == sdSet.end()){ | 
| 450 |  |  | sdSet.insert(sdB); | 
| 451 |  |  | mol->addConstraintElem(new ConstraintElem(sdB)); | 
| 452 |  |  | } | 
| 453 | gezelter | 246 |  | 
| 454 |  |  | } | 
| 455 |  |  |  | 
| 456 | gezelter | 507 | } | 
| 457 | gezelter | 246 |  | 
| 458 |  |  | } |