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 
00013 
00014 // status elements, used for Atom status 
00015 #define UnknownAtom      0x00
00016 #define HydrogenAtom     0x01
00017 #define OxygenAtom       0x02
00018 #define HBDonorAtom      0x04
00019 #define HBAcceptorAtom   0x08
00020 #define HBAntecedentAtom 0x10
00021 #define HBHydrogenAtom   0x20
00022 #define LonepairAtom     0x40
00023 #define DrudeAtom        0x80
00024 
00025 
00026 typedef int 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 typedef struct gromacsPair
00093 {
00094     int32 atom1;
00095     int32 atom2;
00096     Real pairC12;
00097     Real pairC6;
00098     Index gromacsPair_type;
00099 } GromacsPair;
00100 
00101 
00102 // DRUDE: data read from PSF
00103 typedef struct drude_constants  // supplement Atom data
00104 {                        // create array length N of these
00105   Real alpha;
00106   Real thole;
00107 } DrudeConst;
00108 
00118 typedef struct lphost
00119 {
00120   int32 atom1;     
00121   int32 atom2;
00122   int32 atom3;
00123   int32 atom4;
00124   int32 numhosts;  
00125   Real distance;
00126   Real angle;
00127   Real dihedral;
00128 } Lphost;
00129 
00130 typedef struct aniso     // anisotropic term
00131 {
00132   int32 atom1;
00133   int32 atom2;
00134   int32 atom3;
00135   int32 atom4;
00136   Real k11;
00137   Real k22;
00138   Real k33;
00139 } Aniso;
00140 
00141 typedef struct thole    // Thole terms - constructed implicitly from exclusions
00142 {
00143   int32 atom1;  // first heavy atom
00144   int32 atom2;  // Drude particle of first heavy atom
00145   int32 atom3;  // second heavy atom
00146   int32 atom4;  // Drude particle of second heavy atom
00147   Real aa;      // constant (alpha_i * alpha_j)^(-6) / (thole_i + thole_j)
00148   Real qq;      // combined charge of Drudes (C * q_{i+1} * q_{j+1})
00149 } Thole;
00150 // DRUDE
00151 
00152 
00153 class Exclusion
00154 {
00155 public:
00156         Exclusion(void) : modified(0) {;}
00157         Exclusion(int a1, int a2, int mod = 0) :
00158                 atom1(a1), atom2(a2), modified(mod) {;}
00159         int32 atom1;
00160         int32 atom2;
00161         Index modified;
00162         int hash(void) const
00163         {
00164                 return atom1 + atom2;
00165         }
00166         int operator==(const Exclusion &o) const
00167         {
00168                 return atom1 == o.atom1 && atom2 == o.atom2;
00169         }
00170         int operator<(const Exclusion &o) const
00171         {
00172                 return
00173                 (
00174                   ( atom1 < o.atom1 ) ||
00175                   ( atom1 == o.atom1 && atom2 < o.atom2 )
00176                 );
00177         }
00178 };
00179 
00180 
00181 class MOStream;
00182 class MIStream;
00183 
00184 enum TupleSigType {BOND=0, ANGLE, DIHEDRAL, IMPROPER, DONOR, ACCEPTOR, CROSSTERM, EXCLUSION};
00185 
00186 inline unsigned int circShift(unsigned int h, unsigned int by) {
00187   const unsigned int intBits=8*sizeof(unsigned int);
00188   by%=intBits;
00189   return (h<<by)|(h>>(intBits-by));
00190 }
00191 
00192 class TupleSignature{
00193 public:
00194     //This field indicates which class this tuple belongs to (bond or angle or ...)
00195     TupleSigType tupleType;
00196     int numOffset;
00197     //the relative offset from the atom index
00198     int *offset;   
00199 
00200     //This type is determined by the Parameter object
00201     //for Exclusion, this indicates the modified field
00202     Index tupleParamType;
00203 
00204     //indicate this tuple is specified in the psf file, not from other files.
00205     //this is added due to the extraBonds feature. All tuples from extraBonds
00206     //are not real!
00207     char isReal;
00208 
00209 public:
00210     TupleSignature(){        
00211         offset = NULL;
00212         isReal = 1;
00213     }
00214 
00215     TupleSignature(int n, TupleSigType t, Index paramType, char ir=1){
00216         tupleType = t;
00217         numOffset = n;
00218         offset = new int[n];        
00219         tupleParamType = paramType;
00220         isReal = ir;
00221     }
00222     TupleSignature(const TupleSignature& oneSig){
00223         tupleType = oneSig.tupleType;
00224         numOffset = oneSig.numOffset;
00225         offset = new int[numOffset];
00226         setOffsets(oneSig.offset);        
00227         tupleParamType = oneSig.tupleParamType;
00228         isReal = oneSig.isReal;
00229     }
00230     TupleSignature &operator=(const TupleSignature& oneSig){
00231         tupleType = oneSig.tupleType;
00232         numOffset = oneSig.numOffset;
00233         if(offset) delete [] offset;
00234         offset = new int[numOffset];
00235         setOffsets(oneSig.offset);        
00236         tupleParamType = oneSig.tupleParamType;
00237         isReal = oneSig.isReal;
00238         return *this;
00239     }
00240     int operator==(const TupleSignature& sig) const{
00241             if(tupleType!=sig.tupleType)
00242                 return 0;
00243 
00244             if(tupleParamType != sig.tupleParamType)
00245                 return 0;
00246 
00247         if(isReal != sig.isReal)
00248             return 0;
00249 
00250                 if(numOffset != sig.numOffset) return 0;
00251                 
00252             int equalCnt=0;
00253                     
00254             for(int i=0; i<numOffset; i++){
00255                 equalCnt += (offset[i]==sig.offset[i]);      
00256             }
00257             return equalCnt==numOffset;
00258         }
00259     ~TupleSignature(){
00260         if(offset) delete[] offset;
00261     }
00262     void setOffsets(int *offs){
00263         for(int i=0; i<numOffset; i++)
00264             offset[i] = offs[i];
00265         //sort the offset in increasing order
00266         //based on the input files, this offset is almost sorted increasingly
00267         //Therefore using insertion sort
00268         /*switch(numOffset){
00269             case 1:
00270                 break;
00271             case 2:
00272                 if(offset[0]>offset[1]){
00273                     int tmp = offset[0];
00274                     offset[0] = offset[1];
00275                     offset[1] = tmp;
00276                 }
00277                 break;
00278             default: //insertion sort
00279                 for(int ii=1; ii<numOffset; ii++){
00280                     int val = offset[ii];
00281                     for(int jj=ii-1; jj>=0; jj--){
00282                         if(offset[jj]<val){
00283                             offset[jj+1] = offset[jj];
00284                             offset[jj] = val;
00285                         }else
00286                             break;
00287                     }
00288                 }
00289         }*/
00290     }
00291     void setEmpty(){
00292         delete [] offset;
00293         offset = NULL;
00294     }
00295     int isEmpty(){
00296         return offset==NULL;
00297     }
00298     void output(FILE *ofp){
00299         for(int i=0; i<numOffset; i++)
00300             fprintf(ofp, "%d ", offset[i]);
00301         fprintf(ofp, "| %d | %d\n", tupleParamType, isReal);         
00302     }
00303   
00304     int hash() const {
00305       unsigned int code = tupleType;
00306       unsigned int codesz = 8 * sizeof(int);
00307       unsigned int shift = codesz / numOffset;
00308       
00309       if (shift == 0) shift=1;
00310       unsigned int i;
00311       for(i=0; i < numOffset; i++) {
00312         code = circShift(code,shift);
00313         code ^= offset[i];
00314       }
00315       return code;
00316     }
00317   
00318     void pack(MOStream *msg);
00319     void unpack(MIStream *msg);
00320 };
00321 
00322 //represents the signatures for atoms
00323 class AtomSignature{
00324 public:
00325     int bondCnt;
00326     int angleCnt;
00327     int dihedralCnt;
00328     int improperCnt;
00329     int crosstermCnt;
00330     // JLai
00331     int gromacsPairCnt;
00332 
00333     TupleSignature *bondSigs;
00334     TupleSignature *angleSigs;
00335     TupleSignature *dihedralSigs;
00336     TupleSignature *improperSigs;
00337     TupleSignature *crosstermSigs;
00338     // JLai
00339     TupleSignature *gromacsPairSigs;
00340 
00341     AtomSignature(){
00342         bondCnt=angleCnt=dihedralCnt=improperCnt=crosstermCnt=0;
00343         // JLai
00344         gromacsPairCnt=0;
00345         bondSigs = NULL;
00346         angleSigs = NULL;
00347         dihedralSigs = NULL;
00348         improperSigs = NULL;
00349         crosstermSigs = NULL;
00350         // JLai
00351         gromacsPairSigs = NULL;
00352     }
00353     AtomSignature(const AtomSignature &sig){
00354         bondSigs = NULL;
00355         angleSigs = NULL;
00356         dihedralSigs = NULL;
00357         improperSigs = NULL;
00358         crosstermSigs = NULL;
00359         // JLai
00360         gromacsPairSigs = NULL;
00361 
00362         bondCnt = sig.bondCnt;
00363         if(bondCnt>0){            
00364             bondSigs = new TupleSignature[bondCnt];
00365             for(int i=0; i<bondCnt; i++)
00366                 bondSigs[i] = sig.bondSigs[i];
00367         }
00368 
00369         angleCnt = sig.angleCnt;
00370         if(angleCnt>0){            
00371             angleSigs = new TupleSignature[angleCnt];
00372             for(int i=0; i<angleCnt; i++)
00373                 angleSigs[i] = sig.angleSigs[i];
00374         }
00375         
00376         dihedralCnt = sig.dihedralCnt;
00377         if(dihedralCnt>0){            
00378             dihedralSigs = new TupleSignature[dihedralCnt];
00379             for(int i=0; i<dihedralCnt; i++)
00380                 dihedralSigs[i] = sig.dihedralSigs[i];
00381         }
00382         
00383         improperCnt = sig.improperCnt;
00384         if(improperCnt>0){
00385             improperSigs = new TupleSignature[improperCnt];
00386             for(int i=0; i<improperCnt; i++)
00387                 improperSigs[i] = sig.improperSigs[i];
00388         }      
00389 
00390         crosstermCnt = sig.crosstermCnt;
00391         if(crosstermCnt>0){
00392             crosstermSigs = new TupleSignature[crosstermCnt];
00393             for(int i=0; i<crosstermCnt; i++)
00394                 crosstermSigs[i] = sig.crosstermSigs[i];
00395         }        
00396 
00397         // JLai
00398         gromacsPairCnt = sig.gromacsPairCnt;
00399         if(gromacsPairCnt>0){
00400             gromacsPairSigs = new TupleSignature[gromacsPairCnt];
00401             for(int i=0; i<gromacsPairCnt; i++) {
00402                 gromacsPairSigs[i] = sig.gromacsPairSigs[i];
00403             }
00404         }
00405     }
00406     AtomSignature& operator=(const AtomSignature& sig){        
00407         bondCnt = sig.bondCnt;
00408         if(bondSigs) delete [] bondSigs;
00409         if(bondCnt>0){
00410             bondSigs = new TupleSignature[bondCnt];
00411             for(int i=0; i<bondCnt; i++)
00412                 bondSigs[i] = sig.bondSigs[i];
00413         }else
00414             bondSigs = NULL;
00415 
00416         angleCnt = sig.angleCnt;
00417         if(angleSigs) delete [] angleSigs;
00418         if(angleCnt>0){
00419             angleSigs = new TupleSignature[angleCnt];
00420             for(int i=0; i<angleCnt; i++)
00421                 angleSigs[i] = sig.angleSigs[i];
00422         }else
00423             angleSigs = NULL;
00424         
00425         dihedralCnt = sig.dihedralCnt;
00426         if(dihedralSigs) delete [] dihedralSigs;
00427         if(dihedralCnt>0){
00428             dihedralSigs = new TupleSignature[dihedralCnt];
00429             for(int i=0; i<dihedralCnt; i++)
00430                 dihedralSigs[i] = sig.dihedralSigs[i];
00431         }else
00432             dihedralSigs = NULL;
00433         
00434         improperCnt = sig.improperCnt;
00435         if(improperSigs) delete [] improperSigs;
00436         if(improperCnt>0){
00437             improperSigs = new TupleSignature[improperCnt];
00438             for(int i=0; i<improperCnt; i++)
00439                 improperSigs[i] = sig.improperSigs[i];
00440         }else
00441             improperSigs = NULL;      
00442 
00443         crosstermCnt = sig.crosstermCnt;
00444         if(crosstermSigs) delete [] crosstermSigs;
00445         if(crosstermCnt>0){
00446             crosstermSigs = new TupleSignature[crosstermCnt];
00447             for(int i=0; i<crosstermCnt; i++)
00448                 crosstermSigs[i] = sig.crosstermSigs[i];
00449         }else
00450             crosstermSigs = NULL;
00451 
00452         // JLai
00453         gromacsPairCnt = sig.gromacsPairCnt;
00454         if(gromacsPairSigs) delete [] gromacsPairSigs;
00455         if(gromacsPairCnt>0){
00456             gromacsPairSigs = new TupleSignature[gromacsPairCnt];
00457             for(int i=0; i<gromacsPairCnt; i++)
00458                 gromacsPairSigs[i] = sig.gromacsPairSigs[i];
00459         }else
00460             gromacsPairSigs = NULL;
00461 
00462         return *this;
00463     }
00464     int operator==(const AtomSignature& sig) const{
00465             if(bondCnt!=sig.bondCnt) return 0;
00466             if(angleCnt!=sig.angleCnt) return 0;
00467             if(dihedralCnt!=sig.dihedralCnt) return 0;
00468             if(improperCnt!=sig.improperCnt) return 0;
00469             if(crosstermCnt!=sig.crosstermCnt) return 0;
00470             //JLai
00471             if(gromacsPairCnt!=sig.gromacsPairCnt) return 0;
00472         
00473         #define CMPSIGS(TUPLE) \
00474         for(int i=0; i<sig.TUPLE##Cnt; i++){ \
00475             if(!(TUPLE##Sigs[i]==sig.TUPLE##Sigs[i])) return 0; \
00476         } \
00477         
00478             CMPSIGS(bond)
00479             CMPSIGS(angle)
00480             CMPSIGS(dihedral)
00481             CMPSIGS(improper)
00482             CMPSIGS(crossterm)
00483             // JLai
00484             CMPSIGS(gromacsPair)
00485         
00486             return 1;
00487         }
00488     ~AtomSignature(){
00489         if(bondSigs) delete[] bondSigs;
00490         if(angleSigs) delete[] angleSigs;
00491         if(dihedralSigs) delete[] dihedralSigs;
00492         if(improperSigs) delete[] improperSigs;
00493         if(crosstermSigs) delete[] crosstermSigs;
00494         // JLai
00495         if(gromacsPairSigs) delete[] gromacsPairSigs;
00496     }    
00497 
00498     void removeEmptyTupleSigs();
00499     void pack(MOStream *msg);
00500     void unpack(MIStream *msg);
00501 };
00502 
00503 struct AtomNameIdx{
00504     Index resnameIdx;
00505     Index atomnameIdx;
00506     Index atomtypeIdx;
00507 };
00508 struct AtomCstInfo{
00509     Index vdw_type;
00510     int32 status;
00511     int32 partner;
00512     int32 hydrogenList;
00513 };
00514 
00515 struct ExclusionSignature{
00516     int fullExclCnt; //1-2, 1-3 exclusion
00517     int *fullOffset; //should be in increasing order
00518     int modExclCnt; //1-4 exclusion
00519     int *modOffset; //should be in increasing order
00520 #ifdef NAMD_CUDA
00521     int allExclCnt;
00522     TupleSignature *allTuples;
00523 #endif
00524 
00525     ExclusionSignature(){
00526         fullExclCnt = modExclCnt = 0;
00527         fullOffset = modOffset = NULL;
00528 #ifdef NAMD_CUDA
00529         allExclCnt = 0;
00530         allTuples = NULL;
00531 #endif
00532     }    
00533     ExclusionSignature(const ExclusionSignature& sig){
00534         fullOffset = modOffset = NULL;
00535         fullExclCnt = sig.fullExclCnt;
00536         if(fullExclCnt>0){
00537             fullOffset = new int[fullExclCnt];
00538             for(int i=0; i<fullExclCnt; i++)
00539                 fullOffset[i] = sig.fullOffset[i];
00540         }
00541         
00542         modExclCnt = sig.modExclCnt;
00543         if(modExclCnt>0){
00544             modOffset = new int[modExclCnt];
00545             for(int i=0; i<modExclCnt; i++)
00546                 modOffset[i] = sig.modOffset[i];
00547         }
00548 #ifdef NAMD_CUDA
00549         allTuples = NULL;
00550         allExclCnt = sig.allExclCnt;
00551         if(allExclCnt>0){
00552             allTuples = new TupleSignature[allExclCnt];
00553             for(int i=0; i<allExclCnt; i++)
00554                 allTuples[i] = sig.allTuples[i];
00555         }
00556 #endif
00557     }
00558     ~ExclusionSignature(){
00559         if(fullOffset) delete [] fullOffset;
00560         if(modOffset) delete [] modOffset;
00561 #ifdef NAMD_CUDA
00562         if(allTuples) delete [] allTuples;
00563 #endif
00564     }
00565     
00566     ExclusionSignature& operator=(const ExclusionSignature& sig){
00567         fullExclCnt = sig.fullExclCnt;
00568         if(fullOffset) delete [] fullOffset;
00569         if(fullExclCnt>0){
00570             fullOffset = new int[fullExclCnt];
00571             for(int i=0; i<fullExclCnt; i++)
00572                 fullOffset[i] = sig.fullOffset[i];
00573         }else
00574             fullOffset = NULL;
00575     
00576         modExclCnt = sig.modExclCnt;
00577         if(modOffset) delete [] modOffset;
00578         if(modExclCnt>0){
00579             modOffset = new int[modExclCnt];
00580             for(int i=0; i<modExclCnt; i++)
00581                 modOffset[i] = sig.modOffset[i];
00582         }else
00583             modOffset = NULL;
00584 #ifdef NAMD_CUDA
00585         allExclCnt = sig.allExclCnt;
00586         if(allTuples) delete [] allTuples;
00587         if(allExclCnt>0){
00588             allTuples = new TupleSignature[allExclCnt];
00589             for(int i=0; i<allExclCnt; i++)
00590                 allTuples[i] = sig.allTuples[i];
00591         }else
00592             allTuples = NULL;
00593 #endif
00594 
00595         return *this;
00596     }
00597         int operator==(const ExclusionSignature& sig) const{
00598             if(fullExclCnt!=sig.fullExclCnt) return 0;
00599             if(modExclCnt!=sig.modExclCnt) return 0;
00600             
00601             for(int i=0; i<fullExclCnt; i++){
00602                         if(fullOffset[i]!=sig.fullOffset[i]) return 0;
00603             }
00604             for(int i=0; i<modExclCnt; i++){
00605                         if(modOffset[i]!=sig.modOffset[i]) return 0;
00606             }
00607             return 1;
00608         }
00609     //both input should be sorted in increasing order
00610     void setOffsets(std::vector<int>& fullVec, std::vector<int>& modVec){
00611         fullExclCnt = fullVec.size();
00612         modExclCnt = modVec.size();
00613         if(fullExclCnt>0) {        
00614             fullOffset = new int[fullExclCnt];
00615             for(int i=0; i<fullExclCnt; i++)
00616                 fullOffset[i] = fullVec[i];
00617         }
00618 
00619         if(modExclCnt>0) {        
00620             modOffset = new int[modExclCnt];
00621             for(int i=0; i<modExclCnt; i++)
00622                 modOffset[i] = modVec[i];       
00623         }
00624 #ifdef NAMD_CUDA
00625         buildTuples();
00626     }
00627     void buildTuples() {
00628         delete [] allTuples;
00629         allTuples = NULL;
00630         allExclCnt = 0;
00631         for(int i=0; i<fullExclCnt; i++)
00632             if ( fullOffset[i] > 0 ) ++allExclCnt;
00633         for(int i=0; i<modExclCnt; i++)
00634             if ( modOffset[i] > 0 ) ++allExclCnt;
00635         if(allExclCnt>0){
00636             allTuples = new TupleSignature[allExclCnt];
00637             int j = 0;
00638             for(int i=0; i<fullExclCnt; i++){
00639                 if ( fullOffset[i] <= 0 ) continue;
00640                 TupleSignature oneSig(1,EXCLUSION,0);
00641                 oneSig.offset[0] = fullOffset[i];
00642                 allTuples[j++] = oneSig;
00643             }
00644             for(int i=0; i<modExclCnt; i++){
00645                 if ( modOffset[i] <= 0 ) continue;
00646                 TupleSignature oneSig(1,EXCLUSION,1);
00647                 oneSig.offset[0] = modOffset[i];
00648                 allTuples[j++] = oneSig;
00649             }
00650         }
00651 #endif
00652     }
00653 
00654     int hash() const {
00655       unsigned int numOffset = fullExclCnt + modExclCnt;
00656       unsigned int code = 0x12345678;
00657       unsigned int codesz = 8 * sizeof(int);
00658       unsigned int shift = codesz / numOffset;
00659     
00660       if (shift == 0) shift=1;
00661       unsigned int i;
00662       for(i=0; i < fullExclCnt; i++) {
00663         code = circShift(code,shift);
00664         code ^= fullOffset[i];
00665       }
00666       for(i=0; i < modExclCnt; i++) {
00667         code = circShift(code,shift);
00668         code ^= modOffset[i];
00669       }
00670       return code;
00671     }
00672   
00673   void removeEmptyOffset();
00674     //assuming offsets in the signature have been sorted increasingly
00675     int findOffset(int offset, int  *fullOrMod);
00676     void pack(MOStream *msg);
00677     void unpack(MIStream *msg);
00678 };
00679 
00680 #endif
00681 

Generated on Thu Sep 20 01:17:17 2018 for NAMD by  doxygen 1.4.7