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>
26 IMPALGEBRA_BEGIN_NAMESPACE
38 for (
unsigned int i=0; i< get_dimension(); ++i) {
46 Floats ret(get_dimension());
47 for (
unsigned int i=0; i< get_dimension(); ++i) {
52 void initialize_from_box(
Ints ns,
54 Floats nuc(bb.get_dimension());
55 for (
unsigned int i=0; i< bb.get_dimension(); ++i) {
60 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
77 unsigned int get_dimension()
const {
78 return get_origin().get_dimension();
82 Floats iuc(o.get_dimension());
83 for (
unsigned int i=0; i < get_dimension(); ++i) {
84 iuc[i]=1.0/unit_cell_[i];
86 inverse_unit_cell_=
VectorD<D>(iuc.begin(), iuc.end());
90 const VectorD<D>& get_inverse_unit_cell()
const {
91 return inverse_unit_cell_;
109 boost::scoped_array<int> index(
new int[origin_.get_dimension()]);
110 for (
unsigned int i=0; i< get_dimension(); ++i ) {
111 double d = o[i] - origin_[i];
112 double fi= d*inverse_unit_cell_[i];
113 index[i]=
static_cast<int>(std::floor(fi));
118 boost::scoped_array<int> index(
new int[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 index[i]=
static_cast<int>(std::floor(fi));
124 return GridIndexD<D>(index.get(), index.get()+get_dimension());
130 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
132 get_uniform_offset(ei, .5));
134 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
136 get_uniform_offset(ei, .5));
144 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
148 get_uniform_offset(ei,
151 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
155 get_uniform_offset(ei,
160 <<
" unit cell: " << unit_cell_);
163 #if !defined(IMP_DOXYGEN)
164 typedef DefaultEmbeddingD<1> DefaultEmbedding1D;
165 typedef base::Vector<DefaultEmbedding1D> DefaultEmbedding1Ds;
168 typedef DefaultEmbeddingD<2> DefaultEmbedding2D;
169 typedef base::Vector<DefaultEmbedding2D> DefaultEmbedding2Ds;
171 typedef DefaultEmbeddingD<3> DefaultEmbedding3D;
172 typedef base::Vector<DefaultEmbedding3D> DefaultEmbedding3Ds;
174 typedef DefaultEmbeddingD<4> DefaultEmbedding4D;
175 typedef base::Vector<DefaultEmbedding4D> DefaultEmbedding4Ds;
177 typedef DefaultEmbeddingD<5> DefaultEmbedding5D;
178 typedef base::Vector<DefaultEmbedding5D> DefaultEmbedding5Ds;
180 typedef DefaultEmbeddingD<6> DefaultEmbedding6D;
181 typedef base::Vector<DefaultEmbedding6D> DefaultEmbedding6Ds;
183 typedef DefaultEmbeddingD<-1> DefaultEmbeddingKD;
184 typedef base::Vector<DefaultEmbeddingKD> DefaultEmbeddingKDs;
195 VectorD<D> get_coordinates(
const O &index)
const {
197 for (
unsigned int i=0; i< unit_cell_.get_dimension(); ++i) {
201 "Log grid axis must have positive index.");
202 ret[i]+=unit_cell_[i]*(1.0-std::pow(base_[i], index[i]))
205 ret[i]+=unit_cell_[i]*index[i];
213 Floats ret(get_dimension());
214 for (
unsigned int i=0; i< get_dimension(); ++i) {
219 void initialize_from_box(
Ints ns,
221 Floats nuc(bb.get_dimension());
222 for (
unsigned int i=0; i< bb.get_dimension(); ++i) {
227 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
235 set_unit_cell(cell, base);
252 bool bound_centers=
false) {
255 for (
unsigned int i=0; i< bases.get_dimension(); ++i) {
257 "LogEmbedding base #" << i <<
" cannot be negative",
262 /(std::pow(bases[i], counts[i])-1.0);
267 "Too large a cell side");
270 set_unit_cell(cell, bases);
275 = get_coordinates(get_uniform_offset(
GridIndexD<D>(counts), -.5));
276 VectorD<D> extents= upper_corner-lower_corner;
279 for (
unsigned int i=0; i< uc.get_dimension(); ++i) {
286 orig[i]= bb.
get_corner(0)[i]-uc[i]*(1.0-std::pow(bases[i], .5))
291 set_unit_cell(uc, bases);
299 void set_origin(
const VectorD<D> &o) {
302 const VectorD<D> get_origin()
const {
305 unsigned int get_dimension()
const {
306 return get_origin().get_dimension();
308 void set_unit_cell(
const VectorD<D> &o,
309 const VectorD<D> &base) {
313 void set_unit_cell(
const VectorD<D> &o) {
331 boost::scoped_array<int> index(
new int[origin_.get_dimension()]);
332 for (
unsigned int i=0; i< get_dimension(); ++i ) {
333 double d = o[i] - origin_[i];
335 double fi= d/unit_cell_[i];
336 double li= std::log(fi)/std::log(base_[i]);
337 index[i]=
static_cast<int>(std::floor(li));
349 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
350 return get_coordinates(get_uniform_offset(ei, .5));
352 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
353 return get_coordinates(get_uniform_offset(ei, .5));
361 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
362 return BoundingBoxD<D>(get_coordinates(ei),
363 get_coordinates(get_uniform_offset(ei,
366 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
367 return get_bounding_box(ExtendedGridIndexD<D>(ei.begin(), ei.end()));
371 <<
" base: " << base_);
377 #if !defined(IMP_DOXYGEN)
378 typedef LogEmbeddingD<1> LogEmbedding1D;
379 typedef base::Vector<LogEmbedding1D> LogEmbedding1Ds;
382 typedef LogEmbeddingD<2> LogEmbedding2D;
383 typedef base::Vector<LogEmbedding2D> LogEmbedding2Ds;
385 typedef LogEmbeddingD<3> LogEmbedding3D;
386 typedef base::Vector<LogEmbedding3D> LogEmbedding3Ds;
388 typedef LogEmbeddingD<4> LogEmbedding4D;
389 typedef base::Vector<LogEmbedding4D> LogEmbedding4Ds;
391 typedef LogEmbeddingD<5> LogEmbedding5D;
392 typedef base::Vector<LogEmbedding5D> LogEmbedding5Ds;
394 typedef LogEmbeddingD<6> LogEmbedding6D;
395 typedef base::Vector<LogEmbedding6D> LogEmbedding6Ds;
397 typedef LogEmbeddingD<-1> LogEmbeddingKD;
398 typedef base::Vector<LogEmbeddingKD> LogEmbeddingKDs;
402 IMPALGEBRA_END_NAMESPACE