Skip to content

Commit 081216d

Browse files
authored
Merge pull request #6 from libefp2/crystal
bug in crystal pairwise energies
2 parents 34f234b + 1c131a9 commit 081216d

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/pol.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ get_elec_field(const struct efp *efp, size_t frag_idx, size_t pt_idx)
198198
return elec_field;
199199
}
200200

201-
/* this function computes electric field on a polarizable point due to a ligand */
201+
/* this function computes electric field on a polarizable point pt_idx of fragment frag_idx due to other fragment ligand_idx */
202202
static vec_t
203203
get_ligand_field(const struct efp *efp, size_t frag_idx, size_t pt_idx, size_t ligand_idx)
204204
{
@@ -594,6 +594,9 @@ compute_id_crystal(struct efp *efp, void *data)
594594
int nsymm = efp->nsymm_frag;
595595
size_t *unique_frag = (size_t *)calloc(nsymm, sizeof(size_t));
596596
unique_symm_frag(efp, unique_frag);
597+
size_t *nsymm_frag = (size_t *)calloc(nsymm, sizeof(size_t));
598+
n_symm_frag(efp, nsymm_frag);
599+
597600

598601
// step 1: compute induced dipoles on symmetry-unique fragments
599602
for (int i = 0; i < nsymm; i++) {
@@ -620,9 +623,8 @@ compute_id_crystal(struct efp *efp, void *data)
620623
id_conj_new[idx] = mat_trans_vec(&pt->tensor,
621624
&field_conj);
622625

623-
conv += vec_dist(&id_new[idx], &efp->indip[idx]);
624-
conv += vec_dist(&id_conj_new[idx],
625-
&efp->indipconj[idx]);
626+
conv += nsymm_frag[i]*vec_dist(&id_new[idx], &efp->indip[idx]);
627+
conv += nsymm_frag[i]*vec_dist(&id_conj_new[idx], &efp->indipconj[idx]);
626628
}
627629
}
628630
((struct id_work_data *)data)->conv += conv;
@@ -795,7 +797,8 @@ compute_energy_crystal(struct efp *efp, double *polenergy)
795797

796798
struct frag *other_frag = efp->frags + fr;
797799
efp->pair_energies[fr].polarization +=
798-
-0.5 * vec_dot(&efp->indip[idx], &efp->fragment_field[other_frag->fragment_field_offset + idx]);
800+
-0.5 *
801+
vec_dot(&efp->indip[idx], &efp->fragment_field[other_frag->fragment_field_offset + j]);
799802
}
800803
}
801804
}
@@ -816,7 +819,6 @@ compute_energy_crystal(struct efp *efp, double *polenergy)
816819
}
817820
}
818821
}
819-
820822
*polenergy = energy;
821823
}
822824

0 commit comments

Comments
 (0)