9 #ifndef IMPALGEBRA_GRID_EMBEDDINGS_H
10 #define IMPALGEBRA_GRID_EMBEDDINGS_H
12 #include <IMP/algebra/algebra_config.h>
18 #include <boost/iterator/transform_iterator.hpp>
19 #include <cereal/access.hpp>
26 IMPALGEBRA_BEGIN_NAMESPACE
36 friend class cereal::access;
38 template<
class Archive>
void save(Archive &ar)
const {
39 ar(origin_, unit_cell_);
42 template<
class Archive>
void load(Archive &ar) {
43 ar(origin_, unit_cell_);
44 set_unit_cell(unit_cell_);
49 for (
unsigned int i = 0; i < get_dimension(); ++i) {
55 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
56 Floats ret(get_dimension());
57 for (
unsigned int i = 0; i < get_dimension(); ++i) {
63 Floats nuc(bb.get_dimension());
64 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
67 nuc[i] = side / ns[i];
69 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
79 void set_origin(
const VectorD<D> &o) { origin_ = o; }
80 const VectorD<D> get_origin()
const {
return origin_; }
81 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
84 Floats iuc(o.get_dimension());
85 for (
unsigned int i = 0; i < get_dimension(); ++i) {
86 iuc[i] = 1.0 / unit_cell_[i];
88 inverse_unit_cell_ =
VectorD<D>(iuc.begin(), iuc.end());
92 const VectorD<D> &get_inverse_unit_cell()
const {
return inverse_unit_cell_; }
108 origin_.get_dimension());
109 for (
unsigned int i = 0; i < get_dimension(); ++i) {
110 double d = o[i] - origin_[i];
111 double fi = d * inverse_unit_cell_[i];
112 ret.access_data().
get_data()[i] =
static_cast<int>(std::floor(fi));
118 origin_.get_dimension());
119 for (
unsigned int i = 0; i < get_dimension(); ++i) {
120 double d = o[i] - origin_[i];
121 double fi = d * inverse_unit_cell_[i];
122 ret.access_data().
get_data()[i] =
static_cast<int>(std::floor(fi));
130 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
134 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
144 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
145 return BoundingBoxD<D>(
150 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
151 return BoundingBoxD<D>(
158 <<
" unit cell: " << unit_cell_);
161 #if !defined(IMP_DOXYGEN)
162 typedef DefaultEmbeddingD<1> DefaultEmbedding1D;
163 typedef Vector<DefaultEmbedding1D> DefaultEmbedding1Ds;
165 typedef DefaultEmbeddingD<2> DefaultEmbedding2D;
166 typedef Vector<DefaultEmbedding2D> DefaultEmbedding2Ds;
168 typedef DefaultEmbeddingD<3> DefaultEmbedding3D;
169 typedef Vector<DefaultEmbedding3D> DefaultEmbedding3Ds;
171 typedef DefaultEmbeddingD<4> DefaultEmbedding4D;
172 typedef Vector<DefaultEmbedding4D> DefaultEmbedding4Ds;
174 typedef DefaultEmbeddingD<5> DefaultEmbedding5D;
175 typedef Vector<DefaultEmbedding5D> DefaultEmbedding5Ds;
177 typedef DefaultEmbeddingD<6> DefaultEmbedding6D;
178 typedef Vector<DefaultEmbedding6D> DefaultEmbedding6Ds;
180 typedef DefaultEmbeddingD<-1> DefaultEmbeddingKD;
181 typedef Vector<DefaultEmbeddingKD> DefaultEmbeddingKDs;
191 friend class cereal::access;
193 template<
class Archive>
void serialize(Archive &ar) {
194 ar(origin_, unit_cell_, base_);
198 VectorD<D> get_coordinates(
const O &index)
const {
200 for (
unsigned int i = 0; i < unit_cell_.get_dimension(); ++i) {
204 "Log grid axis must have positive index.");
205 ret[i] += unit_cell_[i] * (1.0 - std::pow(base_[i], index[i])) /
208 ret[i] += unit_cell_[i] * index[i];
214 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
215 Floats ret(get_dimension());
216 for (
unsigned int i = 0; i < get_dimension(); ++i) {
222 Floats nuc(bb.get_dimension());
223 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
226 nuc[i] = side / ns[i];
228 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
236 set_unit_cell(cell, base);
251 const Ints &counts,
bool bound_centers =
false) {
254 for (
unsigned int i = 0; i < bases.get_dimension(); ++i) {
256 "LogEmbedding base #" << i <<
" cannot be negative",
261 (std::pow(bases[i], counts[i]) - 1.0);
267 "Too large a cell side");
270 set_unit_cell(cell, bases);
275 get_uniform_offset(
GridIndexD<D>(counts.begin(), counts.end()), -.5));
276 VectorD<D> extents = upper_corner - lower_corner;
279 for (
unsigned int i = 0; i < uc.get_dimension(); ++i) {
288 uc[i] * (1.0 - std::pow(bases[i], .5)) / (1.0 - bases[i]);
292 set_unit_cell(uc, bases);
299 void set_origin(
const VectorD<D> &o) { origin_ = o; }
300 const VectorD<D> get_origin()
const {
return origin_; }
301 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
302 void set_unit_cell(
const VectorD<D> &o,
const VectorD<D> &base) {
306 void set_unit_cell(
const VectorD<D> &o) { unit_cell_ = o; }
321 origin_.get_dimension());
322 for (
unsigned int i = 0; i < get_dimension(); ++i) {
323 double d = o[i] - origin_[i];
325 double fi = d / unit_cell_[i];
326 double li = std::log(fi) / std::log(base_[i]);
327 ret.access_data().get_data()[i] =
static_cast<int>(std::floor(li));
339 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
340 return get_coordinates(get_uniform_offset(ei, .5));
342 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
343 return get_coordinates(get_uniform_offset(ei, .5));
351 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
352 return BoundingBoxD<D>(get_coordinates(ei),
353 get_coordinates(get_uniform_offset(ei, 1)));
355 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
356 return get_bounding_box(ExtendedGridIndexD<D>(ei.begin(), ei.end()));
360 <<
" base: " << base_);
363 #if !defined(IMP_DOXYGEN)
364 typedef LogEmbeddingD<1> LogEmbedding1D;
365 typedef Vector<LogEmbedding1D> LogEmbedding1Ds;
367 typedef LogEmbeddingD<2> LogEmbedding2D;
368 typedef Vector<LogEmbedding2D> LogEmbedding2Ds;
370 typedef LogEmbeddingD<3> LogEmbedding3D;
371 typedef Vector<LogEmbedding3D> LogEmbedding3Ds;
373 typedef LogEmbeddingD<4> LogEmbedding4D;
374 typedef Vector<LogEmbedding4D> LogEmbedding4Ds;
376 typedef LogEmbeddingD<5> LogEmbedding5D;
377 typedef Vector<LogEmbedding5D> LogEmbedding5Ds;
379 typedef LogEmbeddingD<6> LogEmbedding6D;
380 typedef Vector<LogEmbedding6D> LogEmbedding6Ds;
382 typedef LogEmbeddingD<-1> LogEmbeddingKD;
383 typedef Vector<LogEmbeddingKD> LogEmbeddingKDs;
386 IMPALGEBRA_END_NAMESPACE
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
VectorD< D > get_elementwise_product(const algebra::VectorD< D > &a, const algebra::VectorD< D > &b)
Return the vector that is the elementwise product of the two.
const VectorD< D > & get_corner(unsigned int i) const
For 0 return lower corner and for 1, the upper corner.
#define IMP_FAILURE(message)
A runtime failure for IMP.
A class to represent a voxel grid.
Represent a real cell in a grid (one within the bounding box)
An index in an infinite grid on space.
ExtendedGridIndexD< D > get_extended_index(const VectorD< D > &o) const
Return the index that would contain the voxel if the grid extended there.
Exception definitions and assertions.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
A Cartesian vector in D-dimensions.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
ExtendedGridIndexD< D > get_extended_index(const VectorD< D > &o) const
Return the index that would contain the voxel if the grid extended there.
const VectorD< D > & get_unit_cell() const
Return the unit cell, relative to the origin.
A bounding box in D dimensions.
A class for storing lists of IMP items.
An axis-aligned bounding box.
Helper macros for throwing and handling exceptions.
Embed a grid as an evenly spaced axis aligned grid.
const VectorD< D > & get_unit_cell() const
Return the unit cell, relative to the origin.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
const double * get_data() const
Return a pointer to the data stored.
#define IMP_ALWAYS_CHECK(condition, message, exception_name)
Throw an exception if a check fails.
An exception for an invalid value being passed to IMP.
LogEmbeddingD(const BoundingBoxD< D > &bb, const VectorD< D > &bases, const Ints &counts, bool bound_centers=false)