Skip to content

Commit 449b4b1

Browse files
committed
Separate cutoff for exrep and turning off interactions based on swf
1 parent db3d0af commit 449b4b1

10 files changed

Lines changed: 308 additions & 257 deletions

File tree

efpmd/src/main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static struct cfg *make_cfg(void)
110110
cfg_add_string(cfg, "efp_params_file", "params.efp");
111111
cfg_add_bool(cfg, "enable_cutoff", false);
112112
cfg_add_double(cfg, "swf_cutoff", 10.0);
113+
cfg_add_double(cfg, "xr_cutoff", 0.0);
113114
cfg_add_int(cfg, "max_steps", 100);
114115
cfg_add_int(cfg, "multistep_steps", 1);
115116
cfg_add_string(cfg, "fraglib_path", FRAGLIB_PATH);
@@ -253,11 +254,17 @@ static struct efp *create_efp(const struct cfg *cfg, const struct sys *sys)
253254
.enable_pbc = cfg_get_bool(cfg, "enable_pbc"),
254255
.enable_cutoff = cfg_get_bool(cfg, "enable_cutoff"),
255256
.swf_cutoff = cfg_get_double(cfg, "swf_cutoff"),
257+
.xr_cutoff = cfg_get_double(cfg, "xr_cutoff"),
256258
.enable_pairwise = cfg_get_bool(cfg, "enable_pairwise"),
257259
.ligand = cfg_get_int(cfg, "ligand"),
258260
.print_pbc = cfg_get_bool(cfg, "print_pbc")
259261
};
260262

263+
if (opts.xr_cutoff == 0.0) {
264+
opts.xr_cutoff = opts.swf_cutoff;
265+
printf("xr_cutoff is set to %lf \n\n\n", opts.xr_cutoff*0.52917721092);
266+
}
267+
261268
enum efp_coord_type coord_type = cfg_get_enum(cfg, "coord");
262269
struct efp *efp = efp_create();
263270

@@ -393,7 +400,9 @@ static void convert_units(struct cfg *cfg, struct sys *sys)
393400
cfg_get_double(cfg, "pressure") * BAR_TO_AU);
394401
cfg_set_double(cfg, "swf_cutoff",
395402
cfg_get_double(cfg, "swf_cutoff") / BOHR_RADIUS);
396-
cfg_set_double(cfg, "num_step_dist",
403+
cfg_set_double(cfg, "xr_cutoff",
404+
cfg_get_double(cfg, "xr_cutoff") / BOHR_RADIUS);
405+
cfg_set_double(cfg, "num_step_dist",
397406
cfg_get_double(cfg, "num_step_dist") / BOHR_RADIUS);
398407

399408
size_t n_convert = (size_t []) {

src/disp.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -280,27 +280,32 @@ efp_frag_frag_disp(struct efp *efp, size_t frag_i, size_t frag_j,
280280
struct frag *fr_i = efp->frags + frag_i;
281281
struct frag *fr_j = efp->frags + frag_j;
282282

283-
size_t n_disp_i = fr_i->n_dynamic_polarizable_pts;
284-
size_t n_disp_j = fr_j->n_dynamic_polarizable_pts;
285-
286-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
287-
288-
for (size_t ii = 0, idx = 0; ii < n_disp_i; ii++)
289-
for (size_t jj = 0; jj < n_disp_j; jj++, idx++)
290-
energy += point_point_disp(efp, frag_i, frag_j, ii, jj,
291-
s[idx], ds[idx], &swf);
292-
293-
vec_t force = {
294-
swf.dswf.x * energy,
295-
swf.dswf.y * energy,
296-
swf.dswf.z * energy
297-
};
298-
299-
six_atomic_add_xyz(efp->grad + frag_i, &force);
300-
six_atomic_sub_xyz(efp->grad + frag_j, &force);
301-
efp_add_stress(&swf.dr, &force, &efp->stress);
302-
303-
return energy * swf.swf;
283+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
284+
// skip calculations if distance between fragments is too big...
285+
if (swf.swf == 0.0) {
286+
return 0.0;
287+
}
288+
else {
289+
size_t n_disp_i = fr_i->n_dynamic_polarizable_pts;
290+
size_t n_disp_j = fr_j->n_dynamic_polarizable_pts;
291+
292+
293+
for (size_t ii = 0, idx = 0; ii < n_disp_i; ii++)
294+
for (size_t jj = 0; jj < n_disp_j; jj++, idx++)
295+
energy += point_point_disp(efp, frag_i, frag_j, ii, jj,
296+
s[idx], ds[idx], &swf);
297+
298+
vec_t force = {
299+
swf.dswf.x * energy,
300+
swf.dswf.y * energy,
301+
swf.dswf.z * energy
302+
};
303+
304+
six_atomic_add_xyz(efp->grad + frag_i, &force);
305+
six_atomic_sub_xyz(efp->grad + frag_j, &force);
306+
efp_add_stress(&swf.dr, &force, &efp->stress);
307+
return energy * swf.swf;
308+
}
304309
}
305310

306311
void

src/efp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ check_opts(const struct efp_opts *opts)
288288
return EFP_RESULT_FATAL;
289289
}
290290
}
291+
if (opts->enable_cutoff) {
292+
if (opts->swf_cutoff < opts->xr_cutoff) {
293+
efp_log("exchange-repulsion cutoff is smaller than interaction cutoff");
294+
return EFP_RESULT_FATAL;
295+
}
296+
}
291297
return EFP_RESULT_SUCCESS;
292298
}
293299

