Skip to content

ChemCompGroupFactory not respecting the ChemCompProvider if value is already cached #145

Closed

Description

@josemduarte

This is a subtle issue with singletons in the structure module. I've only found it because of a strange inconsistency while parsing both mmCIF and PDB files in same JVM.

In ChemCompGroupFactory the ChemCompProvider can be set with setChemCompProvider (e.g. it is set to ReducedChemCompProvider in PDBFileParser when isLoadChemCompInfo is false), however if the cache in ChemCompGroupFactory is already initialised then the ChemCompProvider setting is ignored and the value from the cache is taken instead.

For instance the PDB file parser sets it by default to ReducedChemCompProvider while the mmCIF parser sets it by default to DownloadChemCompProvider. If one uses the mmCIF parser first and then the PDB parser the setting to ReducedChemCompProvider is ignored because the cache contains already the value coming from the DownloadChemCompProvider (i.e. from the file in /tmp/chemcomp/xxx.cif.gz)

One way to reproduce it is with this code:

String pdbCode = "1oew";
Structure structure = null;

AtomCache cache = new AtomCache();  
cache.setUseMmCif(true);
structure = cache.getStructure(pdbCode);

cache.setUseMmCif(false);
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(true);
cache.setFileParsingParams(params);

structure = cache.getStructure(pdbCode);

That produces an error because of an issue in the alignment of SEQRES to ATOM.

However this doesn't produce an error:

String pdbCode = "1oew";
Structure structure = null;

AtomCache cache = new AtomCache();  
cache.setUseMmCif(false);
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(true);
cache.setFileParsingParams(params);

structure = cache.getStructure(pdbCode);

Activity

  1. josemduarte commented on Aug 12, 2014

    @josemduarte
    ContributorAuthor

    One possible solution to the issue is having different caches for different ChemCompProviders. That's the only way I can see to avoid weird behaviours that depend on what was run previously with same JVM.

  2. josemduarte commented on Aug 12, 2014

    @josemduarte
    ContributorAuthor

    BTW this is loosely related to #103 . Could this have caused that issue? or was it another problem with some singleton state resetting?

  3. sbliven commented on Aug 27, 2014

    @sbliven
    Member

    It seems that the real problem is that the two ChemCompProvider implementations are not equivalent. If the seqres problem were fixed than this wouldn't be an issue, right?

    If the difference between them is expected and desired, than we could do something similar to how SCOPFactory deals with remote vs local installations. There is a version of the getter where you can force a local installation (which has slower instantiation but faster asymptotic performance). So in places where you care about it, you can request a local instance, but most of the time you use the generic getter and use whatever was used last. Note that the results of all implementations are the same; only the performance changes.

  4. josemduarte commented on Sep 1, 2014

    @josemduarte
    ContributorAuthor

    This test demonstrates the issue. As expected, when using ReducedChemCompProvider the returned description is empty, that's fine. BUT, if provider is changed to DownloadChemCompProvider then it fails because it uses the empty value cached instead of downloading the corresponding chem comp dictionary file for MEA.

        @Test
        public void testChangingProviders(){
    
    
            String chemID = "MEA";
    
            // first we test with reduced chem comp provider 
            ChemCompGroupFactory.setChemCompProvider(new ReducedChemCompProvider());
    
            ChemComp cc = ChemCompGroupFactory.getChemComp(chemID);
    
            assertNotNull(cc);
    
            assertTrue(" is not mea" , cc.getId().equals(chemID));
    
            // an empty description is returned as expected
            assertNull(cc.getThree_letter_code());
    
    
            // now we change to download chem comp provider: it should all work but...
            DownloadChemCompProvider all = new DownloadChemCompProvider();
    
            ChemCompGroupFactory.setChemCompProvider(all);
    
            cc = ChemCompGroupFactory.getChemComp(chemID);
    
            assertNotNull(cc);
    
            assertTrue(" is not mea" , cc.getId().equals(chemID));
    
            // IT FAILS HERE!! it took the cached value and did not download the chem comp dict file        
            assertEquals("MEA",cc.getThree_letter_code());
    
        }

    One could avoid caching the empty values and it would help. But the real issue is that the state of the singleton depends on the history of what's been run before, thus resulting in unpredictable behaviour. In fact if one inverts the order of the test, then it fails in assertNull(cc.getThree_letter_code()); instead of failing in assertEquals("MEA",cc.getThree_letter_code());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and bugfixes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions