ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/brains/MoleculeCreator.cpp
Revision: 1719
Committed: Fri Nov 5 23:38:27 2004 UTC (19 years, 9 months ago) by tim
File size: 7690 byte(s)
Log Message:
Fix Exclude class etc.

File Contents

# User Rev Content
1 tim 1719 /*
2     * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3     *
4     * Contact: oopse@oopse.org
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU Lesser General Public License
8     * as published by the Free Software Foundation; either version 2.1
9     * of the License, or (at your option) any later version.
10     * All we ask is that proper credit is given for our work, which includes
11     * - but is not limited to - adding the above copyright notice to the beginning
12     * of your source code files, and to any copyright notice that you may distribute
13     * with programs based on this work.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU Lesser General Public License for more details.
19     *
20     * You should have received a copy of the GNU Lesser General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23     *
24     */
25    
26     /**
27     * @file MoleculeCreator.cpp
28     * @author tlin
29     * @date 11/04/2004
30     * @time 13:44am
31     * @version 1.0
32     */
33    
34     #include "brains/MoleculeCreator.hpp"
35     #include <cassert>
36    
37     namespace oopse {
38    
39     Molecule* MoleculeCreator::createMolecule(ForceField* ff, MoleculeStamp *molStamp, int stampId, int globalIndex) {
40     Molecule* mol = new Molecule(stampId, globalIndex);
41    
42     //create atoms
43     Atom* atom;
44     AtomStamp* currentAtomStamp;
45     int nAtom = molStamp->getNAtoms();
46     for (int i = 0; i < nAtom; ++i) {
47     currentAtomStamp = molStamp->getAtom(i);
48     atom = createAtom(ff, currentAtomStamp);
49     mol->addAtom(atom);
50     }
51    
52     //create rigidbodies
53     RigidBody* rb;
54     RigidBodyStamp * currentRigidBodyStamp;
55     int nRigidbodies = molStamp->getNRigidBodies();
56    
57     for (int i = 0; i < nRigidbodies; ++i) {
58     currentRigidBodyStamp = molStamp->getRigidBody(i);
59     rb = createRigidBody(ff, mol, currentRigidBodyStamp);
60     mol->addRigidBody(rb);
61     }
62    
63     //create bonds
64     Bond* bond;
65     BondStamp* currentBondStamp;
66     int nBonds = molStamp->getNBends();
67    
68     for (int i = 0; i < nBonds; ++i) {
69     currentBondStamp = molStamp->getBend(i);
70     bond = createBond(ff, mol, currentBondStamp);
71     mol->addBond(bond);
72     }
73    
74     //create bends
75     Bend* bend;
76     BendStamp* currentBendStamp;
77     int nBends = molStamp->getNBends();
78     for (int i = 0; i < nBends; ++i) {
79     currentBendStamp = molStamp->getBend(i);
80     bend = createBend(ff, mol, currentBendStamp);
81     mol->addBend(bend);
82     }
83    
84     //create torsions
85     Torsion* torsion;
86     TorsionStamp* currentTorsionStamp;
87     int nTorsions = molStamp->getNTorsions();
88     for (int i = 0; i < nTorsions; ++i) {
89     currentTorsionStamp = molStamp->getTorsion(i);
90     torsion = createTorsion(ff, mol, currentTorsionStamp);
91     mol->addTorsion(torsion);
92     }
93    
94     //create cutoffGroups
95     CutoffGroup* cutoffGroup;
96     CutoffGroupStamp* currentCutoffGroupStamp;
97     int nCutoffGroups = molStamp->getNCutoffGroups();
98     for (int i = 0; i < nCutoffGroups; ++i) {
99     currentCutoffGroupStamp = molStamp->getCutoffGroup(i);
100     cutoffGroup = createCutoffGroup(ff, mol, currentCutoffGroupStamp);
101     mol->addCutoffGroup(cutoffGroup);
102     }
103    
104     //create constraints
105    
106     //the construction of this molecule is finished
107     mol->complete();
108    
109     return mol;
110     }
111    
112    
113     Atom* MoleculeCreator::createAtom(ForceField* ff, Molecule* mol, AtomStamp* stamp,
114     LocalIndexManager* localIndexMan) {
115     AtomType * atomType;
116     Atom* atom;
117    
118     atomType = ff->getAtomType(stamp->getType());
119    
120     //below code still have some kind of hard-coding smell
121     if (stamp->haveOrientation()){
122     DirectionalAtom* dAtom;
123     double phi;
124     double theta;
125     double psi;
126    
127     dAtom = new DirectionalAtom(atomType);
128    
129     // Directional Atoms have standard unit vectors which are oriented
130     // in space using the three Euler angles. We assume the standard
131     // unit vector was originally along the z axis below.
132    
133     phi = stamp->getEulerPhi() * M_PI / 180.0;
134     theta = stamp->getEulerTheta() * M_PI / 180.0;
135     psi = stamp->getEulerPsi()* M_PI / 180.0;
136    
137     dAtom->setUnitFrameFromEuler(phi, theta, psi);
138     atom = dAtom;
139     }
140     else{
141     atom = new Atom(atomType);
142     }
143    
144     atom->setLocalIndex(localIndexMan->getNextAtomIndex());
145     }
146    
147     RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol,
148     RigidBodyStamp* rbStamp,
149     LocalIndexManager* localIndexMan) {
150     Atom* atom;
151     int nAtoms;
152     Vector3d refCoor;
153     AtomStamp* atomStamp;
154    
155     nAtoms = stamp->getNMembers();
156    
157     RigidBody* rb = new RigidBody();
158    
159     for (int i = 0; i < nAtoms; ++i) {
160     //rbStamp->getMember(i) return the local index of current atom inside the molecule.
161     //It is not the same as local index of atom which is the index of atom at DataStorage class
162     atom = mol->getAtomAt(rbStamp->getMember(i));
163     atomStamp= molStamp->molStamp->getAtom(rbStamp->getMember(i));
164     rb->addAtom(atom, atomStamp);
165     }
166    
167     rb->calcRefCoords();
168     rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex());
169     rb->setType(mol->getType() + "_" + itoa(mol.getNRigidBodies()));
170    
171     return rb;
172     }
173    
174     Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) {
175     BondType* bondType;
176     Atom* atomA;
177     Atom* atomB;
178    
179     atomA = mol->getAtomAt(stamp->getA());
180     atomB = mol->getAtomAt(stamp->getB());
181    
182     assert( atomA && atomB);
183    
184     bondType = ff->getBondType(atomA, atomB);
185    
186     return new Bond(atomA, atomB, bondType);
187     }
188    
189     Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) {
190     BendType* benType;
191     Atom* atomA;
192     Atom* atomB;
193     Atom* atomC;
194    
195     //need to consider the ghost bend
196     atomA = mol->getAtomAt(stamp->getA());
197     atomB = mol->getAtomAt(stamp->getB());
198     atomC = mol->getAtomAt(stamp->getC());
199    
200     assert( atomA && atomB && atomC);
201    
202     benType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType());
203    
204     return new Bond(atomA, atomB, benType);
205    
206     }
207    
208     Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) {
209     TorsionType* torsionType;
210     Atom* atomA;
211     Atom* atomB;
212     Atom* atomC;
213     Atom* atomD;
214    
215     atomA = mol->getAtomAt(stamp->getA());
216     atomB = mol->getAtomAt(stamp->getB());
217     atomC = mol->getAtomAt(stamp->getC());
218     atomD = mol->getAtomAt(stamp->getD());
219    
220     assert(atomA && atomB && atomC && atomD);
221    
222     torsionType = ff->getTosionType(atomA->getType(), atomB->getType(),
223     atomC->getType(), atomD->getType());
224    
225     return new Torsion(atomA, atomB, torsionType);
226     }
227    
228     CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) {
229     int nAtoms;
230     CutoffGroup* cg;
231     Atom* atom;
232     cg = new CutoffGroup();
233    
234     nAtoms = stamp->getNMembers();
235     for (int i =0; i < nAtoms; ++i) {
236     atom = mol->getAtomAt(stamp->getMember(i));
237     assert(atom);
238     cg->addAtom(atom);
239     }
240    
241     return cg;
242     }
243    
244     //Constraint* MoleculeCreator::createConstraint() {
245    
246     //}
247    
248     }

Properties

Name Value
svn:executable *