1 |
#include <cstdlib> |
2 |
#include <cstdio> |
3 |
|
4 |
#include "MakeStamps.hpp" |
5 |
#include "MoleculeStamp.hpp" |
6 |
#include "simError.h" |
7 |
#ifdef IS_MPI |
8 |
#include "mpiBASS.h" |
9 |
#endif // is_mpi |
10 |
|
11 |
LinkedMolStamp::~LinkedMolStamp(){ |
12 |
if( mol_stamp != NULL ) delete mol_stamp; |
13 |
if( next != NULL ) delete next; |
14 |
} |
15 |
|
16 |
MoleculeStamp* LinkedMolStamp::match( char* id ){ |
17 |
|
18 |
if( mol_stamp != NULL ){ |
19 |
|
20 |
if(!strcmp( mol_stamp->getID(), id )) return mol_stamp; |
21 |
|
22 |
if( next != NULL ) return next->match( id ); |
23 |
} |
24 |
|
25 |
return NULL; |
26 |
} |
27 |
|
28 |
MakeStamps::MakeStamps(){ |
29 |
|
30 |
int i; |
31 |
|
32 |
my_mols = new LinkedMolStamp*[hash_size]; |
33 |
for( i=0; i<hash_size; i++ ){ |
34 |
my_mols[i] = NULL; |
35 |
} |
36 |
|
37 |
} |
38 |
|
39 |
MakeStamps::~MakeStamps(){ |
40 |
|
41 |
int i; |
42 |
|
43 |
for( i=0; i<hash_size; i++ ){ |
44 |
if( my_mols[i] != NULL ) delete my_mols[i]; |
45 |
} |
46 |
delete[] my_mols; |
47 |
} |
48 |
|
49 |
int MakeStamps::hash( char* text ){ |
50 |
|
51 |
register unsigned short int i = 0; // loop counter |
52 |
int key = 0; // the hash key |
53 |
|
54 |
while( text[i] != '\0' ){ |
55 |
|
56 |
key = ( ( key << hash_shift ) + text[i] ) % hash_size; |
57 |
|
58 |
i++; |
59 |
} |
60 |
|
61 |
if( key < 0 ){ |
62 |
|
63 |
// if the key is less than zero, we've had an overflow error |
64 |
|
65 |
sprintf( painCave.errMsg, |
66 |
"There has been an overflow error in the MakeStamps hash key."); |
67 |
painCave.isFatal = 1; |
68 |
simError(); |
69 |
#ifdef IS_MPI |
70 |
if( painCave.isEventLoop ){ |
71 |
if( worldRank == 0 ) mpiInterfaceExit(); |
72 |
} |
73 |
#endif //is_mpi |
74 |
} |
75 |
|
76 |
return key; |
77 |
} |
78 |
|
79 |
MoleculeStamp* MakeStamps::getMolecule( char* the_id ){ |
80 |
int key; |
81 |
|
82 |
key = hash( the_id ); |
83 |
if( my_mols[key] != NULL ){ |
84 |
return my_mols[key]->match( the_id ); |
85 |
} |
86 |
|
87 |
return NULL; |
88 |
} |
89 |
|
90 |
void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){ |
91 |
|
92 |
int key; |
93 |
LinkedMolStamp* linked_mol; |
94 |
|
95 |
key = hash( the_stamp->getID() ); |
96 |
|
97 |
linked_mol = new LinkedMolStamp; |
98 |
linked_mol->setStamp( the_stamp ); |
99 |
linked_mol->setNext( my_mols[key] ); |
100 |
|
101 |
my_mols[key] = linked_mol; |
102 |
} |
103 |
|
104 |
|
105 |
int MakeStamps::newMolecule( event* the_event ){ |
106 |
|
107 |
current_mol = new MoleculeStamp; |
108 |
return 1; |
109 |
} |
110 |
|
111 |
int MakeStamps::moleculeAssign( event* the_event ){ |
112 |
|
113 |
switch( the_event->evt.asmt.asmt_type ){ |
114 |
|
115 |
case STRING: |
116 |
the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs, |
117 |
the_event->evt.asmt.rhs.sval ); |
118 |
break; |
119 |
|
120 |
case DOUBLE: |
121 |
the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs, |
122 |
the_event->evt.asmt.rhs.dval ); |
123 |
break; |
124 |
|
125 |
case INT: |
126 |
the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs, |
127 |
the_event->evt.asmt.rhs.ival ); |
128 |
break; |
129 |
|
130 |
default: |
131 |
the_event->err_msg = strdup( "MakeStamp error. Invalid molecule" |
132 |
" assignment type" ); |
133 |
return 0; |
134 |
break; |
135 |
} |
136 |
if( the_event->err_msg != NULL ) return 0; |
137 |
return 1; |
138 |
} |
139 |
|
140 |
int MakeStamps::moleculeEnd( event* the_event ){ |
141 |
|
142 |
the_event->err_msg = current_mol->checkMe(); |
143 |
// if err_msg is set, then something is wrong |
144 |
if( the_event->err_msg != NULL ) return 0; |
145 |
|
146 |
addMolStamp( current_mol ); |
147 |
return 1; |
148 |
} |
149 |
|
150 |
int MakeStamps::newAtom( event* the_event ){ |
151 |
|
152 |
current_atom = new AtomStamp; |
153 |
|
154 |
the_event->err_msg = current_mol->addAtom( current_atom, |
155 |
the_event->evt.blk_index ); |
156 |
if( the_event->err_msg != NULL ) return 0; |
157 |
return 1; |
158 |
} |
159 |
|
160 |
int MakeStamps::atomPosition( event* the_event ){ |
161 |
|
162 |
current_atom->setPosition( the_event->evt.pos.x, |
163 |
the_event->evt.pos.y, |
164 |
the_event->evt.pos.z ); |
165 |
return 1; |
166 |
} |
167 |
|
168 |
|
169 |
int MakeStamps::atomOrientation( event* the_event ){ |
170 |
|
171 |
current_atom->setOrientation( the_event->evt.ornt.x, |
172 |
the_event->evt.ornt.y, |
173 |
the_event->evt.ornt.z ); |
174 |
return 1; |
175 |
} |
176 |
|
177 |
int MakeStamps::atomAssign( event* the_event ){ |
178 |
|
179 |
switch( the_event->evt.asmt.asmt_type ){ |
180 |
|
181 |
case STRING: |
182 |
the_event->err_msg = |
183 |
current_atom->assignString( the_event->evt.asmt.lhs, |
184 |
the_event->evt.asmt.rhs.sval ); |
185 |
if( the_event->err_msg != NULL ) return 0; |
186 |
return 1; |
187 |
break; |
188 |
|
189 |
case DOUBLE: |
190 |
the_event->err_msg = |
191 |
current_atom->assignDouble( the_event->evt.asmt.lhs, |
192 |
the_event->evt.asmt.rhs.dval ); |
193 |
if( the_event->err_msg != NULL ) return 0; |
194 |
return 1; |
195 |
break; |
196 |
|
197 |
case INT: |
198 |
the_event->err_msg = |
199 |
current_atom->assignInt( the_event->evt.asmt.lhs, |
200 |
the_event->evt.asmt.rhs.ival ); |
201 |
if( the_event->err_msg != NULL ) return 0; |
202 |
return 1; |
203 |
break; |
204 |
|
205 |
default: |
206 |
the_event->err_msg = strdup( "MakeStamp error. Invalid atom" |
207 |
" assignment type" ); |
208 |
return 0; |
209 |
break; |
210 |
} |
211 |
return 0; |
212 |
} |
213 |
|
214 |
int MakeStamps::atomEnd( event* the_event ){ |
215 |
|
216 |
the_event->err_msg = current_atom->checkMe(); |
217 |
if( the_event->err_msg != NULL ) return 0; |
218 |
|
219 |
return 1; |
220 |
} |
221 |
|
222 |
int MakeStamps::newBond( event* the_event ){ |
223 |
|
224 |
current_bond = new BondStamp; |
225 |
|
226 |
the_event->err_msg = current_mol->addBond( current_bond, |
227 |
the_event->evt.blk_index ); |
228 |
if( the_event->err_msg != NULL ) return 0; |
229 |
|
230 |
return 1; |
231 |
} |
232 |
|
233 |
int MakeStamps::bondAssign( event* the_event ){ |
234 |
|
235 |
switch( the_event->evt.asmt.asmt_type ){ |
236 |
|
237 |
case STRING: |
238 |
current_bond->assignString( the_event->evt.asmt.lhs, |
239 |
the_event->evt.asmt.rhs.sval ); |
240 |
return 1; |
241 |
break; |
242 |
|
243 |
case DOUBLE: |
244 |
current_bond->assignDouble( the_event->evt.asmt.lhs, |
245 |
the_event->evt.asmt.rhs.dval ); |
246 |
return 1; |
247 |
break; |
248 |
|
249 |
case INT: |
250 |
current_bond->assignInt( the_event->evt.asmt.lhs, |
251 |
the_event->evt.asmt.rhs.ival ); |
252 |
return 1; |
253 |
break; |
254 |
|
255 |
default: |
256 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bond" |
257 |
" assignment type" ); |
258 |
return 0; |
259 |
break; |
260 |
} |
261 |
return 0; |
262 |
} |
263 |
|
264 |
int MakeStamps::bondMember( event* the_event ){ |
265 |
|
266 |
current_bond->members( the_event->evt.mbr.a, |
267 |
the_event->evt.mbr.b ); |
268 |
return 1; |
269 |
} |
270 |
|
271 |
int MakeStamps::bondConstraint( event* the_event ){ |
272 |
|
273 |
current_bond->constrain( the_event->evt.cnstr ); |
274 |
return 1; |
275 |
} |
276 |
|
277 |
int MakeStamps::bondEnd( event* the_event ){ |
278 |
|
279 |
the_event->err_msg = current_bond->checkMe(); |
280 |
if( the_event->err_msg != NULL ) return 0; |
281 |
|
282 |
return 1; |
283 |
} |
284 |
|
285 |
int MakeStamps::newBend( event* the_event ){ |
286 |
|
287 |
current_bend = new BendStamp; |
288 |
|
289 |
the_event->err_msg = current_mol->addBend( current_bend, |
290 |
the_event->evt.blk_index ); |
291 |
if( the_event->err_msg != NULL ) return 0; |
292 |
|
293 |
return 1; |
294 |
} |
295 |
|
296 |
int MakeStamps::bendAssign( event* the_event ){ |
297 |
|
298 |
switch( the_event->evt.asmt.asmt_type ){ |
299 |
|
300 |
case STRING: |
301 |
current_bend->assignString( the_event->evt.asmt.lhs, |
302 |
the_event->evt.asmt.rhs.sval ); |
303 |
return 1; |
304 |
break; |
305 |
|
306 |
case DOUBLE: |
307 |
current_bend->assignDouble( the_event->evt.asmt.lhs, |
308 |
the_event->evt.asmt.rhs.dval ); |
309 |
return 1; |
310 |
break; |
311 |
|
312 |
case INT: |
313 |
current_bend->assignInt( the_event->evt.asmt.lhs, |
314 |
the_event->evt.asmt.rhs.ival ); |
315 |
return 1; |
316 |
break; |
317 |
|
318 |
default: |
319 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bend" |
320 |
" assignment type" ); |
321 |
return 0; |
322 |
break; |
323 |
} |
324 |
return 0; |
325 |
} |
326 |
|
327 |
int MakeStamps::bendMember( event* the_event ){ |
328 |
|
329 |
current_bend->members( the_event->evt.mbr.a, |
330 |
the_event->evt.mbr.b, |
331 |
the_event->evt.mbr.c ); |
332 |
return 1; |
333 |
} |
334 |
|
335 |
int MakeStamps::bendConstraint( event* the_event ){ |
336 |
|
337 |
current_bend->constrain( the_event->evt.cnstr ); |
338 |
return 1; |
339 |
} |
340 |
|
341 |
int MakeStamps::bendEnd( event* the_event ){ |
342 |
|
343 |
the_event->err_msg = current_bend->checkMe(); |
344 |
if( the_event->err_msg != NULL ) return 0; |
345 |
|
346 |
return 1; |
347 |
} |
348 |
|
349 |
int MakeStamps::newTorsion( event* the_event ){ |
350 |
|
351 |
current_torsion = new TorsionStamp; |
352 |
|
353 |
the_event->err_msg = current_mol->addTorsion( current_torsion, |
354 |
the_event->evt.blk_index ); |
355 |
if( the_event->err_msg != NULL ) return 0; |
356 |
|
357 |
return 1; |
358 |
} |
359 |
|
360 |
int MakeStamps::torsionAssign( event* the_event ){ |
361 |
|
362 |
switch( the_event->evt.asmt.asmt_type ){ |
363 |
|
364 |
case STRING: |
365 |
current_torsion->assignString( the_event->evt.asmt.lhs, |
366 |
the_event->evt.asmt.rhs.sval ); |
367 |
return 1; |
368 |
break; |
369 |
|
370 |
case DOUBLE: |
371 |
current_torsion->assignDouble( the_event->evt.asmt.lhs, |
372 |
the_event->evt.asmt.rhs.dval ); |
373 |
return 1; |
374 |
break; |
375 |
|
376 |
case INT: |
377 |
current_torsion->assignInt( the_event->evt.asmt.lhs, |
378 |
the_event->evt.asmt.rhs.ival ); |
379 |
return 1; |
380 |
break; |
381 |
|
382 |
default: |
383 |
the_event->err_msg = strdup( "MakeStamp error. Invalid torsion" |
384 |
" assignment type" ); |
385 |
return 0; |
386 |
break; |
387 |
} |
388 |
return 0; |
389 |
} |
390 |
|
391 |
int MakeStamps::torsionMember( event* the_event ){ |
392 |
|
393 |
current_torsion->members( the_event->evt.mbr.a, |
394 |
the_event->evt.mbr.b, |
395 |
the_event->evt.mbr.c, |
396 |
the_event->evt.mbr.d ); |
397 |
return 1; |
398 |
} |
399 |
|
400 |
int MakeStamps::torsionConstraint( event* the_event ){ |
401 |
|
402 |
current_torsion->constrain( the_event->evt.cnstr ); |
403 |
return 1; |
404 |
} |
405 |
|
406 |
int MakeStamps::torsionEnd( event* the_event ){ |
407 |
|
408 |
the_event->err_msg = current_torsion->checkMe(); |
409 |
if( the_event->err_msg != NULL ) return 0; |
410 |
|
411 |
return 1; |
412 |
} |