2323package org .biojava .nbio .structure .test ;
2424
2525import junit .framework .TestCase ;
26+
2627import org .biojava .nbio .structure .*;
2728import org .biojava .nbio .structure .align .util .AtomCache ;
2829import org .biojava .nbio .structure .io .FileParsingParameters ;
3536
3637public class StructureToolsTest extends TestCase {
3738
38- Structure structure , structure2 , structure3 ;
39+ Structure structure , structure2 , structure3 , structure4 ;
3940
4041 @ Override
4142 protected void setUp () throws IOException
4243 {
4344 InputStream inStream = this .getClass ().getResourceAsStream ("/5pti.pdb" );
4445 assertNotNull (inStream );
4546
46-
4747 PDBFileParser pdbpars = new PDBFileParser ();
48- FileParsingParameters params = new FileParsingParameters ();
49- params .setAlignSeqRes (false );
50- params .setLoadChemCompInfo (false );
51-
52- pdbpars .setFileParsingParameters (params );
5348
5449 structure = pdbpars .parsePDBFile (inStream ) ;
5550
@@ -59,7 +54,7 @@ protected void setUp() throws IOException
5954
6055 Chain chain = structure .getChain (0 );
6156 assertEquals ("Wrong number of residues." ,123 ,chain .getAtomLength ());
62-
57+
6358 inStream .close ();
6459
6560 // Load structure2
@@ -93,11 +88,32 @@ public void testGetCAAtoms(){
9388 assertEquals ("did not find the expected number of Atoms (58), but got " + cas .length ,58 ,cas .length );
9489 }
9590
91+ public void testGetAtomsConsistency () throws IOException , StructureException {
92+ AtomCache cache = new AtomCache ();
93+ FileParsingParameters params = new FileParsingParameters ();
94+ params .setLoadChemCompInfo (true );
95+ cache .setFileParsingParams (params );
96+
97+ Structure hivA = cache .getStructure ("1hiv.A" );
98+ Atom [] caSa = StructureTools .getRepresentativeAtomArray (hivA );
99+ Atom [] caCa = StructureTools .getRepresentativeAtomArray (hivA .getChain (0 ));
100+ assertEquals ("did not find the same number of Atoms from structure and from chain.." ,
101+ caSa .length ,caCa .length );
102+ Structure hivB = cache .getStructure ("1hiv.B" );
103+ Atom [] caSb = StructureTools .getRepresentativeAtomArray (hivB );
104+ Atom [] caCb = StructureTools .getRepresentativeAtomArray (hivB .getChain (0 ));
105+ assertEquals ("did not find the same number of Atoms from structure and from chain.." ,
106+ caSb .length ,caCb .length );
107+ //Both chains have to be the same size (A and B)
108+ assertEquals (caSa .length ,99 );
109+ assertEquals ("did not find the same number of Atoms in both chains..." ,
110+ caSa .length ,caCb .length );
111+ assertEquals (caSa .length , 99 );
112+ }
113+
96114 public void testGetNrAtoms (){
97115 int length = StructureTools .getNrAtoms (structure );
98116 assertEquals ("did not find the expected number of Atoms (1087), but got " + length ,1087 ,length );
99-
100-
101117 }
102118
103119 public void testGetSubRanges () throws StructureException {
@@ -188,18 +204,18 @@ public void testGetSubRanges() throws StructureException {
188204 range = "_:" ;
189205 substr = StructureTools .getSubRanges (structure2 , range );
190206 assertEquals ("Wrong number of chains in " +range , 1 , substr .size ());
191-
207+
192208 chain = substr .getChain (0 );
193209 assertEquals ("Chain _ not converted to chain A." ,"A" ,chain .getChainID ());
194210 assertEquals ("Did not find the expected number of residues in first chain of " +range , 411 , chain .getAtomLength () );
195-
211+
196212 try {
197213 // Illegal chain name
198214 range = "X:" ;
199215 substr = StructureTools .getSubRanges (structure2 , range );
200216 fail ("Illegal chain name in '" +range +"'. Should throw StructureException" );
201217 } catch (StructureException ex ) {} //expected
202-
218+
203219 // some negative tests
204220 try {
205221 range = "7-10" ;
@@ -217,7 +233,7 @@ public void testRevisedConvention() throws IOException, StructureException{
217233
218234 AtomCache cache = new AtomCache ();
219235
220-
236+
221237 String name11 = "4hhb.A" ;
222238 Structure s = cache .getStructure (name11 );
223239 assertTrue (s .getChains ().size () == 1 );
@@ -230,7 +246,7 @@ public void testRevisedConvention() throws IOException, StructureException{
230246 String name13 = "4hhb.A_" ;
231247 s = cache .getStructure (name13 );
232248 assertTrue (s .getChains ().size () == 1 );
233-
249+
234250 String name9 = "4hhb.C_1-83" ;
235251 String chainId = "C" ;
236252 s = cache .getStructure (name9 );
@@ -247,47 +263,47 @@ public void testRevisedConvention() throws IOException, StructureException{
247263 ca = StructureTools .getRepresentativeAtomArray (s );
248264 assertEquals (93 , ca .length );
249265
250-
266+
251267 }
252268
253269
254- // this will get replaced by #81
255- // public void testStructureToolsRegexp(){
256- //
257- //
258- // Pattern p = ResidueRange.RANGE_REGEX;
259- //
260- // String t2 = "A_10-20";
261- // Matcher m2 = p.matcher(t2);
262- // assertNotNull(m2);
263- // assertTrue(m2.find());
264- // assertTrue(m2.matches());
265- //
266- // // for (int i=0;i< m2.groupCount();i++){
267- // // String s = m2.group(i);
268- // // System.out.println(s);
269- // // }
270- // assertEquals(3,m2.groupCount());
271- //
272- //
273- // String t1 = "A:10-20";
274- // Matcher m1 = p.matcher(t1);
275- // assertNotNull(m1);
276- // assertTrue(m1.find());
277- // assertTrue(m1.matches());
278- // assertEquals(3,m1.groupCount());
279- //
280- //
281- // String t3 = "A";
282- // Matcher m3 = p.matcher(t3);
283- //
284- // assertNotNull(m3);
285- // assertTrue(m3.find());
286- // assertTrue(m3.matches());
287- // assertEquals(3,m3.groupCount());
288- //
289- //
290- // }
270+ // this will get replaced by #81
271+ // public void testStructureToolsRegexp(){
272+ //
273+ //
274+ // Pattern p = ResidueRange.RANGE_REGEX;
275+ //
276+ // String t2 = "A_10-20";
277+ // Matcher m2 = p.matcher(t2);
278+ // assertNotNull(m2);
279+ // assertTrue(m2.find());
280+ // assertTrue(m2.matches());
281+ //
282+ // // for (int i=0;i< m2.groupCount();i++){
283+ // // String s = m2.group(i);
284+ // // System.out.println(s);
285+ // // }
286+ // assertEquals(3,m2.groupCount());
287+ //
288+ //
289+ // String t1 = "A:10-20";
290+ // Matcher m1 = p.matcher(t1);
291+ // assertNotNull(m1);
292+ // assertTrue(m1.find());
293+ // assertTrue(m1.matches());
294+ // assertEquals(3,m1.groupCount());
295+ //
296+ //
297+ // String t3 = "A";
298+ // Matcher m3 = p.matcher(t3);
299+ //
300+ // assertNotNull(m3);
301+ // assertTrue(m3.find());
302+ // assertTrue(m3.matches());
303+ // assertEquals(3,m3.groupCount());
304+ //
305+ //
306+ // }
291307
292308 /**
293309 * Test some subranges that we used to have problems with
@@ -408,27 +424,35 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
408424 public void testGroupsWithinShell () {
409425 //TODO
410426 }
411-
427+
412428 public void testCAmmCIF () throws StructureException {
413429 //mmCIF files left justify their atom names (eg "CA "), so can have different behavior
414430 AtomCache pdbCache = new AtomCache ();
415431 pdbCache .setUseMmCif (false );
432+ FileParsingParameters params = new FileParsingParameters ();
433+ params .setLoadChemCompInfo (true );
434+ pdbCache .setFileParsingParams (params );
435+
416436 AtomCache mmcifCache = new AtomCache ();
417437 mmcifCache .setUseMmCif (true );
438+ FileParsingParameters params2 = new FileParsingParameters ();
439+ params2 .setLoadChemCompInfo (true );
440+ mmcifCache .setFileParsingParams (params2 );
418441
442+
419443 Structure pdb =null , mmcif =null ;
420-
444+
421445 String name = "3PIU" ;
422446 try {
423447 pdb = pdbCache .getStructure (name );
424448 mmcif = mmcifCache .getStructure (name );
425449 } catch (IOException e ) {
426450 assumeNoException (e );
427451 }
428-
452+
429453 Atom [] pdbCA = StructureTools .getRepresentativeAtomArray (pdb );
430454 Atom [] mmcifCA = StructureTools .getRepresentativeAtomArray (mmcif );
431-
455+
432456 assertEquals ("PDB has wrong length" ,409 ,pdbCA .length );
433457 assertEquals ("PDB has wrong length" ,409 ,mmcifCA .length );
434458 }
0 commit comments