1 |
/* |
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, molStamp->getID()); |
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 |
if (bondType == NULL) { |
121 |
sprintf(painCave.errMsg, "Can not find Matching Atom Type for[%s]", |
122 |
stamp->getType()); |
123 |
|
124 |
painCave.isFatal = 1; |
125 |
simError(); |
126 |
} |
127 |
|
128 |
//below code still have some kind of hard-coding smell |
129 |
if (stamp->haveOrientation()){ |
130 |
DirectionalAtom* dAtom; |
131 |
double phi; |
132 |
double theta; |
133 |
double psi; |
134 |
|
135 |
dAtom = new DirectionalAtom(atomType); |
136 |
|
137 |
// Directional Atoms have standard unit vectors which are oriented |
138 |
// in space using the three Euler angles. We assume the standard |
139 |
// unit vector was originally along the z axis below. |
140 |
|
141 |
phi = stamp->getEulerPhi() * M_PI / 180.0; |
142 |
theta = stamp->getEulerTheta() * M_PI / 180.0; |
143 |
psi = stamp->getEulerPsi()* M_PI / 180.0; |
144 |
|
145 |
dAtom->setUnitFrameFromEuler(phi, theta, psi); |
146 |
atom = dAtom; |
147 |
} |
148 |
else{ |
149 |
atom = new Atom(atomType); |
150 |
} |
151 |
|
152 |
atom->setLocalIndex(localIndexMan->getNextAtomIndex()); |
153 |
} |
154 |
|
155 |
RigidBody* MoleculeCreator::createRigidBody(MoleculeStamp *molStamp, Molecule* mol, |
156 |
RigidBodyStamp* rbStamp, |
157 |
LocalIndexManager* localIndexMan) { |
158 |
Atom* atom; |
159 |
int nAtoms; |
160 |
Vector3d refCoor; |
161 |
AtomStamp* atomStamp; |
162 |
|
163 |
nAtoms = molStamp->getNMembers(); |
164 |
|
165 |
RigidBody* rb = new RigidBody(); |
166 |
|
167 |
for (int i = 0; i < nAtoms; ++i) { |
168 |
//rbStamp->getMember(i) return the local index of current atom inside the molecule. |
169 |
//It is not the same as local index of atom which is the index of atom at DataStorage class |
170 |
atom = mol->getAtomAt(rbStamp->getMember(i)); |
171 |
atomStamp= molStamp->molStamp->getAtom(rbStamp->getMember(i)); |
172 |
rb->addAtom(atom, atomStamp); |
173 |
} |
174 |
|
175 |
//after all of the atoms are added, we need to calculate the reference coordinates |
176 |
rb->calcRefCoords(); |
177 |
|
178 |
//set the local index of this rigid body, global index will be set later |
179 |
rb->setLocalIndex(localIndexMan->getNextRigidBodyIndex()); |
180 |
|
181 |
//the rule for naming rigidbody MoleculeName_RB_Integer |
182 |
//The first part is the name of the molecule |
183 |
//The second part is alway fixed as "RB" |
184 |
//The third part is the index of the rigidbody defined in meta-data file |
185 |
//For example, Butane_RB_0 is a valid rigid body name of butane molecule |
186 |
rb->setType(mol->getType() + "_RB_" + itoa(mol.getNRigidBodies())); |
187 |
|
188 |
return rb; |
189 |
} |
190 |
|
191 |
Bond* MoleculeCreator::createBond(ForceField* ff, Molecule* mol, BondStamp* stamp) { |
192 |
BondType* bondType; |
193 |
Atom* atomA; |
194 |
Atom* atomB; |
195 |
|
196 |
atomA = mol->getAtomAt(stamp->getA()); |
197 |
atomB = mol->getAtomAt(stamp->getB()); |
198 |
|
199 |
assert( atomA && atomB); |
200 |
|
201 |
bondType = ff->getBondType(atomA, atomB); |
202 |
|
203 |
if (bondType == NULL) { |
204 |
sprintf(painCave.errMsg, "Can not find Matching Bond Type for[%s, %s]", |
205 |
atomA->getType().c_str(), |
206 |
atomB->getType().c_str()); |
207 |
|
208 |
painCave.isFatal = 1; |
209 |
simError(); |
210 |
} |
211 |
return new Bond(atomA, atomB, bondType); |
212 |
} |
213 |
|
214 |
Bend* MoleculeCreator::createBend(ForceField* ff, Molecule* mol, BendStamp* stamp) { |
215 |
BendType* bendType; |
216 |
Atom* atomA; |
217 |
Atom* atomB; |
218 |
Atom* atomC; |
219 |
|
220 |
//need to consider the ghost bend |
221 |
atomA = mol->getAtomAt(stamp->getA()); |
222 |
atomB = mol->getAtomAt(stamp->getB()); |
223 |
atomC = mol->getAtomAt(stamp->getC()); |
224 |
|
225 |
assert( atomA && atomB && atomC); |
226 |
|
227 |
bendType = ff->getBendType(atomA->getType(), atomB->getType(), atomC->getType()); |
228 |
|
229 |
if (bendType == NULL) { |
230 |
sprintf(painCave.errMsg, "Can not find Matching Bend Type for[%s, %s, %s]", |
231 |
atomA->getType().c_str(), |
232 |
atomB->getType().c_str(), |
233 |
atomC->getType().c_str()); |
234 |
|
235 |
painCave.isFatal = 1; |
236 |
simError(); |
237 |
} |
238 |
|
239 |
return new Bond(atomA, atomB, bendType); |
240 |
|
241 |
} |
242 |
|
243 |
Torsion* MoleculeCreator::createTorsion(ForceField* ff, Molecule* mol, TorsionStamp* stamp) { |
244 |
TorsionType* torsionType; |
245 |
Atom* atomA; |
246 |
Atom* atomB; |
247 |
Atom* atomC; |
248 |
Atom* atomD; |
249 |
|
250 |
atomA = mol->getAtomAt(stamp->getA()); |
251 |
atomB = mol->getAtomAt(stamp->getB()); |
252 |
atomC = mol->getAtomAt(stamp->getC()); |
253 |
atomD = mol->getAtomAt(stamp->getD()); |
254 |
|
255 |
assert(atomA && atomB && atomC && atomD); |
256 |
|
257 |
torsionType = ff->getTosionType(atomA->getType(), atomB->getType(), |
258 |
atomC->getType(), atomD->getType()); |
259 |
|
260 |
if (torsionType == NULL) { |
261 |
sprintf(painCave.errMsg, "Can not find Matching Torsion Type for[%s, %s, %s, %s]", |
262 |
atomA->getType().c_str(), |
263 |
atomB->getType().c_str(), |
264 |
atomC->getType().c_str(), |
265 |
atomD->getType().c_str()); |
266 |
|
267 |
painCave.isFatal = 1; |
268 |
simError(); |
269 |
} |
270 |
|
271 |
return new Torsion(atomA, atomB, torsionType); |
272 |
} |
273 |
|
274 |
CutoffGroup* MoleculeCreator::createCutoffGroup(Molecule* mol, CutoffGroupStamp* stamp) { |
275 |
int nAtoms; |
276 |
CutoffGroup* cg; |
277 |
Atom* atom; |
278 |
cg = new CutoffGroup(); |
279 |
|
280 |
nAtoms = stamp->getNMembers(); |
281 |
for (int i =0; i < nAtoms; ++i) { |
282 |
atom = mol->getAtomAt(stamp->getMember(i)); |
283 |
assert(atom); |
284 |
cg->addAtom(atom); |
285 |
} |
286 |
|
287 |
return cg; |
288 |
} |
289 |
|
290 |
//Constraint* MoleculeCreator::createConstraint() { |
291 |
|
292 |
//} |
293 |
|
294 |
} |