00001 #ifndef CCTBX_GEOMETRY_RESTRAINTS_NONBONDED_SORTED_H
00002 #define CCTBX_GEOMETRY_RESTRAINTS_NONBONDED_SORTED_H
00003
00004 #include <cctbx/geometry_restraints/nonbonded.h>
00005 #include <cctbx/crystal/pair_tables.h>
00006
00007 namespace cctbx { namespace geometry_restraints {
00008
00010 class nonbonded_sorted_asu_proxies : public nonbonded_sorted_asu_proxies_base
00011 {
00012 public:
00014 nonbonded_sorted_asu_proxies() {}
00015
00017 nonbonded_sorted_asu_proxies(
00018 boost::shared_ptr<
00019 direct_space_asu::asu_mappings<> > const& asu_mappings)
00020 :
00021 nonbonded_sorted_asu_proxies_base(asu_mappings),
00022 n_1_3(0),
00023 n_1_4(0),
00024 n_nonbonded(0),
00025 n_unknown_nonbonded_type_pairs(0),
00026 min_vdw_distance(-1),
00027 max_vdw_distance(-1)
00028 {}
00029
00031
00041 nonbonded_sorted_asu_proxies(
00042 af::const_ref<std::size_t> const& model_indices,
00043 af::const_ref<std::size_t> const& conformer_indices,
00044 geometry_restraints::nonbonded_params const& nonbonded_params,
00045 af::const_ref<std::string> const& nonbonded_types,
00046 double nonbonded_distance_cutoff_plus_buffer,
00047 double min_cubicle_edge,
00048 std::vector<crystal::pair_asu_table<> > const& shell_asu_tables)
00049 :
00050 nonbonded_sorted_asu_proxies_base(shell_asu_tables[0].asu_mappings()),
00051 n_1_3(0),
00052 n_1_4(0),
00053 n_nonbonded(0),
00054 n_unknown_nonbonded_type_pairs(0),
00055 min_vdw_distance(-1),
00056 max_vdw_distance(-1)
00057 {
00058 CCTBX_ASSERT(model_indices.size() == 0
00059 || model_indices.size() == nonbonded_types.size());
00060 CCTBX_ASSERT(conformer_indices.size() == 0
00061 || conformer_indices.size() == nonbonded_types.size());
00062 CCTBX_ASSERT(shell_asu_tables.size() > 0);
00063 for(unsigned i=0; i<shell_asu_tables.size(); i++) {
00064 CCTBX_ASSERT(shell_asu_tables[i].table().size()
00065 == nonbonded_types.size());
00066 }
00067 unsigned shell_asu_tables_size = shell_asu_tables.size();
00068 for(unsigned i=1; i<shell_asu_tables_size; i++) {
00069 CCTBX_ASSERT(shell_asu_tables[i].asu_mappings().get()
00070 == shell_asu_tables[0].asu_mappings().get());
00071 }
00072 crystal::neighbors::fast_pair_generator<> pair_generator(
00073 shell_asu_tables[0].asu_mappings(),
00074 nonbonded_distance_cutoff_plus_buffer,
00075 false,
00076 min_cubicle_edge);
00077 while (!pair_generator.at_end()) {
00078 direct_space_asu::asu_mapping_index_pair_and_diff<>
00079 pair = pair_generator.next();
00080 if (shell_asu_tables[0].contains(pair)) {
00081 continue;
00082 }
00083 if ( shell_asu_tables_size > 1
00084 && shell_asu_tables[1].contains(pair)) {
00085 n_1_3++;
00086 continue;
00087 }
00088 if ( model_indices.size() != 0
00089 && model_indices[pair.i_seq] != model_indices[pair.j_seq]) {
00090 continue;
00091 }
00092 if ( conformer_indices.size() != 0
00093 && conformer_indices[pair.i_seq] != 0
00094 && conformer_indices[pair.j_seq] != 0
00095 && conformer_indices[pair.i_seq]
00096 != conformer_indices[pair.j_seq]) {
00097 continue;
00098 }
00099 if ( shell_asu_tables_size > 2
00100 && shell_asu_tables[2].contains(pair)) {
00101 nonbonded_asu_proxy proxy = make_nonbonded_asu_proxy(
00102 nonbonded_params, nonbonded_types, pair, true);
00103 if (min_vdw_distance < 0 || min_vdw_distance > proxy.vdw_distance){
00104 min_vdw_distance = proxy.vdw_distance;
00105 }
00106 if (max_vdw_distance < proxy.vdw_distance) {
00107 max_vdw_distance = proxy.vdw_distance;
00108 }
00109 process(proxy);
00110 n_1_4++;
00111 continue;
00112 }
00113 {
00114 nonbonded_asu_proxy proxy = make_nonbonded_asu_proxy(
00115 nonbonded_params, nonbonded_types, pair, false);
00116 if (min_vdw_distance < 0 || min_vdw_distance > proxy.vdw_distance){
00117 min_vdw_distance = proxy.vdw_distance;
00118 }
00119 if (max_vdw_distance < proxy.vdw_distance) {
00120 max_vdw_distance = proxy.vdw_distance;
00121 }
00122 process(proxy);
00123 n_nonbonded++;
00124 }
00125 }
00126 }
00127
00129 nonbonded_asu_proxy
00130 make_nonbonded_asu_proxy(
00131 geometry_restraints::nonbonded_params const& nonbonded_params,
00132 af::const_ref<std::string> const& nonbonded_types,
00133 direct_space_asu::asu_mapping_index_pair const& pair,
00134 bool is_1_4_interaction)
00135 {
00136 std::string const& type_i = nonbonded_types[pair.i_seq];
00137 std::string const& type_j = nonbonded_types[pair.j_seq];
00138 double distance = nonbonded_params.get_nonbonded_distance(
00139 type_i, type_j);
00140 if (distance != -1) {
00141 return nonbonded_asu_proxy(
00142 pair,
00143 nonbonded_params.adjust_nonbonded_distance(
00144 distance, is_1_4_interaction));
00145 }
00146 if (nonbonded_params.default_distance > 0) {
00147 n_unknown_nonbonded_type_pairs++;
00148 return nonbonded_asu_proxy(
00149 pair,
00150 nonbonded_params.adjust_nonbonded_distance(
00151 nonbonded_params.default_distance, is_1_4_interaction));
00152 }
00153 throw error(
00154 "Unknown nonbonded type pair (incomplete nonbonded_distance_table): "
00155 + type_i + " - " + type_j);
00156 }
00157
00159 unsigned n_1_3;
00161 unsigned n_1_4;
00163 unsigned n_nonbonded;
00167 unsigned n_unknown_nonbonded_type_pairs;
00168
00170 double min_vdw_distance;
00172 double max_vdw_distance;
00173 };
00174
00175 }}
00176
00177 #endif // CCTBX_GEOMETRY_RESTRAINTS_NONBONDED_SORTED_H