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 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 2469 by tim, Fri Dec 2 15:38:03 2005 UTC

# Line 59 | Line 59 | namespace oopse {
59   #include "utils/StringUtils.hpp"
60  
61   namespace oopse {
62 <
62 >  
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      }
129  
130      //every free atom is a cutoff group    
131 <    std::set<Atom*> allAtoms;
132 <    Molecule::AtomIterator ai;
131 >    std::vector<Atom*> freeAtoms;
132 >    std::vector<Atom*>::iterator ai;
133 >    std::vector<Atom*>::iterator fai;
134  
135      //add all atoms into allAtoms set
136 <    for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
137 <      allAtoms.insert(atom);
136 >    for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) {
137 >      freeAtoms.push_back(atom);
138      }
139  
140      Molecule::CutoffGroupIterator ci;
141      CutoffGroup* cg;
141    std::set<Atom*> cutoffAtoms;    
142      
143    //add all of the atoms belong to cutoff groups into cutoffAtoms set
143      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
144  
145        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
146 <        cutoffAtoms.insert(atom);
146 >           //erase the atoms belong to cutoff groups from freeAtoms vector
147 >           freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom), freeAtoms.end());
148        }
149  
150      }      
151      
152    //find all free atoms (which do not belong to cutoff groups)  
153    //performs the "difference" operation from set theory,  the output range contains a copy of every
154    //element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in
155    //[cutoffAtoms.begin(), cutoffAtoms.end()).
156    std::vector<Atom*> freeAtoms;    
157    std::set_difference(allAtoms.begin(), allAtoms.end(), cutoffAtoms.begin(), cutoffAtoms.end(),
158                        std::back_inserter(freeAtoms));
159
160    if (freeAtoms.size() != allAtoms.size() - cutoffAtoms.size()) {
161      //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");
163
164      painCave.isFatal = 1;
165      simError();        
166    }
167
152      //loop over the free atoms and then create one cutoff group for every single free atom
153 <    std::vector<Atom*>::iterator fai;
170 <
153 >    
154      for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) {
155        cutoffGroup = createCutoffGroup(mol, *fai);
156        mol->addCutoffGroup(cutoffGroup);
# Line 192 | 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 236 | 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 283 | 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 <    
290 <    //
291 <    if (stamp->haveExtras()){
292 <      LinkedAssign* extras = stamp->getExtras();
293 <      LinkedAssign* currentExtra = extras;
276 >      assert( atomA && atomB && atomC);
277  
278 <      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;
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();
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 <      }
317 <        
318 <    }
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 <
322 <      int indexA = stamp->getA();
323 <      int indexB= stamp->getB();
324 <
325 <      assert(indexA != indexB);
326 <
327 <      int normalIndex;
328 <      if (indexA == ghostIndex) {
329 <        normalIndex = indexB;
330 <      } else if (indexB == ghostIndex) {
331 <        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 351 | 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());
359 <      Atom* atomB = mol->getAtomAt(stamp->getB());
360 <      Atom* atomC = mol->getAtomAt(stamp->getC());
361 <
362 <      assert( atomA && atomB && atomC);
363 <        
364 <      BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType());
365 <
366 <      if (bendType == NULL) {
367 <        sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
368 <                atomA->getType().c_str(),
369 <                atomB->getType().c_str(),
370 <                atomC->getType().c_str());
371 <
372 <        painCave.isFatal = 1;
373 <        simError();
374 <      }
375 <
376 <      return new Bend(atomA, atomB, atomC, bendType);      
377 <    }
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 407 | 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 442 | 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