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 403 by gezelter, Tue Mar 8 21:06:49 2005 UTC vs.
Revision 1979 by gezelter, Sat Apr 5 20:56:01 2014 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, localIndexMan);
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, localIndexMan);
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, localIndexMan);
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 +                                  localIndexMan);
132 +      if (inversion != NULL ) {
133 +        mol->addInversion(inversion);
134 +      }
135 +    }
136 +
137      //create cutoffGroups
138      CutoffGroup* cutoffGroup;
139      CutoffGroupStamp* currentCutoffGroupStamp;
140      int nCutoffGroups = molStamp->getNCutoffGroups();
141      for (int i = 0; i < nCutoffGroups; ++i) {
142 <        currentCutoffGroupStamp = molStamp->getCutoffGroup(i);
143 <        cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp);
144 <        mol->addCutoffGroup(cutoffGroup);
142 >      currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i);
143 >      cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp,
144 >                                      localIndexMan);
145 >      mol->addCutoffGroup(cutoffGroup);
146      }
147  
148      //every free atom is a cutoff group    
149 <    std::set<Atom*> allAtoms;
150 <     Molecule::AtomIterator ai;
149 >    std::vector<Atom*> freeAtoms;
150 >    std::vector<Atom*>::iterator ai;
151 >    std::vector<Atom*>::iterator fai;
152  
153      //add all atoms into allAtoms set
154 <    for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
155 <        allAtoms.insert(atom);
154 >    for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) {
155 >      freeAtoms.push_back(atom);
156      }
157  
158      Molecule::CutoffGroupIterator ci;
159      CutoffGroup* cg;
141    std::set<Atom*> cutoffAtoms;    
160      
161 <    //add all of the atoms belong to cutoff groups into cutoffAtoms set
162 <    for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
163 <
164 <        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
165 <            cutoffAtoms.insert(atom);
166 <        }
167 <
161 >    for (cg = mol->beginCutoffGroup(ci); cg != NULL;
162 >         cg = mol->nextCutoffGroup(ci)) {
163 >      
164 >      for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
165 >        //erase the atoms belong to cutoff groups from freeAtoms vector
166 >        freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom),
167 >                        freeAtoms.end());
168 >      }      
169      }      
170      
171 <    //find all free atoms (which do not belong to cutoff groups)  
172 <    //performs the "difference" operation from set theory,  the output range contains a copy of every
173 <    //element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in
174 <    //[cutoffAtoms.begin(), cutoffAtoms.end()).
175 <    std::vector<Atom*> freeAtoms;    
176 <    std::set_difference(allAtoms.begin(), allAtoms.end(), cutoffAtoms.begin(), cutoffAtoms.end(),
177 <                            std::back_inserter(freeAtoms));
171 >    // loop over the free atoms and then create one cutoff group for
172 >    // every single free atom
173 >    
174 >    for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) {
175 >      cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan);
176 >      mol->addCutoffGroup(cutoffGroup);
177 >    }
178  
179 <    if (freeAtoms.size() != allAtoms.size() - cutoffAtoms.size()) {
180 <        //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");
179 >    //create bonded constraintPairs:
180 >    createConstraintPair(mol);
181  
182 +    //create non-bonded constraintPairs
183 +    for (int i = 0; i < molStamp->getNConstraints(); ++i) {
184 +      ConstraintStamp* cStamp = molStamp->getConstraintStamp(i);
185 +      Atom* atomA;
186 +      Atom* atomB;
187 +      
188 +      atomA = mol->getAtomAt(cStamp->getA());
189 +      atomB = mol->getAtomAt(cStamp->getB());
190 +      assert( atomA && atomB );
191 +      
192 +      RealType distance;
193 +      bool printConstraintForce = false;
194 +
195 +      if (!cStamp->haveConstrainedDistance()) {
196 +        sprintf(painCave.errMsg,
197 +                "Constraint Error: A non-bond constraint was specified\n"
198 +                "\twithout providing a value for the constrainedDistance.\n");
199          painCave.isFatal = 1;
200 <        simError();        
200 >        simError();      
201 >      } else {
202 >        distance = cStamp->getConstrainedDistance();
203 >      }
204 >
205 >      if (cStamp->havePrintConstraintForce()) {
206 >        printConstraintForce = cStamp->getPrintConstraintForce();
207 >      }
208 >    
209 >      ConstraintElem* consElemA = new ConstraintElem(atomA);
210 >      ConstraintElem* consElemB = new ConstraintElem(atomB);
211 >      ConstraintPair* cPair = new ConstraintPair(consElemA, consElemB, distance,
212 >                                                 printConstraintForce);
213 >      mol->addConstraintPair(cPair);
214      }
215  
216 <    //loop over the free atoms and then create one cutoff group for every single free atom
169 <    std::vector<Atom*>::iterator fai;
216 >    // now create the constraint elements:
217  
171    for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) {
172        cutoffGroup = createCutoffGroup(mol, *fai);
173        mol->addCutoffGroup(cutoffGroup);
174    }
175    //create constraints
176    createConstraintPair(mol);
218      createConstraintElem(mol);
219      
220 +    // Does this molecule stamp define a total constrained charge value?
221 +    // If so, let the created molecule know about it.
222 +
223 +    if (molStamp->haveConstrainTotalCharge() ) {
224 +      mol->setConstrainTotalCharge( molStamp->getConstrainTotalCharge() );
225 +    }
226 +
227      //the construction of this molecule is finished
228      mol->complete();
229 <
229 >    
230      return mol;
231 < }    
231 >  }    
232  
233  
234 < Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp,
235 <                                                                  LocalIndexManager* localIndexMan) {
234 >  Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol,
235 >                                    AtomStamp* stamp,
236 >                                    LocalIndexManager* localIndexMan) {
237      AtomType * atomType;
238      Atom* atom;
239  
240      atomType =  ff->getAtomType(stamp->getType());
241 <
241 >    
242      if (atomType == NULL) {
243 <        sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
244 <                   stamp->getType());
243 >      sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
244 >              stamp->getType().c_str());
245  
246 <        painCave.isFatal = 1;
247 <        simError();
246 >      painCave.isFatal = 1;
247 >      simError();
248      }
249 <    
249 >
250      //below code still have some kind of hard-coding smell
251      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");
252  
253 <            painCave.isFatal = 1;
254 <            simError();
255 <        }
212 <
213 <        DirectionalAtom* dAtom;
214 <        dAtom = new DirectionalAtom(dAtomType);
215 <        atom = dAtom;    
253 >      DirectionalAtom* dAtom;
254 >      dAtom = new DirectionalAtom(atomType);
255 >      atom = dAtom;    
256      }
257      else{
258 <        atom = new Atom(atomType);
258 >      atom = new Atom(atomType);
259      }
260  
261      atom->setLocalIndex(localIndexMan->getNextAtomIndex());
262  
263      return atom;
264 < }
265 <
266 < RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol,
267 <                                                                                    RigidBodyStamp* rbStamp,
268 <                                                                                    LocalIndexManager* localIndexMan) {
264 >  }
265 >  
266 >  RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp,
267 >                                              Molecule* mol,
268 >                                              RigidBodyStamp* rbStamp,
269 >                                              LocalIndexManager* localIndexMan){
270      Atom* atom;
271      int nAtoms;
272      Vector3d refCoor;
# Line 234 | Line 275 | RigidBody* MoleculeCreator::createRigidBody(MoleculeSt
275      RigidBody* rb = new RigidBody();
276      nAtoms = rbStamp->getNMembers();    
277      for (int i = 0; i < nAtoms; ++i) {
278 <        //rbStamp->getMember(i) return the local index of current atom inside the molecule.
279 <        //It is not the same as local index of atom which is the index of atom at DataStorage class
280 <        atom = mol->getAtomAt(rbStamp->getMember(i));
281 <        atomStamp= molStamp->getAtom(rbStamp->getMember(i));    
282 <        rb->addAtom(atom, atomStamp);
278 >      //rbStamp->getMember(i) return the local index of current atom
279 >      //inside the molecule.  It is not the same as local index of
280 >      //atom which is the index of atom at DataStorage class
281 >      atom = mol->getAtomAt(rbStamp->getMemberAt(i));
282 >      atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i));    
283 >      rb->addAtom(atom, atomStamp);
284      }
285  
286 <    //after all of the atoms are added, we need to calculate the reference coordinates
286 >    //after all of the atoms are added, we need to calculate the
287 >    //reference coordinates
288      rb->calcRefCoords();
289  
290      //set the local index of this rigid body, global index will be set later
291      rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex());
292  
293 <    //the rule for naming rigidbody MoleculeName_RB_Integer
294 <    //The first part is the name of the molecule
295 <    //The second part is alway fixed as "RB"
296 <    //The third part is the index of the rigidbody defined in meta-data file
297 <    //For example, Butane_RB_0 is a valid rigid body name of butane molecule
255 <    /**@todo replace itoa by lexi_cast */
256 <    std::string s = OOPSE_itoa(mol->getNRigidBodies(), 10);
257 <    rb->setType(mol->getType() + "_RB_" + s.c_str());
293 >    // The rule for naming a rigidbody is: MoleculeName_RB_Integer
294 >    // The first part is the name of the molecule
295 >    // The second part is always fixed as "RB"
296 >    // The third part is the index of the rigidbody defined in meta-data file
297 >    // For example, Butane_RB_0 is a valid rigid body name of butane molecule
298  
299 +    std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10);
300 +    rb->setType(mol->getType() + "_RB_" + s.c_str());
301      return rb;
302 < }    
302 >  }    
303  
304 < Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) {
304 >  Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol,
305 >                                    BondStamp* stamp,
306 >                                    LocalIndexManager* localIndexMan) {
307      BondType* bondType;
308      Atom* atomA;
309      Atom* atomB;
310 <
310 >    
311      atomA = mol->getAtomAt(stamp->getA());
312      atomB = mol->getAtomAt(stamp->getB());
313 <
313 >    
314      assert( atomA && atomB);
315      
316      bondType = ff->getBondType(atomA->getType(), atomB->getType());
317  
318      if (bondType == NULL) {
319 <        sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
320 <                   atomA->getType().c_str(),
321 <                   atomB->getType().c_str());
319 >      sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
320 >              atomA->getType().c_str(),
321 >              atomB->getType().c_str());
322 >      
323 >      painCave.isFatal = 1;
324 >      simError();
325 >    }
326 >    Bond* bond = new Bond(atomA, atomB, bondType);
327  
328 +    //set the local index of this bond, the global index will be set later
329 +    bond->setLocalIndex(localIndexMan->getNextBondIndex());
330 +
331 +    // The rule for naming a bond is: MoleculeName_Bond_Integer
332 +    // The first part is the name of the molecule
333 +    // The second part is always fixed as "Bond"
334 +    // The third part is the index of the bond defined in meta-data file
335 +    // For example, Butane_bond_0 is a valid Bond name in a butane molecule
336 +
337 +    std::string s = OpenMD_itoa(mol->getNBonds(), 10);
338 +    bond->setName(mol->getType() + "_Bond_" + s.c_str());
339 +    return bond;    
340 +  }    
341 +  
342 +  Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol,
343 +                                    BendStamp* stamp,
344 +                                    LocalIndexManager* localIndexMan) {
345 +    Bend* bend = NULL;
346 +    std::vector<int> bendAtoms = stamp->getMembers();
347 +    if (bendAtoms.size() == 3) {
348 +      Atom* atomA = mol->getAtomAt(bendAtoms[0]);
349 +      Atom* atomB = mol->getAtomAt(bendAtoms[1]);
350 +      Atom* atomC = mol->getAtomAt(bendAtoms[2]);
351 +      
352 +      assert( atomA && atomB && atomC);
353 +      
354 +      BendType* bendType = ff->getBendType(atomA->getType().c_str(),
355 +                                           atomB->getType().c_str(),
356 +                                           atomC->getType().c_str());
357 +      
358 +      if (bendType == NULL) {
359 +        sprintf(painCave.errMsg,
360 +                "Can not find Matching Bend Type for[%s, %s, %s]",
361 +                atomA->getType().c_str(),
362 +                atomB->getType().c_str(),
363 +                atomC->getType().c_str());
364 +        
365          painCave.isFatal = 1;
366          simError();
367 <    }
368 <    return new Bond(atomA, atomB, bondType);    
369 < }    
367 >      }
368 >      
369 >      bend = new Bend(atomA, atomB, atomC, bendType);
370 >    } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) {
371 >      int ghostIndex = stamp->getGhostVectorSource();
372 >      int normalIndex = ghostIndex != bendAtoms[0] ? bendAtoms[0] : bendAtoms[1];
373 >      Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
374 >      DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
375 >      if (ghostAtom == NULL) {
376 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
377 >        painCave.isFatal = 1;
378 >        simError();
379 >      }
380 >                
381 >      BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
382  
383 < Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) {
384 <    bool isGhostBend = false;
385 <    int ghostIndex;
383 >      if (bendType == NULL) {
384 >        sprintf(painCave.errMsg,
385 >                "Can not find Matching Bend Type for[%s, %s, %s]",
386 >                normalAtom->getType().c_str(),
387 >                ghostAtom->getType().c_str(),
388 >                "GHOST");
389  
390 <    
391 <    //
392 <    if (stamp->haveExtras()){
393 <        LinkedAssign* extras = stamp->getExtras();
394 <        LinkedAssign* currentExtra = extras;
390 >        painCave.isFatal = 1;
391 >        simError();
392 >      }
393 >      
394 >      bend = new GhostBend(normalAtom, ghostAtom, bendType);      
395 >      
396 >    }
397  
398 <        while (currentExtra != NULL){
399 <            if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){
297 <                switch (currentExtra->getType()){
298 <                case 0:
299 <                    ghostIndex = currentExtra->getInt();
300 <                    isGhostBend = true;
301 <                    break;
398 >    //set the local index of this bend, the global index will be set later
399 >    bend->setLocalIndex(localIndexMan->getNextBendIndex());
400  
401 <                default:
402 <                sprintf(painCave.errMsg,
403 <                "SimSetup Error: ghostVectorSource must be an int.\n");
404 <                painCave.isFatal = 1;
405 <                simError();
308 <                }
309 <            } else{
310 <                sprintf(painCave.errMsg,
311 <                "SimSetup Error: unhandled bend assignment:\n");
312 <                painCave.isFatal = 1;
313 <                simError();
314 <            }
315 <            currentExtra = currentExtra->getNext();
316 <        }
317 <        
318 <    }
401 >    // The rule for naming a bend is: MoleculeName_Bend_Integer
402 >    // The first part is the name of the molecule
403 >    // The second part is always fixed as "Bend"
404 >    // The third part is the index of the bend defined in meta-data file
405 >    // For example, Butane_Bend_0 is a valid Bend name in a butane molecule
406  
407 <    if (isGhostBend) {
407 >    std::string s = OpenMD_itoa(mol->getNBends(), 10);
408 >    bend->setName(mol->getType() + "_Bend_" + s.c_str());    
409 >    return bend;
410 >  }    
411  
412 <        int indexA = stamp->getA();
413 <        int indexB= stamp->getB();
412 >  Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol,
413 >                                          TorsionStamp* stamp,
414 >                                          LocalIndexManager* localIndexMan) {
415  
416 <        assert(indexA != indexB);
416 >    Torsion* torsion = NULL;
417 >    std::vector<int> torsionAtoms = stamp->getMembers();
418 >    if (torsionAtoms.size() < 3) {
419 >        return torsion;
420 >    }
421  
422 <        int normalIndex;
423 <        if (indexA == ghostIndex) {
424 <            normalIndex = indexB;
330 <        } else if (indexB == ghostIndex) {
331 <            normalIndex = indexA;
332 <        }
333 <        
334 <        Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
335 <        DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
336 <        if (ghostAtom == NULL) {
337 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
338 <            painCave.isFatal = 1;
339 <            simError();
340 <        }
341 <                
342 <        BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
422 >    Atom* atomA = mol->getAtomAt(torsionAtoms[0]);
423 >    Atom* atomB = mol->getAtomAt(torsionAtoms[1]);
424 >    Atom* atomC = mol->getAtomAt(torsionAtoms[2]);
425  
426 <        if (bendType == NULL) {
427 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
346 <                       normalAtom->getType().c_str(),
347 <                       ghostAtom->getType().c_str(),
348 <                       "GHOST");
426 >    if (torsionAtoms.size() == 4) {
427 >      Atom* atomD = mol->getAtomAt(torsionAtoms[3]);
428  
429 <            painCave.isFatal = 1;
351 <            simError();
352 <        }
429 >      assert(atomA && atomB && atomC && atomD);
430          
431 <        return new GhostBend(normalAtom, ghostAtom, bendType);      
432 <
433 <    } else {
434 <            
435 <        Atom* atomA = mol->getAtomAt(stamp->getA());
436 <        Atom* atomB = mol->getAtomAt(stamp->getB());
437 <        Atom* atomC = mol->getAtomAt(stamp->getC());
438 <
439 <        assert( atomA && atomB && atomC);
431 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(),
432 >                                                    atomB->getType(),
433 >                                                    atomC->getType(),
434 >                                                    atomD->getType());
435 >      if (torsionType == NULL) {
436 >        sprintf(painCave.errMsg,
437 >                "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 >                atomD->getType().c_str());
442          
443 <        BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType());
443 >        painCave.isFatal = 1;
444 >        simError();
445 >      }
446 >      
447 >      torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
448 >    }
449 >    else {
450 >      
451 >      DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource()));
452 >      if (dAtom == NULL) {
453 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
454 >        painCave.isFatal = 1;
455 >        simError();
456 >      }        
457 >      
458 >      TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
459 >                                                    atomC->getType(), "GHOST");
460 >      
461 >      if (torsionType == NULL) {
462 >        sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
463 >                atomA->getType().c_str(),
464 >                atomB->getType().c_str(),
465 >                atomC->getType().c_str(),
466 >                "GHOST");
467 >        
468 >        painCave.isFatal = 1;
469 >        simError();
470 >      }
471 >      
472 >      torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
473 >    }
474  
475 <        if (bendType == NULL) {
476 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
477 <                       atomA->getType().c_str(),
478 <                       atomB->getType().c_str(),
479 <                       atomC->getType().c_str());
475 >    //set the local index of this torsion, the global index will be set later
476 >    torsion->setLocalIndex(localIndexMan->getNextTorsionIndex());
477 >    
478 >    // The rule for naming a torsion is: MoleculeName_Torsion_Integer
479 >    // The first part is the name of the molecule
480 >    // The second part is always fixed as "Torsion"
481 >    // The third part is the index of the torsion defined in meta-data file
482 >    // For example, Butane_Torsion_0 is a valid Torsion name in a
483 >    // butane molecule
484  
485 <            painCave.isFatal = 1;
486 <            simError();
487 <        }
485 >    std::string s = OpenMD_itoa(mol->getNTorsions(), 10);
486 >    torsion->setName(mol->getType() + "_Torsion_" + s.c_str());
487 >    return torsion;
488 >  }    
489  
490 <        return new Bend(atomA, atomB, atomC, bendType);      
490 >  Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol,
491 >                                              InversionStamp* stamp,
492 >                                              LocalIndexManager* localIndexMan) {
493 >    
494 >    Inversion* inversion = NULL;
495 >    int center = stamp->getCenter();
496 >    std::vector<int> satellites = stamp->getSatellites();
497 >    if (satellites.size() != 3) {
498 >        return inversion;
499      }
378 }    
500  
501 < Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) {
501 >    Atom* atomA = mol->getAtomAt(center);
502 >    Atom* atomB = mol->getAtomAt(satellites[0]);
503 >    Atom* atomC = mol->getAtomAt(satellites[1]);
504 >    Atom* atomD = mol->getAtomAt(satellites[2]);
505 >      
506 >    assert(atomA && atomB && atomC && atomD);
507 >    
508 >    InversionType* inversionType = ff->getInversionType(atomA->getType(),
509 >                                                        atomB->getType(),
510 >                                                        atomC->getType(),
511 >                                                        atomD->getType());
512  
513 <    Atom* atomA = mol->getAtomAt(stamp->getA());
514 <    Atom* atomB = mol->getAtomAt(stamp->getB());
515 <    Atom* atomC = mol->getAtomAt(stamp->getC());
516 <    Torsion* torsion;
513 >    if (inversionType == NULL) {
514 >      sprintf(painCave.errMsg, "No Matching Inversion Type for[%s, %s, %s, %s]\n"
515 >              "\t(May not be a problem: not all inversions are parametrized)\n",
516 >              atomA->getType().c_str(),
517 >              atomB->getType().c_str(),
518 >              atomC->getType().c_str(),
519 >              atomD->getType().c_str());
520 >      
521 >      painCave.isFatal = 0;
522 >      painCave.severity = OPENMD_INFO;
523 >      simError();
524 >      return NULL;
525 >    } else {
526 >      
527 >      inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType);
528  
529 <    if (stamp->getD() != -1) {
530 <        Atom* atomD = mol->getAtomAt(stamp->getD());
529 >      // set the local index of this inversion, the global index will
530 >      // be set later
531 >      inversion->setLocalIndex(localIndexMan->getNextInversionIndex());
532  
533 <        assert(atomA && atomB && atomC && atomD);
534 <        
535 <        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
536 <                                                           atomC->getType(), atomD->getType());
533 >      // The rule for naming an inversion is: MoleculeName_Inversion_Integer
534 >      // The first part is the name of the molecule
535 >      // The second part is always fixed as "Inversion"
536 >      // The third part is the index of the inversion defined in meta-data file
537 >      // For example, Benzene_Inversion_0 is a valid Inversion name in a
538 >      // Benzene molecule
539  
540 <        if (torsionType == NULL) {
541 <            sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
542 <                       atomA->getType().c_str(),
398 <                       atomB->getType().c_str(),
399 <                       atomC->getType().c_str(),
400 <                       atomD->getType().c_str());
401 <
402 <            painCave.isFatal = 1;
403 <            simError();
404 <        }
405 <        
406 <        torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
540 >      std::string s = OpenMD_itoa(mol->getNInversions(), 10);
541 >      inversion->setName(mol->getType() + "_Inversion_" + s.c_str());
542 >      return inversion;
543      }
544 <    else {
544 >  }
545 >  
546  
547 <        DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(atomC);
548 <        if (dAtom == NULL) {
549 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
413 <            painCave.isFatal = 1;
414 <            simError();
415 <        }        
416 <
417 <        TorsionType* torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
418 <                                                           atomC->getType(), "GHOST");
419 <
420 <        if (torsionType == NULL) {
421 <            sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
422 <                       atomA->getType().c_str(),
423 <                       atomB->getType().c_str(),
424 <                       atomC->getType().c_str(),
425 <                       "GHOST");
426 <
427 <            painCave.isFatal = 1;
428 <            simError();
429 <        }
430 <        
431 <        torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
432 <    }
433 <
434 <    return torsion;
435 < }    
436 <
437 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) {
547 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol,
548 >                                                  CutoffGroupStamp* stamp,
549 >                                                  LocalIndexManager* localIndexMan) {
550      int nAtoms;
551      CutoffGroup* cg;
552      Atom* atom;
# Line 442 | Line 554 | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecu
554      
555      nAtoms = stamp->getNMembers();
556      for (int i =0; i < nAtoms; ++i) {
557 <        atom = mol->getAtomAt(stamp->getMember(i));
558 <        assert(atom);
559 <        cg->addAtom(atom);
557 >      atom = mol->getAtomAt(stamp->getMemberAt(i));
558 >      assert(atom);
559 >      cg->addAtom(atom);
560      }
561 <
561 >    
562 >    //set the local index of this cutoffGroup, global index will be set later
563 >    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
564 >    
565      return cg;
566 < }    
567 <
568 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) {
566 >  }    
567 >  
568 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom,
569 >                                                  LocalIndexManager* localIndexMan) {
570      CutoffGroup* cg;
571      cg  = new CutoffGroup();
572      cg->addAtom(atom);
573 +
574 +    //set the local index of this cutoffGroup, global index will be set later
575 +    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
576 +
577      return cg;
578 < }
578 >  }
579  
580 < void MoleculeCreator::createConstraintPair(Molecule* mol) {
580 >  void MoleculeCreator::createConstraintPair(Molecule* mol) {
581  
582      //add bond constraints
583      Molecule::BondIterator bi;
584      Bond* bond;
585 +    ConstraintPair* cPair;
586 +
587      for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) {
588          
589 <        BondType* bt = bond->getBondType();
589 >      BondType* bt = bond->getBondType();
590  
591 <        //class Parent1 {};
592 <        //class Child1 : public Parent {};
471 <        //class Child2 : public Parent {};
472 <        //Child1* ch1 = new Child1();
473 <        //Child2* ch2 = dynamic_cast<Child2*>(ch1);
474 <        //the dynamic_cast is succeed in above line. A compiler bug?        
591 >      if (typeid(FixedBondType) == typeid(*bt)) {
592 >        FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
593  
594 <        if (typeid(FixedBondType) == typeid(*bt)) {
595 <            FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
596 <
597 <            ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
598 <            ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
599 <            ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength());
482 <            mol->addConstraintPair(consPair);
483 <        }
594 >        ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
595 >        ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
596 >        cPair = new ConstraintPair(consElemA, consElemB,
597 >                                   fbt->getEquilibriumBondLength(), false);
598 >        mol->addConstraintPair(cPair);
599 >      }
600      }
601  
602      //rigidbody -- rigidbody constraint is not support yet
603 < }
603 >  }
604  
605 < void MoleculeCreator::createConstraintElem(Molecule* mol) {
605 >  void MoleculeCreator::createConstraintElem(Molecule* mol) {
606  
607      ConstraintPair* consPair;
608      Molecule::ConstraintPairIterator cpi;
609      std::set<StuntDouble*> sdSet;
610 <    for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) {
610 >    for (consPair = mol->beginConstraintPair(cpi); consPair != NULL;
611 >         consPair = mol->nextConstraintPair(cpi)) {
612  
613 <        StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
614 <        if (sdSet.find(sdA) == sdSet.end()){
615 <            sdSet.insert(sdA);
616 <            mol->addConstraintElem(new ConstraintElem(sdA));
617 <        }
618 <
619 <        StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
620 <        if (sdSet.find(sdB) == sdSet.end()){
621 <            sdSet.insert(sdB);
622 <            mol->addConstraintElem(new ConstraintElem(sdB));
623 <        }
507 <        
613 >      StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
614 >      if (sdSet.find(sdA) == sdSet.end()){
615 >        sdSet.insert(sdA);
616 >        mol->addConstraintElem(new ConstraintElem(sdA));
617 >      }
618 >      
619 >      StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
620 >      if (sdSet.find(sdB) == sdSet.end()){
621 >        sdSet.insert(sdB);
622 >        mol->addConstraintElem(new ConstraintElem(sdB));
623 >      }      
624      }
625 <
625 >  }
626   }
511    
512 }

Comparing trunk/src/brains/MoleculeCreator.cpp (property svn:keywords):
Revision 403 by gezelter, Tue Mar 8 21:06:49 2005 UTC vs.
Revision 1979 by gezelter, Sat Apr 5 20:56:01 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines