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