File: getInitialState.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 (254 lines) | stat: -rw-r--r-- 9,254 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
252
253
254
/*

 $Id: getInitialState.cc,v 1.42 2014/07/02 00:01:21 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 <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <time.h>
#include "timesys.h"
#include "getInitialState.h"
#include "trilinterp.h"
#include "calculateEnergies.h"


extern char *programname;


void getInitialState(

            /* not const */ Real *const Addr_e0total,
            ConstReal  e0max,

            /* not const */ State *const sInit, /* was qtn0[QUAT] and tor0[MAX_TORS] */
            /* not const */ State *const sMinm, /* was qtnMin[QUAT] and torMin[MAX_TORS] */
            /* not const */ State *const sLast, /* was qtnLast[QUAT] and torLast[MAX_TORS] */

            const Boole B_RandomTran0,
            const Boole B_RandomQuat0,
            const Boole B_RandomDihe0,

            const Real charge[MAX_ATOMS],
            const Real abs_charge[MAX_ATOMS],
            const Real qsp_abs_charge[MAX_ATOMS],
            /* not const */ Real crd[MAX_ATOMS][SPACE],
            const Real crdpdb[MAX_ATOMS][SPACE],
            const char  atomstuff[MAX_ATOMS][MAX_CHARS],
            /* not const */ EnergyComponent	*peratomE,        // output if not NULL - intermolecular energies

            const EnergyTables *const ptr_ad_energy_tables,

            const Boole B_calcIntElec,
                #include "map_declare.h"
            const int   natom,
            const int   Nnb,
	    int Nnb_array[3],
	    GroupEnergy *group_energy,
	    const int true_ligand_atoms,
            const NonbondParam *const nonbondlist,
            const int   ntor,
            const int   tlist[MAX_TORS+1][MAX_ATOMS],
            const int   type[MAX_ATOMS],
            const Real vt[MAX_TORS][SPACE],
            const int   irun, // 0-origin, includes nconf
            const int   MaxRetries,

            ConstReal  torsFreeEnergy,

            const int   ligand_is_inhibitor,

            const int   ignore_inter[MAX_ATOMS],

            const Boole         B_include_1_4_interactions,
            ConstReal  scale_1_4,
	    ConstReal            scale_eintermol,  // input  scaling factor for intermolecular energies


            ConstReal  unbound_internal_FE,

            const GridMapSetInfo *const info,
            const Boole B_use_non_bond_cutoff,
            const Boole B_have_flexible_residues,
            const Unbound_Model ad4_unbound_model,
            const int   outlev,
	    FILE *logFile
           )

