ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/MoleculeStamp.cpp
(Generate patch)

Comparing trunk/OOPSE/libBASS/MoleculeStamp.cpp (file contents):
Revision 378 by mmeineke, Fri Mar 21 17:42:12 2003 UTC vs.
Revision 1153 by gezelter, Tue May 11 04:21:52 2004 UTC

# Line 1 | Line 1
1 < #include <cstdlib>
2 < #include <cstdio>
3 < #include <cstring>
1 > #include <stdlib.h>
2 > #include <stdio.h>
3 > #include <string.h>
4   #include <iostream>
5  
6   #include "MoleculeStamp.hpp"
# Line 13 | Line 13 | MoleculeStamp::MoleculeStamp(){
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  
# Line 32 | Line 39 | 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    }
# Line 74 | Line 89 | char* MoleculeStamp::assignDouble( char* lhs, double r
89      if( have_atoms ){
90        sprintf( errMsg,
91                 "MoleculeStamp error, n_atoms already declared"
92 <               "for molecule: %s\n",
92 >               " for molecule: %s\n",
93                 name);
94        return strdup( errMsg );
95      }
# Line 127 | Line 142 | char* MoleculeStamp::assignDouble( char* lhs, double r
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 );
# Line 197 | Line 243 | char*  MoleculeStamp::assignInt( char* lhs, int rhs ){
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 );
# Line 208 | Line 283 | char* MoleculeStamp::addAtom( AtomStamp* the_atom, int
283   char* MoleculeStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
284    
285    if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
286 <  else{
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." );
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    
# Line 276 | Line 387 | char* MoleculeStamp::checkMe( void ){
387   char* MoleculeStamp::checkMe( void ){
388    
389    int i;
390 <  short int no_atom;
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_name || !have_atoms ){
396 <    if( !have_name ) return strdup( "MoleculeStamp error. Molecule's name"
283 <                                    " was not given.\n" );
284 <    else return strdup( "MoleculeStamp error. Molecule contains no atoms." );
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;
# Line 296 | Line 432 | char* MoleculeStamp::checkMe( void ){
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 < }
447 > }  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines