Skip to content

Commit 2d57e54

Browse files
committed
Fix unit tests
- Most differences were due to structures newly including ligands. - One bug fixed involving headerOnly structures
1 parent dc4abd9 commit 2d57e54

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,21 @@ public void testGetAtomsConsistency() throws IOException, StructureException{
105105
Structure hivA = cache.getStructure("1hiv.A");
106106
Atom[] caSa = StructureTools.getRepresentativeAtomArray(hivA);
107107
Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChainByIndex(0));
108+
//TODO Residue 67 is PTM. In BioJava 4 this is treated as a ligand, so it
109+
// gets added to caSa. In BioJava 5 this should be fixed, so they
110+
// should match again.
108111
assertEquals("did not find the same number of Atoms from structure and from chain..",
109-
caSa.length,caCa.length);
112+
caSa.length-1,caCa.length);
110113
Structure hivB = cache.getStructure("1hiv.B");
111114
Atom[] caSb = StructureTools.getRepresentativeAtomArray(hivB);
112115
Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChainByIndex(0));
113116
assertEquals("did not find the same number of Atoms from structure and from chain..",
114-
caSb.length,caCb.length);
117+
caSb.length-1,caCb.length);
115118
//Both chains have to be the same size (A and B)
116-
assertEquals(caSa.length,99);
119+
assertEquals(99,caSa.length-1);
117120
assertEquals("did not find the same number of Atoms in both chains...",
118-
caSa.length,caCb.length);
119-
assertEquals(caSa.length, 99);
121+
caSa.length-1,caCb.length);
122+
assertEquals(99,caSa.length-1);
120123

121124
ChemCompGroupFactory.setChemCompProvider(provider);
122125
}
@@ -413,7 +416,9 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
413416
// range including insertion
414417
range = "H:35-37"; //includes 36A
415418
substr = StructureTools.getSubRanges(structure3, range);
416-
assertEquals("Wrong number of chains in "+range, 1, substr.size());
419+
// Because we are loading from PDB, TYS I:363 is recognized as a ligand
420+
// rather than a PTM, so it gets included here
421+
assertEquals("Wrong number of chains in "+range, 2, substr.size());
417422

418423
chain = substr.getChainByIndex(0);
419424

@@ -423,7 +428,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
423428
// end with insertion
424429
range = "H:35-36A";
425430
substr = StructureTools.getSubRanges(structure3, range);
426-
assertEquals("Wrong number of chains in "+range, 1, substr.size());
431+
assertEquals("Wrong number of chains in "+range, 2, substr.size());
427432

428433
chain = substr.getChainByIndex(0);
429434

@@ -439,7 +444,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
439444
assertEquals("Did not find the expected number of residues in "+range, 3, chain.getAtomLength() );
440445

441446
// within insertion
442-
range = "L:14-14K"; //includes 36A
447+
range = "L:14-14K";
443448
substr = StructureTools.getSubRanges(structure3, range);
444449
assertEquals("Wrong number of chains in "+range, 1, substr.size());
445450

@@ -448,7 +453,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
448453
assertEquals("Did not find the expected number of residues in "+range, 12, chain.getAtomLength() );
449454

450455
// within insertion
451-
range = "L:14C-14J"; //includes 36A
456+
range = "L:14C-14J";
452457
substr = StructureTools.getSubRanges(structure3, range);
453458
assertEquals("Wrong number of chains in "+range, 1, substr.size());
454459

biojava-structure/src/main/java/org/biojava/nbio/structure/SubstructureIdentifier.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,10 @@ public Structure reduce(Structure s) throws StructureException {
287287

288288
prevChainId = c.getId();
289289
} // end range
290+
291+
// Transfer any close ligands
292+
copyLigandsByProximity(s,newS, StructureTools.DEFAULT_LIGAND_PROXIMITY_CUTOFF, modelNr, modelNr);
290293
}
291-
292-
copyLigandsByProximity(s,newS, StructureTools.DEFAULT_LIGAND_PROXIMITY_CUTOFF, modelNr, modelNr);
293294
} // end modelNr
294295

