@@ -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
427433static void
0 commit comments