| 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 | 
| 46 | – | * @time 13:44am | 
| 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 "types/BondTypeParser.hpp" | 
| 60 | + | #include "types/BendTypeParser.hpp" | 
| 61 | + | #include "types/TorsionTypeParser.hpp" | 
| 62 | + | #include "types/InversionTypeParser.hpp" | 
| 63 |  | #include "utils/simError.h" | 
| 64 |  | #include "utils/StringUtils.hpp" | 
| 65 |  |  | 
| 66 | < | namespace oopse { | 
| 66 | > | namespace OpenMD { | 
| 67 | > |  | 
| 68 | > | Molecule* MoleculeCreator::createMolecule(ForceField* ff, | 
| 69 | > | MoleculeStamp *molStamp, | 
| 70 | > | int stampId, int globalIndex, | 
| 71 | > | LocalIndexManager* localIndexMan) { | 
| 72 | > | Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName(), | 
| 73 | > | molStamp->getRegion() ); | 
| 74 |  |  | 
| 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 | – |  | 
| 75 |  | //create atoms | 
| 76 |  | Atom* atom; | 
| 77 |  | AtomStamp* currentAtomStamp; | 
| 78 |  | int nAtom = molStamp->getNAtoms(); | 
| 79 |  | for (int i = 0; i < nAtom; ++i) { | 
| 80 | < | currentAtomStamp = molStamp->getAtom(i); | 
| 80 | > | currentAtomStamp = molStamp->getAtomStamp(i); | 
| 81 |  | atom = createAtom(ff, mol, currentAtomStamp, localIndexMan); | 
| 82 |  | mol->addAtom(atom); | 
| 83 |  | } | 
| 88 |  | int nRigidbodies = molStamp->getNRigidBodies(); | 
| 89 |  |  | 
| 90 |  | for (int i = 0; i < nRigidbodies; ++i) { | 
| 91 | < | currentRigidBodyStamp = molStamp->getRigidBody(i); | 
| 92 | < | rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan); | 
| 91 | > | currentRigidBodyStamp = molStamp->getRigidBodyStamp(i); | 
| 92 | > | rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, | 
| 93 | > | localIndexMan); | 
| 94 |  | mol->addRigidBody(rb); | 
| 95 |  | } | 
| 96 | < |  | 
| 96 | > |  | 
| 97 |  | //create bonds | 
| 98 |  | Bond* bond; | 
| 99 |  | BondStamp* currentBondStamp; | 
| 100 |  | int nBonds = molStamp->getNBonds(); | 
| 101 |  |  | 
| 102 |  | for (int i = 0; i < nBonds; ++i) { | 
| 103 | < | currentBondStamp = molStamp->getBond(i); | 
| 104 | < | bond = createBond(ff, mol, currentBondStamp); | 
| 103 | > | currentBondStamp = molStamp->getBondStamp(i); | 
| 104 | > | bond = createBond(ff, mol, currentBondStamp, localIndexMan); | 
| 105 |  | mol->addBond(bond); | 
| 106 |  | } | 
| 107 |  |  | 
| 110 |  | BendStamp* currentBendStamp; | 
| 111 |  | int nBends = molStamp->getNBends(); | 
| 112 |  | for (int i = 0; i < nBends; ++i) { | 
| 113 | < | currentBendStamp = molStamp->getBend(i); | 
| 114 | < | bend = createBend(ff, mol, currentBendStamp); | 
| 113 | > | currentBendStamp = molStamp->getBendStamp(i); | 
| 114 | > | bend = createBend(ff, mol, currentBendStamp, localIndexMan); | 
| 115 |  | mol->addBend(bend); | 
| 116 |  | } | 
| 117 |  |  | 
| 120 |  | TorsionStamp* currentTorsionStamp; | 
| 121 |  | int nTorsions = molStamp->getNTorsions(); | 
| 122 |  | for (int i = 0; i < nTorsions; ++i) { | 
| 123 | < | currentTorsionStamp = molStamp->getTorsion(i); | 
| 124 | < | torsion = createTorsion(ff, mol, currentTorsionStamp); | 
| 123 | > | currentTorsionStamp = molStamp->getTorsionStamp(i); | 
| 124 | > | torsion = createTorsion(ff, mol, currentTorsionStamp, localIndexMan); | 
| 125 |  | mol->addTorsion(torsion); | 
| 126 |  | } | 
| 127 |  |  | 
| 128 | + | //create inversions | 
| 129 | + | Inversion* inversion; | 
| 130 | + | InversionStamp* currentInversionStamp; | 
| 131 | + | int nInversions = molStamp->getNInversions(); | 
| 132 | + | for (int i = 0; i < nInversions; ++i) { | 
| 133 | + | currentInversionStamp = molStamp->getInversionStamp(i); | 
| 134 | + | inversion = createInversion(ff, mol, currentInversionStamp, | 
| 135 | + | localIndexMan); | 
| 136 | + | if (inversion != NULL ) { | 
| 137 | + | mol->addInversion(inversion); | 
| 138 | + | } | 
| 139 | + | } | 
| 140 | + |  | 
| 141 |  | //create cutoffGroups | 
| 142 |  | CutoffGroup* cutoffGroup; | 
| 143 |  | CutoffGroupStamp* currentCutoffGroupStamp; | 
| 144 |  | int nCutoffGroups = molStamp->getNCutoffGroups(); | 
| 145 |  | for (int i = 0; i < nCutoffGroups; ++i) { | 
| 146 | < | currentCutoffGroupStamp = molStamp->getCutoffGroup(i); | 
| 147 | < | cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp); | 
| 146 | > | currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i); | 
| 147 | > | cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp, | 
| 148 | > | localIndexMan); | 
| 149 |  | mol->addCutoffGroup(cutoffGroup); | 
| 150 |  | } | 
| 151 |  |  | 
| 152 |  | //every free atom is a cutoff group | 
| 153 | < | std::set<Atom*> allAtoms; | 
| 154 | < | Molecule::AtomIterator ai; | 
| 153 | > | std::vector<Atom*> freeAtoms; | 
| 154 | > | std::vector<Atom*>::iterator ai; | 
| 155 | > | std::vector<Atom*>::iterator fai; | 
| 156 |  |  | 
| 157 |  | //add all atoms into allAtoms set | 
| 158 | < | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 159 | < | allAtoms.insert(atom); | 
| 158 | > | for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) { | 
| 159 | > | freeAtoms.push_back(atom); | 
| 160 |  | } | 
| 161 |  |  | 
| 162 |  | Molecule::CutoffGroupIterator ci; | 
| 163 |  | CutoffGroup* cg; | 
| 141 | – | std::set<Atom*> cutoffAtoms; | 
| 164 |  |  | 
| 165 | < | //add all of the atoms belong to cutoff groups into cutoffAtoms set | 
| 166 | < | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 167 | < |  | 
| 165 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; | 
| 166 | > | cg = mol->nextCutoffGroup(ci)) { | 
| 167 | > |  | 
| 168 |  | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { | 
| 169 | < | cutoffAtoms.insert(atom); | 
| 170 | < | } | 
| 171 | < |  | 
| 169 | > | //erase the atoms belong to cutoff groups from freeAtoms vector | 
| 170 | > | freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom), | 
| 171 | > | freeAtoms.end()); | 
| 172 | > | } | 
| 173 |  | } | 
| 174 |  |  | 
| 175 | < | //find all free atoms (which do not belong to cutoff groups) | 
| 176 | < | //performs the "difference" operation from set theory,  the output range contains a copy of every | 
| 177 | < | //element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in | 
| 178 | < | //[cutoffAtoms.begin(), cutoffAtoms.end()). | 
| 179 | < | std::vector<Atom*> freeAtoms; | 
| 180 | < | std::set_difference(allAtoms.begin(), allAtoms.end(), cutoffAtoms.begin(), cutoffAtoms.end(), | 
| 181 | < | std::back_inserter(freeAtoms)); | 
| 175 | > | // loop over the free atoms and then create one cutoff group for | 
| 176 | > | // every single free atom | 
| 177 | > |  | 
| 178 | > | for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) { | 
| 179 | > | cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan); | 
| 180 | > | mol->addCutoffGroup(cutoffGroup); | 
| 181 | > | } | 
| 182 |  |  | 
| 183 | < | if (freeAtoms.size() != allAtoms.size() - cutoffAtoms.size()) { | 
| 184 | < | //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"); | 
| 183 | > | //create bonded constraintPairs: | 
| 184 | > | createConstraintPair(mol); | 
| 185 |  |  | 
| 186 | < | painCave.isFatal = 1; | 
| 187 | < | simError(); | 
| 188 | < | } | 
| 186 | > | //create non-bonded constraintPairs | 
| 187 | > | for (int i = 0; i < molStamp->getNConstraints(); ++i) { | 
| 188 | > | ConstraintStamp* cStamp = molStamp->getConstraintStamp(i); | 
| 189 | > | Atom* atomA; | 
| 190 | > | Atom* atomB; | 
| 191 | > |  | 
| 192 | > | atomA = mol->getAtomAt(cStamp->getA()); | 
| 193 | > | atomB = mol->getAtomAt(cStamp->getB()); | 
| 194 | > | assert( atomA && atomB ); | 
| 195 | > |  | 
| 196 | > | RealType distance; | 
| 197 | > | bool printConstraintForce = false; | 
| 198 |  |  | 
| 199 | < | //loop over the free atoms and then create one cutoff group for every single free atom | 
| 200 | < | std::vector<Atom*>::iterator fai; | 
| 199 | > | if (!cStamp->haveConstrainedDistance()) { | 
| 200 | > | sprintf(painCave.errMsg, | 
| 201 | > | "Constraint Error: A non-bond constraint was specified\n" | 
| 202 | > | "\twithout providing a value for the constrainedDistance.\n"); | 
| 203 | > | painCave.isFatal = 1; | 
| 204 | > | simError(); | 
| 205 | > | } else { | 
| 206 | > | distance = cStamp->getConstrainedDistance(); | 
| 207 | > | } | 
| 208 |  |  | 
| 209 | < | for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) { | 
| 210 | < | cutoffGroup = createCutoffGroup(mol, *fai); | 
| 211 | < | mol->addCutoffGroup(cutoffGroup); | 
| 209 | > | if (cStamp->havePrintConstraintForce()) { | 
| 210 | > | printConstraintForce = cStamp->getPrintConstraintForce(); | 
| 211 | > | } | 
| 212 | > |  | 
| 213 | > | ConstraintElem* consElemA = new ConstraintElem(atomA); | 
| 214 | > | ConstraintElem* consElemB = new ConstraintElem(atomB); | 
| 215 | > | ConstraintPair* cPair = new ConstraintPair(consElemA, consElemB, distance, | 
| 216 | > | printConstraintForce); | 
| 217 | > | mol->addConstraintPair(cPair); | 
| 218 |  | } | 
| 219 | < | //create constraints | 
| 220 | < | createConstraintPair(mol); | 
| 219 | > |  | 
| 220 | > | // now create the constraint elements: | 
| 221 | > |  | 
| 222 |  | createConstraintElem(mol); | 
| 223 |  |  | 
| 224 | + | // Does this molecule stamp define a total constrained charge value? | 
| 225 | + | // If so, let the created molecule know about it. | 
| 226 | + |  | 
| 227 | + | if (molStamp->haveConstrainTotalCharge() ) { | 
| 228 | + | mol->setConstrainTotalCharge( molStamp->getConstrainTotalCharge() ); | 
| 229 | + | } | 
| 230 | + |  | 
| 231 |  | //the construction of this molecule is finished | 
| 232 |  | mol->complete(); | 
| 233 | < |  | 
| 233 | > |  | 
| 234 |  | return mol; | 
| 235 |  | } | 
| 236 |  |  | 
| 237 |  |  | 
| 238 | < | Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp, | 
| 239 | < | LocalIndexManager* localIndexMan) { | 
| 238 | > | Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, | 
| 239 | > | AtomStamp* stamp, | 
| 240 | > | LocalIndexManager* localIndexMan) { | 
| 241 |  | AtomType * atomType; | 
| 242 |  | Atom* atom; | 
| 243 |  |  | 
| 244 |  | atomType =  ff->getAtomType(stamp->getType()); | 
| 245 | < |  | 
| 245 | > |  | 
| 246 |  | if (atomType == NULL) { | 
| 247 |  | sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", | 
| 248 | < | stamp->getType()); | 
| 248 | > | stamp->getType().c_str()); | 
| 249 |  |  | 
| 250 |  | painCave.isFatal = 1; | 
| 251 |  | simError(); | 
| 252 |  | } | 
| 253 | < |  | 
| 253 | > |  | 
| 254 |  | //below code still have some kind of hard-coding smell | 
| 255 |  | 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"); | 
| 256 |  |  | 
| 209 | – | painCave.isFatal = 1; | 
| 210 | – | simError(); | 
| 211 | – | } | 
| 212 | – |  | 
| 257 |  | DirectionalAtom* dAtom; | 
| 258 | < | dAtom = new DirectionalAtom(dAtomType); | 
| 258 | > | dAtom = new DirectionalAtom(atomType); | 
| 259 |  | atom = dAtom; | 
| 260 |  | } | 
| 261 |  | else{ | 
| 266 |  |  | 
| 267 |  | return atom; | 
| 268 |  | } | 
| 269 | < |  | 
| 270 | < | RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol, | 
| 269 | > |  | 
| 270 | > | RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, | 
| 271 | > | Molecule* mol, | 
| 272 |  | RigidBodyStamp* rbStamp, | 
| 273 | < | LocalIndexManager* localIndexMan) { | 
| 273 | > | LocalIndexManager* localIndexMan){ | 
| 274 |  | Atom* atom; | 
| 275 |  | int nAtoms; | 
| 276 |  | Vector3d refCoor; | 
| 279 |  | RigidBody* rb = new RigidBody(); | 
| 280 |  | nAtoms = rbStamp->getNMembers(); | 
| 281 |  | for (int i = 0; i < nAtoms; ++i) { | 
| 282 | < | //rbStamp->getMember(i) return the local index of current atom inside the molecule. | 
| 283 | < | //It is not the same as local index of atom which is the index of atom at DataStorage class | 
| 284 | < | atom = mol->getAtomAt(rbStamp->getMember(i)); | 
| 285 | < | atomStamp= molStamp->getAtom(rbStamp->getMember(i)); | 
| 282 | > | //rbStamp->getMember(i) return the local index of current atom | 
| 283 | > | //inside the molecule.  It is not the same as local index of | 
| 284 | > | //atom which is the index of atom at DataStorage class | 
| 285 | > | atom = mol->getAtomAt(rbStamp->getMemberAt(i)); | 
| 286 | > | atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i)); | 
| 287 |  | rb->addAtom(atom, atomStamp); | 
| 288 |  | } | 
| 289 |  |  | 
| 290 | < | //after all of the atoms are added, we need to calculate the reference coordinates | 
| 290 | > | //after all of the atoms are added, we need to calculate the | 
| 291 | > | //reference coordinates | 
| 292 |  | rb->calcRefCoords(); | 
| 293 |  |  | 
| 294 |  | //set the local index of this rigid body, global index will be set later | 
| 295 |  | rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex()); | 
| 296 |  |  | 
| 297 | < | //the rule for naming rigidbody MoleculeName_RB_Integer | 
| 298 | < | //The first part is the name of the molecule | 
| 299 | < | //The second part is alway fixed as "RB" | 
| 300 | < | //The third part is the index of the rigidbody defined in meta-data file | 
| 301 | < | //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()); | 
| 297 | > | // The rule for naming a rigidbody is: MoleculeName_RB_Integer | 
| 298 | > | // The first part is the name of the molecule | 
| 299 | > | // The second part is always fixed as "RB" | 
| 300 | > | // The third part is the index of the rigidbody defined in meta-data file | 
| 301 | > | // For example, Butane_RB_0 is a valid rigid body name of butane molecule | 
| 302 |  |  | 
| 303 | + | std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10); | 
| 304 | + | rb->setType(mol->getType() + "_RB_" + s.c_str()); | 
| 305 |  | return rb; | 
| 306 |  | } | 
| 307 |  |  | 
| 308 | < | Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) { | 
| 309 | < | BondType* bondType; | 
| 308 | > | Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, | 
| 309 | > | BondStamp* stamp, | 
| 310 | > | LocalIndexManager* localIndexMan) { | 
| 311 | > | BondTypeParser btParser; | 
| 312 | > | BondType* bondType = NULL; | 
| 313 |  | Atom* atomA; | 
| 314 |  | Atom* atomB; | 
| 315 | < |  | 
| 315 | > |  | 
| 316 |  | atomA = mol->getAtomAt(stamp->getA()); | 
| 317 |  | atomB = mol->getAtomAt(stamp->getB()); | 
| 269 | – |  | 
| 270 | – | assert( atomA && atomB); | 
| 318 |  |  | 
| 319 | < | bondType = ff->getBondType(atomA->getType(), atomB->getType()); | 
| 319 | > | assert( atomA && atomB); | 
| 320 |  |  | 
| 321 | < | if (bondType == NULL) { | 
| 275 | < | sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", | 
| 276 | < | atomA->getType().c_str(), | 
| 277 | < | atomB->getType().c_str()); | 
| 321 | > | if (stamp->hasOverride()) { | 
| 322 |  |  | 
| 323 | < | painCave.isFatal = 1; | 
| 324 | < | simError(); | 
| 325 | < | } | 
| 326 | < | return new Bond(atomA, atomB, bondType); | 
| 327 | < | } | 
| 323 | > | try { | 
| 324 | > | bondType = btParser.parseTypeAndPars(stamp->getOverrideType(), | 
| 325 | > | stamp->getOverridePars() ); | 
| 326 | > | } | 
| 327 | > | catch( OpenMDException e) { | 
| 328 | > | sprintf(painCave.errMsg, "MoleculeCreator Error: %s " | 
| 329 | > | "for molecule %s\n", | 
| 330 | > | e.what(), mol->getType().c_str() ); | 
| 331 | > | painCave.isFatal = 1; | 
| 332 | > | simError(); | 
| 333 | > | } | 
| 334 |  |  | 
| 335 | < | Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) { | 
| 336 | < | bool isGhostBend = false; | 
| 287 | < | int ghostIndex; | 
| 335 | > | } else { | 
| 336 | > | bondType = ff->getBondType(atomA->getType(), atomB->getType()); | 
| 337 |  |  | 
| 338 | < |  | 
| 339 | < | // | 
| 340 | < | if (stamp->haveExtras()){ | 
| 341 | < | LinkedAssign* extras = stamp->getExtras(); | 
| 293 | < | LinkedAssign* currentExtra = extras; | 
| 294 | < |  | 
| 295 | < | while (currentExtra != NULL){ | 
| 296 | < | if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){ | 
| 297 | < | switch (currentExtra->getType()){ | 
| 298 | < | case 0: | 
| 299 | < | ghostIndex = currentExtra->getInt(); | 
| 300 | < | isGhostBend = true; | 
| 301 | < | break; | 
| 302 | < |  | 
| 303 | < | default: | 
| 304 | < | sprintf(painCave.errMsg, | 
| 305 | < | "SimSetup Error: ghostVectorSource must be an int.\n"); | 
| 306 | < | painCave.isFatal = 1; | 
| 307 | < | 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 | < | } | 
| 338 | > | if (bondType == NULL) { | 
| 339 | > | sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", | 
| 340 | > | atomA->getType().c_str(), | 
| 341 | > | atomB->getType().c_str()); | 
| 342 |  |  | 
| 343 | + | painCave.isFatal = 1; | 
| 344 | + | simError(); | 
| 345 | + | } | 
| 346 |  | } | 
| 347 | + |  | 
| 348 | + | Bond* bond = new Bond(atomA, atomB, bondType); | 
| 349 |  |  | 
| 350 | < | if (isGhostBend) { | 
| 350 | > | //set the local index of this bond, the global index will be set later | 
| 351 | > | bond->setLocalIndex(localIndexMan->getNextBondIndex()); | 
| 352 |  |  | 
| 353 | < | int indexA = stamp->getA(); | 
| 354 | < | int indexB= stamp->getB(); | 
| 353 | > | // The rule for naming a bond is: MoleculeName_Bond_Integer | 
| 354 | > | // The first part is the name of the molecule | 
| 355 | > | // The second part is always fixed as "Bond" | 
| 356 | > | // The third part is the index of the bond defined in meta-data file | 
| 357 | > | // For example, Butane_bond_0 is a valid Bond name in a butane molecule | 
| 358 |  |  | 
| 359 | < | assert(indexA != indexB); | 
| 359 | > | std::string s = OpenMD_itoa(mol->getNBonds(), 10); | 
| 360 | > | bond->setName(mol->getType() + "_Bond_" + s.c_str()); | 
| 361 | > | return bond; | 
| 362 | > | } | 
| 363 | > |  | 
| 364 | > | Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, | 
| 365 | > | BendStamp* stamp, | 
| 366 | > | LocalIndexManager* localIndexMan) { | 
| 367 | > | BendTypeParser btParser; | 
| 368 | > | BendType* bendType = NULL; | 
| 369 | > | Bend* bend = NULL; | 
| 370 | > |  | 
| 371 | > | std::vector<int> bendAtoms = stamp->getMembers(); | 
| 372 | > | if (bendAtoms.size() == 3) { | 
| 373 | > | Atom* atomA = mol->getAtomAt(bendAtoms[0]); | 
| 374 | > | Atom* atomB = mol->getAtomAt(bendAtoms[1]); | 
| 375 | > | Atom* atomC = mol->getAtomAt(bendAtoms[2]); | 
| 376 | > |  | 
| 377 | > | assert( atomA && atomB && atomC ); | 
| 378 |  |  | 
| 379 | < | int normalIndex; | 
| 328 | < | if (indexA == ghostIndex) { | 
| 329 | < | normalIndex = indexB; | 
| 330 | < | } else if (indexB == ghostIndex) { | 
| 331 | < | normalIndex = indexA; | 
| 332 | < | } | 
| 379 | > | if (stamp->hasOverride()) { | 
| 380 |  |  | 
| 381 | + | try { | 
| 382 | + | bendType = btParser.parseTypeAndPars(stamp->getOverrideType(), | 
| 383 | + | stamp->getOverridePars() ); | 
| 384 | + | } | 
| 385 | + | catch( OpenMDException e) { | 
| 386 | + | sprintf(painCave.errMsg, "MoleculeCreator Error: %s " | 
| 387 | + | "for molecule %s\n", | 
| 388 | + | e.what(), mol->getType().c_str() ); | 
| 389 | + | painCave.isFatal = 1; | 
| 390 | + | simError(); | 
| 391 | + | } | 
| 392 | + | } else { | 
| 393 | + |  | 
| 394 | + | bendType = ff->getBendType(atomA->getType().c_str(), | 
| 395 | + | atomB->getType().c_str(), | 
| 396 | + | atomC->getType().c_str()); | 
| 397 | + |  | 
| 398 | + | if (bendType == NULL) { | 
| 399 | + | sprintf(painCave.errMsg, | 
| 400 | + | "Can not find Matching Bend Type for[%s, %s, %s]", | 
| 401 | + | atomA->getType().c_str(), | 
| 402 | + | atomB->getType().c_str(), | 
| 403 | + | atomC->getType().c_str()); | 
| 404 | + |  | 
| 405 | + | painCave.isFatal = 1; | 
| 406 | + | simError(); | 
| 407 | + | } | 
| 408 | + | } | 
| 409 | + |  | 
| 410 | + | bend = new Bend(atomA, atomB, atomC, bendType); | 
| 411 | + |  | 
| 412 | + | } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) { | 
| 413 | + | int ghostIndex = stamp->getGhostVectorSource(); | 
| 414 | + | int normalIndex = ghostIndex != bendAtoms[0] ? | 
| 415 | + | bendAtoms[0] : bendAtoms[1]; | 
| 416 |  | Atom* normalAtom = mol->getAtomAt(normalIndex) ; | 
| 417 |  | DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex)); | 
| 418 |  | if (ghostAtom == NULL) { | 
| 420 |  | painCave.isFatal = 1; | 
| 421 |  | simError(); | 
| 422 |  | } | 
| 341 | – |  | 
| 342 | – | BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST"); | 
| 423 |  |  | 
| 424 | < | if (bendType == NULL) { | 
| 345 | < | 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"); | 
| 349 | < |  | 
| 350 | < | painCave.isFatal = 1; | 
| 351 | < | simError(); | 
| 352 | < | } | 
| 424 | > | if (stamp->hasOverride()) { | 
| 425 |  |  | 
| 426 | < | return new GhostBend(normalAtom, ghostAtom, bendType); | 
| 427 | < |  | 
| 428 | < | } else { | 
| 429 | < |  | 
| 430 | < | Atom* atomA = mol->getAtomAt(stamp->getA()); | 
| 431 | < | Atom* atomB = mol->getAtomAt(stamp->getB()); | 
| 432 | < | Atom* atomC = mol->getAtomAt(stamp->getC()); | 
| 433 | < |  | 
| 434 | < | assert( atomA && atomB && atomC); | 
| 426 | > | try { | 
| 427 | > | bendType = btParser.parseTypeAndPars(stamp->getOverrideType(), | 
| 428 | > | stamp->getOverridePars() ); | 
| 429 | > | } | 
| 430 | > | catch( OpenMDException e) { | 
| 431 | > | sprintf(painCave.errMsg, "MoleculeCreator Error: %s " | 
| 432 | > | "for molecule %s\n", | 
| 433 | > | e.what(), mol->getType().c_str() ); | 
| 434 | > | painCave.isFatal = 1; | 
| 435 | > | simError(); | 
| 436 | > | } | 
| 437 | > | } else { | 
| 438 | > |  | 
| 439 | > | bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), | 
| 440 | > | "GHOST"); | 
| 441 |  |  | 
| 442 | < | BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType()); | 
| 442 | > | if (bendType == NULL) { | 
| 443 | > | sprintf(painCave.errMsg, | 
| 444 | > | "Can not find Matching Bend Type for[%s, %s, %s]", | 
| 445 | > | normalAtom->getType().c_str(), | 
| 446 | > | ghostAtom->getType().c_str(), | 
| 447 | > | "GHOST"); | 
| 448 | > |  | 
| 449 | > | painCave.isFatal = 1; | 
| 450 | > | simError(); | 
| 451 | > | } | 
| 452 | > | } | 
| 453 | > |  | 
| 454 | > | bend = new GhostBend(normalAtom, ghostAtom, bendType); | 
| 455 | > |  | 
| 456 | > | } | 
| 457 | > |  | 
| 458 | > | //set the local index of this bend, the global index will be set later | 
| 459 | > | bend->setLocalIndex(localIndexMan->getNextBendIndex()); | 
| 460 | > |  | 
| 461 | > | // The rule for naming a bend is: MoleculeName_Bend_Integer | 
| 462 | > | // The first part is the name of the molecule | 
| 463 | > | // The second part is always fixed as "Bend" | 
| 464 | > | // The third part is the index of the bend defined in meta-data file | 
| 465 | > | // For example, Butane_Bend_0 is a valid Bend name in a butane molecule | 
| 466 | > |  | 
| 467 | > | std::string s = OpenMD_itoa(mol->getNBends(), 10); | 
| 468 | > | bend->setName(mol->getType() + "_Bend_" + s.c_str()); | 
| 469 | > | return bend; | 
| 470 | > | } | 
| 471 |  |  | 
| 472 | < | if (bendType == NULL) { | 
| 473 | < | sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", | 
| 474 | < | atomA->getType().c_str(), | 
| 369 | < | atomB->getType().c_str(), | 
| 370 | < | atomC->getType().c_str()); | 
| 472 | > | Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, | 
| 473 | > | TorsionStamp* stamp, | 
| 474 | > | LocalIndexManager* localIndexMan) { | 
| 475 |  |  | 
| 476 | < | painCave.isFatal = 1; | 
| 477 | < | simError(); | 
| 478 | < | } | 
| 476 | > | TorsionTypeParser ttParser; | 
| 477 | > | TorsionType* torsionType = NULL; | 
| 478 | > | Torsion* torsion = NULL; | 
| 479 |  |  | 
| 480 | < | return new Bend(atomA, atomB, atomC, bendType); | 
| 480 | > | std::vector<int> torsionAtoms = stamp->getMembers(); | 
| 481 | > | if (torsionAtoms.size() < 3) { | 
| 482 | > | return torsion; | 
| 483 |  | } | 
| 378 | – | } | 
| 484 |  |  | 
| 485 | < | Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) { | 
| 485 | > | Atom* atomA = mol->getAtomAt(torsionAtoms[0]); | 
| 486 | > | Atom* atomB = mol->getAtomAt(torsionAtoms[1]); | 
| 487 | > | Atom* atomC = mol->getAtomAt(torsionAtoms[2]); | 
| 488 |  |  | 
| 489 | < | Atom* atomA = mol->getAtomAt(stamp->getA()); | 
| 490 | < | Atom* atomB = mol->getAtomAt(stamp->getB()); | 
| 384 | < | Atom* atomC = mol->getAtomAt(stamp->getC()); | 
| 385 | < | Torsion* torsion; | 
| 489 | > | if (torsionAtoms.size() == 4) { | 
| 490 | > | Atom* atomD = mol->getAtomAt(torsionAtoms[3]); | 
| 491 |  |  | 
| 492 | < | if (stamp->getD() != -1) { | 
| 388 | < | Atom* atomD = mol->getAtomAt(stamp->getD()); | 
| 492 | > | assert(atomA && atomB && atomC && atomD ); | 
| 493 |  |  | 
| 494 | < | assert(atomA && atomB && atomC && atomD); | 
| 494 | > | if (stamp->hasOverride()) { | 
| 495 |  |  | 
| 496 | < | TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), | 
| 497 | < | atomC->getType(), atomD->getType()); | 
| 496 | > | try { | 
| 497 | > | torsionType = ttParser.parseTypeAndPars(stamp->getOverrideType(), | 
| 498 | > | stamp->getOverridePars() ); | 
| 499 | > | } | 
| 500 | > | catch( OpenMDException e) { | 
| 501 | > | sprintf(painCave.errMsg, "MoleculeCreator Error: %s " | 
| 502 | > | "for molecule %s\n", | 
| 503 | > | e.what(), mol->getType().c_str() ); | 
| 504 | > | painCave.isFatal = 1; | 
| 505 | > | simError(); | 
| 506 | > | } | 
| 507 | > | } else { | 
| 508 |  |  | 
| 395 | – | if (torsionType == NULL) { | 
| 396 | – | sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", | 
| 397 | – | 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 | – | } | 
| 509 |  |  | 
| 510 | + | torsionType = ff->getTorsionType(atomA->getType(), | 
| 511 | + | atomB->getType(), | 
| 512 | + | atomC->getType(), | 
| 513 | + | atomD->getType()); | 
| 514 | + | if (torsionType == NULL) { | 
| 515 | + | sprintf(painCave.errMsg, | 
| 516 | + | "Can not find Matching Torsion Type for[%s, %s, %s, %s]", | 
| 517 | + | atomA->getType().c_str(), | 
| 518 | + | atomB->getType().c_str(), | 
| 519 | + | atomC->getType().c_str(), | 
| 520 | + | atomD->getType().c_str()); | 
| 521 | + |  | 
| 522 | + | painCave.isFatal = 1; | 
| 523 | + | simError(); | 
| 524 | + | } | 
| 525 | + | } | 
| 526 | + |  | 
| 527 |  | torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType); | 
| 528 | < | } | 
| 529 | < | else { | 
| 530 | < |  | 
| 410 | < | DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(atomC); | 
| 528 | > | } else { | 
| 529 | > |  | 
| 530 | > | DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource())); | 
| 531 |  | if (dAtom == NULL) { | 
| 532 |  | sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom"); | 
| 533 |  | painCave.isFatal = 1; | 
| 534 |  | simError(); | 
| 535 |  | } | 
| 536 |  |  | 
| 537 | < | 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 | < | } | 
| 537 | > | if (stamp->hasOverride()) { | 
| 538 |  |  | 
| 539 | + | try { | 
| 540 | + | torsionType = ttParser.parseTypeAndPars(stamp->getOverrideType(), | 
| 541 | + | stamp->getOverridePars() ); | 
| 542 | + | } | 
| 543 | + | catch( OpenMDException e) { | 
| 544 | + | sprintf(painCave.errMsg, "MoleculeCreator Error: %s " | 
| 545 | + | "for molecule %s\n", | 
| 546 | + | e.what(), mol->getType().c_str() ); | 
| 547 | + | painCave.isFatal = 1; | 
| 548 | + | simError(); | 
| 549 | + | } | 
| 550 | + | } else { | 
| 551 | + | torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(), | 
| 552 | + | atomC->getType(), "GHOST"); | 
| 553 | + |  | 
| 554 | + | if (torsionType == NULL) { | 
| 555 | + | sprintf(painCave.errMsg, | 
| 556 | + | "Can not find Matching Torsion Type for[%s, %s, %s, %s]", | 
| 557 | + | atomA->getType().c_str(), | 
| 558 | + | atomB->getType().c_str(), | 
| 559 | + | atomC->getType().c_str(), | 
| 560 | + | "GHOST"); | 
| 561 | + |  | 
| 562 | + | painCave.isFatal = 1; | 
| 563 | + | simError(); | 
| 564 | + | } | 
| 565 | + | } | 
| 566 | + |  | 
| 567 |  | torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType); | 
| 568 |  | } | 
| 569 |  |  | 
| 570 | + | //set the local index of this torsion, the global index will be set later | 
| 571 | + | torsion->setLocalIndex(localIndexMan->getNextTorsionIndex()); | 
| 572 | + |  | 
| 573 | + | // The rule for naming a torsion is: MoleculeName_Torsion_Integer | 
| 574 | + | // The first part is the name of the molecule | 
| 575 | + | // The second part is always fixed as "Torsion" | 
| 576 | + | // The third part is the index of the torsion defined in meta-data file | 
| 577 | + | // For example, Butane_Torsion_0 is a valid Torsion name in a | 
| 578 | + | // butane molecule | 
| 579 | + |  | 
| 580 | + | std::string s = OpenMD_itoa(mol->getNTorsions(), 10); | 
| 581 | + | torsion->setName(mol->getType() + "_Torsion_" + s.c_str()); | 
| 582 |  | return torsion; | 
| 583 |  | } | 
| 584 |  |  | 
| 585 | < | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) { | 
| 585 | > | Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol, | 
| 586 | > | InversionStamp* stamp, | 
| 587 | > | LocalIndexManager* localIndexMan) { | 
| 588 | > |  | 
| 589 | > | InversionTypeParser itParser; | 
| 590 | > | InversionType* inversionType = NULL; | 
| 591 | > | Inversion* inversion = NULL; | 
| 592 | > |  | 
| 593 | > | int center = stamp->getCenter(); | 
| 594 | > | std::vector<int> satellites = stamp->getSatellites(); | 
| 595 | > | if (satellites.size() != 3) { | 
| 596 | > | return inversion; | 
| 597 | > | } | 
| 598 | > |  | 
| 599 | > | Atom* atomA = mol->getAtomAt(center); | 
| 600 | > | Atom* atomB = mol->getAtomAt(satellites[0]); | 
| 601 | > | Atom* atomC = mol->getAtomAt(satellites[1]); | 
| 602 | > | Atom* atomD = mol->getAtomAt(satellites[2]); | 
| 603 | > |  | 
| 604 | > | assert(atomA && atomB && atomC && atomD); | 
| 605 | > |  | 
| 606 | > | if (stamp->hasOverride()) { | 
| 607 | > |  | 
| 608 | > | try { | 
| 609 | > | inversionType = itParser.parseTypeAndPars(stamp->getOverrideType(), | 
| 610 | > | stamp->getOverridePars() ); | 
| 611 | > | } | 
| 612 | > | catch( OpenMDException e) { | 
| 613 | > | sprintf(painCave.errMsg, "MoleculeCreator Error: %s " | 
| 614 | > | "for molecule %s\n", | 
| 615 | > | e.what(), mol->getType().c_str() ); | 
| 616 | > | painCave.isFatal = 1; | 
| 617 | > | simError(); | 
| 618 | > | } | 
| 619 | > | } else { | 
| 620 | > |  | 
| 621 | > | inversionType = ff->getInversionType(atomA->getType(), | 
| 622 | > | atomB->getType(), | 
| 623 | > | atomC->getType(), | 
| 624 | > | atomD->getType()); | 
| 625 | > |  | 
| 626 | > | if (inversionType == NULL) { | 
| 627 | > | sprintf(painCave.errMsg, | 
| 628 | > | "No Matching Inversion Type for[%s, %s, %s, %s]\n" | 
| 629 | > | "\t(May not be a problem: not all inversions are parametrized)\n", | 
| 630 | > | atomA->getType().c_str(), | 
| 631 | > | atomB->getType().c_str(), | 
| 632 | > | atomC->getType().c_str(), | 
| 633 | > | atomD->getType().c_str()); | 
| 634 | > |  | 
| 635 | > | painCave.isFatal = 0; | 
| 636 | > | painCave.severity = OPENMD_INFO; | 
| 637 | > | simError(); | 
| 638 | > | } | 
| 639 | > | } | 
| 640 | > | if (inversionType != NULL) { | 
| 641 | > |  | 
| 642 | > | inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType); | 
| 643 | > |  | 
| 644 | > | // set the local index of this inversion, the global index will | 
| 645 | > | // be set later | 
| 646 | > | inversion->setLocalIndex(localIndexMan->getNextInversionIndex()); | 
| 647 | > |  | 
| 648 | > | // The rule for naming an inversion is: MoleculeName_Inversion_Integer | 
| 649 | > | // The first part is the name of the molecule | 
| 650 | > | // The second part is always fixed as "Inversion" | 
| 651 | > | // The third part is the index of the inversion defined in meta-data file | 
| 652 | > | // For example, Benzene_Inversion_0 is a valid Inversion name in a | 
| 653 | > | // Benzene molecule | 
| 654 | > |  | 
| 655 | > | std::string s = OpenMD_itoa(mol->getNInversions(), 10); | 
| 656 | > | inversion->setName(mol->getType() + "_Inversion_" + s.c_str()); | 
| 657 | > | return inversion; | 
| 658 | > | } else { | 
| 659 | > | return NULL; | 
| 660 | > | } | 
| 661 | > | } | 
| 662 | > |  | 
| 663 | > |  | 
| 664 | > | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, | 
| 665 | > | CutoffGroupStamp* stamp, | 
| 666 | > | LocalIndexManager* localIndexMan) { | 
| 667 |  | int nAtoms; | 
| 668 |  | CutoffGroup* cg; | 
| 669 |  | Atom* atom; | 
| 671 |  |  | 
| 672 |  | nAtoms = stamp->getNMembers(); | 
| 673 |  | for (int i =0; i < nAtoms; ++i) { | 
| 674 | < | atom = mol->getAtomAt(stamp->getMember(i)); | 
| 674 | > | atom = mol->getAtomAt(stamp->getMemberAt(i)); | 
| 675 |  | assert(atom); | 
| 676 |  | cg->addAtom(atom); | 
| 677 |  | } | 
| 678 | < |  | 
| 678 | > |  | 
| 679 | > | //set the local index of this cutoffGroup, global index will be set later | 
| 680 | > | cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex()); | 
| 681 | > |  | 
| 682 |  | return cg; | 
| 683 |  | } | 
| 684 | < |  | 
| 685 | < | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) { | 
| 684 | > |  | 
| 685 | > | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom, | 
| 686 | > | LocalIndexManager* localIndexMan) { | 
| 687 |  | CutoffGroup* cg; | 
| 688 |  | cg  = new CutoffGroup(); | 
| 689 |  | cg->addAtom(atom); | 
| 690 | + |  | 
| 691 | + | //set the local index of this cutoffGroup, global index will be set later | 
| 692 | + | cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex()); | 
| 693 | + |  | 
| 694 |  | return cg; | 
| 695 |  | } | 
| 696 |  |  | 
| 699 |  | //add bond constraints | 
| 700 |  | Molecule::BondIterator bi; | 
| 701 |  | Bond* bond; | 
| 702 | + | ConstraintPair* cPair; | 
| 703 | + |  | 
| 704 |  | for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) { | 
| 705 |  |  | 
| 706 |  | BondType* bt = bond->getBondType(); | 
| 707 |  |  | 
| 469 | – | //class Parent1 {}; | 
| 470 | – | //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? | 
| 475 | – |  | 
| 708 |  | if (typeid(FixedBondType) == typeid(*bt)) { | 
| 709 |  | FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); | 
| 710 |  |  | 
| 711 |  | ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA()); | 
| 712 |  | ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB()); | 
| 713 | < | ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength()); | 
| 714 | < | mol->addConstraintPair(consPair); | 
| 713 | > | cPair = new ConstraintPair(consElemA, consElemB, | 
| 714 | > | fbt->getEquilibriumBondLength(), false); | 
| 715 | > | mol->addConstraintPair(cPair); | 
| 716 |  | } | 
| 717 |  | } | 
| 718 |  |  | 
| 724 |  | ConstraintPair* consPair; | 
| 725 |  | Molecule::ConstraintPairIterator cpi; | 
| 726 |  | std::set<StuntDouble*> sdSet; | 
| 727 | < | for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) { | 
| 727 | > | for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; | 
| 728 | > | consPair = mol->nextConstraintPair(cpi)) { | 
| 729 |  |  | 
| 730 |  | StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble(); | 
| 731 |  | if (sdSet.find(sdA) == sdSet.end()){ | 
| 732 |  | sdSet.insert(sdA); | 
| 733 |  | mol->addConstraintElem(new ConstraintElem(sdA)); | 
| 734 |  | } | 
| 735 | < |  | 
| 735 | > |  | 
| 736 |  | StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble(); | 
| 737 |  | if (sdSet.find(sdB) == sdSet.end()){ | 
| 738 |  | sdSet.insert(sdB); | 
| 739 |  | mol->addConstraintElem(new ConstraintElem(sdB)); | 
| 740 | < | } | 
| 507 | < |  | 
| 740 | > | } | 
| 741 |  | } | 
| 509 | – |  | 
| 742 |  | } | 
| 511 | – |  | 
| 743 |  | } |