5454import org .biojava .nbio .structure .io .LocalPDBDirectory .FetchBehavior ;
5555import org .biojava .nbio .structure .io .LocalPDBDirectory .ObsoleteBehavior ;
5656import org .biojava .nbio .structure .io .MMCIFFileReader ;
57+ import org .biojava .nbio .structure .io .mmcif .ChemCompGroupFactory ;
58+ import org .biojava .nbio .structure .io .mmcif .ChemCompProvider ;
59+ import org .biojava .nbio .structure .io .mmcif .DownloadChemCompProvider ;
5760import org .biojava .nbio .structure .io .mmcif .model .ChemComp ;
5861import org .biojava .nbio .structure .io .util .FileDownloadUtils ;
5962import org .biojava .nbio .structure .scop .ScopDatabase ;
@@ -77,6 +80,7 @@ public class AtomCacheTest {
7780 private String previousPDB_DIR ;
7881 private String previousPDB_CACHE_DIR ;
7982 private AtomCache cleanCache = new AtomCache ();
83+ private ChemCompProvider previousChemCompProvider = ChemCompGroupFactory .getChemCompProvider ();
8084
8185 @ Before
8286 public void setUp () {
@@ -85,8 +89,10 @@ public void setUp() {
8589 cache = new AtomCache ();
8690 cache .setObsoleteBehavior (ObsoleteBehavior .FETCH_OBSOLETE );
8791 StructureIO .setAtomCache (cache );
92+
8893 // Use a fixed SCOP version for stability
8994 ScopFactory .setScopDatabase (ScopFactory .VERSION_1_75B );
95+ logger .warn ("setUp()" );
9096 }
9197
9298 @ After
@@ -96,6 +102,7 @@ public void tearDown() {
96102 System .setProperty (UserConfiguration .PDB_CACHE_DIR , previousPDB_CACHE_DIR );
97103 }
98104 StructureIO .setAtomCache (cleanCache );
105+ ChemCompGroupFactory .setChemCompProvider (previousChemCompProvider );
99106 }
100107
101108 /**
@@ -363,7 +370,8 @@ public void testEmptyChemComp() throws IOException, StructureException {
363370 cache .setPath (tmpCache .toString ());
364371 cache .setCachePath (tmpCache .toString ());
365372 cache .setUseMmCif (true );
366-
373+ ChemCompGroupFactory .setChemCompProvider (new DownloadChemCompProvider (tmpCache .toString ()));
374+
367375 // Create an empty chemcomp
368376 Path chemCompCif = tmpCache .resolve (Paths .get ("chemcomp" , "ATP.cif.gz" ));
369377 Files .createDirectories (chemCompCif .getParent ());
@@ -381,6 +389,10 @@ public void testEmptyChemComp() throws IOException, StructureException {
381389 // Load structure
382390 Structure s = cache .getStructure ("1ABC" );
383391
392+ // Should have re-downloaded the file
393+ assertTrue (Files .size (chemCompCif ) > LocalPDBDirectory .MIN_PDB_FILE_SIZE );
394+
395+ // Structure should have valid ChemComp now
384396 assertNotNull (s );
385397
386398 Group g = s .getChainByPDB ("A" ).getAtomGroup (0 );
@@ -417,6 +429,8 @@ public void testEmptyGZChemComp() throws IOException, StructureException {
417429 cache .setPath (tmpCache .toString ());
418430 cache .setCachePath (tmpCache .toString ());
419431 cache .setUseMmCif (true );
432+ ChemCompGroupFactory .setChemCompProvider (new DownloadChemCompProvider (tmpCache .toString ()));
433+
420434
421435 // Create an empty chemcomp
422436 Path sub = tmpCache .resolve (Paths .get ("chemcomp" , "ATP.cif.gz" ));
@@ -426,7 +440,7 @@ public void testEmptyGZChemComp() throws IOException, StructureException {
426440 out .flush ();
427441 }
428442 assertTrue (Files .exists (sub ));
429- assertTrue (0 < Files .size (sub ));
443+ assertTrue (0 < Files .size (sub ) && Files . size ( sub ) < LocalPDBDirectory . MIN_PDB_FILE_SIZE );
430444
431445 // Copy stub file into place
432446 Path testCif = tmpCache .resolve (Paths .get ("data" , "structures" , "divided" , "mmCIF" , "ab" ,"1abc.cif.gz" ));
@@ -438,6 +452,10 @@ public void testEmptyGZChemComp() throws IOException, StructureException {
438452 // Load structure
439453 Structure s = cache .getStructure ("1ABC" );
440454
455+ // Should have re-downloaded the file
456+ assertTrue (Files .size (sub ) > LocalPDBDirectory .MIN_PDB_FILE_SIZE );
457+
458+ // Structure should have valid ChemComp
441459 assertNotNull (s );
442460
443461 Group g = s .getChainByPDB ("A" ).getAtomGroup (0 );
0 commit comments