-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclmode.cc
executable file
·323 lines (273 loc) · 11.8 KB
/
clmode.cc
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
/*
$Id: clmode.cc,v 1.7 2007/04/27 06:01:48 garrett Exp $
AutoDock
Copyright (C) 1989-2007, Garrett M. Morris, David S. Goodsell, Ruth Huey, Arthur J. Olson,
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 <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <sys/times.h>
#include "clmode.h"
extern FILE *logFile;
extern char *programname;
void clmode( int num_atm_maps,
Real clus_rms_tol,
char hostnm[MAX_CHARS],
Clock jobStart,
struct tms tms_jobStart,
Boole write_all_clusmem,
char clusFN[MAX_CHARS],
Real crdpdb[MAX_ATOMS][SPACE],
Real sml_center[SPACE],
Boole symmetry_flag,
char rms_ref_crds[MAX_CHARS] )
{
FILE *clusFile;
register int xyz = 0;
int anum = 0;
char atomstuff[MAX_ATOMS][MAX_CHARS];
Real crdSave[MAX_RUNS][MAX_ATOMS][SPACE];
Real econf[MAX_RUNS];
Real eSave[2];
Boole haveAtoms = FALSE;
Boole haveTypes = FALSE;
int ii = 0;
int lastanum = -1;
char line[LINE_LEN];
int atomCounter = 0;
int natom = 0;
int natom_1 = -1;
int nconf = 0;
int confCounter = 0;
int ntype[MAX_ATOMS];
char pdbaname[MAX_ATOMS][5];
Real q = 0.;
char rec5[5];
int nsaved = 0;
char anumStr[5];
int type[MAX_ATOMS];
Real clu_rms[MAX_RUNS][MAX_RUNS];
int cluster[MAX_RUNS][MAX_RUNS];
register int i = 0;
register int j = 0;
int irunmax = -1;
int isort[MAX_RUNS];
int ncluster = 0;
int num_in_clu[MAX_RUNS];
Real ref_crds[MAX_ATOMS][SPACE];
int ref_natoms = -1;
Real ref_rms[MAX_RUNS];
Boole haveEnergy = FALSE;
ParameterEntry thisparm;
for (j = 0; j < MAX_RUNS; j++) {
num_in_clu[j] = 0;
isort[j] = j;
econf[j] = 0.;
}
/*
* Open file containing coordinates to be clustered...
*/
if ( openFile( clusFN , "r", &clusFile, jobStart, tms_jobStart, TRUE ) ) {
pr( logFile, "Conformations to be clustered are in this file: \"%s\"\n\n", clusFN );
}
/*
* Read in the conformations
* All we need are the xyz's of each conformation,
* and their Energies, plus the Run number/parent dlg file.
*/
while ( fgets( line, LINE_LEN, clusFile) != NULL ) {
pr( logFile, "INPUT-PDBQ: %s", line);
for (ii = 0; ii < 4; ii++) { rec5[ii] = tolower( (int)line[ii] ); };
if (( strindex( line, "USER Total Interaction Energy of Complex") >= 0 )
|| ( strindex( line, "REMARK Total Interaction Energy of Complex") >= 0 )) {
/*
* Read in the energy of this conformation;
* This is preferred over "Final Docked Energy" because this is never
* printed out rounded up as +4.25e+03, but always as +4246.45, e.g.:
*/
if ( haveAtoms ) {
econf[confCounter] = 0.;
sscanf( line, "%*s %*s %*s %*s %*s %*s %*s " FDFMT, &econf[confCounter]);
haveEnergy = TRUE;
} else {
/* ! haveAtoms
* We have not seen any atoms yet, so save this energy.
*/
eSave[nsaved]=0.;
sscanf( line, "%*s %*s %*s %*s %*s %*s %*s " FDFMT, &eSave[nsaved] );
++nsaved;
}
} else if ( (( strindex( line, "USER Final Docked Energy") >= 0 )
|| ( strindex( line, "REMARK Final Docked Energy") >= 0 )) && ( ! haveEnergy ) ) {
/*
* Read in the energy of this conformation if we don't already
* have an energy:
*/
if ( haveAtoms ) {
econf[confCounter] = 0.;
sscanf( line, "%*s %*s %*s %*s %*s " FDFMT, &econf[confCounter]);
haveEnergy = TRUE;
} else {
/* ! haveAtoms
* We have not seen any atoms yet, so save this energy.
*/
eSave[nsaved]=0.;
sscanf( line, "%*s %*s %*s %*s %*s " FDFMT, &eSave[nsaved] );
++nsaved;
}
} else if (equal( rec5,"atom", 4) || equal( rec5,"heta", 4)) {
int serial;
/*
* This line should contain coordinates, partial charge &
* atom type for one atom.
* Let's save the coordinates for this atom, atomCounter.
*/
readPDBQTLine( line, &serial, crdSave[confCounter][atomCounter], &q, &thisparm );
if ( ! haveAtoms ) {
/*
* We do not have any atoms for this conformation,
*/
sscanf( &line[6], "%s", anumStr );
if ((anum = atoi(anumStr)) < lastanum) { /* initially, lastanum is -1, while anum is probably never -1, so this is false initially */
/*
* haveAtoms is FALSE, but this line begins with "atom" or
* "heta", so this must be the...
*
* Start of next conformation,
*/
/* This is an atom line, so haveAtoms must be set to true: */
haveAtoms = TRUE;
/* We must also have read in the atom types: */
haveTypes = TRUE;
/* Transfer the saved energies to the econf arrays: */
econf[0] = eSave[0];
econf[1] = eSave[1];
/* Now we have the energy: */
haveEnergy = TRUE;
/* Increment the number of conformations */
++confCounter;
for (xyz = 0; xyz < SPACE; xyz++) {
crdSave[confCounter][0][xyz] = crdSave[confCounter-1][atomCounter][xyz];
}
natom = atomCounter; /* number of atoms is set to the atom counter*/
natom_1 = natom - 1; /* number of atoms minus 1, for 0-based counting */
atomCounter = 0; /* reset the counter "atomCounter" */
} else {
/*
* First of all, determine the atom types for all the atoms in the
* molecule:
*/
strncpy( atomstuff[atomCounter], line, (size_t)30 );
atomstuff[atomCounter][30] = '\0';
if ( ! haveTypes ) {
type[atomCounter] = -1;
sscanf( &line[12], "%s", pdbaname[atomCounter] );
/*
* Determine this atom's atom type:
*/
type[atomCounter] = get_atom_type(pdbaname[atomCounter]);
if (type[atomCounter] == -1) {
pr( logFile, "\nNOTE: Atom number %d, using default atom type 1...\n\n", atomCounter+1);
type[atomCounter] = 1;
} else {
pr( logFile, "\nAtom number %d, recognized atom type = %d...\n\n", atomCounter+1, type[atomCounter]+1);
}
/*
* Increment the number of atoms with this atom type:
*/
++ntype[ type[atomCounter] ];
}
}
/*
* Update the value of the last atom's serial number:
*/
lastanum = anum;
} else if ( atomCounter == natom_1 ) { /* initially, atomCounter=0, and natom_1= -1, so this is not true initially */
/*
* We have all the atoms we expect for one molecule:
* Increment total number of conformations,
*/
++confCounter;
atomCounter = -1; /* Pre-zero out the "atomCounter" counter... */
haveEnergy = FALSE; /* we don't have energy yet for next conf. */
}
/*
* Just increment the number of atoms, atomCounter:
*/
++atomCounter;
} /* This was an "atom" or "heta" line */
} /* end while there is a new line. */
irunmax = confCounter;
nconf = confCounter;
pr( logFile, "\nNumber of conformations found = %d\n", nconf );
pr( logFile, "\nNumber of atoms per conformation = %d\n\n", natom );
for (i=0; i<num_atm_maps; i++) {
pr( logFile, "Number of atoms with type %d = %d\n", i+1, ntype[i]);
}
if (strncmp(rms_ref_crds,"unspecified filename",20) != 0) {
/*
* Read in reference structure, specified by the "rmsref" command...
*/
if ((ref_natoms = getpdbcrds( rms_ref_crds, ref_crds)) == -1) {
fprintf( logFile, "%s: Problems while reading \"%s\".\n", programname, rms_ref_crds);
fprintf( logFile, "Will attempt to use the input PDBQ file coordinates as reference.\n");
} else if (ref_natoms != natom) {
pr( logFile, "%s: ERROR! Wrong number of atoms in reference structure.\n", programname);
pr( logFile, "Input PDBQ structure has %d atoms, but reference structure has %d atoms.\n\n", natom, ref_natoms);
ref_natoms = -1;
}
}
if (nconf <= 1) {
pr( logFile, "\nSorry! Unable to perform cluster analysis, because not enough structures were read in.\n");
} else {
#ifdef DEBUG
for (i = 0; i < nconf; i++) {
pr( logFile, "i=%-3d\tisort[i]=%-3d\teconf[isort[i]]=%+7.2f\n",
i, isort[i], econf[isort[i]] );
}
#endif /* DEBUG */
pr( logFile, "\nSorting %d conformations by their energy.\n", irunmax);
flushLog;
sort_enrg( econf, isort, nconf );
#ifdef DEBUG
for (i = 0; i < nconf; i++) { pr( logFile, "i=%-3d\tisort[i]=%-3d\teconf[isort[i]]=%+7.2f\n", i, isort[i], econf[isort[i]] ); }
#endif /* DEBUG */
pr( logFile, "\nPerforming cluster analysis, using a cluster RMS tolerance of %.1f\n", clus_rms_tol );
flushLog;
ncluster = cluster_analysis( clus_rms_tol, cluster, num_in_clu, isort,
nconf, natom, type, crdSave, crdpdb,
sml_center, clu_rms, symmetry_flag,
ref_crds, ref_natoms, ref_rms);
pr( logFile, "\nOutputting structurally similar clusters, ranked in order of increasing energy.\n" );
flushLog;
prClusterHist( ncluster, irunmax, clus_rms_tol, num_in_clu,
cluster, econf, clu_rms, ref_rms);
bestpdb( ncluster, num_in_clu, cluster, econf, crdSave,
atomstuff, natom, write_all_clusmem, ref_rms);
}/*if we have more than 1 conformation... */
/*
* End cluster_mode and END PROGRAM...
*/
success( hostnm, jobStart, tms_jobStart );
exit((int)0);
}
/* EOF */