NAMD
structures.h
Go to the documentation of this file.
1 
7 #ifndef STRUCTURES_H
8 #define STRUCTURES_H
9 
10 #include "common.h"
11 #include <vector>
12 
13 
14 // status elements, used for Atom status
15 #define UnknownAtom 0x00
16 #define HydrogenAtom 0x01
17 #define OxygenAtom 0x02
18 #define HBDonorAtom 0x04
19 #define HBAcceptorAtom 0x08
20 #define HBAntecedentAtom 0x10
21 #define HBHydrogenAtom 0x20
22 #define LonepairAtom 0x40
23 #define DrudeAtom 0x80
24 
25 
26 typedef int Index; // Used for index into arrays
27  // or parameters
28 
29 typedef struct atom_name_info
30 {
31  char *resname;
32  char *atomname;
33  char *atomtype;
34 } AtomNameInfo;
35 
36 typedef struct atom_constants
37 {
41  int32 status; // flags telling about this atom
42  int32 partner; // connecting atom, for hydrogens
43  int32 hydrogenList; // index of atom in hydrogenGroup list
44 } Atom;
45 
46 typedef struct bond
47 {
51 } Bond;
52 
53 typedef struct angle
54 {
59 } Angle;
60 
61 typedef struct dihedral
62 {
68 } Dihedral;
69 
70 typedef struct improper
71 {
77 } Improper;
78 
79 typedef struct crossterm
80 {
90 } Crossterm;
91 
92 typedef struct gromacsPair
93 {
99 } GromacsPair;
100 
101 
102 // DRUDE: data read from PSF
103 typedef struct drude_constants // supplement Atom data
104 { // create array length N of these
107 } DrudeConst;
108 
118 typedef struct lphost
119 {
128 } Lphost;
129 
130 typedef struct aniso // anisotropic term
131 {
139 } Aniso;
140 
141 typedef struct thole // Thole terms - constructed implicitly from exclusions
142 {
143  int32 atom1; // first heavy atom
144  int32 atom2; // Drude particle of first heavy atom
145  int32 atom3; // second heavy atom
146  int32 atom4; // Drude particle of second heavy atom
147  Real aa; // constant (alpha_i * alpha_j)^(-6) / (thole_i + thole_j)
148  Real qq; // combined charge of Drudes (C * q_{i+1} * q_{j+1})
149 } Thole;
150 // DRUDE
151 
152 
154 {
155 public:
156  Exclusion(void) : modified(0) {;}
157  Exclusion(int a1, int a2, int mod = 0) :
158  atom1(a1), atom2(a2), modified(mod) {;}
162  int hash(void) const
163  {
164  return atom1 + atom2;
165  }
166  int operator==(const Exclusion &o) const
167  {
168  return atom1 == o.atom1 && atom2 == o.atom2;
169  }
170  int operator<(const Exclusion &o) const
171  {
172  return
173  (
174  ( atom1 < o.atom1 ) ||
175  ( atom1 == o.atom1 && atom2 < o.atom2 )
176  );
177  }
178 };
179 
180 
181 class MOStream;
182 class MIStream;
183 
185 
186 inline unsigned int circShift(unsigned int h, unsigned int by) {
187  const unsigned int intBits=8*sizeof(unsigned int);
188  by%=intBits;
189  return (h<<by)|(h>>(intBits-by));
190 }
191 
193 public:
194  //This field indicates which class this tuple belongs to (bond or angle or ...)
197  //the relative offset from the atom index
198  int *offset;
199 
200  //This type is determined by the Parameter object
201  //for Exclusion, this indicates the modified field
203 
204  //indicate this tuple is specified in the psf file, not from other files.
205  //this is added due to the extraBonds feature. All tuples from extraBonds
206  //are not real!
207  char isReal;
208 
209 public:
211  offset = NULL;
212  isReal = 1;
213  }
214 
215  TupleSignature(int n, TupleSigType t, Index paramType, char ir=1){
216  tupleType = t;
217  numOffset = n;
218  offset = new int[n];
219  tupleParamType = paramType;
220  isReal = ir;
221  }
223  tupleType = oneSig.tupleType;
224  numOffset = oneSig.numOffset;
225  offset = new int[numOffset];
226  setOffsets(oneSig.offset);
228  isReal = oneSig.isReal;
229  }
231  tupleType = oneSig.tupleType;
232  numOffset = oneSig.numOffset;
233  if(offset) delete [] offset;
234  offset = new int[numOffset];
235  setOffsets(oneSig.offset);
237  isReal = oneSig.isReal;
238  return *this;
239  }
240  int operator==(const TupleSignature& sig) const{
241  if(tupleType!=sig.tupleType)
242  return 0;
243 
244  if(tupleParamType != sig.tupleParamType)
245  return 0;
246 
247  if(isReal != sig.isReal)
248  return 0;
249 
250  if(numOffset != sig.numOffset) return 0;
251 
252  int equalCnt=0;
253 
254  for(int i=0; i<numOffset; i++){
255  equalCnt += (offset[i]==sig.offset[i]);
256  }
257  return equalCnt==numOffset;
258  }
260  if(offset) delete[] offset;
261  }
262  void setOffsets(int *offs){
263  for(int i=0; i<numOffset; i++)
264  offset[i] = offs[i];
265  //sort the offset in increasing order
266  //based on the input files, this offset is almost sorted increasingly
267  //Therefore using insertion sort
268  /*switch(numOffset){
269  case 1:
270  break;
271  case 2:
272  if(offset[0]>offset[1]){
273  int tmp = offset[0];
274  offset[0] = offset[1];
275  offset[1] = tmp;
276  }
277  break;
278  default: //insertion sort
279  for(int ii=1; ii<numOffset; ii++){
280  int val = offset[ii];
281  for(int jj=ii-1; jj>=0; jj--){
282  if(offset[jj]<val){
283  offset[jj+1] = offset[jj];
284  offset[jj] = val;
285  }else
286  break;
287  }
288  }
289  }*/
290  }
291  void setEmpty(){
292  delete [] offset;
293  offset = NULL;
294  }
295  int isEmpty(){
296  return offset==NULL;
297  }
298  void output(FILE *ofp){
299  for(int i=0; i<numOffset; i++)
300  fprintf(ofp, "%d ", offset[i]);
301  fprintf(ofp, "| %d | %d\n", tupleParamType, isReal);
302  }
303 
304  int hash() const {
305  unsigned int code = tupleType;
306  unsigned int codesz = 8 * sizeof(int);
307  unsigned int shift = codesz / numOffset;
308 
309  if (shift == 0) shift=1;
310  unsigned int i;
311  for(i=0; i < numOffset; i++) {
312  code = circShift(code,shift);
313  code ^= offset[i];
314  }
315  return code;
316  }
317 
318  void pack(MOStream *msg);
319  void unpack(MIStream *msg);
320 };
321 
322 //represents the signatures for atoms
324 public:
325  int bondCnt;
326  int angleCnt;
330  // JLai
332 
338  // JLai
340 
343  // JLai
344  gromacsPairCnt=0;
345  bondSigs = NULL;
346  angleSigs = NULL;
347  dihedralSigs = NULL;
348  improperSigs = NULL;
349  crosstermSigs = NULL;
350  // JLai
351  gromacsPairSigs = NULL;
352  }
354  bondSigs = NULL;
355  angleSigs = NULL;
356  dihedralSigs = NULL;
357  improperSigs = NULL;
358  crosstermSigs = NULL;
359  // JLai
360  gromacsPairSigs = NULL;
361 
362  bondCnt = sig.bondCnt;
363  if(bondCnt>0){
365  for(int i=0; i<bondCnt; i++)
366  bondSigs[i] = sig.bondSigs[i];
367  }
368 
369  angleCnt = sig.angleCnt;
370  if(angleCnt>0){
372  for(int i=0; i<angleCnt; i++)
373  angleSigs[i] = sig.angleSigs[i];
374  }
375 
376  dihedralCnt = sig.dihedralCnt;
377  if(dihedralCnt>0){
379  for(int i=0; i<dihedralCnt; i++)
380  dihedralSigs[i] = sig.dihedralSigs[i];
381  }
382 
383  improperCnt = sig.improperCnt;
384  if(improperCnt>0){
386  for(int i=0; i<improperCnt; i++)
387  improperSigs[i] = sig.improperSigs[i];
388  }
389 
391  if(crosstermCnt>0){
393  for(int i=0; i<crosstermCnt; i++)
394  crosstermSigs[i] = sig.crosstermSigs[i];
395  }
396 
397  // JLai
399  if(gromacsPairCnt>0){
401  for(int i=0; i<gromacsPairCnt; i++) {
402  gromacsPairSigs[i] = sig.gromacsPairSigs[i];
403  }
404  }
405  }
407  bondCnt = sig.bondCnt;
408  if(bondSigs) delete [] bondSigs;
409  if(bondCnt>0){
411  for(int i=0; i<bondCnt; i++)
412  bondSigs[i] = sig.bondSigs[i];
413  }else
414  bondSigs = NULL;
415 
416  angleCnt = sig.angleCnt;
417  if(angleSigs) delete [] angleSigs;
418  if(angleCnt>0){
420  for(int i=0; i<angleCnt; i++)
421  angleSigs[i] = sig.angleSigs[i];
422  }else
423  angleSigs = NULL;
424 
425  dihedralCnt = sig.dihedralCnt;
426  if(dihedralSigs) delete [] dihedralSigs;
427  if(dihedralCnt>0){
429  for(int i=0; i<dihedralCnt; i++)
430  dihedralSigs[i] = sig.dihedralSigs[i];
431  }else
432  dihedralSigs = NULL;
433 
434  improperCnt = sig.improperCnt;
435  if(improperSigs) delete [] improperSigs;
436  if(improperCnt>0){
438  for(int i=0; i<improperCnt; i++)
439  improperSigs[i] = sig.improperSigs[i];
440  }else
441  improperSigs = NULL;
442 
444  if(crosstermSigs) delete [] crosstermSigs;
445  if(crosstermCnt>0){
447  for(int i=0; i<crosstermCnt; i++)
448  crosstermSigs[i] = sig.crosstermSigs[i];
449  }else
450  crosstermSigs = NULL;
451 
452  // JLai
454  if(gromacsPairSigs) delete [] gromacsPairSigs;
455  if(gromacsPairCnt>0){
457  for(int i=0; i<gromacsPairCnt; i++)
458  gromacsPairSigs[i] = sig.gromacsPairSigs[i];
459  }else
460  gromacsPairSigs = NULL;
461 
462  return *this;
463  }
464  int operator==(const AtomSignature& sig) const{
465  if(bondCnt!=sig.bondCnt) return 0;
466  if(angleCnt!=sig.angleCnt) return 0;
467  if(dihedralCnt!=sig.dihedralCnt) return 0;
468  if(improperCnt!=sig.improperCnt) return 0;
469  if(crosstermCnt!=sig.crosstermCnt) return 0;
470  //JLai
471  if(gromacsPairCnt!=sig.gromacsPairCnt) return 0;
472 
473  #define CMPSIGS(TUPLE) \
474  for(int i=0; i<sig.TUPLE##Cnt; i++){ \
475  if(!(TUPLE##Sigs[i]==sig.TUPLE##Sigs[i])) return 0; \
476  } \
477 
478  CMPSIGS(bond)
479  CMPSIGS(angle)
483  // JLai
485 
486  return 1;
487  }
489  if(bondSigs) delete[] bondSigs;
490  if(angleSigs) delete[] angleSigs;
491  if(dihedralSigs) delete[] dihedralSigs;
492  if(improperSigs) delete[] improperSigs;
493  if(crosstermSigs) delete[] crosstermSigs;
494  // JLai
495  if(gromacsPairSigs) delete[] gromacsPairSigs;
496  }
497 
498  void removeEmptyTupleSigs();
499  void pack(MOStream *msg);
500  void unpack(MIStream *msg);
501 };
502 
503 struct AtomNameIdx{
507 };
508 struct AtomCstInfo{
513 };
514 
516  int fullExclCnt; //1-2, 1-3 exclusion
517  int *fullOffset; //should be in increasing order
518  int modExclCnt; //1-4 exclusion
519  int *modOffset; //should be in increasing order
520 #ifdef NAMD_CUDA
523 #endif
524 
526  fullExclCnt = modExclCnt = 0;
527  fullOffset = modOffset = NULL;
528 #ifdef NAMD_CUDA
529  allExclCnt = 0;
530  allTuples = NULL;
531 #endif
532  }
534  fullOffset = modOffset = NULL;
535  fullExclCnt = sig.fullExclCnt;
536  if(fullExclCnt>0){
537  fullOffset = new int[fullExclCnt];
538  for(int i=0; i<fullExclCnt; i++)
539  fullOffset[i] = sig.fullOffset[i];
540  }
541 
542  modExclCnt = sig.modExclCnt;
543  if(modExclCnt>0){
544  modOffset = new int[modExclCnt];
545  for(int i=0; i<modExclCnt; i++)
546  modOffset[i] = sig.modOffset[i];
547  }
548 #ifdef NAMD_CUDA
549  allTuples = NULL;
550  allExclCnt = sig.allExclCnt;
551  if(allExclCnt>0){
553  for(int i=0; i<allExclCnt; i++)
554  allTuples[i] = sig.allTuples[i];
555  }
556 #endif
557  }
559  if(fullOffset) delete [] fullOffset;
560  if(modOffset) delete [] modOffset;
561 #ifdef NAMD_CUDA
562  if(allTuples) delete [] allTuples;
563 #endif
564  }
565 
567  fullExclCnt = sig.fullExclCnt;
568  if(fullOffset) delete [] fullOffset;
569  if(fullExclCnt>0){
570  fullOffset = new int[fullExclCnt];
571  for(int i=0; i<fullExclCnt; i++)
572  fullOffset[i] = sig.fullOffset[i];
573  }else
574  fullOffset = NULL;
575 
576  modExclCnt = sig.modExclCnt;
577  if(modOffset) delete [] modOffset;
578  if(modExclCnt>0){
579  modOffset = new int[modExclCnt];
580  for(int i=0; i<modExclCnt; i++)
581  modOffset[i] = sig.modOffset[i];
582  }else
583  modOffset = NULL;
584 #ifdef NAMD_CUDA
585  allExclCnt = sig.allExclCnt;
586  if(allTuples) delete [] allTuples;
587  if(allExclCnt>0){
589  for(int i=0; i<allExclCnt; i++)
590  allTuples[i] = sig.allTuples[i];
591  }else
592  allTuples = NULL;
593 #endif
594 
595  return *this;
596  }
597  int operator==(const ExclusionSignature& sig) const{
598  if(fullExclCnt!=sig.fullExclCnt) return 0;
599  if(modExclCnt!=sig.modExclCnt) return 0;
600 
601  for(int i=0; i<fullExclCnt; i++){
602  if(fullOffset[i]!=sig.fullOffset[i]) return 0;
603  }
604  for(int i=0; i<modExclCnt; i++){
605  if(modOffset[i]!=sig.modOffset[i]) return 0;
606  }
607  return 1;
608  }
609  //both input should be sorted in increasing order
610  void setOffsets(std::vector<int>& fullVec, std::vector<int>& modVec){
611  fullExclCnt = fullVec.size();
612  modExclCnt = modVec.size();
613  if(fullExclCnt>0) {
614  fullOffset = new int[fullExclCnt];
615  for(int i=0; i<fullExclCnt; i++)
616  fullOffset[i] = fullVec[i];
617  }
618 
619  if(modExclCnt>0) {
620  modOffset = new int[modExclCnt];
621  for(int i=0; i<modExclCnt; i++)
622  modOffset[i] = modVec[i];
623  }
624 #ifdef NAMD_CUDA
625  buildTuples();
626  }
627  void buildTuples() {
628  delete [] allTuples;
629  allTuples = NULL;
630  allExclCnt = 0;
631  for(int i=0; i<fullExclCnt; i++)
632  if ( fullOffset[i] > 0 ) ++allExclCnt;
633  for(int i=0; i<modExclCnt; i++)
634  if ( modOffset[i] > 0 ) ++allExclCnt;
635  if(allExclCnt>0){
637  int j = 0;
638  for(int i=0; i<fullExclCnt; i++){
639  if ( fullOffset[i] <= 0 ) continue;
640  TupleSignature oneSig(1,EXCLUSION,0);
641  oneSig.offset[0] = fullOffset[i];
642  allTuples[j++] = oneSig;
643  }
644  for(int i=0; i<modExclCnt; i++){
645  if ( modOffset[i] <= 0 ) continue;
646  TupleSignature oneSig(1,EXCLUSION,1);
647  oneSig.offset[0] = modOffset[i];
648  allTuples[j++] = oneSig;
649  }
650  }
651 #endif
652  }
653 
654  int hash() const {
655  unsigned int numOffset = fullExclCnt + modExclCnt;
656  unsigned int code = 0x12345678;
657  unsigned int codesz = 8 * sizeof(int);
658  unsigned int shift = codesz / numOffset;
659 
660  if (shift == 0) shift=1;
661  unsigned int i;
662  for(i=0; i < fullExclCnt; i++) {
663  code = circShift(code,shift);
664  code ^= fullOffset[i];
665  }
666  for(i=0; i < modExclCnt; i++) {
667  code = circShift(code,shift);
668  code ^= modOffset[i];
669  }
670  return code;
671  }
672 
673  void removeEmptyOffset();
674  //assuming offsets in the signature have been sorted increasingly
675  int findOffset(int offset, int *fullOrMod);
676  void pack(MOStream *msg);
677  void unpack(MIStream *msg);
678 };
679 
680 #endif
681 
struct angle Angle
int32 atom3
Definition: structures.h:145
TupleSignature(const TupleSignature &oneSig)
Definition: structures.h:222
struct lphost Lphost
Index crossterm_type
Definition: structures.h:89
struct atom_name_info AtomNameInfo
int32 atom4
Definition: structures.h:75
Index improper_type
Definition: structures.h:76
Real k11
Definition: structures.h:136
int32 atom2
Definition: structures.h:160
int32 atom2
Definition: structures.h:133
int32 atom2
Definition: structures.h:121
short int32
Definition: dumpdcd.c:24
void pack(MOStream *msg)
int32 atom3
Definition: structures.h:134
int32 atom3
Definition: structures.h:65
TupleSignature * improperSigs
Definition: structures.h:336
int32 numhosts
Either 2 or 3 host atoms, depending on LP type.
Definition: structures.h:124
TupleSigType
Definition: structures.h:184
struct dihedral Dihedral
Real pairC6
Definition: structures.h:97
int operator<(const Exclusion &o) const
Definition: structures.h:170
void unpack(MIStream *msg)
struct bond Bond
TupleSignature * dihedralSigs
Definition: structures.h:335
float Real
Definition: common.h:107
int32 atom5
Definition: structures.h:85
Real dihedral
Definition: structures.h:127
Real distance
Definition: structures.h:125
int32 atom3
Definition: structures.h:122
struct crossterm Crossterm
int32 atom8
Definition: structures.h:88
ExclusionSignature(const ExclusionSignature &sig)
Definition: structures.h:533
TupleSignature * crosstermSigs
Definition: structures.h:337
int32 atom1
Definition: structures.h:81
void unpack(MIStream *msg)
int32 atom4
Definition: structures.h:84
int32 atom4
Definition: structures.h:146
Real pairC12
Definition: structures.h:96
TupleSignature * allTuples
Definition: structures.h:522
ExclusionSignature & operator=(const ExclusionSignature &sig)
Definition: structures.h:566
int32 atom3
Definition: structures.h:83
int32 atom2
Definition: structures.h:95
struct atom_constants Atom
int32 atom4
Definition: structures.h:123
int32 atom4
Definition: structures.h:66
int32 atom1
Definition: structures.h:48
int Index
Definition: structures.h:26
TupleSignature(int n, TupleSigType t, Index paramType, char ir=1)
Definition: structures.h:215
TupleSignature * gromacsPairSigs
Definition: structures.h:339
int32 atom1
First index is to the LP.
Definition: structures.h:120
void setOffsets(int *offs)
Definition: structures.h:262
void pack(MOStream *msg)
int operator==(const TupleSignature &sig) const
Definition: structures.h:240
Index modified
Definition: structures.h:161
int32 atom2
Definition: structures.h:144
struct thole Thole
int32 atom2
Definition: structures.h:82
Index resnameIdx
Definition: structures.h:504
Index dihedral_type
Definition: structures.h:67
int32 atom2
Definition: structures.h:56
int32 atom7
Definition: structures.h:87
char * resname
Definition: structures.h:31
int findOffset(int offset, int *fullOrMod)
char * atomtype
Definition: structures.h:33
AtomSignature & operator=(const AtomSignature &sig)
Definition: structures.h:406
int32 atom1
Definition: structures.h:55
TupleSigType tupleType
Definition: structures.h:195
int32 atom1
Definition: structures.h:143
int32 partner
Definition: structures.h:511
unsigned int circShift(unsigned int h, unsigned int by)
Definition: structures.h:186
int32 atom3
Definition: structures.h:57
int hash() const
Definition: structures.h:654
int32 hydrogenList
Definition: structures.h:43
void setEmpty()
Definition: structures.h:291
void removeEmptyTupleSigs()
TupleSignature * bondSigs
Definition: structures.h:333
int32 atom1
Definition: structures.h:159
#define CMPSIGS(TUPLE)
Index angle_type
Definition: structures.h:58
Index vdw_type
Definition: structures.h:509
Real k22
Definition: structures.h:137
Real qq
Definition: structures.h:148
int32 atom2
Definition: structures.h:64
AtomSignature(const AtomSignature &sig)
Definition: structures.h:353
Real aa
Definition: structures.h:147
Real angle
Definition: structures.h:126
int32 atom1
Definition: structures.h:72
struct aniso Aniso
Real k33
Definition: structures.h:138
Index vdw_type
Definition: structures.h:40
int32 atom1
Definition: structures.h:132
struct improper Improper
void setOffsets(std::vector< int > &fullVec, std::vector< int > &modVec)
Definition: structures.h:610
void output(FILE *ofp)
Definition: structures.h:298
Index tupleParamType
Definition: structures.h:202
int hash(void) const
Definition: structures.h:162
int32 atom2
Definition: structures.h:73
int32 atom6
Definition: structures.h:86
struct gromacsPair GromacsPair
struct drude_constants DrudeConst
Exclusion(void)
Definition: structures.h:156
void unpack(MIStream *msg)
int operator==(const ExclusionSignature &sig) const
Definition: structures.h:597
Index gromacsPair_type
Definition: structures.h:98
void pack(MOStream *msg)
int32 status
Definition: structures.h:510
Index bond_type
Definition: structures.h:50
int32 atom4
Definition: structures.h:135
int operator==(const AtomSignature &sig) const
Definition: structures.h:464
Index atomtypeIdx
Definition: structures.h:506
int32 hydrogenList
Definition: structures.h:512
int gromacsPairCnt
Definition: structures.h:331
Exclusion(int a1, int a2, int mod=0)
Definition: structures.h:157
int32 atom3
Definition: structures.h:74
TupleSignature * angleSigs
Definition: structures.h:334
int32 atom1
Definition: structures.h:63
TupleSignature & operator=(const TupleSignature &oneSig)
Definition: structures.h:230
int32 atom2
Definition: structures.h:49
Index atomnameIdx
Definition: structures.h:505
int hash() const
Definition: structures.h:304
char * atomname
Definition: structures.h:32
int operator==(const Exclusion &o) const
Definition: structures.h:166
int32 atom1
Definition: structures.h:94