NAMD
common.h
Go to the documentation of this file.
1 
7 /*
8  common definitions for namd.
9 */
10 
11 #ifndef COMMON_H
12 #define COMMON_H
13 
14 #ifndef SEQUENCER_SOA
15 #define SEQUENCER_SOA
16 #endif
17 
18 // Check all bonds that have atom IDs in the range given below.
19 #if defined(DEBUG_PROTOCELL)
20 // Use Noah's default index range unless others are explicitly provided.
21 #ifndef PRMIN
22 #define PRMIN 23749759
23 #endif
24 #ifndef PRMAX
25 #define PRMAX 23749892
26 #endif
27 #endif
28 
29 #if !defined(WIN32) || defined(__CYGWIN__)
30 #include <unistd.h>
31 #endif
32 #include <stdio.h>
33 #include <climits>
34 #include <vector>
35 #include <cstdint>
36 typedef int8_t int8;
37 typedef int16_t int16;
38 typedef int32_t int32;
39 typedef int64_t int64;
40 typedef uint8_t uint8;
41 typedef uint16_t uint16;
42 typedef uint32_t uint32;
43 typedef uint64_t uint64;
44 
45 #define NAMD_FILENAME_BUFFER_SIZE 4096
46 
47 #if defined(PLACEMENT_NEW)
48 void * ::operator new (size_t, void *p) { return p; }
49 #elif defined(PLACEMENT_NEW_GLOBAL)
50 void * operator new (size_t, void *p) { return p; }
51 #endif
52 
53 #define COULOMB 332.0636
54 #define BOLTZMANN 0.001987191
55 #define TIMEFACTOR 48.88821
56 #define PRESSUREFACTOR 6.95E4
57 #define PDBVELFACTOR 20.45482706
58 #define PDBVELINVFACTOR (1.0/PDBVELFACTOR)
59 #define PNPERKCALMOL 69.479
60 
61 #define RECIP_TIMEFACTOR (1.0 / TIMEFACTOR)
62 
63 //
64 // Defining macro namdnearbyint(X).
65 //
66 // Some plagtforms don't have nearbyint or round, so we'll define one
67 // that works everywhere.
68 //
69 // Use namdnearbyint(X) instead of rint(X) because rint() is sensitive
70 // to the current rounding mode and floor() is not. It's just safer.
71 //
72 #ifdef ARCH_POWERPC
73 #ifdef POWERPC_TANINT
74 // round for BlueGeneQ (and others that set POWERPC_TANINT)
75 extern "builtin" double __tanint(double); // IEEE round
76 #define namdnearbyint(x) __tanint(x)
77 #else
78 // round for Linux POWER
79 #include <builtins.h>
80 #include <tgmath.h>
81 #define namdnearbyint(x) (round(x))
82 #endif
83 #else
84 // fall back should work everywhere
85 #define namdnearbyint(x) floor((x)+0.5)
86 #endif
87 //
88 // End defining macro namdnearbyint(X).
89 //
90 
91 #ifndef PI
92 #define PI 3.141592653589793
93 #endif
94 
95 #ifndef TWOPI
96 #define TWOPI 2.0 * PI
97 #endif
98 
99 #ifndef ONE
100 #define ONE 1.000000000000000
101 #endif
102 
103 #ifndef ZERO
104 #define ZERO 0.000000000000000
105 #endif
106 
107 #ifndef SMALLRAD
108 #define SMALLRAD 0.0005
109 #endif
110 
111 #ifndef SMALLRAD2
112 #define SMALLRAD2 SMALLRAD*SMALLRAD
113 #endif
114 
115 /* Define the size for Real and BigReal. Real is usually mapped to float */
116 /* and BigReal to double. To get BigReal mapped to float, use the */
117 /* -DSHORTREALS compile time option */
118 typedef float Real;
119 
120 #ifdef SHORTREALS
121 typedef float BigReal;
122 #else
123 typedef double BigReal;
124 #endif
125 
126 #ifndef FALSE
127 #define FALSE 0
128 #define TRUE 1
129 #endif
130 
131 #ifndef NO
132 #define NO 0
133 #define YES 1
134 #endif
135 
136 #ifndef STRINGNULL
137 #define STRINGNULL '\0'
138 #endif
139 
140 #define MAX_NEIGHBORS 27
141 
142 typedef int Bool;
143 
144 class Communicate;
145 
146 // provide NAMD version in similar way as done for Tcl
152 };
153 // pass address of int variables or NULL to disregard
154 // releaseType gets set to one of the above enum constants
155 void NAMD_version(int *major, int *minor, int *patchLevel, int *releaseType);
156 // obtain a pointer to the raw version string
157 const char *NAMD_version_string(void);
158 
159 // global functions
160 void NAMD_quit(const char *);
161 void NAMD_die(const char *);
162 void NAMD_err(const char *); // also prints strerror(errno)
163 void NAMD_bug(const char *);
164 int NAMD_file_exists(const char *filename);
165 void NAMD_backup_file(const char *filename, const char *extension = 0);
166 int NAMD_open_text(const char *fname, int append=0);
167 void NAMD_write(int fd, const char *buf, size_t count, const char *fname = "in NAMD_write()"); // NAMD_die on error
168 void NAMD_close(int fd, const char *fname);
169 char *NAMD_stringdup(const char *);
170 FILE *Fopen(const char *filename, const char *mode);
171 int Fclose(FILE *fout);
172 
173 //Math functions
174 int NAMD_gcd(int a, int b);
175 
176 // message tags
177 #define SIMPARAMSTAG 100 // Tag for SimParameters class
178 #define STATICPARAMSTAG 101 // Tag for Parameters class
179 #define MOLECULETAG 102 // Tag for Molecule class
180 #define FULLTAG 104
181 #define FULLFORCETAG 105
182 #define DPMTATAG 106
183 #define GRIDFORCEGRIDTAG 107
184 #define COMPUTEMAPTAG 108
185 
186 #define CYCLE_BARRIER 0
187 #define PME_BARRIER 0
188 #define STEP_BARRIER 0
189 
190 #define USE_BARRIER (CYCLE_BARRIER || PME_BARRIER || STEP_BARRIER)
191 
192 
194 
204 #define NAMD_SeparateWaters 0
205 
206 // DMK - Atom Sort
207 // Setting this define to a non-zero value will cause the nonbonded compute
208 // objects (pairs, not selfs) to sort the atoms along a line connecting the
209 // center of masses of the two patches. This is only done during timesteps
210 // where the pairlists are being generated. As the pairlist is being
211 // generated, once an atom that is far enough away along the line is found,
212 // the remaining atoms are automatically skipped (avoiding a distance
213 // calculation/check for them).
214 // NOTE: The "less branches" flag toggles between two versions of merge sort.
215 // When it is non-zero, a version that has fewer branches (but more integer
216 // math) is used. This version may or may not be faster or some architectures.
217 #define NAMD_ComputeNonbonded_SortAtoms 1
218  #define NAMD_ComputeNonbonded_SortAtoms_LessBranches 1
219 
220 // plf -- alternate water models
221 enum class WaterModel {
222  TIP3,
223  TIP4,
224  SWM4, /* Drude model (5 charge sites) */
225 };
226 
227 // Haochuan: map water model enums to their corresponding water group sizes
228 inline constexpr int getWaterModelGroupSize(const WaterModel& watmodel) {
229  return (watmodel == WaterModel::TIP3) ? 3:
230  (watmodel == WaterModel::TIP4) ? 4:
231  (watmodel == WaterModel::SWM4) ? 5: -1;
232 }
233 
234 #if defined(__NVCC__) || defined(__HIPCC__)
235 #define NAMD_HOST_DEVICE __forceinline__ __device__ __host__
236 #else
237 #define NAMD_HOST_DEVICE inline
238 #endif
239 
240 
241 // Do not include converse when NVCC is being used. Make depends uses gcc so we
242 // define NAMD_NVCC to prevent inclusion there
243 #if !(defined(__NVCC__) || defined(NAMD_NVCC) || defined(__HIPCC__))
244 #include "converse.h"
245 #endif
246 
254 };
255 
256 // bundle together the pertinent parameters for a DCD so we can
257 // support many user defined atom lists
258 typedef struct dcd_params {
259  uint16 tag; // key for this set of parameters
260  char inputFilename[NAMD_FILENAME_BUFFER_SIZE]; // PDB defining DCD selection
261  char outFilename[NAMD_FILENAME_BUFFER_SIZE]; // DCD file to write
262  int frequency; // frequency
263  OUTPUTFILETYPE type; // type of DCD file (coords, vel, force etc.)
264  std::vector <int32> dcdSelectionIndex; // user selection -> atomindex map
265  std::vector <int32> dcdSelectionIndexReverse; // atomindex map -> userDcd selection
266  int size;
268 } DCDParams;
269 
270 // defined here so it is available to both NamdTypes.h and structures.h
271 typedef struct per_atom_flags{
275  } PerAtomFlags;
276 
277 #endif
278 
int Fclose(FILE *fout)
Definition: common.C:435
int frequency
Definition: common.h:262
char inputFilename[NAMD_FILENAME_BUFFER_SIZE]
Definition: common.h:260
uint8_t uint8
Definition: common.h:40
void NAMD_die(const char *)
Definition: common.C:147
char * NAMD_stringdup(const char *)
Definition: common.C:111
uint16 tag
Definition: common.h:259
float Real
Definition: common.h:118
int32_t int32
Definition: common.h:38
struct dcd_params DCDParams
void NAMD_version(int *major, int *minor, int *patchLevel, int *releaseType)
Definition: common.C:56
#define NAMD_FILENAME_BUFFER_SIZE
Definition: common.h:45
uint8 reservedForStatus
Definition: common.h:272
void NAMD_backup_file(const char *filename, const char *extension=0)
Definition: common.C:235
OUTPUTFILETYPE type
Definition: common.h:263
uint16_t uint16
Definition: common.h:41
dcd_params()
Definition: common.h:267
constexpr int getWaterModelGroupSize(const WaterModel &watmodel)
Definition: common.h:228
char outFilename[NAMD_FILENAME_BUFFER_SIZE]
Definition: common.h:261
void NAMD_err(const char *)
Definition: common.C:170
uint32_t uint32
Definition: common.h:42
int NAMD_gcd(int a, int b)
Definition: common.C:102
NAMD_ReleaseType
Definition: common.h:147
int Bool
Definition: common.h:142
void NAMD_quit(const char *)
Definition: common.C:125
struct per_atom_flags PerAtomFlags
uint16 dcdSelection
Definition: common.h:274
int16_t int16
Definition: common.h:37
OUTPUTFILETYPE
Definition: common.h:247
FILE * Fopen(const char *filename, const char *mode)
Definition: common.C:341
std::vector< int32 > dcdSelectionIndex
Definition: common.h:264
int size
Definition: common.h:266
int NAMD_file_exists(const char *filename)
Definition: common.C:219
int8_t int8
Definition: common.h:36
void NAMD_close(int fd, const char *fname)
Definition: common.C:315
void NAMD_bug(const char *)
Definition: common.C:195
int64_t int64
Definition: common.h:39
const char * NAMD_version_string(void)
Definition: common.C:51
uint8 unused1
Definition: common.h:273
WaterModel
Definition: common.h:221
int NAMD_open_text(const char *fname, int append=0)
Definition: common.C:270
std::vector< int32 > dcdSelectionIndexReverse
Definition: common.h:265
uint64_t uint64
Definition: common.h:43
double BigReal
Definition: common.h:123
void NAMD_write(int fd, const char *buf, size_t count, const char *fname="in NAMD_write()")
Definition: common.C:295