00001 #ifndef CCTBX_ADP_RESTRAINTS_RIGID_BOND_H
00002 #define CCTBX_ADP_RESTRAINTS_RIGID_BOND_H
00003
00004 #include <cctbx/error.h>
00005 #include <cctbx/adptbx.h>
00006
00007 #include <scitbx/array_family/versa.h>
00008 #include <vector>
00009 #include <scitbx/array_family/shared.h>
00010 #include <cctbx/import_scitbx_af.h>
00011
00012 namespace cctbx { namespace adp_restraints {
00013
00014 using scitbx::vec3;
00015 using scitbx::mat3;
00016 using scitbx::sym_mat3;
00017
00018 class rigid_bond_pair {
00019 public:
00020 rigid_bond_pair(vec3<double> const& site1,
00021 vec3<double> const& site2,
00022 sym_mat3<double> const& ustar1,
00023 sym_mat3<double> const& ustar2,
00024 cctbx::uctbx::unit_cell const& uc);
00025 double z_12() { return z_12_; }
00026 double z_21() { return z_21_; }
00027 double delta_z() { return delta_z_; }
00028 private:
00029 double z_12_, z_21_, delta_z_;
00030 };
00031
00032 struct rigid_bond_proxy
00033 {
00035 rigid_bond_proxy() {}
00036
00038 rigid_bond_proxy(
00039 af::tiny<unsigned, 2> const& i_seqs_,
00040 double weight_)
00041 :
00042 i_seqs(i_seqs_),
00043 weight(weight_)
00044 {}
00045
00047 af::tiny<unsigned, 2> i_seqs;
00049 double weight;
00050 };
00051
00052 class rigid_bond
00053 {
00054 public:
00056 rigid_bond() {}
00057
00059 rigid_bond(
00060 af::tiny<scitbx::vec3<double>, 2> const& sites_,
00061 af::tiny<scitbx::sym_mat3<double>, 2> const& u_cart_,
00062 double weight_)
00063 :
00064 sites(sites_),
00065 u_cart(u_cart_),
00066 weight(weight_)
00067 {
00068 init_delta();
00069 }
00070
00072 rigid_bond(
00073 af::const_ref<scitbx::vec3<double> > const& sites_cart,
00074 af::const_ref<scitbx::sym_mat3<double> > const& u_cart_,
00075 rigid_bond_proxy const& proxy);
00076
00078 double
00079 residual() const { return weight * scitbx::fn::pow2(delta_z_); }
00080
00081 scitbx::sym_mat3<double>
00082 gradient_0() const;
00083
00084 af::tiny<scitbx::sym_mat3<double>, 2>
00085 gradients() const;
00086
00088
00090 void
00091 add_gradients(
00092 af::ref<scitbx::sym_mat3<double> > const& gradients_aniso_cart,
00093 af::tiny<unsigned, 2> const& i_seqs) const;
00094
00095 double z_12() { return z_12_; }
00096 double z_21() { return z_21_; }
00097 double delta_z() { return delta_z_; }
00098
00100 af::tiny<scitbx::vec3<double>, 2> sites;
00102 af::tiny<scitbx::sym_mat3<double>, 2> u_cart;
00103
00104 double delta;
00105 double weight;
00106 protected:
00107 void init_delta();
00108
00109 double z_12_, z_21_, delta_z_;
00111 vec3<double> l_12;
00112 double bond_length_sq;
00113 };
00114
00124 double
00125 rigid_bond_residual_sum(
00126 af::const_ref<scitbx::vec3<double> > const& sites_cart,
00127 af::const_ref<scitbx::sym_mat3<double> > const& u_cart,
00128 af::const_ref<rigid_bond_proxy> const& proxies,
00129 af::ref<scitbx::sym_mat3<double> > const& gradients_aniso_cart);
00130
00134 af::shared<double>
00135 rigid_bond_residuals(
00136 af::const_ref<scitbx::vec3<double> > const& sites_cart,
00137 af::const_ref<scitbx::sym_mat3<double> > const& u_cart,
00138 af::const_ref<rigid_bond_proxy> const& proxies);
00139
00143 af::shared<double>
00144 rigid_bond_deltas(
00145 af::const_ref<scitbx::vec3<double> > const& sites_cart,
00146 af::const_ref<scitbx::sym_mat3<double> > const& u_cart,
00147 af::const_ref<rigid_bond_proxy> const& proxies);
00148
00149 }}
00150
00151 #endif // CCTBX_ADP_RESTRAINTS_RIGID_BOND_H