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 828 by gezelter, Tue Oct 28 16:03:06 2003 UTC vs.
Revision 988 by gezelter, Tue Jan 27 19:37:48 2004 UTC

# Line 13 | Line 13 | MoleculeStamp::MoleculeStamp(){
13    n_bonds = 0;
14    n_bends = 0;
15    n_torsions = 0;
16 +  n_rigidbodies = 0;
17  
18    unhandled = NULL;
19    atoms = NULL;
20    bonds = NULL;
21    bends = NULL;
22    torsions = NULL;
23 +  rigidBodies = NULL;
24  
25    have_name = 0;
26    have_atoms = 0;
27    have_bonds = 0;
28    have_bends = 0;
29    have_torsions = 0;
30 +  have_rigidbodies = 0;
31  
32   }
33  
# Line 32 | Line 35 | MoleculeStamp::~MoleculeStamp(){
35    int i;
36    
37    if( unhandled != NULL) delete unhandled;
38 <
38 >  
39 >  if( rigidBodies != NULL ) {
40 >    for( i=0; i<n_rigidbodies; i++ ) delete rigidBodies[i];
41 >  }
42 >  
43    if( atoms != NULL ){
44      for( i=0; i<n_atoms; i++ ) delete atoms[i];
45    }
# Line 74 | Line 81 | char* MoleculeStamp::assignDouble( char* lhs, double r
81      if( have_atoms ){
82        sprintf( errMsg,
83                 "MoleculeStamp error, n_atoms already declared"
84 <               "for molecule: %s\n",
84 >               " for molecule: %s\n",
85                 name);
86        return strdup( errMsg );
87      }
# Line 127 | Line 134 | char* MoleculeStamp::assignDouble( char* lhs, double r
134      torsions = new TorsionStamp*[n_torsions];
135      for( i=0; i<n_torsions; i++ ) torsions[i] = NULL;
136    }
137 +
138 +  else if( !strcmp( lhs, "nRigidBodies" ) ){
139 +    n_rigidbodies = (int)rhs;
140 +
141 +    if( have_rigidbodies ){
142 +      sprintf( errMsg,
143 +               "MoleculeStamp error, n_rigidbodies already declared for"
144 +               " molecule: %s\n",
145 +               name );
146 +      return strdup( errMsg );
147 +    }
148 +    have_rigidbodies = 1;
149 +    rigidBodies = new RigidBodyStamp*[n_rigidbodies];
150 +    for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
151 +  }
152 +
153    else{
154      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
155      else unhandled->add( lhs, rhs );
# Line 197 | Line 220 | char*  MoleculeStamp::assignInt( char* lhs, int rhs ){
220      torsions = new TorsionStamp*[n_torsions];
221      for( i=0; i<n_torsions; i++ ) torsions[i] = NULL;
222    }
223 +
224 +  else if( !strcmp( lhs, "nRigidBodies" ) ){
225 +    n_rigidbodies = rhs;
226 +
227 +    if( have_rigidbodies ){
228 +      sprintf( errMsg,
229 +               "RigidBodyStamp error, n_rigidbodies already declared for"
230 +               " molecule: %s\n",
231 +               name);
232 +      return strdup( errMsg );
233 +    }
234 +    have_rigidbodies = 1;
235 +    rigidBodies = new RigidBodyStamp*[n_rigidbodies];
236 +    for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
237 +  }
238    else{
239      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
240      else unhandled->add( lhs, rhs );
# Line 215 | Line 253 | char* MoleculeStamp::addAtom( AtomStamp* the_atom, int
253        return strdup( errMsg );
254      }
255      else return strdup("MoleculeStamp error, nAtoms not given before"
256 <                       "first atom declaration." );
256 >                       " first atom declaration." );
257    }
258  
259    return NULL;
260   }
261  
262 + char* MoleculeStamp::addRigidBody( RigidBodyStamp* the_rigidbody,
263 +                                   int rigidBodyIndex ){
264 +  
265 +  if( have_rigidbodies && rigidBodyIndex < n_rigidbodies )
266 +    rigidBodies[rigidBodyIndex] = the_rigidbody;
267 +  else{
268 +    if( have_rigidbodies ){
269 +      sprintf( errMsg, "MoleculeStamp error, %d out of nRigidBodies range",
270 +               rigidBodyIndex );
271 +      return strdup( errMsg );
272 +    }
273 +    else return strdup("MoleculeStamp error, nRigidBodies not given before"
274 +                       " first rigidBody declaration." );
275 +  }
276 +  
277 +  return NULL;
278 + }
279 +
280   char* MoleculeStamp::addBond( BondStamp* the_bond, int bondIndex ){
281    
282    
# Line 276 | Line 332 | char* MoleculeStamp::checkMe( void ){
332   char* MoleculeStamp::checkMe( void ){
333    
334    int i;
335 <  short int no_atom;
335 >  short int no_atom, no_rigidbody;
336 >
337 >  if( !have_name ) return strdup( "MoleculeStamp error. Molecule's name"
338 >                                  " was not given.\n" );
339    
340 <  if( !have_name || !have_atoms ){
341 <    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." );
340 >  if( !have_atoms ){
341 >    return strdup( "MoleculeStamp error. Molecule contains no atoms." );
342    }
343    
344 +  no_rigidbody = 0;
345 +  for( i=0; i<n_rigidbodies; i++ ){
346 +    if( rigidBodies[i] == NULL ) no_rigidbody = 1;
347 +  }
348 +
349 +  if( no_rigidbody ){
350 +    sprintf( errMsg,
351 +             "MoleculeStamp error. Not all of the RigidBodies were"
352 +             " declared in molecule \"%s\".\n", name );
353 +    return strdup( errMsg );
354 +  }
355 +
356    no_atom = 0;
357    for( i=0; i<n_atoms; i++ ){
358      if( atoms[i] == NULL ) no_atom = 1;
# Line 297 | Line 366 | char* MoleculeStamp::checkMe( void ){
366    }
367  
368    return NULL;
369 < }
369 > }  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines