00001 #ifndef CCTBX_GEOMETRY_RESTRAINTS_MOTIF_H
00002 #define CCTBX_GEOMETRY_RESTRAINTS_MOTIF_H
00003
00004 #include <cctbx/error.h>
00005 #include <cctbx/import_scitbx_af.h>
00006 #include <scitbx/array_family/shared.h>
00007 #include <string>
00008
00009 namespace cctbx { namespace geometry_restraints {
00010
00011 struct motif {
00012
00013 struct atom
00014 {
00015 std::string name;
00016 std::string scattering_type;
00017 std::string nonbonded_type;
00018 double partial_charge;
00019
00020 atom() : partial_charge(0) {}
00021
00022 atom(
00023 const char* name_,
00024 const char* scattering_type_="",
00025 const char* nonbonded_type_="",
00026 double partial_charge_=0)
00027 :
00028 name(name_),
00029 scattering_type(scattering_type_),
00030 nonbonded_type(nonbonded_type_),
00031 partial_charge(partial_charge_)
00032 {}
00033 };
00034
00035 struct bond
00036 {
00037 af::tiny<std::string, 2> atom_names;
00038 std::string type;
00039 double distance_ideal;
00040 double weight;
00041 std::string id;
00042
00043 bond() : distance_ideal(0), weight(0) {}
00044
00045 bond(
00046 af::tiny<std::string, 2> atom_names_,
00047 const char* type_="",
00048 double distance_ideal_=0,
00049 double weight_=0,
00050 const char* id_="")
00051 :
00052 atom_names(atom_names_),
00053 type(type_),
00054 distance_ideal(distance_ideal_),
00055 weight(weight_),
00056 id(id_)
00057 {}
00058 };
00059
00060 struct angle
00061 {
00062 af::tiny<std::string, 3> atom_names;
00063 double angle_ideal;
00064 double weight;
00065 std::string id;
00066
00067 angle() : angle_ideal(0), weight(0) {}
00068
00069 angle(
00070 af::tiny<std::string, 3> atom_names_,
00071 double angle_ideal_=0,
00072 double weight_=0,
00073 const char* id_="")
00074 :
00075 atom_names(atom_names_),
00076 angle_ideal(angle_ideal_),
00077 weight(weight_),
00078 id(id_)
00079 {}
00080 };
00081
00082 struct dihedral
00083 {
00084 af::tiny<std::string, 4> atom_names;
00085 double angle_ideal;
00086 double weight;
00087 int periodicity;
00088 std::string id;
00089
00090 dihedral() : angle_ideal(0), weight(0), periodicity(0) {}
00091
00092 dihedral(
00093 af::tiny<std::string, 4> atom_names_,
00094 double angle_ideal_=0,
00095 double weight_=0,
00096 int periodicity_=0,
00097 const char* id_="")
00098 :
00099 atom_names(atom_names_),
00100 angle_ideal(angle_ideal_),
00101 weight(weight_),
00102 periodicity(periodicity_),
00103 id(id_)
00104 {}
00105 };
00106
00107 struct chirality
00108 {
00109 af::tiny<std::string, 4> atom_names;
00110 std::string volume_sign;
00111 bool both_signs;
00112 double volume_ideal;
00113 double weight;
00114 std::string id;
00115
00116 chirality() : both_signs(false), volume_ideal(0), weight(0) {}
00117
00118 chirality(
00119 af::tiny<std::string, 4> atom_names_,
00120 const char* volume_sign_="",
00121 bool both_signs_=false,
00122 double volume_ideal_=0,
00123 double weight_=0,
00124 const char* id_="")
00125 :
00126 atom_names(atom_names_),
00127 volume_sign(volume_sign_),
00128 both_signs(both_signs_),
00129 volume_ideal(volume_ideal_),
00130 weight(weight_),
00131 id(id_)
00132 {}
00133 };
00134
00135 struct planarity
00136 {
00137 af::shared<std::string> atom_names;
00138 af::shared<double> weights;
00139 std::string id;
00140
00141 planarity() {}
00142
00143 planarity(
00144 af::shared<std::string> const& atom_names_,
00145 af::shared<double> const& weights_,
00146 const char* id_="")
00147 :
00148 atom_names(atom_names_),
00149 weights(weights_),
00150 id(id_)
00151 {
00152 CCTBX_ASSERT(weights.size() == atom_names.size());
00153 }
00154 };
00155
00156 std::string id;
00157 std::string description;
00158 af::shared<std::string> info;
00159 af::shared<std::string> manipulation_ids;
00160 af::shared<atom> atoms;
00161 af::shared<bond> bonds;
00162 af::shared<angle> angles;
00163 af::shared<dihedral> dihedrals;
00164 af::shared<chirality> chiralities;
00165 af::shared<planarity> planarities;
00166
00167 struct alteration
00168 {
00169 struct action_type
00170 {
00171 action_type(std::string const& description="")
00172 {
00173 if (description == "") code_ = 0;
00174 else if (description == "add") code_ = 1;
00175 else if (description == "delete") code_ = 2;
00176 else if (description == "change") code_ = 3;
00177 else {
00178 throw std::runtime_error(
00179 "Unknown cctbx::geometry_restraints::motif::alteration"
00180 "::action_type: \"" + description + "\"\n"
00181 " Possible action types are:"
00182 " \"\", \"add\", \"delete\", \"change\"");
00183 }
00184 }
00185
00186 int
00187 code() const { return code_; }
00188
00189 bool is_add() const { return code_ == 1; }
00190 bool is_delete() const { return code_ == 2; }
00191 bool is_change() const { return code_ == 3; }
00192
00193 std::string
00194 description() const
00195 {
00196 if (is_add()) return "add";
00197 if (is_delete()) return "delete";
00198 if (is_change()) return "change";
00199 return "";
00200 }
00201
00202 private:
00203 int code_;
00204 };
00205
00206 struct operand_type
00207 {
00208 operand_type(std::string const& description="")
00209 {
00210 if (description == "") code_ = 0;
00211 else if (description == "atom") code_ = 1;
00212 else if (description == "bond") code_ = 2;
00213 else if (description == "angle") code_ = 3;
00214 else if (description == "dihedral") code_ = 4;
00215 else if (description == "chirality") code_ = 5;
00216 else if (description == "planarity") code_ = 6;
00217 else {
00218 throw std::runtime_error(
00219 "Unknown cctbx::geometry_restraints::motif::alteration"
00220 "::operand_type: \"" + description + "\"\n"
00221 " Possible operand types are:"
00222 " \"\", \"atom\", \"bond\", \"angle\","
00223 " \"dihedral\", \"chirality\", \"planarity\"");
00224 }
00225 }
00226
00227 int
00228 code() const { return code_; }
00229
00230 bool is_atom() const { return code_ == 1; }
00231 bool is_bond() const { return code_ == 2; }
00232 bool is_angle() const { return code_ == 3; }
00233 bool is_dihedral() const { return code_ == 4; }
00234 bool is_chirality() const { return code_ == 5; }
00235 bool is_planarity() const { return code_ == 6; }
00236
00237 std::string
00238 description() const
00239 {
00240 if (is_atom()) return "atom";
00241 if (is_bond()) return "bond";
00242 if (is_angle()) return "angle";
00243 if (is_dihedral()) return "dihedral";
00244 if (is_chirality()) return "chirality";
00245 if (is_planarity()) return "planarity";
00246 return "";
00247 }
00248
00249 private:
00250 int code_;
00251 };
00252
00253 action_type action;
00254 operand_type operand;
00255 af::shared<std::string> motif_ids;
00256 std::string motif_atom_name;
00257 motif::atom atom;
00258 motif::bond bond;
00259 motif::angle angle;
00260 motif::dihedral dihedral;
00261 motif::chirality chirality;
00262 motif::planarity planarity;
00263 std::string planarity_motif_id;
00264 af::shared<action_type> planarity_atom_actions;
00265 unsigned change_bits;
00266
00267 alteration(
00268 std::string const& action_="",
00269 std::string const& operand_="")
00270 :
00271 action(action_),
00272 operand(operand_),
00273 change_bits(0)
00274 {}
00275
00276 static const unsigned change_partial_charge_bit = 0x00000001U;
00277 static const unsigned change_distance_ideal_bit = 0x00000002U;
00278 static const unsigned change_weight_bit = 0x00000004U;
00279 static const unsigned change_angle_ideal_bit = 0x00000008U;
00280 static const unsigned change_periodicity_bit = 0x00000010U;
00281 static const unsigned change_both_signs_bit = 0x00000020U;
00282 static const unsigned change_volume_ideal_bit = 0x00000040U;
00283
00284 #define CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(attr) \
00285 bool \
00286 change_##attr() const { return change_bits & change_##attr##_bit; } \
00287 \
00288 alteration& \
00289 set_change_##attr(bool state) \
00290 { \
00291 if (state) change_bits |= change_##attr##_bit; \
00292 else change_bits &= ~change_##attr##_bit; \
00293 return *this; \
00294 }
00295
00296 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(partial_charge)
00297 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(distance_ideal)
00298 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(weight)
00299 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(angle_ideal)
00300 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(periodicity)
00301 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(both_signs)
00302 CCTBX_GEOMETRY_RESTRAINTS_MOTIF_MANIP_CHNG_BITS_GET_SET(volume_ideal)
00303 };
00304
00305 struct manipulation
00306 {
00307 std::string id;
00308 std::string description;
00309 af::shared<std::string> info;
00310 af::shared<alteration> alterations;
00311 };
00312
00313 };
00314
00315 }}
00316
00317 #endif // CCTBX_GEOMETRY_RESTRAINTS_MOTIF_H