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 292 by tim, Fri Feb 4 22:44:15 2005 UTC vs.
branches/development/src/brains/MoleculeCreator.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# 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 < /**
44 <  * @file MoleculeCreator.cpp
45 <  * @author tlin
46 <  * @date 11/04/2004
47 <  * @time 13:44am
48 <  * @version 1.0
49 <  */
43 > /**
44 > * @file MoleculeCreator.cpp
45 > * @author tlin
46 > * @date 11/04/2004
47 > * @time 13:44am
48 > * @version 1.0
49 > */
50  
51   #include <cassert>
52 + #include <typeinfo>
53   #include <set>
54  
55   #include "brains/MoleculeCreator.hpp"
# Line 58 | Line 60
60   #include "utils/simError.h"
61   #include "utils/StringUtils.hpp"
62  
63 < namespace oopse {
64 <
65 < Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp,
66 <    int stampId, int globalIndex, LocalIndexManager* localIndexMan) {
67 <
68 <    Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getID());
63 > namespace OpenMD {
64 >  
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
72      Atom* atom;
73      AtomStamp* currentAtomStamp;
74      int nAtom = molStamp->getNAtoms();
75      for (int i = 0; i < nAtom; ++i) {
76 <        currentAtomStamp = molStamp->getAtom(i);
77 <        atom = createAtom(ff, mol, currentAtomStamp, localIndexMan);
78 <        mol->addAtom(atom);
76 >      currentAtomStamp = molStamp->getAtomStamp(i);
77 >      atom = createAtom(ff, mol, currentAtomStamp, localIndexMan);
78 >      mol->addAtom(atom);
79      }
80  
81      //create rigidbodies
# Line 81 | Line 84 | Molecule* MoleculeCreator::createMolecule(ForceField*
84      int nRigidbodies = molStamp->getNRigidBodies();
85  
86      for (int i = 0; i < nRigidbodies; ++i) {
87 <        currentRigidBodyStamp = molStamp->getRigidBody(i);
88 <        rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan);
89 <        mol->addRigidBody(rb);
87 >      currentRigidBodyStamp = molStamp->getRigidBodyStamp(i);
88 >      rb = createRigidBody(molStamp, mol, currentRigidBodyStamp,
89 >                           localIndexMan);
90 >      mol->addRigidBody(rb);
91      }
92 <
92 >    
93      //create bonds
94      Bond* bond;
95      BondStamp* currentBondStamp;
96      int nBonds = molStamp->getNBonds();
97  
98      for (int i = 0; i < nBonds; ++i) {
99 <        currentBondStamp = molStamp->getBond(i);
100 <        bond = createBond(ff, mol, currentBondStamp);
101 <        mol->addBond(bond);
99 >      currentBondStamp = molStamp->getBondStamp(i);
100 >      bond = createBond(ff, mol, currentBondStamp);
101 >      mol->addBond(bond);
102      }
103  
104      //create bends
# Line 102 | Line 106 | Molecule* MoleculeCreator::createMolecule(ForceField*
106      BendStamp* currentBendStamp;
107      int nBends = molStamp->getNBends();
108      for (int i = 0; i < nBends; ++i) {
109 <        currentBendStamp = molStamp->getBend(i);
110 <        bend = createBend(ff, mol, currentBendStamp);
111 <        mol->addBend(bend);
109 >      currentBendStamp = molStamp->getBendStamp(i);
110 >      bend = createBend(ff, mol, currentBendStamp);
111 >      mol->addBend(bend);
112      }
113  
114      //create torsions
# Line 112 | Line 116 | Molecule* MoleculeCreator::createMolecule(ForceField*
116      TorsionStamp* currentTorsionStamp;
117      int nTorsions = molStamp->getNTorsions();
118      for (int i = 0; i < nTorsions; ++i) {
119 <        currentTorsionStamp = molStamp->getTorsion(i);
120 <        torsion = createTorsion(ff, mol, currentTorsionStamp);
121 <        mol->addTorsion(torsion);
119 >      currentTorsionStamp = molStamp->getTorsionStamp(i);
120 >      torsion = createTorsion(ff, mol, currentTorsionStamp);
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->getCutoffGroup(i);
142 <        cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp);
143 <        mol->addCutoffGroup(cutoffGroup);
141 >      currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i);
142 >      cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp, localIndexMan);
143 >      mol->addCutoffGroup(cutoffGroup);
144      }
145  
146      //every free atom is a cutoff group    
147 <    std::set<Atom*> allAtoms;
148 <     Molecule::AtomIterator ai;
147 >    std::vector<Atom*> freeAtoms;
148 >    std::vector<Atom*>::iterator ai;
149 >    std::vector<Atom*>::iterator fai;
150  
151      //add all atoms into allAtoms set
152 <    for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
153 <        allAtoms.insert(atom);
152 >    for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) {
153 >      freeAtoms.push_back(atom);
154      }
155  
156      Molecule::CutoffGroupIterator ci;
157      CutoffGroup* cg;
141    std::set<Atom*> cutoffAtoms;    
158      
159 <    //add all of the atoms belong to cutoff groups into cutoffAtoms set
160 <    for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
161 <
162 <        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
163 <            cutoffAtoms.insert(atom);
164 <        }
165 <
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),
165 >                        freeAtoms.end());
166 >      }      
167      }      
168      
169 <    //find all free atoms (which do not belong to cutoff groups)  
170 <    //performs the "difference" operation from set theory,  the output range contains a copy of every
171 <    //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 <
168 <    //loop over the free atoms and then create one cutoff group for every single free atom
169 <    std::vector<Atom*>::iterator fai;
170 <
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);
174 <        mol->addCutoffGroup(cutoffGroup);
173 >      cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan);
174 >      mol->addCutoffGroup(cutoffGroup);
175      }
176      //create constraints
177      createConstraintPair(mol);
# Line 178 | Line 179 | Molecule* MoleculeCreator::createMolecule(ForceField*
179      
180      //the construction of this molecule is finished
181      mol->complete();
182 <
182 >    
183      return mol;
184 < }    
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());
196 >      sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
197 >              stamp->getType().c_str());
198  
199 <        painCave.isFatal = 1;
200 <        simError();
199 >      painCave.isFatal = 1;
200 >      simError();
201      }
202      
203      //below code still have some kind of hard-coding smell
204      if (atomType->isDirectional()){
205      
206 <        DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
206 >      DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
207          
208 <        if (dAtomType == NULL) {
209 <            sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType");
208 >      if (dAtomType == NULL) {
209 >        sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType");
210  
211 <            painCave.isFatal = 1;
212 <            simError();
213 <        }
211 >        painCave.isFatal = 1;
212 >        simError();
213 >      }
214  
215 <        DirectionalAtom* dAtom;
216 <        dAtom = new DirectionalAtom(dAtomType);
217 <        atom = dAtom;    
215 >      DirectionalAtom* dAtom;
216 >      dAtom = new DirectionalAtom(dAtomType);
217 >      atom = dAtom;    
218      }
219      else{
220 <        atom = new Atom(atomType);
220 >      atom = new Atom(atomType);
221      }
222  
223      atom->setLocalIndex(localIndexMan->getNextAtomIndex());
224  
225      return atom;
226 < }
227 <
228 < RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol,
229 <                                                                                    RigidBodyStamp* rbStamp,
230 <                                                                                    LocalIndexManager* localIndexMan) {
226 >  }
227 >  
228 >  RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp,
229 >                                              Molecule* mol,
230 >                                              RigidBodyStamp* rbStamp,
231 >                                              LocalIndexManager* localIndexMan) {
232      Atom* atom;
233      int nAtoms;
234      Vector3d refCoor;
# Line 234 | Line 237 | RigidBody* MoleculeCreator::createRigidBody(MoleculeSt
237      RigidBody* rb = new RigidBody();
238      nAtoms = rbStamp->getNMembers();    
239      for (int i = 0; i < nAtoms; ++i) {
240 <        //rbStamp->getMember(i) return the local index of current atom inside the molecule.
241 <        //It is not the same as local index of atom which is the index of atom at DataStorage class
242 <        atom = mol->getAtomAt(rbStamp->getMember(i));
243 <        atomStamp= molStamp->getAtom(rbStamp->getMember(i));    
244 <        rb->addAtom(atom, atomStamp);
240 >      //rbStamp->getMember(i) return the local index of current atom
241 >      //inside the molecule.  It is not the same as local index of
242 >      //atom which is the index of atom at DataStorage class
243 >      atom = mol->getAtomAt(rbStamp->getMemberAt(i));
244 >      atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i));    
245 >      rb->addAtom(atom, atomStamp);
246      }
247  
248 <    //after all of the atoms are added, we need to calculate the reference coordinates
248 >    //after all of the atoms are added, we need to calculate the
249 >    //reference coordinates
250      rb->calcRefCoords();
251  
252      //set the local index of this rigid body, global index will be set later
# Line 253 | Line 258 | RigidBody* MoleculeCreator::createRigidBody(MoleculeSt
258      //The third part is the index of the rigidbody defined in meta-data file
259      //For example, Butane_RB_0 is a valid rigid body name of butane molecule
260      /**@todo replace itoa by lexi_cast */
261 <    char buffer [33];  
262 <    sprintf(buffer, "%d", mol->getNRigidBodies());
258 <    //rb->setType(mol->getType() + "_RB_" + toString<int>(mol->getNRigidBodies()));
259 <    rb->setType(mol->getType() + "_RB_" + buffer);
261 >    std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10);
262 >    rb->setType(mol->getType() + "_RB_" + s.c_str());
263  
264      return rb;
265 < }    
265 >  }    
266  
267 < Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) {
267 >  Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol,
268 >                                    BondStamp* stamp) {
269      BondType* bondType;
270      Atom* atomA;
271      Atom* atomB;
272 <
272 >    
273      atomA = mol->getAtomAt(stamp->getA());
274      atomB = mol->getAtomAt(stamp->getB());
275 <
275 >    
276      assert( atomA && atomB);
277      
278      bondType = ff->getBondType(atomA->getType(), atomB->getType());
279  
280      if (bondType == NULL) {
281 <        sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
282 <                   atomA->getType().c_str(),
283 <                   atomB->getType().c_str());
284 <
285 <        painCave.isFatal = 1;
286 <        simError();
281 >      sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
282 >              atomA->getType().c_str(),
283 >              atomB->getType().c_str());
284 >      
285 >      painCave.isFatal = 1;
286 >      simError();
287      }
288      return new Bond(atomA, atomB, bondType);    
289 < }    
289 >  }    
290 >  
291 >  Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol,
292 >                                    BendStamp* stamp) {
293 >    Bend* bend = NULL;
294 >    std::vector<int> bendAtoms = stamp->getMembers();
295 >    if (bendAtoms.size() == 3) {
296 >      Atom* atomA = mol->getAtomAt(bendAtoms[0]);
297 >      Atom* atomB = mol->getAtomAt(bendAtoms[1]);
298 >      Atom* atomC = mol->getAtomAt(bendAtoms[2]);
299 >      
300 >      assert( atomA && atomB && atomC);
301 >      
302 >      BendType* bendType = ff->getBendType(atomA->getType().c_str(),
303 >                                           atomB->getType().c_str(),
304 >                                           atomC->getType().c_str());
305 >      
306 >      if (bendType == NULL) {
307 >        sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
308 >                atomA->getType().c_str(),
309 >                atomB->getType().c_str(),
310 >                atomC->getType().c_str());
311 >        
312 >        painCave.isFatal = 1;
313 >        simError();
314 >      }
315 >      
316 >      bend = new Bend(atomA, atomB, atomC, bendType);
317 >    } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) {
318 >      int ghostIndex = stamp->getGhostVectorSource();
319 >      int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1];
320 >      Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
321 >      DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
322 >      if (ghostAtom == NULL) {
323 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
324 >        painCave.isFatal = 1;
325 >        simError();
326 >      }
327 >                
328 >      BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
329  
330 < Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) {
331 <    bool isGhostBend = false;
332 <    int ghostIndex;
330 >      if (bendType == NULL) {
331 >        sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
332 >                normalAtom->getType().c_str(),
333 >                ghostAtom->getType().c_str(),
334 >                "GHOST");
335  
336 +        painCave.isFatal = 1;
337 +        simError();
338 +      }
339 +      
340 +      bend = new GhostBend(normalAtom, ghostAtom, bendType);      
341 +      
342 +    }
343      
344 <    //
345 <    if (stamp->haveExtras()){
294 <        LinkedAssign* extras = stamp->getExtras();
295 <        LinkedAssign* currentExtra = extras;
344 >    return bend;
345 >  }    
346  
347 <        while (currentExtra != NULL){
348 <            if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){
299 <                switch (currentExtra->getType()){
300 <                case 0:
301 <                    ghostIndex = currentExtra->getInt();
302 <                    isGhostBend = true;
303 <                    break;
347 >  Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol,
348 >                                          TorsionStamp* stamp) {
349  
350 <                default:
351 <                sprintf(painCave.errMsg,
352 <                "SimSetup Error: ghostVectorSource must be an int.\n");
353 <                painCave.isFatal = 1;
309 <                simError();
310 <                }
311 <            } else{
312 <                sprintf(painCave.errMsg,
313 <                "SimSetup Error: unhandled bend assignment:\n");
314 <                painCave.isFatal = 1;
315 <                simError();
316 <            }
317 <            currentExtra = currentExtra->getNext();
318 <        }
319 <        
350 >    Torsion* torsion = NULL;
351 >    std::vector<int> torsionAtoms = stamp->getMembers();
352 >    if (torsionAtoms.size() < 3) {
353 >        return torsion;
354      }
355  
356 <    if (isGhostBend) {
356 >    Atom* atomA = mol->getAtomAt(torsionAtoms[0]);
357 >    Atom* atomB = mol->getAtomAt(torsionAtoms[1]);
358 >    Atom* atomC = mol->getAtomAt(torsionAtoms[2]);
359  
360 <        int indexA = stamp->getA();
361 <        int indexB= stamp->getB();
360 >    if (torsionAtoms.size() == 4) {
361 >      Atom* atomD = mol->getAtomAt(torsionAtoms[3]);
362  
363 <        assert(indexA != indexB);
328 <
329 <        int normalIndex;
330 <        if (indexA == ghostIndex) {
331 <            normalIndex = indexB;
332 <        } else if (indexB == ghostIndex) {
333 <            normalIndex = indexA;
334 <        }
363 >      assert(atomA && atomB && atomC && atomD);
364          
365 <        Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
366 <        DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
367 <        if (ghostAtom == NULL) {
368 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
369 <            painCave.isFatal = 1;
370 <            simError();
371 <        }
372 <                
373 <        BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
374 <
346 <        if (bendType == NULL) {
347 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
348 <                       normalAtom->getType().c_str(),
349 <                       ghostAtom->getType().c_str(),
350 <                       "GHOST");
351 <
352 <            painCave.isFatal = 1;
353 <            simError();
354 <        }
365 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(),
366 >                                                    atomB->getType(),
367 >                                                    atomC->getType(),
368 >                                                    atomD->getType());
369 >      if (torsionType == NULL) {
370 >        sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
371 >                atomA->getType().c_str(),
372 >                atomB->getType().c_str(),
373 >                atomC->getType().c_str(),
374 >                atomD->getType().c_str());
375          
376 <        return new GhostBend(normalAtom, ghostAtom, bendType);      
377 <
378 <    } else {
379 <            
380 <        Atom* atomA = mol->getAtomAt(stamp->getA());
381 <        Atom* atomB = mol->getAtomAt(stamp->getB());
382 <        Atom* atomC = mol->getAtomAt(stamp->getC());
383 <
384 <        assert( atomA && atomB && atomC);
376 >        painCave.isFatal = 1;
377 >        simError();
378 >      }
379 >      
380 >      torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
381 >    }
382 >    else {
383 >      
384 >      DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource()));
385 >      if (dAtom == NULL) {
386 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
387 >        painCave.isFatal = 1;
388 >        simError();
389 >      }        
390 >      
391 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
392 >                                                    atomC->getType(), "GHOST");
393 >      
394 >      if (torsionType == NULL) {
395 >        sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
396 >                atomA->getType().c_str(),
397 >                atomB->getType().c_str(),
398 >                atomC->getType().c_str(),
399 >                "GHOST");
400          
401 <        BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType());
402 <
403 <        if (bendType == NULL) {
404 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
405 <                       atomA->getType().c_str(),
371 <                       atomB->getType().c_str(),
372 <                       atomC->getType().c_str());
373 <
374 <            painCave.isFatal = 1;
375 <            simError();
376 <        }
377 <
378 <        return new Bend(atomA, atomB, atomC, bendType);      
401 >        painCave.isFatal = 1;
402 >        simError();
403 >      }
404 >      
405 >      torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
406      }
407 < }    
407 >    
408 >    return torsion;
409 >  }    
410  
411 < Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) {
412 <
413 <    Atom* atomA = mol->getAtomAt(stamp->getA());
414 <    Atom* atomB = mol->getAtomAt(stamp->getB());
415 <    Atom* atomC = mol->getAtomAt(stamp->getC());
416 <    Torsion* torsion;
417 <
418 <    if (stamp->getD() != -1) {
390 <        Atom* atomD = mol->getAtomAt(stamp->getD());
391 <
392 <        assert(atomA && atomB && atomC && atomD);
393 <        
394 <        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
395 <                                                           atomC->getType(), atomD->getType());
396 <
397 <        if (torsionType == NULL) {
398 <            sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
399 <                       atomA->getType().c_str(),
400 <                       atomB->getType().c_str(),
401 <                       atomC->getType().c_str(),
402 <                       atomD->getType().c_str());
403 <
404 <            painCave.isFatal = 1;
405 <            simError();
406 <        }
407 <        
408 <        torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
411 >  Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol,
412 >                                              InversionStamp* stamp) {
413 >    
414 >    Inversion* inversion = NULL;
415 >    int center = stamp->getCenter();
416 >    std::vector<int> satellites = stamp->getSatellites();
417 >    if (satellites.size() != 3) {
418 >        return inversion;
419      }
410    else {
420  
421 <        DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(atomC);
422 <        if (dAtom == NULL) {
423 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
424 <            painCave.isFatal = 1;
425 <            simError();
426 <        }        
421 >    Atom* atomA = mol->getAtomAt(center);
422 >    Atom* atomB = mol->getAtomAt(satellites[0]);
423 >    Atom* atomC = mol->getAtomAt(satellites[1]);
424 >    Atom* atomD = mol->getAtomAt(satellites[2]);
425 >      
426 >    assert(atomA && atomB && atomC && atomD);
427 >    
428 >    InversionType* inversionType = ff->getInversionType(atomA->getType(),
429 >                                                        atomB->getType(),
430 >                                                        atomC->getType(),
431 >                                                        atomD->getType());
432  
433 <        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
434 <                                                           atomC->getType(), "GHOST");
435 <
436 <        if (torsionType == NULL) {
437 <            sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
438 <                       atomA->getType().c_str(),
439 <                       atomB->getType().c_str(),
440 <                       atomC->getType().c_str(),
441 <                       "GHOST");
442 <
443 <            painCave.isFatal = 1;
444 <            simError();
445 <        }
446 <        
447 <        torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
433 >    if (inversionType == NULL) {
434 >      sprintf(painCave.errMsg, "No Matching Inversion Type for[%s, %s, %s, %s]\n"
435 >              "\t(May not be a problem: not all inversions are parametrized)\n",
436 >              atomA->getType().c_str(),
437 >              atomB->getType().c_str(),
438 >              atomC->getType().c_str(),
439 >              atomD->getType().c_str());
440 >      
441 >      painCave.isFatal = 0;
442 >      painCave.severity = OPENMD_INFO;
443 >      simError();
444 >      return NULL;
445 >    } else {
446 >      
447 >      inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType);
448 >      return inversion;
449      }
450 +  }
451 +  
452  
453 <    return torsion;
454 < }    
455 <
439 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) {
453 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol,
454 >                                                  CutoffGroupStamp* stamp,
455 >                                                  LocalIndexManager* localIndexMan) {
456      int nAtoms;
457      CutoffGroup* cg;
458      Atom* atom;
# Line 444 | Line 460 | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecu
460      
461      nAtoms = stamp->getNMembers();
462      for (int i =0; i < nAtoms; ++i) {
463 <        atom = mol->getAtomAt(stamp->getMember(i));
464 <        assert(atom);
465 <        cg->addAtom(atom);
463 >      atom = mol->getAtomAt(stamp->getMemberAt(i));
464 >      assert(atom);
465 >      cg->addAtom(atom);
466      }
467 <
467 >    
468 >    //set the local index of this cutoffGroup, global index will be set later
469 >    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
470 >    
471      return cg;
472 < }    
473 <
474 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) {
472 >  }    
473 >  
474 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom,
475 >                                                  LocalIndexManager* localIndexMan) {
476      CutoffGroup* cg;
477      cg  = new CutoffGroup();
478      cg->addAtom(atom);
479 +
480 +    //set the local index of this cutoffGroup, global index will be set later
481 +    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
482 +
483      return cg;
484 < }
484 >  }
485  
486 < void MoleculeCreator::createConstraintPair(Molecule* mol) {
486 >  void MoleculeCreator::createConstraintPair(Molecule* mol) {
487  
488      //add bond constraints
489      Molecule::BondIterator bi;
490      Bond* bond;
491      for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) {
492          
493 <        BondType* bt = bond->getBondType();
493 >      BondType* bt = bond->getBondType();
494  
495 <        //class Parent1 {};
496 <        //class Child1 : public Parent {};
497 <        //class Child2 : public Parent {};
498 <        //Child1* ch1 = new Child1();
499 <        //Child2* ch2 = dynamic_cast<Child2*>(ch1);
500 <        //the dynamic_cast is succeed in above line. A compiler bug?        
495 >      //class Parent1 {};
496 >      //class Child1 : public Parent {};
497 >      //class Child2 : public Parent {};
498 >      //Child1* ch1 = new Child1();
499 >      //Child2* ch2 = dynamic_cast<Child2*>(ch1);
500 >      //the dynamic_cast is succeed in above line. A compiler bug?        
501  
502 <        if (typeid(FixedBondType) == typeid(*bt)) {
503 <            FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
502 >      if (typeid(FixedBondType) == typeid(*bt)) {
503 >        FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
504  
505 <            ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
506 <            ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
507 <            ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength());
508 <            mol->addConstraintPair(consPair);
509 <        }
505 >        ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
506 >        ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
507 >        ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength());
508 >        mol->addConstraintPair(consPair);
509 >      }
510      }
511  
512      //rigidbody -- rigidbody constraint is not support yet
513 < }
513 >  }
514  
515 < void MoleculeCreator::createConstraintElem(Molecule* mol) {
515 >  void MoleculeCreator::createConstraintElem(Molecule* mol) {
516  
517      ConstraintPair* consPair;
518      Molecule::ConstraintPairIterator cpi;
519      std::set<StuntDouble*> sdSet;
520      for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) {
521  
522 <        StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
523 <        if (sdSet.find(sdA) == sdSet.end()){
524 <            sdSet.insert(sdA);
525 <            mol->addConstraintElem(new ConstraintElem(sdA));
526 <        }
522 >      StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
523 >      if (sdSet.find(sdA) == sdSet.end()){
524 >        sdSet.insert(sdA);
525 >        mol->addConstraintElem(new ConstraintElem(sdA));
526 >      }
527  
528 <        StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
529 <        if (sdSet.find(sdB) == sdSet.end()){
530 <            sdSet.insert(sdB);
531 <            mol->addConstraintElem(new ConstraintElem(sdB));
532 <        }
528 >      StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
529 >      if (sdSet.find(sdB) == sdSet.end()){
530 >        sdSet.insert(sdB);
531 >        mol->addConstraintElem(new ConstraintElem(sdB));
532 >      }
533          
534      }
535  
536 < }
536 >  }
537      
538   }

Comparing:
trunk/src/brains/MoleculeCreator.cpp (property svn:keywords), Revision 292 by tim, Fri Feb 4 22:44:15 2005 UTC vs.
branches/development/src/brains/MoleculeCreator.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines