~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/protein/ProteinPocketFinder.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
2
 * 
 
3
 * Copyright (C) 2005-2007  Christian Hoppe <chhoppe@users.sf.net>
 
4
 * 
 
5
 * Contact: cdk-devel@lists.sourceforge.net
 
6
 * 
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public License
 
9
 * as published by the Free Software Foundation; either version 2.1
 
10
 * of the License, or (at your option) any later version.
 
11
 * 
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU Lesser General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
20
 */
 
21
package org.openscience.cdk.protein;
 
22
 
 
23
import org.openscience.cdk.config.AtomTypeFactory;
 
24
import org.openscience.cdk.interfaces.*;
 
25
import org.openscience.cdk.io.IChemObjectReader;
 
26
import org.openscience.cdk.io.ReaderFactory;
 
27
import org.openscience.cdk.protein.data.PDBAtom;
 
28
import org.openscience.cdk.tools.GridGenerator;
 
29
import org.openscience.cdk.tools.LoggingTool;
 
30
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
 
31
 
 
32
import javax.vecmath.Point3d;
 
33
import java.io.BufferedWriter;
 
34
import java.io.FileReader;
 
35
import java.io.FileWriter;
 
36
import java.io.IOException;
 
37
import java.util.ArrayList;
 
38
import java.util.Collections;
 
39
import java.util.Hashtable;
 
40
import java.util.Vector;
 
41
 
 
42
/**
 
43
 * The detection of pocket and cavities in a bioPolymer is done similar to the program 
 
44
 * LIGSITE {@cdk.cite MH1997}.
 
45
 * 
 
46
 * <p>TODO: Optimisation of the cubic grid placement 
 
47
 *
 
48
 * @author      cho
 
49
 * @cdk.created 2005-09-30
 
50
 * @cdk.module     experimental
 
51
 * @cdk.keyword    protein
 
52
 * @cdk.keyword    pocket
 
53
 */
 
