Clipper
coords.h
1
4//C Copyright (C) 2000-2006 Kevin Cowtan and University of York
5//L
6//L This library is free software and is distributed under the terms
7//L and conditions of version 2.1 of the GNU Lesser General Public
8//L Licence (LGPL) with the following additional clause:
9//L
10//L `You may also combine or link a "work that uses the Library" to
11//L produce a work containing portions of the Library, and distribute
12//L that work under terms of your choice, provided that you give
13//L prominent notice with each copy of the work that the specified
14//L version of the Library is used in it, and that you include or
15//L provide public access to the complete corresponding
16//L machine-readable source code for the Library including whatever
17//L changes were used in the work. (i.e. If you make changes to the
18//L Library you must distribute those, but you do not need to
19//L distribute source or object code to those portions of the work
20//L not covered by this licence.)'
21//L
22//L Note that this clause grants an additional right and does not impose
23//L any additional restriction, and so does not affect compatibility
24//L with the GNU General Public Licence (GPL). If you wish to negotiate
25//L other terms, please contact the maintainer.
26//L
27//L You can redistribute it and/or modify the library under the terms of
28//L the GNU Lesser General Public License as published by the Free Software
29//L Foundation; either version 2.1 of the License, or (at your option) any
30//L later version.
31//L
32//L This library is distributed in the hope that it will be useful, but
33//L WITHOUT ANY WARRANTY; without even the implied warranty of
34//L MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35//L Lesser General Public License for more details.
36//L
37//L You should have received a copy of the CCP4 licence and/or GNU
38//L Lesser General Public License along with this library; if not, write
39//L to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
40//L The GNU Lesser General Public can also be obtained by writing to the
41//L Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
42//L MA 02111-1307 USA
43
44
45#ifndef CLIPPER_COORDS
46#define CLIPPER_COORDS
47
48
49#include "cell.h"
50#include "spacegroup.h"
51#include "clipper_stats.h"
52
53
54namespace clipper
55{
56 // forward definitions
57 class Grid; class Grid_sampling; class Grid_range;
58 class Coord_grid; class Coord_map;
59 class Coord_reci_frac; class Coord_reci_orth;
60 class Coord_frac; class Coord_orth;
61 class U_aniso_frac; class U_aniso_orth;
62
63
65
69 {
70 public:
71 inline Resolution() : resol(0.0) {}
72 explicit Resolution( const ftype& resol_ );
73 void init( const ftype& resol_ );
74 const ftype& limit() const;
75 ftype invresolsq_limit() const;
76 bool is_null() const;
77 private:
78 ftype resol;
79 };
80
81
83
87 {
88 public:
90 inline HKL_class() { epsilon_ = 0; allowed_ = 255; }
92 HKL_class( const Spacegroup& spgr, const HKL& hkl );
94 inline ftype epsilon() const { return ftype(epsilon_); }
96 inline ftype epsilonc() const
97 { if ( centric() ) return 2.0*ftype(epsilon_);
98 else return ftype(epsilon_); }
100 inline ftype allowed() const { return ftype(allowed_) * (Util::pi()/12.0); }
101 inline bool centric() const { return allowed_ != 255; }
102 inline bool sys_abs() const { return epsilon_ == 0; }
103 private:
104 unsigned char epsilon_, allowed_;
105 };
106
107
109
112 class RTop_orth : public RTop<>
113 {
114 public:
116 inline RTop_orth() {}
118 inline explicit RTop_orth( const RTop<>& o ) : RTop<>( o ) {}
120 inline explicit RTop_orth( const Mat33<>& r ) : RTop<>( r ) {}
122 inline RTop_orth( const Mat33<>& r, const Vec3<>& t ) : RTop<>( r, t ) {}
124 RTop_orth( const std::vector<Coord_orth>& src, const std::vector<Coord_orth>& tgt );
126 RTop_orth( const std::vector<Coord_orth>& src, const std::vector<Coord_orth>& tgt, const std::vector<ftype>& wgt );
128 template<class T> RTop_orth( const T& src, const T& tgt );
130 RTop_frac rtop_frac( const Cell& cell ) const;
132 RTop_orth inverse() const;
134 Coord_orth axis_coordinate_near( const Coord_orth& centre ) const;
138 static RTop_orth identity();
140 static RTop_orth null();
141 };
142
143
145 class HKL : public Vec3<int>
146 {
147 public:
148 inline HKL() {}
149 inline explicit HKL( const Vec3<int>& v ) :
150 Vec3<int>( v ) {}
151 inline HKL( const int& h, const int& k, const int& l ) :
152 Vec3<int>( h, k, l ) {}
153 inline const int& h() const { return (*this)[0]; }
154 inline const int& k() const { return (*this)[1]; }
155 inline const int& l() const { return (*this)[2]; }
156 inline int& h() { return (*this)[0]; }
157 inline int& k() { return (*this)[1]; }
158 inline int& l() { return (*this)[2]; }
160 inline ftype invresolsq( const Cell& cell ) const;
162 inline Coord_reci_frac coord_reci_frac() const;
164 inline Coord_reci_orth coord_reci_orth( const Cell& cell ) const;
166 inline HKL transform( const Symop& op ) const;
168 inline HKL transform( const Isymop& op ) const;
170 inline ftype sym_phase_shift( const Symop& op ) const;
171 String format() const;
172 friend inline HKL operator -(const HKL& h1)
173 { return HKL( -h1.h(), -h1.k(), -h1.l() ); }
174 friend inline HKL operator +(const HKL& h1, const HKL& h2)
175 { return HKL( h1.h()+h2.h(), h1.k()+h2.k(), h1.l()+h2.l() ); }
176 friend inline HKL operator -(const HKL& h1, const HKL& h2)
177 { return HKL( h1.h()-h2.h(), h1.k()-h2.k(), h1.l()-h2.l() ); }
178 friend inline HKL operator *(const int& s, const HKL& h1)
179 { return HKL( s*h1.h(), s*h1.k(), s*h1.l() ); }
180 friend inline HKL operator *(const Isymop& op, const HKL& h1)
181 { return HKL( h1 * op.rot() ); }
182 };
183
184
186 class Coord_reci_orth : public Vec3<>
187 {
188 public:
189 inline Coord_reci_orth() {}
190 inline explicit Coord_reci_orth( const Vec3<>& v ) :
191 Vec3<>( v ) {}
192 inline Coord_reci_orth( const ftype& xs, const ftype& ys, const ftype& zs ) : Vec3<>( xs, ys, zs ) {}
193 inline const ftype& xs() const { return (*this)[0]; }
194 inline const ftype& ys() const { return (*this)[1]; }
195 inline const ftype& zs() const { return (*this)[2]; }
197 inline ftype invresolsq() const;
199 inline Coord_reci_frac coord_reci_frac( const Cell& cell ) const;
201 inline Coord_reci_orth transform( const RTop_orth& op ) const
202 { return Coord_reci_orth( (*this) * op.rot() ); }
203 String format() const;
204 };
205
206
208 class Coord_reci_frac : public Vec3<>
209 {
210 public:
211 inline Coord_reci_frac() {}
212 inline explicit Coord_reci_frac( const Vec3<>& v ) :
213 Vec3<>( v ) {}
214 inline Coord_reci_frac( const ftype& us, const ftype& vs, const ftype& ws ) : Vec3<>( us, vs, ws ) {}
216 inline Coord_reci_frac( const HKL& hkl ) :
217 Vec3<>( ftype(hkl[0]), ftype(hkl[1]), ftype(hkl[2]) ) {}
219 inline HKL hkl() const
220 { return HKL( Util::intr(us()), Util::intr(vs()), Util::intr(ws()) ); }
222 inline ftype invresolsq( const Cell& cell ) const;
223 inline const ftype& us() const { return (*this)[0]; }
224 inline const ftype& vs() const { return (*this)[1]; }
225 inline const ftype& ws() const { return (*this)[2]; }
227 inline Coord_reci_orth coord_reci_orth( const Cell& cell ) const;
229 inline Coord_reci_frac transform( const RTop_frac& op ) const
230 { return Coord_reci_frac( (*this) * op.rot() ); }
231 String format() const;
232 };
233
234
236 class Coord_grid : public Vec3<int>
237 {
238 public:
239 inline Coord_grid() {}
241 inline explicit Coord_grid( const Vec3<int> v ) : Vec3<int>( v ) {}
243 inline Coord_grid( const int& u, const int& v, const int& w ) :
244 Vec3<int>(u,v,w) {}
246 inline Coord_grid( const Grid& g, const int& index )
247 { deindex( g, index ); }
248 inline const int& u() const { return (*this)[0]; }
249 inline const int& v() const { return (*this)[1]; }
250 inline const int& w() const { return (*this)[2]; }
251 inline int& u() { return (*this)[0]; }
252 inline int& v() { return (*this)[1]; }
253 inline int& w() { return (*this)[2]; }
254
256 inline Coord_map coord_map() const;
258 inline Coord_frac coord_frac( const Grid_sampling& g ) const;
260 inline Coord_grid transform( const Isymop& op ) const
261 { return op * (*this); }
262
264 inline Coord_grid unit( const Grid_sampling& g ) const;
265
267
268 inline const Coord_grid& next( const Grid& g );
270
271 inline const Coord_grid& next( const Grid_range& g );
273 inline bool last( const Grid& g ) const;
275 inline bool last( const Grid_range& g ) const;
277 inline int index( const Grid& g ) const;
279 inline void deindex( const Grid& g, const int& index );
280 // grid indexing operator
281 //inline int index( const Grid_range& g ) const;
282 // grid deindexing operator
283 //inline void deindex( const Grid_range& g, const int& index );
284
285 String format() const;
286 friend inline Coord_grid operator -(const Coord_grid& r1)
287 { return ( Coord_grid( -r1.u(), -r1.v(), -r1.w() ) ); }
288 friend inline Coord_grid operator +(const Coord_grid& r1, const Coord_grid& r2) { return ( Coord_grid( r1.u()+r2.u(), r1.v()+r2.v(), r1.w()+r2.w() ) ); }
289 friend inline Coord_grid operator -(const Coord_grid& r1, const Coord_grid& r2) { return ( Coord_grid( r1.u()-r2.u(), r1.v()-r2.v(), r1.w()-r2.w() ) ); }
290 friend inline Coord_grid operator *(const int& s, const Coord_grid& r1)
291 { return ( Coord_grid( s*r1.u(), s*r1.v(), s*r1.w() ) ); }
292 friend inline int operator == (const Coord_grid& r1, const Coord_grid& r2)
293 { return (r1.u()==r2.u() && r1.v()==r2.v() && r1.w()==r2.w()); }
294 friend inline int operator != (const Coord_grid& r1, const Coord_grid& r2)
295 { return (r1.u()!=r2.u() || r1.v()!=r2.v() || r1.w()!=r2.w()); }
296 friend inline Coord_grid operator *(const Isymop& op, const Coord_grid& r1)
297 { return Coord_grid( op.rot() * r1 + op.trn() ); }
298 };
299
300
302 class Coord_orth : public Vec3<>
303 {
304 public:
305 inline Coord_orth() {}
306 inline explicit Coord_orth( const Vec3<>& v ) :
307 Vec3<>( v ) {}
308 inline Coord_orth( const ftype& x, const ftype& y, const ftype& z ) :
309 Vec3<>( x, y, z ) {}
311 Coord_orth( const Coord_orth& x1, const Coord_orth& x2, const Coord_orth& x3, const ftype& length, const ftype& angle, const ftype& torsion );
312 inline const ftype& x() const { return (*this)[0]; }
313 inline const ftype& y() const { return (*this)[1]; }
314 inline const ftype& z() const { return (*this)[2]; }
316 inline ftype lengthsq() const;
318 inline Coord_frac coord_frac( const Cell& cell ) const;
320 inline Coord_orth transform( const RTop_orth& op ) const
321 { return op*(*this); }
322 String format() const;
324 static ftype length( const Coord_orth& x1, const Coord_orth& x2);
326 static ftype angle( const Coord_orth& x1, const Coord_orth& x2,
327 const Coord_orth& x3);
329 static ftype torsion( const Coord_orth& x1, const Coord_orth& x2,
330 const Coord_orth& x3, const Coord_orth& x4);
331 friend inline Coord_orth operator -(const Coord_orth& x1)
332 { return Coord_orth( -x1.x(), -x1.y(), -x1.z() ); }
333 friend inline Coord_orth operator +(const Coord_orth& x1, const Coord_orth& x2) { return Coord_orth( x1.x()+x2.x(), x1.y()+x2.y(), x1.z()+x2.z() ); }
334 friend inline Coord_orth operator -(const Coord_orth& x1, const Coord_orth& x2) { return Coord_orth( x1.x()-x2.x(), x1.y()-x2.y(), x1.z()-x2.z() ); }
335 friend inline Coord_orth operator *(const ftype& s, const Coord_orth& x1)
336 { return Coord_orth( s*x1.x(), s*x1.y(), s*x1.z() ); }
337 friend inline Coord_orth operator *(const RTop_orth& op, const Coord_orth& x1) { return Coord_orth( op.rot() * x1 + op.trn() ); }
338 };
339
340
342 class Coord_frac : public Vec3<>
343 {
344 public:
345 inline Coord_frac() {}
346 inline explicit Coord_frac( const Vec3<>& v ) :
347 Vec3<>( v ) {}
348 inline Coord_frac( const ftype& u, const ftype& v, const ftype& w ) :
349 Vec3<>( u, v, w ) {}
350 inline const ftype& u() const { return (*this)[0]; }
351 inline const ftype& v() const { return (*this)[1]; }
352 inline const ftype& w() const { return (*this)[2]; }
354 inline ftype lengthsq( const Cell& cell ) const;
356 inline Coord_orth coord_orth( const Cell& cell ) const;
358 inline Coord_map coord_map( const Grid& g ) const;
360 inline Coord_grid coord_grid( const Grid& g ) const;
362 inline Coord_frac transform( const RTop_frac& op ) const
363 { return op*(*this); }
366 { return Coord_frac(u()-rint(u()),v()-rint(v()),w()-rint(w())); }
369 { return Coord_frac(u()-floor(u()),v()-floor(v()),w()-floor(w())); }
372 { return (*this-n).lattice_copy_zero()+n; }
374 Coord_frac symmetry_copy_near(const Spacegroup& spgr, const Cell& cell, const Coord_frac& n) const;
375 String format() const;
376 friend inline Coord_frac operator -(const Coord_frac& u1)
377 { return Coord_frac( -u1.u(), -u1.v(), -u1.w() ); }
378 friend inline Coord_frac operator +(const Coord_frac& u1, const Coord_frac& u2) { return Coord_frac( u1.u()+u2.u(), u1.v()+u2.v(), u1.w()+u2.w() ); }
379 friend inline Coord_frac operator -(const Coord_frac& u1, const Coord_frac& u2) { return Coord_frac( u1.u()-u2.u(), u1.v()-u2.v(), u1.w()-u2.w() ); }
380 friend inline Coord_frac operator *(const ftype& s, const Coord_frac& u1)
381 { return Coord_frac( s*u1.u(), s*u1.v(), s*u1.w() ); }
382 friend inline Coord_frac operator *(const RTop_frac& op, const Coord_frac& x1) { return Coord_frac( op.rot() * x1 + op.trn() ); }
383 };
384
385
387 class Coord_map : public Vec3<>
388 {
389 public:
390 inline Coord_map() {}
392 inline explicit Coord_map( const Vec3<>& v ) :
393 Vec3<>( v ) {}
395 inline explicit Coord_map( const Coord_grid& c ) :
396 Vec3<>( ftype(c[0]), ftype(c[1]), ftype(c[2]) ) {}
398 inline Coord_map( const ftype& u, const ftype& v, const ftype& w ) :
399 Vec3<>( u, v, w ) {}
401 inline Coord_frac coord_frac( const Grid& g ) const;
403 inline Coord_grid coord_grid() const { return Coord_grid( Util::intr((*this)[0]), Util::intr((*this)[1]), Util::intr((*this)[2]) ); }
405 inline Coord_grid floor() const { return Coord_grid( Util::intf((*this)[0]), Util::intf((*this)[1]), Util::intf((*this)[2]) ); }
407 inline Coord_grid ceil() const { return Coord_grid( Util::intc((*this)[0]), Util::intc((*this)[1]), Util::intc((*this)[2]) ); }
408 inline const ftype& u() const { return (*this)[0]; }
409 inline const ftype& v() const { return (*this)[1]; }
410 inline const ftype& w() const { return (*this)[2]; }
411 String format() const;
412 friend inline Coord_map operator -(const Coord_map& u1)
413 { return Coord_map( -u1.u(), -u1.v(), -u1.w() ); }
414 friend inline Coord_map operator +(const Coord_map& u1, const Coord_map& u2)
415 { return Coord_map( u1.u()+u2.u(), u1.v()+u2.v(), u1.w()+u2.w() ); }
416 friend inline Coord_map operator -(const Coord_map& u1, const Coord_map& u2)
417 { return Coord_map( u1.u()-u2.u(), u1.v()-u2.v(), u1.w()-u2.w() ); }
418 friend inline Coord_map operator *(const ftype& s, const Coord_map& u1)
419 { return Coord_map( s*u1.u(), s*u1.v(), s*u1.w() ); }
420 };
421
422
424
426 class U_aniso_orth : public Mat33sym<>
427 {
428 public:
430 inline U_aniso_orth() {};
432 inline explicit U_aniso_orth( const Mat33sym<>& m ) : Mat33sym<>(m) {}
434 inline explicit U_aniso_orth( const ftype& u ) :
435 Mat33sym<>( u, u, u, 0.0, 0.0, 0.0 ) {}
437 U_aniso_orth( const ftype& u11, const ftype& u22, const ftype& u33,
438 const ftype& u12, const ftype& u13, const ftype& u23 ) :
439 Mat33sym<>( u11, u22, u33, u12, u13, u23 ) {}
441 ftype u_iso() const;
443 U_aniso_frac u_aniso_frac( const Cell& cell ) const;
445 U_aniso_orth transform( const RTop_orth& op ) const;
446 friend U_aniso_orth operator +(const U_aniso_orth& u1, const U_aniso_orth& u2) { return U_aniso_orth( u1.mat00()+u2.mat00(), u1.mat11()+u2.mat11(), u1.mat22()+u2.mat22(), u1.mat01()+u2.mat01(), u1.mat02()+u2.mat02(), u1.mat12()+u2.mat12() ); }
447 friend U_aniso_orth operator -(const U_aniso_orth& u) { return U_aniso_orth( -u.mat00(), -u.mat11(), -u.mat22(), -u.mat01(), -u.mat02(), -u.mat12() ); }
448 friend U_aniso_orth operator *(const ftype& s, const U_aniso_orth& u) { return U_aniso_orth( s*u.mat00(), s*u.mat11(), s*u.mat22(), s*u.mat01(), s*u.mat02(), s*u.mat12() ); }
449 };
450
451
453
455 class U_aniso_frac : public Mat33sym<>
456 {
457 public:
459 inline U_aniso_frac() {};
461 inline explicit U_aniso_frac( const Mat33sym<>& m ) : Mat33sym<>(m) {}
463 U_aniso_frac( const ftype& u11, const ftype& u22, const ftype& u33,
464 const ftype& u12, const ftype& u13, const ftype& u23 ) :
465 Mat33sym<>( u11, u22, u33, u12, u13, u23 ) {}
467 U_aniso_orth u_aniso_orth( const Cell& cell ) const;
469 U_aniso_frac transform( const RTop_frac& op ) const;
470 friend U_aniso_frac operator +(const U_aniso_frac& u1, const U_aniso_frac& u2) { return U_aniso_frac( u1.mat00()+u2.mat00(), u1.mat11()+u2.mat11(), u1.mat22()+u2.mat22(), u1.mat01()+u2.mat01(), u1.mat02()+u2.mat02(), u1.mat12()+u2.mat12() ); }
471 friend U_aniso_frac operator -(const U_aniso_frac& u) { return U_aniso_frac( -u.mat00(), -u.mat11(), -u.mat22(), -u.mat01(), -u.mat02(), -u.mat12() ); }
472 friend U_aniso_frac operator *(const ftype& s, const U_aniso_frac& u) { return U_aniso_frac( s*u.mat00(), s*u.mat11(), s*u.mat22(), s*u.mat01(), s*u.mat02(), s*u.mat12() ); }
473 };
474
475
477
479 class Grid : public Vec3<int>
480 {
481 public:
482 inline Grid() {}
483 inline Grid( const int& nu, const int& nv, const int& nw ) :
484 Vec3<int>( nu, nv, nw ) {}
485 inline const int& nu() const { return (*this)[0]; }
486 inline const int& nv() const { return (*this)[1]; }
487 inline const int& nw() const { return (*this)[2]; }
489 inline int size() const { return nu()*nv()*nw(); }
491 inline bool in_grid( Coord_grid g ) const { return (g.u() >= 0 && g.u() < nu() && g.v() >= 0 && g.v() < nv() && g.w() >= 0 && g.w() < nw()); }
492
494 inline int index( const Coord_grid& c ) const { return c.index(*this); }
496 inline Coord_grid deindex( const int& index ) const { return Coord_grid( *this, index ); }
497 String format() const;
498 void debug() const;
499 };
500
501
503
515 class Grid_sampling : public Grid
516 {
517 public:
519 inline Grid_sampling() : Grid(Grid(0,0,0)) {}
521 inline Grid_sampling( const int& nu, const int& nv, const int& nw ) :
522 Grid( nu, nv, nw ) {}
524 Grid_sampling( const Spacegroup& spacegroup, const Cell& cell, const Resolution& resol, const ftype rate = 1.5 );
526 void init( const Spacegroup& spacegroup, const Cell& cell, const Resolution& resol, const ftype rate = 1.5 );
527
532
534 bool is_null() const;
535
536 // inherited functions listed for documentation purposes
537 //-- const int& nu() const;
538 //-- const int& nv() const;
539 //-- const int& nw() const;
540 //-- int size() const;
541 //-- int index( const Coord_grid& c ) const;
542 //-- Coord_grid deindex( const int& index ) const;
543 //-- const String format() const;
544 };
545
546
548
553 {
554 public:
556 HKL_sampling();
558 HKL_sampling( const Cell& cell, const Resolution& resolution );
560 HKL hkl_limit() const;
562 Resolution resolution( const Cell& cell ) const;
564 inline bool in_resolution( const HKL& h ) const
565 { return ( m00*itype64(h.h()*h.h()) + m11*itype64(h.k()*h.k()) +
566 m22*itype64(h.l()*h.l()) + m01*itype64(h.h()*h.k()) +
567 m02*itype64(h.h()*h.l()) + m12*itype64(h.k()*h.l()) )
568 <= ( sqrt_limit_value*sqrt_limit_value ); }
570 bool is_null() const;
571 String format() const;
572 friend inline int operator == (const HKL_sampling& h1, const HKL_sampling& h2)
573 { return ( h1.m00==h2.m00 && h1.m11==h2.m11 && h1.m22==h2.m22 &&
574 h1.m01==h2.m01 && h1.m02==h2.m02 && h1.m12==h2.m12 ); }
575 private:
576 static itype64 sqrt_limit_value;
577 itype64 m00, m11, m22, m01, m02, m12;
578 };
579
580
582
584 class Grid_range : public Grid
585 {
586 public:
588 inline Grid_range() {}
590 Grid_range( const Coord_grid& min, const Coord_grid& max );
592 Grid_range( const Grid& grid, const Coord_frac& min, const Coord_frac& max );
594 Grid_range( const Cell& cell, const Grid& grid, const ftype& radius );
596 const Coord_grid& min() const { return min_; }
598 const Coord_grid& max() const { return max_; }
600 void add_border( const int b );
602 bool in_grid( Coord_grid g ) const { return (g.u() >= min_.u() && g.u() <= max_.u() && g.v() >= min_.v() && g.v() <= max_.v() && g.w() >= min_.w() && g.w() <= max_.w()); }
603
605 int index( const Coord_grid& c ) const { return (c - min_).index(*this); }
607 Coord_grid deindex( const int& index ) const { return Coord_grid( *this, index ) + min_; }
608 private:
609 Coord_grid min_, max_;
610 };
613
614
616
620 class Atom
621 {
622 public:
624 Atom() {}
626 template<class T> Atom( const T& atom ) : element_(atom.element()), coord_orth_(atom.coord_orth()), u_aniso_orth_(atom.u_aniso_orth()) , occupancy_(atom.occupancy()), u_iso_(atom.u_iso()){}
628 const String& element() const { return element_; }
630 const Coord_orth& coord_orth() const { return coord_orth_; }
632 const ftype& occupancy() const { return occupancy_; }
634 const ftype& u_iso() const { return u_iso_; }
636 const U_aniso_orth& u_aniso_orth() const { return u_aniso_orth_; }
637 void set_element( const String& s );
638 void set_coord_orth( const Coord_orth& s );
639 void set_occupancy( const ftype& s );
640 void set_u_iso( const ftype& s );
641 void set_u_aniso_orth( const U_aniso_orth& s );
643 void transform( const RTop_orth rt );
645 bool is_null() const { return coord_orth_.is_null(); }
647 static Atom null();
648 private:
649 String element_;
650 Coord_orth coord_orth_;
651 U_aniso_orth u_aniso_orth_;
652 ftype occupancy_, u_iso_;
653 };
654
655
657
662 class Atom_list : public std::vector<Atom>
663 {
664 public:
668 Atom_list( const std::vector<Atom>& list ) : std::vector<Atom>( list ) {}
670 template<class T> Atom_list( const T& list ) { for ( int i = 0; i < list.size(); i++ ) push_back( Atom( list[i] ) ); }
671 };
672
673
674 // some template function definitions
675
683 template<class T> RTop_orth::RTop_orth( const T& src, const T& tgt )
684 {
685 std::vector<Coord_orth> vsrc( src.size() );
686 std::vector<Coord_orth> vtgt( tgt.size() );
687 for ( int i = 0; i < src.size(); i++ ) vsrc[i] = src[i].coord_orth();
688 for ( int i = 0; i < tgt.size(); i++ ) vtgt[i] = tgt[i].coord_orth();
689 (*this) = RTop_orth( vsrc, vtgt );
690 }
691
692 // some inline function definitions
696 HKL HKL::transform( const Symop& op ) const
697 { return Coord_reci_frac(*this).transform(op).hkl(); }
701 HKL HKL::transform( const Isymop& op ) const
702 { return op*(*this); }
708 { return -Util::twopi()*( Coord_reci_frac(*this) * op.trn() ); }
709
714 { w()++; if ( w() >= g.nw() ) { w() = 0; v()++; if ( v() >= g.nv() ) { v() = 0; u()++; } } return *this; }
719 { w()++; if ( w() > g.max().w() ) { w() = g.min().w(); v()++; if ( v() > g.max().v() ) { v() = g.min().v(); u()++; } } return *this; }
723 bool Coord_grid::last( const Grid& g ) const
724 { return ( u() >= g.nu() ); }
728 bool Coord_grid::last( const Grid_range& g ) const
729 { return ( u() > g.max().u() ); }
734 int Coord_grid::index( const Grid& g ) const
735 { return ( u()*g.nv() + v() )*g.nw() + w(); }
740 void Coord_grid::deindex( const Grid& g, const int& index )
741 { u() = index/(g.nv()*g.nw()); v() = (index/g.nw()) % g.nv(); w() = (index) % g.nw(); }
742
745 { return Coord_grid( Util::mod(u(), g.nu()), Util::mod(v(), g.nv()), Util::mod(w(), g.nw()) ); }
748 { return Coord_map( *this ); }
753 { return Coord_frac( ftype(u())/ftype(g.nu()), ftype(v())/ftype(g.nv()), ftype(w())/ftype(g.nw()) ); }
754
757 ftype HKL::invresolsq( const Cell& cell ) const
758 { return cell.metric_reci().lengthsq( Coord_reci_frac( *this ) ); }
761 { return Coord_reci_frac( *this ); }
764 { return coord_reci_frac().coord_reci_orth( cell ); }
767 { return xs()*xs() + ys()*ys() + zs()*zs(); }
770 { return Coord_reci_frac( (*this) * cell.matrix_orth() ); }
773 { return cell.metric_reci().lengthsq( *this ); }
776 { return Coord_reci_orth( (*this) * cell.matrix_frac() ); }
777
780 { return x()*x()+y()*y()+z()*z(); }
783 { return Coord_frac( cell.matrix_frac() * (*this) ); }
785 ftype Coord_frac::lengthsq( const Cell& cell ) const
786 { return cell.metric_real().lengthsq( *this ); }
789 { return Coord_orth( cell.matrix_orth() * (*this) ); }
792 { return Coord_map( u()*ftype(g.nu()), v()*ftype(g.nv()), w()*ftype(g.nw()) ); }
795 { return Coord_grid( Util::intr(u()*ftype(g.nu())), Util::intr(v()*ftype(g.nv())), Util::intr(w()*ftype(g.nw())) ); }
798 { return Coord_frac( u()/ftype(g.nu()), v()/ftype(g.nv()), w()/ftype(g.nw()) ); }
799
800} // namespace clipper
801
802#endif
Atom list class.
Definition: coords.h:663
Atom_list(const T &list)
Constructor: from vector-like list of atom-like objects.
Definition: coords.h:670
Atom_list()
null constructor
Definition: coords.h:666
Atom_list(const std::vector< Atom > &list)
constructor: from std::vector<Atom>
Definition: coords.h:668
Atom class.
Definition: coords.h:621
void set_u_iso(const ftype &s)
set u_iso
Definition: coords.cpp:637
Atom()
null constructor
Definition: coords.h:624
const Coord_orth & coord_orth() const
get atom orthogonal (Angstrom) coordinate
Definition: coords.h:630
bool is_null() const
test for null atom: atom is null is coord is null
Definition: coords.h:645
void set_occupancy(const ftype &s)
set occupancy
Definition: coords.cpp:636
const ftype & occupancy() const
get atom occupancy
Definition: coords.h:632
static Atom null()
return null atom
Definition: coords.cpp:650
const String & element() const
get atom element name: e.g. "C", "N", "Zn2+"
Definition: coords.h:628
const ftype & u_iso() const
get atom orthogonal isotropic U value
Definition: coords.h:634
void set_element(const String &s)
set element
Definition: coords.cpp:634
void transform(const RTop_orth rt)
apply a rotation-translation operator (RTop) to the atom
Definition: coords.cpp:645
const U_aniso_orth & u_aniso_orth() const
get atom orthogonal anisotropic U value
Definition: coords.h:636
void set_u_aniso_orth(const U_aniso_orth &s)
set u_aniso
Definition: coords.cpp:638
void set_coord_orth(const Coord_orth &s)
set coord_orth
Definition: coords.cpp:635
Atom(const T &atom)
Constructor: from atom-like object.
Definition: coords.h:626
Cell object.
Definition: cell.h:122
const Mat33 & matrix_frac() const
return fractionalisation matrix
Definition: cell.h:161
const Metric_tensor & metric_reci() const
return reciprocal space metric tensor
Definition: cell.h:165
const Mat33 & matrix_orth() const
return orthogonalisation matrix
Definition: cell.h:159
const Metric_tensor & metric_real() const
return real space metric tensor
Definition: cell.h:163
fractional (cell) coordinates
Definition: coords.h:343
Coord_map coord_map(const Grid &g) const
fractional-grid coordinate conversion
Definition: coords.h:791
Coord_frac lattice_copy_unit() const
return lattice copy in unit box (0...1,0...1,0...1)
Definition: coords.h:368
const ftype & v() const
get v
Definition: coords.h:351
Coord_frac symmetry_copy_near(const Spacegroup &spgr, const Cell &cell, const Coord_frac &n) const
return symmetry copy near the specified coordinate
Definition: coords.cpp:331
Coord_frac lattice_copy_zero() const
return lattice copy nearest origin
Definition: coords.h:365
const ftype & w() const
get w
Definition: coords.h:352
ftype lengthsq(const Cell &cell) const
return square of length of vector in Angstroms
Definition: coords.h:785
Coord_frac()
null constructor
Definition: coords.h:345
Coord_frac transform(const RTop_frac &op) const
return transformed coordinate
Definition: coords.h:362
String format() const
return formatted String representation
Definition: coords.cpp:348
Coord_frac(const Vec3<> &v)
constructor: copy/convert
Definition: coords.h:346
Coord_orth coord_orth(const Cell &cell) const
fractional-orthogonal coordinate conversion
Definition: coords.h:788
const ftype & u() const
get u
Definition: coords.h:350
Coord_grid coord_grid(const Grid &g) const
fractional-grid coordinate conversion
Definition: coords.h:794
Coord_frac lattice_copy_near(const Coord_frac &n) const
return lattice copy near the specified coordinate
Definition: coords.h:371
Coord_frac(const ftype &u, const ftype &v, const ftype &w)
constructor: from u,v,w
Definition: coords.h:348
Grid coordinate.
Definition: coords.h:237
int index(const Grid &g) const
grid indexing operator
Definition: coords.h:734
int & w()
set w
Definition: coords.h:253
const Coord_grid & next(const Grid &g)
increment in storage order (see index())
Definition: coords.h:713
const int & v() const
get v
Definition: coords.h:249
const int & w() const
get w
Definition: coords.h:250
int & v()
set v
Definition: coords.h:252
Coord_frac coord_frac(const Grid_sampling &g) const
convert to Coord_frac using given Grid_sampling
Definition: coords.h:752
Coord_grid()
null constructor
Definition: coords.h:239
int & u()
set u
Definition: coords.h:251
Coord_grid transform(const Isymop &op) const
return transformed coordinate
Definition: coords.h:260
Coord_map coord_map() const
convert to Coord_map
Definition: coords.h:747
Coord_grid(const int &u, const int &v, const int &w)
constructor: from u,v,w
Definition: coords.h:243
bool last(const Grid &g) const
test if done in storage order (see index())
Definition: coords.h:723
void deindex(const Grid &g, const int &index)
grid deindexing operator
Definition: coords.h:740
const int & u() const
get u
Definition: coords.h:248
Coord_grid(const Vec3< int > v)
constructor: copy/convert
Definition: coords.h:241
String format() const
return formatted String representation
Definition: coords.cpp:353
Coord_grid(const Grid &g, const int &index)
constructor: from a grid and an index in that grid
Definition: coords.h:246
map coordinate: this is like Coord_grid, but non-integer
Definition: coords.h:388
String format() const
return formatted String representation
Definition: coords.cpp:358
Coord_grid ceil() const
return integer Coord_grid above this coordinate
Definition: coords.h:407
Coord_map(const Coord_grid &c)
constructor: from Coord_grid
Definition: coords.h:395
const ftype & u() const
get u
Definition: coords.h:408
const ftype & v() const
get v
Definition: coords.h:409
Coord_grid coord_grid() const
return integer Coord_grid nearest this coordinate
Definition: coords.h:403
const ftype & w() const
get w
Definition: coords.h:410
Coord_grid floor() const
return integer Coord_grid below this coordinate
Definition: coords.h:405
Coord_map(const Vec3<> &v)
constructor: copy/convert
Definition: coords.h:392
Coord_frac coord_frac(const Grid &g) const
grid-fractional coordinate conversion
Definition: coords.h:797
Coord_map()
null constructor
Definition: coords.h:390
Coord_map(const ftype &u, const ftype &v, const ftype &w)
constructor: from u,v,w
Definition: coords.h:398
orthogonal (Angstrom) coordinates
Definition: coords.h:303
static ftype length(const Coord_orth &x1, const Coord_orth &x2)
Return length of vector between two coord orths.
Definition: coords.cpp:307
Coord_orth()
null constructor
Definition: coords.h:305
ftype lengthsq() const
return square of length of vector in Angstroms
Definition: coords.h:779
const ftype & z() const
get z
Definition: coords.h:314
const ftype & y() const
get y
Definition: coords.h:313
static ftype angle(const Coord_orth &x1, const Coord_orth &x2, const Coord_orth &x3)
Return angle between three coord orths.
Definition: coords.cpp:311
Coord_orth(const ftype &x, const ftype &y, const ftype &z)
constructor: from x,y,z
Definition: coords.h:308
static ftype torsion(const Coord_orth &x1, const Coord_orth &x2, const Coord_orth &x3, const Coord_orth &x4)
Return torsion between four coord orths.
Definition: coords.cpp:316
Coord_orth transform(const RTop_orth &op) const
return transformed coordinate
Definition: coords.h:320
Coord_frac coord_frac(const Cell &cell) const
orthogonal-fractional coordinate conversion
Definition: coords.h:782
const ftype & x() const
get x
Definition: coords.h:312
Coord_orth(const Vec3<> &v)
constructor: copy/convert
Definition: coords.h:306
String format() const
return formatted String representation
Definition: coords.cpp:327
fractional reciprocal coordinate (i.e. non-integer hkl)
Definition: coords.h:209
HKL hkl() const
round to HKL
Definition: coords.h:219
Coord_reci_frac transform(const RTop_frac &op) const
return transformed coordinate
Definition: coords.h:229
const ftype & us() const
get u*
Definition: coords.h:223
ftype invresolsq(const Cell &cell) const
return inverse resolution squared for this reflection in given cell
Definition: coords.h:772
Coord_reci_frac()
null constructor
Definition: coords.h:211
const ftype & vs() const
get v*
Definition: coords.h:224
const ftype & ws() const
get w*
Definition: coords.h:225
Coord_reci_frac(const ftype &us, const ftype &vs, const ftype &ws)
constructor: from u,v,w
Definition: coords.h:214
Coord_reci_frac(const HKL &hkl)
constructor: from HKL
Definition: coords.h:216
String format() const
return formatted String representation
Definition: coords.cpp:282
Coord_reci_frac(const Vec3<> &v)
constructor: copy/convert
Definition: coords.h:212
Coord_reci_orth coord_reci_orth(const Cell &cell) const
fractional-orthogonal reciprocal space coordinate conversion
Definition: coords.h:775
orthogonal reciprocal coordinate (length of which is invresolsq)
Definition: coords.h:187
String format() const
return formatted String representation
Definition: coords.cpp:277
const ftype & zs() const
get z*
Definition: coords.h:195
const ftype & ys() const
get y*
Definition: coords.h:194
Coord_reci_orth(const Vec3<> &v)
constructor: copy/convert
Definition: coords.h:190
Coord_reci_orth()
null constructor
Definition: coords.h:189
Coord_reci_orth(const ftype &xs, const ftype &ys, const ftype &zs)
constructor: from x*,y*,z*
Definition: coords.h:192
Coord_reci_frac coord_reci_frac(const Cell &cell) const
orthogonal-fractional reciprocal space coordinate conversion
Definition: coords.h:769
Coord_reci_orth transform(const RTop_orth &op) const
return transformed coordinate
Definition: coords.h:201
ftype invresolsq() const
return inverse resolution squared for this coord
Definition: coords.h:766
const ftype & xs() const
get x*
Definition: coords.h:193
Grid range class: defines array limits for a grid.
Definition: coords.h:585
const Coord_grid & max() const
access grid limits
Definition: coords.h:598
Coord_grid deindex(const int &index) const
grid deindexing operator
Definition: coords.h:607
void add_border(const int b)
border: increase grid to include given border
Definition: coords.cpp:419
int index(const Coord_grid &c) const
grid indexing operator
Definition: coords.h:605
Grid_range()
null constructor
Definition: coords.h:588
bool in_grid(Coord_grid g) const
determine if a point is in the grid
Definition: coords.h:602
const Coord_grid & min() const
access grid limits
Definition: coords.h:596
Grid sampling of a unit cell.
Definition: coords.h:516
void init(const Spacegroup &spacegroup, const Cell &cell, const Resolution &resol, const ftype rate=1.5)
initialiser: from Spacegroup, Cell, Resolution, Shannon rate
Definition: coords.cpp:457
Grid_sampling(const int &nu, const int &nv, const int &nw)
constructor: from nu, nv, nw
Definition: coords.h:521
Grid_sampling()
null constructor
Definition: coords.h:519
bool is_null() const
test if object has been initialised
Definition: coords.cpp:532
Mat33 matrix_grid_frac() const
return matrix which converts grid to fractional coordinates
Definition: coords.cpp:510
Mat33 matrix_frac_grid() const
return matrix which converts fractional to grid coordinates
Definition: coords.cpp:522
generic grid
Definition: coords.h:480
bool in_grid(Coord_grid g) const
determine if a point is in the grid
Definition: coords.h:491
String format() const
return formatted String representation
Definition: coords.cpp:363
Coord_grid deindex(const int &index) const
grid deindexing operator
Definition: coords.h:496
Grid(const int &nu, const int &nv, const int &nw)
constructor: from nu,nv,nw
Definition: coords.h:483
int index(const Coord_grid &c) const
grid indexing operator
Definition: coords.h:494
Grid()
null constructor
Definition: coords.h:482
int size() const
return size of grid array
Definition: coords.h:489
const int & nu() const
get nu
Definition: coords.h:485
const int & nw() const
get nw
Definition: coords.h:487
const int & nv() const
get nv
Definition: coords.h:486
reflection class
Definition: coords.h:87
bool sys_abs() const
is sys abs?
Definition: coords.h:102
HKL_class()
null constructor
Definition: coords.h:90
bool centric() const
is centric?
Definition: coords.h:101
ftype epsilonc() const
get epsilon for acentric, 2x epsilon for centric
Definition: coords.h:96
ftype epsilon() const
get epsilon
Definition: coords.h:94
ftype allowed() const
get allowed phase
Definition: coords.h:100
HKL sampling of reciprocal space.
Definition: coords.h:553
bool in_resolution(const HKL &h) const
test if a reflection is within the resolution limit
Definition: coords.h:564
String format() const
return formatted String representation
Definition: coords.cpp:592
HKL hkl_limit() const
return limiting values of H, K, L
Definition: coords.cpp:560
HKL_sampling()
null constructor
Definition: coords.cpp:540
bool is_null() const
test if object has been initialised
Definition: coords.cpp:590
Resolution resolution(const Cell &cell) const
return approximate resolution given cell
Definition: coords.cpp:576
reflection 'Miller' index
Definition: coords.h:146
const int & h() const
get h
Definition: coords.h:153
HKL transform(const Symop &op) const
return transformed hkl
Definition: coords.h:696
ftype sym_phase_shift(const Symop &op) const
return symmetry phase shift for this HKL under op
Definition: coords.h:707
int & h()
set h
Definition: coords.h:156
Coord_reci_orth coord_reci_orth(const Cell &cell) const
orthogonal-fractional reciprocal space coordinate conversion
Definition: coords.h:763
ftype invresolsq(const Cell &cell) const
return inverse resolution squared for this reflection in given cell
Definition: coords.h:757
int & k()
set k
Definition: coords.h:157
int & l()
set l
Definition: coords.h:158
HKL()
null constructor
Definition: coords.h:148
const int & k() const
get k
Definition: coords.h:154
const int & l() const
get l
Definition: coords.h:155
HKL(const int &h, const int &k, const int &l)
constructor: from H,K,L
Definition: coords.h:151
String format() const
return formatted String representation
Definition: coords.cpp:272
HKL(const Vec3< int > &v)
constructor: copy/convert
Definition: coords.h:149
Coord_reci_frac coord_reci_frac() const
return fractional reciprocal coordinate (i.e. non-integer HKL)
Definition: coords.h:760
Integerised symmetry matrix.
Definition: symop.h:109
3x3-matrix class
Definition: clipper_types.h:183
Compressed form for 3x3 symmetric matrix class.
Definition: clipper_types.h:259
const T & mat01() const
element (0,1)
Definition: clipper_types.h:294
const T & mat00() const
element (0,0)
Definition: clipper_types.h:291
const T & mat11() const
element (1,1)
Definition: clipper_types.h:292
const T & mat02() const
element (0,2)
Definition: clipper_types.h:295
const T & mat12() const
element (1,2)
Definition: clipper_types.h:296
const T & mat22() const
element (2,2)
Definition: clipper_types.h:293
ftype lengthsq(const Vec3<> &v) const
apply metric to vector
Definition: cell.h:71
Fractional operator class.
Definition: symop.h:65
Orthogonal operator class.
Definition: coords.h:113
Coord_orth axis_coordinate_near(const Coord_orth &centre) const
return point on axis near the specified coordinate
Definition: coords.cpp:230
RTop_orth(const Mat33<> &r, const Vec3<> &t)
constructor: from rotation and translation
Definition: coords.h:122
RTop_orth(const Mat33<> &r)
constructor: from rotation
Definition: coords.h:120
static RTop_orth identity()
return identity operator
Definition: coords.cpp:263
RTop_orth()
null constructor
Definition: coords.h:116
RTop_frac rtop_frac(const Cell &cell) const
orthogonal-fractional conversion
Definition: coords.cpp:219
RTop_orth(const RTop<> &o)
constructor: copy/convert
Definition: coords.h:118
Coord_orth screw_translation() const
return screw translation
Definition: coords.cpp:251
static RTop_orth null()
return null (uninitialised) operator
Definition: coords.cpp:267
RTop_orth inverse() const
inverse operator
Definition: coords.cpp:225
Rotation-translation operator.
Definition: clipper_types.h:323
const Vec3< T > & trn() const
get translation
Definition: clipper_types.h:338
const Mat33< T > & rot() const
get rotation
Definition: clipper_types.h:337
Resolution in angstroms.
Definition: coords.h:69
const ftype & limit() const
get resolution limit
Definition: coords.cpp:61
bool is_null() const
test if value has been initialised
Definition: coords.cpp:69
ftype invresolsq_limit() const
get invresolsq limit
Definition: coords.cpp:65
void init(const ftype &resol_)
initialiser: from ftype
Definition: coords.cpp:57
Resolution()
null constructor
Definition: coords.h:71
Spacegroup object.
Definition: spacegroup.h:173
String extension with simple parsing methods.
Definition: clipper_types.h:65
Crystallographic symmetry operator.
Definition: symop.h:93
Anisotropic fractional atomic displacement parameters.
Definition: coords.h:456
U_aniso_frac(const ftype &u11, const ftype &u22, const ftype &u33, const ftype &u12, const ftype &u13, const ftype &u23)
constructor: from Uij
Definition: coords.h:463
U_aniso_orth u_aniso_orth(const Cell &cell) const
fractional-orthogonal conversion
Definition: coords.cpp:623
U_aniso_frac(const Mat33sym<> &m)
constructor: from Mat33sym
Definition: coords.h:461
U_aniso_frac()
null constructor
Definition: coords.h:459
U_aniso_frac transform(const RTop_frac &op) const
return transformed U_aniso
Definition: coords.cpp:628
Anisotropic orthogonal atomic displacement parameters.
Definition: coords.h:427
U_aniso_frac u_aniso_frac(const Cell &cell) const
orthogonal-fractional conversion
Definition: coords.cpp:611
U_aniso_orth transform(const RTop_orth &op) const
return transformed U_aniso
Definition: coords.cpp:616
U_aniso_orth(const ftype &u)
constructor: from isotropic U
Definition: coords.h:434
U_aniso_orth(const ftype &u11, const ftype &u22, const ftype &u33, const ftype &u12, const ftype &u13, const ftype &u23)
constructor: from Uij
Definition: coords.h:437
ftype u_iso() const
return nearest isotropic U
Definition: coords.cpp:605
U_aniso_orth()
null constructor
Definition: coords.h:430
U_aniso_orth(const Mat33sym<> &m)
constructor: from Mat33sym
Definition: coords.h:432
static int intr(const ftype &a)
Round-to-integer: int(round(a))
Definition: clipper_util.h:133
static const ftype & twopi()
2 pi
Definition: clipper_util.h:164
static int intc(const ftype &a)
Truncate-to-integer above: int(ceil(a))
Definition: clipper_util.h:131
static const ftype & pi()
pi
Definition: clipper_util.h:162
static int intf(const ftype &a)
Truncate-to-integer: int(floor(a))
Definition: clipper_util.h:129
static ftype mod(const ftype &a, const ftype &b)
Corrected mod.
Definition: clipper_util.h:136
3-vector class
Definition: clipper_types.h:106
Vec3< int > unit() const
return unit vector with same direction as this vector
Definition: clipper_types.h:123
bool is_null() const
test for null vector
Definition: clipper_types.h:130
Grid_range Grid_map
Obsolete form for Grid_range.
Definition: coords.h:612
ftype64 ftype
ftype definition for floating point representation
Definition: clipper_precision.h:58