Skip to content

Commit bec7990

Browse files
committed
Reverting parser change: removing pure non-poly chains is a bad idea.
Now all non-poly chains will be ignored in compound finder, biojava#305
1 parent 6f70909 commit bec7990

File tree

5 files changed

+144
-170
lines changed

5 files changed

+144
-170
lines changed

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

Lines changed: 89 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import java.io.IOException;
3737
import java.io.InputStream;
3838
import java.io.StringReader;
39-
import java.util.logging.Level;
40-
import java.util.logging.Logger;
4139

4240
import static org.junit.Assert.*;
4341

@@ -53,28 +51,22 @@ public void setUp(){
5351
}
5452

5553
@Test
56-
public void test2LetterResidueName() {
57-
try {
58-
59-
// from 1a4w:
60-
String t =
61-
"HETATM 2242 NA NA 541 5.845 -14.122 30.560 0.88 23.48 NA"+newline+
62-
"HETATM 2243 NA NA 542 18.411 -16.475 38.464 0.88 24.77 NA"+newline;
63-
BufferedReader br = new BufferedReader(new StringReader(t));
64-
Structure s = parser.parsePDBFile(br);
65-
String pdb = s.toPDB();
66-
67-
assertEquals("two letter residue names are not dealt with correctly! ",t,pdb);
54+
public void test2LetterResidueName() throws IOException {
55+
// from 1a4w:
56+
String t =
57+
"HETATM 2242 NA NA L 541 5.845 -14.122 30.560 0.88 23.48 NA"+newline+
58+
"HETATM 2243 NA NA L 542 18.411 -16.475 38.464 0.88 24.77 NA"+newline;
59+
BufferedReader br = new BufferedReader(new StringReader(t));
60+
Structure s = parser.parsePDBFile(br);
61+
String pdb = s.toPDB();
6862

63+
assertEquals("two letter residue names are not dealt with correctly! ",t,pdb);
6964

70-
} catch (Exception e){
71-
fail(e.getMessage());
72-
}
7365

7466
}
7567

7668
@Test
77-
public void testCorrectFloatingPointDisplay() {
69+
public void testCorrectFloatingPointDisplay() throws IOException {
7870

7971
// from 1a4w:
8072

@@ -96,19 +88,17 @@ public void testCorrectFloatingPointDisplay() {
9688
"ATOM 14 SG CYS L 1 12.247 14.885 22.538 1.00 20.55 S"+newline;
9789

9890
BufferedReader br = new BufferedReader(new StringReader(t));
99-
try {
100-
Structure s = parser.parsePDBFile(br);
101-
String pdb = s.toPDB();
10291

103-
assertTrue("the created PDB file does not match the input file", pdb.equals(t));
104-
} catch (Exception e){
105-
fail(e.getMessage());
106-
}
92+
Structure s = parser.parsePDBFile(br);
93+
String pdb = s.toPDB();
94+
95+
assertTrue("the created PDB file does not match the input file", pdb.equals(t));
96+
10797

10898
}
10999

110100
@Test
111-
public void testPDBHeader(){
101+
public void testPDBHeader() throws IOException {
112102

113103
String t =
114104
"HEADER COMPLEX (SERINE PROTEASE/INHIBITORS) 06-FEB-98 1A4W "+newline+
@@ -120,23 +110,21 @@ public void testPDBHeader(){
120110
//"REMARK 2 RESOLUTION. 2.00 ANGSTROMS. "+newline;
121111

122112
BufferedReader br = new BufferedReader(new StringReader(t));
123-
try {
124-
Structure s = parser.parsePDBFile(br);
125-
String pdb = s.toPDB();
126-
127-
if (! pdb.equalsIgnoreCase(t)){
128-
StringManipulationTestsHelper.compareString(t, pdb);
129-
System.out.println(t);
130-
System.out.println(pdb);
131-
}
132113

133-
// we ignore the case here, since the month FEB is written as Feb, which should be ok...
134-
assertTrue("the created header does not match the PDB file" ,pdb.equalsIgnoreCase(t));
114+
Structure s = parser.parsePDBFile(br);
115+
String pdb = s.toPDB();
135116

136-
} catch (IOException e){
137-
fail(e.getMessage());
117+
if (! pdb.equalsIgnoreCase(t)){
118+
StringManipulationTestsHelper.compareString(t, pdb);
119+
System.out.println(t);
120+
System.out.println(pdb);
138121
}
139122

123+
// we ignore the case here, since the month FEB is written as Feb, which should be ok...
124+
assertTrue("the created header does not match the PDB file" ,pdb.equalsIgnoreCase(t));
125+
126+
127+
140128
}
141129

142130
@Test
@@ -228,7 +216,7 @@ public void testREMARK3() throws IOException {
228216
// }
229217

230218
@Test
231-
public void testSITE() {
219+
public void testSITE() throws IOException {
232220
// from 1a4w:
233221
String remark800Test =
234222
//don't add these here - they are present in the PDB file but are added in the structure.toPDB()
@@ -269,57 +257,53 @@ public void testSITE() {
269257
"SITE 1 AC6 5 HIS H 57 TRP H 60D LYS H 60F 2EP H 375 " + newline +
270258
"SITE 2 AC6 5 HOH H 532 " + newline;
271259
InputStream inStream = this.getClass().getResourceAsStream("/1a4w.pdb");
272-
try {
273-
Structure s = parser.parsePDBFile(inStream);
274-
// System.out.print(s.getSites());
275-
Chain chain = new ChainImpl();
276-
chain.setChainID("H");
277-
for (Site site : s.getSites()) {
278-
//System.out.println("Site: " + site.getSiteID());
279-
for (Group group : site.getGroups()) {
280-
//manually add the chain as this is added later once the ATOM recrds are parsed usually
281-
group.setChain(chain);
282-
// System.out.println(" PDBName: " + group.getPDBName());
283-
// System.out.println(" PDBCode: " + group.getPDBCode());
284-
// System.out.println(" Type: " + group.getType());
285-
// System.out.println(" Parent: " + group.getChainId());
286-
}
287-
260+
Structure s = parser.parsePDBFile(inStream);
261+
// System.out.print(s.getSites());
262+
Chain chain = new ChainImpl();
263+
chain.setChainID("H");
264+
for (Site site : s.getSites()) {
265+
//System.out.println("Site: " + site.getSiteID());
266+
for (Group group : site.getGroups()) {
267+
//manually add the chain as this is added later once the ATOM recrds are parsed usually
268+
group.setChain(chain);
269+
// System.out.println(" PDBName: " + group.getPDBName());
270+
// System.out.println(" PDBCode: " + group.getPDBCode());
271+
// System.out.println(" Type: " + group.getType());
272+
// System.out.println(" Parent: " + group.getChainId());
288273
}
289-
StringBuilder remark800 = new StringBuilder();
290-
StringBuilder sites = new StringBuilder();
291274

292-
for (Site site : s.getSites()) {
293-
remark800.append(site.remark800toPDB());
294-
sites.append(site.toPDB());
295-
}
296-
297-
// System.out.println("testSITE: " + newline + pdb);
298-
if (!remark800.toString().equals(remark800Test)) {
299-
// System.out.println("Expected:");
300-
// System.out.println(remark800Test);
301-
// System.out.println("Got:");
302-
// System.out.println(remark800.toString());
303-
}
304-
assertTrue("the created PDB REMARK800 section does not match the input file", remark800.toString().equals(remark800Test));
275+
}
276+
StringBuilder remark800 = new StringBuilder();
277+
StringBuilder sites = new StringBuilder();
305278

306-
if (!sites.toString().equals(sitesTest)) {
307-
System.out.println("Expected:");
308-
System.out.println(sitesTest);
309-
System.out.println("Got:");
310-
System.out.println(sites.toString());
311-
}
312-
assertEquals("the created PDB SITE section does not match the input file", sites.toString(),sitesTest);
279+
for (Site site : s.getSites()) {
280+
remark800.append(site.remark800toPDB());
281+
sites.append(site.toPDB());
282+
}
313283

284+
// System.out.println("testSITE: " + newline + pdb);
285+
if (!remark800.toString().equals(remark800Test)) {
286+
// System.out.println("Expected:");
287+
// System.out.println(remark800Test);
288+
// System.out.println("Got:");
289+
// System.out.println(remark800.toString());
290+
}
291+
assertTrue("the created PDB REMARK800 section does not match the input file", remark800.toString().equals(remark800Test));
314292

315-
} catch (Exception e){
316-
e.printStackTrace();
317-
fail(e.getMessage());
293+
if (!sites.toString().equals(sitesTest)) {
294+
System.out.println("Expected:");
295+
System.out.println(sitesTest);
296+
System.out.println("Got:");
297+
System.out.println(sites.toString());
318298
}
299+
assertEquals("the created PDB SITE section does not match the input file", sites.toString(),sitesTest);
300+
301+
302+
319303
}
320304

321305
@Test
322-
public void testMultiLineJRNL(){
306+
public void testMultiLineJRNL() throws IOException {
323307
// System.out.println("Testing JRNL record parsing from 3pfk");
324308
String jrnlString =
325309
"JRNL AUTH P.R.EVANS,G.W.FARRANTS,P.J.HUDSON " + newline +
@@ -332,11 +316,9 @@ public void testMultiLineJRNL(){
332316

333317
BufferedReader br = new BufferedReader(new StringReader(jrnlString));
334318
Structure s = null;
335-
try {
336-
s = parser.parsePDBFile(br);
337-
} catch (IOException ex) {
338-
Logger.getLogger(PDBFileParserTest.class.getName()).log(Level.SEVERE, null, ex);
339-
}
319+
320+
s = parser.parsePDBFile(br);
321+
340322
// String jrnl = s.getJournalArticle().toString();
341323
// System.out.println(jrnl);
342324
JournalArticle journalArticle = s.getJournalArticle();
@@ -347,7 +329,7 @@ public void testMultiLineJRNL(){
347329
}
348330

349331
@Test
350-
public void testIncorrectDateFormatMultiLineJRNL(){
332+
public void testIncorrectDateFormatMultiLineJRNL() throws IOException{
351333
// System.out.println("Testing JRNL record parsing from 3pfk");
352334
String jrnlString =
353335
"JRNL AUTH P.R.EVANS,G.W.FARRANTS,P.J.HUDSON " + newline +
@@ -360,11 +342,7 @@ public void testIncorrectDateFormatMultiLineJRNL(){
360342

361343
BufferedReader br = new BufferedReader(new StringReader(jrnlString));
362344
Structure s = null;
363-
try {
364-
s = parser.parsePDBFile(br);
365-
} catch (IOException ex) {
366-
Logger.getLogger(PDBFileParserTest.class.getName()).log(Level.SEVERE, null, ex);
367-
}
345+
s = parser.parsePDBFile(br);
368346
// String jrnl = s.getJournalArticle().toString();
369347
// System.out.println(jrnl);
370348
JournalArticle journalArticle = s.getJournalArticle();
@@ -375,7 +353,7 @@ public void testIncorrectDateFormatMultiLineJRNL(){
375353
}
376354

377355
@Test
378-
public void testInvalidFormatREFsectionJRNL(){
356+
public void testInvalidFormatREFsectionJRNL() throws IOException{
379357
// System.out.println("Testing JRNL record parsing from 3pfk");
380358
String jrnlString =
381359
"JRNL AUTH P.R.EVANS,G.W.FARRANTS,P.J.HUDSON " + newline +
@@ -387,11 +365,7 @@ public void testInvalidFormatREFsectionJRNL(){
387365

388366
BufferedReader br = new BufferedReader(new StringReader(jrnlString));
389367
Structure s = null;
390-
try {
391-
s = parser.parsePDBFile(br);
392-
} catch (IOException ex) {
393-
Logger.getLogger(PDBFileParserTest.class.getName()).log(Level.SEVERE, null, ex);
394-
}
368+
s = parser.parsePDBFile(br);
395369
// String jrnl = s.getJournalArticle().toString();
396370
// System.out.println(jrnl);
397371
JournalArticle journalArticle = s.getJournalArticle();
@@ -402,7 +376,7 @@ public void testInvalidFormatREFsectionJRNL(){
402376
}
403377

404378
@Test
405-
public void testSecondMultiLineJRNL(){
379+
public void testSecondMultiLineJRNL() throws IOException{
406380
// System.out.println("Testing JRNL record parsing from 1gpb");
407381
String jrnlString =
408382
"JRNL AUTH K.R.ACHARYA,D.I.STUART,K.M.VARVILL,L.N.JOHNSON " + newline +
@@ -417,11 +391,7 @@ public void testSecondMultiLineJRNL(){
417391

418392
BufferedReader br = new BufferedReader(new StringReader(jrnlString));
419393
Structure s = null;
420-
try {
421-
s = parser.parsePDBFile(br);
422-
} catch (IOException ex) {
423-
Logger.getLogger(PDBFileParserTest.class.getName()).log(Level.SEVERE, null, ex);
424-
}
394+
s = parser.parsePDBFile(br);
425395
// String jrnl = s.getJournalArticle().toString();
426396
// System.out.println(jrnl);
427397
JournalArticle journalArticle = s.getJournalArticle();
@@ -432,7 +402,7 @@ public void testSecondMultiLineJRNL(){
432402
}
433403

434404
@Test
435-
public void testSingleLineJRNL(){
405+
public void testSingleLineJRNL() throws IOException{
436406
// System.out.println("Testing JRNL record parsing from 2bln");
437407
String jrnlString =
438408
"JRNL AUTH G.J.WILLIAMS,S.D.BREAZEALE,C.R.H.RAETZ,J.H.NAISMITH " + newline +
@@ -448,11 +418,7 @@ public void testSingleLineJRNL(){
448418

449419
BufferedReader br = new BufferedReader(new StringReader(jrnlString));
450420
Structure s = null;
451-
try {
452-
s = parser.parsePDBFile(br);
453-
} catch (IOException ex) {
454-
Logger.getLogger(PDBFileParserTest.class.getName()).log(Level.SEVERE, null, ex);
455-
}
421+
s = parser.parsePDBFile(br);
456422
// String jrnl = s.getJournalArticle().toString();
457423
// System.out.println(jrnl);
458424
JournalArticle journalArticle = s.getJournalArticle();
@@ -464,7 +430,7 @@ public void testSingleLineJRNL(){
464430
}
465431

466432
@Test
467-
public void testToBePublishedJRNL(){
433+
public void testToBePublishedJRNL() throws IOException{
468434
// System.out.println("Testing JRNL record parsing from 1i2c");
469435
String jrnlString =
470436
"JRNL AUTH M.J.THEISEN,S.L.SANDA,S.L.GINELL,C.BENNING, " + newline +
@@ -478,11 +444,7 @@ public void testToBePublishedJRNL(){
478444

479445
BufferedReader br = new BufferedReader(new StringReader(jrnlString));
480446
Structure s = null;
481-
try {
482-
s = parser.parsePDBFile(br);
483-
} catch (IOException ex) {
484-
Logger.getLogger(PDBFileParserTest.class.getName()).log(Level.SEVERE, null, ex);
485-
}
447+
s = parser.parsePDBFile(br);
486448

487449
JournalArticle journalArticle = s.getJournalArticle();
488450
assertNull(journalArticle.getVolume());
@@ -492,7 +454,7 @@ public void testToBePublishedJRNL(){
492454
}
493455

494456
@Test
495-
public void test4hhbAcceptedAtomNames(){
457+
public void test4hhbAcceptedAtomNames() throws IOException, StructureException{
496458

497459
FileParsingParameters params = new FileParsingParameters();
498460

@@ -501,33 +463,27 @@ public void test4hhbAcceptedAtomNames(){
501463
AtomCache cache = new AtomCache();
502464

503465
cache.setFileParsingParams(params);
504-
try {
505-
Structure s = cache.getStructure("4HHB");
466+
Structure s = cache.getStructure("4HHB");
506467

507-
//System.out.println(s.toPDB());
508-
Atom[] ca = StructureTools.getRepresentativeAtomArray(s);
509-
Atom[] cb = StructureTools.getAtomArray(s, new String[]{StructureTools.CB_ATOM_NAME,});
468+
//System.out.println(s.toPDB());
469+
Atom[] ca = StructureTools.getRepresentativeAtomArray(s);
470+
Atom[] cb = StructureTools.getAtomArray(s, new String[]{StructureTools.CB_ATOM_NAME,});
510471

511-
// gly does not have cb...
512-
assertTrue(ca.length > cb.length);
513-
assertTrue(cb.length > 500);
472+
// gly does not have cb...
473+
assertTrue(ca.length > cb.length);
474+
assertTrue(cb.length > 500);
514475

515-
Atom[] allwithoutGLY = StructureTools.getAtomArray(s, acceptedAtoms);
476+
Atom[] allwithoutGLY = StructureTools.getAtomArray(s, acceptedAtoms);
516477

517-
assertEquals(allwithoutGLY.length, (ca.length + cb.length - (ca.length-cb.length)));
478+
assertEquals(allwithoutGLY.length, (ca.length + cb.length - (ca.length-cb.length)));
518479

519-
} catch (Exception e){
520-
e.printStackTrace();
521-
fail(e.getMessage());
522-
}
523480
}
524481

525482
@Test
526483
public void testCorrectAtomNamePadding() throws IOException {
527484

528485
// from 1a4w:
529486
String atomLines =
530-
531487
"HETATM 2242 NA NA H 541 5.845 -14.122 30.560 0.88 23.48 NA"+newline+
532488
"HETATM 2243 NA NA H 542 18.411 -16.475 38.464 0.88 24.77 NA"+newline+
533489
"HETATM 2244 C1 QWE H 373 17.735 -17.178 22.612 1.00 26.29 C"+newline+

0 commit comments

Comments
 (0)