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