File: com.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 (330 lines) | stat: -rw-r--r-- 11,627 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*

 $Id: com.cc,v 1.12 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 <stdio.h>
#include <stdlib.h>
#include "ranlib.h"
#include "structs.h"
#include "stop.h"

/* this software can be configured to provide multiple concurrent
 random number generators (e.g., 32), however, AutoDock uses only one
 at present unless compiled for OpenMP (OMP).
 This number NUMG is defined in ranlib.h M Pique 2014-02
 */

/* this software can be configured to optionally return antithetic values,
 * see function Xqanti below. Not used in AutoDock.
 * to enable, #define ANTITHETIC
 */



/* former FORTRAN COMMON block, now statically initialized as constants: */
/*
     V=20;                            W=30;
     A1W = MOD(A1**(2**W),M1)         A2W = MOD(A2**(2**W),M2)
     A1VW = MOD(A1**(2**(V+W)),M1)    A2VW = MOD(A2**(2**(V+W)),M2)
   If V or W is changed A1W, A2W, A1VW, and A2VW need to be recomputed.
    An efficient way to precompute a**(2*j) MOD m is to start with
    a and square it j times modulo m using the function MLTMOD.
*/
#define Xm1 ((FourByteLong) 2147483563L)
#define Xm2 ((FourByteLong) 2147483399L)
#define Xa1 ((FourByteLong) 40014L)
#define Xa2 ((FourByteLong) 40692L)
#define Xa1w ((FourByteLong) 1033780774L)
#define Xa2w ((FourByteLong) 1494757890L)
#define Xa1vw ((FourByteLong) 2082007225L)
#define Xa2vw ((FourByteLong) 784306273L)

/* former FORTRAN EXTERN, now static to this source file: */
static FourByteLong Xcg1[NUMG],Xcg2[NUMG],Xig1[NUMG],Xig2[NUMG],Xlg1[NUMG],Xlg2[NUMG];

#ifdef ANTITHETIC
static int Xqanti[NUMG]; /* boolean, initially zero */
#endif

static int qqssd=false; /* have seeds been set (was gsssd() in code MP */
static int curntg=0; /* global: current generator (was 'g' from gscgn() in code) MP */

void advnst(const int k)  // not used in AutoDock code
/*
**********************************************************************
     void advnst(const int k)
               ADV-a-N-ce ST-ate
     Advances the state  of  the current  generator  by 2^K values  and
     resets the initial seed to that value.
     This is  a  transcription from   Pascal to  Fortran    of  routine
     Advance_State from the paper
     L'Ecuyer, P. and  Cote, S. "Implementing  a  Random Number Package
     with  Splitting   Facilities."  ACM  Transactions  on Mathematical
     Software, 17:98-111 (1991)
                              Arguments
     k -> The generator is advanced by 2^K values
**********************************************************************
*/
{
FourByteLong ib1,ib2;


    ib1 = Xa1;
    ib2 = Xa2;
    for (int i=0; i<k; i++) {
        ib1 = mltmod(ib1,ib1,Xm1);
        ib2 = mltmod(ib2,ib2,Xm2);
    }
    setsd_t(mltmod(ib1,Xcg1[curntg],Xm1),mltmod(ib2,Xcg2[curntg],Xm2),curntg);
/*
     NOW, IB1 = A1**K AND IB2 = A2**K
*/
}
void getsd_t(FourByteLong *const iseed1,FourByteLong *const iseed2, int curntg)
/* thread-safe if curntg is current thread number
**********************************************************************
     void getsd_t(FourByteLong *iseed1,FourByteLong *iseed2)
               GET SeeD
     Returns the value of two integer seeds of the current generator
     This  is   a  transcription from  Pascal   to  Fortran  of routine
     Get_State from the paper
     L'Ecuyer, P. and  Cote,  S. "Implementing a Random Number  Package
     with   Splitting Facilities."  ACM  Transactions   on Mathematical
     Software, 17:98-111 (1991)
                              Arguments
     iseed1 <- First integer seed of generator G
     iseed2 <- Second integer seed of generator G
**********************************************************************
*/
{

    *iseed1 = Xcg1[curntg];
    *iseed2 = Xcg2[curntg];
}
FourByteLong ignlgi_t(int curntg)
/* thread-safe if curntg is thread index (0 to NUMG-1)
**********************************************************************
     FourByteLong ignlgi(void)
               GeNerate LarGe Integer
     Returns a random integer following a uniform distribution over
     (1, 2147483562) using the current generator.
     This is a transcription from Pascal to Fortran of routine
     Random from the paper
     L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
     with Splitting Facilities." ACM Transactions on Mathematical
     Software, 17:98-111 (1991)
**********************************************************************
*/
{
FourByteLong k,s1,s2,z;
/*
     IF THE RANDOM NUMBER PACKAGE HAS NOT BEEN INITIALIZED YET, DO SO.
     IT CAN BE INITIALIZED IN ONE OF TWO WAYS : 1) THE FIRST CALL TO
     THIS ROUTINE  2) A CALL TO SETALL.
*/
    if(!qqssd) setall(1234567890L,123456789L);
/*
     Get Current Generator
*/
    s1 = Xcg1[curntg];
    s2 = Xcg2[curntg];
    k = s1/53668L;
    s1 = Xa1*(s1-k*53668L)-k*12211;
    if(s1 < 0) s1 += Xm1;
    k = s2/52774L;
    s2 = Xa2*(s2-k*52774L)-k*3791;
    if(s2 < 0) s2 += Xm2;
    Xcg1[curntg] = s1;
    Xcg2[curntg] = s2;
    z = s1-s2;
    if(z < 1) z += (Xm1-1);
#ifdef ANTITHETIC
    if(Xqanti[curntg]) z = Xm1-z;
#endif
    return z;
}

