Class DensityMapCache
Cached files live under the BioJava cache directory (PDB_CACHE_DIR),
laid out as described in DensityCacheLayout. Typical use is simply:
DensityMapCache cache = new DensityMapCache();
DensityMapResult map = cache.getDensityMap(new PdbId("1cbs"), DensityMapKind.TWO_FO_FC);
File file = map.getFile();
Source order. Sources are tried smallest-adequate-first, because they
differ enormously in size for the same entry and the smallest is usually
perfectly adequate to look at. For 1cbs a density-server slice is roughly a
tenth the size of the equivalent pair of CCP4 files; for the cryo-EM entry
behind EMD-0262 it is a few hundred kilobytes against 106 MB. Anything
that cannot be displayed at all is tried last, and
DensityMapSource.WWPDB_MAP_COEFFICIENTS is disabled altogether by
default for that reason. Override with setSourceChain(DensityMapKind, java.util.List) or setSourceEnabled(DensityMapSource, boolean).
Failures. A source that has nothing for an entry is skipped and the next
is tried; if every source is exhausted, NoDensityMapException is thrown
carrying the reason from each one, so a caller can explain what happened.
Genuine transport failures abort the chain instead, so that a network outage is
never reported as "this entry has no density".
- Since:
- 7.3.0
- Author:
- Amr ALHOSSARY
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<DensityMapSource> Order in which sources are tried for cryo-EM entries.static final longDefault ceiling on a single download, 256 MiB.static final List<DensityMapSource> Order in which sources are tried for X-ray and neutron entries. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a cache using the standard BioJava cache directory, i.e.DensityMapCache(String cachePath) -
Method Summary
Modifier and TypeMethodDescriptionintdeleteDensityMaps(PdbId pdbId) Removes every cached density file for an entry, including the sidecars.findDensityMap(PdbId pdbId, DensityMapKind kind) AsgetDensityMap(PdbId, DensityMapKind)but returning an emptyOptionalrather than throwing when nothing is available.getCached(PdbId pdbId, DensityMapKind kind, DensityMapSource source) Looks a map up in the cache without contacting any server.getDensityMap(String id, DensityMapKind kind) Fetches a density map for a PDB or EMDB identifier.getDensityMap(DensityMapRequest request) Fetches a density map.getDensityMap(PdbId pdbId, DensityMapKind kind) Fetches a density map, using the cache where possible.getDensityMap(Structure structure, DensityMapKind kind) Fetches a density map for an already-loaded structure.getDifferenceMapPair(PdbId pdbId) Fetches both halves of the conventional X-ray pair: the 2mFo-DFc map and the mFo-DFc difference map.static DensityMapCacheA lazily created shared instance, for callers that do not want to manage one.longgetSourceChain(DensityMapKind kind) The order sources are tried in for a given kind of map.booleanisSourceEnabled(DensityMapSource source) voidregisterProvider(DensityMapProvider provider) Replaces the provider used for a source.voidsetCachePath(String cachePath) voidsetEmdbResolver(EmdbEntryResolver resolver) voidsetFetchBehavior(LocalPDBDirectory.FetchBehavior fetchBehavior) voidsetMaxDownloadBytes(long maxDownloadBytes) voidsetSourceChain(DensityMapKind kind, List<DensityMapSource> chain) Overrides the order sources are tried in.voidsetSourceEnabled(DensityMapSource source, boolean enabled) Enables or disables a source.
-
Field Details
-
DEFAULT_MAX_DOWNLOAD_BYTES
public static final long DEFAULT_MAX_DOWNLOAD_BYTESDefault ceiling on a single download, 256 MiB. Exceeding it is not an error: the chain moves on to a source that offers a smaller representation. Set to 0 to remove the limit.- See Also:
-
DEFAULT_XRAY_SOURCE_CHAIN
Order in which sources are tried for X-ray and neutron entries. -
DEFAULT_EM_SOURCE_CHAIN
Order in which sources are tried for cryo-EM entries.
-
-
Constructor Details
-
DensityMapCache
public DensityMapCache()Creates a cache using the standard BioJava cache directory, i.e.PDB_CACHE_DIRfalling back toPDB_DIR. -
DensityMapCache
- Parameters:
cachePath- the directory to cache under
-
-
Method Details
-
getInstance
A lazily created shared instance, for callers that do not want to manage one.- Returns:
- the shared cache
-
getCachePath
- Returns:
- the directory maps are cached under
-
setCachePath
- Parameters:
cachePath- the directory to cache under
-
getFetchBehavior
- Returns:
- how aggressively cached maps are re-fetched
-
setFetchBehavior
- Parameters:
fetchBehavior- how aggressively to re-fetch.LocalPDBDirectory.FetchBehavior.FETCH_REMEDIATEDbehaves asLocalPDBDirectory.FetchBehavior.FETCH_FILES: the 2011 remediation date is a coordinate-file concept with no meaning for maps.
-
getMaxDownloadBytes
public long getMaxDownloadBytes()- Returns:
- the ceiling on a single download in bytes, or 0 for no limit
-
setMaxDownloadBytes
public void setMaxDownloadBytes(long maxDownloadBytes) - Parameters:
maxDownloadBytes- the ceiling on a single download in bytes, or 0 for no limit
-
getSourceChain
The order sources are tried in for a given kind of map.- Parameters:
kind- the kind of map- Returns:
- the source order
-
setSourceChain
Overrides the order sources are tried in.- Parameters:
kind-DensityMapKind.EMto set the cryo-EM order, anything else to set the X-ray orderchain- the new order
-
isSourceEnabled
- Parameters:
source- the source- Returns:
- whether it will be tried
-
setSourceEnabled
Enables or disables a source.DensityMapSource.WWPDB_MAP_COEFFICIENTSis disabled by default because it delivers structure factors rather than a map; enable it explicitly if you want the archival form and are prepared to run a Fourier transform.- Parameters:
source- the sourceenabled- whether to try it
-
registerProvider
Replaces the provider used for a source. Mainly a testing seam, but also the way to plug in a site-local mirror.- Parameters:
provider- the provider to use
-
getEmdbResolver
- Returns:
- the resolver used to map PDB entries to EMDB entries
-
setEmdbResolver
- Parameters:
resolver- the resolver used to map PDB entries to EMDB entries
-
getDensityMap
Fetches a density map, using the cache where possible.- Parameters:
pdbId- the entrykind- the kind of map, orDensityMapKind.AUTOto take whatever the entry has- Returns:
- the map
- Throws:
NoDensityMapException- if no enabled source has a map for this entryIOException- on transport failure
-
getDensityMap
Fetches a density map for a PDB or EMDB identifier.- Parameters:
id- a PDB identifier, or an EMDB identifier such asEMD-0262kind- the kind of map wanted- Returns:
- the map
- Throws:
NoDensityMapException- if no enabled source has a map for this entryIOException- on transport failure
-
getDensityMap
Fetches a density map for an already-loaded structure.Knowing the structure lets the experimental method be read directly rather than guessed, so a cryo-EM entry goes straight to the EM sources instead of trying the X-ray ones first. No extra network request is involved.
- Parameters:
structure- the structurekind- the kind of map wanted- Returns:
- the map
- Throws:
NoDensityMapException- if no enabled source has a map for this entryIOException- on transport failure
-
getDensityMap
Fetches a density map.- Parameters:
request- what is wanted- Returns:
- the map
- Throws:
NoDensityMapException- if no enabled source has a map for this entryIOException- on transport failure
-
findDensityMap
AsgetDensityMap(PdbId, DensityMapKind)but returning an emptyOptionalrather than throwing when nothing is available. Genuine transport failures are still logged and swallowed, so use this only where "no map" and "could not reach the server" need not be told apart.- Parameters:
pdbId- the entrykind- the kind of map wanted- Returns:
- the map, if one could be obtained
-
getDifferenceMapPair
Fetches both halves of the conventional X-ray pair: the 2mFo-DFc map and the mFo-DFc difference map.- Parameters:
pdbId- the entry- Returns:
- whichever of the two could be obtained, in that order; possibly empty
-
getCached
Looks a map up in the cache without contacting any server.- Parameters:
pdbId- the entrykind- the kind of mapsource- the source it would have come from- Returns:
- the cached map, or
nullif it is not cached
-
deleteDensityMaps
Removes every cached density file for an entry, including the sidecars.- Parameters:
pdbId- the entry- Returns:
- the number of files deleted
-