00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MSMPOT_INTERNAL_H
00019 #define MSMPOT_INTERNAL_H
00020
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <math.h>
00025 #include "msmpot.h"
00026
00027
00028 #undef hz
00029
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033
00034
00035
00036 typedef int IndexType;
00037
00038
00039
00040 #undef GRID_TEMPLATE
00041 #define GRID_TEMPLATE(TYPE) \
00042 typedef struct TYPE##Grid_t { \
00043 TYPE *buffer; \
00044 TYPE *data; \
00045 size_t numbytes; \
00046 size_t maxbytes; \
00047 int i0, j0, k0; \
00048 int ni, nj, nk; \
00049 } TYPE##Grid
00050
00051
00052 #define GRID_INIT(a) \
00053 ((a)->buffer=NULL, (a)->data=NULL, (a)->numbytes=0, (a)->maxbytes=0, \
00054 (a)->i0=0, (a)->j0=0, (a)->k0=0, (a)->ni=0, (a)->nj=0, (a)->nk=0)
00055
00056
00057 #define GRID_DONE(a) \
00058 free((a)->buffer)
00059
00060
00061 #define GRID_INDEX(a, _i, _j, _k) \
00062 (((_k)*((a)->nj) + (_j))*(IndexType)((a)->ni) + (_i))
00063
00064
00065 #define GRID_POINTER(a, _i, _j, _k) \
00066 ((a)->data + GRID_INDEX(a, _i, _j, _k))
00067
00068
00069
00070
00071 #define GRID_RESIZE(a, __i0, __ni, __j0, __nj, __k0, __nk) \
00072 do { \
00073 int _i0=(__i0), _ni=(__ni); \
00074 int _j0=(__j0), _nj=(__nj); \
00075 int _k0=(__k0), _nk=(__nk); \
00076 size_t _numbytes = (_nk * _nj) * (size_t) _ni * sizeof((a)->buffer[0]); \
00077 if ((a)->maxbytes < _numbytes) { \
00078 void *_t = realloc((a)->buffer, _numbytes); \
00079 if (NULL == _t) return ERROR(MSMPOT_ERROR_MALLOC); \
00080 (a)->buffer = (float *) _t; \
00081 (a)->maxbytes = _numbytes; \
00082 } \
00083 (a)->numbytes = _numbytes; \
00084 (a)->i0 = _i0, (a)->ni = _ni; \
00085 (a)->j0 = _j0, (a)->nj = _nj; \
00086 (a)->k0 = _k0, (a)->nk = _nk; \
00087 (a)->data = (a)->buffer + GRID_INDEX((a), -_i0, -_j0, -_k0); \
00088 } while (0)
00089
00090
00091 #define GRID_ZERO(a) \
00092 memset((a)->buffer, 0, (a)->numbytes)
00093
00094
00095
00096 #ifdef MSMPOT_DEBUG
00097 #define GRID_INDEX_CHECK(a, _i, _j, _k) \
00098 do { \
00099 ASSERT((a)->i0 <= (_i) && (_i) < (a)->ni + (a)->i0); \
00100 ASSERT((a)->j0 <= (_j) && (_j) < (a)->nj + (a)->j0); \
00101 ASSERT((a)->k0 <= (_k) && (_k) < (a)->nk + (a)->k0); \
00102 } while (0)
00103 #else
00104 #define GRID_INDEX_CHECK(a, _i, _j, _k)
00105 #endif
00106
00107
00108
00109 #define DEFAULT_HMIN 2.f
00110 #define DEFAULT_CUTOFF 12.f
00111 #define DEFAULT_INTERP MSMPOT_INTERP_CUBIC
00112 #define DEFAULT_SPLIT MSMPOT_SPLIT_TAYLOR2
00113
00114 #define DEFAULT_BINLENMAX 4.f
00115
00116 #define DEFAULT_BINDEPTH 8
00117 #define DEFAULT_BINFILL 0.75f
00118 #define DEFAULT_DENSITY 0.1f
00119
00120 #define DEFAULT_OVER 20
00121
00122 #define DEFAULT_ERRTOL 5e-3
00123
00124 #define ATOM_SIZE 4
00125
00126 #define ATOM_X(i) ((i)<<2)
00127 #define ATOM_Y(i) (((i)<<2)+1)
00128 #define ATOM_Z(i) (((i)<<2)+2)
00129 #define ATOM_Q(i) (((i)<<2)+3)
00130
00131 #define SET_X(flag) ((flag) |= 0x01)
00132 #define SET_Y(flag) ((flag) |= 0x02)
00133 #define SET_Z(flag) ((flag) |= 0x04)
00134 #define IS_SET_X(flag) ((flag) & 0x01)
00135 #define IS_SET_Y(flag) ((flag) & 0x02)
00136 #define IS_SET_Z(flag) ((flag) & 0x04)
00137 #define IS_SET_ANY(flag) ((flag) & 0x07)
00138 #define IS_SET_ALL(flag) ((flag) == 0x07)
00139
00140
00141 GRID_TEMPLATE(float);
00142
00143
00144 #ifdef MSMPOT_CUDA
00145 struct MsmpotCuda_t;
00146 typedef struct MsmpotCuda_t MsmpotCuda;
00147
00148 MsmpotCuda *Msmpot_cuda_create(void);
00149 void Msmpot_cuda_destroy(MsmpotCuda *);
00150 int Msmpot_cuda_setup(MsmpotCuda *, Msmpot *);
00151
00152 int Msmpot_cuda_compute_shortrng(MsmpotCuda *);
00153
00154 int Msmpot_cuda_compute_latcut(MsmpotCuda *);
00155 int Msmpot_cuda_condense_qgrids(MsmpotCuda *);
00156 int Msmpot_cuda_expand_egrids(MsmpotCuda *);
00157 #endif
00158
00159
00160
00161
00162 struct Msmpot_t {
00163 float *epotmap;
00164 int mx, my, mz;
00165 float lx, ly, lz;
00166 float lx0, ly0, lz0;
00167 float dx, dy, dz;
00168
00169 const float *atom;
00170 int natoms;
00171
00172 int isperiodic;
00173 float px, py, pz;
00174 float px0, py0, pz0;
00175
00176 float density;
00177
00178 float xmin, xmax;
00179 float ymin, ymax;
00180 float zmin, zmax;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 float *bin;
00200 int *bincount;
00201 int bindepth;
00202 int nbx, nby, nbz;
00203 int maxbin;
00204 int isbinwrap;
00205 int islongcutoff;
00206 float binfill;
00207 float bx, by, bz;
00208 float invbx, invby, invbz;
00209
00210 float *over;
00211 int nover;
00212 int maxover;
00213
00214 int *boff;
00215 int nboff;
00216 int maxboff;
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 float errtol;
00241
00242 float hmin;
00243 float hx, hy, hz;
00244 float a;
00245 int nx, ny, nz;
00246
00247 int interp;
00248 int split;
00249
00250 int nlevels;
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 floatGrid *qh;
00266 floatGrid *eh;
00267 floatGrid *gc;
00268 int maxlevels;
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 int px2, py2, pz2;
00281 int px3, py3, pz3;
00282 float hx_dx, hy_dy, hz_dz;
00283
00284 int cycle_x, cycle_y, cycle_z;
00285 int rmap_x, rmap_y, rmap_z;
00286
00287 int max_phi_x, max_phi_y, max_phi_z;
00288 float *phi_x;
00289 float *phi_y;
00290 float *phi_z;
00291
00292
00293
00294
00295
00296 int max_ezd, max_eyzd;
00297 float *ezd;
00298 float *eyzd;
00299
00300 int max_lzd, max_lyzd;
00301 float *lzd;
00302 float *lyzd;
00303
00304
00305
00306 int maxatoms;
00307 int *first_atom_index;
00308 int *next_atom_index;
00309
00310 #ifdef MSMPOT_CUDA
00311 MsmpotCuda *msmcuda;
00312 const int *devlist;
00313 int devlistlen;
00314 int cuda_optional;
00315 int use_cuda;
00316 int use_cuda_shortrng;
00317 int use_cuda_latcut;
00318 #endif
00319 };
00320
00321
00322
00323 void Msmpot_set_defaults(Msmpot *msm);
00324 int Msmpot_check_params(Msmpot *msm, const float *epotmap,
00325 int mx, int my, int mz, float lx, float ly, float lz,
00326 float vx, float vy, float vz, const float *atom, int natoms);
00327
00328 int Msmpot_setup(Msmpot *msm);
00329 void Msmpot_cleanup(Msmpot *msm);
00330
00331
00332
00333
00334
00335 int Msmpot_compute_shortrng_bins(Msmpot *msm);
00336
00337
00338
00339
00340
00341
00342 int Msmpot_compute_shortrng_bin_neighborhood(Msmpot *msm,
00343 float rx,
00344 float ry,
00345 float rz
00346 );
00347
00348
00349
00350
00351
00352
00353 int Msmpot_compute_shortrng_bin_hashing(Msmpot *msm);
00354
00355
00356
00357
00358
00359
00360 int Msmpot_compute_shortrng_linklist(Msmpot *msm,
00361 const float *atom,
00362 int natoms
00363 );
00364
00365 int Msmpot_compute_longrng(Msmpot *msm);
00366
00367 int Msmpot_compute_longrng_cubic(Msmpot *msm);
00368
00369
00370
00371
00372
00373 #undef ERROR
00374 #ifndef MSMPOT_DEBUG
00375 #define ERROR(err) (err)
00376 #define ERRMSG(err,msg) (err)
00377 #else
00378
00379 int Msmpot_report_error(int err, const char *msg, const char *fn, int ln);
00380 #define ERROR(err) Msmpot_report_error(err, NULL, __FILE__, __LINE__)
00381 #define ERRMSG(err,msg) Msmpot_report_error(err, msg, __FILE__, __LINE__)
00382 #endif
00383
00384
00385
00386 #ifndef MSMPOT_DEBUG
00387 #define ASSERT(expr)
00388 #else
00389 #define ASSERT(expr) \
00390 do { \
00391 if ( !(expr) ) { \
00392 return Msmpot_report_error(MSMPOT_ERROR_ASSERT, \
00393 #expr, __FILE__, __LINE__); \
00394 } \
00395 } while (0)
00396 #endif
00397
00398
00399
00400 #ifdef MSMPOT_VERBOSE
00401 #undef MSMPOT_REPORT
00402 #define MSMPOT_REPORT
00403 #endif
00404
00405
00406 #ifndef MSMPOT_REPORT
00407 #define REPORT(msg)
00408 #else
00409 #define REPORT(msg) printf("MSMPOT: %s\n", (msg))
00410 #endif
00411
00412
00413
00414
00415
00416
00417
00418
00419 #undef SPOLY
00420 #define SPOLY(pg, s, split) \
00421 do { \
00422 float _s = s; \
00423 float _g = 0; \
00424 ASSERT(0 <= _s && _s <= 1); \
00425 switch (split) { \
00426 case MSMPOT_SPLIT_TAYLOR2: \
00427 _g = 1 + (_s-1)*(-1.f/2 + (_s-1)*(3.f/8)); \
00428 break; \
00429 case MSMPOT_SPLIT_TAYLOR3: \
00430 _g = 1 + (_s-1)*(-1.f/2 + (_s-1)*(3.f/8 + (_s-1)*(-5.f/16))); \
00431 break; \
00432 case MSMPOT_SPLIT_TAYLOR4: \
00433 _g = 1 + (_s-1)*(-1.f/2 + (_s-1)*(3.f/8 + (_s-1)*(-5.f/16 \
00434 + (_s-1)*(35.f/128)))); \
00435 break; \
00436 default: \
00437 return ERRMSG(MSMPOT_ERROR_SUPPORT, \
00438 "splitting function not implemented"); \
00439 } \
00440 *(pg) = _g; \
00441 } while (0)
00442
00443
00444
00445 #ifdef __cplusplus
00446 }
00447 #endif
00448
00449 #endif