src/efp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ struct efp_opts {
150150
int enable_cutoff;
151151
/** Cutoff distance for fragment-fragment interactions. */
152152
double swf_cutoff;
153-
/** Enable ligand-fragment energy decomposition from total system */
153+
/** Cutoff distance for exchange-repulsion calculations. */
154+
double xr_cutoff;
155+
/** Enable ligand-fragment energy decomposition from total system */
154156
int enable_pairwise;
155157
/** Index of ligand for enable_pairwise; default = 0; */
156158
int ligand;

src/elec.c

Lines changed: 89 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -337,91 +337,97 @@ efp_frag_frag_elec(struct efp *efp, size_t fr_i_idx, size_t fr_j_idx)
337337
{
338338
struct frag *fr_i = efp->frags + fr_i_idx;
339339
struct frag *fr_j = efp->frags + fr_j_idx;
340-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
340+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
341341
double energy = 0.0;
342342

343-
/* nuclei - nuclei */
344-
for (size_t ii = 0; ii < fr_i->n_atoms; ii++) {
345-
for (size_t jj = 0; jj < fr_j->n_atoms; jj++) {
346-
struct efp_atom *at_i = fr_i->atoms + ii;
347-
struct efp_atom *at_j = fr_j->atoms + jj;
348-
349-
vec_t dr = {
350-
at_j->x - at_i->x - swf.cell.x,
351-
at_j->y - at_i->y - swf.cell.y,
352-
at_j->z - at_i->z - swf.cell.z
353-
};
354-
355-
energy += efp_charge_charge_energy(at_i->znuc,
356-
at_j->znuc, &dr);
357-
if (efp->do_gradient) {
358-
vec_t force, add_i, add_j;
359-
360-
efp_charge_charge_grad(at_i->znuc, at_j->znuc,
361-
&dr, &force, &add_i, &add_j);
362-
vec_scale(&force, swf.swf);
363-
efp_add_force(efp->grad + fr_i_idx,
364-
CVEC(fr_i->x), CVEC(at_i->x), &force, NULL);
365-
efp_sub_force(efp->grad + fr_j_idx,
366-
CVEC(fr_j->x), CVEC(at_j->x), &force, NULL);
367-
efp_add_stress(&swf.dr, &force, &efp->stress);
368-
}
369-
}
370-
}
371-
372-
/* nuclei - mult points */
373-
for (size_t ii = 0; ii < fr_i->n_atoms; ii++) {
374-
for (size_t jj = 0; jj < fr_j->n_multipole_pts; jj++) {
375-
energy += atom_mult_energy(efp, fr_i, fr_j,
376-
ii, jj, &swf);
377-
if (efp->do_gradient) {
378-
atom_mult_grad(efp, fr_i_idx, fr_j_idx,
379-
ii, jj, &swf);
380-
}
381-
}
382-
}
383-
384-
/* mult points - nuclei */
385-
for (size_t jj = 0; jj < fr_j->n_atoms; jj++) {
386-
for (size_t ii = 0; ii < fr_i->n_multipole_pts; ii++) {
387-
struct swf swf2 = swf;
388-
389-
vec_negate(&swf2.cell);
390-
vec_negate(&swf2.dr);
391-
vec_negate(&swf2.dswf);
392-
393-
energy += atom_mult_energy(efp, fr_j, fr_i,
394-
jj, ii, &swf2);
395-
if (efp->do_gradient) {
396-
atom_mult_grad(efp, fr_j_idx, fr_i_idx,
397-
jj, ii, &swf2);
398-
}
399-
}
400-
}
401-
402-
/* mult points - mult points */
403-
for (size_t ii = 0; ii < fr_i->n_multipole_pts; ii++) {
404-
for (size_t jj = 0; jj < fr_j->n_multipole_pts; jj++) {
405-
energy += mult_mult_energy(efp, fr_i_idx, fr_j_idx,
406-
ii, jj, &swf);
407-
if (efp->do_gradient) {
408-
mult_mult_grad(efp, fr_i_idx, fr_j_idx,
409-
ii, jj, &swf);
410-
}
411-
}
412-
}
413-
414-
vec_t force = {
415-
swf.dswf.x * energy,
416-
swf.dswf.y * energy,
417-
swf.dswf.z * energy
418-
};
419-
420-
six_atomic_add_xyz(efp->grad + fr_i_idx, &force);
421-
six_atomic_sub_xyz(efp->grad + fr_j_idx, &force);
422-
efp_add_stress(&swf.dr, &force, &efp->stress);
423-
424-
return energy * swf.swf;
343+
// skip calculations if distance between fragments is too big...
344+
if (swf.swf == 0.0) {
345+
return 0.0;
346+
}
347+
else {
348+
/* nuclei - nuclei */
349+
for (size_t ii = 0; ii < fr_i->n_atoms; ii++) {
350+
for (size_t jj = 0; jj < fr_j->n_atoms; jj++) {
351+
struct efp_atom *at_i = fr_i->atoms + ii;
352+
struct efp_atom *at_j = fr_j->atoms + jj;
353+
354+
vec_t dr = {
355+
at_j->x - at_i->x - swf.cell.x,
356+
at_j->y - at_i->y - swf.cell.y,
357+
at_j->z - at_i->z - swf.cell.z
358+
};
359+
360+
energy += efp_charge_charge_energy(at_i->znuc,
361+
at_j->znuc, &dr);
362+
if (efp->do_gradient) {
363+
vec_t force, add_i, add_j;
364+
365+
efp_charge_charge_grad(at_i->znuc, at_j->znuc,
366+
&dr, &force, &add_i, &add_j);
367+
vec_scale(&force, swf.swf);
368+
efp_add_force(efp->grad + fr_i_idx,
369+
CVEC(fr_i->x), CVEC(at_i->x), &force, NULL);
370+
efp_sub_force(efp->grad + fr_j_idx,
371+
CVEC(fr_j->x), CVEC(at_j->x), &force, NULL);
372+
efp_add_stress(&swf.dr, &force, &efp->stress);
373+
}
374+
}
375+
}
376+
377+
/* nuclei - mult points */
378+
for (size_t ii = 0; ii < fr_i->n_atoms; ii++) {
379+
for (size_t jj = 0; jj < fr_j->n_multipole_pts; jj++) {
380+
energy += atom_mult_energy(efp, fr_i, fr_j,
381+
ii, jj, &swf);
382+
if (efp->do_gradient) {
383+
atom_mult_grad(efp, fr_i_idx, fr_j_idx,
384+
ii, jj, &swf);
385+
}
386+
}
387+
}
388+
389+
/* mult points - nuclei */
390+
for (size_t jj = 0; jj < fr_j->n_atoms; jj++) {
391+
for (size_t ii = 0; ii < fr_i->n_multipole_pts; ii++) {
392+
struct swf swf2 = swf;
393+
394+
vec_negate(&swf2.cell);
395+
vec_negate(&swf2.dr);
396+
vec_negate(&swf2.dswf);
397+
398+
energy += atom_mult_energy(efp, fr_j, fr_i,
399+
jj, ii, &swf2);
400+
if (efp->do_gradient) {
401+
atom_mult_grad(efp, fr_j_idx, fr_i_idx,
402+
jj, ii, &swf2);
403+
}
404+
}
405+
}
406+
407+
/* mult points - mult points */
408+
for (size_t ii = 0; ii < fr_i->n_multipole_pts; ii++) {
409+
for (size_t jj = 0; jj < fr_j->n_multipole_pts; jj++) {
410+
energy += mult_mult_energy(efp, fr_i_idx, fr_j_idx,
411+
ii, jj, &swf);
412+
if (efp->do_gradient) {
413+
mult_mult_grad(efp, fr_i_idx, fr_j_idx,
414+
ii, jj, &swf);
415+
}
416+
}
417+
}
418+
419+
vec_t force = {
420+
swf.dswf.x * energy,
421+
swf.dswf.y * energy,
422+
swf.dswf.z * energy
423+
};
424+
425+
six_atomic_add_xyz(efp->grad + fr_i_idx, &force);
426+
six_atomic_sub_xyz(efp->grad + fr_j_idx, &force);
427+
efp_add_stress(&swf.dr, &force, &efp->stress);
428+
429+
return energy * swf.swf;
430+
}
425431
}
426432

427433
static void

src/pol.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ get_elec_field(const struct efp *efp, size_t frag_idx, size_t pt_idx)
125125
continue;
126126

127127
const struct frag *fr_i = efp->frags + i;
128-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
128+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
129+
if (swf.swf == 0.0)
130+
continue;
129131

130132
/* field due to nuclei */
131133
for (size_t j = 0; j < fr_i->n_atoms; j++) {
@@ -205,7 +207,9 @@ get_ligand_field(const struct efp *efp, size_t frag_idx, size_t pt_idx, size_t l
205207
if (efp_skip_frag_pair(efp, ligand_idx, frag_idx))
206208
return elec_field;
207209

208-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
210+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
211+
if (swf.swf == 0)
212+
return elec_field;
209213

210214
/* field due to nuclei */
211215
for (size_t j = 0; j < fr_i->n_atoms; j++) {
@@ -429,7 +433,9 @@ get_induced_dipole_field(struct efp *efp, size_t frag_idx,
429433
continue;
430434

431435
struct frag *fr_j = efp->frags + j;
432-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
436+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
437+
if (swf.swf == 0)
438+
continue;
433439

434440
for (size_t jj = 0; jj < fr_j->n_polarizable_pts; jj++) {
435441
struct polarizable_pt *pt_j = fr_j->polarizable_pts+jj;
@@ -649,7 +655,9 @@ compute_grad_point(struct efp *efp, size_t frag_idx, size_t pt_idx)
649655
continue;
650656

651657
struct frag *fr_j = efp->frags + j;
652-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
658+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
659+
if (swf.swf == 0.0)
660+
continue;
653661

654662
/* energy without switching applied */
655663
double energy = 0.0;
@@ -917,7 +925,9 @@ efp_get_electric_field(struct efp *efp, size_t frag_idx, const double *xyz,
917925
continue;
918926

919927
const struct frag *fr_i = efp->frags + i;
920-
struct swf swf = efp_make_swf(efp, fr_i, frag);
928+
struct swf swf = efp_make_swf(efp, fr_i, frag, 0);
929+
if (swf.swf == 0.0)
930+
continue;
921931

922932
/* field due to nuclei */
923933
for (size_t j = 0; j < fr_i->n_atoms; j++) {

src/poldirect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ get_int_mat(const struct efp *efp, size_t i, size_t j, size_t ii, size_t jj)
6565
const struct frag *fr_j = efp->frags + j;
6666
const struct polarizable_pt *pt_i = fr_i->polarizable_pts + ii;
6767
const struct polarizable_pt *pt_j = fr_j->polarizable_pts + jj;
68-
struct swf swf = efp_make_swf(efp, fr_i, fr_j);
68+
struct swf swf = efp_make_swf(efp, fr_i, fr_j, 0);
6969

7070
vec_t dr = {
7171
pt_j->x - pt_i->x - swf.cell.x,

src/util.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ efp_skip_frag_pair(const struct efp *efp, size_t fr_i_idx, size_t fr_j_idx)
6565

6666
struct swf
6767
efp_make_swf(const struct efp *efp, const struct frag *fr_i,
68-
const struct frag *fr_j)
68+
const struct frag *fr_j, int short_range_cutoff)
6969
{
7070
struct swf swf;
7171

@@ -97,9 +97,16 @@ efp_make_swf(const struct efp *efp, const struct frag *fr_i,
9797

9898
double r = vec_len(&swf.dr);
9999

100-
swf.swf = efp_get_swf(r, efp->opts.swf_cutoff);
101-
double dswf = efp_get_dswf(r, efp->opts.swf_cutoff);
102-
100+
// differentiating between cutoff for exrep and other terms
101+
double dswf = 0.0;
102+
if (short_range_cutoff == 1) {
103+
swf.swf = efp_get_swf(r, efp->opts.xr_cutoff);
104+
dswf = efp_get_dswf(r, efp->opts.xr_cutoff);
105+
}
106+
else {
107+
swf.swf = efp_get_swf(r, efp->opts.swf_cutoff);
108+
dswf = efp_get_dswf(r, efp->opts.swf_cutoff);
109+
}
103110
swf.dswf.x = -dswf * swf.dr.x;
104111
swf.dswf.y = -dswf * swf.dr.y;
105112
swf.dswf.z = -dswf * swf.dr.z;

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct frag;
3434

3535
int efp_skip_frag_pair(const struct efp *, size_t, size_t);
3636
struct swf efp_make_swf(const struct efp *, const struct frag *,
37-
const struct frag *);
37+
const struct frag *, int);
3838
int efp_check_rotation_matrix(const mat_t *);
3939
void efp_points_to_matrix(const double *, mat_t *);
4040
const struct frag *efp_find_lib(struct efp *, const char *);

0 commit comments

Comments
 (0)