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 #define DrudeAtom 0x80
00025
00026
00027 typedef unsigned short Index;
00028
00029
00030 typedef struct atom_name_info
00031 {
00032 char *resname;
00033 char *atomname;
00034 char *atomtype;
00035 } AtomNameInfo;
00036
00037 typedef struct atom_constants
00038 {
00039 Real mass;
00040 Real charge;
00041 Index vdw_type;
00042 int32 status;
00043 int32 partner;
00044 int32 hydrogenList;
00045 } Atom;
00046
00047 typedef struct bond
00048 {
00049 int32 atom1;
00050 int32 atom2;
00051 Index bond_type;
00052 } Bond;
00053
00054 typedef struct angle
00055 {
00056 int32 atom1;
00057 int32 atom2;
00058 int32 atom3;
00059 Index angle_type;
00060 } Angle;
00061
00062 typedef struct dihedral
00063 {
00064 int32 atom1;
00065 int32 atom2;
00066 int32 atom3;
00067 int32 atom4;
00068 Index dihedral_type;
00069 } Dihedral;
00070
00071 typedef struct improper
00072 {
00073 int32 atom1;
00074 int32 atom2;
00075 int32 atom3;
00076 int32 atom4;
00077 Index improper_type;
00078 } Improper;
00079
00080 typedef struct crossterm
00081 {
00082 int32 atom1;
00083 int32 atom2;
00084 int32 atom3;
00085 int32 atom4;
00086 int32 atom5;
00087 int32 atom6;
00088 int32 atom7;
00089 int32 atom8;
00090 Index crossterm_type;
00091 } Crossterm;
00092
00093
00094
00095 typedef struct drude_constants
00096 {
00097 Real alpha;
00098 Real thole;
00099 } DrudeConst;
00100
00101 typedef struct lphost
00102 {
00103 int32 atom1;
00104 int32 atom2;
00105 int32 atom3;
00106 int32 atom4;
00107 Real distance;
00108 Real angle;
00109 Real dihedral;
00110 } Lphost;
00111
00112 typedef struct aniso
00113 {
00114 int32 atom1;
00115 int32 atom2;
00116 int32 atom3;
00117 int32 atom4;
00118 Real k11;
00119 Real k22;
00120 Real k33;
00121 } Aniso;
00122
00123
00124
00125 class Exclusion
00126 {
00127 public:
00128 Exclusion(void) : modified(0) {;}
00129 Exclusion(int a1, int a2, int mod = 0) :
00130 atom1(a1), atom2(a2), modified(mod) {;}
00131 int32 atom1;
00132 int32 atom2;
00133 Index modified;
00134 int hash(void) const
00135 {
00136 return atom1 + atom2;
00137 }
00138 int operator==(const Exclusion &o) const
00139 {
00140 return atom1 == o.atom1 && atom2 == o.atom2;
00141 }
00142 int operator<(const Exclusion &o) const
00143 {
00144 return
00145 (
00146 ( atom1 < o.atom1 ) ||
00147 ( atom1 == o.atom1 && atom2 < o.atom2 )
00148 );
00149 }
00150 };
00151
00152
00153 class MOStream;
00154 class MIStream;
00155
00156 enum TupleSigType {BOND=0, ANGLE, DIHEDRAL, IMPROPER, DONOR, ACCEPTOR, CROSSTERM, EXCLUSION};
00157
00158 inline unsigned int circShift(unsigned int h, unsigned int by) {
00159 const unsigned int intBits=8*sizeof(unsigned int);
00160 by%=intBits;
00161 return (h<<by)|(h>>(intBits-by));
00162 }
00163
00164 class TupleSignature{
00165 public:
00166
00167 TupleSigType tupleType;
00168 int numOffset;
00169
00170 int *offset;
00171
00172
00173
00174 Index tupleParamType;
00175
00176
00177
00178
00179 char isReal;
00180
00181 public:
00182 TupleSignature(){
00183 offset = NULL;
00184 isReal = 1;
00185 }
00186
00187 TupleSignature(int n, TupleSigType t, Index paramType, char ir=1){
00188 tupleType = t;
00189 numOffset = n;
00190 offset = new int[n];
00191 tupleParamType = paramType;
00192 isReal = ir;
00193 }
00194 TupleSignature(const TupleSignature& oneSig){
00195 tupleType = oneSig.tupleType;
00196 numOffset = oneSig.numOffset;
00197 offset = new int[numOffset];
00198 setOffsets(oneSig.offset);
00199 tupleParamType = oneSig.tupleParamType;
00200 isReal = oneSig.isReal;
00201 }
00202 TupleSignature &operator=(const TupleSignature& oneSig){
00203 tupleType = oneSig.tupleType;
00204 numOffset = oneSig.numOffset;
00205 if(offset) delete [] offset;
00206 offset = new int[numOffset];
00207 setOffsets(oneSig.offset);
00208 tupleParamType = oneSig.tupleParamType;
00209 isReal = oneSig.isReal;
00210 return *this;
00211 }
00212 int operator==(const TupleSignature& sig) const{
00213 if(tupleType!=sig.tupleType)
00214 return 0;
00215
00216 if(tupleParamType != sig.tupleParamType)
00217 return 0;
00218
00219 if(isReal != sig.isReal)
00220 return 0;
00221
00222 if(numOffset != sig.numOffset) return 0;
00223
00224 int equalCnt=0;
00225
00226 for(int i=0; i<numOffset; i++){
00227 equalCnt += (offset[i]==sig.offset[i]);
00228 }
00229 return equalCnt==numOffset;
00230 }
00231 ~TupleSignature(){
00232 if(offset) delete[] offset;
00233 }
00234 void setOffsets(int *offs){
00235 for(int i=0; i<numOffset; i++)
00236 offset[i] = offs[i];
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 }
00264 void setEmpty(){
00265 delete [] offset;
00266 offset = NULL;
00267 }
00268 int isEmpty(){
00269 return offset==NULL;
00270 }
00271 void output(FILE *ofp){
00272 for(int i=0; i<numOffset; i++)
00273 fprintf(ofp, "%d ", offset[i]);
00274 fprintf(ofp, "| %d | %d\n", tupleParamType, isReal);
00275 }
00276
00277 int hash() const {
00278 unsigned int code = tupleType;
00279 unsigned int codesz = 8 * sizeof(int);
00280 unsigned int shift = codesz / numOffset;
00281
00282 if (shift == 0) shift=1;
00283 unsigned int i;
00284 for(i=0; i < numOffset; i++) {
00285 code = circShift(code,shift);
00286 code ^= offset[i];
00287 }
00288 return code;
00289 }
00290
00291 void pack(MOStream *msg);
00292 void unpack(MIStream *msg);
00293 };
00294
00295
00296 class AtomSignature{
00297 public:
00298 int bondCnt;
00299 int angleCnt;
00300 int dihedralCnt;
00301 int improperCnt;
00302 int crosstermCnt;
00303
00304 TupleSignature *bondSigs;
00305 TupleSignature *angleSigs;
00306 TupleSignature *dihedralSigs;
00307 TupleSignature *improperSigs;
00308 TupleSignature *crosstermSigs;
00309
00310 AtomSignature(){
00311 bondCnt=angleCnt=dihedralCnt=improperCnt=crosstermCnt=0;
00312 bondSigs = NULL;
00313 angleSigs = NULL;
00314 dihedralSigs = NULL;
00315 improperSigs = NULL;
00316 crosstermSigs = NULL;
00317 }
00318 AtomSignature(const AtomSignature &sig){
00319 bondSigs = NULL;
00320 angleSigs = NULL;
00321 dihedralSigs = NULL;
00322 improperSigs = NULL;
00323 crosstermSigs = NULL;
00324
00325 bondCnt = sig.bondCnt;
00326 if(bondCnt>0){
00327 bondSigs = new TupleSignature[bondCnt];
00328 for(int i=0; i<bondCnt; i++)
00329 bondSigs[i] = sig.bondSigs[i];
00330 }
00331
00332 angleCnt = sig.angleCnt;
00333 if(angleCnt>0){
00334 angleSigs = new TupleSignature[angleCnt];
00335 for(int i=0; i<angleCnt; i++)
00336 angleSigs[i] = sig.angleSigs[i];
00337 }
00338
00339 dihedralCnt = sig.dihedralCnt;
00340 if(dihedralCnt>0){
00341 dihedralSigs = new TupleSignature[dihedralCnt];
00342 for(int i=0; i<dihedralCnt; i++)
00343 dihedralSigs[i] = sig.dihedralSigs[i];
00344 }
00345
00346 improperCnt = sig.improperCnt;
00347 if(improperCnt>0){
00348 improperSigs = new TupleSignature[improperCnt];
00349 for(int i=0; i<improperCnt; i++)
00350 improperSigs[i] = sig.improperSigs[i];
00351 }
00352
00353 crosstermCnt = sig.crosstermCnt;
00354 if(crosstermCnt>0){
00355 crosstermSigs = new TupleSignature[crosstermCnt];
00356 for(int i=0; i<crosstermCnt; i++)
00357 crosstermSigs[i] = sig.crosstermSigs[i];
00358 }
00359 }
00360 AtomSignature& operator=(const AtomSignature& sig){
00361 bondCnt = sig.bondCnt;
00362 if(bondSigs) delete [] bondSigs;
00363 if(bondCnt>0){
00364 bondSigs = new TupleSignature[bondCnt];
00365 for(int i=0; i<bondCnt; i++)
00366 bondSigs[i] = sig.bondSigs[i];
00367 }else
00368 bondSigs = NULL;
00369
00370 angleCnt = sig.angleCnt;
00371 if(angleSigs) delete [] angleSigs;
00372 if(angleCnt>0){
00373 angleSigs = new TupleSignature[angleCnt];
00374 for(int i=0; i<angleCnt; i++)
00375 angleSigs[i] = sig.angleSigs[i];
00376 }else
00377 angleSigs = NULL;
00378
00379 dihedralCnt = sig.dihedralCnt;
00380 if(dihedralSigs) delete [] dihedralSigs;
00381 if(dihedralCnt>0){
00382 dihedralSigs = new TupleSignature[dihedralCnt];
00383 for(int i=0; i<dihedralCnt; i++)
00384 dihedralSigs[i] = sig.dihedralSigs[i];
00385 }else
00386 dihedralSigs = NULL;
00387
00388 improperCnt = sig.improperCnt;
00389 if(improperSigs) delete [] improperSigs;
00390 if(improperCnt>0){
00391 improperSigs = new TupleSignature[improperCnt];
00392 for(int i=0; i<improperCnt; i++)
00393 improperSigs[i] = sig.improperSigs[i];
00394 }else
00395 improperSigs = NULL;
00396
00397 crosstermCnt = sig.crosstermCnt;
00398 if(crosstermSigs) delete [] crosstermSigs;
00399 if(crosstermCnt>0){
00400 crosstermSigs = new TupleSignature[crosstermCnt];
00401 for(int i=0; i<crosstermCnt; i++)
00402 crosstermSigs[i] = sig.crosstermSigs[i];
00403 }else
00404 crosstermSigs = NULL;
00405
00406 return *this;
00407 }
00408 int operator==(const AtomSignature& sig) const{
00409 if(bondCnt!=sig.bondCnt) return 0;
00410 if(angleCnt!=sig.angleCnt) return 0;
00411 if(dihedralCnt!=sig.dihedralCnt) return 0;
00412 if(improperCnt!=sig.improperCnt) return 0;
00413 if(crosstermCnt!=sig.crosstermCnt) return 0;
00414
00415 #define CMPSIGS(TUPLE) \
00416 for(int i=0; i<sig.TUPLE##Cnt; i++){ \
00417 if(!(TUPLE##Sigs[i]==sig.TUPLE##Sigs[i])) return 0; \
00418 } \
00419
00420 CMPSIGS(bond)
00421 CMPSIGS(angle)
00422 CMPSIGS(dihedral)
00423 CMPSIGS(improper)
00424 CMPSIGS(crossterm)
00425
00426 return 1;
00427 }
00428 ~AtomSignature(){
00429 if(bondSigs) delete[] bondSigs;
00430 if(angleSigs) delete[] angleSigs;
00431 if(dihedralSigs) delete[] dihedralSigs;
00432 if(improperSigs) delete[] improperSigs;
00433 if(crosstermSigs) delete[] crosstermSigs;
00434 }
00435
00436 void removeEmptyTupleSigs();
00437 void pack(MOStream *msg);
00438 void unpack(MIStream *msg);
00439 };
00440
00441 struct AtomNameIdx{
00442 Index resnameIdx;
00443 Index atomnameIdx;
00444 Index atomtypeIdx;
00445 };
00446 struct AtomCstInfo{
00447 Index vdw_type;
00448 int32 status;
00449 int32 partner;
00450 int32 hydrogenList;
00451 };
00452
00453 struct ExclusionSignature{
00454 int fullExclCnt;
00455 int *fullOffset;
00456 int modExclCnt;
00457 int *modOffset;
00458
00459 ExclusionSignature(){
00460 fullExclCnt = modExclCnt = 0;
00461 fullOffset = modOffset = NULL;
00462 }
00463 ExclusionSignature(const ExclusionSignature& sig){
00464 fullOffset = modOffset = NULL;
00465 fullExclCnt = sig.fullExclCnt;
00466 if(fullExclCnt>0){
00467 fullOffset = new int[fullExclCnt];
00468 for(int i=0; i<fullExclCnt; i++)
00469 fullOffset[i] = sig.fullOffset[i];
00470 }
00471
00472 modExclCnt = sig.modExclCnt;
00473 if(modExclCnt>0){
00474 modOffset = new int[modExclCnt];
00475 for(int i=0; i<modExclCnt; i++)
00476 modOffset[i] = sig.modOffset[i];
00477 }
00478 }
00479 ~ExclusionSignature(){
00480 if(fullOffset) delete [] fullOffset;
00481 if(modOffset) delete [] modOffset;
00482 }
00483
00484 ExclusionSignature& operator=(const ExclusionSignature& sig){
00485 fullExclCnt = sig.fullExclCnt;
00486 if(fullOffset) delete [] fullOffset;
00487 if(fullExclCnt>0){
00488 fullOffset = new int[fullExclCnt];
00489 for(int i=0; i<fullExclCnt; i++)
00490 fullOffset[i] = sig.fullOffset[i];
00491 }else
00492 fullOffset = NULL;
00493
00494 modExclCnt = sig.modExclCnt;
00495 if(modOffset) delete [] modOffset;
00496 if(modExclCnt>0){
00497 modOffset = new int[modExclCnt];
00498 for(int i=0; i<modExclCnt; i++)
00499 modOffset[i] = sig.modOffset[i];
00500 }else
00501 modOffset = NULL;
00502
00503 return *this;
00504 }
00505 int operator==(const ExclusionSignature& sig) const{
00506 if(fullExclCnt!=sig.fullExclCnt) return 0;
00507 if(modExclCnt!=sig.modExclCnt) return 0;
00508
00509 for(int i=0; i<fullExclCnt; i++){
00510 if(fullOffset[i]!=sig.fullOffset[i]) return 0;
00511 }
00512 for(int i=0; i<modExclCnt; i++){
00513 if(modOffset[i]!=sig.modOffset[i]) return 0;
00514 }
00515 return 1;
00516 }
00517
00518 void setOffsets(vector<int>& fullVec, vector<int>& modVec){
00519 fullExclCnt = fullVec.size();
00520 modExclCnt = modVec.size();
00521 if(fullExclCnt>0) {
00522 fullOffset = new int[fullExclCnt];
00523 for(int i=0; i<fullExclCnt; i++)
00524 fullOffset[i] = fullVec[i];
00525 }
00526
00527 if(modExclCnt>0) {
00528 modOffset = new int[modExclCnt];
00529 for(int i=0; i<modExclCnt; i++)
00530 modOffset[i] = modVec[i];
00531 }
00532 }
00533
00534 int hash() const {
00535 unsigned int numOffset = fullExclCnt + modExclCnt;
00536 unsigned int code = 0x12345678;
00537 unsigned int codesz = 8 * sizeof(int);
00538 unsigned int shift = codesz / numOffset;
00539
00540 if (shift == 0) shift=1;
00541 unsigned int i;
00542 for(i=0; i < fullExclCnt; i++) {
00543 code = circShift(code,shift);
00544 code ^= fullOffset[i];
00545 }
00546 for(i=0; i < modExclCnt; i++) {
00547 code = circShift(code,shift);
00548 code ^= modOffset[i];
00549 }
00550 return code;
00551 }
00552
00553 void removeEmptyOffset();
00554
00555 int findOffset(int offset, int *fullOrMod);
00556 void pack(MOStream *msg);
00557 void unpack(MIStream *msg);
00558 };
00559
00560 #endif
00561