void initgn(const int g, const int isdtyp)
/*
**********************************************************************
     void initgn(const int g, const int isdtyp)
          INIT-ialize current G-e-N-erator
     Reinitializes the state of the generator g
     This is a transcription from Pascal to Fortran of routine
     Init_Generator from the paper
     L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
     with Splitting Facilities." ACM Transactions on Mathematical
     Software, 17:98-111 (1991)
                              Arguments
     g the generator index 0..NUMG-1
     isdtyp -> The state to which the generator is to be set
          isdtyp = -1  => sets the seeds to their initial value
          isdtyp =  0  => sets the seeds to the first value of
                          the current block
          isdtyp =  1  => sets the seeds to the first value of
                          the next block
**********************************************************************
*/
{

    switch (isdtyp) {
    case -1:
	Xlg1[g] = Xig1[g];
	Xlg2[g] = Xig2[g];
	break;
    case 0:
	break;
    case 1:
	Xlg1[g] = mltmod(Xa1w,Xlg1[g],Xm1);
	Xlg2[g] = mltmod(Xa2w,Xlg2[g],Xm2);
	break;
    default:
        stop("isdtyp not in range in INITGN");
    }

    Xcg1[g] = Xlg1[g];
    Xcg2[g] = Xlg2[g];
}
void setall(const FourByteLong iseed1,const FourByteLong iseed2)
/*
**********************************************************************
     void setall(FourByteLong iseed1,FourByteLong iseed2)
               SET ALL random number generators
     Sets the initial seed of generator 1 to ISEED1 and ISEED2. The
     initial seeds of the other generators are set accordingly, and
     all generators states are set to these seeds.
     This is a transcription from Pascal to Fortran of routine
     Set_Initial_Seed from the paper
     L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
     with Splitting Facilities." ACM Transactions on Mathematical
     Software, 17:98-111 (1991)
                              Arguments
     iseed1 -> First of two integer seeds
     iseed2 -> Second of two integer seeds
**********************************************************************
*/
{
/*
     TELL IGNLGI, THE ACTUAL NUMBER GENERATOR, THAT THIS ROUTINE
      HAS BEEN CALLED.
*/
// MPique - omp critical probably not needed but being on the safe side 2014
#pragma omp critical
{
    qqssd=true;

    Xig1[0] = iseed1;
    Xig2[0] = iseed2;
    initgn(0, -1);
    for (int g=1; g<NUMG; g++) {
        Xig1[g] = mltmod(Xa1vw,Xig1[g-1],Xm1);
        Xig2[g] = mltmod(Xa2vw,Xig2[g-1],Xm2);
        initgn(g, -1);
    }
    }
}
#ifdef ANTITHETIC
void setant(const FourByteLong qvalue)
/*
**********************************************************************
     void setant(FourByteLong qvalue)
               SET ANTithetic
     Sets whether the current generator produces antithetic values.  If
     X   is  the value  normally returned  from  a uniform [0,1] random
     number generator then 1  - X is the antithetic  value. If X is the
     value  normally  returned  from a   uniform  [0,N]  random  number
     generator then N - 1 - X is the antithetic value.
     All generators are initialized to NOT generate antithetic values.
     This is a transcription from Pascal to Fortran of routine
     Set_Antithetic from the paper
     L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
     with Splitting Facilities." ACM Transactions on Mathematical
     Software, 17:98-111 (1991)
                              Arguments
     qvalue -> nonzero if generator G is to generating antithetic
                    values, otherwise zero
**********************************************************************
*/
{

    Xqanti[curntg] = qvalue;
}
#endif
void setsd_t(const FourByteLong iseed1,const FourByteLong iseed2, int curntg)
/* thread-safe if curntg is current thread number
**********************************************************************
     void setsd_t(FourByteLong iseed1,FourByteLong iseed2,curntg)
               SET S-ee-D of current generator
     Resets the initial  seed of  the current  generator to  ISEED1 and
     ISEED2. The seeds of the other generators remain unchanged.
     This is a transcription from Pascal to Fortran of routine
     Set_Seed from the paper
     L'Ecuyer, P. and Cote, S. "Implementing a Random Number Package
     with Splitting Facilities." ACM Transactions on Mathematical
     Software, 17:98-111 (1991)
                              Arguments
     iseed1 -> First integer seed
     iseed2 -> Second integer seed
**********************************************************************
*/
{

    if(iseed1==0 || iseed2==0) {
	    char errmsg[200];
            sprintf(errmsg, 
	    "BUG: random number seed is zero in setsd_t(iseed1=%ld, iseed2=%ld, g=%d)",
 		(long) iseed1, (long) iseed2, curntg);
	    stop(errmsg);
	    }
    Xig1[curntg] = iseed1;
    Xig2[curntg] = iseed2;
    initgn(curntg, -1);
}
int gscgn(const int g)
/*
**********************************************************************
     int gscgn(const int g)
                         Get/Set GeNerator
     Sets the global number of the current generator curntg to g
     Returns previous value 
                              Arguments
     g <-- Number of the current random number generator (0..NUMG-1)
**********************************************************************
*/
{
int otg = curntg;
    if( g >= 0 && g < NUMG) curntg = g;
    else {
	    char errmsg[200];
            sprintf(errmsg, 
	    "BUG: Generator number %d out of range %d to %d in GSCGN",g,0,NUMG-1);
	    stop(errmsg);
        }
    return otg;
}