Class AbstractDensityMapProvider
java.lang.Object
org.biojava.nbio.structure.io.density.AbstractDensityMapProvider
- All Implemented Interfaces:
DensityMapProvider
- Direct Known Subclasses:
EmdbMapProvider,PdbeCcp4MapProvider,VolumeServerProvider,WwpdbMapCoefficientsProvider
Shared machinery for the concrete density map providers: cache lookup,
download with validation, size limiting and format sanity checking.
- Since:
- 7.3.0
- Author:
- Amr ALHOSSARY
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longAnything smaller than this is not a usable map. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected longdeclaredSize(URL url) TheContent-Lengtha server declares for a resource.protected voiddeleteWithSidecars(File target) Deletes a cached map along with its validation and metadata sidecars.protected FileeffectiveCacheRoot(DensityMapRequest request) The cache directory to use for a request, preferring the request's override.protected LocalPDBDirectory.FetchBehavioreffectiveFetchBehavior(DensityMapRequest request) The effective fetch behaviour for a request, preferring the request's own setting over this provider's.protected longeffectiveMaxBytes(DensityMapRequest request) The effective size limit for a request, preferring the request's own setting.protected voidenforceSizeLimit(URL url, long maxBytes, DensityMapRequest request) Refuses a download whose declared size exceeds the limit, before any of the body is transferred.longprotected booleanisCacheUsable(File target, URL url, LocalPDBDirectory.FetchBehavior behavior) Whether a cached file may be used as-is.protected booleanisPlausibleMap(File file) Checks that a file looks like the format this provider delivers.protected DensityMapResultobtain(DensityMapRequest request, URL url, File target, DensityMapKind kind, String emdbId, Double contourLevel, Double sigma) Obtains a map, serving it from the cache when the fetch behaviour permits and downloading it otherwise.protected voidreportTooLarge(URL url, long size, long maxBytes, DensityMapRequest request) Announces that a map was skipped for being too large.voidsetCacheRoot(File cacheRoot) voidsetFetchBehavior(LocalPDBDirectory.FetchBehavior fetchBehavior) voidsetMaxDownloadBytes(long maxDownloadBytes) booleansupports(DensityMapKind kind) Whether this provider can serve a given kind of map at all.protected StringThe identifier spelling to put into a URL: four characters and lower case where the entry has a short form.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.biojava.nbio.structure.io.density.DensityMapProvider
fetch, getFormat, getSource
-
Field Details
-
MIN_DENSITY_FILE_SIZE
public static final long MIN_DENSITY_FILE_SIZEAnything smaller than this is not a usable map. Density servers answer with a short body rather than an error status when they have nothing, so a size floor is a necessary part of deciding whether a download succeeded.- See Also:
-
-
Constructor Details
-
AbstractDensityMapProvider
- Parameters:
cacheRoot- the BioJava cache directory that the density directory sits in
-
-
Method Details
-
getCacheRoot
- Returns:
- the BioJava cache directory
-
setCacheRoot
- Parameters:
cacheRoot- the BioJava cache directory
-
getFetchBehavior
- Returns:
- how aggressively this provider re-fetches
-
setFetchBehavior
- Parameters:
fetchBehavior- how aggressively to re-fetch
-
getMaxDownloadBytes
public long getMaxDownloadBytes()- Returns:
- the download size limit in bytes, or 0 for no limit
-
setMaxDownloadBytes
public void setMaxDownloadBytes(long maxDownloadBytes) - Parameters:
maxDownloadBytes- the download size limit in bytes, or 0 for no limit
-
supports
Description copied from interface:DensityMapProviderWhether this provider can serve a given kind of map at all. Used to skip requests that could not possibly succeed, such as asking an X-ray map service for a cryo-EM map.- Specified by:
supportsin interfaceDensityMapProvider- Parameters:
kind- the kind of map wanted- Returns:
trueif it is worth trying
-
urlId
The identifier spelling to put into a URL: four characters and lower case where the entry has a short form.- Parameters:
pdbId- the entry- Returns:
- the identifier for use in a URL
-
effectiveFetchBehavior
The effective fetch behaviour for a request, preferring the request's own setting over this provider's.- Parameters:
request- the request- Returns:
- the behaviour to apply
-
effectiveMaxBytes
The effective size limit for a request, preferring the request's own setting.- Parameters:
request- the request- Returns:
- the limit in bytes, or 0 for no limit
-
effectiveCacheRoot
The cache directory to use for a request, preferring the request's override.- Parameters:
request- the request- Returns:
- the cache directory
-
obtain
protected DensityMapResult obtain(DensityMapRequest request, URL url, File target, DensityMapKind kind, String emdbId, Double contourLevel, Double sigma) throws IOException Obtains a map, serving it from the cache when the fetch behaviour permits and downloading it otherwise.- Parameters:
request- what was asked forurl- where to fetch fromtarget- where to cache itkind- the concrete kind of map being fetchedemdbId- the EMDB entry, if this is an EM map; otherwisenullcontourLevel- the author-recommended contour level, ornullsigma- the map RMS deviation, ornull- Returns:
- the result, or
nullif the source has nothing for this entry - Throws:
IOException- on transport failure
-
isCacheUsable
Whether a cached file may be used as-is.- Parameters:
target- the cached fileurl- where it came frombehavior- the fetch behaviour in force- Returns:
trueif the cached file should be served
-
isPlausibleMap
Checks that a file looks like the format this provider delivers. Only the CCP4/MRC formats carry a recognisable stamp; the others are accepted on size alone.- Parameters:
file- the file to check- Returns:
trueif the file is plausibly a map of this format
-
enforceSizeLimit
protected void enforceSizeLimit(URL url, long maxBytes, DensityMapRequest request) throws DensityMapTooLargeException Refuses a download whose declared size exceeds the limit, before any of the body is transferred.- Parameters:
url- the resourcemaxBytes- the limit, or 0 for no limitrequest- the request being served, used for reporting- Throws:
DensityMapTooLargeException- if the resource is too large
-
reportTooLarge
Announces that a map was skipped for being too large.This is reported through the logger and on both standard output and standard error. A user who asked for a map and silently got a coarser one from another source deserves to be told why, and a library log configuration that discards warnings should not be able to hide it.
- Parameters:
url- the resource that was skippedsize- its size in bytesmaxBytes- the limit in bytesrequest- the request being served
-
declaredSize
TheContent-Lengtha server declares for a resource.- Parameters:
url- the resource- Returns:
- the size in bytes, or a negative value if the server did not say
-
deleteWithSidecars
Deletes a cached map along with its validation and metadata sidecars.- Parameters:
target- the cached map
-