Skip to content

Commit 0bdf25a

Browse files
committed
Handling 0 atoms case in InterfaceFinder
1 parent ed3061c commit 0bdf25a

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/contact/BoundingBox.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ public BoundingBox(BoundingBox bb) {
7171

7272
/**
7373
* Constructs a BoundingBox by calculating maxs and mins of given array of atoms.
74-
* @param atoms
74+
* @param atoms the atom array
75+
* @throws IllegalArgumentException if atom array is empty
7576
*/
7677
public BoundingBox (Point3d[] atoms) {
7778

78-
if (atoms.length==0) logger.error("Error! Empty list of atoms");
79+
if (atoms.length==0)
80+
throw new IllegalArgumentException("Empty list of atoms is not allowed for BoundingBox construction");
7981

8082
xmax = atoms[0].x;
8183
xmin = xmax;
@@ -97,30 +99,15 @@ public BoundingBox (Point3d[] atoms) {
9799

98100
}
99101

100-
101-
/** Returns the dimensions of this bounding box.
102-
*
103-
* @return a double array (x,y,z) with the dimensions of the box.
104-
*/
105-
public double[] getDimensions(){
106-
107-
double[] dim = new double[3];
108-
109-
dim[0] = xmax-xmin;
110-
dim[1] = ymax-ymin;
111-
dim[2] = zmax-zmin;
112-
113-
return dim;
114-
115-
}
116-
117102
/**
118103
* Given a set of bounding boxes returns a bounding box that bounds all of them.
119-
* @param boxes
104+
* @param boxes an array of bounding boxes
105+
* @throws IllegalArgumentException if input array is empty
120106
*/
121107
public BoundingBox(BoundingBox[] boxes) {
122108

123-
if (boxes.length==0) logger.error("Error! Empty list of bounding boxes");
109+
if (boxes.length==0)
110+
throw new IllegalArgumentException("Empty list of bounding boxes is not allowed for BoundingBox construction");
124111

125112
xmax = boxes[0].xmax;
126113
xmin = boxes[0].xmin;
@@ -140,7 +127,7 @@ public BoundingBox(BoundingBox[] boxes) {
140127

141128
}
142129

143-
private class Bound implements Comparable<Bound> {
130+
private static class Bound implements Comparable<Bound> {
144131
int cardinal;
145132
double value;
146133
public Bound(int cardinal,double value) {
@@ -157,6 +144,19 @@ public String toString() {
157144
}
158145
}
159146

147+
/**
148+
* Returns the dimensions of this bounding box.
149+
*
150+
* @return a double array (x,y,z) with the dimensions of the box.
151+
*/
152+
public double[] getDimensions(){
153+
double[] dim = new double[3];
154+
dim[0] = xmax-xmin;
155+
dim[1] = ymax-ymin;
156+
dim[2] = zmax-zmin;
157+
return dim;
158+
}
159+
160160
/**
161161
* Returns true if this bounding box overlaps given one, i.e. they are within
162162
* one cutoff distance in one of their 3 dimensions.

biojava-structure/src/main/java/org/biojava/nbio/structure/contact/InterfaceFinder.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.biojava.nbio.structure.contact;
22

3-
import org.biojava.nbio.structure.Atom;
4-
import org.biojava.nbio.structure.Calc;
5-
import org.biojava.nbio.structure.Chain;
6-
import org.biojava.nbio.structure.Structure;
7-
import org.biojava.nbio.structure.StructureTools;
3+
import org.biojava.nbio.structure.*;
84
import org.biojava.nbio.structure.xtal.CrystalTransform;
95
import org.biojava.nbio.structure.xtal.SpaceGroup;
106

117
import javax.vecmath.Point3d;
8+
import java.util.ArrayList;
9+
import java.util.Iterator;
1210
import java.util.List;
1311

1412
/**
@@ -23,16 +21,31 @@ public class InterfaceFinder {
2321
private static final CrystalTransform IDENTITY_TRANSFORM = new CrystalTransform((SpaceGroup) null);
2422
private static final boolean INCLUDE_HETATOMS = true;
2523

26-
private Structure structure;
24+
private List<Chain> polyChains;
2725
private double cutoff;
2826

2927
private BoundingBox[] boundingBoxes;
3028

3129
public InterfaceFinder(Structure structure) {
32-
this.structure = structure;
30+
this.polyChains = new ArrayList<>(structure.getPolyChains());
31+
trimPolyChains();
3332
this.cutoff = DEFAULT_CONTACT_CUTOFF;
3433
}
3534

35+
/**
36+
* Remove polymer chains with 0 atoms.
37+
*/
38+
private void trimPolyChains() {
39+
Iterator<Chain> it = polyChains.iterator();
40+
while (it.hasNext()) {
41+
int count = 0;
42+
for (Group g:it.next().getAtomGroups())
43+
count += g.getAtoms().size();
44+
if (count==0)
45+
it.remove();
46+
}
47+
}
48+
3649
/**
3750
* Set the contact distance cutoff.
3851
* @param cutoff the distance value in Angstroms
@@ -52,7 +65,6 @@ public StructureInterfaceList getAllInterfaces() {
5265

5366
StructureInterfaceList list = new StructureInterfaceList();
5467

55-
List<Chain> polyChains = structure.getPolyChains();
5668
for (int i = 0; i<polyChains.size(); i++) {
5769
for (int j = i + 1; j<polyChains.size(); j++) {
5870
if (! boundingBoxes[i].overlaps(boundingBoxes[j], cutoff)) {
@@ -68,7 +80,6 @@ public StructureInterfaceList getAllInterfaces() {
6880
}
6981

7082
private void initBoundingBoxes() {
71-
List<Chain> polyChains = structure.getPolyChains();
7283
boundingBoxes = new BoundingBox[polyChains.size()];
7384
for (int i = 0; i<polyChains.size(); i++) {
7485
Atom[] atoms = StructureTools.getAllNonHAtomArray(polyChains.get(i), INCLUDE_HETATOMS);

0 commit comments

Comments
 (0)