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

Comparing trunk/src/brains/MoleculeCreator.cpp (property svn:keywords):
Revision 273 by tim, Tue Jan 25 17:45:23 2005 UTC vs.
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines