ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/MoleculeStamp.cpp
Revision: 1153
Committed: Tue May 11 04:21:52 2004 UTC (20 years, 2 months ago) by gezelter
File size: 11114 byte(s)
Log Message:
BASS changes for adding CutoffGroups to molecules.  Also restructured
the plethora of cutoff radii into one cutoffRadius and one
switchingRadius.  Also removed the useMolecularCutoffs keyword

File Contents

# Content
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <iostream>
5
6 #include "MoleculeStamp.hpp"
7
8 char MoleculeStamp::errMsg[500];
9
10 MoleculeStamp::MoleculeStamp(){
11
12 n_atoms = 0;
13 n_bonds = 0;
14 n_bends = 0;
15 n_torsions = 0;
16 n_rigidbodies = 0;
17 n_cutoffgroups = 0;
18 n_integrable = 0;
19
20 unhandled = NULL;
21 atoms = NULL;
22 bonds = NULL;
23 bends = NULL;
24 torsions = NULL;
25 rigidBodies = NULL;
26 cutoffGroups = NULL;
27
28 have_name = 0;
29 have_atoms = 0;
30 have_bonds = 0;
31 have_bends = 0;
32 have_torsions = 0;
33 have_rigidbodies = 0;
34 have_cutoffgroups = 0;
35
36 }
37
38 MoleculeStamp::~MoleculeStamp(){
39 int i;
40
41 if( unhandled != NULL) delete unhandled;
42
43 if( rigidBodies != NULL ) {
44 for( i=0; i<n_rigidbodies; i++ ) delete rigidBodies[i];
45 }
46
47 if( cutoffGroups != NULL ) {
48 for( i=0; i<n_cutoffgroups; i++ ) delete cutoffGroups[i];
49 }
50
51 if( atoms != NULL ){
52 for( i=0; i<n_atoms; i++ ) delete atoms[i];
53 }
54
55 if( bonds != NULL ){
56 for( i=0; i<n_bonds; i++ ) delete bonds[i];
57 }
58
59 if( bends != NULL ){
60 for( i=0; i<n_bends; i++ ) delete bends[i];
61 }
62
63 if( torsions != NULL ){
64 for( i=0; i<n_torsions; i++ ) delete torsions[i];
65 }
66
67 }
68
69 char* MoleculeStamp::assignString( char* lhs, char* rhs ){
70
71 if( !strcmp( lhs, "name" ) ){
72 strcpy( name, rhs );
73 have_name = 1;
74 }
75 else{
76 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
77 else unhandled->add( lhs, rhs );
78 have_extras = 1;
79 }
80 return NULL;
81 }
82
83 char* MoleculeStamp::assignDouble( char* lhs, double rhs ){
84 int i;
85
86 if( !strcmp( lhs, "nAtoms" ) ){
87 n_atoms = (int)rhs;
88
89 if( have_atoms ){
90 sprintf( errMsg,
91 "MoleculeStamp error, n_atoms already declared"
92 " for molecule: %s\n",
93 name);
94 return strdup( errMsg );
95 }
96 have_atoms = 1;
97 atoms = new AtomStamp*[n_atoms];
98 for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
99 }
100
101 else if( !strcmp( lhs, "nBonds" ) ){
102 n_bonds = (int)rhs;
103
104 if( have_bonds ){
105 sprintf( errMsg,
106 "MoleculeStamp error, n_bonds already declared for"
107 " molecule: %s\n",
108 name);
109 return strdup( errMsg );
110 }
111 have_bonds = 1;
112 bonds = new BondStamp*[n_bonds];
113 for( i=0; i<n_bonds; i++ ) bonds[i] = NULL;
114 }
115
116 else if( !strcmp( lhs, "nBends" ) ){
117 n_bends = (int)rhs;
118
119 if( have_bends ){
120 sprintf( errMsg,
121 "MoleculeStamp error, n_bends already declared for"
122 " molecule: %s\n",
123 name);
124 return strdup( errMsg );
125 }
126 have_bends = 1;
127 bends = new BendStamp*[n_bends];
128 for( i=0; i<n_bends; i++ ) bends[i] = NULL;
129 }
130
131 else if( !strcmp( lhs, "nTorsions" ) ){
132 n_torsions = (int)rhs;
133
134 if( have_torsions ){
135 sprintf( errMsg,
136 "MoleculeStamp error, n_torsions already declared for"
137 " molecule: %s\n",
138 name );
139 return strdup( errMsg );
140 }
141 have_torsions = 1;
142 torsions = new TorsionStamp*[n_torsions];
143 for( i=0; i<n_torsions; i++ ) torsions[i] = NULL;
144 }
145
146 else if( !strcmp( lhs, "nRigidBodies" ) ){
147 n_rigidbodies = (int)rhs;
148
149 if( have_rigidbodies ){
150 sprintf( errMsg,
151 "MoleculeStamp error, n_rigidbodies already declared for"
152 " molecule: %s\n",
153 name );
154 return strdup( errMsg );
155 }
156 have_rigidbodies = 1;
157 rigidBodies = new RigidBodyStamp*[n_rigidbodies];
158 for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
159 }
160
161 else if( !strcmp( lhs, "nCutoffGroups" ) ){
162 n_cutoffgroups = (int)rhs;
163
164 if( have_cutoffgroups ){
165 sprintf( errMsg,
166 "MoleculeStamp error, n_cutoffgroups already declared for"
167 " molecule: %s\n",
168 name );
169 return strdup( errMsg );
170 }
171 have_cutoffgroups = 1;
172 cutoffGroups = new CutoffGroupStamp*[n_cutoffgroups];
173 for( i=0; i<n_cutoffgroups; i++ ) cutoffGroups[i] = NULL;
174 }
175
176 else{
177 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
178 else unhandled->add( lhs, rhs );
179 have_extras = 1;
180 }
181 return NULL;
182 }
183
184 char* MoleculeStamp::assignInt( char* lhs, int rhs ){
185 int i;
186
187 if( !strcmp( lhs, "nAtoms" ) ){
188 n_atoms = rhs;
189
190 if( have_atoms ){
191 sprintf( errMsg,
192 "MoleculeStamp error, n_atoms already declared for"
193 " molecule: %s\n",
194 name);
195 return strdup( errMsg );
196 }
197 have_atoms = 1;
198 atoms = new AtomStamp*[n_atoms];
199 for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
200 }
201
202 else if( !strcmp( lhs, "nBonds" ) ){
203 n_bonds = rhs;
204
205 if( have_bonds ){
206 sprintf( errMsg,
207 "MoleculeStamp error, n_bonds already declared for"
208 " molecule: %s\n",
209 name);
210 return strdup( errMsg );
211 }
212 have_bonds = 1;
213 bonds = new BondStamp*[n_bonds];
214 for( i=0; i<n_bonds; i++ ) bonds[i] = NULL;
215 }
216
217 else if( !strcmp( lhs, "nBends" ) ){
218 n_bends = rhs;
219
220 if( have_bends ){
221 sprintf( errMsg,
222 "MoleculeStamp error, n_bends already declared for"
223 " molecule: %s\n",
224 name );
225 return strdup( errMsg );
226 }
227 have_bends = 1;
228 bends = new BendStamp*[n_bends];
229 for( i=0; i<n_bends; i++ ) bends[i] = NULL;
230 }
231
232 else if( !strcmp( lhs, "nTorsions" ) ){
233 n_torsions = rhs;
234
235 if( have_torsions ){
236 sprintf( errMsg,
237 "MoleculeStamp error, n_torsions already declared for"
238 " molecule: %s\n",
239 name);
240 return strdup( errMsg );
241 }
242 have_torsions = 1;
243 torsions = new TorsionStamp*[n_torsions];
244 for( i=0; i<n_torsions; i++ ) torsions[i] = NULL;
245 }
246
247 else if( !strcmp( lhs, "nRigidBodies" ) ){
248 n_rigidbodies = rhs;
249
250 if( have_rigidbodies ){
251 sprintf( errMsg,
252 "MoleculeStamp error, n_rigidbodies already declared for"
253 " molecule: %s\n",
254 name);
255 return strdup( errMsg );
256 }
257 have_rigidbodies = 1;
258 rigidBodies = new RigidBodyStamp*[n_rigidbodies];
259 for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
260 }
261 else if( !strcmp( lhs, "nCutoffGroups" ) ){
262 n_cutoffgroups = rhs;
263
264 if( have_cutoffgroups ){
265 sprintf( errMsg,
266 "MoleculeStamp error, n_cutoffgroups already declared for"
267 " molecule: %s\n",
268 name);
269 return strdup( errMsg );
270 }
271 have_cutoffgroups = 1;
272 cutoffGroups = new CutoffGroupStamp*[n_cutoffgroups];
273 for( i=0; i<n_cutoffgroups; i++ ) cutoffGroups[i] = NULL;
274 }
275 else{
276 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
277 else unhandled->add( lhs, rhs );
278 have_extras = 1;
279 }
280 return NULL;
281 }
282
283 char* MoleculeStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
284
285 if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
286 else {
287 if( have_atoms ){
288 sprintf( errMsg, "MoleculeStamp error, %d out of nAtoms range",
289 atomIndex );
290 return strdup( errMsg );
291 }
292 else return strdup("MoleculeStamp error, nAtoms not given before"
293 " first atom declaration." );
294 }
295
296 return NULL;
297 }
298
299 char* MoleculeStamp::addRigidBody( RigidBodyStamp* the_rigidbody,
300 int rigidBodyIndex ){
301
302 if( have_rigidbodies && rigidBodyIndex < n_rigidbodies )
303 rigidBodies[rigidBodyIndex] = the_rigidbody;
304 else {
305 if( have_rigidbodies ){
306 sprintf( errMsg, "MoleculeStamp error, %d out of nRigidBodies range",
307 rigidBodyIndex );
308 return strdup( errMsg );
309 }
310 else return strdup("MoleculeStamp error, nRigidBodies not given before"
311 " first rigidBody declaration." );
312 }
313
314 return NULL;
315 }
316
317 char* MoleculeStamp::addCutoffGroup( CutoffGroupStamp* the_cutoffgroup,
318 int cutoffGroupIndex ){
319
320 if( have_cutoffgroups && cutoffGroupIndex < n_cutoffgroups )
321 cutoffGroups[cutoffGroupIndex] = the_cutoffgroup;
322 else {
323 if( have_cutoffgroups ){
324 sprintf( errMsg, "MoleculeStamp error, %d out of nCutoffGroups range",
325 cutoffGroupIndex );
326 return strdup( errMsg );
327 }
328 else return strdup("MoleculeStamp error, nCutoffGroups not given before"
329 " first CutoffGroup declaration." );
330 }
331
332 return NULL;
333 }
334
335 char* MoleculeStamp::addBond( BondStamp* the_bond, int bondIndex ){
336
337
338 if( have_bonds && bondIndex < n_bonds ) bonds[bondIndex] = the_bond;
339 else{
340 if( have_bonds ){
341 sprintf( errMsg, "MoleculeStamp error, %d out of nBonds range",
342 bondIndex );
343 return strdup( errMsg );
344 }
345 else return strdup("MoleculeStamp error, nBonds not given before"
346 "first bond declaration." );
347 }
348
349 return NULL;
350 }
351
352 char* MoleculeStamp::addBend( BendStamp* the_bend, int bendIndex ){
353
354
355 if( have_bends && bendIndex < n_bends ) bends[bendIndex] = the_bend;
356 else{
357 if( have_bends ){
358 sprintf( errMsg, "MoleculeStamp error, %d out of nBends range",
359 bendIndex );
360 return strdup( errMsg );
361 }
362 else return strdup("MoleculeStamp error, nBends not given before"
363 "first bend declaration." );
364 }
365
366 return NULL;
367 }
368
369 char* MoleculeStamp::addTorsion( TorsionStamp* the_torsion, int torsionIndex ){
370
371
372 if( have_torsions && torsionIndex < n_torsions )
373 torsions[torsionIndex] = the_torsion;
374 else{
375 if( have_torsions ){
376 sprintf( errMsg, "MoleculeStamp error, %d out of nTorsions range",
377 torsionIndex );
378 return strdup( errMsg );
379 }
380 else return strdup("MoleculeStamp error, nTorsions not given before"
381 "first torsion declaration." );
382 }
383
384 return NULL;
385 }
386
387 char* MoleculeStamp::checkMe( void ){
388
389 int i;
390 short int no_atom, no_rigidbody, no_cutoffgroup;
391
392 if( !have_name ) return strdup( "MoleculeStamp error. Molecule's name"
393 " was not given.\n" );
394
395 if( !have_atoms ){
396 return strdup( "MoleculeStamp error. Molecule contains no atoms." );
397 }
398
399 no_rigidbody = 0;
400 for( i=0; i<n_rigidbodies; i++ ){
401 if( rigidBodies[i] == NULL ) no_rigidbody = 1;
402 }
403
404 if( no_rigidbody ){
405 sprintf( errMsg,
406 "MoleculeStamp error. Not all of the RigidBodies were"
407 " declared in molecule \"%s\".\n", name );
408 return strdup( errMsg );
409 }
410
411 no_cutoffgroup = 0;
412 for( i=0; i<n_cutoffgroups; i++ ){
413 if( cutoffGroups[i] == NULL ) no_cutoffgroup = 1;
414 }
415
416 if( no_cutoffgroup ){
417 sprintf( errMsg,
418 "MoleculeStamp error. Not all of the CutoffGroups were"
419 " declared in molecule \"%s\".\n", name );
420 return strdup( errMsg );
421 }
422
423 no_atom = 0;
424 for( i=0; i<n_atoms; i++ ){
425 if( atoms[i] == NULL ) no_atom = 1;
426 }
427
428 if( no_atom ){
429 sprintf( errMsg,
430 "MoleculeStamp error. Not all of the atoms were"
431 " declared in molecule \"%s\".\n", name );
432 return strdup( errMsg );
433 }
434
435 n_integrable = n_atoms;
436 for (i = 0; i < n_rigidbodies; i++)
437 n_integrable = n_integrable - rigidBodies[i]->getNMembers() + 1; //rigidbody is an integrable object
438
439 if (n_integrable <= 0 || n_integrable > n_atoms) {
440 sprintf( errMsg,
441 "MoleculeStamp error. n_integrable is either <= 0 or"
442 " greater than n_atoms in molecule \"%s\".\n", name );
443 return strdup( errMsg );
444 }
445
446 return NULL;
447 }