ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/brains/MoleculeCreator.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/brains/MoleculeCreator.cpp (file contents):
Revision 2346 by tim, Wed Oct 5 19:34:01 2005 UTC vs.
Revision 2469 by tim, Fri Dec 2 15:38:03 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines