Skip to content

Commit 232d845

Browse files
committed
working but uncleaned revolutionized version
1 parent d043e81 commit 232d845

12 files changed

Lines changed: 182 additions & 45961 deletions

File tree

efpmd/src/main.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static struct cfg *make_cfg(void)
152152
cfg_add_double(cfg, "thermostat_tau", 1.0e3);
153153
cfg_add_double(cfg, "barostat_tau", 1.0e4);
154154

155-
cfg_add_int(cfg, "ligand", 0);
155+
cfg_add_int(cfg, "ligand", -100);
156156
cfg_add_bool(cfg, "enable_pairwise", false);
157157
cfg_add_bool(cfg, "print_pbc", false);
158158
cfg_add_bool(cfg, "symmetry", false);
@@ -291,7 +291,7 @@ static struct efp *create_efp(const struct cfg *cfg, const struct sys *sys)
291291

292292
if (opts.xr_cutoff == 0.0) {
293293
opts.xr_cutoff = opts.swf_cutoff;
294-
printf("xr_cutoff is set to %lf \n\n\n", opts.xr_cutoff*0.52917721092);
294+
printf("xr_cutoff is set to %lf \n\n", opts.xr_cutoff*0.52917721092);
295295
}
296296

297297
enum efp_coord_type coord_type = cfg_get_enum(cfg, "coord");
@@ -305,12 +305,8 @@ static struct efp *create_efp(const struct cfg *cfg, const struct sys *sys)
305305
else
306306
add_potentials(efp, cfg, sys);
307307

308-
for (size_t i = 0; i < sys->n_frags; i++) {
309-
if (i == opts.ligand)
310-
check_fail(efp_add_ligand(efp, sys->frags[i].name));
311-
else
312-
check_fail(efp_add_fragment(efp, sys->frags[i].name));
313-
}
308+
for (size_t i = 0; i < sys->n_frags; i++)
309+
check_fail(efp_add_fragment(efp, sys->frags[i].name));
314310

315311
if (sys->n_charges > 0) {
316312
double q[sys->n_charges];
@@ -335,7 +331,10 @@ static struct efp *create_efp(const struct cfg *cfg, const struct sys *sys)
335331
if (cfg_get_bool(cfg, "enable_ff"))
336332
opts.terms &= ~(EFP_TERM_ELEC | EFP_TERM_POL | EFP_TERM_DISP | EFP_TERM_XR);
337333

338-
check_fail(efp_set_opts(efp, &opts));
334+
if (opts.enable_pairwise)
335+
check_fail(efp_add_ligand(efp, opts.ligand));
336+
337+
check_fail(efp_set_opts(efp, &opts));
339338
check_fail(efp_prepare(efp));
340339
check_fail(efp_set_symmlist(efp));
341340

efpmd/src/parse.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ struct sys *parse_input(struct cfg *cfg, const char *path)
253253
if (cfg_get_bool(cfg, "enable_pbc"))
254254
cfg_set_bool(cfg, "enable_cutoff", true);
255255

256+
// turn off pairwise calculations if ligand is not set
257+
if (cfg_get_int(cfg, "ligand") == -100 && cfg_get_bool(cfg, "enable_pairwise") == true)
258+
error("Specify ligand for pairwise calculations");
259+
256260
check_cfg(cfg);
257261
efp_stream_close(stream);
258262

src/efp.c

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,13 @@ free_ligand(struct ligand *ligand)
201201
if (!ligand)
202202
return;
203203

204-
free_frag(ligand->ligand_frag);
204+
//free_frag(&ligand->ligand_frag);
205205
for (size_t i=0; i<ligand->n_ligand_pts; i++) {
206-
free(ligand->ligand_pts[i].fragment_field)
206+
if (ligand->ligand_pts[i].fragment_field)
207+
free(ligand->ligand_pts[i].fragment_field);
207208
}
208-
free(ligand->ligand_pts);
209+
if (ligand->ligand_pts)
210+
free(ligand->ligand_pts);
209211
}
210212

211213
static enum efp_result
@@ -316,6 +318,7 @@ copy_frag(struct frag *dest, const struct frag *src)
316318
return EFP_RESULT_SUCCESS;
317319
}
318320

