ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/MoleculeCreator.cpp
(Generate patch)

Comparing:
trunk/src/brains/MoleculeCreator.cpp (file contents), Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
branches/development/src/brains/MoleculeCreator.cpp (file contents), Revision 1710 by gezelter, Fri May 18 21:44:02 2012 UTC

# Line 6 | Line 6
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.
# Line 37 | Line 28
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, 24107 (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   /**
# Line 48 | Line 49
49   */
50  
51   #include <cassert>
52 + #include <typeinfo>
53   #include <set>
54  
55   #include "brains/MoleculeCreator.hpp"
56   #include "primitives/GhostBend.hpp"
57   #include "primitives/GhostTorsion.hpp"
58 < #include "types/DirectionalAtomType.hpp"
58 > #include "types/AtomType.hpp"
59   #include "types/FixedBondType.hpp"
60   #include "utils/simError.h"
61   #include "utils/StringUtils.hpp"
62  
63 < namespace oopse {
63 > namespace OpenMD {
64    
65 <  Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp,
66 <                                            int stampId, int globalIndex, LocalIndexManager* localIndexMan) {
67 <
65 >  Molecule* MoleculeCreator::createMolecule(ForceField* ff,
66 >                                            MoleculeStamp *molStamp,
67 >                                            int stampId, int globalIndex,
68 >                                            LocalIndexManager* localIndexMan) {
69      Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName());
70      
71      //create atoms
# Line 82 | Line 85 | namespace oopse {
85  
86      for (int i = 0; i < nRigidbodies; ++i) {
87        currentRigidBodyStamp = molStamp->getRigidBodyStamp(i);
88 <      rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan);
88 >      rb = createRigidBody(molStamp, mol, currentRigidBodyStamp,
89 >                           localIndexMan);
90        mol->addRigidBody(rb);
91      }
92 <
92 >    
93      //create bonds
94      Bond* bond;
95      BondStamp* currentBondStamp;
# Line 117 | Line 121 | namespace oopse {
121        mol->addTorsion(torsion);
122      }
123  
124 +    //create inversions
125 +    Inversion* inversion;
126 +    InversionStamp* currentInversionStamp;
127 +    int nInversions = molStamp->getNInversions();
128 +    for (int i = 0; i < nInversions; ++i) {
129 +      currentInversionStamp = molStamp->getInversionStamp(i);
130 +      inversion = createInversion(ff, mol, currentInversionStamp);
131 +      if (inversion != NULL ) {
132 +        mol->addInversion(inversion);
133 +      }
134 +    }
135 +
136      //create cutoffGroups
137      CutoffGroup* cutoffGroup;
138      CutoffGroupStamp* currentCutoffGroupStamp;
139      int nCutoffGroups = molStamp->getNCutoffGroups();
140      for (int i = 0; i < nCutoffGroups; ++i) {
141        currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i);
142 <      cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp);
142 >      cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp, localIndexMan);
143        mol->addCutoffGroup(cutoffGroup);
144      }
145  
# Line 140 | Line 156 | namespace oopse {
156      Molecule::CutoffGroupIterator ci;
157      CutoffGroup* cg;
158      
159 <    for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
160 <
159 >    for (cg = mol->beginCutoffGroup(ci); cg != NULL;
160 >         cg = mol->nextCutoffGroup(ci)) {
161 >      
162        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
163 <           //erase the atoms belong to cutoff groups from freeAtoms vector
164 <           freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom), freeAtoms.end());
165 <      }
166 <
163 >        //erase the atoms belong to cutoff groups from freeAtoms vector
164 >        freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom),
165 >                        freeAtoms.end());
166 >      }      
167      }      
168      
169 <    //loop over the free atoms and then create one cutoff group for every single free atom
169 >    // loop over the free atoms and then create one cutoff group for
170 >    // every single free atom
171      
172      for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) {
173 <      cutoffGroup = createCutoffGroup(mol, *fai);
173 >      cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan);
174        mol->addCutoffGroup(cutoffGroup);
175      }
176      //create constraints
# Line 161 | Line 179 | namespace oopse {
179      
180      //the construction of this molecule is finished
181      mol->complete();
182 <
182 >    
183      return mol;
184    }    
185  
186  
187 <  Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp,
188 <                                    LocalIndexManager* localIndexMan) {
187 >  Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol,
188 >                                    AtomStamp* stamp,
189 >                                    LocalIndexManager* localIndexMan) {
190      AtomType * atomType;
191      Atom* atom;
192  
193      atomType =  ff->getAtomType(stamp->getType());
194 <
194 >    
195      if (atomType == NULL) {
196        sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
197                stamp->getType().c_str());
# Line 183 | Line 202 | namespace oopse {
202      
203      //below code still have some kind of hard-coding smell
204      if (atomType->isDirectional()){
186    
187      DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
188        
189      if (dAtomType == NULL) {
190        sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType");
191
192        painCave.isFatal = 1;
193        simError();
194      }
195
205        DirectionalAtom* dAtom;
206 <      dAtom = new DirectionalAtom(dAtomType);
206 >      dAtom = new DirectionalAtom(atomType);
207        atom = dAtom;    
208      }
209      else{
# Line 205 | Line 214 | namespace oopse {
214  
215      return atom;
216    }
217 <
218 <  RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol,
217 >  
218 >  RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp,
219 >                                              Molecule* mol,
220                                                RigidBodyStamp* rbStamp,
221                                                LocalIndexManager* localIndexMan) {
222      Atom* atom;
# Line 217 | Line 227 | namespace oopse {
227      RigidBody* rb = new RigidBody();
228      nAtoms = rbStamp->getNMembers();    
229      for (int i = 0; i < nAtoms; ++i) {
230 <      //rbStamp->getMember(i) return the local index of current atom inside the molecule.
231 <      //It is not the same as local index of atom which is the index of atom at DataStorage class
230 >      //rbStamp->getMember(i) return the local index of current atom
231 >      //inside the molecule.  It is not the same as local index of
232 >      //atom which is the index of atom at DataStorage class
233        atom = mol->getAtomAt(rbStamp->getMemberAt(i));
234        atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i));    
235        rb->addAtom(atom, atomStamp);
236      }
237  
238 <    //after all of the atoms are added, we need to calculate the reference coordinates
238 >    //after all of the atoms are added, we need to calculate the
239 >    //reference coordinates
240      rb->calcRefCoords();
241  
242      //set the local index of this rigid body, global index will be set later
# Line 236 | Line 248 | namespace oopse {
248      //The third part is the index of the rigidbody defined in meta-data file
249      //For example, Butane_RB_0 is a valid rigid body name of butane molecule
250      /**@todo replace itoa by lexi_cast */
251 <    std::string s = OOPSE_itoa(mol->getNRigidBodies(), 10);
251 >    std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10);
252      rb->setType(mol->getType() + "_RB_" + s.c_str());
253  
254      return rb;
255    }    
256  
257 <  Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) {
257 >  Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol,
258 >                                    BondStamp* stamp) {
259      BondType* bondType;
260      Atom* atomA;
261      Atom* atomB;
262 <
262 >    
263      atomA = mol->getAtomAt(stamp->getA());
264      atomB = mol->getAtomAt(stamp->getB());
265 <
265 >    
266      assert( atomA && atomB);
267      
268      bondType = ff->getBondType(atomA->getType(), atomB->getType());
# Line 258 | Line 271 | namespace oopse {
271        sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
272                atomA->getType().c_str(),
273                atomB->getType().c_str());
274 <
274 >      
275        painCave.isFatal = 1;
276        simError();
277      }
278      return new Bond(atomA, atomB, bondType);    
279    }    
280 <
281 <  Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) {
280 >  
281 >  Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol,
282 >                                    BendStamp* stamp) {
283      Bend* bend = NULL;
284      std::vector<int> bendAtoms = stamp->getMembers();
285      if (bendAtoms.size() == 3) {
286        Atom* atomA = mol->getAtomAt(bendAtoms[0]);
287        Atom* atomB = mol->getAtomAt(bendAtoms[1]);
288        Atom* atomC = mol->getAtomAt(bendAtoms[2]);
289 <
289 >      
290        assert( atomA && atomB && atomC);
291 <
292 <      BendType* bendType = ff->getBendType(atomA->getType().c_str(), atomB->getType().c_str(), atomC->getType().c_str());
293 <
291 >      
292 >      BendType* bendType = ff->getBendType(atomA->getType().c_str(),
293 >                                           atomB->getType().c_str(),
294 >                                           atomC->getType().c_str());
295 >      
296        if (bendType == NULL) {
297          sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
298                  atomA->getType().c_str(),
299                  atomB->getType().c_str(),
300                  atomC->getType().c_str());
301 <
301 >        
302          painCave.isFatal = 1;
303          simError();
304        }
305 <
305 >      
306        bend = new Bend(atomA, atomB, atomC, bendType);
307      } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) {
308        int ghostIndex = stamp->getGhostVectorSource();
# Line 310 | Line 326 | namespace oopse {
326          painCave.isFatal = 1;
327          simError();
328        }
329 <        
329 >      
330        bend = new GhostBend(normalAtom, ghostAtom, bendType);      
331 <
331 >      
332      }
333      
334      return bend;
335    }    
336  
337 <  Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) {
337 >  Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol,
338 >                                          TorsionStamp* stamp) {
339  
340      Torsion* torsion = NULL;
341      std::vector<int> torsionAtoms = stamp->getMembers();
# Line 335 | Line 352 | namespace oopse {
352  
353        assert(atomA && atomB && atomC && atomD);
354          
355 <      TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
356 <                                                    atomC->getType(), atomD->getType());
357 <
355 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(),
356 >                                                    atomB->getType(),
357 >                                                    atomC->getType(),
358 >                                                    atomD->getType());
359        if (torsionType == NULL) {
360          sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
361                  atomA->getType().c_str(),
362                  atomB->getType().c_str(),
363                  atomC->getType().c_str(),
364                  atomD->getType().c_str());
365 <
365 >        
366          painCave.isFatal = 1;
367          simError();
368        }
369 <        
369 >      
370        torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
371      }
372      else {
373 <
373 >      
374        DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource()));
375        if (dAtom == NULL) {
376          sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
377          painCave.isFatal = 1;
378          simError();
379        }        
380 <
380 >      
381        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
382                                                      atomC->getType(), "GHOST");
383 <
383 >      
384        if (torsionType == NULL) {
385          sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
386                  atomA->getType().c_str(),
387                  atomB->getType().c_str(),
388                  atomC->getType().c_str(),
389                  "GHOST");
390 <
390 >        
391          painCave.isFatal = 1;
392          simError();
393        }
394 <        
394 >      
395        torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
396      }
397 <
397 >    
398      return torsion;
399    }    
400  
401 <  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) {
401 >  Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol,
402 >                                              InversionStamp* stamp) {
403 >    
404 >    Inversion* inversion = NULL;
405 >    int center = stamp->getCenter();
406 >    std::vector<int> satellites = stamp->getSatellites();
407 >    if (satellites.size() != 3) {
408 >        return inversion;
409 >    }
410 >
411 >    Atom* atomA = mol->getAtomAt(center);
412 >    Atom* atomB = mol->getAtomAt(satellites[0]);
413 >    Atom* atomC = mol->getAtomAt(satellites[1]);
414 >    Atom* atomD = mol->getAtomAt(satellites[2]);
415 >      
416 >    assert(atomA && atomB && atomC && atomD);
417 >    
418 >    InversionType* inversionType = ff->getInversionType(atomA->getType(),
419 >                                                        atomB->getType(),
420 >                                                        atomC->getType(),
421 >                                                        atomD->getType());
422 >
423 >    if (inversionType == NULL) {
424 >      sprintf(painCave.errMsg, "No Matching Inversion Type for[%s, %s, %s, %s]\n"
425 >              "\t(May not be a problem: not all inversions are parametrized)\n",
426 >              atomA->getType().c_str(),
427 >              atomB->getType().c_str(),
428 >              atomC->getType().c_str(),
429 >              atomD->getType().c_str());
430 >      
431 >      painCave.isFatal = 0;
432 >      painCave.severity = OPENMD_INFO;
433 >      simError();
434 >      return NULL;
435 >    } else {
436 >      
437 >      inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType);
438 >      return inversion;
439 >    }
440 >  }
441 >  
442 >
443 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol,
444 >                                                  CutoffGroupStamp* stamp,
445 >                                                  LocalIndexManager* localIndexMan) {
446      int nAtoms;
447      CutoffGroup* cg;
448      Atom* atom;
# Line 392 | Line 454 | namespace oopse {
454        assert(atom);
455        cg->addAtom(atom);
456      }
457 <
457 >    
458 >    //set the local index of this cutoffGroup, global index will be set later
459 >    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
460 >    
461      return cg;
462    }    
463 <
464 <  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) {
463 >  
464 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom,
465 >                                                  LocalIndexManager* localIndexMan) {
466      CutoffGroup* cg;
467      cg  = new CutoffGroup();
468      cg->addAtom(atom);
469 +
470 +    //set the local index of this cutoffGroup, global index will be set later
471 +    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
472 +
473      return cg;
474    }
475  

Comparing:
trunk/src/brains/MoleculeCreator.cpp (property svn:keywords), Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
branches/development/src/brains/MoleculeCreator.cpp (property svn:keywords), Revision 1710 by gezelter, Fri May 18 21:44:02 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines