File: printEnergies.cc

package info (click to toggle)
autodocksuite 4.2.6-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 97,028 kB
  • sloc: cpp: 24,257; sh: 4,419; python: 1,261; makefile: 627; perl: 15
file content (251 lines) | stat: -rw-r--r-- 8,988 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*

 $Id: printEnergies.cc,v 1.23 2014/06/12 01:44:07 mp Exp $

 AutoDock 

Copyright (C) 2009 The Scripps Research Institute. All rights reserved.

 AutoDock is a Trade Mark of The Scripps Research Institute.

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "printEnergies.h"
#include "constants.h"

static inline void  print1000(FILE *file, ConstReal x) {
	pr(file,  ((fabs((x)) >= 0.0) && ((fabs(x)) <= 1000.)) ? "%+7.2f" : "%+11.2e" , (x));
}

static inline void print1000_no_sign(FILE *const file, const double x) {
    pr(file,  ((fabs((x)) >= 0.01) && ((fabs(x)) <= 1000.)) ? "%7.2f" : "%11.2e" , (x));
}

void print_molar(FILE *const file, const double x) {
    // 1e-3  <= x < 1     mM millimolar
    // 1e-6  <= x < 1e-3  uM micromolar
    // 1e-9  <= x < 1e-6  nM nanomolar
    // 1e-12 <= x < 1e-9  pM picomolar
    // 1e-15 <= x < 1e-12 fM femtomolar
    // 1e-18 <= x < 1e-15 aM attomolar
    // 1e-21 <= x < 1e-18 zM zeptomolar
    // 1e-24 <= x < 1e-21 yM yottomolar
    //          x < 1e-24    sub-yottomolar
    if ((fabs((x)) > 1e-3) && ((fabs(x)) <= 1.)) {
        pr(file, "%7.2f mM (millimolar)", x*1e3);
    } else if ((fabs((x)) > 1e-6) && ((fabs(x)) <= 1e-3)) {
        pr(file, "%7.2f uM (micromolar)", x*1e6);
    } else if ((fabs((x)) > 1e-9) && ((fabs(x)) <= 1e-6)) {
        pr(file, "%7.2f nM (nanomolar)", x*1e9);
    } else if ((fabs((x)) > 1e-12) && ((fabs(x)) <= 1e-9)) {
        pr(file, "%7.2f pM (picomolar)", x*1e12);
    } else if ((fabs((x)) > 1e-15) && ((fabs(x)) <= 1e-12)) {
        pr(file, "%7.2f fM (femtomolar)", x*1e15);
    } else if ((fabs((x)) > 1e-18) && ((fabs(x)) <= 1e-15)) {
        pr(file, "%7.2f aM (attomolar)", x*1e18);
    } else if ((fabs((x)) > 1e-21) && ((fabs(x)) <= 1e-18)) {
        pr(file, "%7.2f zM (zeptomolar)", x*1e21);
    } else if ((fabs((x)) > 1e-24) && ((fabs(x)) <= 1e-21)) {
        pr(file, "%7.2f yM (yottomolar)", x*1e24);
    } else {
        pr(file, "%11.2e M (molar)", x);
    }
}

void printEnergies( const EnergyBreakdown *const eb,
                    const char *const prefixString,
                    const int  ligand_is_inhibitor,
                    ConstReal emap_total,
                    ConstReal elec_total,
                    const Boole B_have_flexible_residues, 
		    ConstReal emap_flexres_total,
		    ConstReal elec_flexres_total,
                    const Unbound_Model ad4_unbound_model,
		    int outlev, FILE *logFile
                   )

{
    Real Ki = 1.0;

    // equilibrium:   E  +  I  <=>    EI
    // binding:       E  +  I   ->    EI         K(binding),      Kb
    // dissociation:     EI     ->  E  +  I      K(dissociation), Kd
    //
    //                            1
    //         K(binding) = ---------------
    //                      K(dissociation)
    // so:
    //      ln K(binding) = -ln K(dissociation)
    //              ln Kb = -ln Kd
    // Ki = dissociation constant of the enzyme-inhibitor complex = Kd
    //      [E][I]
    // Ki = ------
    //       [EI]
    // so:
    //              ln Kb = -ln Ki
    // deltaG(binding)    = -R*T*ln Kb
    // deltaG(inhibition) =  R*T*ln Ki
    //
    // Binding and Inhibition occur in opposite directions, so we 
    // lose the minus-sign:  deltaG = R*T*lnKi,  _not_ -R*T*lnKi
    // => deltaG/(R*T) = lnKi
    // => Ki = exp(deltaG/(R*T))
    if (eb->deltaG < 0.0) {
        Ki = exp((eb->deltaG*1000.)/(Rcal*TK));
    }

    if (strncmp(prefixString, "UNBOUND", 7) != 0 ) {
        pr( logFile, "%sEstimated Free Energy of Binding    = ", prefixString);
        print1000(logFile, eb->deltaG);
        pr( logFile, " kcal/mol  [=(1)+(2)+(3)-(4)]\n");

        if (eb->deltaG < 0.0) {
            if (ligand_is_inhibitor == 1) {
                pr( logFile, "%sEstimated Inhibition Constant, Ki   = ", prefixString);
            } else {
                pr( logFile, "%sEstimated Dissociation Constant, Kd = ", prefixString);
            }
            // print1000_no_sign(logFile, Ki);
            print_molar(logFile, Ki);
            pr( logFile, "  [Temperature = %.2f K]\n", TK);
        }

        pr( logFile, "%s\n", prefixString);
    }

// convenience function:
#define item(label, term) pr(logFile, "%s%s", prefixString, label),\
 print1000(logFile, term),\
 pr(logFile, " kcal/mol\n")

item("(1) Final Intermolecular Energy     = ", eb->e_inter);

if(B_have_flexible_residues) {
item("    Moving Ligand-Fixed Receptor    = ", eb->e_inter_moving_fixed);
item("       vdW + Hbond + desolv Energy  = ", emap_total);
item("       Electrostatic Energy         = ", elec_total);
item("    Moving Ligand-Moving Receptor   = ", eb->e_inter_moving_moving);
item("       vdW + Hbond + desolv Energy  = ", emap_flexres_total);
item("       Electrostatic Energy         = ", elec_flexres_total);
} else {
item("    vdW + Hbond + desolv Energy     = ", emap_total);
item("    Electrostatic Energy            = ", elec_total);
}

item("(2) Final Total Internal Energy     = ", eb->e_intra);
if(B_have_flexible_residues) {
item("    Internal Energy Ligand          = ", eb->e_intra_lig);
item("    Internal Moving-Fixed Receptor  = ", eb->e_intra_moving_fixed_rec);
item("    Internal Moving-Moving Receptor = ", eb->e_intra_moving_moving_rec);
}
item("(3) Torsional Free Energy           = ", eb->e_torsFreeEnergy);

    switch(ad4_unbound_model){
        // in AutoDock 4.2, the default unbound model is "unbound is same as bound"
        case Unbound_Default:
        case Unbound_Same_As_Bound:
        default:
            item("(4) Unbound System's Energy  [=(2)] = ", eb->e_unbound_internal_FE); 
            break;
        case User:
        case Extended:
        case Compact:
            item("(4) Unbound System's Energy         = ", eb->e_unbound_internal_FE);
            break;
    }

    pr( logFile, "%s\n", prefixString);
    pr( logFile, "%s\n", prefixString);
}
#undef item

void printStateEnergies( const EnergyBreakdown *const eb, 
  const char  *const prefixString, const int ligand_is_inhibitor,
  int outlev, FILE *stateFile)
{
    // Real deltaG = 0.0;
    Real Ki = 1.0;
    // Real RJ = 8.31441;  // in J/K/mol, Gas Constant, Atkins Phys.Chem., 2/e
    Real Rcal = 1.9871917; // in cal/K/mol, Gas Constant, RJ/4.184
    Real TK = 298.15;      // Room temperature, in K

    // equilibrium:   E  +  I  <=>    EI
    // binding:       E  +  I   ->    EI         K(binding),      Kb
    // dissociation:     EI     ->  E  +  I      K(dissociation), Kd
    //
    //                            1
    //         K(binding) = ---------------
    //                      K(dissociation)
    // so:
    //      ln K(binding) = -ln K(dissociation)
    //              ln Kb = -ln Kd
    // Ki = dissociation constant of the enzyme-inhibitor complex = Kd
    //      [E][I]
    // Ki = ------
    //       [EI]
    // so:
    //              ln Kb = -ln Ki
    // deltaG(binding)    = -R*T*ln Kb
    // deltaG(inhibition) =  R*T*ln Ki
    //
    // Binding and Inhibition occur in opposite directions, so we 
    // lose the minus-sign:  deltaG = R*T*lnKi,  _not_ -R*T*lnKi
    // => deltaG/(R*T) = lnKi
    // => Ki = exp(deltaG/(R*T))
    if (eb->deltaG < 0.0) {
        Ki = exp((eb->deltaG*1000.)/(Rcal*TK));
    }

    pr(stateFile, "\t\t<free_NRG_binding>");
    print1000(stateFile, eb->deltaG);
    pr(stateFile, "</free_NRG_binding>\n");

    if (eb->deltaG < 0.0) {
        if (ligand_is_inhibitor == 1) {
            pr(stateFile, "\t\t<Ki>");
            print1000_no_sign(stateFile, Ki);
            pr(stateFile, "</Ki>\n");
        } else {
            pr(stateFile, "\t\t<Kd>");
            print1000_no_sign(stateFile, Ki);
            pr(stateFile, "</Kd>\n");
        }
        pr(stateFile, "\t\t<Temp>%.2f</Temp>\n", TK); //temperature in K
    } 

    pr(stateFile, "\t\t<final_intermol_NRG>");
    print1000(stateFile, eb->e_inter);
    pr(stateFile, "</final_intermol_NRG>\n");

    pr(stateFile, "\t\t<internal_ligand_NRG>");
    print1000(stateFile, eb->e_intra);
    pr(stateFile, "</internal_ligand_NRG>\n");

    pr(stateFile, "\t\t<torsonial_free_NRG>");
    print1000(stateFile, eb->e_torsFreeEnergy);
    pr(stateFile, "</torsonial_free_NRG>\n"); 
}

// EOF