Skip to content

Commit 20ec51e

Browse files
committed
Solving a compilation problem, making Grid usable for Point3d #545
1 parent 90b55c3 commit 20ec51e

4 files changed

Lines changed: 148 additions & 10 deletions

File tree

‎biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public boolean isPureNonPolymer() {
759759
@Override
760760
public GroupType getPredominantGroupType(){
761761

762-
double RATIO_RESIDUES_TO_TOTAL = StructureTools.RATIO_RESIDUES_TO_TOTAL;
762+
double ratioResiduesToTotal = StructureTools.RATIO_RESIDUES_TO_TOTAL;
763763

764764
int sizeAminos = getAtomGroups(GroupType.AMINOACID).size();
765765
int sizeNucleotides = getAtomGroups(GroupType.NUCLEOTIDE).size();
@@ -774,13 +774,13 @@ public GroupType getPredominantGroupType(){
774774

775775
int fullSize = sizeAminos + sizeNucleotides + sizeHetatomsWithoutWater;
776776

777-
if ((double) sizeAminos / (double) fullSize > StructureTools.RATIO_RESIDUES_TO_TOTAL)
777+
if ((double) sizeAminos / (double) fullSize > ratioResiduesToTotal)
778778
return GroupType.AMINOACID;
779779

780-
if ((double) sizeNucleotides / (double) fullSize > RATIO_RESIDUES_TO_TOTAL)
780+
if ((double) sizeNucleotides / (double) fullSize > ratioResiduesToTotal)
781781
return GroupType.NUCLEOTIDE;
782782

783-
if ((double) (sizeHetatomsWithoutWater) / (double) fullSize > RATIO_RESIDUES_TO_TOTAL)
783+
if ((double) (sizeHetatomsWithoutWater) / (double) fullSize > ratioResiduesToTotal)
784784
return GroupType.HETATM;
785785

786786
// finally if neither condition works, we try based on majority, but log
@@ -803,7 +803,7 @@ public GroupType getPredominantGroupType(){
803803
"Ratio of residues to total for chain with asym_id {} is below {}. Assuming it is a {} chain. "
804804
+ "Counts: # aa residues: {}, # nuc residues: {}, # non-water het residues: {}, # waters: {}, "
805805
+ "ratio aa/total: {}, ratio nuc/total: {}",
806-
getId(), RATIO_RESIDUES_TO_TOTAL, max, sizeAminos,
806+
getId(), ratioResiduesToTotal, max, sizeAminos,
807807
sizeNucleotides, sizeHetatomsWithoutWater, sizeWaters,
808808
(double) sizeAminos / (double) fullSize,
809809
(double) sizeNucleotides / (double) fullSize);

‎biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Set;
3737

3838
import javax.vecmath.Matrix4d;
39+
import javax.vecmath.Point3d;
3940

4041
import org.biojava.nbio.structure.align.util.AtomCache;
4142
import org.biojava.nbio.structure.contact.AtomContactSet;
@@ -497,6 +498,35 @@ public static final Atom[] getAllNonHAtomArray(Chain c, boolean hetAtoms) {
497498
}
498499
return atoms.toArray(new Atom[atoms.size()]);
499500
}
501+
502+
/**
503+
* Returns and array of all non-Hydrogen atoms coordinates in the given Chain,
504+
* optionally including HET atoms or not Waters are not included.
505+
*
506+
* @param c
507+
* @param hetAtoms
508+
* if true HET atoms are included in array, if false they are not
509+
* @return
510+
*/
511+
public static final Point3d[] getAllNonHCoordsArray(Chain c, boolean hetAtoms) {
512+
List<Point3d> atoms = new ArrayList<Point3d>();
513+
514+
for (Group g : c.getAtomGroups()) {
515+
if (g.isWater())
516+
continue;
517+
for (Atom a : g.getAtoms()) {
518+
519+
if (a.getElement() == Element.H)
520+
continue;
521+
522+
if (!hetAtoms && g.getType().equals(GroupType.HETATM))
523+
continue;
524+
525+
atoms.add(a.getCoordsAsPoint3d());
526+
}
527+
}
528+
return atoms.toArray(new Point3d[atoms.size()]);
529+
}
500530

501531
/**
502532
* Adds to the given atoms list, all atoms of groups that contained all

‎biojava-structure/src/main/java/org/biojava/nbio/structure/contact/Grid.java‎

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,25 @@
3131

3232

3333
/**
34-
* A grid to be used for calculating atom contacts through spatial hashing algorithm.
35-
*
34+
* A grid to be used for calculating atom contacts through a spatial hashing algorithm.
35+
* <p>
3636
* The grid is composed of cells of size of the cutoff so that the distances that need to be calculated
3737
* are reduced to those within each cell and to the neighbouring cells.
38+
* <p>
39+
* Usage, for generic 3D points:
40+
* <pre>
41+
* Point3d[] points = ...;
42+
* Grid grid = new Grid(8.0);
43+
* grid.addCoords(points);
44+
* List&lt;Contact&gt; contacts = getIndicesContacts();
45+
* </pre>
46+
* Usage, for atoms:
47+
* <pre>
48+
* Atom[] atoms = ...;
49+
* Grid grid = new Grid(8.0);
50+
* grid.addCoords(atoms);
51+
* AtomContactSet contacts = getAtomContacts();
52+
* </pre>
3853
*
3954
* @author Jose Duarte
4055
*
@@ -67,8 +82,9 @@ public class Grid {
6782
private boolean noOverlap; // if the 2 sets of atoms are found not to overlap then this is set to true
6883

6984
/**
70-
* Creates a <code>Grid</code>, the cutoff is in Angstroms and can
71-
* be specified to a precision of 0.01A
85+
* Creates a <code>Grid</code>, the cutoff is in the same units as the coordinates
86+
* (Angstroms if they are atom coordinates) and can
87+
* be specified to a precision of 0.01.
7288
* @param cutoff
7389
*/
7490
public Grid(double cutoff) {
@@ -170,6 +186,98 @@ public void addAtoms(Atom[] atoms, BoundingBox bounds) {
170186

171187
fillGrid();
172188
}
189+
190+
/**
191+
* Adds the i and j coordinates and fills the grid. Their bounds will be computed.
192+
* Subsequent call to {@link #getIndicesContacts()} will produce the
193+
* contacts, i.e. the set of points within distance cutoff.
194+
*
195+
* Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException
196+
* since this only adds coordinates and no atom information.
197+
* @param iAtoms
198+
* @param jAtoms
199+
*/
200+
public void addCoords(Point3d[] iAtoms, Point3d[] jAtoms) {
201+
addCoords(iAtoms, null, jAtoms, null);
202+
}
203+
204+
/**
205+
* Adds the i and j coordinates and fills the grid, passing their bounds (array of size 6 with x,y,z minima and x,y,z maxima)
206+
* This way the bounds don't need to be recomputed.
207+
* Subsequent call to {@link #getIndicesContacts()} will produce the
208+
* contacts, i.e. the set of points within distance cutoff.
209+
*
210+
* Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException
211+
* since this only adds coordinates and no atom information.
212+
* @param iAtoms
213+
* @param icoordbounds
214+
* @param jAtoms
215+
* @param jcoordbounds
216+
*/
217+
public void addCoords(Point3d[] iAtoms, BoundingBox icoordbounds, Point3d[] jAtoms, BoundingBox jcoordbounds) {
218+
this.iAtoms = iAtoms;
219+
this.iAtomObjects = null;
220+
221+
if (icoordbounds!=null) {
222+
this.ibounds = icoordbounds;
223+
} else {
224+
this.ibounds = new BoundingBox(this.iAtoms);
225+
}
226+
227+
this.jAtoms = jAtoms;
228+
this.jAtomObjects = null;
229+
230+
if (jAtoms==iAtoms) {
231+
this.jbounds=ibounds;
232+
} else {
233+
if (jcoordbounds!=null) {
234+
this.jbounds = jcoordbounds;
235+
} else {
236+
this.jbounds = new BoundingBox(this.jAtoms);
237+
238+
}
239+
}
240+
241+
fillGrid();
242+
}
243+
244+
/**
245+
* Adds a set of coordinates, subsequent call to {@link #getIndicesContacts()} will produce the
246+
* contacts, i.e. the set of points within distance cutoff.
247+
* The bounding box of the atoms will be computed based on input array.
248+
* Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException
249+
* since this only adds coordinates and no atom information.
250+
* @param atoms
251+
*/
252+
public void addCoords(Point3d[] atoms) {
253+
addCoords(atoms, (BoundingBox) null);
254+
}
255+
256+
/**
257+
* Adds a set of coordinates, subsequent call to {@link #getIndicesContacts()} will produce the
258+
* contacts, i.e. the set of points within distance cutoff.
259+
* The bounds calculated elsewhere can be passed, or if null they are computed.
260+
* Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException
261+
* since this only adds coordinates and no atom information.
262+
* @param atoms
263+
* @param bounds
264+
*/
265+
public void addCoords(Point3d[] atoms, BoundingBox bounds) {
266+
this.iAtoms = atoms;
267+
this.iAtomObjects = null;
268+
269+
if (bounds!=null) {
270+
this.ibounds = bounds;
271+
} else {
272+
this.ibounds = new BoundingBox(iAtoms);
273+
}
274+
275+
this.jAtoms = null;
276+
this.jAtomObjects = null;
277+
this.jbounds = null;
278+
279+
fillGrid();
280+
}
173281

174282
/**
175283
* Creates the grid based on the boundaries defined by all atoms given (iAtoms and jAtoms)

‎biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/UnitCellBoundingBox.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void setBb(Structure s, boolean includeHetAtoms, int i) {
7878
List<Chain> polyChains = s.getPolyChains();
7979
int j = 0;
8080
for (Chain polyChain : polyChains) {
81-
chainBbs[i][j] = new BoundingBox(StructureTools.getAllNonHAtomArray(polyChain, includeHetAtoms));
81+
chainBbs[i][j] = new BoundingBox(StructureTools.getAllNonHCoordsArray(polyChain, includeHetAtoms));
8282
j++;
8383
}
8484
auBbs[i] = new BoundingBox(chainBbs[i]);

0 commit comments

Comments
 (0)