You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ChemCompGroupFactory not respecting the ChemCompProvider if value is already cached #145
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 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.
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.
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.
@TestpublicvoidtestChangingProviders(){
StringchemID = "MEA";
// first we test with reduced chem comp provider ChemCompGroupFactory.setChemCompProvider(newReducedChemCompProvider());
ChemCompcc = ChemCompGroupFactory.getChemComp(chemID);
assertNotNull(cc);
assertTrue(" is not mea" , cc.getId().equals(chemID));
// an empty description is returned as expectedassertNull(cc.getThree_letter_code());
// now we change to download chem comp provider: it should all work but...DownloadChemCompProviderall = newDownloadChemCompProvider();
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());
Activity
josemduarte commentedon Aug 12, 2014
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.josemduarte commentedon Aug 12, 2014
BTW this is loosely related to #103 . Could this have caused that issue? or was it another problem with some singleton state resetting?
sbliven commentedon Aug 27, 2014
It seems that the real problem is that the two
ChemCompProviderimplementations 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.
josemduarte commentedon Sep 1, 2014
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.
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 inassertEquals("MEA",cc.getThree_letter_code());Better logging to debug biojava#145
Solving issue biojava#145
Solving issue #145