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 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2046 by gezelter, Tue Dec 2 22:11:04 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 "types/DirectionalAtomType.hpp"
56 > #include "primitives/GhostTorsion.hpp"
57 > #include "types/AtomType.hpp"
58   #include "types/FixedBondType.hpp"
59 + #include "types/BondTypeParser.hpp"
60 + #include "types/BendTypeParser.hpp"
61 + #include "types/TorsionTypeParser.hpp"
62 + #include "types/InversionTypeParser.hpp"
63   #include "utils/simError.h"
64   #include "utils/StringUtils.hpp"
65  
66 < namespace oopse {
66 > namespace OpenMD {
67 >  
68 >  Molecule* MoleculeCreator::createMolecule(ForceField* ff,
69 >                                            MoleculeStamp *molStamp,
70 >                                            int stampId, int globalIndex,
71 >                                            LocalIndexManager* localIndexMan) {
72 >    Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getName(),
73 >                                 molStamp->getRegion() );
74  
62 Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp,
63    int stampId, int globalIndex, LocalIndexManager* localIndexMan) {
64
65    Molecule* mol = new Molecule(stampId, globalIndex, molStamp->getID());
66    
75      //create atoms
76      Atom* atom;
77      AtomStamp* currentAtomStamp;
78      int nAtom = molStamp->getNAtoms();
79      for (int i = 0; i < nAtom; ++i) {
80 <        currentAtomStamp = molStamp->getAtom(i);
81 <        atom = createAtom(ff, mol, currentAtomStamp, localIndexMan);
82 <        mol->addAtom(atom);
80 >      currentAtomStamp = molStamp->getAtomStamp(i);
81 >      atom = createAtom(ff, mol, currentAtomStamp, localIndexMan);
82 >      mol->addAtom(atom);
83      }
84  
85      //create rigidbodies
# Line 80 | Line 88 | Molecule* MoleculeCreator::createMolecule(ForceField*
88      int nRigidbodies = molStamp->getNRigidBodies();
89  
90      for (int i = 0; i < nRigidbodies; ++i) {
91 <        currentRigidBodyStamp = molStamp->getRigidBody(i);
92 <        rb = createRigidBody(molStamp, mol, currentRigidBodyStamp, localIndexMan);
93 <        mol->addRigidBody(rb);
91 >      currentRigidBodyStamp = molStamp->getRigidBodyStamp(i);
92 >      rb = createRigidBody(molStamp, mol, currentRigidBodyStamp,
93 >                           localIndexMan);
94 >      mol->addRigidBody(rb);
95      }
96 <
96 >    
97      //create bonds
98      Bond* bond;
99      BondStamp* currentBondStamp;
100      int nBonds = molStamp->getNBonds();
101  
102      for (int i = 0; i < nBonds; ++i) {
103 <        currentBondStamp = molStamp->getBond(i);
104 <        bond = createBond(ff, mol, currentBondStamp);
105 <        mol->addBond(bond);
103 >      currentBondStamp = molStamp->getBondStamp(i);        
104 >      bond = createBond(ff, mol, currentBondStamp, localIndexMan);
105 >      mol->addBond(bond);
106      }
107  
108      //create bends
# Line 101 | Line 110 | Molecule* MoleculeCreator::createMolecule(ForceField*
110      BendStamp* currentBendStamp;
111      int nBends = molStamp->getNBends();
112      for (int i = 0; i < nBends; ++i) {
113 <        currentBendStamp = molStamp->getBend(i);
114 <        bend = createBend(ff, mol, currentBendStamp);
115 <        mol->addBend(bend);
113 >      currentBendStamp = molStamp->getBendStamp(i);
114 >      bend = createBend(ff, mol, currentBendStamp, localIndexMan);
115 >      mol->addBend(bend);
116      }
117  
118      //create torsions
# Line 111 | Line 120 | Molecule* MoleculeCreator::createMolecule(ForceField*
120      TorsionStamp* currentTorsionStamp;
121      int nTorsions = molStamp->getNTorsions();
122      for (int i = 0; i < nTorsions; ++i) {
123 <        currentTorsionStamp = molStamp->getTorsion(i);
124 <        torsion = createTorsion(ff, mol, currentTorsionStamp);
125 <        mol->addTorsion(torsion);
123 >      currentTorsionStamp = molStamp->getTorsionStamp(i);
124 >      torsion = createTorsion(ff, mol, currentTorsionStamp, localIndexMan);
125 >      mol->addTorsion(torsion);
126      }
127  
128 +    //create inversions
129 +    Inversion* inversion;
130 +    InversionStamp* currentInversionStamp;
131 +    int nInversions = molStamp->getNInversions();
132 +    for (int i = 0; i < nInversions; ++i) {
133 +      currentInversionStamp = molStamp->getInversionStamp(i);
134 +      inversion = createInversion(ff, mol, currentInversionStamp,
135 +                                  localIndexMan);
136 +      if (inversion != NULL ) {
137 +        mol->addInversion(inversion);
138 +      }
139 +    }
140 +
141      //create cutoffGroups
142      CutoffGroup* cutoffGroup;
143      CutoffGroupStamp* currentCutoffGroupStamp;
144      int nCutoffGroups = molStamp->getNCutoffGroups();
145      for (int i = 0; i < nCutoffGroups; ++i) {
146 <        currentCutoffGroupStamp = molStamp->getCutoffGroup(i);
147 <        cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp);
148 <        mol->addCutoffGroup(cutoffGroup);
146 >      currentCutoffGroupStamp = molStamp->getCutoffGroupStamp(i);
147 >      cutoffGroup = createCutoffGroup(mol, currentCutoffGroupStamp,
148 >                                      localIndexMan);
149 >      mol->addCutoffGroup(cutoffGroup);
150      }
151  
152      //every free atom is a cutoff group    
153 <    std::set<Atom*> allAtoms;
154 <     Molecule::AtomIterator ai;
153 >    std::vector<Atom*> freeAtoms;
154 >    std::vector<Atom*>::iterator ai;
155 >    std::vector<Atom*>::iterator fai;
156  
157      //add all atoms into allAtoms set
158 <    for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
159 <        allAtoms.insert(atom);
158 >    for(atom = mol->beginAtom(fai); atom != NULL; atom = mol->nextAtom(fai)) {
159 >      freeAtoms.push_back(atom);
160      }
161  
162      Molecule::CutoffGroupIterator ci;
163      CutoffGroup* cg;
140    std::set<Atom*> cutoffAtoms;    
164      
165 <    //add all of the atoms belong to cutoff groups into cutoffAtoms set
166 <    for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
167 <
168 <        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
169 <            cutoffAtoms.insert(atom);
170 <        }
171 <
165 >    for (cg = mol->beginCutoffGroup(ci); cg != NULL;
166 >         cg = mol->nextCutoffGroup(ci)) {
167 >      
168 >      for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
169 >        //erase the atoms belong to cutoff groups from freeAtoms vector
170 >        freeAtoms.erase(std::remove(freeAtoms.begin(), freeAtoms.end(), atom),
171 >                        freeAtoms.end());
172 >      }      
173      }      
174      
175 <    //find all free atoms (which do not belong to cutoff groups)  
176 <    //performs the "difference" operation from set theory,  the output range contains a copy of every
177 <    //element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in
178 <    //[cutoffAtoms.begin(), cutoffAtoms.end()).
179 <    std::vector<Atom*> freeAtoms;    
180 <    std::set_difference(allAtoms.begin(), allAtoms.end(), cutoffAtoms.begin(), cutoffAtoms.end(),
181 <                            std::back_inserter(freeAtoms));
175 >    // loop over the free atoms and then create one cutoff group for
176 >    // every single free atom
177 >    
178 >    for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) {
179 >      cutoffGroup = createCutoffGroup(mol, *fai, localIndexMan);
180 >      mol->addCutoffGroup(cutoffGroup);
181 >    }
182  
183 <    if (freeAtoms.size() != allAtoms.size() - cutoffAtoms.size()) {
184 <        //Some atoms in rigidAtoms are not in allAtoms, something must be wrong
161 <        sprintf(painCave.errMsg, "Atoms in cutoff groups are not in the atom list of the same molecule");
183 >    //create bonded constraintPairs:
184 >    createConstraintPair(mol);
185  
186 +    //create non-bonded constraintPairs
187 +    for (int i = 0; i < molStamp->getNConstraints(); ++i) {
188 +      ConstraintStamp* cStamp = molStamp->getConstraintStamp(i);
189 +      Atom* atomA;
190 +      Atom* atomB;
191 +      
192 +      atomA = mol->getAtomAt(cStamp->getA());
193 +      atomB = mol->getAtomAt(cStamp->getB());
194 +      assert( atomA && atomB );
195 +      
196 +      RealType distance;
197 +      bool printConstraintForce = false;
198 +
199 +      if (!cStamp->haveConstrainedDistance()) {
200 +        sprintf(painCave.errMsg,
201 +                "Constraint Error: A non-bond constraint was specified\n"
202 +                "\twithout providing a value for the constrainedDistance.\n");
203          painCave.isFatal = 1;
204 <        simError();        
204 >        simError();      
205 >      } else {
206 >        distance = cStamp->getConstrainedDistance();
207 >      }
208 >
209 >      if (cStamp->havePrintConstraintForce()) {
210 >        printConstraintForce = cStamp->getPrintConstraintForce();
211 >      }
212 >    
213 >      ConstraintElem* consElemA = new ConstraintElem(atomA);
214 >      ConstraintElem* consElemB = new ConstraintElem(atomB);
215 >      ConstraintPair* cPair = new ConstraintPair(consElemA, consElemB, distance,
216 >                                                 printConstraintForce);
217 >      mol->addConstraintPair(cPair);
218      }
219  
220 <    //loop over the free atoms and then create one cutoff group for every single free atom
168 <    std::vector<Atom*>::iterator fai;
220 >    // now create the constraint elements:
221  
170    for (fai = freeAtoms.begin(); fai != freeAtoms.end(); ++fai) {
171        cutoffGroup = createCutoffGroup(mol, *fai);
172        mol->addCutoffGroup(cutoffGroup);
173    }
174    //create constraints
175    createConstraintPair(mol);
222      createConstraintElem(mol);
223      
224 +    // Does this molecule stamp define a total constrained charge value?
225 +    // If so, let the created molecule know about it.
226 +
227 +    if (molStamp->haveConstrainTotalCharge() ) {
228 +      mol->setConstrainTotalCharge( molStamp->getConstrainTotalCharge() );
229 +    }
230 +
231      //the construction of this molecule is finished
232      mol->complete();
233 <
233 >    
234      return mol;
235 < }    
235 >  }    
236  
237  
238 < Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp,
239 <                                                                  LocalIndexManager* localIndexMan) {
238 >  Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol,
239 >                                    AtomStamp* stamp,
240 >                                    LocalIndexManager* localIndexMan) {
241      AtomType * atomType;
242      Atom* atom;
243  
244      atomType =  ff->getAtomType(stamp->getType());
245 <
245 >    
246      if (atomType == NULL) {
247 <        sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
248 <                   stamp->getType());
247 >      sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]",
248 >              stamp->getType().c_str());
249  
250 <        painCave.isFatal = 1;
251 <        simError();
250 >      painCave.isFatal = 1;
251 >      simError();
252      }
253 <    
253 >
254      //below code still have some kind of hard-coding smell
255      if (atomType->isDirectional()){
202    
203        DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
204        
205        if (dAtomType == NULL) {
206            sprintf(painCave.errMsg, "Can not cast AtomType to DirectionalAtomType");
256  
257 <            painCave.isFatal = 1;
258 <            simError();
259 <        }
211 <
212 <        DirectionalAtom* dAtom;
213 <        dAtom = new DirectionalAtom(dAtomType);
214 <        atom = dAtom;    
257 >      DirectionalAtom* dAtom;
258 >      dAtom = new DirectionalAtom(atomType);
259 >      atom = dAtom;    
260      }
261      else{
262 <        atom = new Atom(atomType);
262 >      atom = new Atom(atomType);
263      }
264  
265      atom->setLocalIndex(localIndexMan->getNextAtomIndex());
266  
267      return atom;
268 < }
269 <
270 < RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol,
271 <                                                                                    RigidBodyStamp* rbStamp,
272 <                                                                                    LocalIndexManager* localIndexMan) {
268 >  }
269 >  
270 >  RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp,
271 >                                              Molecule* mol,
272 >                                              RigidBodyStamp* rbStamp,
273 >                                              LocalIndexManager* localIndexMan){
274      Atom* atom;
275      int nAtoms;
276      Vector3d refCoor;
# Line 233 | Line 279 | RigidBody* MoleculeCreator::createRigidBody(MoleculeSt
279      RigidBody* rb = new RigidBody();
280      nAtoms = rbStamp->getNMembers();    
281      for (int i = 0; i < nAtoms; ++i) {
282 <        //rbStamp->getMember(i) return the local index of current atom inside the molecule.
283 <        //It is not the same as local index of atom which is the index of atom at DataStorage class
284 <        atom = mol->getAtomAt(rbStamp->getMember(i));
285 <        atomStamp= molStamp->getAtom(rbStamp->getMember(i));    
286 <        rb->addAtom(atom, atomStamp);
282 >      //rbStamp->getMember(i) return the local index of current atom
283 >      //inside the molecule.  It is not the same as local index of
284 >      //atom which is the index of atom at DataStorage class
285 >      atom = mol->getAtomAt(rbStamp->getMemberAt(i));
286 >      atomStamp= molStamp->getAtomStamp(rbStamp->getMemberAt(i));    
287 >      rb->addAtom(atom, atomStamp);
288      }
289  
290 <    //after all of the atoms are added, we need to calculate the reference coordinates
290 >    //after all of the atoms are added, we need to calculate the
291 >    //reference coordinates
292      rb->calcRefCoords();
293  
294      //set the local index of this rigid body, global index will be set later
295      rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex());
296  
297 <    //the rule for naming rigidbody MoleculeName_RB_Integer
298 <    //The first part is the name of the molecule
299 <    //The second part is alway fixed as "RB"
300 <    //The third part is the index of the rigidbody defined in meta-data file
301 <    //For example, Butane_RB_0 is a valid rigid body name of butane molecule
302 <    /**@todo replace itoa by lexi_cast */
303 <    rb->setType(mol->getType() + "_RB_" + toString(mol->getNRigidBodies()));
304 <    
297 >    // The rule for naming a rigidbody is: MoleculeName_RB_Integer
298 >    // The first part is the name of the molecule
299 >    // The second part is always fixed as "RB"
300 >    // The third part is the index of the rigidbody defined in meta-data file
301 >    // For example, Butane_RB_0 is a valid rigid body name of butane molecule
302 >
303 >    std::string s = OpenMD_itoa(mol->getNRigidBodies(), 10);
304 >    rb->setType(mol->getType() + "_RB_" + s.c_str());
305      return rb;
306 < }    
306 >  }    
307  
308 < Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) {
309 <    BondType* bondType;
308 >  Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol,
309 >                                    BondStamp* stamp,
310 >                                    LocalIndexManager* localIndexMan) {
311 >    BondTypeParser btParser;        
312 >    BondType* bondType = NULL;
313      Atom* atomA;
314      Atom* atomB;
315 <
315 >    
316      atomA = mol->getAtomAt(stamp->getA());
317      atomB = mol->getAtomAt(stamp->getB());
267
268    assert( atomA && atomB);
318      
319 <    bondType = ff->getBondType(atomA->getType(), atomB->getType());
319 >    assert( atomA && atomB);
320  
321 <    if (bondType == NULL) {
273 <        sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
274 <                   atomA->getType().c_str(),
275 <                   atomB->getType().c_str());
321 >    if (stamp->hasOverride()) {
322  
323 +      try {
324 +        bondType = btParser.parseTypeAndPars(stamp->getOverrideType(),
325 +                                             stamp->getOverridePars() );
326 +      }
327 +      catch( OpenMDException e) {
328 +        sprintf(painCave.errMsg, "MoleculeCreator Error: %s "
329 +                "for molecule %s\n",
330 +                e.what(), mol->getType().c_str() );
331          painCave.isFatal = 1;
332          simError();
333 <    }
280 <    return new Bond(atomA, atomB, bondType);    
281 < }    
333 >      }
334  
335 < Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) {
336 <    bool isGhostBend = false;
285 <    int ghostIndex;
335 >    } else {
336 >      bondType = ff->getBondType(atomA->getType(), atomB->getType());
337  
338 <    
339 <    //
340 <    if (stamp->haveExtras()){
341 <        LinkedAssign* extras = stamp->getExtras();
291 <        LinkedAssign* currentExtra = extras;
292 <
293 <        while (currentExtra != NULL){
294 <            if (!strcmp(currentExtra->getlhs(), "ghostVectorSource")){
295 <                switch (currentExtra->getType()){
296 <                case 0:
297 <                    ghostIndex = currentExtra->getInt();
298 <                    isGhostBend = true;
299 <                    break;
300 <
301 <                default:
302 <                sprintf(painCave.errMsg,
303 <                "SimSetup Error: ghostVectorSource must be an int.\n");
304 <                painCave.isFatal = 1;
305 <                simError();
306 <                }
307 <            } else{
308 <                sprintf(painCave.errMsg,
309 <                "SimSetup Error: unhandled bend assignment:\n");
310 <                painCave.isFatal = 1;
311 <                simError();
312 <            }
313 <            currentExtra = currentExtra->getNext();
314 <        }
338 >      if (bondType == NULL) {
339 >        sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]",
340 >                atomA->getType().c_str(),
341 >                atomB->getType().c_str());
342          
343 +        painCave.isFatal = 1;
344 +        simError();
345 +      }
346      }
347 +    
348 +    Bond* bond = new Bond(atomA, atomB, bondType);
349  
350 <    if (isGhostBend) {
350 >    //set the local index of this bond, the global index will be set later
351 >    bond->setLocalIndex(localIndexMan->getNextBondIndex());
352  
353 <        int indexA = stamp->getA();
354 <        int indexB= stamp->getB();
353 >    // The rule for naming a bond is: MoleculeName_Bond_Integer
354 >    // The first part is the name of the molecule
355 >    // The second part is always fixed as "Bond"
356 >    // The third part is the index of the bond defined in meta-data file
357 >    // For example, Butane_bond_0 is a valid Bond name in a butane molecule
358  
359 <        assert(indexA != indexB);
359 >    std::string s = OpenMD_itoa(mol->getNBonds(), 10);
360 >    bond->setName(mol->getType() + "_Bond_" + s.c_str());
361 >    return bond;    
362 >  }    
363 >  
364 >  Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol,
365 >                                    BendStamp* stamp,
366 >                                    LocalIndexManager* localIndexMan) {
367 >    BendTypeParser btParser;
368 >    BendType* bendType = NULL;
369 >    Bend* bend = NULL;
370 >    
371 >    std::vector<int> bendAtoms = stamp->getMembers();
372 >    if (bendAtoms.size() == 3) {
373 >      Atom* atomA = mol->getAtomAt(bendAtoms[0]);
374 >      Atom* atomB = mol->getAtomAt(bendAtoms[1]);
375 >      Atom* atomC = mol->getAtomAt(bendAtoms[2]);
376 >      
377 >      assert( atomA && atomB && atomC );
378  
379 <        int normalIndex;
326 <        if (indexA == ghostIndex) {
327 <            normalIndex = indexB;
328 <        } else if (indexB == ghostIndex) {
329 <            normalIndex = indexA;
330 <        }
379 >      if (stamp->hasOverride()) {
380          
381 <        Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
382 <        DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
383 <        if (ghostAtom == NULL) {
335 <            sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
336 <            painCave.isFatal = 1;
337 <            simError();
381 >        try {
382 >          bendType = btParser.parseTypeAndPars(stamp->getOverrideType(),
383 >                                               stamp->getOverridePars() );
384          }
385 <                
386 <        BendType* bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(), "GHOST");
387 <
388 <        if (bendType == NULL) {
389 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
390 <                       normalAtom->getType().c_str(),
391 <                       ghostAtom->getType().c_str(),
392 <                       "GHOST");
393 <
394 <            painCave.isFatal = 1;
395 <            simError();
396 <        }
397 <        
398 <        return new GhostBend(normalAtom, ghostAtom, bendType);      
385 >        catch( OpenMDException e) {
386 >          sprintf(painCave.errMsg, "MoleculeCreator Error: %s "
387 >                  "for molecule %s\n",
388 >                  e.what(), mol->getType().c_str() );
389 >          painCave.isFatal = 1;
390 >          simError();
391 >        }
392 >      } else {
393 >        
394 >        bendType = ff->getBendType(atomA->getType().c_str(),
395 >                                             atomB->getType().c_str(),
396 >                                             atomC->getType().c_str());
397 >      
398 >        if (bendType == NULL) {
399 >          sprintf(painCave.errMsg,
400 >                  "Can not find Matching Bend Type for[%s, %s, %s]",
401 >                  atomA->getType().c_str(),
402 >                  atomB->getType().c_str(),
403 >                  atomC->getType().c_str());
404 >          
405 >          painCave.isFatal = 1;
406 >          simError();
407 >        }
408 >      }
409 >      
410 >      bend = new Bend(atomA, atomB, atomC, bendType);
411 >      
412 >    } else if ( bendAtoms.size() == 2 && stamp->haveGhostVectorSource()) {
413 >      int ghostIndex = stamp->getGhostVectorSource();
414 >      int normalIndex = ghostIndex != bendAtoms[0] ?
415 >        bendAtoms[0] : bendAtoms[1];
416 >      Atom* normalAtom = mol->getAtomAt(normalIndex) ;        
417 >      DirectionalAtom* ghostAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(ghostIndex));
418 >      if (ghostAtom == NULL) {
419 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
420 >        painCave.isFatal = 1;
421 >        simError();
422 >      }
423  
424 <    } else {
425 <            
426 <        Atom* atomA = mol->getAtomAt(stamp->getA());
427 <        Atom* atomB = mol->getAtomAt(stamp->getB());
428 <        Atom* atomC = mol->getAtomAt(stamp->getC());
424 >      if (stamp->hasOverride()) {
425 >        
426 >        try {
427 >          bendType = btParser.parseTypeAndPars(stamp->getOverrideType(),
428 >                                               stamp->getOverridePars() );
429 >        }
430 >        catch( OpenMDException e) {
431 >          sprintf(painCave.errMsg, "MoleculeCreator Error: %s "
432 >                  "for molecule %s\n",
433 >                  e.what(), mol->getType().c_str() );
434 >          painCave.isFatal = 1;
435 >          simError();
436 >        }
437 >      } else {
438 >      
439 >        bendType = ff->getBendType(normalAtom->getType(), ghostAtom->getType(),
440 >                                   "GHOST");
441 >        
442 >        if (bendType == NULL) {
443 >          sprintf(painCave.errMsg,
444 >                  "Can not find Matching Bend Type for[%s, %s, %s]",
445 >                  normalAtom->getType().c_str(),
446 >                  ghostAtom->getType().c_str(),
447 >                  "GHOST");
448 >          
449 >          painCave.isFatal = 1;
450 >          simError();
451 >        }
452 >      }
453 >      
454 >      bend = new GhostBend(normalAtom, ghostAtom, bendType);      
455 >      
456 >    }
457 >    
458 >    //set the local index of this bend, the global index will be set later
459 >    bend->setLocalIndex(localIndexMan->getNextBendIndex());
460 >    
461 >    // The rule for naming a bend is: MoleculeName_Bend_Integer
462 >    // The first part is the name of the molecule
463 >    // The second part is always fixed as "Bend"
464 >    // The third part is the index of the bend defined in meta-data file
465 >    // For example, Butane_Bend_0 is a valid Bend name in a butane molecule
466 >    
467 >    std::string s = OpenMD_itoa(mol->getNBends(), 10);
468 >    bend->setName(mol->getType() + "_Bend_" + s.c_str());    
469 >    return bend;
470 >  }    
471  
472 <        assert( atomA && atomB && atomC);
472 >  Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol,
473 >                                          TorsionStamp* stamp,
474 >                                          LocalIndexManager* localIndexMan) {
475 >
476 >    TorsionTypeParser ttParser;
477 >    TorsionType* torsionType = NULL;
478 >    Torsion* torsion = NULL;
479 >
480 >    std::vector<int> torsionAtoms = stamp->getMembers();
481 >    if (torsionAtoms.size() < 3) {
482 >        return torsion;
483 >    }
484 >
485 >    Atom* atomA = mol->getAtomAt(torsionAtoms[0]);
486 >    Atom* atomB = mol->getAtomAt(torsionAtoms[1]);
487 >    Atom* atomC = mol->getAtomAt(torsionAtoms[2]);
488 >
489 >    if (torsionAtoms.size() == 4) {
490 >      Atom* atomD = mol->getAtomAt(torsionAtoms[3]);
491 >
492 >      assert(atomA && atomB && atomC && atomD );
493 >
494 >      if (stamp->hasOverride()) {
495          
496 <        BendType* bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType());
496 >        try {
497 >          torsionType = ttParser.parseTypeAndPars(stamp->getOverrideType(),
498 >                                                  stamp->getOverridePars() );
499 >        }
500 >        catch( OpenMDException e) {
501 >          sprintf(painCave.errMsg, "MoleculeCreator Error: %s "
502 >                  "for molecule %s\n",
503 >                  e.what(), mol->getType().c_str() );
504 >          painCave.isFatal = 1;
505 >          simError();
506 >        }
507 >      } else {
508  
509 <        if (bendType == NULL) {
510 <            sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]",
511 <                       atomA->getType().c_str(),
512 <                       atomB->getType().c_str(),
513 <                       atomC->getType().c_str());
509 >        
510 >        torsionType = ff->getTorsionType(atomA->getType(),
511 >                                         atomB->getType(),
512 >                                         atomC->getType(),
513 >                                         atomD->getType());
514 >        if (torsionType == NULL) {
515 >          sprintf(painCave.errMsg,
516 >                  "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
517 >                  atomA->getType().c_str(),
518 >                  atomB->getType().c_str(),
519 >                  atomC->getType().c_str(),
520 >                  atomD->getType().c_str());
521 >          
522 >          painCave.isFatal = 1;
523 >          simError();
524 >        }
525 >      }
526 >      
527 >      torsion = new Torsion(atomA, atomB, atomC, atomD, torsionType);      
528 >    } else {
529 >      
530 >      DirectionalAtom* dAtom = dynamic_cast<DirectionalAtom*>(mol->getAtomAt(stamp->getGhostVectorSource()));
531 >      if (dAtom == NULL) {
532 >        sprintf(painCave.errMsg, "Can not cast Atom to DirectionalAtom");
533 >        painCave.isFatal = 1;
534 >        simError();
535 >      }        
536  
537 <            painCave.isFatal = 1;
538 <            simError();
537 >      if (stamp->hasOverride()) {
538 >        
539 >        try {
540 >          torsionType = ttParser.parseTypeAndPars(stamp->getOverrideType(),
541 >                                                  stamp->getOverridePars() );
542          }
543 +        catch( OpenMDException e) {
544 +          sprintf(painCave.errMsg, "MoleculeCreator Error: %s "
545 +                  "for molecule %s\n",
546 +                  e.what(), mol->getType().c_str() );
547 +          painCave.isFatal = 1;
548 +          simError();
549 +        }
550 +      } else {              
551 +        torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
552 +                                         atomC->getType(), "GHOST");
553 +      
554 +        if (torsionType == NULL) {
555 +          sprintf(painCave.errMsg,
556 +                  "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
557 +                  atomA->getType().c_str(),
558 +                  atomB->getType().c_str(),
559 +                  atomC->getType().c_str(),
560 +                  "GHOST");
561 +          
562 +          painCave.isFatal = 1;
563 +          simError();
564 +        }
565 +      }
566  
567 <        return new Bend(atomA, atomB, atomC, bendType);      
567 >      torsion = new GhostTorsion(atomA, atomB, dAtom, torsionType);              
568      }
376 }    
569  
570 < Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) {
571 <    TorsionType* torsionType;
572 <    Atom* atomA;
573 <    Atom* atomB;
574 <    Atom* atomC;
575 <    Atom* atomD;
570 >    //set the local index of this torsion, the global index will be set later
571 >    torsion->setLocalIndex(localIndexMan->getNextTorsionIndex());
572 >    
573 >    // The rule for naming a torsion is: MoleculeName_Torsion_Integer
574 >    // The first part is the name of the molecule
575 >    // The second part is always fixed as "Torsion"
576 >    // The third part is the index of the torsion defined in meta-data file
577 >    // For example, Butane_Torsion_0 is a valid Torsion name in a
578 >    // butane molecule
579  
580 <    atomA = mol->getAtomAt(stamp->getA());
581 <    atomB = mol->getAtomAt(stamp->getB());
582 <    atomC = mol->getAtomAt(stamp->getC());
583 <    atomD = mol->getAtomAt(stamp->getD());
580 >    std::string s = OpenMD_itoa(mol->getNTorsions(), 10);
581 >    torsion->setName(mol->getType() + "_Torsion_" + s.c_str());
582 >    return torsion;
583 >  }    
584  
585 <    assert(atomA && atomB && atomC && atomD);
585 >  Inversion* MoleculeCreator::createInversion(ForceField* ff, Molecule* mol,
586 >                                              InversionStamp* stamp,
587 >                                              LocalIndexManager* localIndexMan) {
588 >
589 >    InversionTypeParser itParser;
590 >    InversionType* inversionType = NULL;
591 >    Inversion* inversion = NULL;
592      
593 <    torsionType = ff->getTorsionType(atomA->getType(), atomB->getType(),
594 <                                                       atomC->getType(), atomD->getType());
593 >    int center = stamp->getCenter();
594 >    std::vector<int> satellites = stamp->getSatellites();
595 >    if (satellites.size() != 3) {
596 >        return inversion;
597 >    }
598  
599 <    if (torsionType == NULL) {
600 <        sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]",
601 <                   atomA->getType().c_str(),
602 <                   atomB->getType().c_str(),
603 <                   atomC->getType().c_str(),
604 <                   atomD->getType().c_str());
599 >    Atom* atomA = mol->getAtomAt(center);
600 >    Atom* atomB = mol->getAtomAt(satellites[0]);
601 >    Atom* atomC = mol->getAtomAt(satellites[1]);
602 >    Atom* atomD = mol->getAtomAt(satellites[2]);
603 >      
604 >    assert(atomA && atomB && atomC && atomD);
605  
606 +    if (stamp->hasOverride()) {
607 +      
608 +      try {
609 +        inversionType = itParser.parseTypeAndPars(stamp->getOverrideType(),
610 +                                                  stamp->getOverridePars() );
611 +      }
612 +      catch( OpenMDException e) {
613 +        sprintf(painCave.errMsg, "MoleculeCreator Error: %s "
614 +                "for molecule %s\n",
615 +                e.what(), mol->getType().c_str() );
616          painCave.isFatal = 1;
617          simError();
618 +      }
619 +    } else {
620 +      
621 +      inversionType = ff->getInversionType(atomA->getType(),
622 +                                           atomB->getType(),
623 +                                           atomC->getType(),
624 +                                           atomD->getType());
625 +      
626 +      if (inversionType == NULL) {
627 +        sprintf(painCave.errMsg,
628 +                "No Matching Inversion Type for[%s, %s, %s, %s]\n"
629 +                "\t(May not be a problem: not all inversions are parametrized)\n",
630 +                atomA->getType().c_str(),
631 +                atomB->getType().c_str(),
632 +                atomC->getType().c_str(),
633 +                atomD->getType().c_str());
634 +        
635 +        painCave.isFatal = 0;
636 +        painCave.severity = OPENMD_INFO;
637 +        simError();
638 +      }
639      }
640 <    
641 <    return new Torsion(atomA, atomB, atomC, atomD, torsionType);      
642 < }    
640 >    if (inversionType != NULL) {
641 >      
642 >      inversion = new Inversion(atomA, atomB, atomC, atomD, inversionType);
643 >      
644 >      // set the local index of this inversion, the global index will
645 >      // be set later
646 >      inversion->setLocalIndex(localIndexMan->getNextInversionIndex());
647 >      
648 >      // The rule for naming an inversion is: MoleculeName_Inversion_Integer
649 >      // The first part is the name of the molecule
650 >      // The second part is always fixed as "Inversion"
651 >      // The third part is the index of the inversion defined in meta-data file
652 >      // For example, Benzene_Inversion_0 is a valid Inversion name in a
653 >      // Benzene molecule
654  
655 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) {
655 >      std::string s = OpenMD_itoa(mol->getNInversions(), 10);
656 >      inversion->setName(mol->getType() + "_Inversion_" + s.c_str());
657 >      return inversion;
658 >    } else {
659 >      return NULL;
660 >    }
661 >  }
662 >  
663 >
664 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol,
665 >                                                  CutoffGroupStamp* stamp,
666 >                                                  LocalIndexManager* localIndexMan) {
667      int nAtoms;
668      CutoffGroup* cg;
669      Atom* atom;
# Line 414 | Line 671 | CutoffGroup* MoleculeCreator::createCutoffGroup(Molecu
671      
672      nAtoms = stamp->getNMembers();
673      for (int i =0; i < nAtoms; ++i) {
674 <        atom = mol->getAtomAt(stamp->getMember(i));
675 <        assert(atom);
676 <        cg->addAtom(atom);
674 >      atom = mol->getAtomAt(stamp->getMemberAt(i));
675 >      assert(atom);
676 >      cg->addAtom(atom);
677      }
678 <
678 >    
679 >    //set the local index of this cutoffGroup, global index will be set later
680 >    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
681 >    
682      return cg;
683 < }    
684 <
685 < CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom) {
683 >  }    
684 >  
685 >  CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule * mol, Atom* atom,
686 >                                                  LocalIndexManager* localIndexMan) {
687      CutoffGroup* cg;
688      cg  = new CutoffGroup();
689      cg->addAtom(atom);
690 +
691 +    //set the local index of this cutoffGroup, global index will be set later
692 +    cg->setLocalIndex(localIndexMan->getNextCutoffGroupIndex());
693 +
694      return cg;
695 < }
695 >  }
696  
697 < void MoleculeCreator::createConstraintPair(Molecule* mol) {
697 >  void MoleculeCreator::createConstraintPair(Molecule* mol) {
698  
699      //add bond constraints
700      Molecule::BondIterator bi;
701      Bond* bond;
702 +    ConstraintPair* cPair;
703 +
704      for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) {
705          
706 <        BondType* bt = bond->getBondType();
706 >      BondType* bt = bond->getBondType();
707  
708 <        //class Parent1 {};
709 <        //class Child1 : public Parent {};
443 <        //class Child2 : public Parent {};
444 <        //Child1* ch1 = new Child1();
445 <        //Child2* ch2 = dynamic_cast<Child2*>(ch1);
446 <        //the dynamic_cast is succeed in above line. A compiler bug?        
708 >      if (typeid(FixedBondType) == typeid(*bt)) {
709 >        FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
710  
711 <        if (typeid(FixedBondType) == typeid(*bt)) {
712 <            FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt);
713 <
714 <            ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
715 <            ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
716 <            ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength());
454 <            mol->addConstraintPair(consPair);
455 <        }
711 >        ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA());
712 >        ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB());            
713 >        cPair = new ConstraintPair(consElemA, consElemB,
714 >                                   fbt->getEquilibriumBondLength(), false);
715 >        mol->addConstraintPair(cPair);
716 >      }
717      }
718  
719      //rigidbody -- rigidbody constraint is not support yet
720 < }
720 >  }
721  
722 < void MoleculeCreator::createConstraintElem(Molecule* mol) {
722 >  void MoleculeCreator::createConstraintElem(Molecule* mol) {
723  
724      ConstraintPair* consPair;
725      Molecule::ConstraintPairIterator cpi;
726      std::set<StuntDouble*> sdSet;
727 <    for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) {
727 >    for (consPair = mol->beginConstraintPair(cpi); consPair != NULL;
728 >         consPair = mol->nextConstraintPair(cpi)) {
729  
730 <        StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
731 <        if (sdSet.find(sdA) == sdSet.end()){
732 <            sdSet.insert(sdA);
733 <            mol->addConstraintElem(new ConstraintElem(sdA));
734 <        }
735 <
736 <        StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
737 <        if (sdSet.find(sdB) == sdSet.end()){
738 <            sdSet.insert(sdB);
739 <            mol->addConstraintElem(new ConstraintElem(sdB));
740 <        }
479 <        
730 >      StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble();            
731 >      if (sdSet.find(sdA) == sdSet.end()){
732 >        sdSet.insert(sdA);
733 >        mol->addConstraintElem(new ConstraintElem(sdA));
734 >      }
735 >      
736 >      StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble();            
737 >      if (sdSet.find(sdB) == sdSet.end()){
738 >        sdSet.insert(sdB);
739 >        mol->addConstraintElem(new ConstraintElem(sdB));
740 >      }      
741      }
742 <
742 >  }
743   }
483    
484 }

Comparing trunk/src/brains/MoleculeCreator.cpp (property svn:keywords):
Revision 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2046 by gezelter, Tue Dec 2 22:11:04 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines