Package org.openmolecules.chem.conf.gen
Class RigidFragmentCache
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.concurrent.ConcurrentHashMap<java.lang.String,RigidFragmentCache.CacheEntry>
-
- org.openmolecules.chem.conf.gen.RigidFragmentCache
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.concurrent.ConcurrentMap<java.lang.String,RigidFragmentCache.CacheEntry>
,java.util.Map<java.lang.String,RigidFragmentCache.CacheEntry>
public class RigidFragmentCache extends java.util.concurrent.ConcurrentHashMap<java.lang.String,RigidFragmentCache.CacheEntry> implements java.io.Serializable
This class implements a thread-save, concurrent cache of rigid fragments' 3D-atom-coordinates. It is accessed by the RigidFragmentProvider instances, which serve RigidFragments to ConformerGenerator instances when constructing 3D-coordinates for molecules by assembling them from 3-dimensional rigid fragments and torsion tables. Typically, ConformerGenerators start with an empty cache that fills over time or with a default cache, which is prefilled with many common fragments from organic and medicinal chemistry as well as with common building block fragments.
The default cache is balanced in memory footprint and number of fragments it contains. For special purposes you may consider creating an own custom cache file using the createCacheFiles() method.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RigidFragmentCache.CacheEntry
-
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap
java.util.concurrent.ConcurrentHashMap.KeySetView<K extends java.lang.Object,V extends java.lang.Object>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
static RigidFragmentCache
createCache(java.lang.String[] inputFileNames, java.lang.String outputDirectory, int threadCount, boolean optimizeFragments, int maxCompoundsPerFile, RigidFragmentProvider rfp)
This is a helper method to generate a custom cache and optionally a set of cache files from one or more compound files.static RigidFragmentCache
createInstance(java.lang.String cacheFileName)
RigidFragmentCache.CacheEntry
get(java.lang.Object key)
static RigidFragmentCache
getDefaultInstance()
int
getHitCount()
double
getHitQuote()
int
getNonCachableCount()
int
getRequestCount()
void
increaseNonCachableCount()
void
loadCache(java.lang.String cacheFileName)
Loads pre-calculated rigid fragment coordinates from a cache file, which is either a text file created by the createCacheFiles() method, or a zip archive of the text file.void
loadDefaultCache()
This loads the default cache filevoid
resetAllCounters()
boolean
serializeCache(java.lang.String cacheFileName, int minHits)
Writes for every distinct fragment: one idcode, multiple encoded coordinate sets, multiple conformer likelihoodsboolean
writeTabDelimitedTable(java.lang.String cacheFileName)
Writes a TAB delimited text file that can be opened for debug or other purposes by DataWarrior containing idcode, idcoords, multiple conformer likelihoods-
Methods inherited from class java.util.concurrent.ConcurrentHashMap
compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, values
-
-
-
-
Method Detail
-
getDefaultInstance
public static RigidFragmentCache getDefaultInstance()
-
createInstance
public static RigidFragmentCache createInstance(java.lang.String cacheFileName)
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<java.lang.String,RigidFragmentCache.CacheEntry>
- Overrides:
clear
in classjava.util.concurrent.ConcurrentHashMap<java.lang.String,RigidFragmentCache.CacheEntry>
-
get
public RigidFragmentCache.CacheEntry get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map<java.lang.String,RigidFragmentCache.CacheEntry>
- Overrides:
get
in classjava.util.concurrent.ConcurrentHashMap<java.lang.String,RigidFragmentCache.CacheEntry>
-
getHitQuote
public double getHitQuote()
-
getHitCount
public int getHitCount()
-
getRequestCount
public int getRequestCount()
-
getNonCachableCount
public int getNonCachableCount()
-
increaseNonCachableCount
public void increaseNonCachableCount()
-
resetAllCounters
public void resetAllCounters()
-
serializeCache
public boolean serializeCache(java.lang.String cacheFileName, int minHits)
Writes for every distinct fragment: one idcode, multiple encoded coordinate sets, multiple conformer likelihoods- Parameters:
cacheFileName
-minHits
- number of hits for a cache entry to be included in the cache file
-
loadDefaultCache
public void loadDefaultCache()
This loads the default cache file
-
loadCache
public void loadCache(java.lang.String cacheFileName)
Loads pre-calculated rigid fragment coordinates from a cache file, which is either a text file created by the createCacheFiles() method, or a zip archive of the text file. This method can be called multiple times to add conformer data from multiple sources. If the method is called with a cacheFileNam, which was loaded before, then it is not loaded a second time.- Parameters:
cacheFileName
- text file or zipped text file with extension .zip
-
createCache
public static RigidFragmentCache createCache(java.lang.String[] inputFileNames, java.lang.String outputDirectory, int threadCount, boolean optimizeFragments, int maxCompoundsPerFile, RigidFragmentProvider rfp)
This is a helper method to generate a custom cache and optionally a set of cache files from one or more compound files. You may use this function to create a custom fragment cache if the default cache file used by the ConformerGenerator in not adequate for your purpose. The default file covers many common fragments in organic and medicinal chemistry and common building block fragments. However, it is limited in size. You may consider using a custom cache file in these cases:
- To achieve a maximum of speed on the expense of memory, e.g. for a cloud based service that generates conformers on request.
- If you process molecules with limited diversity, e.g. combinatorial libraries as the Enamine REAL space. Then you may use a complete cache covering every existing fragment for maximum speed.
- If you store conformer sets as fragment references and torsion tables. Then your fragment cache needs a complete cache covering every existing fragment.
This method processes all input files, locates and all rigid fragments, produces one or more distinct conformers from the fragments and creates a new cache from them. Optionally, the fragment conformers can be energy minimized using the MMFF94s+ forcefield. Then multiple cache cache export files are written: with all cache entries, with entries used at least 2,3,5, and 10 times. The numbers 1,2,3,5,10 and .txt extention will be appended to the given cache file name.- Parameters:
inputFileNames
- array of one or more input file paths (may be mixture of sdf and dwar)outputDirectory
- path to output directory ('_cache_n_.txt' will be added)threadCount
- if 1 then a single threaded approach is used; if 0 then all existing cores are usedoptimizeFragments
- whether to energy minimize fragments using MMFF94s+maxCompoundsPerFile
- if an input file contains more compounds than this, then the rest are skippedrfp
- null or custom RigidFragmentProvider if fragments shall be minimized with a different method- Returns:
- created cache or null, if an input file could not be found
-
writeTabDelimitedTable
public boolean writeTabDelimitedTable(java.lang.String cacheFileName)
Writes a TAB delimited text file that can be opened for debug or other purposes by DataWarrior containing idcode, idcoords, multiple conformer likelihoods- Parameters:
cacheFileName
-
-
-