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