Skip to content

Commit 3f4ff27

Browse files
committed
nonorthogonal PBC and PBC print-out
1 parent 2958785 commit 3f4ff27

5 files changed

Lines changed: 69 additions & 24 deletions

File tree

src/efp.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "elec.h"
3333
#include "private.h"
3434
#include "stream.h"
35+
#include "util.h"
3536

3637
static void
3738
update_fragment(struct frag *frag)
@@ -837,35 +838,32 @@ EFP_EXPORT enum efp_result
837838
efp_set_periodic_box(struct efp *efp, double x, double y, double z, double alpha, double beta, double gamma)
838839
{
839840
assert(efp);
840-
841-
if (x < 2.0 * efp->opts.swf_cutoff ||
842-
y < 2.0 * efp->opts.swf_cutoff ||
843-
z < 2.0 * efp->opts.swf_cutoff) {
844-
efp_log("periodic box dimensions must be at least twice "
845-
"the switching function cutoff");
846-
return EFP_RESULT_FATAL;
847-
}
848-
849-
if (alpha == 0.0 && beta == 0.0 && gamma == 0.0) {
841+
if (alpha < 0.01) {
850842
// assigning default angles of 90.0 degrees
843+
//printf("\n assigning angles to 90.0 \n");
851844
alpha = 90.0;
852845
beta = 90.0;
853846
gamma = 90.0;
854847
}
855848

856-
if (alpha == 0.0 || beta == 0.0 || gamma == 0.0) {
857-
efp_log("periodic box angle cannot be zero");
858-
return EFP_RESULT_FATAL;
859-
}
860-
861849
efp->box.x = x;
862850
efp->box.y = y;
863851
efp->box.z = z;
864852
efp->box.a = alpha;
865853
efp->box.b = beta;
866854
efp->box.c = gamma;
867855

868-
return EFP_RESULT_SUCCESS;
856+
double max_cut = max_cutoff(efp->box);
857+
double cut = efp->opts.swf_cutoff;
858+
if (cut > max_cut) {
859+
printf("\n Maximum allowed cutoff is %lf ", max_cut*0.52917721092);
860+
printf("\n Given cutoff is %lf \n", cut*0.52917721092);
861+
efp_log("periodic box dimensions must be at least twice "
862+
"the switching function cutoff");
863+
return EFP_RESULT_FATAL;
864+
}
865+
866+
return EFP_RESULT_SUCCESS;
869867
}
870868

871869
EFP_EXPORT enum efp_result
@@ -874,7 +872,7 @@ efp_get_periodic_box(struct efp *efp, double *xyzabc)
874872
assert(efp);
875873
assert(xyzabc);
876874

877-
xyzabc[0] = efp->box.x;
875+
xyzabc[0] = efp->box.x;
878876
xyzabc[1] = efp->box.y;
879877
xyzabc[2] = efp->box.z;
880878
xyzabc[3] = efp->box.a;

src/efp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ struct efp_opts {
153153
/** Enable ligand-fragment energy decomposition from total system */
154154
int enable_pairwise;
155155
/** Index of ligand for enable_pairwise; default = 0; */
156-
int ligand;
156+
int ligand;
157+
/** Prints fragment coordinates rearranged around ligand. Applicable for periodic simulations only. */
158+
int print_pbc;
157159
};
158160

159161
/** EFP energy terms. */

src/mathutil.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ matrix_to_euler(const mat_t *rotmat, double *ea, double *eb, double *ec)
382382
*ec = c;
383383
}
384384

385-
static inline vec_t *
385+
static inline void
386386
cart_to_frac(const six_t box, vec_t *dr)
387387
{
388388
double radian = 180.0/PI;
@@ -397,10 +397,9 @@ cart_to_frac(const six_t box, vec_t *dr)
397397
dr->z = (dr->z/gamma_term) / box.z;
398398
dr->y = ((dr->y - dr->z * box.z * beta_term)/gamma_sin) / box.y;
399399
dr->x = (dr->x - dr->y * box.y * gamma_cos - dr->z * box.z * beta_cos) / box.x;
400-
return dr;
401400
}
402401