54
public class ProteinPocketFinder {
 
55
        
 
56
        private final LoggingTool logger = new LoggingTool(ProteinPocketFinder.class);
 
57
 
 
58
        int solvantValue = 0;
 
59
        int proteinInterior = -1;
 
60
        int pocketSize = 100;// # datapoints needed to form a pocket
 
61
        double rAtom = 1.5;// default atom radius
 
62
        double rSolvent = 1.4;// default solvant radius
 
63
        double latticeConstant = 0.5;
 
64
        int minPSPocket = 2;
 
65
        int minPSCluster = 2;
 
66
        double linkageRadius = 1;
 
67
        double atomCheckRadius = 0;// variable to reduce the atom radius search
 
68
        // points
 
69
        IBioPolymer protein = null;
 
70
        String vanDerWaalsFile="org/openscience/cdk/config/data/pdb_atomtypes.xml";
 
71
        double[][][] grid = null;
 
72
        GridGenerator gridGenerator = new GridGenerator();
 
73
        Hashtable visited = new Hashtable();
 
74
        Vector pockets = new Vector();
 
75
 
 
76
        /**
 
77
         * @param biopolymerFile The file name containing the protein
 
78
         * @param cubicGrid          if true generate the grid
 
79
         */
 
80
        public ProteinPocketFinder(String biopolymerFile, boolean cubicGrid) {
 
81
                readBioPolymer(biopolymerFile);
 
82
                if (cubicGrid) {
 
83
                        createCubicGrid();
 
84
                }
 
85
        }
 
86
 
 
87
        public ProteinPocketFinder(String biopolymerFile, double latticeConstant,
 
88
                        boolean cubicGrid) {
 
89
                readBioPolymer(biopolymerFile);
 
90
                this.latticeConstant = latticeConstant;
 
91
                gridGenerator.setLatticeConstant(this.latticeConstant);
 
92
                if (cubicGrid) {
 
93
                        createCubicGrid();
 
94
                } else {
 
95
                        
 
96
                }
 
97
        }
 
98
 
 
99
        public ProteinPocketFinder(String biopolymerFile, double[][][] grid) {
 
100
                this.grid = grid;
 
101
                gridGenerator.setGrid(grid);
 
102
                readBioPolymer(biopolymerFile);
 
103
        }
 
104
 
 
105
        public ProteinPocketFinder(IBioPolymer protein, double[][][] grid) {
 
106
                this.protein = protein;
 
107
                this.grid = grid;
 
108
                gridGenerator.setGrid(grid);
 
109
        }
 
110
 
 
111
        /**
 
112
         * Creates from a PDB File a BioPolymer.
 
113
         */
 
114
        private void readBioPolymer(String biopolymerFile) {
 
115
                try {
 
116
                        // Read PDB file
 
117
                        FileReader fileReader = new FileReader(biopolymerFile);
 
118
                        IChemObjectReader reader = new ReaderFactory()
 
119
                                        .createReader(fileReader);
 
120
                        IChemFile chemFile = (IChemFile) reader
 
121
                                        .read((IChemObject) new org.openscience.cdk.ChemFile());
 
122
                        // Get molecule from ChemFile
 
123
                        IChemSequence chemSequence = chemFile.getChemSequence(0);
 
124
                        IChemModel chemModel = chemSequence.getChemModel(0);
 
125
                        IMoleculeSet setOfMolecules = chemModel.getMoleculeSet();
 
126
                        protein = (IBioPolymer) setOfMolecules.getMolecule(0);
 
127
                } catch (Exception exc) {
 
128
                        logger.error("Could not read BioPolymer from file>"
 
129
                                        + biopolymerFile + " due to: " + exc.getMessage());
 
130
                        logger.debug(exc);
 
131
                }
 
132
        }
 
133
 
 
134
        
 
135
        /**
 
136
         * Method determines the minimum and maximum values of a coordinate space 
 
137
         * up to 3D space.
 
138
         * 
 
139
         * @return double[] stores min,max,min,max,min,max
 
140
         */
 
141
        public double[] findGridBoundaries() {
 
142
                IAtom[] atoms = AtomContainerManipulator.getAtomArray(protein);
 
143
                double[] minMax = new double[6];
 
144
                minMax[0] = atoms[0].getPoint3d().x;
 
145
                minMax[1] = atoms[0].getPoint3d().x;
 
146
                minMax[2] = atoms[0].getPoint3d().y;
 
147
                minMax[3] = atoms[0].getPoint3d().y;
 
148
                minMax[4] = atoms[0].getPoint3d().z;
 
149
                minMax[5] = atoms[0].getPoint3d().z;
 
150
                for (int i = 0; i < atoms.length; i++) {
 
151
                        if (atoms[i].getPoint3d().x > minMax[1]) {
 
152
                                minMax[1] = atoms[i].getPoint3d().x;
 
153
                        } else if (atoms[i].getPoint3d().y > minMax[3]) {
 
154
                                minMax[3] = atoms[i].getPoint3d().y;
 
155
                        } else if (atoms[i].getPoint3d().z > minMax[5]) {
 
156
                                minMax[5] = atoms[i].getPoint3d().z;
 
157
                        } else if (atoms[i].getPoint3d().x < minMax[0]) {
 
158
                                minMax[0] = atoms[i].getPoint3d().x;
 
159
                        } else if (atoms[i].getPoint3d().y < minMax[2]) {
 
160
                                minMax[2] = atoms[i].getPoint3d().y;
 
161
                        } else if (atoms[i].getPoint3d().z < minMax[4]) {
 
162
                                minMax[4] = atoms[i].getPoint3d().z;
 
163
                        }
 
164
                }
 
165
                return minMax;
 
166
        }
 
167
 
 
168
 
 
169
        /**
 
170
         * Method creates a cubic grid with the grid generator class.
 
171
         */
 
172
        public void createCubicGrid() {
 
173
//              logger.debug("  CREATE CUBIC GRID");
 
174
                gridGenerator.setDimension(findGridBoundaries(), true);
 
175
                gridGenerator.generateGrid();
 
176
                this.grid = gridGenerator.getGrid();
 
177
        }
 
178
 
 
179
        /**
 
180
         * Method assigns the atoms of a biopolymer to the grid. For every atom
 
181
         * the corresponding grid point is identified and set to the value
 
182
         * of the proteinInterior variable.
 
183
         * The atom radius and solvent radius is accounted for with the variables:
 
184
         * double rAtom, and dpuble rSolvent.
 
185
         *
 
186
         * @throws Exception
 
187
         */
 
188
        public void assignProteinToGrid() throws Exception {
 
189
//              logger.debug.print("    ASSIGN PROTEIN TO GRID");
 
190
                // 1. Step: Set all grid points to solvent accessible
 
191
                this.grid = gridGenerator.initializeGrid(this.grid, 0);
 
192
                // 2. Step Grid points inaccessible to solvent are assigend a value of -1
 
193
                // set grid points around (r_atom+r_solv) to -1
 
194
                IAtom[] atoms = AtomContainerManipulator.getAtomArray(protein);
 
195
                Point3d gridPoint = null;
 
196
                int checkGridPoints = 0;
 
197
                double vdWRadius = 0;
 
198
                int[] dim = gridGenerator.getDim();
 
199
                //int proteinAtomCount = 0;//Debugging
 
200
                int[] minMax = { 0, 0, 0, 0, 0, 0 };
 
201
 
 
202
                for (int i = 0; i < atoms.length; i++) {
 
203
                        if (((PDBAtom) atoms[i]).getHetAtom()) {
 
204
                                continue;
 
205
                        }
 
206
                        gridPoint = gridGenerator.getGridPointFrom3dCoordinates(atoms[i]
 
207
                                        .getPoint3d());
 
208
                        this.grid[(int) gridPoint.x][(int) gridPoint.y][(int) gridPoint.z] = -1;
 
209
                        vdWRadius = atoms[i].getVanderwaalsRadius();
 
210
                        if (vdWRadius == 0) {
 
211
                                vdWRadius = rAtom;
 
212
                        }
 
213
                        checkGridPoints = (int) (((vdWRadius + rSolvent) / gridGenerator
 
214
                                        .getLatticeConstant()) - atomCheckRadius);
 
215
                        if (checkGridPoints < 0) {
 
216
                                checkGridPoints = 0;
 
217
                        }
 
218
                        minMax[0] = (int) gridPoint.x - checkGridPoints;
 
219
                        minMax[1] = (int) gridPoint.x + checkGridPoints;
 
220
                        minMax[2] = (int) gridPoint.y - checkGridPoints;
 
221
                        minMax[3] = (int) gridPoint.y + checkGridPoints;
 
222
                        minMax[4] = (int) gridPoint.z - checkGridPoints;
 
223
                        minMax[5] = (int) gridPoint.z + checkGridPoints;
 
224
                        minMax = checkBoundaries(minMax, dim);
 
225
                        for (int x = minMax[0]; x <= minMax[1]; x++) {
 
226
                                for (int y = minMax[2]; y <= minMax[3]; y++) {
 
227
                                        for (int z = minMax[4]; z <= minMax[5]; z++) {
 
228
                                                this.grid[x][y][z] = this.grid[x][y][z] - 1;
 
229
                                                //proteinAtomCount++;//Debugging
 
230
                                        }
 
231
                                }
 
232
 
 
233
                        }
 
234
                }// for atoms.length
 
235
 
 
236
//              logger.debug("- checkGridPoints>" + checkGridPoints
 
237
//                              + " ProteinGridPoints>" + proteinAtomCount);
 
238
        }
 
239
 
 
240
        public void debuggCheckPSPEvent() {
 
241
                logger.debug("  debugg_checkPSPEvent");
 
242
                int[] dim = gridGenerator.getDim();
 
243
                // int pspMin=0;
 
244
                int[] pspEvents = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
245
                int proteinGrid = 0;
 
246
                for (int x = 0; x <= dim[0]; x++) {
 
247
                        for (int y = 0; y <= dim[1]; y++) {
 
248
                                for (int z = 0; z <= dim[2]; z++) {
 
249
 
 
250
                                        if (this.grid[x][y][z] == 0) {
 
251
                                                pspEvents[0]++;
 
252
                                        } else if (this.grid[x][y][z] == 1) {
 
253
                                                pspEvents[1]++;
 
254
                                        } else if (this.grid[x][y][z] == 2) {
 
255
                                                pspEvents[2]++;
 
256
                                        } else if (this.grid[x][y][z] == 3) {
 
257
                                                pspEvents[3]++;
 
258
                                        } else if (this.grid[x][y][z] == 4) {
 
259
                                                pspEvents[4]++;
 
260
                                        } else if (this.grid[x][y][z] == 5) {
 
261
                                                pspEvents[5]++;
 
262
                                        } else if (this.grid[x][y][z] == 6) {
 
263
                                                pspEvents[6]++;
 
264
                                        } else if (this.grid[x][y][z] == 7) {
 
265
                                                pspEvents[7]++;
 
266
                                        } else if (this.grid[x][y][z] >= 7) {
 
267
                                                pspEvents[8]++;
 
268
                                        }
 
269
 
 
270
                                        if (this.grid[x][y][z] < 0) {
 
271
                                                proteinGrid++;
 
272
                                        }
 
273
                                }
 
274
                        }
 
275
                }
 
276
                System.out.print("  minPSPocket:" + minPSPocket + " proteinGridPoints:"
 
277
                                + proteinGrid);
 
278
                int sum = 0;
 
279
                for (int i = 0; i < pspEvents.length; i++) {
 
280
                        if (i >= minPSPocket) {
 
281
                                sum = sum + pspEvents[i];
 
282
                        }
 
283
                        logger.debug(" " + i + ":" + pspEvents[i]);
 
284
                }
 
285
                logger.debug(" pspAll>" + sum);
 
286
                // logger.debug(" PSPAll:"+pspAll+" minPSP:"+minPSP+"
 
287
                // #pspMin:"+pspMin+" psp7:"+psp7+" proteinGridPoints:"+proteinGrid
 
288
                // +" solventGridPoints:"+solventGrid);
 
289
        }
 
290
 
 
291
        /**
 
292
         * Main method which calls the methods: assignProteinToGrid,
 
293
         * GridScan, and FindPockets.
 
294
         *
 
295
         */
 
296
        public void sitefinder() {
 
297
                //logger.debug("SITEFINDER");
 
298
                try {
 
299
                        assignProteinToGrid();
 
300
                } catch (Exception ex1) {
 
301
                        logger.error("Problems with assignProteinToGrid due to:"
 
302
                                        + ex1.toString());
 
303
                }
 
304
                // 3. Step scan allong x,y,z axis and the diagonals, if PSP event add +1
 
305
                // to grid cell
 
306
                int[] dim = gridGenerator.getDim();
 
307
//              logger.debug("  SITEFINDER-SCAN - dim:" + dim[0] + " grid:"
 
308
//                              + this.grid[0].length + " grid point sum:" + this.grid.length
 
309
//                              * this.grid[0].length * this.grid[0][0].length);
 
310
                axisScanX(dim[2], dim[1], dim[0]);// x-Axis
 
311
                axisScanY(dim[2], dim[0], dim[1]);// y-Axis
 
312
                axisScanZ(dim[0], dim[1], dim[2]);// z-Axis
 
313
 
 
314
                diagonalAxisScanXZY(dim[0], dim[2], dim[1]);// diagonal1-Axis
 
315
                diagonalAxisScanYZX(dim[1], dim[2], dim[0]);// diagonal2-Axis
 
316
                diagonalAxisScanYXZ(dim[1], dim[0], dim[2]);// diagonal3-Axis
 
317
                diagonalAxisScanXYZ(dim[0], dim[1], dim[2]);// diagonal4-Axis
 
318
 
 
319
                //debuggCheckPSPEvent();
 
320
 
 
321
                findPockets();
 
322
 
 
323
                sortPockets();
 
324
        }
 
325
 
 
326
        /**
 
327
         * Method sorts the pockets due to its size. The biggest pocket is the first.
 
328
         *
 
329
         */
 
330
        private void sortPockets() {
 
331
//              logger.debug("  SORT POCKETS Start#:" + pockets.size());
 
332
                Hashtable hashPockets = new Hashtable();
 
333
                Vector pocket;
 
334
                Vector sortPockets = new Vector(pockets.size());
 
335
                for (int i = 0; i < pockets.size(); i++) {
 
336
                        pocket = (Vector) pockets.get(i);
 
337
                        if (hashPockets.containsKey(new Integer(pocket.size()))) {
 
338
                                Vector tmp = (Vector) hashPockets
 
339
                                                .get(new Integer(pocket.size()));
 
340
                                tmp.add(new Integer(i));
 
341
                                hashPockets.put(new Integer(pocket.size()), tmp);
 
342
                        } else {
 
343
                                Vector value = new Vector();
 
344
                                value.add(new Integer(i));
 
345
                                hashPockets.put(new Integer(pocket.size()), value);
 
346
                        }
 
347
                }
 
348
 
 
349
                ArrayList keys = new ArrayList(hashPockets.keySet());
 
350
                Collections.sort(keys);
 
351
                for (int i = keys.size() - 1; i >= 0; i--) {
 
352
                        Vector value = (Vector) hashPockets.get(keys.get(i));
 
353
//                      logger.debug("key:" + i + " Value" + keys.get(i)
 
354
//                                      + " #Pockets:" + value.size());
 
355
                        for (int j = 0; j < value.size(); j++) {
 
356
                                sortPockets.add(pockets
 
357
                                                .get(((Integer) value.get(j)).intValue()));
 
358
                        }
 
359
                }
 
360
//              logger.debug("  SORT POCKETS End#:" + sortPockets.size());
 
361
                pockets = sortPockets;
 
362
        }
 
363
 
 
364
        /**
 
365
         * Method which finds the pocket, with a simple nearest neighbour clustering. The points
 
366
         * which should be clustered or form a pocket can be determined with:
 
367
         *      minPSPocket, minPSCluster, linkageRadius, and pocketSize.
 
368
         */
 
369
        private void findPockets() {
 
370
                int[] dim = gridGenerator.getDim();
 
371
//              logger.debug("  FIND POCKETS>dimx:" + dim[0] + " dimy:" + dim[1]
 
372
//                              + " dimz:" + dim[2] + " linkageRadius>" + linkageRadius
 
373
//                              + " latticeConstant>" + latticeConstant + " pocketSize:"
 
374
//                              + pocketSize + " minPSPocket:" + minPSPocket + " minPSCluster:"
 
375
//                              + minPSCluster);
 
376
                //int pointsVisited = 0;//Debugging
 
377
                //int significantPointsVisited = 0;//Debugging
 
378
                for (int x = 0; x < dim[0]; x++) {
 
379
                        for (int y = 0; y < dim[1]; y++) {
 
380
                                for (int z = 0; z < dim[2]; z++) {
 
381
                                        // logger.debug.print(" x:"+x+" y:"+y+" z:"+z);
 
382
                                        Point3d start = new Point3d(x, y, z);
 
383
                                        //pointsVisited++;
 
384
                                        if (this.grid[x][y][z] >= minPSPocket
 
385
                                                        & !visited.containsKey(x + "." + y + "."+ z)) {
 
386
                                                Vector subPocket = new Vector();
 
387
                                                // logger.debug.print("new Point: "+grid[x][y][z]);
 
388
                                                //significantPointsVisited++;
 
389
                                                // logger.debug("visited:"+pointsVisited);
 
390
                                                subPocket = this
 
391
                                                                .clusterPSPPocket(start, subPocket, dim);
 
392
                                                if (subPocket != null && subPocket.size() >= pocketSize) {
 
393
                                                        pockets.add((Vector) subPocket);
 
394
                                                }
 
395
                                                // logger.debug(" Points visited:"+pointsVisited+"
 
396
                                                // subPocketSize:"+subPocket.size()+"
 
397
                                                // pocketsSize:"+pockets.size()
 
398
                                                // +" hashtable:"+visited.size());
 
399
 
 
400
                                        }
 
401
                                }
 
402
                        }
 
403
 
 
404
                }
 
405
//              try {
 
406
//                      logger.debug("  ->>>> #pockets:" + pockets.size()
 
407
//                                      + " significantPointsVisited:" + significantPointsVisited
 
408
//                                      + " keys:" + visited.size() + " PointsVisited:"
 
409
//                                      + pointsVisited);
 
410
//              } catch (Exception ex1) {
 
411
//                      logger.debug
 
412
//                                      .println("Problem in System.out due to " + ex1.toString());
 
413
//              }
 
414
 
 
415
        }
 
416
 
 
417
        /**
 
418
         * Method performs the clustering, is called by findPockets().
 
419
         */
 
420
        public Vector clusterPSPPocket(Point3d root, Vector sub_Pocket, int[] dim) {
 
421
                // logger.debug(" ****** New Root ******:"+root.x+" "+root.y+"
 
422
                // "+root.z);
 
423
                visited.put((int) root.x + "." + (int) root.y + "."
 
424
                + (int) root.z, new Integer(1));
 
425
                int[] minMax = { 0, 0, 0, 0, 0, 0 };
 
426
                minMax[0] = (int) (root.x - linkageRadius);
 
427
                minMax[1] = (int) (root.x + linkageRadius);
 
428
                minMax[2] = (int) (root.y - linkageRadius);
 
429
                minMax[3] = (int) (root.y + linkageRadius);
 
430
                minMax[4] = (int) (root.z - linkageRadius);
 
431
                minMax[5] = (int) (root.z + linkageRadius);
 
432
                minMax = checkBoundaries(minMax, dim);
 
433
                // logger.debug("cluster:"+minMax[0]+" "+minMax[1]+" "+minMax[2]+"
 
434
                // "+minMax[3]+" "+minMax[4]+" "+minMax[5]+" ");
 
435
                for (int k = minMax[0]; k <= minMax[1]; k++) {
 
436
                        for (int m = minMax[2]; m <= minMax[3]; m++) {
 
437
                                for (int l = minMax[4]; l <= minMax[5]; l++) {
 
438
                                        Point3d node = new Point3d(k, m, l);
 
439
                                        // logger.debug(" clusterPSPPocket:"+root.x+"
 
440
                                        // "+root.y+" "+root.z+" ->"+k+" "+m+" "+l+"
 
441
                                        // #>"+this.grid[k][m][l]+" key:"+visited.containsKey(new
 
442
                                        // String(k+"."+m+"."+l)));
 
443
                                        if (this.grid[k][m][l] >= minPSCluster
 
444
                                                        && !visited.containsKey(k + "." + m
 
445
                            + "." + l)) {
 
446
                                                // logger.debug(" ---->FOUND");
 
447
                                                sub_Pocket.add(node);
 
448
                                                this.clusterPSPPocket(node, sub_Pocket, dim);
 
449
                                        }
 
450
                                }
 
451
                        }
 
452
                }
 
453
                sub_Pocket.add(root);
 
454
                return sub_Pocket;
 
455
        }
 
456
 
 
457
        /**
 
458
         * Method checks boundaries.
 
459
         *
 
460
         * @param minMax with minMax values
 
461
         * @param dim    dimension
 
462
         * @return new minMax values between 0 and dim  
 
463
         */
 
464
        private int[] checkBoundaries(int[] minMax, int[] dim) {
 
465
                if (minMax[0] < 0) {
 
466
                        minMax[0] = 0;
 
467
                }
 
468
                if (minMax[1] > dim[0]) {
 
469
                        minMax[1] = dim[0];
 
470
                }
 
471
                if (minMax[2] < 0) {
 
472
                        minMax[2] = 0;
 
473
                }
 
474
                if (minMax[3] > dim[1]) {
 
475
                        minMax[3] = dim[1];
 
476
                }
 
477
                if (minMax[4] < 0) {
 
478
                        minMax[4] = 0;
 
479
                }
 
480
                if (minMax[5] > dim[2]) {
 
481
                        minMax[5] = dim[2];
 
482
                }
 
483
                return minMax;
 
484
        }
 
485
 
 
486
        /**
 
487
         * Method which assigns upon a PSP event +1 to these grid points.
 
488
         */
 
489
        private void firePSPEvent(Vector line) {
 
490
                for (int i = 0; i < line.size(); i++) {
 
491
                        this.grid[(int) ((Point3d) line.get(i)).x][(int) ((Point3d) line
 
492
                                        .get(i)).y][(int) ((Point3d) line.get(i)).z] = this.grid[(int) ((Point3d) line
 
493
                                        .get(i)).x][(int) ((Point3d) line.get(i)).y][(int) ((Point3d) line
 
494
                                        .get(i)).z] + 1;
 
495
                }
 
496
 
 
497
        }
 
498
 
 
499
        /**
 
500
         * Method performs a scan; works only for cubic grids!
 
501
         *
 
502
         * @param dimK first dimension 
 
503
         * @param dimL second dimension 
 
504
         * @param dimM third dimension
 
505
         */
 
506
        public void diagonalAxisScanXZY(int dimK, int dimL, int dimM) {
 
507
                // x min ->x max;left upper corner z+y max->min//1
 
508
                //logger.debug("        diagonalAxisScanXZY");
 
509
                if (dimM < dimL) {
 
510
                        dimL = dimM;
 
511
                }
 
512
                //int gridPoints = 0;//Debugging
 
513
                Vector line = new Vector();
 
514
                int pspEvent = 0;
 
515
                int m = 0;
 
516
                for (int j = dimM; j >= 1; j--) {// z
 
517
                        line.removeAllElements();
 
518
                        pspEvent = 0;
 
519
                        for (int k = 0; k <= dimK; k++) {// min -> max; x
 
520
                                m = dimM;// m==y
 
521
                                line.removeAllElements();
 
522
                                pspEvent = 0;
 
523
                                for (int l = dimL; l >= 0; l--) {// z
 
524
                                        //gridPoints++;
 
525
                                        if (grid[k][m][l] < 0) {
 
526
                                                if (pspEvent < 2) {
 
527
                                                        line.removeAllElements();
 
528
                                                        pspEvent = 1;
 
529
                                                } else if (pspEvent == 2) {
 
530
                                                        firePSPEvent(line);
 
531
                                                        line.removeAllElements();
 
532
                                                        pspEvent = 1;
 
533
                                                }
 
534
                                        } else {
 
535
                                                if (pspEvent == 1 | pspEvent == 2) {
 
536
                                                        line.add(new Point3d(k, m, l));
 
537
                                                        pspEvent = 2;
 
538
                                                }
 
539
                                        }
 
540
                                        m--;
 
541
                                }// for l
 
542
                        }
 
543
                        dimL = j;
 
544
                }
 
545
                //logger.debug(" #gridPoints>" + gridPoints);
 
546
        }
 
547
 
 
548
        /**
 
549
         * Method performs a scan; works only for cubic grids!
 
550
         *
 
551
         * @param dimK first dimension 
 
552
         * @param dimL second dimension 
 
553
         * @param dimM third dimension
 
554
         */
 
555
        public void diagonalAxisScanYZX(int dimK, int dimL, int dimM) {
 
556
                // y min -> y max; right lower corner zmax->zmin, xmax ->min//4
 
557
                // logger.debug.print(" diagonalAxisScanYZX");
 
558
                //int gridPoints = 0;//Debugging
 
559
                if (dimM < dimL) {
 
560
                        dimL = dimM;
 
561
                }
 
562
                Vector line = new Vector();
 
563
                int pspEvent = 0;
 
564
                int m = 0;
 
565
                for (int j = dimM; j >= 1; j--) {// z
 
566
                        line.removeAllElements();
 
567
                        pspEvent = 0;
 
568
                        for (int k = 0; k <= dimK; k++) {// min -> max; y
 
569
                                m = dimM;// m==x
 
570
                                line.removeAllElements();
 
571
                                pspEvent = 0;
 
572
                                for (int l = dimL; l >= 0; l--) {// z
 
573
                                        //gridPoints++;
 
574
                                        if (grid[m][k][l] < 0) {
 
575
                                                if (pspEvent < 2) {
 
576
                                                        line.removeAllElements();
 
577
                                                        pspEvent = 1;
 
578
                                                } else if (pspEvent == 2) {
 
579
                                                        firePSPEvent(line);
 
580
                                                        line.removeAllElements();
 
581
                                                        pspEvent = 1;
 
582
                                                }
 
583
                                        } else {
 
584
                                                if (pspEvent == 1 | pspEvent == 2) {
 
585
                                                        line.add(new Point3d(m, k, l));
 
586
                                                        pspEvent = 2;
 
587
                                                }
 
588
                                        }
 
589
                                        m--;
 
590
                                }// for l
 
591
                        }
 
592
                        dimL = j;
 
593
                }
 
594
                // logger.debug(" #gridPoints>"+gridPoints);
 
595
        }
 
596
 
 
597
        /**
 
598
         * Method performs a scan; works only for cubic grids!
 
599
         *
 
600
         * @param dimK first dimension 
 
601
         * @param dimL second dimension 
 
602
         * @param dimM third dimension
 
603
         */
 
604
        public void diagonalAxisScanYXZ(int dimK, int dimL, int dimM) {
 
605
                // y min -> y max; left lower corner z max->min, x min->max//2
 
606
                // logger.debug.print(" diagonalAxisScanYXZ");
 
607
                //int gridPoints = 0;//Debugging
 
608
                if (dimM < dimL) {
 
609
                        dimL = dimM;
 
610
                } else {
 
611
                        dimM = dimL;
 
612
                }
 
613
                Vector line = new Vector();
 
614
                int pspEvent = 0;
 
615
                int l = 0;
 
616
                for (int j = dimL; j >= 1; j--) {// z
 
617
                        line.removeAllElements();
 
618
                        pspEvent = 0;
 
619
                        for (int k = 0; k <= dimK; k++) {// min -> max; y
 
620
                                line.removeAllElements();
 
621
                                pspEvent = 0;
 
622
                                l = 0;// x
 
623
                                for (int m = dimM; m >= 0; m--) {// z
 
624
                                        //gridPoints++;
 
625
                                        if (grid[l][k][m] < 0) {
 
626
                                                if (pspEvent < 2) {
 
627
                                                        line.removeAllElements();
 
628
                                                        pspEvent = 1;
 
629
                                                } else if (pspEvent == 2) {
 
630
                                                        firePSPEvent(line);
 
631
                                                        line.removeAllElements();
 
632
                                                        pspEvent = 1;
 
633
                                                }
 
634
                                        } else {
 
635
                                                if (pspEvent == 1 | pspEvent == 2) {
 
636
                                                        line.add(new Point3d(l, k, m));
 
637
                                                        pspEvent = 2;
 
638
                                                }
 
639
                                        }
 
640
                                        l++;
 
641
                                }// for m;z
 
642
                        }// for k;y
 
643
                        dimM = j;
 
644
                }
 
645
                // logger.debug(" #gridPoints>"+gridPoints);
 
646
        }
 
647
 
 
648
        /**
 
649
         * Method performs a scan; works only for cubic grids!
 
650
         *
 
651
         * @param dimK first dimension
 
652
         * @param dimL second dimension
 
653
         * @param dimM third dimension
 
654
         */
 
655
        public void diagonalAxisScanXYZ(int dimK, int dimL, int dimM) {
 
656
                // x min -> xmax;left lower corner z max->min, y min->max//3
 
657
                // logger.debug.print(" diagonalAxisScanXYZ");
 
658
                //int gridPoints = 0;//Debugging
 
659
                if (dimM < dimL) {
 
660
                        dimL = dimM;
 
661
                } else {
 
662
                        dimM = dimL;
 
663
                }
 
664
                Vector line = new Vector();
 
665
                int pspEvent = 0;
 
666
                int l = 0;
 
667
                for (int j = dimL; j >= 1; j--) {// z
 
668
                        line.removeAllElements();
 
669
                        pspEvent = 0;
 
670
                        for (int k = 0; k <= dimK; k++) {// min -> max;x
 
671
                                line.removeAllElements();
 
672
                                pspEvent = 0;
 
673
                                l = 0;// y
 
674
                                for (int m = dimM; m >= 0; m--) {// z
 
675
                                        //gridPoints++;
 
676
                                        if (grid[k][l][m] < 0) {
 
677
                                                if (pspEvent < 2) {
 
678
                                                        line.removeAllElements();
 
679
                                                        pspEvent = 1;
 
680
                                                } else if (pspEvent == 2) {
 
681
                                                        firePSPEvent(line);
 
682
                                                        line.removeAllElements();
 
683
                                                        pspEvent = 1;
 
684
                                                }
 
685
                                        } else {
 
686
                                                if (pspEvent == 1 | pspEvent == 2) {
 
687
                                                        line.add(new Point3d(k, l, m));
 
688
                                                        pspEvent = 2;
 
689
                                                }
 
690
                                        }
 
691
                                        l++;
 
692
                                }// for m;z
 
693
                        }// for k;x
 
694
                        dimM = j;
 
695
                }
 
696
                // logger.debug(" #gridPoints>"+gridPoints);
 
697
        }
 
698
 
 
699
        /**
 
700
         * Method performs a scan; works only for cubic grids!
 
701
         *
 
702
         * @param dimK first dimension
 
703
         * @param dimL second dimension
 
704
         * @param dimM third dimension
 
705
         */
 
706
        public void axisScanX(int dimK, int dimL, int dimM) {
 
707
                // z,y,x
 
708
//              logger.debug.print("    diagonalAxisScanX");
 
709
                //int gridPoints = 0;//Debugging
 
710
                Vector line = new Vector();
 
711
                int pspEvent = 0;
 
712
                for (int k = 0; k <= dimK; k++) {
 
713
                        line.removeAllElements();
 
714
                        pspEvent = 0;
 
715
                        for (int l = 0; l <= dimL; l++) {
 
716
                                line.removeAllElements();
 
717
                                pspEvent = 0;
 
718
                                for (int m = 0; m <= dimM; m++) {
 
719
                                        //gridPoints++;
 
720
                                        if (grid[m][l][k] < 0) {
 
721
                                                if (pspEvent < 2) {
 
722
                                                        pspEvent = 1;
 
723
                                                        line.removeAllElements();
 
724
                                                } else if (pspEvent == 2) {
 
725
                                                        firePSPEvent(line);
 
726
                                                        line.removeAllElements();
 
727
                                                        pspEvent = 1;
 
728
                                                }
 
729
                                        } else {
 
730
                                                if (pspEvent == 1 | pspEvent == 2) {
 
731
                                                        line.add(new Point3d(m, l, k));
 
732
                                                        pspEvent = 2;
 
733
                                                }
 
734
                                        }
 
735
                                }
 
736
                        }
 
737
                }
 
738
//              logger.debug(" #gridPoints>" + gridPoints);
 
739
        }
 
740
 
 
741
        /**
 
742
         * Method performs a scan; works only for cubic grids!
 
743
         *
 
744
         * @param dimK first dimension
 
745
         * @param dimL second dimension
 
746
         * @param dimM third dimension
 
747
         */
 
748
        public void axisScanY(int dimK, int dimL, int dimM) {
 
749
                // z,x,y
 
750
                Vector line = new Vector();
 
751
                int pspEvent = 0;
 
752
                for (int k = 0; k <= dimK; k++) {
 
753
                        line.removeAllElements();
 
754
                        pspEvent = 0;
 
755
                        for (int l = 0; l <= dimL; l++) {
 
756
                                line.removeAllElements();
 
757
                                pspEvent = 0;
 
758
                                for (int m = 0; m <= dimM; m++) {
 
759
                                        if (grid[l][m][k] < 0) {
 
760
                                                if (pspEvent < 2) {
 
761
                                                        pspEvent = 1;
 
762
                                                        line.removeAllElements();
 
763
                                                } else if (pspEvent == 2) {
 
764
                                                        // if (line.size()>2){
 
765
                                                        firePSPEvent(line);
 
766
                                                        // }
 
767
                                                        line.removeAllElements();
 
768
                                                        pspEvent = 1;
 
769
                                                }
 
770
                                        } else {
 
771
                                                if (pspEvent > 0) {
 
772
                                                        line.add(new Point3d(l, m, k));
 
773
                                                        pspEvent = 2;
 
774
                                                }
 
775
                                        }
 
776
                                }
 
777
                        }
 
778
                }
 
779
        }
 
780
 
 
781
        /**
 
782
         * Method performs a scan; works only for cubic grids!
 
783
         *
 
784
         * @param dimK first dimension
 
785
         * @param dimL second dimension
 
786
         * @param dimM third dimension
 
787
         */
 
788
        public void axisScanZ(int dimK, int dimL, int dimM) {
 
789
                // x,y,z
 
790
                Vector line = new Vector();
 
791
                int pspEvent = 0;
 
792
                for (int k = 0; k <= dimK; k++) {
 
793
                        line.removeAllElements();
 
794
                        pspEvent = 0;
 
795
                        for (int l = 0; l <= dimL; l++) {
 
796
                                line.removeAllElements();
 
797
                                pspEvent = 0;
 
798
                                for (int m = 0; m <= dimM; m++) {
 
799
                                        if (grid[k][l][m] < 0) {
 
800
                                                if (pspEvent < 2) {
 
801
                                                        pspEvent = 1;
 
802
                                                        line.removeAllElements();
 
803
                                                } else if (pspEvent == 2) {
 
804
                                                        firePSPEvent(line);
 
805
                                                        line.removeAllElements();
 
806
                                                        pspEvent = 1;
 
807
                                                }
 
808
                                        } else {
 
809
                                                if (pspEvent > 0) {
 
810
                                                        line.add(new Point3d(k, l, m));
 
811
                                                        pspEvent = 2;
 
812
                                                }
 
813
                                        }
 
814
                                }
 
815
                        }
 
816
                }
 
817
        }
 
818
 
 
819
 
 
820
        /**
 
821
         * Method which assigns van der Waals radii to the biopolymer
 
822
         * default org/openscience/cdk/config/data/pdb_atomtypes.xml
 
823
         * stored in the variable String vanDerWaalsFile.
 
824
         */
 
825
        public void assignVdWRadiiToProtein() {
 
826
                AtomTypeFactory atf = null;
 
827
                IAtom[] atoms = AtomContainerManipulator.getAtomArray(protein);
 
828
                try {
 
829
                        atf = AtomTypeFactory.getInstance(
 
830
                vanDerWaalsFile, atoms[0].getBuilder()
 
831
            );
 
832
                } catch (Exception ex1) {
 
833
                        System.out.println("Problem with AtomTypeFactory due to:"
 
834
                                        + ex1.toString());
 
835
                }
 
836
                for (int i = 0; i < atoms.length; i++) {
 
837
                        try {
 
838
                                atf.configure(atoms[i]);
 
839
                        } catch (Exception ex2) {
 
840
                                logger.error("Problem with atf.configure due to:"
 
841
                                                + ex2.toString());
 
842
                        }
 
843
                }
 
844
 
 
845
        }
 
846
 
 
847
        /**
 
848
         * Method writes the grid to pmesh format.
 
849
         */
 
850
        public void gridToPmesh(String outPutFileName) {
 
851
                try {
 
852
                        gridGenerator.writeGridInPmeshFormat(outPutFileName);
 
853
                } catch (IOException e) {
 
854
                        logger.debug(e);
 
855
                }
 
856
        }
 
857
 
 
858
        /**
 
859
         * Method writes the PSP points (>=minPSPocket) to pmesh format.
 
860
         */
 
861
        public void pspGridToPmesh(String outPutFileName) {
 
862
                try {
 
863
                        gridGenerator.writeGridInPmeshFormat(outPutFileName, minPSPocket);
 
864
                } catch (IOException e) {
 
865
                        logger.debug(e);
 
866
                }
 
867
        }
 
868
 
 
869
        /**
 
870
         * Method writes the protein grid points to pmesh format.
 
871
         */
 
872
        public void proteinGridToPmesh(String outPutFileName) {
 
873
                try {
 
874
                        gridGenerator.writeGridInPmeshFormat(outPutFileName, -1);
 
875
                } catch (IOException e) {
 
876
                        logger.debug(e);
 
877
                }
 
878
        }
 
879
 
 
880
        /**
 
881
         * Method writes the pockets to pmesh format.
 
882
         */
 
883
        public void writePocketsToPMesh(String outPutFileName) {
 
884
 
 
885
                try {
 
886
                        for (int i = 0; i < pockets.size(); i++) {// go through every
 
887
                                // pocket
 
888
                                BufferedWriter writer = new BufferedWriter(new FileWriter(
 
889
                                                outPutFileName + "-" + i + ".pmesh"));
 
890
                                Vector pocket = (Vector) pockets.get(i);
 
891
                                writer.write(pocket.size() + "\n");
 
892
                                for (int j = 0; j < pocket.size(); j++) {// go through every
 
893
                                        // grid point of the
 
894
                                        // actual pocket
 
895
                                        Point3d actualGridPoint = (Point3d) pocket.get(j);
 
896
                                        Point3d coords = gridGenerator
 
897
                                                        .getCoordinatesFromGridPoint(actualGridPoint);
 
898
                                        writer.write(coords.x + "\t" + coords.y + "\t" + coords.z
 
899
                                                        + "\n");
 
900
                                }
 
901
                                writer.close();
 
902
                        }
 
903
                } catch (IOException e) {
 
904
                        logger.debug(e);
 
905
                }
 
906
        }
 
907
 
 
908
 
 
909
        /**
 
910
         * @return      Returns the grid.
 
911
         */
 
912
        public double[][][] getGrid() {
 
913
                return grid;
 
914
        }
 
915
 
 
916
 
 
917
        /**
 
918
         * @param  grid The grid to set.
 
919
         */
 
920
        public void setGrid(double[][][] grid) {
 
921
                this.grid = grid;
 
922
        }
 
923
 
 
924
 
 
925
        /**
 
926
         * @return Returns the latticeConstant.
 
927
         */
 
928
        public double getLatticeConstant() {
 
929
                return latticeConstant;
 
930
        }
 
931
 
 
932
 
 
933
        /**
 
934
         * @param latticeConstant The latticeConstant to set.
 
935
         */
 
936
        public void setLatticeConstant(double latticeConstant) {
 
937
                this.latticeConstant = latticeConstant;
 
938
        }
 
939
 
 
940
 
 
941
        /**
 
942
         * @return Returns the linkageRadius.
 
943
         */
 
944
        public double getLinkageRadius() {
 
945
                return linkageRadius;
 
946
        }
 
947
 
 
948
 
 
949
        /**
 
950
         * @param linkageRadius The linkageRadius to set.
 
951
         */
 
952
        public void setLinkageRadius(double linkageRadius) {
 
953
                this.linkageRadius = linkageRadius;
 
954
        }
 
955
 
 
956
 
 
957
        /**
 
958
         * @return Returns the minPSCluster.
 
959
         */
 
960
        public int getMinPSCluster() {
 
961
                return minPSCluster;
 
962
        }
 
963
 
 
964
 
 
965
        /**
 
966
         * @param  minPSCluster The minPSCluster to set.
 
967
         */
 
968
        public void setMinPSCluster(int minPSCluster) {
 
969
                this.minPSCluster = minPSCluster;
 
970
        }
 
971
 
 
972
 
 
973
        /**
 
974
         * @return Returns the minPSPocket.
 
975
         */
 
976
        public int getMinPSPocket() {
 
977
                return minPSPocket;
 
978
        }
 
979
 
 
980
 
 
981
        /**
 
982
         * @param minPSPocket The minPSPocket to set.
 
983
         */
 
984
        public void setMinPSPocket(int minPSPocket) {
 
985
                this.minPSPocket = minPSPocket;
 
986
        }
 
987
 
 
988
 
 
989
        /**
 
990
         * @return Returns the pocketSize.
 
991
         */
 
992
        public int getPocketSize() {
 
993
                return pocketSize;
 
994
        }
 
995
 
 
996
 
 
997
        /**
 
998
         * @param pocketSize The pocketSize to set.
 
999
         */
 
1000
        public void setPocketSize(int pocketSize) {
 
1001
                this.pocketSize = pocketSize;
 
1002
        }
 
1003
 
 
1004
 
 
1005
        /**
 
1006
         * @return Returns the protein.
 
1007
         */
 
1008
        public IBioPolymer getProtein() {
 
1009
                return protein;
 
1010
        }
 
1011
 
 
1012
 
 
1013
        /**
 
1014
         * @param protein The protein to set.
 
1015
         */
 
1016
        public void setProtein(IBioPolymer protein) {
 
1017
                this.protein = protein;
 
1018
        }
 
1019
 
 
1020
 
 
1021
        /**
 
1022
         * @return Returns the proteinInterior.
 
1023
         */
 
1024
        public int getProteinInterior() {
 
1025
                return proteinInterior;
 
1026
        }
 
1027
 
 
1028
 
 
1029
        /**
 
1030
         * @param proteinInterior The proteinInterior to set.
 
1031
         */
 
1032
        public void setProteinInterior(int proteinInterior) {
 
1033
                this.proteinInterior = proteinInterior;
 
1034
        }
 
1035
 
 
1036
 
 
1037
        /**
 
1038
         * @return Returns the rAtom.
 
1039
         */
 
1040
        public double getRAtom() {
 
1041
                return rAtom;
 
1042
        }
 
1043
 
 
1044
 
 
1045
        /**
 
1046
         * @param atom The rAtom to set.
 
1047
         */
 
1048
        public void setRAtom(double atom) {
 
1049
                rAtom = atom;
 
1050
        }
 
1051
 
 
1052
 
 
1053
        /**
 
1054
         * @return Returns the rSolvent.
 
1055
         */
 
1056
        public double getRSolvent() {
 
1057
                return rSolvent;
 
1058
        }
 
1059
 
 
1060
 
 
1061
        /**
 
1062
         * @param solvent The rSolvent to set.
 
1063
         */
 
1064
        public void setRSolvent(double solvent) {
 
1065
                rSolvent = solvent;
 
1066
        }
 
1067
 
 
1068
 
 
1069
        /**
 
1070
         * @return Returns the solvantValue.
 
1071
         */
 
1072
        public int getSolvantValue() {
 
1073
                return solvantValue;
 
1074
        }
 
1075
 
 
1076
 
 
1077
        /**
 
1078
         * @param solvantValue The solvantValue to set.
 
1079
         */
 
1080
        public void setSolvantValue(int solvantValue) {
 
1081
                this.solvantValue = solvantValue;
 
1082
        }
 
1083
 
 
1084
 
 
1085
        /**
 
1086
         * @return Returns the vanDerWaalsFile.
 
1087
         */
 
1088
        public String getVanDerWaalsFile() {
 
1089
                return vanDerWaalsFile;
 
1090
        }
 
1091
 
 
1092
 
 
1093
        /**
 
1094
         * @param vanDerWaalsFile The vanDerWaalsFile to set.
 
1095
         */
 
1096
        public void setVanDerWaalsFile(String vanDerWaalsFile) {
 
1097
                this.vanDerWaalsFile = vanDerWaalsFile;
 
1098
        }
 
1099
 
 
1100
 
 
1101
        /**
 
1102
         * @return      Returns the pockets.
 
1103
         */
 
1104
        public Vector getPockets() {
 
1105
                return pockets;
 
1106
        }
 
1107
 
 
1108
 
 
1109
        /**
 
1110
         * @param atomCheckRadius The atomCheckRadius to set.
 
1111
         */
 
1112
        public void setAtomCheckRadius(double atomCheckRadius) {
 
1113
                this.atomCheckRadius = atomCheckRadius;
 
1114
        }
 
1115
 
 
1116
}