GLYLIB  0.3.0b
deallocate_structures.c
Go to the documentation of this file.
00001 #include "../inc/mylib.h"
00002 #include "../inc/molecules.h"
00003 
00004 /* \file deallocate_structures.c 
00005 \addtogroup MEMORY_MANAGEMENT
00006 \brief   Dealloction routines for structures relevant to main GLYLIB 
00007 structures.
00008 
00009 20100223 BLFoley:  When I got here, I found that these functions all 
00010 seemed to use a variant of:
00011 
00012         if(foo != NULL || foo != 0x0){free(foo);}
00013 
00014 ...but I think that should be && not ||.  So, I'm gonna change them all to
00015 be that way and if everything seems to break, I'll undo it.
00016 
00017 I say this because if a system has some weird notion of what "NULL"
00018 means, possibly because of something a programmer did, then a pointer 
00019 could actually be null, but the compiler would still try to free it,
00020 because it would never check the second case.  And if 0x0 is always
00021 the same as NULL, then why check both?
00022 
00023 I'm also about to expand these considerably to reflect the new structure design.
00024 
00025 Notes regarding these functions:
00026 
00027 * If a structure does not contain any pointers, it can just be freed.
00028 * Structures that contain pointers must have a deallocation function.
00029 * Single-pointers to arrays of simple types (e.g. int) may be freed.
00030 * Single-pointers to arrays of structures might need individual deallocation.
00031 * Double-pointers
00032         * Be very careful before freeing double-pointed structures
00033         *       -- they might point somewhere you don't want freed
00034         * Freeing the top-level pointer should not interfere with data below 
00035 */
00036 
00037 /********** structures from geometries.h ****************/
00038 // Structures that contain no pointers need no work, but here are some
00039 // functions in case someone calls it -- it won't complain
00040 void deallocateCoord3D(coord_3D *c){ return ; }
00041 void deallocateVectormag3D(vectormag_3D *v){ return ; }
00042 void deallocatePlane(plane *p){ return ; }
00043 /* void deallocateBondedPositionSet(bonded_position_set *b){ return ; } */
00044 // Multi-Dimensional
00045 void deallocateCoordND(coord_nD *c){ 
00046         if(c[0].D != NULL && c[0].D != 0x0){free(c[0].D);} 
00047         return ; 
00048 }
00049 void deallocateNDIndex(nD_index *i){ 
00050         if(i[0].Di != NULL && i[0].Di != 0x0){free(i[0].Di);} 
00051         return ; 
00052 }
00053 void deallocateNDPtrs(nD_ptrs *p){ 
00054         if(p[0].Dp != NULL && p[0].Dp != 0x0){free(p[0].Dp);} 
00055         return ; 
00056 }
00057 void deallocateCoordNDi(coord_nDi *c){ 
00058         if(c[0].D != NULL && c[0].D != 0x0){free(c[0].D);} 
00059         if(c[0].Di != NULL && c[0].Di != 0x0){free(c[0].Di);} 
00060         return ; 
00061 }
00062 void deallocateBoxinfo(boxinfo *bi){ 
00063         int i;
00064         if(bi[0].STYPE != NULL && bi[0].STYPE != 0x0){free(bi[0].STYPE);} 
00065         if(bi[0].GTYPE != NULL && bi[0].GTYPE != 0x0){free(bi[0].GTYPE);} 
00066         if(bi[0].C != NULL && bi[0].C != 0x0){
00067                 for(i=0;i<bi[0].nC;i++){deallocateCoordND(&bi[0].C[i]);}
00068                 free(bi[0].C);}
00069         if(bi[0].CD != NULL && bi[0].CD != 0x0){
00070                 for(i=0;i<bi[0].nCD;i++){if(bi[0].CD[i] != NULL && bi[0].CD[i] != 0x0){free(bi[0].CD[i]);}}
00071                 free(bi[0].CD);}
00072         return ; 
00073 } 
00074 /********** structures from parameter_sets.h ****************/
00075 void deallocateChiralityDescription(chirality_description *cd){
00076  int i;
00077         if(cd[0].ELGEOM != NULL && cd[0].ELGEOM != 0x0){free(cd[0].ELGEOM);} 
00078         if(cd[0].SPGEOM != NULL && cd[0].SPGEOM != 0x0){free(cd[0].SPGEOM);} 
00079         if(cd[0].iso != NULL && cd[0].iso != 0x0){
00080                 for(i=0;i<cd[0].niso;i++){if(cd[0].iso[i] != NULL && cd[0].iso[i] != 0x0){free(cd[0].iso[i]);}}
00081                 free(cd[0].iso);}
00082  return ;
00083 } 
00084 void deallocateBondType(bond_type *btp){
00085  //Free up the description
00086  if(btp[0].desc != NULL && btp[0].desc != 0x0){free(btp[0].desc);}
00087  //Free up the first and second atom types in bond
00088  if(btp[0].NT[0] != NULL && btp[0].NT[0] != 0x0){free(btp[0].NT[0]);}
00089  if(btp[0].NT[1] != NULL && btp[0].NT[1] != 0x0){free(btp[0].NT[1]);}
00090  if(btp[0].NT != NULL && btp[0].NT != 0x0){free(btp[0].NT);}
00091  //Print a warning if the void pointer doesn't seem to be empty
00092  if(btp[0].VP!= NULL && btp[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating bond_type structure with non-NULL void pointer!\n");}
00093  return ;
00094 }
00095 void deallocateAngleType(angle_type *atp){
00096  //Free up the description
00097  if(atp[0].desc != NULL && atp[0].desc != 0x0){free(atp[0].desc);}
00098  //Free up the first and second atom types in bond
00099  if(atp[0].NT[0] != NULL && atp[0].NT[0] != 0x0){free(atp[0].NT[0]);}
00100  if(atp[0].NT[1] != NULL && atp[0].NT[1] != 0x0){free(atp[0].NT[1]);}
00101  if(atp[0].NT[2] != NULL && atp[0].NT[2] != 0x0){free(atp[0].NT[2]);}
00102  if(atp[0].NT != NULL && atp[0].NT != 0x0){free(atp[0].NT);}
00103  //Print a warning if the void pointer doesn't seem to be empty
00104  if(atp[0].VP!= NULL && atp[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating angle_type structure with non-NULL void pointer!\n");}
00105  return ;
00106 }
00107 void deallocateTorsionType(torsion_type *ttp){
00108  //Free up the description
00109  if(ttp[0].desc != NULL && ttp[0].desc != 0x0){free(ttp[0].desc);}
00110  //Free up the first and second atom types in bond
00111  if(ttp[0].NT[0] != NULL && ttp[0].NT[0] != 0x0){free(ttp[0].NT[0]);}
00112  if(ttp[0].NT[1] != NULL && ttp[0].NT[1] != 0x0){free(ttp[0].NT[1]);}
00113  if(ttp[0].NT[2] != NULL && ttp[0].NT[2] != 0x0){free(ttp[0].NT[2]);}
00114  if(ttp[0].NT[3] != NULL && ttp[0].NT[3] != 0x0){free(ttp[0].NT[3]);}
00115  if(ttp[0].NT != NULL && ttp[0].NT != 0x0){free(ttp[0].NT);}
00116  //Free the n terms
00117  if(ttp[0].k != NULL && ttp[0].k != 0x0){free(ttp[0].k);} 
00118  if(ttp[0].N != NULL && ttp[0].N != 0x0){free(ttp[0].N);} 
00119  if(ttp[0].P != NULL && ttp[0].P != 0x0){free(ttp[0].P);} 
00120  //Print a warning if the void pointer doesn't seem to be empty
00121  if(ttp[0].VP!= NULL && ttp[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating torsion_type structure with non-NULL void pointer!\n");}
00122  return ;
00123 }
00124 void deallocateAtype(atype *atp){
00125  int i;
00126  if(atp[0].N != NULL && atp[0].N != 0x0){free(atp[0].N);}
00127  if(atp[0].NT != NULL && atp[0].NT != 0x0){free(atp[0].NT);}
00128  if(atp[0].desc != NULL && atp[0].desc != 0x0){free(atp[0].desc);}
00129  if(atp[0].bo != NULL && atp[0].bo != 0x0){free(atp[0].bo);}
00130  if(atp[0].ch != NULL && atp[0].ch != 0x0){free(atp[0].ch);}
00131  if(atp[0].R != NULL && atp[0].R != 0x0){free(atp[0].R);}
00132  if(atp[0].SC != NULL && atp[0].SC != 0x0){free(atp[0].SC);}
00133 //Free n terms
00134  if(atp[0].RD != NULL && atp[0].RD != 0x0){
00135         for(i=0;i<atp[0].nR;i++){if(atp[0].RD[i] != NULL && atp[0].RD[i] != 0x0){free(atp[0].RD[i]);}}
00136         free(atp[0].RD);}
00137 // free up the convenience indices & pointers
00138 //      only need free top level here.  None of these should hold
00139 //      data of their own.  They should only point into other arrays.
00140  if(atp[0].iBT != NULL && atp[0].iBT != 0x0){free(atp[0].iBT);}
00141  if(atp[0].BT != NULL && atp[0].BT != 0x0){free(atp[0].BT);}
00142  if(atp[0].iHBT != NULL && atp[0].iHBT != 0x0){free(atp[0].iHBT);}
00143  if(atp[0].HBT != NULL && atp[0].HBT != 0x0){free(atp[0].HBT);}
00144  if(atp[0].iNBT != NULL && atp[0].iNBT != 0x0){free(atp[0].iNBT);}
00145  if(atp[0].NBT != NULL && atp[0].NBT != 0x0){free(atp[0].NBT);}
00146  if(atp[0].iANT != NULL && atp[0].iANT != 0x0){free(atp[0].iANT);}
00147  if(atp[0].ANT != NULL && atp[0].ANT != 0x0){free(atp[0].ANT);}
00148  if(atp[0].iHANT != NULL && atp[0].iHANT != 0x0){free(atp[0].iHANT);}
00149  if(atp[0].HANT != NULL && atp[0].HANT != 0x0){free(atp[0].HANT);}
00150  if(atp[0].iNANT != NULL && atp[0].iNANT != 0x0){free(atp[0].iNANT);}
00151  if(atp[0].NANT != NULL && atp[0].NANT != 0x0){free(atp[0].NANT);}
00152  if(atp[0].iTRT != NULL && atp[0].iTRT != 0x0){free(atp[0].iTRT);}
00153  if(atp[0].TRT != NULL && atp[0].TRT != 0x0){free(atp[0].TRT);}
00154  if(atp[0].iHTRT != NULL && atp[0].iHTRT != 0x0){free(atp[0].iHTRT);}
00155  if(atp[0].HTRT != NULL && atp[0].HTRT != 0x0){free(atp[0].HTRT);}
00156  if(atp[0].iNTRT != NULL && atp[0].iNTRT != 0x0){free(atp[0].iNTRT);}
00157  if(atp[0].NTRT != NULL && atp[0].NTRT != 0x0){free(atp[0].NTRT);}
00158  //Print a warning if the void pointer doesn't seem to be empty
00159  if(atp[0].VP!= NULL && atp[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating atype structure with non-NULL void pointer!\n");}
00160  return ;
00161 } 
00162 void deallocateRtype(rtype *rtp){
00163  if(rtp[0].ac != NULL && rtp[0].ac != 0x0){free(rtp[0].ac);} 
00164  //Print a warning if the void pointer doesn't seem to be empty
00165  if(rtp[0].VP!= NULL && rtp[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating rtype structure with non-NULL void pointer!\n");}
00166  return ;
00167 }
00168 void deallocateMtype(mtype *mtp){
00169  //Print a warning if the void pointer doesn't seem to be empty
00170  if(mtp[0].VP!= NULL && mtp[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating mtype structure with non-NULL void pointer!\n");}
00171  return ;
00172 } 
00173 void deallocateTypes(types *tps){
00174  int i;
00175  //deallocate substructures
00176         if(tps[0].a != NULL && tps[0].a != 0x0){
00177                 for(i=0;i<tps[0].na;i++){deallocateAtype(&tps[0].a[i]);}
00178                 free(tps[0].a);}
00179         if(tps[0].r != NULL && tps[0].r != 0x0){
00180                 for(i=0;i<tps[0].nr;i++){deallocateRtype(&tps[0].r[i]);}
00181                 free(tps[0].r);}
00182         if(tps[0].m != NULL && tps[0].m != 0x0){
00183                 for(i=0;i<tps[0].nm;i++){deallocateMtype(&tps[0].m[i]);}
00184                 free(tps[0].m);}
00185  //Print a warning if the void pointer doesn't seem to be emp if(tps[0].VP!= NULL && tps[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating types structure with non-NULL void pointer!\n");}
00186 if(tps[0].VP!= NULL && tps[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating types structure with non-NULL void pointer!\n");}
00187  return ;
00188 }
00189 
00190 void deallocateParameterSet(parameter_set *ps){
00191  int i;
00192  //deallocate substructures
00193         if(ps[0].AT != NULL && ps[0].AT != 0x0){
00194                 for(i=0;i<ps[0].nAT;i++){deallocateAtype(&ps[0].AT[i]);}
00195                 free(ps[0].AT);}
00196         if(ps[0].RT != NULL && ps[0].RT != 0x0){
00197                 for(i=0;i<ps[0].nRT;i++){deallocateRtype(&ps[0].RT[i]);}
00198                 free(ps[0].RT);}
00199         if(ps[0].MT != NULL && ps[0].MT != 0x0){
00200                 for(i=0;i<ps[0].nMT;i++){deallocateMtype(&ps[0].MT[i]); }
00201                 free(ps[0].MT);}
00202         if(ps[0].BT != NULL && ps[0].BT != 0x0){
00203                 for(i=0;i<ps[0].nBT;i++){deallocateBondType(&ps[0].BT[i]);}
00204                 free(ps[0].BT);}
00205         if(ps[0].HBT != NULL && ps[0].HBT != 0x0){
00206                 for(i=0;i<ps[0].nHBT;i++){deallocateBondType(&ps[0].HBT[i]);}
00207                 free(ps[0].HBT);}
00208         if(ps[0].NBT != NULL && ps[0].NBT != 0x0){
00209                 for(i=0;i<ps[0].nNBT;i++){deallocateBondType(&ps[0].NBT[i]);}
00210                 free(ps[0].NBT);}
00211         if(ps[0].ANT != NULL && ps[0].ANT != 0x0){
00212                 for(i=0;i<ps[0].nANT;i++){deallocateAngleType(&ps[0].ANT[i]);}
00213                 free(ps[0].ANT);}
00214         if(ps[0].TRT != NULL && ps[0].TRT != 0x0){
00215                 for(i=0;i<ps[0].nTRT;i++){deallocateTorsionType(&ps[0].TRT[i]);}
00216                 free(ps[0].TRT);}
00217  return ;
00218 }
00219 /********** structures from molecules.h ****************/
00220 void deallocateMolindexSet(molindex_set *ms){
00221  if(ms[0].P != NULL && ms[0].P != 0x0){free(ms[0].P);} //molindex is simple -- no deallocation
00222  return ;
00223 }
00224 void deallocateResidueTreeIndex(residue_tree_index *rti){
00225  if(rti[0].ai != NULL && rti[0].ai != 0x0){free(rti[0].ai);} 
00226 }
00227 void deallocateMoleculeTreeIndex(molecule_tree_index *mti){
00228  int i;
00229  if(mti[0].ri != NULL && mti[0].ri != 0x0){free(mti[0].ri);} 
00230  if(mti[0].r != NULL && mti[0].r != 0x0){
00231         for(i=0;i<mti[0].nr;i++){deallocateResidueTreeIndex(&mti[0].r[i]);} 
00232         free(mti[0].r);}
00233 }
00234 void deallocateEnsembleTreeIndex(ensemble_tree_index *eti){
00235  int i;
00236  if(eti[0].mi != NULL && eti[0].mi != 0x0){free(eti[0].mi);} 
00237  if(eti[0].m != NULL && eti[0].m != 0x0){
00238         for(i=0;i<eti[0].nm;i++){deallocateMoleculeTreeIndex(&eti[0].m[i]);} 
00239         free(eti[0].m);}
00240 }
00241 void deallocateMoietySelection(moiety_selection *ms){
00242  int i;
00243  if(ms[0].mn != NULL && ms[0].mn != 0x0){free(ms[0].mn);} 
00244  if(ms[0].mi != NULL && ms[0].mi != 0x0){free(ms[0].mi);} 
00245  if(ms[0].rn != NULL && ms[0].rn != 0x0){free(ms[0].rn);} 
00246  if(ms[0].ri != NULL && ms[0].ri != 0x0){free(ms[0].ri);} 
00247  if(ms[0].an != NULL && ms[0].an != 0x0){free(ms[0].an);} 
00248  if(ms[0].ai != NULL && ms[0].ai != 0x0){free(ms[0].ai);} 
00249  if(ms[0].mN != NULL && ms[0].mN != 0x0){
00250         for(i=0;i<ms[0].nmN;i++){if(ms[0].mN[i] != NULL && ms[0].mN[i] != 0x0){free(ms[0].mN[i]);}}
00251         free(ms[0].mN);}
00252  if(ms[0].rN != NULL && ms[0].rN != 0x0){
00253         for(i=0;i<ms[0].nrN;i++){if(ms[0].rN[i] != NULL && ms[0].rN[i] != 0x0){free(ms[0].rN[i]);}}
00254         free(ms[0].rN);}
00255  if(ms[0].aN != NULL && ms[0].aN != 0x0){
00256         for(i=0;i<ms[0].naN;i++){if(ms[0].aN[i] != NULL && ms[0].aN[i] != 0x0){free(ms[0].aN[i]);}}
00257         free(ms[0].aN);}
00258 }
00259 void deallocateBond(bond *bnd){
00260  if(bnd[0].D != NULL && bnd[0].D != 0x0){free(bnd[0].D);}
00261  // this should just be a pointer into an array, so set to null
00262  bnd[0].typ = 0x0; 
00263  return ;
00264 } 
00265 void deallocateBondset(bondset *bst){
00266  int i; 
00267  if(bst[0].b != NULL && bst[0].b != 0x0){
00268   for(i=0;i<bst[0].n;i++){deallocateBond(&bst[0].b[i]);}
00269   free(bst[0].b);}
00270  return ; 
00271 } 
00272 /*
00273 void deallocateConnectionTree(connection_tree *ct){
00274  if(ct[0].i != NULL && ct[0].i != 0x0){free(ct[0].i);}
00275  if(ct[0].o != NULL && ct[0].o != 0x0){free(ct[0].o);}
00276  if(ct[0].op != NULL && ct[0].op != 0x0){free(ct[0].op);}
00277  if(ct[0].OV != NULL && ct[0].OV != 0x0){free(ct[0].OV);}
00278  if(ct[0].EC != NULL && ct[0].EC != 0x0){free(ct[0].EC);}
00279  return ;
00280 }
00281 */
00282 void deallocateMolbond(molbond *mb){
00283  // the bond_type pointer should point into an array, so just set null
00284  mb[0].typ = 0x0;
00285  if(mb[0].D != NULL && mb[0].D != 0x0){free(mb[0].D);}
00286  return ;
00287 }
00288 void deallocateMolbondset(molbondset *mbs){
00289  int i;
00290  if(mbs[0].D != NULL && mbs[0].D != 0x0){free(mbs[0].D);}
00291  if(mbs[0].b != NULL && mbs[0].b != 0x0){
00292         for(i=0;i<mbs[0].n;i++){deallocateMolbond(&mbs[0].b[i]);}
00293         free(mbs[0].b);}
00294  return ;
00295 }
00296 void deallocateAngleIndex(angle_index *ai){
00297  // the pointer should point into an array, so just set null
00298  ai[0].typ = 0x0;
00299  if(ai[0].D != NULL && ai[0].D != 0x0){free(ai[0].D);}
00300  return ;
00301 }
00302 void deallocateTorsionIndex(torsion_index *ti){
00303  // the pointer should point into an array, so just set null
00304  ti[0].typ = 0x0;
00305  if(ti[0].D != NULL && ti[0].D != 0x0){free(ti[0].D);}
00306  return ;
00307 }
00308 void deallocateAtom(atom *a){
00309  int i;
00310  //set null
00311  a[0].typ = 0x0;
00312  // deallocate each
00313  if(a[0].b != NULL && a[0].b != 0x0){
00314         for(i=0;i<a[0].nb;i++){deallocateBond(&a[0].b[i]);}
00315         free(a[0].b);}
00316  if(a[0].mb != NULL && a[0].mb != 0x0){
00317         for(i=0;i<a[0].nmb;i++){deallocateMolbond(&a[0].mb[i]);}
00318         free(a[0].mb);}
00319  // free each
00320  if(a[0].OD != NULL && a[0].OD != 0x0){
00321         for(i=0;i<a[0].nOD;i++){if(a[0].OD[i] != NULL && a[0].OD[i] != 0x0){free(a[0].OD[i]);}}
00322         free(a[0].OD);}
00323  // free top
00324  if(a[0].N != NULL && a[0].N != 0x0){free(a[0].N);}
00325  if(a[0].T != NULL && a[0].T != 0x0){free(a[0].T);}
00326  if(a[0].D != NULL && a[0].D != 0x0){free(a[0].D);}
00327  if(a[0].xa != NULL && a[0].xa != 0x0){free(a[0].xa);}
00328  if(a[0].xva != NULL && a[0].xva != 0x0){free(a[0].xva);}
00329  if(a[0].v != NULL && a[0].v != 0x0){free(a[0].v);}
00330  if(a[0].ch != NULL && a[0].ch != 0x0){free(a[0].ch);}
00331  if(a[0].i != NULL && a[0].i != 0x0){free(a[0].i);}
00332  if(a[0].d != NULL && a[0].d != 0x0){free(a[0].d);}
00333  if(a[0].ensi != NULL && a[0].ensi != 0x0){free(a[0].ensi);}
00334  if(a[0].sres != NULL && a[0].sres != 0x0){free(a[0].sres);}
00335         // check and warn if non-null
00336  if(a[0].VP!= NULL && a[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating atom structure with non-NULL void pointer!\n");}
00337  return ;
00338 }
00339 void deallocateResidue(residue *r){
00340  int i;
00341  //set null
00342  r[0].typ = 0x0;
00343  // deallocate each
00344  if(r[0].a != NULL && r[0].a != 0x0){
00345         for(i=0;i<r[0].na;i++){deallocateAtom(&r[0].a[i]);}
00346         free(r[0].a);}
00347 /*
00348  if(r[0].aT != NULL && r[0].aT != 0x0){
00349         for(i=0;i<r[0].na;i++){deallocateConnectionTree(&r[0].aT[i]);}
00350         free(r[0].aT);}
00351 */
00352  if(r[0].bs != NULL && r[0].bs != 0x0){
00353         for(i=0;i<r[0].nbs;i++){deallocateMolbondset(&r[0].bs[i]);}
00354         free(r[0].bs);}
00355  // free each
00356  if(r[0].OD != NULL && r[0].OD != 0x0){
00357         for(i=0;i<r[0].nOD;i++){if(r[0].OD[i] != NULL && r[0].OD[i] != 0x0){free(r[0].OD[i]);}}
00358         free(r[0].OD);}
00359  // free top
00360  if(r[0].N != NULL && r[0].N != 0x0){free(r[0].N);}
00361  if(r[0].T != NULL && r[0].T != 0x0){free(r[0].T);}
00362  if(r[0].D != NULL && r[0].D != 0x0){free(r[0].D);}
00363  if(r[0].rc != NULL && r[0].rc != 0x0){free(r[0].rc);}
00364  if(r[0].rp != NULL && r[0].rp != 0x0){free(r[0].rp);}
00365  if(r[0].i != NULL && r[0].i != 0x0){free(r[0].i);}
00366  if(r[0].d != NULL && r[0].d != 0x0){free(r[0].d);}
00367  if(r[0].ensi != NULL && r[0].ensi != 0x0){free(r[0].ensi);}
00368         // check and warn if non-null
00369  if(r[0].VP!= NULL && r[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating residue structure with non-NULL void pointer!\n");}
00370  return ;
00371 }
00372 void deallocateMolecule(molecule *m){
00373  int i;
00374  //set null
00375  m[0].typ = 0x0;
00376  // deallocate each
00377  if(m[0].r != NULL && m[0].r != 0x0){
00378         for(i=0;i<m[0].nr;i++){deallocateResidue(&m[0].r[i]);}
00379         free(m[0].r);}
00380 /*
00381  if(m[0].rb != NULL && m[0].rb != 0x0){
00382         for(i=0;i<m[0].nrb;i++){deallocateMolbond(&m[0].rb[i]);}
00383         free(m[0].rb);}
00384 */
00385  if(m[0].rbs != NULL && m[0].rbs != 0x0){
00386         for(i=0;i<m[0].nrbs;i++){deallocateMolbondset(&m[0].rbs[i]);}
00387         free(m[0].rbs);}
00388 /*
00389  if(m[0].aT != NULL && m[0].aT != 0x0){
00390         for(i=0;i<m[0].na;i++){deallocateConnectionTree(&m[0].aT[i]);}
00391         free(m[0].aT);}
00392  if(m[0].rT != NULL && m[0].rT != 0x0){
00393         for(i=0;i<m[0].nr;i++){deallocateConnectionTree(&m[0].rT[i]);}
00394         free(m[0].rT);}
00395 */
00396  if(m[0].BOX != NULL && m[0].BOX != 0x0){
00397         for(i=0;i<m[0].nBOX;i++){deallocateBoxinfo(&m[0].BOX[i]);}
00398         free(m[0].BOX);}
00399  // free each
00400  if(m[0].OD != NULL && m[0].OD != 0x0){
00401         for(i=0;i<m[0].nOD;i++){if(m[0].OD[i] != NULL && m[0].OD[i] != 0x0){free(m[0].OD[i]);}}
00402         free(m[0].OD);}
00403  // free top
00404  if(m[0].N != NULL && m[0].N != 0x0){free(m[0].N);}
00405  if(m[0].D != NULL && m[0].D != 0x0){free(m[0].D);}
00406  if(m[0].T != NULL && m[0].T != 0x0){free(m[0].T);}
00407  if(m[0].a != NULL && m[0].a != 0x0){free(m[0].a);}
00408  if(m[0].rc != NULL && m[0].rc != 0x0){free(m[0].rc);}
00409  if(m[0].oi != NULL && m[0].oi != 0x0){free(m[0].oi);}
00410  if(m[0].d != NULL && m[0].d != 0x0){free(m[0].d);}
00411  if(m[0].ensi != NULL && m[0].ensi != 0x0){free(m[0].ensi);}
00412         // check and warn if non-null
00413  if(m[0].VP!= NULL && m[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating molecule structure with non-NULL void pointer!\n");}
00414  return ;
00415 } 
00416 void deallocateDockinfo(dockinfo *di){
00417  // deallocate once 
00418  deallocateMolecule(&di[0].M); // this can't be null...
00419  // free top
00420  if(di[0].TR != NULL && di[0].TR != 0x0){free(di[0].TR);}
00421  if(di[0].Q != NULL && di[0].Q != 0x0){free(di[0].Q);}
00422  if(di[0].QN != NULL && di[0].QN != 0x0){free(di[0].QN);}
00423  if(di[0].QN0 != NULL && di[0].QN0 != 0x0){free(di[0].QN0);}
00424  if(di[0].Tors != NULL && di[0].Tors != 0x0){free(di[0].Tors);}
00425  if(di[0].eFEB != NULL && di[0].eFEB != 0x0){free(di[0].eFEB);}
00426  if(di[0].eKi != NULL && di[0].eKi != 0x0){free(di[0].eKi);}
00427  if(di[0].Tmp != NULL && di[0].Tmp != 0x0){free(di[0].Tmp);}
00428  if(di[0].fDE != NULL && di[0].fDE != 0x0){free(di[0].fDE);}
00429  if(di[0].fIE != NULL && di[0].fIE != 0x0){free(di[0].fIE);}
00430  if(di[0].fIEL != NULL && di[0].fIEL != 0x0){free(di[0].fIEL);}
00431  if(di[0].TFE != NULL && di[0].TFE != 0x0){free(di[0].TFE);}
00432  if(di[0].USE != NULL && di[0].USE != 0x0){free(di[0].USE);}
00433  if(di[0].DIH != NULL && di[0].DIH != 0x0){free(di[0].DIH);}
00434  if(di[0].D != NULL && di[0].D != 0x0){free(di[0].D);}
00435  if(di[0].DOCK_PROGRAM != NULL && di[0].DOCK_PROGRAM != 0x0){free(di[0].DOCK_PROGRAM);}
00436  if(di[0].VERSION != NULL && di[0].VERSION != 0x0){free(di[0].VERSION);}
00437  return ;
00438 }
00439  
00440 void deallocateAssembly(assembly *a){
00441  int i;
00442  // deallocate each
00443 /*
00444  if(a[0].mT != NULL && a[0].mT != 0x0){ 
00445         for(i=0;i<a[0].nm;i++){deallocateConnectionTree(&a[0].mT[i]);}
00446         free(a[0].mT);}
00447  if(a[0].rT != NULL && a[0].rT != 0x0){
00448         for(i=0;i<a[0].nr;i++){deallocateConnectionTree(&a[0].rT[i]);}
00449         free(a[0].rT);}
00450  if(a[0].aT != NULL && a[0].aT != 0x0){
00451         for(i=0;i<a[0].na;i++){deallocateConnectionTree(&a[0].aT[i]);}
00452         free(a[0].aT);}
00453 */
00454  if(a[0].b != NULL && a[0].b != 0x0){
00455         for(i=0;i<a[0].nb;i++){deallocateMolbond(&a[0].b[i]);}
00456         free(a[0].b);}
00457  if(a[0].mbs != NULL && a[0].mbs != 0x0){
00458         for(i=0;i<a[0].nmbs;i++){deallocateMolbondset(&a[0].mbs[i]);}
00459         free(a[0].mbs);}
00460  if(a[0].ANG != NULL && a[0].ANG != 0x0){
00461         for(i=0;i<a[0].nANG;i++){deallocateAngleIndex(&a[0].ANG[i]);}
00462         free(a[0].ANG);}
00463  if(a[0].TOR != NULL && a[0].TOR != 0x0){
00464         for(i=0;i<a[0].nTOR;i++){deallocateTorsionIndex(&a[0].TOR[i]);}
00465         free(a[0].TOR);}
00466  if(a[0].BOX != NULL && a[0].BOX != 0x0){
00467         for(i=0;i<a[0].nBOX;i++){deallocateBoxinfo(&a[0].BOX[i]);}
00468         free(a[0].BOX);}
00469  if(a[0].PRM != NULL && a[0].PRM != 0x0){
00470         for(i=0;i<a[0].nPRM;i++){deallocateParameterSet(a[0].PRM[i]);}
00471         free(a[0].PRM);}
00472  // free each
00473  if(a[0].OD != NULL && a[0].OD != 0x0){
00474         for(i=0;i<a[0].nOD;i++){if(a[0].OD[i] != NULL && a[0].OD[i] != 0x0){free(a[0].OD[i]);}}
00475         free(a[0].OD);}
00476  // free top
00477  if(a[0].N != NULL && a[0].N != 0x0){free(a[0].N);}
00478  if(a[0].T != NULL && a[0].T != 0x0){free(a[0].T);}
00479  if(a[0].D != NULL && a[0].D != 0x0){free(a[0].D);}
00480  if(a[0].r != NULL && a[0].r != 0x0){free(a[0].r);}
00481  if(a[0].a != NULL && a[0].a != 0x0){free(a[0].a);}
00482  if(a[0].m != NULL && a[0].m != 0x0){free(a[0].m);}
00483  if(a[0].ensi != NULL && a[0].ensi != 0x0){free(a[0].ensi);}
00484         // check and warn if non-null
00485  if(a[0].VP!= NULL && a[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating assembly structure with non-NULL void pointer!\n");}
00486  return ;
00487 }
00488 void deallocateFullAssembly(assembly *a){
00489  int i;
00490  if(a[0].m != NULL && a[0].m != 0x0){
00491         for(i=0;i<a[0].nm;i++){if(a[0].m[i] != NULL && a[0].m[i] != 0x0){deallocateMolecule(a[0].m[i]);}}}
00492  deallocateAssembly(a);
00493  return ;
00494 }
00495 void deallocateEnsemble(ensemble *e){
00496  int i;
00497  // deallocate each
00498  if(e[0].m != NULL && e[0].m != 0x0){
00499         for(i=0;i<e[0].nm;i++){deallocateMolecule(&e[0].m[i]);}
00500         free(e[0].m);}
00501  if(e[0].BOX != NULL && e[0].BOX != 0x0){
00502         for(i=0;i<e[0].nBOX;i++){deallocateBoxinfo(&e[0].BOX[i]);}
00503         free(e[0].BOX);}
00504  if(e[0].A != NULL && e[0].A != 0x0){
00505         for(i=0;i<e[0].nA;i++){deallocateAssembly(e[0].A[i]);}
00506         free(e[0].A);}
00507  if(e[0].PRM != NULL && e[0].PRM != 0x0){
00508         for(i=0;i<e[0].nPRM;i++){deallocateParameterSet(e[0].PRM[i]);}
00509         free(e[0].PRM);}
00510  // free each
00511  if(e[0].OD != NULL && e[0].OD != 0x0){
00512         for(i=0;i<e[0].nOD;i++){if(e[0].OD[i] != NULL && e[0].OD[i] != 0x0){free(e[0].OD[i]);}}
00513         free(e[0].OD);}
00514  // free top
00515  if(e[0].N != NULL && e[0].N != 0x0){free(e[0].N);}
00516  if(e[0].T != NULL && e[0].T != 0x0){free(e[0].T);}
00517  if(e[0].D != NULL && e[0].D != 0x0){free(e[0].D);}
00518  if(e[0].ensi != NULL && e[0].ensi != 0x0){free(e[0].ensi);}
00519  // check and warn if non-null
00520  if(e[0].VP!= NULL && e[0].VP != 0x0){fprintf(stderr,"WARNING: deallocating ensemble structure with non-NULL void pointer!\n");}
00521  return ;
00522 }
 All Classes Files Functions Variables Typedefs Defines