00001
00007 #ifndef STRUCTURES_H
00008 #define STRUCTURES_H
00009
00010 #include "common.h"
00011 #include <vector>
00012 using namespace std;
00013
00014
00015
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;
00027
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;
00042 int32 partner;
00043 int32 hydrogenList;
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
00128 TupleSigType tupleType;
00129 int numOffset;
00130
00131 int *offset;
00132
00133
00134
00135 Index tupleParamType;
00136
00137
00138
00139
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
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
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
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;
00401 int *fullOffset;
00402 int modExclCnt;
00403 int *modOffset;
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
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
00482 int findOffset(int offset, int *fullOrMod);
00483 void pack(MOStream *msg);
00484 void unpack(MIStream *msg);
00485 };
00486
00487 #endif
00488