@@ -168,6 +168,7 @@ void print_energy(struct state *state)
168168 msg ("\n\n" );
169169}
170170
171+
171172void print_gradient (struct state * state )
172173{
173174 size_t n_frags ;
@@ -270,6 +271,98 @@ void print_matrix(size_t rows, size_t cols, const double *mat)
270271 }
271272}
272273
274+ void print_pair_energy (struct state * state ){
275+
276+ if (cfg_get_bool (state -> cfg , "enable_pairwise" )) {
277+ msg (" ------ PAIRWISE ENERGY ANALYSIS FOLLOWS ------------------\n\n" );
278+ size_t n_frags ;
279+ check_fail (efp_get_frag_count (state -> efp , & n_frags ));
280+ double coord [6 * n_frags ];
281+ check_fail (efp_get_coordinates (state -> efp , coord ));
282+
283+ struct efp_energy * energies ;
284+ energies = xmalloc (n_frags * sizeof (struct efp_energy ));
285+ check_fail (efp_get_pairwise_energy (state -> efp , energies ));
286+
287+ char ligand [32 ];
288+ size_t lig_atoms ;
289+
290+ size_t ligand_index = cfg_get_int (state -> cfg , "ligand" );
291+ check_fail (efp_get_frag_name (state -> efp , ligand_index , sizeof (ligand ),ligand ));
292+ check_fail (efp_get_frag_atom_count (state -> efp , ligand_index , & lig_atoms ));
293+ struct efp_atom latoms [lig_atoms ];
294+ check_fail (efp_get_frag_atoms (state -> efp , ligand_index , lig_atoms , latoms ));
295+
296+ char frag_name [32 ];
297+ size_t frag_atoms ;
298+ double lattice_energy [6 ];
299+ for (size_t j = 0 ; j < 6 ; j ++ ){
300+ lattice_energy [j ]= 0.0 ;
301+ }
302+ for (size_t i = 0 ; i < n_frags ; i ++ ){
303+ check_fail (efp_get_frag_name (state -> efp , i , sizeof (frag_name ),frag_name ));
304+ check_fail (efp_get_frag_atom_count (state -> efp , i , & frag_atoms ));
305+
306+ struct efp_atom atoms [frag_atoms ];
307+ check_fail (efp_get_frag_atoms (state -> efp , i , frag_atoms , atoms ));
308+
309+ msg (" PAIRWISE ENERGY BETWEEN FRAGMENT %zu (%s) AND LIGAND %zu (%s) \n" , i , frag_name , ligand_index , ligand );
310+ msg ("fragment %s\n" , frag_name );
311+ for (size_t a = 0 ; a < frag_atoms ; a ++ ) {
312+ double x = atoms [a ].x * BOHR_RADIUS ;
313+ double y = atoms [a ].y * BOHR_RADIUS ;
314+ double z = atoms [a ].z * BOHR_RADIUS ;
315+ msg (" %-16s %12.6lf %12.6lf %12.6lf\n" , atoms [a ].label , x , y , z );
316+ }
317+ msg ("\n" );
318+
319+ msg ("fragment %s\n" , ligand );
320+ for (size_t a = 0 ; a < lig_atoms ; a ++ ) {
321+ double x = latoms [a ].x * BOHR_RADIUS ;
322+ double y = latoms [a ].y * BOHR_RADIUS ;
323+ double z = latoms [a ].z * BOHR_RADIUS ;
324+ msg (" %-16s %12.6lf %12.6lf %12.6lf\n" , latoms [a ].label , x , y , z );
325+ }
326+ msg ("\n" );
327+
328+ msg (" PAIRWISE ENERGY COMPONENTS (ATOMIC UNITS)\n" );
329+ msg ("%40s %16.10lf\n" , "PAIRWISE ELECTROSTATIC ENERGY" , energies [i ].electrostatic );
330+ msg ("%40s %16.10lf\n" , "PAIRWISE POLARIZATION ENERGY" , energies [i ].polarization );
331+ msg ("%40s %16.10lf\n" , "PAIRWISE DISPERSION ENERGY" , energies [i ].dispersion );
332+ msg ("%40s %16.10lf\n" , "PAIRWISE EXCHANGE REPULSION ENERGY" ,
333+ energies [i ].exchange_repulsion );
334+ msg ("%40s %16.10lf\n" , "PAIRWISE CHARGE PENETRATION ENERGY" ,
335+ energies [i ].charge_penetration );
336+
337+ energies [i ].total = energies [i ].electrostatic + energies [i ].polarization + energies [i ].dispersion
338+ + energies [i ].exchange_repulsion + energies [i ].charge_penetration ;
339+ msg ("%40s %16.10lf\n" , "PAIRWISE TOTAL ENERGY" , energies [i ].total );
340+ msg ("\n ---------------------------------------------------------\n" );
341+
342+ lattice_energy [0 ] = lattice_energy [0 ] + energies [i ].electrostatic ;
343+ lattice_energy [1 ] = lattice_energy [1 ] + energies [i ].polarization ;
344+ lattice_energy [2 ] = lattice_energy [2 ] + energies [i ].dispersion ;
345+ lattice_energy [3 ] = lattice_energy [3 ] + energies [i ].exchange_repulsion ;
346+ lattice_energy [4 ] = lattice_energy [4 ] + energies [i ].charge_penetration ;
347+ lattice_energy [5 ] = lattice_energy [5 ] + energies [i ].total ;
348+ }
349+ free (energies );
350+
351+ msg (" LATTICE ENERGY COMPONENTS (ATOMIC UNITS)\n" );
352+ msg ("%40s %16.10lf\n" , "LATTICE ELECTROSTATIC ENERGY" , lattice_energy [0 ]);
353+ msg ("%40s %16.10lf\n" , "LATTICE POLARIZATION ENERGY" , lattice_energy [1 ]);
354+ msg ("%40s %16.10lf\n" , "LATTICE DISPERSION ENERGY" , lattice_energy [2 ]);
355+ msg ("%40s %16.10lf\n" , "LATTICE EXCHANGE REPULSION ENERGY" , lattice_energy [3 ]);
356+ msg ("%40s %16.10lf\n" , "LATTICE CHARGE PENETRATION ENERGY" , lattice_energy [4 ]);
357+ msg ("%40s %16.10lf\n" , "LATTICE TOTAL ENERGY" , lattice_energy [5 ]);
358+ msg ("\n\n" );
359+
360+ msg (" ------ PAIRWISE ENERGY ANALYSIS COMPLETED --------------\n\n" );
361+ }
362+ }
363+
364+
365+
273366six_t box_from_str (const char * str )
274367{
275368 six_t box ;
@@ -283,3 +376,4 @@ six_t box_from_str(const char *str)
283376 // vec_scale(&box, 1.0 / BOHR_RADIUS);
284377 return box ;
285378}
379+
0 commit comments