libmolgrid C++ API Documentation
- Home
- About
- Docs Home
- Tutorials
- libmolgrid C++ API Documentation
- C++ Docs
- The
AtomIndexTypeMapper
class - The
AtomIndexTyper
class - The
AtomTyper
class - The
AtomVectorTyper
class - The
BalancedExampleRefProvider
class - The
CallbackIndexTyper
class - The
CallbackVectorTyper
class - The
CartesianGrid
class - The
CoordCache
class - The
CoordinateSet
class - The
ElementIndexTyper
class - The
Example
class - The
ExampleExtractor
class - The
ExampleProvider
class - The
ExampleProviderSettings
class - The
ExampleRef
class - The
ExampleRefProvider
class - The
FileAtomMapper
class - The
FileMappedElementTyper
class - The
FileMappedGninaTyper
class - The
GninaIndexTyper
class - The
GninaIndexTyper::info
class - The
GninaVectorTyper
class - The
Grid
class - The
GridMaker
class - The
GroupedExampleRefProvider
class - The
ManagedGrid
class - The
ManagedGridBase
class - The
MappedAtomIndexTyper
class - The
mgrid_buffer_data
class - The
NullIndexTyper
class - The
Quaternion
class - The
ReceptorStratifiedExampleRefProvider
class - The
SamplingExampleRefProvider
class - The
StringCache
class - The
SubsetAtomMapper
class - The
SubsettedElementTyper
class - The
SubsettedGninaTyper
class - The
Transform
class - The
UniformExampleRefProvider
class - The
ValueStratifiedExampleRefProfider
class
- The
- Indices and tables
C++ Docs
The AtomIndexTypeMapper
class
-
class libmolgrid::AtomIndexTypeMapper
Base class for mapping between type indices.
Subclassed by FileAtomMapper, SubsetAtomMapper
Public Functions
-
inline AtomIndexTypeMapper()
-
inline virtual ~AtomIndexTypeMapper()
-
inline virtual unsigned num_types() const
return number of mapped types, zero if unknown (no mapping)
-
inline virtual int get_new_type(unsigned origt) const
return mapped type
-
virtual std::vector<std::string> get_type_names() const = 0
return vector of string representations of types
-
inline AtomIndexTypeMapper()
The AtomIndexTyper
class
-
class libmolgrid::AtomIndexTyper : public AtomTyper
Base class for generating numerical types along with atomic radius.
Subclassed by CallbackIndexTyper, ElementIndexTyper, GninaIndexTyper, MappedAtomIndexTyper< Mapper, Typer >, NullIndexTyper, MappedAtomIndexTyper< FileAtomMapper, ElementIndexTyper >, MappedAtomIndexTyper< FileAtomMapper, GninaIndexTyper >, MappedAtomIndexTyper< SubsetAtomMapper, ElementIndexTyper >, MappedAtomIndexTyper< SubsetAtomMapper, GninaIndexTyper >
Public Functions
-
inline AtomIndexTyper()
-
inline virtual ~AtomIndexTyper()
-
virtual unsigned num_types() const = 0
return number of types
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const = 0
return type index of a along with the apprioriate index
-
virtual std::pair<int, float> get_int_type(int t) const = 0
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
virtual std::vector<std::string> get_type_names() const = 0
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
if applicable to the typer, return the standard atomic radius of each type
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline AtomIndexTyper()
The AtomTyper
class
-
class libmolgrid::AtomTyper
Base class for all atom typers.
Subclassed by AtomIndexTyper, AtomVectorTyper
Public Functions
-
inline AtomTyper()
-
inline virtual ~AtomTyper()
-
inline virtual unsigned num_types() const
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
-
inline virtual std::pair<int, float> get_int_type(int t) const
-
inline virtual std::vector<std::string> get_type_names() const
-
inline virtual bool is_vector_typer() const
-
inline AtomTyper()
The AtomVectorTyper
class
-
class libmolgrid::AtomVectorTyper : public AtomTyper
Base class for generating vector types.
Subclassed by CallbackVectorTyper, GninaVectorTyper
Public Functions
-
inline AtomVectorTyper()
-
inline virtual ~AtomVectorTyper()
-
virtual unsigned num_types() const = 0
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const final
-
virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const = 0
set vector type of atom a, return radius
-
inline virtual std::vector<float> get_vector_type_radii() const
return radii of types
-
virtual std::vector<std::string> get_type_names() const = 0
-
inline virtual bool is_vector_typer() const
-
inline virtual std::pair<int, float> get_int_type(int t) const
-
inline AtomVectorTyper()
The BalancedExampleRefProvider
class
-
class libmolgrid::BalancedExampleRefProvider : public ExampleRefProvider
sample uniformly from actives and decoys
Public Functions
-
inline BalancedExampleRefProvider()
-
inline BalancedExampleRefProvider(const ExampleProviderSettings &settings)
-
virtual void addref(const ExampleRef &ex)
-
inline virtual size_t num_labels() const
return number of labels in an example
-
virtual void setup()
-
virtual void nextref(ExampleRef &ex)
-
inline virtual unsigned size() const
-
inline unsigned num_actives() const
-
inline unsigned num_decoys() const
-
inline void next_active(ExampleRef &ex)
-
inline void next_decoy(ExampleRef &ex)
-
inline virtual size_t small_epoch_size() const
Return number of example in small epoch.
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset iterators to start.
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
Private Members
-
UniformExampleRefProvider actives
-
UniformExampleRefProvider decoys
-
size_t current = 0
-
unsigned labelpos = 0
-
inline BalancedExampleRefProvider()
The CallbackIndexTyper
class
-
class libmolgrid::CallbackIndexTyper : public AtomIndexTyper
Use user-provided callback to do typing Must provide the number of types and their names.
Public Types
-
using AtomIndexTyperFunc = std::function<std::pair<int, float>(OpenBabel::OBAtom *a)>
Public Functions
-
CallbackIndexTyper(AtomIndexTyperFunc f, unsigned ntypes, const std::vector<std::string> &names = std::vector<std::string>())
iniitalize callbacktyper, if names are not provided, numerical names will be generated
-
inline virtual unsigned num_types() const
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
if applicable to the typer, return the standard atomic radius of each type
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
Private Members
-
AtomIndexTyperFunc callback = nullptr
-
std::vector<std::string> type_names
-
const float default_radius = 1.6
-
using AtomIndexTyperFunc = std::function<std::pair<int, float>(OpenBabel::OBAtom *a)>
The CallbackVectorTyper
class
-
class libmolgrid::CallbackVectorTyper : public AtomVectorTyper
Use user-provided callback to do vector typing Must provide the number of types and their names.
Public Types
-
using AtomVectorTyperFunc = std::function<float(OpenBabel::OBAtom *a, std::vector<float>&)>
Public Functions
-
CallbackVectorTyper(AtomVectorTyperFunc f, unsigned ntypes, const std::vector<std::string> &names = std::vector<std::string>())
iniitalize callbacktyper, if names are not provided, numerical names will be generated
-
inline virtual unsigned num_types() const
return number of types
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const
set type vector and return radius for a
-
inline virtual std::vector<std::string> get_type_names() const
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const final
-
inline virtual std::vector<float> get_vector_type_radii() const
return radii of types
-
inline virtual bool is_vector_typer() const
-
inline virtual std::pair<int, float> get_int_type(int t) const
-
using AtomVectorTyperFunc = std::function<float(OpenBabel::OBAtom *a, std::vector<float>&)>
The CartesianGrid
class
-
template<class G>
class libmolgrid::CartesianGrid Wrapper around grid of type G that imposes Cartesian coordinates. Includes center and resolution and supports (eventually) interpolation.
Public Functions
-
inline CartesianGrid(const G &g, float3 c, float res)
Initialize CartesianGrid.
-
inline ~CartesianGrid()
-
inline float3 center() const
return center of grid
-
inline float resolution() const
return resolution of grid
-
inline float3 cart2grid(float x, float y, float z) const
return grid coordinates (not rounded) for Cartesian coordinates
-
inline float3 grid2cart(unsigned i, unsigned j, unsigned k) const
return Cartesian coordinates of provided grid position
-
inline CartesianGrid(const G &g, float3 c, float res)
The CoordCache
class
-
class libmolgrid::CoordCache
Load and cache molecular coordinates and atom types.
Precalculated molcache2 files are supported and are memory mapped for efficient memory usage when running multiple training runs.
Public Functions
-
inline CoordCache()
-
inline ~CoordCache()
-
void set_coords(const char *fname, CoordinateSet &coord)
Set coord to the appropriate CoordinateSet for fname.
- Parameters
fname – [in] file name, not including root directory prefix, of molecular data
coord – [out] CoordinateSet for passed molecule
-
inline size_t num_types() const
return the number of types (channels) each example will have
-
inline std::vector<std::string> get_type_names() const
Private Types
-
using MemCache = std::unordered_map<const char*, CoordinateSet>
Private Members
-
std::string data_root
-
std::string molcache
-
bool use_cache = true
-
bool addh = true
-
bool make_vector_types = false
protonate
-
boost::iostreams::mapped_file_source cache_map
convert index types to vector, will also convert to type based radii and add a dummy type
-
std::unordered_map<const char*, size_t> offsets
-
inline CoordCache()
The CoordinateSet
class
-
struct libmolgrid::CoordinateSet
A collection of typed atomic coordinates.
Types may be specified either as an index or a dense vector. Typically, only one type formated will be initialized although a vector one-hot encoding of an index type can be created.
Public Functions
-
inline CoordinateSet()
source (filename) of coordinates, if available
-
CoordinateSet(OpenBabel::OBMol *mol)
-
CoordinateSet(const std::vector<float3> &c, const std::vector<int> &t, const std::vector<float> &r, unsigned maxt)
initialize with indexed types
-
CoordinateSet(const std::vector<float3> &c, const std::vector<float> &t, const std::vector<float> &r, unsigned maxt)
-
CoordinateSet(const Grid2f &coords, const Grid1f &t, const Grid1f &radii, unsigned maxt)
initialize with indexed types using grids - data is copied into coordinate set
-
CoordinateSet(const Grid2fCUDA &coords, const Grid1fCUDA &t, const Grid1fCUDA &radii, unsigned maxt)
-
CoordinateSet(const std::vector<float3> &c, const std::vector<std::vector<float>> &t, const std::vector<float> &r)
initialize with vector types
-
CoordinateSet(const Grid2f &cr, const Grid2f &t, const Grid1f &r)
initialize with vector types using grids - data is copied into coordinate set
-
CoordinateSet(const Grid2fCUDA &cr, const Grid2fCUDA &t, const Grid1fCUDA &r)
-
CoordinateSet(const CoordinateSet &rec, const CoordinateSet &lig, bool unique_index_types = true)
create coordinate set from the merger of two coordinate sets if unique_index_types, the index types of the second are offset
-
template<bool isCUDA>
size_t copyTo(Grid<float, 2, isCUDA> &c, Grid<float, 1, isCUDA> &t, Grid<float, 1, isCUDA> &r) const Copy coordinates into provided grids. If grids are too small, copy will be truncated. If grids are too large, extra elements will not be overwritten (fill with pad characters before copying). Returns the number of coordinates copied.
-
template<bool isCUDA>
size_t copyTo(Grid<float, 2, isCUDA> &c, Grid<float, 2, isCUDA> &t, Grid<float, 1, isCUDA> &r) const Copy coordinates into provided grids. If grids are too small, copy will be truncated. If grids are too large, extra elements will not be overwritten (fill with pad characters before copying). Returns the number of coordinates copied. Vectored types are copied a row at a time so truncation/expansion happens per-atom.
-
inline bool has_indexed_types() const
return true if index types are available (or no atoms)
-
inline bool has_vector_types() const
return true if vector types are available (or no atoms)
-
void make_vector_types(bool include_dummy_type = false, const std::vector<float> &type_radii = std::vector<float>())
convert index types to vector types in-place
- Parameters
include_dummy_type – - if true will create an additional type at end (has zero radii if type radii are provided is true)
type_radii – - if provided, convert radii array to be type indexed,
-
inline unsigned num_types() const
return number of types
-
inline void set_num_types(unsigned maxt)
set number of (indexed) types
-
void sum_types(Grid<float, 1, false> &sum, bool zerofirst = true) const
compute the sum of each type class across vector types for this set, if zerofirst is false, add to existing elements of sum
-
inline unsigned size() const
number of atoms
-
float3 center() const
return mean of coordinates
-
inline void togpu(bool copy = true)
-
inline void tocpu(bool copy = true)
-
inline bool operator==(const CoordinateSet &rhs) const
-
inline CoordinateSet clone() const
return deep copy
-
void size_like(const CoordinateSet &s)
size this to have the same size as s without copying data
-
void copyInto(const CoordinateSet &src)
copy contents of src into this, attempting to avoid reallocation if possible
-
void mergeInto(const CoordinateSet &rec, const CoordinateSet &lig, bool unique_index_types = true)
merge provided sets into this, reallocating as necessary
-
void dump(std::ostream &out) const
for debugging
-
inline CoordinateSet()
The ElementIndexTyper
class
-
class libmolgrid::ElementIndexTyper : public AtomIndexTyper
Calculate element types.
There are quite a few elements, so should probably run this through an organic chem atom mapper that reduces to number of types. The type id is the atomic number. Any element with atomic number greater than or equal to the specified max is assigned type zero.
Public Functions
-
inline ElementIndexTyper(unsigned maxe = 84)
-
inline virtual ~ElementIndexTyper()
-
virtual unsigned num_types() const
return number of types
-
virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
virtual std::pair<int, float> get_int_type(int t) const
look up covalent radius of element or provide default
-
virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
virtual std::vector<float> get_type_radii() const
return atomic radius of each type, generic type is given zero radius
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline ElementIndexTyper(unsigned maxe = 84)
The Example
class
-
struct libmolgrid::Example
A single example represented by its typed coordinates and label(s)
Public Functions
-
size_t num_coordinates() const
for grouped inputs, true if not first member of group
The total number of atom across all sets
-
size_t num_types(bool unique_index_types = true) const
The maximum number of types across all sets - if unique_index_types is true, each set gets different type ids.
-
template<bool isCUDA>
void sum_types(Grid<float, 1, isCUDA> &sum, bool unique_types = true) const Accumulate sum of each type class into sum.
-
CoordinateSet merge_coordinates(unsigned start = 0, bool unique_index_types = true) const
Combine all coordinate sets into one and return it. All coordinate sets must have the same kind of typing. The result is a copy of the input coordinates.
- Parameters
start – [in] ignore coordinates sets prior to this index (default zero)
unique_indexed_types – [in] if true, different coordinate sets will have unique, non-overlapping types
-
void merge_coordinates(Grid2f &coords, Grid1f &type_index, Grid1f &radii, unsigned start = 0, bool unique_index_types = true) const
Combine all coordinate sets into one. All coordinate sets must have index typing.
- Parameters
coords – [out] combined coordinates
type_index – [out] combined types
radii – [out] combined radii
start – [in] ignore coordinates sets prior to this index (default zero)
unique_indexed_types – [in] if true, different coordinate sets will have unique, non-overlapping types
-
void merge_coordinates(std::vector<float3> &coords, std::vector<float> &type_index, std::vector<float> &radii, unsigned start = 0, bool unique_index_types = true) const
-
void merge_coordinates(Grid2f &coords, Grid2f &type_vector, Grid1f &radii, unsigned start = 0, bool unique_index_types = true) const
Combine all coordinate sets into one. All coordinate sets must have vector typing.
- Parameters
coords – [out] combined coordinates
type_index – [out] combined types
radii – [out] combined radii
start – [in] ignore coordinates sets prior to this index (default zero)
unique_indexed_types – [in] if true, different coordinate sets will have unique, non-overlapping types
-
void merge_coordinates(std::vector<float3> &coords, std::vector<std::vector<float>> &type_vector, std::vector<float> &radii, unsigned start = 0, bool unique_index_types = true) const
-
inline void togpu()
-
inline void tocpu()
-
inline void make_vector_types()
Convert coordinate sets to vector types.
-
bool has_vector_types(unsigned start = 0) const
Return true if all coord_sets >= start have vector types (or is empty)
-
bool has_index_types(unsigned start = 0) const
Return true if all coord_sets >= start have index types (or is empty)
Public Members
-
std::vector<CoordinateSet> sets
-
std::vector<float> labels
-
int group = -1
-
bool seqcont = false
Public Static Functions
-
template<bool isCUDA>
static void extract_labels(const std::vector<Example> &examples, Grid<float, 2, isCUDA> &out) Extract labels from a vector of examples, as returned by ExampleProvider.next_batch.
- Parameters
examples – [in] vector of examples
grid – [out] 2D grid (NxL)
-
template<bool isCUDA>
static void extract_label(const std::vector<Example> &examples, unsigned labelpos, Grid<float, 1, isCUDA> &out) Extract a specific label from a vector of examples, as returned by ExampleProvider.next_batch.
- Parameters
examples – [in] vector of examples
labelpos – [in] position of label
out – [out] 1D grid (N)
-
size_t num_coordinates() const
The ExampleExtractor
class
-
class libmolgrid::ExampleExtractor
Converts an ExampleRef to and Example Loads (potentially cached) data and applies atom typers to create coordinate sets. Takes care of in-memory caching (optional) and also supports memory mapped gnina cache files (incurring slight overhead on recalculation of atom types in exchange for substantially less real mem usage).
Can take multiple atom typers, in which case they are applied in order, with the last being repeated.
Public Functions
setup an extract according to settings, types and molcaches if not present, will get molcaches from settings if there, repeating ligand if necessary
-
inline virtual ~ExampleExtractor()
-
virtual void extract(const ExampleRef &ref, Example &ex)
Extract ref into ex.
-
virtual size_t num_types() const
return the number of types (channels) each example will have Note: this is only accurate if types are explicitly setup. Must provide an ExampleRef
-
virtual size_t num_types(const ExampleRef &ref) const
-
virtual std::vector<std::string> get_type_names() const
return names of types for explicitly typed examples type names are prepended by coordinate set index
Private Functions
-
size_t count_types(unsigned n) const
The ExampleProvider
class
-
class libmolgrid::ExampleProvider
Given a file of examples, provide Example classes one at a time This contains an ExampleRefProvider, which can be configured using a single settings object if so desired, and an example extractor. Note that cache_structs is true by default which will load the entirety of the dataset into memory.
An example files contains a single example on each line where an example consists of some number of numerical labels (num_labels, will be auto-detected if not specified) followed by file paths to molecular data, all space separated.
Public Functions
-
ExampleProvider(const ExampleProviderSettings &settings = ExampleProviderSettings())
Create provider using default gnina typing.
Create provider/extractor according to settings with single typer.
Create provider/extractor according to settings with two typers.
Create provider/extractor according to settings.
use provided provider
-
inline virtual ~ExampleProvider()
-
virtual void populate(const std::string &fname, int num_labels = -1)
load example file file fname and setup provider
-
virtual void populate(const std::vector<std::string> &fnames, int num_labels = -1)
load multiple example files
-
inline virtual size_t num_labels() const
return number of labels for each example (computed from first example only)
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number A small epoch occurs once every training example has been seen at MOST once. For example, when providing a balanced view of unbalanced data, a small epoch will complete once the less common class has been iterated over. Note this is the epoch of the next example to be provided, not the previous.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number A large epoch occurs once every training example has been seen at LEAST once. For example, when providing a balanced view of unbalanced data, a large epoch will complete once the more common class has been iterated over. Note this is the epoch of the next example to be provided, not the previous.
-
inline virtual size_t small_epoch_size() const
Return number of example in small epoch.
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset to beginning.
-
virtual void skip(unsigned n)
skip over the first n examples
-
inline const ExampleProviderSettings &settings() const
return settings created with
-
virtual void next_batch(std::vector<Example> &ex, unsigned batch_size = 0)
provide a batch of examples
-
inline virtual std::vector<Example> next_batch(unsigned batch_size = 0)
provide a batch of examples, unspecified or 0 batch_size uses default batch size
-
inline bool at_new_epoch()
return true if we have crossed into a new epoch (or are about to) Note that once this returns true once, it won’t again until the next epoch has been consumed.
-
inline ExampleExtractor &get_extractor()
-
inline ExampleRefProvider &get_provider()
-
inline size_t num_types() const
number of types
-
inline std::vector<std::string> get_type_names() const
names of types (requires explicit typing)
-
inline size_t size() const
return number of examples
Public Static Functions
-
static std::shared_ptr<ExampleRefProvider> createProvider(const ExampleProviderSettings &settings)
return provider as specifyed by settings
Private Members
-
std::shared_ptr<ExampleRefProvider> provider
-
ExampleExtractor extractor
-
ExampleProviderSettings init_settings
-
size_t last_epoch = 0
-
ExampleProvider(const ExampleProviderSettings &settings = ExampleProviderSettings())
The ExampleProviderSettings
class
-
struct ExampleProviderSettings
Description of how examples should be provided This provides configuration to example refs, extractors, and the provider itself as a declarative syntax.
The ExampleRef
class
The ExampleRefProvider
class
-
class libmolgrid::ExampleRefProvider
abstract class for storing training example references
Subclassed by BalancedExampleRefProvider, GroupedExampleRefProvider< Provider >, ReceptorStratifiedExampleRefProvider< Provider, K >, SamplingExampleRefProvider< Provider1, Provider2 >, UniformExampleRefProvider, ValueStratifiedExampleRefProfider< Provider >
Public Functions
-
inline ExampleRefProvider()
-
inline ExampleRefProvider(const ExampleProviderSettings &settings)
-
virtual void addref(const ExampleRef &ex) = 0
-
virtual void setup() = 0
-
virtual void nextref(ExampleRef &ex) = 0
-
virtual unsigned size() const = 0
-
inline virtual ~ExampleRefProvider()
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
virtual size_t num_labels() const = 0
return number of labels in an example
if provider has predetermined batch size
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
-
virtual size_t small_epoch_size() const = 0
Return number of example in small epoch.
-
virtual size_t large_epoch_size() const = 0
Return number of example in large epoch.
-
virtual void reset() = 0
Reset iterators to start.
-
inline ExampleRefProvider()
The FileAtomMapper
class
-
class libmolgrid::FileAtomMapper : public AtomIndexTypeMapper
Map atom types based on provided file.
Each line for the provided file specifies a single type. Types are specified using type names. This class must be provided the type names properly indexed (should match get_type_names).
Public Functions
-
FileAtomMapper(const std::string &fname, const std::vector<std::string> &type_names)
initialize from filename
-
inline FileAtomMapper(std::istream &in, const std::vector<std::string> &type_names)
initialize from stream
-
inline virtual ~FileAtomMapper()
-
inline virtual unsigned num_types() const
return number of mapped types, zero if unknown (no mapping)
-
virtual int get_new_type(unsigned origt) const
return mapped type
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types
Private Functions
-
void setup(std::istream &in)
read in map
-
FileAtomMapper(const std::string &fname, const std::vector<std::string> &type_names)
The FileMappedElementTyper
class
-
class libmolgrid::FileMappedElementTyper : public MappedAtomIndexTyper<FileAtomMapper, ElementIndexTyper>
file mapping element types, derived class for convenient initialization
Public Functions
-
inline FileMappedElementTyper(const std::string &fname, unsigned maxe = 84)
-
inline FileMappedElementTyper(const ElementIndexTyper &etyper, const std::string &fname)
-
inline FileMappedElementTyper(std::istream &i, unsigned maxe = 84)
-
inline FileMappedElementTyper(const ElementIndexTyper &etyper, std::istream &i)
-
inline virtual unsigned num_types() const
return number of types
-
virtual unsigned num_types() const = 0
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
virtual std::vector<std::string> get_type_names() const = 0
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
radii are the average of the underlying mapped types
-
inline virtual std::vector<float> get_type_radii() const
if applicable to the typer, return the standard atomic radius of each type
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline FileMappedElementTyper(const std::string &fname, unsigned maxe = 84)
The FileMappedGninaTyper
class
-
class libmolgrid::FileMappedGninaTyper : public MappedAtomIndexTyper<FileAtomMapper, GninaIndexTyper>
file mapping element types, derived class for convenient initialization
Public Functions
-
inline FileMappedGninaTyper(const std::string &fname, bool usec = false)
-
inline FileMappedGninaTyper(const GninaIndexTyper &etyper, const std::string &fname)
-
inline FileMappedGninaTyper(std::istream &i, bool usec = false)
-
inline FileMappedGninaTyper(const GninaIndexTyper &etyper, std::istream &i)
-
inline virtual unsigned num_types() const
return number of types
-
virtual unsigned num_types() const = 0
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
virtual std::vector<std::string> get_type_names() const = 0
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
radii are the average of the underlying mapped types
-
inline virtual std::vector<float> get_type_radii() const
if applicable to the typer, return the standard atomic radius of each type
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline FileMappedGninaTyper(const std::string &fname, bool usec = false)
The GninaIndexTyper
class
-
class libmolgrid::GninaIndexTyper : public AtomIndexTyper
Calculate gnina types.
These are variants of AutoDock4 types.
Public Types
-
enum type
Values:
-
enumerator Hydrogen
-
enumerator PolarHydrogen
-
enumerator AliphaticCarbonXSHydrophobe
-
enumerator AliphaticCarbonXSNonHydrophobe
-
enumerator AromaticCarbonXSHydrophobe
-
enumerator AromaticCarbonXSNonHydrophobe
-
enumerator Nitrogen
-
enumerator NitrogenXSDonor
-
enumerator NitrogenXSDonorAcceptor
-
enumerator NitrogenXSAcceptor
-
enumerator Oxygen
-
enumerator OxygenXSDonor
-
enumerator OxygenXSDonorAcceptor
-
enumerator OxygenXSAcceptor
-
enumerator Sulfur
-
enumerator SulfurAcceptor
-
enumerator Phosphorus
-
enumerator Fluorine
-
enumerator Chlorine
-
enumerator Bromine
-
enumerator Iodine
-
enumerator Magnesium
-
enumerator Manganese
-
enumerator Zinc
-
enumerator Calcium
-
enumerator Iron
-
enumerator GenericMetal
-
enumerator Boron
-
enumerator NumTypes
-
enumerator Hydrogen
Public Functions
-
inline GninaIndexTyper(bool usec = false, const info *d = default_data)
Create a gnina typer.
- Parameters
usec – [in] use the gnina determined covalent radius.
-
inline virtual ~GninaIndexTyper()
-
virtual unsigned num_types() const
return number of types
-
virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
return type index and radius of a
-
virtual std::pair<int, float> get_int_type(int t) const
basically look up the radius of the given gnina type
-
virtual std::vector<std::string> get_type_names() const
return vector of string representations of types
-
virtual std::vector<float> get_type_radii() const
return atomic radius of each type
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static std::string gnina_type_name(int t)
return name of default gnina type t
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
struct info
Information for an atom type. This includes many legacy fields.
-
enum type
The GninaIndexTyper::info
class
-
struct libmolgrid::GninaIndexTyper::info
Information for an atom type. This includes many legacy fields.
Public Members
-
type sm
-
const char *smina_name
-
const char *adname
-
unsigned anum
-
float ad_radius
-
float ad_depth
-
float ad_solvation
-
float ad_volume
-
float covalent_radius
-
float xs_radius
-
bool xs_hydrophobe
-
bool xs_donor
-
bool xs_acceptor
-
bool ad_heteroatom
-
type sm
The Grid
class
-
template<typename Dtype, std::size_t NumDims, bool isCUDA = false>
class libmolgrid::Grid A dense array of memory stored on the CPU. The memory is owned and managed external to this class. The location and size of the memory should not change during the lifetime of the grid. If isCUDA is true, data should only be accessed in kernels.
Public Types
-
using managed_t = ManagedGrid<Dtype, NumDims>
Public Functions
-
CUDA_CALLABLE_MEMBER inline const size_t *dimensions() const
dimensions along each axis
-
CUDA_CALLABLE_MEMBER inline size_t dimension(size_t i) const
dimensions along specified axis
-
CUDA_CALLABLE_MEMBER inline const size_t *offsets() const
offset for each dimension, all indexing calculations use this
-
CUDA_CALLABLE_MEMBER inline size_t offset(size_t i) const
offset for each dimension, all indexing calculations use this
-
CUDA_CALLABLE_MEMBER inline size_t size() const
number of elements in grid
-
CUDA_CALLABLE_MEMBER inline void set_buffer(Dtype *ptr)
set the underlying memory buffer - use with caution!
-
inline Grid()
Empty grid constructor.
-
template<typename ...I>
inline Grid(Dtype *const d, I... sizes) Grid constructor.
Provide pointer and dimensions specified as arguments
-
inline Grid(Dtype *const d, size_t *sizes)
Grid constructor.
Provide pointer and dimensions array specified as arguments. sizes must contain NumDims values.
-
~Grid() = default
-
CUDA_CALLABLE_MEMBER inline subgrid_t operator[](size_t i) const
Bracket indexing.
Accessing data this way will be safe (indices are checked) and convenient, but not maximally efficient (unless the compiler is really good). Use operator() for fastest (but unchecked) access or access data directly.
-
template<typename ...I>
CUDA_CALLABLE_MEMBER inline Dtype &operator()(I... indices) Initializer list indexing.
-
template<typename ...I>
CUDA_CALLABLE_MEMBER inline Dtype *address(I... indices) Return memory address of specified index.
-
template<bool destCUDA>
inline size_t copyTo(Grid<Dtype, NumDims, destCUDA> &dest) const copy contents to dest
Sizes should be the same, but will narrow as necessary. Will copy across device/host.
-
template<bool srcCUDA>
inline size_t copyFrom(const Grid<Dtype, NumDims, srcCUDA> &src) copy contents from src
Sizes should be the same, but will narrow as necessary. Will copy across device/host.
-
inline void fill_zero()
Set contents to zero.
-
using managed_t = ManagedGrid<Dtype, NumDims>
The GridMaker
class
-
class libmolgrid::GridMaker
Populates a grid with atom density values that correspond to atoms in a CoordinateSet and accumulates atomic gradients from the grid gradients. It stores state about universal grid settings. In functions that map from atomic coordinates to grids and vice versa (e.g. forward and backward), it must be passed the grid_center (which may have changed due to transformations performed directly on the atom coordinates externally to this class)
Public Functions
-
inline GridMaker(float res = 0, float d = 0, bool bin = false, bool rti = false, float rscale = 1.0, float grm = 1.0)
GridMaker contructor.
- Parameters
res – [in] resolution of grid in Angstroms
d – [in] dimension of cubic grid side in Angstroms
bin – [in] boolean indicating if binary density should be used
rti – [in] booliean indicating the radii are type indexed
rscale – [in] scaling factor to be uniformly applied to all input radii
grm – [in] gaussian radius multiplier - cutoff point for switching from Gaussian density to quadratic. If negative no quadratic component is included and gradient is truncated at this ratio (-1.5 recommended)
-
inline virtual ~GridMaker()
-
void initialize(float res, float d, bool bin = false, float rscale = 1.0, float grm = 1.0)
Initialize grid settings.
- Parameters
res – [in] resolution of grid in Angstroms
d – [in] dimension of cubic grid side in Angstroms
bin – [in] boolean indicating if binary density should be used
rscale – [in] scaling factor to be uniformly applied to all input radii
grm – [in] gaussian radius multiplier - cutoff point for switching from Gaussian density to quadratic. If negative no quadratic component is included and gradient is truncated at this ratio (-1.5 recommended)
-
inline float3 get_grid_dims() const
return spatial dimensions of grid
-
CUDA_CALLABLE_MEMBER inline float get_resolution() const
return resolution in Angstroms
-
CUDA_CALLABLE_MEMBER inline void set_resolution(float res)
set resolution in Angstroms
-
CUDA_CALLABLE_MEMBER inline float get_dimension() const
get dimension in Angstroms
-
CUDA_CALLABLE_MEMBER inline void set_dimension(float d)
set dimension in Angstroms
-
CUDA_CALLABLE_MEMBER inline unsigned get_first_dim() const
-
CUDA_CALLABLE_MEMBER inline bool get_binary() const
return if density is binary
-
CUDA_CALLABLE_MEMBER inline void set_binary(bool b)
set if density is binary
-
CUDA_CALLABLE_MEMBER inline bool get_radii_type_indexed() const
return if radius array should be indexed by type id (for vector types)
-
CUDA_CALLABLE_MEMBER inline void set_radii_type_indexed(bool b)
set if radius array should be indexed by type id, not atom
-
CUDA_CALLABLE_MEMBER inline float get_radiusmultiple() const
return multiplier of radius where density goes to zero
-
CUDA_CALLABLE_MEMBER float3 get_grid_origin(const float3 &grid_center) const
Use externally specified grid_center to determine where grid begins. Used for translating between cartesian coords and grids.
- Parameters
grid_center – [in] - center
grid – [out] bounds
-
template<typename Dtype>
inline void forward(float3 grid_center, const CoordinateSet &in, Grid<Dtype, 4, false> &out) const
-
template<typename Dtype>
inline void forward(float3 grid_center, const CoordinateSet &in, Grid<Dtype, 4, true> &out) const
-
template<typename Dtype, bool isCUDA>
void forward(const Example &in, const Transform &transform, Grid<Dtype, 4, isCUDA> &out) const
-
template<typename Dtype, bool isCUDA>
void forward(const Example &in, Grid<Dtype, 4, isCUDA> &out, float random_translation = 0.0, bool random_rotation = false, const float3 ¢er = make_float3(INFINITY, INFINITY, INFINITY)) const
-
template<typename Dtype, bool isCUDA>
inline void forward(const std::vector<Example> &in, Grid<Dtype, 5, isCUDA> &out, float random_translation = 0.0, bool random_rotation = false) const
-
template<typename Dtype>
void forward(float3 grid_center, const Grid<float, 2, false> &coords, const Grid<float, 1, false> &type_index, const Grid<float, 1, false> &radii, Grid<Dtype, 4, false> &out) const
-
template<typename Dtype>
void forward(float3 grid_center, const Grid<float, 2, true> &coords, const Grid<float, 1, true> &type_index, const Grid<float, 1, true> &radii, Grid<Dtype, 4, true> &out) const
-
template<typename Dtype>
void forward(float3 grid_center, const Grid<float, 2, false> &coords, const Grid<float, 2, false> &type_vector, const Grid<float, 1, false> &radii, Grid<Dtype, 4, false> &out) const
-
template<typename Dtype>
void forward(float3 grid_center, const Grid<float, 2, true> &coords, const Grid<float, 2, true> &type_vector, const Grid<float, 1, true> &radii, Grid<Dtype, 4, true> &out) const
-
template<typename Dtype, int N, bool isCUDA>
inline void forward(const Grid<float, 2, isCUDA> ¢ers, const Grid<float, 3, isCUDA> &coords, const Grid<float, N, isCUDA> &types, const Grid<float, 2, isCUDA> &radii, Grid<Dtype, 5, isCUDA> &out) const
-
template<typename Dtype>
inline void backward(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, false> &diff, Grid<Dtype, 2, false> &atomic_gradients, Grid<Dtype, 2, false> &type_gradients) const
-
template<typename Dtype>
inline void backward(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, false> &diff, Grid<Dtype, 2, false> &atomic_gradients) const
-
template<typename Dtype>
inline void backward(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, true> &diff, Grid<Dtype, 2, true> &atomic_gradients, Grid<Dtype, 2, true> &type_gradients) const
-
template<typename Dtype>
inline void backward(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, true> &diff, Grid<Dtype, 2, true> &atomic_gradients) const
-
template<typename Dtype>
void backward(float3 grid_center, const Grid<float, 2, false> &coords, const Grid<float, 1, false> &type_index, const Grid<float, 1, false> &radii, const Grid<Dtype, 4, false> &diff, Grid<Dtype, 2, false> &atom_gradients) const
-
template<typename Dtype>
void backward(float3 grid_center, const Grid<float, 2, true> &coords, const Grid<float, 1, true> &type_index, const Grid<float, 1, true> &radii, const Grid<Dtype, 4, true> &grid, Grid<Dtype, 2, true> &atom_gradients) const
-
template<typename Dtype>
void backward(float3 grid_center, const Grid<float, 2, false> &coords, const Grid<float, 2, false> &type_vectors, const Grid<float, 1, false> &radii, const Grid<Dtype, 4, false> &diff, Grid<Dtype, 2, false> &atom_gradients, Grid<Dtype, 2, false> &type_gradients) const
-
template<typename Dtype>
void backward(float3 grid_center, const Grid<float, 2, true> &coords, const Grid<float, 2, true> &type_vectors, const Grid<float, 1, true> &radii, const Grid<Dtype, 4, true> &grid, Grid<Dtype, 2, true> &atom_gradients, Grid<Dtype, 2, true> &type_gradients) const
-
template<typename Dtype>
void backward_gradients(float3 grid_center, const Grid<float, 2, false> &coords, const Grid<float, 2, false> &type_vectors, const Grid<float, 1, false> &radii, const Grid<Dtype, 4, false> &diff, const Grid<Dtype, 2, false> &atom_gradients, const Grid<Dtype, 2, false> &type_gradients, Grid<Dtype, 4, false> &diffdiff, Grid<Dtype, 2, false> &atom_diffdiff, Grid<Dtype, 2, false> &type_diffdiff)
-
template<typename Dtype>
void backward_gradients(float3 grid_center, const Grid<float, 2, true> &coords, const Grid<float, 2, true> &type_vectors, const Grid<float, 1, true> &radii, const Grid<Dtype, 4, true> &diff, const Grid<Dtype, 2, true> &atom_gradients, const Grid<Dtype, 2, true> &type_gradients, Grid<Dtype, 4, true> &diffdiff, Grid<Dtype, 2, true> &atom_diffdiff, Grid<Dtype, 2, true> &type_diffdiff)
-
template<typename Dtype>
inline void backward_gradients(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, false> &diff, const Grid<Dtype, 2, false> &atom_gradients, const Grid<Dtype, 2, false> &type_gradients, Grid<Dtype, 4, false> &diffdiff, Grid<Dtype, 2, false> &atom_diffdiff, Grid<Dtype, 2, false> &type_diffdiff)
-
template<typename Dtype>
inline void backward_gradients(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, true> &diff, const Grid<Dtype, 2, true> &atom_gradients, const Grid<Dtype, 2, true> &type_gradients, Grid<Dtype, 4, true> &diffdiff, Grid<Dtype, 2, true> &atom_diffdiff, Grid<Dtype, 2, true> &type_diffdiff)
-
template<typename Dtype>
inline void backward_relevance(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, false> &density, const Grid<Dtype, 4, false> &diff, Grid<Dtype, 1, false> &relevance) const
-
template<typename Dtype>
inline void backward_relevance(float3 grid_center, const CoordinateSet &in, const Grid<Dtype, 4, true> &density, const Grid<Dtype, 4, true> &diff, Grid<Dtype, 1, true> &relevance) const
-
template<typename Dtype>
void backward_relevance(float3 grid_center, const Grid<float, 2, false> &coords, const Grid<float, 1, false> &type_index, const Grid<float, 1, false> &radii, const Grid<Dtype, 4, false> &density, const Grid<Dtype, 4, false> &diff, Grid<Dtype, 1, false> &relevance) const
-
template<typename Dtype>
void backward_relevance(float3 grid_center, const Grid<float, 2, true> &coords, const Grid<float, 1, true> &type_index, const Grid<float, 1, true> &radii, const Grid<Dtype, 4, true> &density, const Grid<Dtype, 4, true> &diff, Grid<Dtype, 1, true> &relevance) const
- template<typename Dtype, bool Binary> CUDA_DEVICE_MEMBER void set_atoms (unsigned natoms, float3 grid_origin, const float3 *coords, const float *tindex, const float *radii, Dtype *out)
- template<typename Dtype, bool Binary, bool RadiiFromTypes> CUDA_DEVICE_MEMBER void set_atoms (unsigned natoms, float3 grid_origin, const float3 *coords, const float *type_vec, unsigned ntypes, const float *radii, Dtype *out)
-
template<typename Dtype>
float3 calc_atom_gradient_cpu(const float3 &grid_origin, const Grid1f &coord, const Grid<Dtype, 3, false> &diff, float radius) const
-
template<typename Dtype>
float calc_type_gradient_cpu(const float3 &grid_origin, const Grid1f &coord, const Grid<Dtype, 3, false> &diff, float radius) const
-
template<typename Dtype>
float calc_atom_relevance_cpu(const float3 &grid_origin, const Grid1f &coord, const Grid<Dtype, 3, false> &density, const Grid<Dtype, 3, false> &diff, float radius) const
-
CUDA_CALLABLE_MEMBER uint2 get_bounds_1d(const float grid_origin, float coord, float densityrad) const
-
template<bool Binary>
CUDA_CALLABLE_MEMBER float calc_point(float ax, float ay, float az, float ar, const float3 &grid_coords) const
-
CUDA_CALLABLE_MEMBER float density_grad_dist(float dist, float ar) const
-
CUDA_CALLABLE_MEMBER float type_grad_grad(float a, float x, float dist, float r)
-
CUDA_CALLABLE_MEMBER float atom_density_grad_grad(float a, float x, float dist, float r)
-
CUDA_CALLABLE_MEMBER float atom_density_grad_grad_other(float a, float x, float b, float y, float dist, float r)
-
CUDA_CALLABLE_MEMBER void accumulate_atom_gradient(float ax, float ay, float az, float x, float y, float z, float radius, float gridval, float3 &agrad) const
Friends
- template<typename Dtype> friend __global__ friend void set_atom_gradients (GridMaker G, float3 grid_center, Grid2fCUDA coords, Grid1fCUDA type_index, Grid1fCUDA radii, Grid< Dtype, 4, true > grid, Grid< Dtype, 2, true > atom_gradients)
- template<typename Dtype, bool RadiiFromTypes> friend __global__ friend void set_atom_type_gradients (GridMaker G, float3 grid_origin, Grid2fCUDA coords, Grid2fCUDA type_vector, unsigned ntypes, Grid1fCUDA radii, Grid< Dtype, 4, true > grid, Grid< Dtype, 2, true > atom_gradients, Grid< Dtype, 2, true > type_gradients)
- template<typename Dtype, bool RadiiFromTypes> friend __global__ friend void set_atom_type_grad_grad (GridMaker G, float3 grid_origin, Grid2fCUDA coords, Grid2fCUDA type_vector, unsigned ntypes, Grid1fCUDA radii, Grid< Dtype, 4, true > diff, Grid< Dtype, 2, true > atom_gradients, Grid< Dtype, 2, true > type_gradients, Grid< Dtype, 4, true > diffdiff, Grid< Dtype, 2, true > atom_diffdiff, Grid< Dtype, 2, true > type_diffdiff)
- template<typename Dtype> friend __global__ friend void set_atom_relevance (GridMaker G, float3 grid_origin, Grid2fCUDA coords, Grid1fCUDA type_index, Grid1fCUDA radii, Grid< Dtype, 4, true > densitygrid, Grid< Dtype, 4, true > diffgrid, Grid< Dtype, 1, true > relevance)
-
inline GridMaker(float res = 0, float d = 0, bool bin = false, bool rti = false, float rscale = 1.0, float grm = 1.0)
The GroupedExampleRefProvider
class
-
template<class Provider>
class libmolgrid::GroupedExampleRefProvider : public ExampleRefProvider group multiple grids into a single example For example, multiple frames of an MD simulation that will be processed by an RNN. next() returns the next frame for the next example in the batch; traversal is row-major with layout TxN. Frames are maintained in the order they are added. There is a fixed batch and time series (group) size.
The group is specified in the first column. Although labels are permitted to vary across group members, only the labels of the first frame will be used for balancing/stratification. If fewer frames are specified than the maxgroupsize, they will be padded with “none” and the labels set to NaN
Public Functions
-
inline GroupedExampleRefProvider()
-
inline GroupedExampleRefProvider(const ExampleProviderSettings &parm)
-
inline virtual void addref(const ExampleRef &ex)
-
inline virtual void setup()
-
inline virtual size_t num_labels() const
return number of labels in an example
if provider has predetermined batch size
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
inline virtual void nextref(ExampleRef &ex)
-
inline virtual unsigned size() const
-
inline virtual size_t small_epoch_size() const
Return number of example in small epoch.
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset iterators to start.
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
-
inline GroupedExampleRefProvider()
The ManagedGrid
class
-
template<typename Dtype, std::size_t NumDims>
class libmolgrid::ManagedGrid A dense grid whose memory is managed by the class.
Memory is allocated as unified memory so it can be safely accessed from either the CPU or GPU. Note that while the memory is accessible on the GPU, ManagedGrid objects should only be used directly on the host. Device code should use a Grid view of the ManagedGrid. Accessing ManagedGrid data from the host while the GPU is writing to the grid will result in undefined behavior.
If CUDA fails to allocate unified memory (presumably due to lack of GPUs), host-only memory will be used instead.
Grid is a container class of ManagedGrid instead of a base class. Explicit transformation to a Grid view is required to clearly indicate how the memory should be accessed. This can be done with cpu and gpu methods or by an explicit cast to Grid.
There are two class specialization to support bracket indexing.
Public Types
-
using subgrid_t = ManagedGrid<Dtype, NumDims - 1>
-
using base_t = ManagedGridBase<Dtype, NumDims>
Public Functions
-
ManagedGrid() = default
-
template<typename ...I, typename = typename std::enable_if<sizeof...(I) == NumDims>::type>
inline ManagedGrid(I... sizes)
-
inline subgrid_t operator[](size_t i) const
Bracket indexing.
Accessing data this way will be safe (indices are checked) and convenient, but not maximally efficient (unless the compiler is really good). Use operator() for fastest (but unchecked) access or access data directly.
-
inline ManagedGrid<Dtype, NumDims> clone() const
Return a copy of this grid.
-
using subgrid_t = ManagedGrid<Dtype, NumDims - 1>
The ManagedGridBase
class
-
template<typename Dtype, std::size_t NumDims>
class libmolgrid::ManagedGridBase ManagedGrid base class.
Public Types
Public Functions
-
inline const size_t *dimensions() const
dimensions along each axis
-
inline size_t dimension(size_t i) const
dimensions along specified axis
-
inline const size_t *offsets() const
offset for each dimension, all indexing calculations use this
-
inline size_t offset(size_t i) const
offset for each dimension, all indexing calculations use this
-
inline size_t size() const
number of elements in grid
-
inline void fill_zero()
set contents to zero
-
inline size_t copyTo(cpu_grid_t &dest) const
Copy data into dest. Should be same size, but will narrow if needed.
-
inline size_t copyTo(gpu_grid_t &dest) const
Copy data into dest. Should be same size, but will narrow if needed.
-
inline size_t copyTo(ManagedGridBase<Dtype, NumDims> &dest) const
Copy data into dest. Should be same size, but will narrow if needed.
-
inline size_t copyFrom(const cpu_grid_t &src)
Copy data from src. Should be same size, but will narrow if needed.
-
inline size_t copyFrom(const gpu_grid_t &src)
Copy data from src. Should be same size, but will narrow if needed.
-
inline size_t copyFrom(const ManagedGridBase<Dtype, NumDims> &src)
Copy data from src. Should be same size, but will narrow if needed.
-
inline size_t copyInto(size_t start, const ManagedGridBase<Dtype, NumDims> &src)
Copy data from src into this starting at start. Should be same size, but will narrow if needed.
-
template<typename ...I, typename = typename std::enable_if<sizeof...(I) == NumDims>::type>
inline ManagedGrid<Dtype, NumDims> resized(I... sizes) Return a grid in the specified shape that attempts to reuse the memory of this grid. Memory will be allocated if needed. Data will be truncated/copied as needed. DANGER! The returned grid may or may not mirror this grid depending on the shape. This function is provided so code can be optimized to avoid unnecessary allocations and should be used carefully.
-
inline const gpu_grid_t &gpu() const
Return GPU Grid view. Host code should not access the grid until the GPU code is complete.
-
inline gpu_grid_t &gpu()
-
inline const cpu_grid_t &cpu() const
Return CPU Grid view. GPU code should no longer access this memory.
-
inline cpu_grid_t &cpu()
-
inline void togpu(bool dotransfer = true) const
Transfer data to GPU.
-
inline void tocpu(bool dotransfer = true) const
Transfer data to CPU. If not dotransfer, data is not copied back.
-
inline bool ongpu() const
Return true if memory is currently on GPU.
-
inline bool oncpu() const
Return true if memory is currently on CPU.
-
inline operator cpu_grid_t() const
-
inline operator cpu_grid_t&()
-
inline operator gpu_grid_t() const
-
inline operator gpu_grid_t&()
-
inline bool operator==(const ManagedGridBase<Dtype, NumDims> &rhs) const
-
inline const size_t *dimensions() const
The MappedAtomIndexTyper
class
-
template<class Mapper, class Typer>
class libmolgrid::MappedAtomIndexTyper : public AtomIndexTyper Wrap an atom typer with a mapper.
Public Functions
-
inline virtual ~MappedAtomIndexTyper()
-
inline virtual unsigned num_types() const
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
radii are the average of the underlying mapped types
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline virtual ~MappedAtomIndexTyper()
The mgrid_buffer_data
class
-
template<typename Dtype>
struct libmolgrid::mgrid_buffer_data
The NullIndexTyper
class
-
class libmolgrid::NullIndexTyper : public AtomIndexTyper
Always return an invalid type.
Public Functions
-
inline NullIndexTyper()
-
inline virtual ~NullIndexTyper()
-
inline virtual unsigned num_types() const
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
look up covalent radius of element or provide default
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
return atomic radius of each type, generic type is given zero radius
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline NullIndexTyper()
The Quaternion
class
-
class libmolgrid::Quaternion
A CUDA friendly quaternion class. Single precision only for maximum CUDA performance.
Public Types
-
typedef float fl
Public Functions
-
__host__ __device__ inline Quaternion()
-
__host__ __device__ inline Quaternion(fl A, fl B, fl C, fl D)
Construct quaternion with real then unreal components.
-
__host__ __device__ inline Quaternion &operator*=(const fl &r)
In-place multiplication by scalar (element-wise)
-
__host__ __device__ inline Quaternion &operator/=(const fl &r)
In-place division by scalar (element-wise)
-
__host__ __device__ inline Quaternion operator/(const fl &r)
Division by scalar (element-wise)
-
__host__ __device__ inline Quaternion operator*(const Quaternion &r) const
Quaternion multiplication.
-
__host__ __device__ inline Quaternion &operator*=(const Quaternion &r)
Quaternion in-place multiplication.
-
__host__ __device__ inline bool operator==(const Quaternion &r) const
check bit level equality
-
__host__ __device__ inline Quaternion operator/(const Quaternion &r)
Quaternion divison.
-
__host__ __device__ inline Quaternion operator/=(const Quaternion &r)
Quaternion in-place divison.
-
__host__ __device__ inline Quaternion conj() const
Conjugate.
-
__host__ __device__ inline float real() const
-
__host__ __device__ inline float norm() const
The Cayley norm - the square of the Euclidean norm.
-
__host__ __device__ inline float3 rotate(fl x, fl y, fl z) const
Rotation point (x,y,z) using this quaternion.
-
__host__ __device__ inline float3 transform(fl x, fl y, fl z, float3 center, float3 translate) const
Rotate around the provided center and translate.
-
__host__ __device__ inline Quaternion inverse() const
Return inverse.
-
typedef float fl
The ReceptorStratifiedExampleRefProvider
class
-
template<class Provider, int K = 1>
class libmolgrid::ReceptorStratifiedExampleRefProvider : public ExampleRefProvider Partition examples by receptor and sample k times uniformly from each receptor with k=2 and a balanced_provider you get paired examples from each receptor.
Public Functions
-
inline ReceptorStratifiedExampleRefProvider()
-
inline ReceptorStratifiedExampleRefProvider(const ExampleProviderSettings &settings)
-
inline virtual void addref(const ExampleRef &ex)
-
inline virtual size_t num_labels() const
return number of labels in an example
if provider has predetermined batch size
-
inline virtual void setup()
-
inline virtual void nextref(ExampleRef &ex)
-
inline virtual unsigned size() const
-
inline virtual size_t small_epoch_size() const
Return number of example in small epoch.
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset iterators to start.
-
virtual void setup()
-
virtual void setup()
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
-
inline ReceptorStratifiedExampleRefProvider()
The SamplingExampleRefProvider
class
-
template<class Provider1, class Provider2>
class libmolgrid::SamplingExampleRefProvider : public ExampleRefProvider sample with some specified probability between two providers that should already be initialized
Public Functions
-
inline SamplingExampleRefProvider()
-
inline SamplingExampleRefProvider(const ExampleProviderSettings &settings, Provider1 P1, Provider2 P2, double srate)
-
inline virtual void addref(const ExampleRef &ex)
-
inline virtual void setup()
-
inline virtual size_t num_labels() const
return number of labels in an example
if provider has predetermined batch size
-
inline virtual void nextref(ExampleRef &ex)
-
inline virtual unsigned size() const
-
inline virtual size_t small_epoch_size() const
this is the expected size of the epoch
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset iterators to start.
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
-
inline SamplingExampleRefProvider()
The StringCache
class
The SubsetAtomMapper
class
-
class libmolgrid::SubsetAtomMapper : public AtomIndexTypeMapper
Map atom types onto a provided subset.
Public Functions
-
SubsetAtomMapper(const std::vector<int> &map, bool include_catchall = true, const std::vector<std::string> &old_names = std::vector<std::string>())
Indices of map are new types, values are the old types, if include_catchall is true, the last type will be the type returned for anything not in map (otherwise -1 is returned)
-
SubsetAtomMapper(const std::vector<std::vector<int>> &map, bool include_catchall = true, const std::vector<std::string> &old_names = std::vector<std::string>())
surjective mapping
-
inline virtual unsigned num_types() const
return number of mapped types, zero if unknown (no mapping)
-
virtual int get_new_type(unsigned origt) const
return mapped type
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types
-
SubsetAtomMapper(const std::vector<int> &map, bool include_catchall = true, const std::vector<std::string> &old_names = std::vector<std::string>())
The SubsettedElementTyper
class
-
class libmolgrid::SubsettedElementTyper : public MappedAtomIndexTyper<SubsetAtomMapper, ElementIndexTyper>
subsetting element types, derived class for convenient initialization
Public Functions
-
inline SubsettedElementTyper(const std::vector<int> &map, bool include_catchall = true, unsigned maxe = 84)
-
inline SubsettedElementTyper(const ElementIndexTyper &etyper, const std::vector<int> &map, bool include_catchall = true)
-
inline SubsettedElementTyper(const std::vector<std::vector<int>> &map, bool include_catchall = true, unsigned maxe = 84)
-
inline SubsettedElementTyper(const ElementIndexTyper &etyper, const std::vector<std::vector<int>> &map, bool include_catchall = true)
-
inline virtual unsigned num_types() const
return number of types
-
virtual unsigned num_types() const = 0
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
virtual std::vector<std::string> get_type_names() const = 0
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
radii are the average of the underlying mapped types
-
inline virtual std::vector<float> get_type_radii() const
if applicable to the typer, return the standard atomic radius of each type
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline SubsettedElementTyper(const std::vector<int> &map, bool include_catchall = true, unsigned maxe = 84)
The SubsettedGninaTyper
class
-
class libmolgrid::SubsettedGninaTyper : public MappedAtomIndexTyper<SubsetAtomMapper, GninaIndexTyper>
subsetting gnina types, derived class for convenient initialization
Public Functions
-
inline SubsettedGninaTyper(const std::vector<int> &map, bool include_catchall = true, bool usec = false)
-
inline SubsettedGninaTyper(const GninaIndexTyper &etyper, const std::vector<int> &map, bool include_catchall = true)
-
inline SubsettedGninaTyper(const std::vector<std::vector<int>> &map, bool include_catchall = true, bool usec = false)
-
inline SubsettedGninaTyper(const GninaIndexTyper &etyper, const std::vector<std::vector<int>> &map, bool include_catchall = true)
-
inline virtual unsigned num_types() const
return number of types
-
virtual unsigned num_types() const = 0
return number of types
-
inline virtual std::pair<int, float> get_atom_type_index(OpenBabel::OBAtom *a) const
return type index of a
-
inline virtual std::pair<int, float> get_int_type(int t) const
return type and radius given a precomputed type, the meaning of which is specific to the implementation
-
inline virtual std::vector<std::string> get_type_names() const
return vector of string representations of types this isn’t expected to be particularly efficient
-
virtual std::vector<std::string> get_type_names() const = 0
return vector of string representations of types this isn’t expected to be particularly efficient
-
inline virtual std::vector<float> get_type_radii() const
radii are the average of the underlying mapped types
-
inline virtual std::vector<float> get_type_radii() const
if applicable to the typer, return the standard atomic radius of each type
-
inline virtual float get_atom_type_vector(OpenBabel::OBAtom *a, std::vector<float> &typ) const final
-
inline virtual bool is_vector_typer() const
Public Static Functions
-
static void set_names(unsigned ntypes, std::vector<std::string> &type_names, const std::vector<std::string> &names)
-
inline SubsettedGninaTyper(const std::vector<int> &map, bool include_catchall = true, bool usec = false)
The Transform
class
-
class libmolgrid::Transform
Stateful transformation of Cartesian coordinates.
Stores a center of rotation, quaternion, and translation. Can apply transformation forward or backward, with or without translations.
Public Functions
-
inline Transform()
-
inline Transform(const Quaternion &q, float3 c = make_float3(0, 0, 0), float3 t = make_float3(0, 0, 0))
-
Transform(float3 c, float random_translate = 0.0, bool random_rotate = false)
-
template<typename Dtype>
void forward(const Grid<Dtype, 2, false> &in, Grid<Dtype, 2, false> &out, bool dotranslate = true) const
-
void forward(const CoordinateSet &in, CoordinateSet &out, bool dotranslate = true) const
-
template<typename Dtype>
__host__ void forward(const Grid<Dtype, 2, true> &in, Grid<Dtype, 2, true> &out, bool dotranslate = true) const
-
template<typename Dtype>
void backward(const Grid<Dtype, 2, false> &in, Grid<Dtype, 2, false> &out, bool dotranslate = true) const
-
template<typename Dtype>
__host__ void backward(const Grid<Dtype, 2, true> &in, Grid<Dtype, 2, true> &out, bool dotranslate = true) const
-
inline const Quaternion &get_quaternion() const
-
inline float3 get_rotation_center() const
-
inline float3 get_translation() const
-
inline void set_quaternion(const Quaternion &q)
-
inline void set_rotation_center(float3 c)
-
inline void set_translation(float3 t)
-
inline bool is_identity() const
transformation does not change inputs
Private Functions
-
inline Transform()
The UniformExampleRefProvider
class
-
class libmolgrid::UniformExampleRefProvider : public ExampleRefProvider
single array of examples, possibly shuffled or copied
Public Functions
-
inline UniformExampleRefProvider()
-
inline UniformExampleRefProvider(const ExampleProviderSettings &settings)
-
virtual void addref(const ExampleRef &ex)
-
inline virtual size_t num_labels() const
return number of labels in an example
if provider has predetermined batch size
-
virtual void setup()
-
virtual void nextref(ExampleRef &ex)
-
inline virtual unsigned size() const
-
const ExampleRef &operator[](size_t idx) const
Provide ExampleRef at position idx.
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
-
inline virtual size_t small_epoch_size() const
Return number of example in small epoch.
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset iterators to start.
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline UniformExampleRefProvider()
The ValueStratifiedExampleRefProfider
class
-
template<class Provider>
class libmolgrid::ValueStratifiedExampleRefProfider : public ExampleRefProvider Partition examples by affinity and sample uniformly from each affinity bin affinities are binned by absolute value according to molgriddataparameters.
Public Functions
-
inline ValueStratifiedExampleRefProfider()
-
inline ValueStratifiedExampleRefProfider(const ExampleProviderSettings &parm)
-
inline virtual void addref(const ExampleRef &ex)
-
inline virtual size_t num_labels() const
return number of labels in an example
if provider has predetermined batch size
-
inline virtual void setup()
-
inline virtual void nextref(ExampleRef &ex)
-
inline virtual unsigned size() const
-
inline virtual size_t small_epoch_size() const
Return number of example in small epoch.
-
inline virtual size_t large_epoch_size() const
Return number of example in large epoch.
-
inline virtual void reset()
Reset iterators to start.
-
inline virtual bool has_group() const
-
inline virtual void check_batch_size(unsigned bsize) const
has group field
-
virtual int populate(std::istream &lines, int numlabels)
read in all the example refs from lines, but does not setup
-
inline virtual size_t get_small_epoch_num() const
Return current small epoch number.
-
inline virtual size_t get_large_epoch_num() const
Return current large epoch number.
Private Functions
-
inline unsigned bin(double val) const
-
inline ValueStratifiedExampleRefProfider()