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 981 by gezelter, Mon Jan 26 18:52:42 2004 UTC vs.
Revision 1216 by gezelter, Tue Jun 1 21:44:54 2004 UTC

# Line 14 | Line 14 | MoleculeStamp::MoleculeStamp(){
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;
# Line 21 | Line 23 | MoleculeStamp::MoleculeStamp(){
23    bends = NULL;
24    torsions = NULL;
25    rigidBodies = NULL;
26 +  cutoffGroups = NULL;
27  
28    have_name = 0;
29    have_atoms = 0;
# Line 28 | Line 31 | MoleculeStamp::MoleculeStamp(){
31    have_bends = 0;
32    have_torsions = 0;
33    have_rigidbodies = 0;
34 +  have_cutoffgroups = 0;
35  
36   }
37  
# Line 39 | Line 43 | MoleculeStamp::~MoleculeStamp(){
43    if( rigidBodies != NULL ) {
44      for( i=0; i<n_rigidbodies; i++ ) delete rigidBodies[i];
45    }
46 +  delete[] rigidBodies;
47 +
48 +  if( cutoffGroups != NULL ) {
49 +    for( i=0; i<n_cutoffgroups; i++ ) delete cutoffGroups[i];
50 +  }
51 +  delete[] cutoffGroups;
52    
53    if( atoms != NULL ){
54      for( i=0; i<n_atoms; i++ ) delete atoms[i];
55    }
56 +  delete[] atoms;
57    
58    if( bonds != NULL ){
59      for( i=0; i<n_bonds; i++ ) delete bonds[i];
60    }
61 +  delete[] bonds;
62    
63    if( bends != NULL ){
64      for( i=0; i<n_bends; i++ ) delete bends[i];
65    }
66 +  delete[] bends;
67    
68    if( torsions != NULL ){
69      for( i=0; i<n_torsions; i++ ) delete torsions[i];
70    }
71 +  delete[] torsions;
72    
73 +
74 +
75 +
76   }
77  
78   char* MoleculeStamp::assignString( char* lhs, char* rhs ){
# Line 150 | Line 167 | char* MoleculeStamp::assignDouble( char* lhs, double r
167      for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
168    }
169  
170 +  else if( !strcmp( lhs, "nCutoffGroups" ) ){
171 +    n_cutoffgroups = (int)rhs;
172 +
173 +    if( have_cutoffgroups ){
174 +      sprintf( errMsg,
175 +               "MoleculeStamp error, n_cutoffgroups already declared for"
176 +               " molecule: %s\n",
177 +               name );
178 +      return strdup( errMsg );
179 +    }
180 +    have_cutoffgroups = 1;
181 +    cutoffGroups = new CutoffGroupStamp*[n_cutoffgroups];
182 +    for( i=0; i<n_cutoffgroups; i++ ) cutoffGroups[i] = NULL;
183 +  }
184 +  
185    else{
186      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
187      else unhandled->add( lhs, rhs );
# Line 226 | Line 258 | char*  MoleculeStamp::assignInt( char* lhs, int rhs ){
258  
259      if( have_rigidbodies ){
260        sprintf( errMsg,
261 <               "RigidBodyStamp error, n_rigidbodies already declared for"
261 >               "MoleculeStamp error, n_rigidbodies already declared for"
262                 " molecule: %s\n",
263                 name);
264        return strdup( errMsg );
# Line 235 | Line 267 | char*  MoleculeStamp::assignInt( char* lhs, int rhs ){
267      rigidBodies = new RigidBodyStamp*[n_rigidbodies];
268      for( i=0; i<n_rigidbodies; i++ ) rigidBodies[i] = NULL;
269    }
270 +  else if( !strcmp( lhs, "nCutoffGroups" ) ){
271 +    n_cutoffgroups = rhs;
272 +
273 +    if( have_cutoffgroups ){
274 +      sprintf( errMsg,
275 +               "MoleculeStamp error, n_cutoffgroups already declared for"
276 +               " molecule: %s\n",
277 +               name);
278 +      return strdup( errMsg );
279 +    }
280 +    have_cutoffgroups = 1;
281 +    cutoffGroups = new CutoffGroupStamp*[n_cutoffgroups];
282 +    for( i=0; i<n_cutoffgroups; i++ ) cutoffGroups[i] = NULL;
283 +  }
284    else{
285      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
286      else unhandled->add( lhs, rhs );
# Line 246 | Line 292 | char* MoleculeStamp::addAtom( AtomStamp* the_atom, int
292   char* MoleculeStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
293    
294    if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
295 <  else{
295 >  else {
296      if( have_atoms ){
297        sprintf( errMsg, "MoleculeStamp error, %d out of nAtoms range",
298                 atomIndex );
# Line 264 | Line 310 | char* MoleculeStamp::addRigidBody( RigidBodyStamp* the
310    
311    if( have_rigidbodies && rigidBodyIndex < n_rigidbodies )
312      rigidBodies[rigidBodyIndex] = the_rigidbody;
313 <  else{
313 >  else {
314      if( have_rigidbodies ){
315        sprintf( errMsg, "MoleculeStamp error, %d out of nRigidBodies range",
316                 rigidBodyIndex );
# Line 272 | Line 318 | char* MoleculeStamp::addRigidBody( RigidBodyStamp* the
318      }
319      else return strdup("MoleculeStamp error, nRigidBodies not given before"
320                         " first rigidBody declaration." );
321 +  }
322 +  
323 +  return NULL;
324 + }
325 +
326 + char* MoleculeStamp::addCutoffGroup( CutoffGroupStamp* the_cutoffgroup,
327 +                                     int cutoffGroupIndex ){
328 +  
329 +  if( have_cutoffgroups && cutoffGroupIndex < n_cutoffgroups )
330 +    cutoffGroups[cutoffGroupIndex] = the_cutoffgroup;
331 +  else {
332 +    if( have_cutoffgroups ){
333 +      sprintf( errMsg, "MoleculeStamp error, %d out of nCutoffGroups range",
334 +               cutoffGroupIndex );
335 +      return strdup( errMsg );
336 +    }
337 +    else return strdup("MoleculeStamp error, nCutoffGroups not given before"
338 +                       " first CutoffGroup declaration." );
339    }
340    
341    return NULL;
# Line 332 | Line 396 | char* MoleculeStamp::checkMe( void ){
396   char* MoleculeStamp::checkMe( void ){
397    
398    int i;
399 <  short int no_atom, no_rigidbody;
399 >  short int no_atom, no_rigidbody, no_cutoffgroup;
400  
337  // Fix for Rigid Bodies!!!  Molecules may not have any atoms that
338  // they know about.  They might have only rigid bodies (which then
339  // know about the atoms!
340  
341
401    if( !have_name ) return strdup( "MoleculeStamp error. Molecule's name"
402                                    " was not given.\n" );
403 <
404 <  if( !have_rigidbodies && !have_atoms ){
405 <    return strdup( "MoleculeStamp error. Molecule contains no atoms or RigidBodies." );
403 >  
404 >  if( !have_atoms ){
405 >    return strdup( "MoleculeStamp error. Molecule contains no atoms." );
406    }
407    
408    no_rigidbody = 0;
# Line 358 | Line 417 | char* MoleculeStamp::checkMe( void ){
417      return strdup( errMsg );
418    }
419  
420 +  no_cutoffgroup = 0;
421 +  for( i=0; i<n_cutoffgroups; i++ ){
422 +    if( cutoffGroups[i] == NULL ) no_cutoffgroup = 1;
423 +  }
424 +
425 +  if( no_cutoffgroup ){
426 +    sprintf( errMsg,
427 +             "MoleculeStamp error. Not all of the CutoffGroups were"
428 +             " declared in molecule \"%s\".\n", name );
429 +    return strdup( errMsg );
430 +  }
431 +  
432    no_atom = 0;
433    for( i=0; i<n_atoms; i++ ){
434      if( atoms[i] == NULL ) no_atom = 1;
# Line 370 | Line 441 | char* MoleculeStamp::checkMe( void ){
441      return strdup( errMsg );
442    }
443  
444 <  return NULL;
445 < }
446 <
447 <
448 < int MoleculeStamp::getTotAtoms() {
449 <  int total_atoms;
450 <  int i;
451 <
452 <  total_atoms = n_atoms;
382 <
383 <  if( rigidBodies != NULL ) {
384 <    for( i=0; i<n_rigidbodies; i++ )
385 <      total_atoms += rigidBodies[i]->getNAtoms();
444 >  n_integrable = n_atoms;
445 >  for (i = 0; i < n_rigidbodies; i++)
446 >    n_integrable = n_integrable - rigidBodies[i]->getNMembers() + 1; //rigidbody is an integrable object
447 >  
448 >  if (n_integrable <= 0 || n_integrable > n_atoms) {
449 >    sprintf( errMsg,
450 >             "MoleculeStamp error. n_integrable is either <= 0 or"
451 >             " greater than n_atoms in molecule \"%s\".\n", name );
452 >    return strdup( errMsg );
453    }
454  
455 <  return total_atoms;
456 < }
390 <  
455 >  return NULL;
456 > }  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines