Clipper
derivs.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_DERIVS
46#define CLIPPER_DERIVS
47
48
49#include "coords.h"
50
51
52namespace clipper
53{
54 template<class T> class Grad_orth;
55 template<class T> class Grad_frac;
56 template<class T> class Grad_map;
57 template<class T> class Curv_orth;
58 template<class T> class Curv_frac;
59 template<class T> class Curv_map;
60
61
63 template<class T> class Grad_orth : public Vec3<T>
64 {
65 public:
67 explicit Grad_orth( const Vec3<T>& v ) :
68 Vec3<T>( v ) {}
69 Grad_orth( const T& dx, const T& dy, const T& dz ) :
70 Vec3<T>( dx, dy, dz ) {}
71 const T& dx() const { return (*this)[0]; }
72 const T& dy() const { return (*this)[1]; }
73 const T& dz() const { return (*this)[2]; }
75 Grad_frac<T> grad_frac( const Cell& cell ) const;
76 String format() const;
77 };
78
79
81 template<class T> class Grad_frac : public Vec3<T>
82 {
83 public:
85 explicit Grad_frac( const Vec3<T>& v ) :
86 Vec3<T>( v ) {}
87 Grad_frac( const T& du, const T& dv, const T& dw ) :
88 Vec3<T>( du, dv, dw ) {}
89 const T& du() const { return (*this)[0]; }
90 const T& dv() const { return (*this)[1]; }
91 const T& dw() const { return (*this)[2]; }
93 Grad_orth<T> grad_orth( const Cell& cell ) const;
95 Grad_map<T> grad_map( const Grid& g ) const;
96 String format() const;
97 };
98
99
101 template<class T> class Grad_map : public Vec3<T>
102 {
103 public:
105 explicit Grad_map( const Vec3<T>& v ) :
106 Vec3<T>( v ) {}
107 Grad_map( const T& du, const T& dv, const T& dw ) :
108 Vec3<T>( du, dv, dw ) {}
109 const T& du() const { return (*this)[0]; }
110 const T& dv() const { return (*this)[1]; }
111 const T& dw() const { return (*this)[2]; }
113 Grad_frac<T> grad_frac( const Grid& g ) const;
114 String format() const;
115 };
116
117
119 template<class T> class Curv_orth : public Mat33<T>
120 {
121 public:
123 explicit Curv_orth( const Mat33<T>& m ) :
124 Mat33<T>( m ) {}
126 Curv_frac<T> curv_frac( const Cell& cell ) const;
127 };
128
129
131 template<class T> class Curv_frac : public Mat33<T>
132 {
133 public:
135 explicit Curv_frac( const Mat33<T>& m ) :
136 Mat33<T>( m ) {}
138 Curv_orth<T> curv_orth( const Cell& cell ) const;
140 Curv_map<T> curv_map( const Grid& g ) const;
141 };
142
143
145 template<class T> class Curv_map : public Mat33<T>
146 {
147 public:
149 explicit Curv_map( const Mat33<T>& m ) :
150 Mat33<T>( m ) {}
152 Curv_frac<T> curv_frac( const Grid& g ) const;
153 };
154
155
156
157 // template implementations
158
163 template<class T> String Grad_orth<T>::format() const
164 { return "d/dx,d/dy,d/dz = ("+String(dx())+","+String(dy())+","+String(dz())+")"; }
165
167 template<class T> inline Grad_frac<T> Grad_orth<T>::grad_frac( const Cell& cell ) const
168 { return Grad_frac<T>( (*this) * Mat33<T>( cell.matrix_orth() ) ); }
169
170
172 template<class T> String Grad_frac<T>::format() const
173 { return "d/du,d/dv,d/dw = ("+String(du())+","+String(dv())+","+String(dw())+")"; }
174
176 template<class T> inline Grad_orth<T> Grad_frac<T>::grad_orth( const Cell& cell ) const
177 { return Grad_orth<T>( (*this) * Mat33<T>( cell.matrix_frac() ) ); }
178
180 template<class T> inline Grad_map<T> Grad_frac<T>::grad_map( const Grid& g ) const
181 { return Grad_map<T>( du()/g.nu(), dv()/g.nv(), dw()/g.nw() ); }
182
183
185 template<class T> String Grad_map<T>::format() const
186 { return "d/du,d/dv,d/dw = ("+String(du())+","+String(dv())+","+String(dw())+")"; }
187
189 template<class T> inline Grad_frac<T> Grad_map<T>::grad_frac( const Grid& g ) const
190 { return Grad_frac<T>( du()*g.nu(), dv()*g.nv(), dw()*g.nw() ); }
191
192
194 template<class T> Curv_frac<T> Curv_orth<T>::curv_frac( const Cell& cell ) const
195 {
196 Mat33<T> m( cell.matrix_orth() );
197 return Curv_frac<T>( m.transpose() * (*this) * m );
198 }
199
200
202 template<class T> Curv_orth<T> Curv_frac<T>::curv_orth( const Cell& cell ) const
203 {
204 Mat33<T> m( cell.matrix_frac() );
205 return Curv_orth<T>( m.transpose() * (*this) * m );
206 }
207
209 template<class T> Curv_map<T> Curv_frac<T>::curv_map( const Grid& g ) const
210 {
211 Curv_map<T> c;
212 c(0,0) = (*this)(0,0) / T(g.nu()*g.nu());
213 c(0,1) = (*this)(0,1) / T(g.nu()*g.nv());
214 c(0,2) = (*this)(0,2) / T(g.nu()*g.nw());
215 c(1,0) = (*this)(1,0) / T(g.nv()*g.nu());
216 c(1,1) = (*this)(1,1) / T(g.nv()*g.nv());
217 c(1,2) = (*this)(1,2) / T(g.nv()*g.nw());
218 c(2,0) = (*this)(2,0) / T(g.nw()*g.nu());
219 c(2,1) = (*this)(2,1) / T(g.nw()*g.nv());
220 c(2,2) = (*this)(2,2) / T(g.nw()*g.nw());
221 return c;
222 }
223
224
226 template<class T> Curv_frac<T> Curv_map<T>::curv_frac( const Grid& g ) const
227 {
228 Curv_frac<T> c;
229 c(0,0) = (*this)(0,0) * T(g.nu()*g.nu());
230 c(0,1) = (*this)(0,1) * T(g.nu()*g.nv());
231 c(0,2) = (*this)(0,2) * T(g.nu()*g.nw());
232 c(1,0) = (*this)(1,0) * T(g.nv()*g.nu());
233 c(1,1) = (*this)(1,1) * T(g.nv()*g.nv());
234 c(1,2) = (*this)(1,2) * T(g.nv()*g.nw());
235 c(2,0) = (*this)(2,0) * T(g.nw()*g.nu());
236 c(2,1) = (*this)(2,1) * T(g.nw()*g.nv());
237 c(2,2) = (*this)(2,2) * T(g.nw()*g.nw());
238 return c;
239 }
240
241
242} // namespace clipper
243
244#endif
Cell object.
Definition: cell.h:122
const Mat33 & matrix_frac() const
return fractionalisation matrix
Definition: cell.h:161
const Mat33 & matrix_orth() const
return orthogonalisation matrix
Definition: cell.h:159
fractional (cell) curvatures, with respect to fractional u,v,w
Definition: derivs.h:132
Curv_orth< T > curv_orth(const Cell &cell) const
fractional-orthogonal derivative conversion
Definition: derivs.h:202
Curv_frac(const Mat33< T > &m)
constructor: copy/convert
Definition: derivs.h:135
Curv_frac()
null constructor
Definition: derivs.h:134
Curv_map< T > curv_map(const Grid &g) const
fractional-grid derivative conversion
Definition: derivs.h:209
map coordinate curvatures, with respect to grid u,v,w
Definition: derivs.h:146
Curv_map(const Mat33< T > &m)
constructor: copy/convert
Definition: derivs.h:149
Curv_frac< T > curv_frac(const Grid &g) const
grid-fractional derivative conversion
Definition: derivs.h:226
Curv_map()
null constructor
Definition: derivs.h:148
orthogonal (Angstom) curvatures, with respect to orthogonal x,y,z
Definition: derivs.h:120
Curv_orth()
null constructor
Definition: derivs.h:122
Curv_orth(const Mat33< T > &m)
constructor: copy/convert
Definition: derivs.h:123
Curv_frac< T > curv_frac(const Cell &cell) const
orthogonal-fractional derivative conversion
Definition: derivs.h:194
fractional (cell) gradient, with respect to fractional u,v,w
Definition: derivs.h:82
Grad_frac(const Vec3< T > &v)
constructor: copy/convert
Definition: derivs.h:85
Grad_frac(const T &du, const T &dv, const T &dw)
constructor: from d/du,d/dv,d/dw
Definition: derivs.h:87
Grad_map< T > grad_map(const Grid &g) const
fractional-grid derivative conversion
Definition: derivs.h:180
Grad_orth< T > grad_orth(const Cell &cell) const
fractional-orthogonal derivative conversion
Definition: derivs.h:176
const T & du() const
get d/du
Definition: derivs.h:89
const T & dw() const
get d/dw
Definition: derivs.h:91
Grad_frac()
null constructor
Definition: derivs.h:84
const T & dv() const
get d/dv
Definition: derivs.h:90
String format() const
return formatted String representation
Definition: derivs.h:172
map coordinate gradient, with respect to grid u,v,w
Definition: derivs.h:102
Grad_map(const T &du, const T &dv, const T &dw)
constructor: from d/du,d/dv,d/dw
Definition: derivs.h:107
Grad_frac< T > grad_frac(const Grid &g) const
grid-fractional derivative conversion
Definition: derivs.h:189
const T & du() const
get d/du
Definition: derivs.h:109
const T & dv() const
get d/dv
Definition: derivs.h:110
const T & dw() const
get d/dw
Definition: derivs.h:111
String format() const
return formatted String representation
Definition: derivs.h:185
Grad_map()
null constructor
Definition: derivs.h:104
Grad_map(const Vec3< T > &v)
constructor: copy/convert
Definition: derivs.h:105
orthogonal (Angstom) gradient, with respect to orthogonal x,y,z
Definition: derivs.h:64
Grad_orth(const Vec3< T > &v)
constructor: copy/convert
Definition: derivs.h:67
const T & dy() const
get d/dy
Definition: derivs.h:72
String format() const
return formatted String representation
Definition: derivs.h:163
const T & dz() const
get d/dz
Definition: derivs.h:73
const T & dx() const
get d/dx
Definition: derivs.h:71
Grad_orth()
null constructor
Definition: derivs.h:66
Grad_orth(const T &dx, const T &dy, const T &dz)
constructor: from d/dx,d/dy,d/dz
Definition: derivs.h:69
Grad_frac< T > grad_frac(const Cell &cell) const
orthogonal-fractional derivative conversion
Definition: derivs.h:167
generic grid
Definition: coords.h:480
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
3x3-matrix class
Definition: clipper_types.h:183
Mat33< T > transpose() const
transpose
Definition: clipper_types.h:488
String extension with simple parsing methods.
Definition: clipper_types.h:65
3-vector class
Definition: clipper_types.h:106