@@ -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
211213static enum efp_result
@@ -316,6 +318,7 @@ copy_frag(struct frag *dest, const struct frag *src)
316318 return EFP_RESULT_SUCCESS ;
317319}
318320
321+ /*
319322static enum efp_result
320323copy_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
348352static 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+
18751885EFP_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
18841925EFP_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+
23062358void
23072359print_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}
0 commit comments