295296
return newS;
@@ -317,7 +318,7 @@ public Structure loadStructure(AtomCache cache) throws IOException, StructureExc
317318
* a distance cutoff. Ligand groups are moved (destructively) from full to reduced
318319
* if they fall within the cutoff of any atom in the reduced structure.
319320
* The {@link StructureTools#DEFAULT_LIGAND_PROXIMITY_CUTOFF default cutoff}
320-
* (currently 7Å) is used.
321+
* is used.
321322
* @param full Structure containing all ligands
322323
* @param reduced Structure with a subset of the polymer groups from full
323324
* @see StructureTools#getLigandsByProximity(java.util.Collection, Atom[], double)
@@ -344,6 +345,8 @@ protected static void copyLigandsByProximity(Structure full, Structure reduced,
344345
// Geometric hashing of the reduced structure
345346
Grid grid = new Grid(cutoff);
346347
Atom[] nonwaters = StructureTools.getAllNonHAtomArray(reduced,true,toModel);
348+
if( nonwaters.length < 1 )
349+
return;
347350
grid.addAtoms(nonwaters);
348351

349352

biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,22 @@ public void testAtomCacheNameParsing() throws IOException, StructureException {
7575
String name1= "4hhb";
7676
Structure s = cache.getStructure(name1);
7777
assertNotNull(s);
78-
assertTrue(s.getPolyChains().size() == 4);
78+
assertEquals(4,s.getPolyChains().size());
7979

8080
String name2 = "4hhb.C";
8181
String chainId2 = "C";
8282
s = cache.getStructure(name2);
8383

84-
assertTrue(s.getChains().size() == 1);
84+
assertEquals(1,s.getChains().size());
8585
Chain c = s.getPolyChainByPDB(chainId2);
86-
assertEquals(c.getName(),chainId2);
86+
assertEquals(chainId2,c.getName());
8787

8888

8989
// Colon separators removed in BioJava 4.1.0
9090
String name2b = "4hhb:A";
9191
try {
9292
s = cache.getStructure(name2b);
9393
fail("Invalid structure format");
94-
} catch(IOException e) {
9594
} catch(StructureException e) {
9695
}
9796

@@ -101,28 +100,28 @@ public void testAtomCacheNameParsing() throws IOException, StructureException {
101100
String chainId3 = "B";
102101
s = cache.getStructure(name3);
103102
assertNotNull(s);
104-
assertTrue(s.getChains().size() == 1);
103+
assertEquals(1,s.getChains().size());
105104

106105
c = s.getPolyChainByPDB(chainId3);
107-
assertEquals(c.getName(),chainId3);
106+
assertEquals(chainId3,c.getName());
108107

109108

110109
String name4 = "4hhb.A:10-20,B:10-20,C:10-20";
111110
s = cache.getStructure(name4);
112111
assertNotNull(s);
113112

114-
assertEquals(s.getChains().size(), 3);
113+
assertEquals(3,s.getChains().size());
115114

116115
c = s.getPolyChainByPDB("B");
117-
assertEquals(c.getAtomLength(),11);
116+
assertEquals(11,c.getAtomLength());
118117

119118
String name5 = "4hhb.(A:10-20,A:30-40)";
120119
s =cache.getStructure(name5);
121120
assertNotNull(s);
122121

123-
assertEquals(s.getChains().size(),1 );
122+
assertEquals(1,s.getChains().size() );
124123
c = s.getPolyChainByPDB("A");
125-
assertEquals(c.getAtomLength(),22);
124+
assertEquals(23,c.getAtomLength());
126125

127126
try {
128127
// This syntax used to work, since the first paren is treated as a separator
@@ -135,9 +134,9 @@ public void testAtomCacheNameParsing() throws IOException, StructureException {
135134
String name8 = "4hhb.(C)";
136135
s = cache.getStructure(name8);
137136

138-
assertTrue(s.getChains().size() == 1);
137+
assertEquals(1,s.getChains().size());
139138
c = s.getPolyChainByPDB(chainId2);
140-
assertEquals(c.getName(),chainId2);
139+
assertEquals(chainId2,c.getName());
141140

142141
}
143142

0 commit comments

Comments
 (0)