{
    Real e0total = 0.;
    Real e0inter = 0.;
    Real e0intra = 0.;
    Real e0min = BIG;
    int   retries = 0;
    register int i = 0;
    Clock  initStart;
    Clock  initEnd;
    struct tms tms_initStart;
    struct tms tms_initEnd;
    EnergyBreakdown eb;


    /* Store time at start of initialization process... */

    initStart = times( &tms_initStart );

    retries = 0;
    if ((B_RandomTran0) || (B_RandomQuat0) || (B_RandomDihe0)) {
        do {
            /*
            ** while e0total, initial energy, is too high,
            */

            /*
            ** Initialize all state variables...
            */
            if (B_RandomTran0) {
                sInit->T.x = random_range( info->lo[X], info->hi[X] );
                sInit->T.y = random_range( info->lo[Y], info->hi[Y] );
                sInit->T.z = random_range( info->lo[Z], info->hi[Z] );
                if (outlev >= LOGRUNV) {
                    pr( logFile, "Random initial translation,  tran0 %.3f %.3f %.3f\n", sInit->T.x, sInit->T.y, sInit->T.z);
                }
            }/*if*/
            if (B_RandomQuat0) {
                sInit->Q = randomQuat(); // generate a uniformly-distributed quaternion

                if (outlev >= LOGRUNV ) {
                    pr( logFile, "Random initial quaternion,  quaternion0 %.3f %.3f %.3f %.3f\n", sInit->Q.x, sInit->Q.y, sInit->Q.z,  sInit->Q.w );
                     // convert from qx,qy,qz,qw to axis-angle (nx,ny,nz,ang)
		    AxisAngle aa = QuatToAxisAngle(sInit->Q);
                    pr( logFile, "Random initial axis-angle,  axisangle0 %.3f %.3f %.3f %.1f\n", aa.nx, aa.ny, aa.nz, RadiansToDegrees( aa.ang ) );
                }
            }/*if*/
            if ( B_RandomDihe0 && (ntor > 0) ) {
                if (outlev >= LOGRUNV ) {
                    pr( logFile, "Random initial torsions, ndihe = %d\ndihe0 = ", ntor);
                }
                sInit->ntor = ntor;
                for (i=0; i<ntor; i++) {
                    sInit->tor[i] = random_range(-180.,180.);
                    if (outlev >= LOGRUNV ) {
                        pr( logFile, "%7.2f ", sInit->tor[i] ); /*in degrees*/
                    }
                    sInit->tor[i] = DegreesToRadians( sInit->tor[i] ); /*now in radians*/
                }
                if (outlev >= LOGRUNV ) {
                    pr( logFile, "\n");
                }
            }/*if*/

            copyState( sMinm, *sInit );
            copyState( sLast, *sInit );

    /* _________________________________________________________________________
    **
    ** Initialize the automated docking simulation,
    ** _________________________________________________________________________
    */
            initautodock( atomstuff, crd, crdpdb, 
                natom, ntor, sInit, tlist, vt, true_ligand_atoms,outlev, info);
            
            e0inter = scale_eintermol * trilinterp( 0, natom, crd, charge, abs_charge, type, map, 
                        info, ignore_inter, peratomE, NULL,
                        NULL_ENERGY_BREAKDOWN);
            e0intra = eintcal( nonbondlist, ptr_ad_energy_tables, crd,
			  Nnb, Nnb_array, group_energy,
                          B_calcIntElec, B_include_1_4_interactions,
                          scale_1_4, qsp_abs_charge,
                          B_use_non_bond_cutoff, B_have_flexible_residues,
			  outlev, logFile);
            e0total = e0inter + e0intra;

            if (e0total < e0min) {
                /*
                ** This energy is lower so update
                ** the initialization minimum-energy state variables,
                */
                e0min = e0total;
                copyState( sMinm, *sInit );
            }

            /*
            if ( (e0total > e0max) && ((!B_RandomTran0)||(!B_RandomQuat0)) ) {
                B_RandomTran0 = TRUE;
                B_RandomQuat0 = TRUE;
            }
            */

            ++retries;
            if ((retries > 0) && (retries < MaxRetries) &&
                (e0total > e0max) && (outlev >= LOGRUNVV)) {

                pr(logFile, "Initial total energy, e0total = %.3f, too high!\n", e0total);
                pr(logFile, "Number of attempts = %d (run %d)\n\n", retries, irun+1);
                pr(logFile, "Will try again...\n");

            } else if (retries >= MaxRetries) {

		if(outlev >= LOGRUNVV)
                pr( logFile, "Sorry, too many retries (%d).  Continuing...\n\nWill use the state with the lowest energy found, %.2f\n\n", MaxRetries, e0min);
                e0total = e0min;
                copyState( sInit, *sMinm );

                break;
            }
            fflush( logFile );
        } while ( e0total > e0max );
    } // endif

    cnv_state_to_coords( *sInit, vt, tlist, ntor, crdpdb, crd, natom,
     true_ligand_atoms, outlev, logFile);

    eb = calculateBindingEnergies( natom, ntor, unbound_internal_FE, torsFreeEnergy, B_have_flexible_residues,
         crd, charge, abs_charge, type, map, info,
         ignore_inter, peratomE, NULL,
         nonbondlist, ptr_ad_energy_tables,
	 Nnb, Nnb_array, group_energy, true_ligand_atoms,
         B_calcIntElec, B_include_1_4_interactions, scale_1_4, qsp_abs_charge, B_use_non_bond_cutoff, ad4_unbound_model,
	 outlev, logFile);

    copyState( sMinm, *sInit );
    copyState( sLast, *sInit );

    if(outlev>=LOGRUNVV) {
      prInitialState( &eb, natom, true_ligand_atoms, crd, atomstuff, type, peratomE, charge, 
       ligand_is_inhibitor, B_have_flexible_residues, ad4_unbound_model,
	outlev, logFile);
      initEnd = times( &tms_initEnd );
      pr(logFile, "Number of initialization attempts = %d (run %d)\n", retries, irun+1);
      pr(logFile, "Time spent initializing: (Real, CPU, System): ");
      timesys( initEnd - initStart, &tms_initStart, &tms_initEnd, logFile);
    }

    *Addr_e0total = eb.e_inter + eb.e_intra;

}
/* EOF */