321+
/*
319322
static enum efp_result
320323
copy_ligand(struct ligand *dest, const struct ligand *src) {
321324
size_t size;
@@ -343,6 +346,7 @@ copy_ligand(struct ligand *dest, const struct ligand *src) {
343346
}
344347
}
345348
}
349+
*/
346350

347351
// updates (shifts) parameters of fragment based on coordinates of fragment atoms
348352
static enum efp_result
@@ -515,11 +519,11 @@ compute_two_body_range(struct efp *efp, size_t frag_from, size_t frag_to,
515519

516520
/* */
517521
if (efp->opts.enable_pairwise) {
518-
if (i == efp->opts.ligand) {
522+
if (i == efp->ligand_index) {
519523
efp->pair_energies[fr_j].exchange_repulsion = exr;
520524
efp->pair_energies[fr_j].charge_penetration = ecp;
521525
}
522-
if (fr_j == efp->opts.ligand) {
526+
if (fr_j == efp->ligand_index) {
523527
efp->pair_energies[i].exchange_repulsion = exr;
524528
efp->pair_energies[i].charge_penetration = ecp;
525529
}
@@ -531,9 +535,9 @@ compute_two_body_range(struct efp *efp, size_t frag_from, size_t frag_to,
531535
e_elec += e_elec_tmp;
532536
/* */
533537
if (efp->opts.enable_pairwise) {
534-
if (i == efp->opts.ligand)
538+
if (i == efp->ligand_index)
535539
efp->pair_energies[fr_j].electrostatic = e_elec_tmp;
536-
if (fr_j == efp->opts.ligand)
540+
if (fr_j == efp->ligand_index)
537541
efp->pair_energies[i].electrostatic = e_elec_tmp;
538542
}
539543
}
@@ -1181,6 +1185,7 @@ efp_prepare(struct efp *efp)
11811185
efp->n_polarizable_pts += efp->frags[i].n_polarizable_pts;
11821186
}
11831187

1188+
/*
11841189
efp->n_fragment_field_pts = 0;
11851190
if (efp->opts.enable_pairwise && efp->opts.ligand != -1) {
11861191
size_t ligand_idx = efp->opts.ligand;
@@ -1190,6 +1195,7 @@ efp_prepare(struct efp *efp)
11901195
}
11911196
}
11921197
efp->fragment_field = (vec_t *)calloc(efp->n_fragment_field_pts, sizeof(vec_t));
1198+
*/
11931199

11941200
efp->grad = (six_t *)calloc(efp->n_frag, sizeof(six_t));
11951201
efp->skiplist = (char *)calloc(efp->n_frag * efp->n_frag, 1);
@@ -1759,6 +1765,9 @@ efp_shutdown(struct efp *efp)
17591765
free_frag(efp->lib_current[i]);
17601766
free(efp->lib_current[i]);
17611767
}
1768+
1769+
free_ligand(efp->ligand);
1770+
free(efp->ligand);
17621771
free(efp->frags);
17631772
free(efp->lib);
17641773
free(efp->lib_current);
@@ -1769,7 +1778,7 @@ efp_shutdown(struct efp *efp)
17691778
free(efp->ai_orbital_energies);
17701779
free(efp->ai_dipole_integrals);
17711780
free(efp->skiplist);
1772-
free(efp->fragment_field);
1781+
// free(efp->fragment_field);
17731782
free(efp->pair_energies);
17741783
free(efp->symmlist);
17751784
free(efp);
@@ -1872,13 +1881,45 @@ efp_add_fragment(struct efp *efp, const char *name)
18721881
return EFP_RESULT_SUCCESS;
18731882
}
18741883

1884+
18751885
EFP_EXPORT enum efp_result
1876-
efp_add_ligand(struct efp *efp, const char *name) {
1886+
efp_add_ligand(struct efp *efp, int ligand_index) {
1887+
18771888
assert(efp);
1878-
assert(name);
1889+
assert(ligand_index >= -1);
1890+
1891+
// ligand_index=-1 means ligand is QM; -100 is default when ligand is not specified
1892+
// 0 and larger: ligand is a fragment with with index
1893+
if (ligand_index > -1) {
1894+
assert( (size_t)ligand_index < efp->n_frag);
1895+
efp->ligand_index = (size_t)ligand_index;
1896+
1897+
efp->ligand = (struct ligand *) calloc(1, sizeof(struct ligand));
1898+
if (efp->ligand == NULL)
1899+
return EFP_RESULT_NO_MEMORY;
1900+
1901+
struct ligand *lig = efp->ligand;
18791902

1880-
check_fail(efp_add_fragment(efp, name));
1881-
check_fail(make_ligand(efp));
1903+
// copy_frag(lig->ligand_frag, &efp->frags[ligand_index]);
1904+
lig->ligand_frag = &efp->frags[ligand_index];
1905+
lig->n_ligand_pts = efp->frags[ligand_index].n_polarizable_pts;
1906+
1907+
size_t size;
1908+
size = lig->n_ligand_pts * sizeof(struct ligand_pt);
1909+
lig->ligand_pts = (struct ligand_pt *) malloc(size);
1910+
if (lig->ligand_pts == NULL)
1911+
return EFP_RESULT_NO_MEMORY;
1912+
1913+
for (size_t i = 0; i < lig->n_ligand_pts; i++) {
1914+
struct ligand_pt *pt = lig->ligand_pts + i;
1915+
size = efp->n_frag * sizeof(vec_t);
1916+
pt->n_frag = efp->n_frag;
1917+
pt->fragment_field = (vec_t *) malloc(size);
1918+
if (!pt->fragment_field)
1919+
return EFP_RESULT_NO_MEMORY;
1920+
}
1921+
}
1922+
return EFP_RESULT_SUCCESS;
18821923
}
18831924

18841925
EFP_EXPORT enum efp_result
@@ -2303,6 +2344,17 @@ print_pol_pt(struct efp *efp, size_t frag_index, size_t pol_index) {
23032344
printf("\n");
23042345
}
23052346

2347+
void print_ligand(struct efp *efp, size_t frag_index) {
2348+
if (! efp->opts.enable_pairwise)
2349+
return;
2350+
if (efp->ligand_index == frag_index) {
2351+
printf("Ligand index %d\n", efp->ligand_index);
2352+
if (efp->ligand_index > -1) {
2353+
printf("Number of ligand points %d", efp->ligand->n_ligand_pts);
2354+
}
2355+
}
2356+
}
2357+
23062358
void
23072359
print_frag_info(struct efp *efp, size_t frag_index) {
23082360
struct frag *fr = efp->frags + frag_index;
@@ -2320,5 +2372,7 @@ print_frag_info(struct efp *efp, size_t frag_index) {
23202372
print_pol_pt(efp, frag_index, i);
23212373
}
23222374

2375+
print_ligand(efp, frag_index);
2376+
23232377
printf("\n");
23242378
}

src/efp.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ enum efp_result efp_add_potential(struct efp *efp, const char *path);
345345
*/
346346
enum efp_result efp_add_fragment(struct efp *efp, const char *name);
347347

348+
/**
349+
* Add a ligand fragment to teh system
350+
* @param[in] efp
351+
* @param[in] ligand_index Index of the ligand in the fragment list
352+
* @return ::EFP_RESULT_SUCCESS on success or error code otherwise.
353+
*/
354+
enum efp_result efp_add_ligand(struct efp *efp, int ligand_index);
355+
348356
/**
349357
* Prepare the calculation.
350358
*
@@ -1368,6 +1376,13 @@ void print_mult_pt(struct efp *efp, size_t frag_index, size_t pt_index);
13681376
*/
13691377
void print_pol_pt(struct efp *efp, size_t frag_index, size_t pol_index);
13701378

1379+
/**
1380+
* Prints information about ligand if any
1381+
* @param efp
1382+
* @param frag_index index of fragment
1383+
*/
1384+
void print_ligand(struct efp *efp, size_t frag_index);
1385+
13711386
/**
13721387
* Prints information on fragment
13731388
* @param efp

0 commit comments

Comments
 (0)