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

Comparing trunk/src/brains/MoleculeCreator.cpp (file contents):
Revision 273 by tim, Tue Jan 25 17:45:23 2005 UTC vs.
Revision 1908 by gezelter, Fri Jul 19 21:25:45 2013 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, 234107 (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
48 <  */
43 > /**
44 > * @file MoleculeCreator.cpp
45 > * @author tlin
46 > * @date 11/04/2004
47 > * @version 1.0
48 > */
49  
50   #include <cassert>
51 + #include <typeinfo>
52   #include <set>
53  
54   #include "brains/MoleculeCreator.hpp"
55   #include "primitives/GhostBend.hpp"
56   #include "primitives/GhostTorsion.hpp"
57 < #include "types/DirectionalAtomType.hpp"
57 > #include "types/AtomType.hpp"
58   #include "types/FixedBondType.hpp"
59   #include "utils/simError.h"
60   #include "utils/StringUtils.hpp"
61  
62 < namespace oopse {
62 > namespace OpenMD {
63 >  
64 >  Molecule* MoleculeCreator::createMolecule(ForceField* ff,
65 >                                            MoleculeStamp *molStamp,
66 >                                            int stampId, int globalIndex,
67 >                                            LocalIndexManager* localIndexMan) {
68 >    Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName(),
69 >                                 molStamp->getRegion() );
70  
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());
67    
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);
178      createConstraintElem(mol);
179      
180 +    // Does this molecule stamp define a total constrained charge value?
181 +    // If so, let the created molecule know about it.
182 +
183 +    if (molStamp->haveConstrainTotalCharge() ) {
184 +      mol->setConstrainTotalCharge( molStamp->getConstrainTotalCharge() );
185 +    }
186 +
187      //the construction of this molecule is finished
188      mol->complete();
189 <
189 >    
190      return mol;
191 < }    
191 >  }    
192  
193  
194 < Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp,
195 <                                                                  LocalIndexManager* localIndexMan) {
194 >  Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol,
195 >                                    AtomStamp* stamp,
196 >                                    LocalIndexManager* localIndexMan) {
197      AtomType * atomType;
198      Atom* atom;
199  
200      atomType =  ff->getAtomType(stamp->getType());
201 <
201 >    
202      if (atomType == NULL) {
203 <        sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
204 <                   stamp->getType());
203 >      sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
204 >              stamp->getType().c_str());
205  
206 <        painCave.isFatal = 1;
207 <        simError();
206 >      painCave.isFatal = 1;
207 >      simError();
208      }
209 <    
209 >
210      //below code still have some kind of hard-coding smell
211      if (atomType->isDirectional()){
203    
204        DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
205        
206        if (dAtomType == NULL) {
207            sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType");
212  
213 <            painCave.isFatal = 1;
214 <            simError();
215 <        }
212 <
213 <        DirectionalAtom* dAtom;
214 <        dAtom = new DirectionalAtom(dAtomType);
215 <        atom = dAtom;    
213 >      DirectionalAtom* dAtom;
214 >      dAtom = new DirectionalAtom(atomType);
215 >      atom = dAtom;    
216      }
217      else{
218 <        atom = new Atom(atomType);
218 >      atom = new Atom(atomType);
219      }
220  
221      atom->setLocalIndex(localIndexMan->getNextAtomIndex());
222  
223      return atom;
224 < }
225 <
226 < RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol,
227 <                                                                                    RigidBodyStamp* rbStamp,
228 <                                                                                    LocalIndexManager* localIndexMan) {
224 >  }
225 >  
226 >  RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp,
227 >                                              Molecule* mol,
228 >                                              RigidBodyStamp* rbStamp,
229 >                                              LocalIndexManager* localIndexMan) {
230      Atom* atom;
231      int nAtoms;
232      Vector3d refCoor;
# Line 234 | Line 235 | RigidBody* MoleculeCreator::createRigidBody(MoleculeSt
235      RigidBody* rb = new RigidBody();
236      nAtoms = rbStamp->getNMembers();    
237      for (int i = 0; i < nAtoms; ++i) {
238 <        //rbStamp->getMember(i) return the local index of current atom inside the molecule.
239 <        //It is not the same as local index of atom which is the index of atom at DataStorage class
240 <        atom = mol->getAtomAt(rbStamp->getMember(i));
241 <        atomStamp= molStamp->getAtom(rbStamp->getMember(i));    
242 <        rb->addAtom(atom, atomStamp);
238 >      //rbStamp->getMember(i) return the local index of current atom
239 >      //inside the molecule.  It is not the same as local index of
240 >      //atom which is the index of atom at DataStorage class
241 >      atom = mol->getAtomAt(rbStamp->getMemberAt(i));
242 >      atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i));    
243 >      rb->addAtom(atom, atomStamp);
244      }
245  
246 <    //after all of the atoms are added, we need to calculate the reference coordinates
246 >    //after all of the atoms are added, we need to calculate the
247 >    //reference coordinates
248      rb->calcRefCoords();
249  
250      //set the local index of this rigid body, global index will be set later
# Line 253 | Line 256 | RigidBody* MoleculeCreator::createRigidBody(MoleculeSt
256      //The third part is the index of the rigidbody defined in meta-data file
257      //For example, Butane_RB_0 is a valid rigid body name of butane molecule
258      /**@todo replace itoa by lexi_cast */
259 <    rb->setType(mol->getType() + "_RB_" + toString(mol->getNRigidBodies()));
260 <    
259 >    std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10);
260 >    rb->setType(mol->getType() + "_RB_" + s.c_str());
261 >
262      return rb;
263 < }    
263 >  }    
264  
265 < Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) {
265 >  Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol,
266 >                                    BondStamp* stamp) {
267      BondType* bondType;
268      Atom* atomA;
269      Atom* atomB;
270 <
270 >    
271      atomA = mol->getAtomAt(stamp->getA());
272      atomB = mol->getAtomAt(stamp->getB());
273 <
273 >    
274      assert( atomA && atomB);
275      
276      bondType = ff->getBondType(atomA->getType(), atomB->getType());
277  
278      if (bondType == NULL) {
279 <        sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
280 <                   atomA->getType().c_str(),
281 <                   atomB->getType().c_str());
282 <
283 <        painCave.isFatal = 1;
284 <        simError();
279 >      sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
280 >              atomA->getType().c_str(),
281 >              atomB->getType().c_str());
282 >      
283 >      painCave.isFatal = 1;
284 >      simError();
285      }
286      return new Bond(atomA, atomB, bondType);    
287 < }    
287 >  }    
288 >  
289 >  Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol,
290 >                                    BendStamp* stamp) {
291 >    Bend* bend = NULL;
292 >    std::vector<int> bendAtoms = stamp->getMembers();
293 >    if (bendAtoms.size() == 3) {
294 >      Atom* atomA = mol->getAtomAt(bendAtoms[0]);
295 >      Atom* atomB = mol->getAtomAt(bendAtoms[1]);
296 >      Atom* atomC = mol->getAtomAt(bendAtoms[2]);
297 >      
298 >      assert( atomA && atomB && atomC);
299 >      
300 >      BendType* bendType = ff->getBendType(atomA->getType().c_str(),
301 >                                           atomB->getType().c_str(),
302 >                                           atomC->getType().c_str());
303 >      
304 >      if (bendType == NULL) {
305 >        sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
306 >                atomA->getType().c_str(),
307 >                atomB->getType().c_str(),
308 >                atomC->getType().c_str());
309 >        
310 >        painCave.isFatal = 1;
311 >        simError();
312 >      }
313 >      
314 >      bend = new Bend(atomA, atomB, atomC, bendType);
315 >    } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) {
316 >      int ghostIndex = stamp->getGhostVectorSource();
317 >      int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1];
318 >      Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
319 >      DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
320 >      if (ghostAtom == NULL) {
321 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
322 >        painCave.isFatal = 1;
323 >        simError();
324 >      }
325 >                
326 >      BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
327  
328 < Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) {
329 <    bool isGhostBend = false;
330 <    int ghostIndex;
328 >      if (bendType == NULL) {
329 >        sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
330 >                normalAtom->getType().c_str(),
331 >                ghostAtom->getType().c_str(),
332 >                "GHOST");
333  
334 +        painCave.isFatal = 1;
335 +        simError();
336 +      }
337 +      
338 +      bend = new GhostBend(normalAtom, ghostAtom, bendType);      
339 +      
340 +    }
341      
342 <    //
343 <    if (stamp->haveExtras()){
291 <        LinkedAssign* extras = stamp->getExtras();
292 <        LinkedAssign* currentExtra = extras;
342 >    return bend;
343 >  }    
344  
345 <        while (currentExtra != NULL){
346 <            if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){
296 <                switch (currentExtra->getType()){
297 <                case 0:
298 <                    ghostIndex = currentExtra->getInt();
299 <                    isGhostBend = true;
300 <                    break;
345 >  Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol,
346 >                                          TorsionStamp* stamp) {
347  
348 <                default:
349 <                sprintf(painCave.errMsg,
350 <                "SimSetup Error: ghostVectorSource must be an int.\n");
351 <                painCave.isFatal = 1;
306 <                simError();
307 <                }
308 <            } else{
309 <                sprintf(painCave.errMsg,
310 <                "SimSetup Error: unhandled bend assignment:\n");
311 <                painCave.isFatal = 1;
312 <                simError();
313 <            }
314 <            currentExtra = currentExtra->getNext();
315 <        }
316 <        
348 >    Torsion* torsion = NULL;
349 >    std::vector<int> torsionAtoms = stamp->getMembers();
350 >    if (torsionAtoms.size() < 3) {
351 >        return torsion;
352      }
353  
354 <    if (isGhostBend) {
354 >    Atom* atomA = mol->getAtomAt(torsionAtoms[0]);
355 >    Atom* atomB = mol->getAtomAt(torsionAtoms[1]);
356 >    Atom* atomC = mol->getAtomAt(torsionAtoms[2]);
357  
358 <        int indexA = stamp->getA();
359 <        int indexB= stamp->getB();
358 >    if (torsionAtoms.size() == 4) {
359 >      Atom* atomD = mol->getAtomAt(torsionAtoms[3]);
360  
361 <        assert(indexA != indexB);
325 <
326 <        int normalIndex;
327 <        if (indexA == ghostIndex) {
328 <            normalIndex = indexB;
329 <        } else if (indexB == ghostIndex) {
330 <            normalIndex = indexA;
331 <        }
361 >      assert(atomA && atomB && atomC && atomD);
362          
363 <        Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
364 <        DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
365 <        if (ghostAtom == NULL) {
366 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
367 <            painCave.isFatal = 1;
368 <            simError();
369 <        }
370 <                
371 <        BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
372 <
343 <        if (bendType == NULL) {
344 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
345 <                       normalAtom->getType().c_str(),
346 <                       ghostAtom->getType().c_str(),
347 <                       "GHOST");
348 <
349 <            painCave.isFatal = 1;
350 <            simError();
351 <        }
363 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(),
364 >                                                    atomB->getType(),
365 >                                                    atomC->getType(),
366 >                                                    atomD->getType());
367 >      if (torsionType == NULL) {
368 >        sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
369 >                atomA->getType().c_str(),
370 >                atomB->getType().c_str(),
371 >                atomC->getType().c_str(),
372 >                atomD->getType().c_str());
373          
374 <        return new GhostBend(normalAtom, ghostAtom, bendType);      
375 <
376 <    } else {
377 <            
378 <        Atom* atomA = mol->getAtomAt(stamp->getA());
379 <        Atom* atomB = mol->getAtomAt(stamp->getB());
380 <        Atom* atomC = mol->getAtomAt(stamp->getC());
381 <
382 <        assert( atomA && atomB && atomC);
374 >        painCave.isFatal = 1;
375 >        simError();
376 >      }
377 >      
378 >      torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
379 >    }
380 >    else {
381 >      
382 >      DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource()));
383 >      if (dAtom == NULL) {
384 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
385 >        painCave.isFatal = 1;
386 >        simError();
387 >      }        
388 >      
389 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
390 >                                                    atomC->getType(), "GHOST");
391 >      
392 >      if (torsionType == NULL) {
393 >        sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
394 >                atomA->getType().c_str(),
395 >                atomB->getType().c_str(),
396 >                atomC->getType().c_str(),
397 >                "GHOST");
398          
399 <        BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType());
400 <
401 <        if (bendType == NULL) {
402 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
403 <                       atomA->getType().c_str(),
368 <                       atomB->getType().c_str(),
369 <                       atomC->getType().c_str());
370 <
371 <            painCave.isFatal = 1;
372 <            simError();
373 <        }
374 <
375 <        return new Bend(atomA, atomB, atomC, bendType);      
399 >        painCave.isFatal = 1;
400 >        simError();
401 >      }
402 >      
403 >      torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
404      }
405 < }    
405 >    
406 >    return torsion;
407 >  }    
408  
409 < Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) {
410 <
411 <    Atom* atomA = mol->getAtomAt(stamp->getA());
412 <    Atom* atomB = mol->getAtomAt(stamp->getB());
413 <    Atom* atomC = mol->getAtomAt(stamp->getC());
414 <    Torsion* torsion;
415 <
416 <    if (stamp->getD() != -1) {
387 <        Atom* atomD = mol->getAtomAt(stamp->getD());
388 <
389 <        assert(atomA && atomB && atomC && atomD);
390 <        
391 <        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
392 <                                                           atomC->getType(), atomD->getType());
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 <                       atomD->getType().c_str());
400 <
401 <            painCave.isFatal = 1;
402 <            simError();
403 <        }
404 <        
405 <        torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
409 >  Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol,
410 >                                              InversionStamp* stamp) {
411 >    
412 >    Inversion* inversion = NULL;
413 >    int center = stamp->getCenter();
414 >    std::vector<int> satellites = stamp->getSatellites();
415 >    if (satellites.size() != 3) {
416 >        return inversion;
417      }
407    else {
418  
419 <        DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(atomC);
420 <        if (dAtom == NULL) {
421 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
422 <            painCave.isFatal = 1;
423 <            simError();
424 <        }        
419 >    Atom* atomA = mol->getAtomAt(center);
420 >    Atom* atomB = mol->getAtomAt(satellites[0]);
421 >    Atom* atomC = mol->getAtomAt(satellites[1]);
422 >    Atom* atomD = mol->getAtomAt(satellites[2]);
423 >      
424 >    assert(atomA && atomB && atomC && atomD);
425 >    
426 >    InversionType* inversionType = ff->getInversionType(atomA->getType(),
427 >                                                        atomB->getType(),
428 >                                                        atomC->getType(),
429 >                                                        atomD->getType());
430  
431 <        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
432 <                                                           atomC->getType(), "GHOST");
433 <
434 <        if (torsionType == NULL) {
435 <            sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
436 <                       atomA->getType().c_str(),
437 <                       atomB->getType().c_str(),
438 <                       atomC->getType().c_str(),
439 <                       "GHOST");
440 <
441 <            painCave.isFatal = 1;
442 <            simError();
443 <        }
444 <        
445 <        torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
431 >    if (inversionType == NULL) {
432 >      sprintf(painCave.errMsg, "No Matching Inversion Type for[%s, %s, %s, %s]\n"
433 >              "\t(May not be a problem: not all inversions are parametrized)\n",
434 >              atomA->getType().c_str(),
435 >              atomB->getType().c_str(),
436 >              atomC->getType().c_str(),
437 >              atomD->getType().c_str());
438 >      
439 >      painCave.isFatal = 0;
440 >      painCave.severity = OPENMD_INFO;
441 >      simError();
442 >      return NULL;
443 >    } else {
444 >      
445 >      inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType);
446 >      return inversion;
447      }
448 +  }
449 +  
450  
451 <    return torsion;
452 < }    
453 <
436 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) {
451 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol,
452 >                                                  CutoffGroupStamp* stamp,
453 >                                                  LocalIndexManager* localIndexMan) {
454      int nAtoms;
455      CutoffGroup* cg;
456      Atom* atom;
# Line 441 | Line 458 | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecu
458      
459      nAtoms = stamp->getNMembers();
460      for (int i =0; i < nAtoms; ++i) {
461 <        atom = mol->getAtomAt(stamp->getMember(i));
462 <        assert(atom);
463 <        cg->addAtom(atom);
461 >      atom = mol->getAtomAt(stamp->getMemberAt(i));
462 >      assert(atom);
463 >      cg->addAtom(atom);
464      }
465 <
465 >    
466 >    //set the local index of this cutoffGroup, global index will be set later
467 >    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
468 >    
469      return cg;
470 < }    
471 <
472 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) {
470 >  }    
471 >  
472 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom,
473 >                                                  LocalIndexManager* localIndexMan) {
474      CutoffGroup* cg;
475      cg  = new CutoffGroup();
476      cg->addAtom(atom);
477 +
478 +    //set the local index of this cutoffGroup, global index will be set later
479 +    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
480 +
481      return cg;
482 < }
482 >  }
483  
484 < void MoleculeCreator::createConstraintPair(Molecule* mol) {
484 >  void MoleculeCreator::createConstraintPair(Molecule* mol) {
485  
486      //add bond constraints
487      Molecule::BondIterator bi;
488      Bond* bond;
489      for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) {
490          
491 <        BondType* bt = bond->getBondType();
491 >      BondType* bt = bond->getBondType();
492  
493 <        //class Parent1 {};
494 <        //class Child1 : public Parent {};
495 <        //class Child2 : public Parent {};
496 <        //Child1* ch1 = new Child1();
497 <        //Child2* ch2 = dynamic_cast<Child2*>(ch1);
498 <        //the dynamic_cast is succeed in above line. A compiler bug?        
493 >      //class Parent1 {};
494 >      //class Child1 : public Parent {};
495 >      //class Child2 : public Parent {};
496 >      //Child1* ch1 = new Child1();
497 >      //Child2* ch2 = dynamic_cast<Child2*>(ch1);
498 >      //the dynamic_cast is succeed in above line. A compiler bug?        
499  
500 <        if (typeid(FixedBondType) == typeid(*bt)) {
501 <            FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
500 >      if (typeid(FixedBondType) == typeid(*bt)) {
501 >        FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
502  
503 <            ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
504 <            ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
505 <            ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength());
506 <            mol->addConstraintPair(consPair);
507 <        }
503 >        ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
504 >        ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
505 >        ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength());
506 >        mol->addConstraintPair(consPair);
507 >      }
508      }
509  
510      //rigidbody -- rigidbody constraint is not support yet
511 < }
511 >  }
512  
513 < void MoleculeCreator::createConstraintElem(Molecule* mol) {
513 >  void MoleculeCreator::createConstraintElem(Molecule* mol) {
514  
515      ConstraintPair* consPair;
516      Molecule::ConstraintPairIterator cpi;
517      std::set<StuntDouble*> sdSet;
518      for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) {
519  
520 <        StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
521 <        if (sdSet.find(sdA) == sdSet.end()){
522 <            sdSet.insert(sdA);
523 <            mol->addConstraintElem(new ConstraintElem(sdA));
524 <        }
520 >      StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
521 >      if (sdSet.find(sdA) == sdSet.end()){
522 >        sdSet.insert(sdA);
523 >        mol->addConstraintElem(new ConstraintElem(sdA));
524 >      }
525  
526 <        StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
527 <        if (sdSet.find(sdB) == sdSet.end()){
528 <            sdSet.insert(sdB);
529 <            mol->addConstraintElem(new ConstraintElem(sdB));
530 <        }
526 >      StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
527 >      if (sdSet.find(sdB) == sdSet.end()){
528 >        sdSet.insert(sdB);
529 >        mol->addConstraintElem(new ConstraintElem(sdB));
530 >      }
531          
532      }
533  
534 < }
534 >  }
535      
536   }

Comparing trunk/src/brains/MoleculeCreator.cpp (property svn:keywords):
Revision 273 by tim, Tue Jan 25 17:45:23 2005 UTC vs.
Revision 1908 by gezelter, Fri Jul 19 21:25:45 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines