Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

structures.h

Go to the documentation of this file.
00001 
00007 #ifndef STRUCTURES_H
00008 #define STRUCTURES_H
00009 
00010 #include "common.h"
00011 #include <vector>
00012 using namespace std;
00013 
00014 
00015 // status elements, used for Atom status 
00016 #define UnknownAtom      0x00
00017 #define HydrogenAtom     0x01
00018 #define OxygenAtom       0x02
00019 #define HBDonorAtom      0x04
00020 #define HBAcceptorAtom   0x08
00021 #define HBAntecedentAtom 0x10
00022 #define HBHydrogenAtom   0x20
00023 #define LonepairAtom     0x40
00024 
00025 
00026 typedef unsigned short Index;           //  Used for index into arrays
00027                                         //  or parameters
00028 
00029 typedef struct atom_name_info
00030 {
00031         char *resname;
00032         char *atomname;
00033         char *atomtype;
00034 } AtomNameInfo;
00035 
00036 typedef struct atom_constants
00037 {
00038         Real mass;
00039         Real charge;
00040         Index vdw_type;
00041         int32 status;            // flags telling about this atom
00042         int32 partner;             // connecting atom, for hydrogens
00043         int32 hydrogenList;     // index of atom in hydrogenGroup list
00044 } Atom;
00045 
00046 typedef struct bond
00047 {
00048         int32 atom1;
00049         int32 atom2;
00050         Index bond_type;
00051 } Bond;
00052 
00053 typedef struct angle
00054 {
00055         int32 atom1;
00056         int32 atom2;
00057         int32 atom3;
00058         Index angle_type;
00059 } Angle;
00060 
00061 typedef struct dihedral
00062 {
00063         int32 atom1;
00064         int32 atom2;
00065         int32 atom3;
00066         int32 atom4;
00067         Index dihedral_type;
00068 } Dihedral;
00069 
00070 typedef struct improper
00071 {
00072         int32 atom1;
00073         int32 atom2;
00074         int32 atom3;
00075         int32 atom4;
00076         Index improper_type;
00077 } Improper;
00078 
00079 typedef struct crossterm
00080 {
00081         int32 atom1;
00082         int32 atom2;
00083         int32 atom3;
00084         int32 atom4;
00085         int32 atom5;
00086         int32 atom6;
00087         int32 atom7;
00088         int32 atom8;
00089         Index crossterm_type;
00090 } Crossterm;
00091 
00092 class Exclusion
00093 {
00094 public:
00095         Exclusion(void) : modified(0) {;}
00096         Exclusion(int a1, int a2, int mod = 0) :
00097                 atom1(a1), atom2(a2), modified(mod) {;}
00098         int32 atom1;
00099         int32 atom2;
00100         Index modified;
00101         int hash(void) const
00102         {
00103                 return atom1 + atom2;
00104         }
00105         int operator==(const Exclusion &o) const
00106         {
00107                 return atom1 == o.atom1 && atom2 == o.atom2;
00108         }
00109         int operator<(const Exclusion &o) const
00110         {
00111                 return
00112                 (
00113                   ( atom1 < o.atom1 ) ||
00114                   ( atom1 == o.atom1 && atom2 < o.atom2 )
00115                 );
00116         }
00117 };
00118 
00119 
00120 class MOStream;
00121 class MIStream;
00122 
00123 enum TupleSigType {BOND=0, ANGLE, DIHEDRAL, IMPROPER, DONOR, ACCEPTOR, CROSSTERM, EXCLUSION};
00124 
00125 class TupleSignature{
00126 public:
00127     //This field indicates which class this tuple belongs to (bond or angle or ...)
00128     TupleSigType tupleType;
00129     int numOffset;
00130     //the relative offset from the atom index
00131     int *offset;   
00132 
00133     //This type is determined by the Parameter object
00134     //for Exclusion, this indicates the modified field
00135     Index tupleParamType;
00136 
00137     //indicate this tuple is specified in the psf file, not from other files.
00138     //this is added due to the extraBonds feature. All tuples from extraBonds
00139     //are not real!
00140     char isReal;
00141 
00142 public:
00143     TupleSignature(){        
00144         offset = NULL;
00145         isReal = 1;
00146     }
00147 
00148     TupleSignature(int n, TupleSigType t, Index paramType, char ir=1){
00149         tupleType = t;
00150         numOffset = n;
00151         offset = new int[n];        
00152         tupleParamType = paramType;
00153         isReal = ir;
00154     }
00155     TupleSignature(const TupleSignature& oneSig){
00156         tupleType = oneSig.tupleType;
00157         numOffset = oneSig.numOffset;
00158         offset = new int[numOffset];
00159         setOffsets(oneSig.offset);        
00160         tupleParamType = oneSig.tupleParamType;
00161         isReal = oneSig.isReal;
00162     }
00163     TupleSignature &operator=(const TupleSignature& oneSig){
00164         tupleType = oneSig.tupleType;
00165         numOffset = oneSig.numOffset;
00166         if(offset) delete [] offset;
00167         offset = new int[numOffset];
00168         setOffsets(oneSig.offset);        
00169         tupleParamType = oneSig.tupleParamType;
00170         isReal = oneSig.isReal;
00171         return *this;
00172     }
00173     int operator==(const TupleSignature& sig) const{
00174             if(tupleType!=sig.tupleType)
00175                 return 0;
00176 
00177             if(tupleParamType != sig.tupleParamType)
00178                 return 0;
00179 
00180         if(isReal != sig.isReal)
00181             return 0;
00182 
00183                 if(numOffset != sig.numOffset) return 0;
00184                 
00185             int equalCnt=0;
00186                     
00187             for(int i=0; i<numOffset; i++){
00188                 equalCnt += (offset[i]==sig.offset[i]);      
00189             }
00190             return equalCnt==numOffset;
00191         }
00192     ~TupleSignature(){
00193         if(offset) delete[] offset;
00194     }
00195     void setOffsets(int *offs){
00196         for(int i=0; i<numOffset; i++)
00197             offset[i] = offs[i];
00198         //sort the offset in increasing order
00199         //based on the input files, this offset is almost sorted increasingly
00200         //Therefore using insertion sort
00201         /*switch(numOffset){
00202             case 1:
00203                 break;
00204             case 2:
00205                 if(offset[0]>offset[1]){
00206                     int tmp = offset[0];
00207                     offset[0] = offset[1];
00208                     offset[1] = tmp;
00209                 }
00210                 break;
00211             default: //insertion sort
00212                 for(int ii=1; ii<numOffset; ii++){
00213                     int val = offset[ii];
00214                     for(int jj=ii-1; jj>=0; jj--){
00215                         if(offset[jj]<val){
00216                             offset[jj+1] = offset[jj];
00217                             offset[jj] = val;
00218                         }else
00219                             break;
00220                     }
00221                 }
00222         }*/
00223 
00224     }
00225     void setEmpty(){
00226         delete [] offset;
00227         offset = NULL;
00228     }
00229     int isEmpty(){
00230         return offset==NULL;
00231     }
00232     void output(FILE *ofp){
00233         for(int i=0; i<numOffset; i++)
00234             fprintf(ofp, "%d ", offset[i]);
00235         fprintf(ofp, "| %d | %d\n", tupleParamType, isReal);         
00236     }
00237     void pack(MOStream *msg);
00238     void unpack(MIStream *msg);
00239 };
00240 
00241 //represents the signatures for atoms
00242 class AtomSignature{
00243 public:
00244     int bondCnt;
00245     int angleCnt;
00246     int dihedralCnt;
00247     int improperCnt;
00248     int crosstermCnt;
00249 
00250     TupleSignature *bondSigs;
00251     TupleSignature *angleSigs;
00252     TupleSignature *dihedralSigs;
00253     TupleSignature *improperSigs;
00254     TupleSignature *crosstermSigs;
00255 
00256     AtomSignature(){
00257         bondCnt=angleCnt=dihedralCnt=improperCnt=crosstermCnt=0;
00258         bondSigs = NULL;
00259         angleSigs = NULL;
00260         dihedralSigs = NULL;
00261         improperSigs = NULL;
00262         crosstermSigs = NULL;
00263     }
00264     AtomSignature(const AtomSignature &sig){
00265         bondSigs = NULL;
00266         angleSigs = NULL;
00267         dihedralSigs = NULL;
00268         improperSigs = NULL;
00269         crosstermSigs = NULL;
00270 
00271         bondCnt = sig.bondCnt;
00272         if(bondCnt>0){            
00273             bondSigs = new TupleSignature[bondCnt];
00274             for(int i=0; i<bondCnt; i++)
00275                 bondSigs[i] = sig.bondSigs[i];
00276         }
00277 
00278         angleCnt = sig.angleCnt;
00279         if(angleCnt>0){            
00280             angleSigs = new TupleSignature[angleCnt];
00281             for(int i=0; i<angleCnt; i++)
00282                 angleSigs[i] = sig.angleSigs[i];
00283         }
00284         
00285         dihedralCnt = sig.dihedralCnt;
00286         if(dihedralCnt>0){            
00287             dihedralSigs = new TupleSignature[dihedralCnt];
00288             for(int i=0; i<dihedralCnt; i++)
00289                 dihedralSigs[i] = sig.dihedralSigs[i];
00290         }
00291         
00292         improperCnt = sig.improperCnt;
00293         if(improperCnt>0){
00294             improperSigs = new TupleSignature[improperCnt];
00295             for(int i=0; i<improperCnt; i++)
00296                 improperSigs[i] = sig.improperSigs[i];
00297         }      
00298 
00299         crosstermCnt = sig.crosstermCnt;
00300         if(crosstermCnt>0){
00301             crosstermSigs = new TupleSignature[crosstermCnt];
00302             for(int i=0; i<crosstermCnt; i++)
00303                 crosstermSigs[i] = sig.crosstermSigs[i];
00304         }        
00305     }
00306     AtomSignature& operator=(const AtomSignature& sig){        
00307         bondCnt = sig.bondCnt;
00308         if(bondSigs) delete [] bondSigs;
00309         if(bondCnt>0){
00310             bondSigs = new TupleSignature[bondCnt];
00311             for(int i=0; i<bondCnt; i++)
00312                 bondSigs[i] = sig.bondSigs[i];
00313         }else
00314             bondSigs = NULL;
00315 
00316         angleCnt = sig.angleCnt;
00317         if(angleSigs) delete [] angleSigs;
00318         if(angleCnt>0){
00319             angleSigs = new TupleSignature[angleCnt];
00320             for(int i=0; i<angleCnt; i++)
00321                 angleSigs[i] = sig.angleSigs[i];
00322         }else
00323             angleSigs = NULL;
00324         
00325         dihedralCnt = sig.dihedralCnt;
00326         if(dihedralSigs) delete [] dihedralSigs;
00327         if(dihedralCnt>0){
00328             dihedralSigs = new TupleSignature[dihedralCnt];
00329             for(int i=0; i<dihedralCnt; i++)
00330                 dihedralSigs[i] = sig.dihedralSigs[i];
00331         }else
00332             dihedralSigs = NULL;
00333         
00334         improperCnt = sig.improperCnt;
00335         if(improperSigs) delete [] improperSigs;
00336         if(improperCnt>0){
00337             improperSigs = new TupleSignature[improperCnt];
00338             for(int i=0; i<improperCnt; i++)
00339                 improperSigs[i] = sig.improperSigs[i];
00340         }else
00341             improperSigs = NULL;      
00342 
00343         crosstermCnt = sig.crosstermCnt;
00344         if(crosstermSigs) delete [] crosstermSigs;
00345         if(crosstermCnt>0){
00346             crosstermSigs = new TupleSignature[crosstermCnt];
00347             for(int i=0; i<crosstermCnt; i++)
00348                 crosstermSigs[i] = sig.crosstermSigs[i];
00349         }else
00350             crosstermSigs = NULL;
00351 
00352         return *this;
00353     }
00354     int operator==(const AtomSignature& sig) const{
00355             if(bondCnt!=sig.bondCnt) return 0;
00356             if(angleCnt!=sig.angleCnt) return 0;
00357             if(dihedralCnt!=sig.dihedralCnt) return 0;
00358             if(improperCnt!=sig.improperCnt) return 0;
00359             if(crosstermCnt!=sig.crosstermCnt) return 0;
00360         
00361         #define CMPSIGS(TUPLE) \
00362         for(int i=0; i<sig.TUPLE##Cnt; i++){ \
00363             if(!(TUPLE##Sigs[i]==sig.TUPLE##Sigs[i])) return 0; \
00364         } \
00365         
00366             CMPSIGS(bond)
00367             CMPSIGS(angle)
00368             CMPSIGS(dihedral)
00369             CMPSIGS(improper)
00370             CMPSIGS(crossterm)
00371         
00372             return 1;
00373         }
00374     ~AtomSignature(){
00375         if(bondSigs) delete[] bondSigs;
00376         if(angleSigs) delete[] angleSigs;
00377         if(dihedralSigs) delete[] dihedralSigs;
00378         if(improperSigs) delete[] improperSigs;
00379         if(crosstermSigs) delete[] crosstermSigs;
00380     }    
00381 
00382     void removeEmptyTupleSigs();
00383     void pack(MOStream *msg);
00384     void unpack(MIStream *msg);
00385 };
00386 
00387 struct AtomNameIdx{
00388     Index resnameIdx;
00389     Index atomnameIdx;
00390     Index atomtypeIdx;
00391 };
00392 struct AtomCstInfo{
00393     Index vdw_type;
00394     int32 status;
00395     int32 partner;
00396     int32 hydrogenList;
00397 };
00398 
00399 struct ExclusionSignature{
00400     int fullExclCnt; //1-2, 1-3 exclusion
00401     int *fullOffset; //should be in increasing order
00402     int modExclCnt; //1-4 exclusion
00403     int *modOffset; //should be in increasing order
00404 
00405     ExclusionSignature(){
00406         fullExclCnt = modExclCnt = 0;
00407         fullOffset = modOffset = NULL;
00408     }    
00409     ExclusionSignature(const ExclusionSignature& sig){
00410         fullOffset = modOffset = NULL;
00411         fullExclCnt = sig.fullExclCnt;
00412         if(fullExclCnt>0){
00413             fullOffset = new int[fullExclCnt];
00414             for(int i=0; i<fullExclCnt; i++)
00415                 fullOffset[i] = sig.fullOffset[i];
00416         }
00417         
00418         modExclCnt = sig.modExclCnt;
00419         if(modExclCnt>0){
00420             modOffset = new int[modExclCnt];
00421             for(int i=0; i<modExclCnt; i++)
00422                 modOffset[i] = sig.modOffset[i];
00423         }
00424     }
00425     ~ExclusionSignature(){
00426         if(fullOffset) delete [] fullOffset;
00427         if(modOffset) delete [] modOffset;
00428     }
00429     
00430     ExclusionSignature& operator=(const ExclusionSignature& sig){
00431         fullExclCnt = sig.fullExclCnt;
00432         if(fullOffset) delete [] fullOffset;
00433         if(fullExclCnt>0){
00434             fullOffset = new int[fullExclCnt];
00435             for(int i=0; i<fullExclCnt; i++)
00436                 fullOffset[i] = sig.fullOffset[i];
00437         }else
00438             fullOffset = NULL;
00439     
00440         modExclCnt = sig.modExclCnt;
00441         if(modOffset) delete [] modOffset;
00442         if(modExclCnt>0){
00443             modOffset = new int[modExclCnt];
00444             for(int i=0; i<modExclCnt; i++)
00445                 modOffset[i] = sig.modOffset[i];
00446         }else
00447             modOffset = NULL;
00448 
00449         return *this;
00450     }
00451         int operator==(const ExclusionSignature& sig) const{
00452             if(fullExclCnt!=sig.fullExclCnt) return 0;
00453             if(modExclCnt!=sig.modExclCnt) return 0;
00454             
00455             for(int i=0; i<fullExclCnt; i++){
00456                         if(fullOffset[i]!=sig.fullOffset[i]) return 0;
00457             }
00458             for(int i=0; i<modExclCnt; i++){
00459                         if(modOffset[i]!=sig.modOffset[i]) return 0;
00460             }
00461             return 1;
00462         }
00463     //both input should be sorted in increasing order
00464     void setOffsets(vector<int>& fullVec, vector<int>& modVec){
00465         fullExclCnt = fullVec.size();
00466         modExclCnt = modVec.size();
00467         if(fullExclCnt>0) {        
00468             fullOffset = new int[fullExclCnt];
00469             for(int i=0; i<fullExclCnt; i++)
00470                 fullOffset[i] = fullVec[i];
00471         }
00472 
00473         if(modExclCnt>0) {        
00474             modOffset = new int[modExclCnt];
00475             for(int i=0; i<modExclCnt; i++)
00476                 modOffset[i] = modVec[i];       
00477         }
00478     }
00479 
00480     void removeEmptyOffset();
00481     //assuming offsets in the signature have been sorted increasingly
00482     int findOffset(int offset, int  *fullOrMod);
00483     void pack(MOStream *msg);
00484     void unpack(MIStream *msg);
00485 };
00486 
00487 #endif
00488 

Generated on Sat Aug 30 04:07:41 2008 for NAMD by  doxygen 1.3.9.1