2929import java .io .File ;
3030import java .io .FileOutputStream ;
3131import java .io .IOException ;
32+ import java .net .URL ;
3233import java .nio .file .Files ;
3334import java .nio .file .Path ;
3435import java .nio .file .Paths ;
35- import java .nio .file .attribute .FileAttribute ;
3636import java .text .ParseException ;
3737import java .text .SimpleDateFormat ;
3838import java .util .Date ;
5353import org .biojava .nbio .structure .io .LocalPDBDirectory ;
5454import org .biojava .nbio .structure .io .LocalPDBDirectory .FetchBehavior ;
5555import org .biojava .nbio .structure .io .LocalPDBDirectory .ObsoleteBehavior ;
56- import org .biojava .nbio .structure .io .util .FileDownloadUtils ;
5756import org .biojava .nbio .structure .io .MMCIFFileReader ;
57+ import org .biojava .nbio .structure .io .mmcif .model .ChemComp ;
58+ import org .biojava .nbio .structure .io .util .FileDownloadUtils ;
5859import org .biojava .nbio .structure .scop .ScopDatabase ;
5960import org .biojava .nbio .structure .scop .ScopFactory ;
6061import org .junit .After ;
@@ -364,17 +365,34 @@ public void testEmptyChemComp() throws IOException, StructureException {
364365 cache .setUseMmCif (true );
365366
366367 // Create an empty chemcomp
367- Path sub = tmpCache .resolve (Paths .get ("chemcomp" , "ALA.cif.gz" ));
368- Files .createDirectories (sub .getParent ());
369- Files .createFile (sub );
370- assertTrue (Files .exists (sub ));
371- assertEquals (0 , Files .size (sub ));
368+ Path chemCompCif = tmpCache .resolve (Paths .get ("chemcomp" , "ATP.cif.gz" ));
369+ Files .createDirectories (chemCompCif .getParent ());
370+ Files .createFile (chemCompCif );
371+ assertTrue (Files .exists (chemCompCif ));
372+ assertEquals (0 , Files .size (chemCompCif ));
373+
374+ // Copy stub file into place
375+ Path testCif = tmpCache .resolve (Paths .get ("data" , "structures" , "divided" , "mmCIF" , "ab" ,"1abc.cif.gz" ));
376+ Files .createDirectories (testCif .getParent ());
377+ URL resource = AtomCacheTest .class .getResource ("/atp.cif.gz" );
378+ File src = new File (resource .getPath ());
379+ FileDownloadUtils .copy (src , testCif .toFile ());
372380
373- Structure s = cache .getStructure ("1A4W" );
381+ // Load structure
382+ Structure s = cache .getStructure ("1ABC" );
374383
375384 assertNotNull (s );
385+
386+ Group g = s .getChainByPDB ("A" ).getAtomGroup (0 );
387+ assertTrue (g .getPDBName ().equals ("ATP" ));
388+
389+ // should be unknown
390+ ChemComp chem = g .getChemComp ();
391+ assertNotNull (chem );
392+ assertTrue (chem .getAtoms ().size () > 0 );
393+ assertEquals ("NON-POLYMER" , chem .getType ());
376394 } finally {
377- FileDownloadUtils .deleteDirectory (tmpCache );
395+ // FileDownloadUtils.deleteDirectory(tmpCache);
378396 }
379397 }
380398
@@ -387,6 +405,7 @@ public void testEmptyChemComp() throws IOException, StructureException {
387405 */
388406 @ Test
389407 public void testEmptyGZChemComp () throws IOException , StructureException {
408+
390409 Path tmpCache = Paths .get (System .getProperty ("java.io.tmpdir" ),"BIOJAVA_TEST_CACHE" );
391410 logger .info ("Testing AtomCache at {}" , tmpCache .toString ());
392411 System .setProperty (UserConfiguration .PDB_DIR , tmpCache .toString ());
@@ -400,7 +419,7 @@ public void testEmptyGZChemComp() throws IOException, StructureException {
400419 cache .setUseMmCif (true );
401420
402421 // Create an empty chemcomp
403- Path sub = tmpCache .resolve (Paths .get ("chemcomp" , "ALA .cif.gz" ));
422+ Path sub = tmpCache .resolve (Paths .get ("chemcomp" , "ATP .cif.gz" ));
404423 Files .createDirectories (sub .getParent ());
405424 try (GZIPOutputStream out = new GZIPOutputStream (new FileOutputStream (sub .toFile ()))) {
406425 // don't write anything
@@ -409,12 +428,28 @@ public void testEmptyGZChemComp() throws IOException, StructureException {
409428 assertTrue (Files .exists (sub ));
410429 assertTrue (0 < Files .size (sub ));
411430
412- Structure s = cache .getStructure ("1A4W" );
431+ // Copy stub file into place
432+ Path testCif = tmpCache .resolve (Paths .get ("data" , "structures" , "divided" , "mmCIF" , "ab" ,"1abc.cif.gz" ));
433+ Files .createDirectories (testCif .getParent ());
434+ URL resource = AtomCacheTest .class .getResource ("/atp.cif.gz" );
435+ File src = new File (resource .getPath ());
436+ FileDownloadUtils .copy (src , testCif .toFile ());
437+
438+ // Load structure
439+ Structure s = cache .getStructure ("1ABC" );
413440
414441 assertNotNull (s );
415442
443+ Group g = s .getChainByPDB ("A" ).getAtomGroup (0 );
444+ assertTrue (g .getPDBName ().equals ("ATP" ));
445+
446+ // should be unknown
447+ ChemComp chem = g .getChemComp ();
448+ assertNotNull (chem );
449+ assertTrue (chem .getAtoms ().size () > 0 );
450+ assertEquals ("NON-POLYMER" , chem .getType ());
416451 } finally {
417- FileDownloadUtils .deleteDirectory (tmpCache );
452+ // FileDownloadUtils.deleteDirectory(tmpCache);
418453 }
419454 }
420455
0 commit comments