403-
static inline vec_t *
402+
static inline void
404403
frac_to_cart(const six_t box, vec_t *dr) {
405404
double radian = 180.0/PI;
406405
double alpha_cos = cos(box.a / radian);
@@ -411,10 +410,9 @@ frac_to_cart(const six_t box, vec_t *dr) {
411410
double beta_term = (alpha_cos - beta_cos*gamma_cos) / gamma_sin;
412411
double gamma_term = sqrt(beta_sin*beta_sin - beta_term*beta_term);
413412

414-
dr->z = dr->z * gamma_term * box.z;
415-
dr->y = dr->y * box.y * gamma_sin + dr->z * box.z * beta_term;
416413
dr->x = dr->x * box.x + dr->y * box.y * gamma_cos + dr->z * box.z * beta_cos;
417-
return dr;
414+
dr->y = dr->y * box.y * gamma_sin + dr->z * box.z * beta_term;
415+
dr->z = dr->z * gamma_term * box.z;
418416
}
419417

420418
#endif /* LIBEFP_MATH_UTIL_H */

src/util.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,46 @@ efp_strncasecmp(const char *s1, const char *s2, size_t n)
295295
}
296296
return 0;
297297
}
298+
299+
void
300+
find_plane(const vec_t pt1, const vec_t pt2, const vec_t pt3, vec_t *normal, double d) {
301+
// determines plane by three points: ax + by + cz + d = 0, where a,b,c are given by a normal vector
302+
vec_t vec21 = vec_sub(&pt2,&pt1);
303+
vec_t vec31 = vec_sub(&pt3,&pt1);
304+
*normal = vec_cross(&vec21,&vec31);
305+
d = - vec_dot(normal,&pt1);
306+
}
307+
308+
double
309+
max_cutoff(const six_t box) {
310+
vec_t point000 = {0.0, 0.0, 0.0};
311+
vec_t point100 = {1.0, 0.0, 0.0};
312+
vec_t point010 = {0.0, 1.0, 0.0};
313+
vec_t point001 = {0.0, 0.0, 1.0};
314+
vec_t point = {0.5,0.5,0.5};
315+
frac_to_cart(box, &point100);
316+
frac_to_cart(box, &point010);
317+
frac_to_cart(box, &point001);
318+
frac_to_cart(box, &point);
319+
// plane xy: points 000, 100, 010
320+
vec_t normal;
321+
double d;
322+
double dist;
323+
double min_dist;
324+
// plane xy: points 000, 100, 010
325+
find_plane(point100, point000, point010, &normal, d);
326+
dist = (vec_dot(&normal, &point) + d) / vec_len(&normal);
327+
dist = sqrt(dist*dist);
328+
min_dist = dist;
329+
// plane xz: points 000, 100, 001
330+
find_plane(point100, point000, point001, &normal, d);
331+
dist = (vec_dot(&normal, &point) + d) / vec_len(&normal);
332+
dist = sqrt(dist*dist);
333+
if (min_dist > dist) min_dist = dist;
334+
// plane yz: points 000, 010, 001
335+
find_plane(point010, point000, point001, &normal, d);
336+
dist = (vec_dot(&normal, &point) + d) / vec_len(&normal);
337+
dist = sqrt(dist*dist);
338+
if (min_dist > dist) min_dist = dist;
339+
return min_dist;
340+
}

src/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,9 @@ void efp_rotate_t2(const mat_t *, const double *, double *);
4848
void efp_rotate_t3(const mat_t *, const double *, double *);
4949
int efp_strcasecmp(const char *, const char *);
5050
int efp_strncasecmp(const char *, const char *, size_t);
51+
// find plane by 3 points
52+
void find_plane(const vec_t, const vec_t, const vec_t, vec_t *, double);
53+
// computes maximum cut_off distance for an arbitrary periodic cell
54+
double max_cutoff(const six_t);
5155

5256
#endif /* LIBEFP_UTIL_H */

0 commit comments

Comments
 (0)