| 1 | /* lidia-core/bond-record-container-t.hh |
| 2 | * |
| 3 | * Copyright 2016 by Medical Research Council |
| 4 | * Author: Paul Emsley |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or (at |
| 9 | * your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 | * 02110-1301, USA |
| 20 | */ |
| 21 | |
| 22 | #ifdef USE_SQLITE3 |
| 23 | #include <sqlite3.h> |
| 24 | #endif // USE_SQLITE3 |
| 25 | |
| 26 | #include "cod-atom-type-t.hh"cxx . . $ `<file>/lidia-core/cod-atom-type-t.hh`/ |
| 27 | #include "bond-table-record-t.hh"cxx . . $ `<file>/lidia-core/bond-table-record-t.hh`/ |
| 28 | // for validation |
| 29 | #include "geometry/protein-geometry.hh"cxx . . $ `<file>/geometry/protein-geometry.hh`/ |
| 30 | |
| 31 | namespace codcxx . . $ cod/ { |
| 32 | |
| 33 | // --------------- record container --------------------- |
| 34 | |
| 35 | class bond_record_container_tcxx . . $ cod/bond_record_container_t# { |
| 36 | stdcxx . . $ std/::stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# get_max_atom_type_widthcxx . . $ cod/bond_record_container_t#get_max_atom_type_width(fe4d2d262d4164a8).() const; |
| 37 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, unsigned int> level_4_atom_types_mapcxx . . $ cod/bond_record_container_t#level_4_atom_types_map.; // convert from acedrg-table |
| 38 | // COD string to its index |
| 39 | bool write_atom_type_indicescxx . . $ cod/bond_record_container_t#write_atom_type_indices(13a55b95a0133754).(const stdcxx . . $ std/::stringcxx . . $ std/string# &file_name) const; |
| 40 | |
| 41 | void sortcxx . . $ cod/bond_record_container_t#sort(49f6e7a06ebc5aa8).() { stdcxx . . $ std/::sortcxx . . $ std/sort(249673c20e2b8d5).(bondscxx . . $ cod/bond_record_container_t#bonds..begincxx . . $ std/vector#begin(55a6de06420d4903).(), bondscxx . . $ cod/bond_record_container_t#bonds..endcxx . . $ std/vector#end(55a6de06420d4903).()); } |
| 42 | void fill_level_4_atom_mapcxx . . $ cod/bond_record_container_t#fill_level_4_atom_map(49f6e7a06ebc5aa8).(); |
| 43 | void fill_bonds_mapcxx . . $ cod/bond_record_container_t#fill_bonds_map(49f6e7a06ebc5aa8).(); |
| 44 | |
| 45 | void fill_cod_atom_type_mapcxx . . $ cod/bond_record_container_t#fill_cod_atom_type_map(49f6e7a06ebc5aa8).(); |
| 46 | stdcxx . . $ std/::setcxx . . $ std/set#<atom_type_tcxx . . $ cod/atom_type_t#> cod_atom_type_setcxx . . $ cod/bond_record_container_t#cod_atom_type_set.; |
| 47 | stdcxx . . $ std/::mapcxx . . $ std/map#<atom_type_tcxx . . $ cod/atom_type_t#, int> cod_atom_type_mapcxx . . $ cod/bond_record_container_t#cod_atom_type_map.; // for extraction of atom type indices |
| 48 | |
| 49 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> |
| 50 | read_atom_type_indicescxx . . $ cod/bond_record_container_t#read_atom_type_indices(4b7fb629c6fc8acf).(const stdcxx . . $ std/::stringcxx . . $ std/string# &atom_type_indices_file_name) const; |
| 51 | |
| 52 | bool read_bondscxx . . $ cod/bond_record_container_t#read_bonds(937f4a479046c89c).(const stdcxx . . $ std/::stringcxx . . $ std/string# &bonds_file_name, |
| 53 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> &types); |
| 54 | |
| 55 | // can throw std::runtime_error |
| 56 | unsigned int get_atom_indexcxx . . $ cod/bond_record_container_t#get_atom_index(b5ff9148dc1b71d4).(const stdcxx . . $ std/::stringcxx . . $ std/string# &at_name_1, |
| 57 | const cootcxx . . $ coot/::dictionary_residue_restraints_tcxx . . $ coot/dictionary_residue_restraints_t# &rest) const; |
| 58 | unsigned int get_atom_indexcxx . . $ cod/bond_record_container_t#get_atom_index(c1b099e75672fb5b).(const stdcxx . . $ std/::stringcxx . . $ std/string# &at_name_1, |
| 59 | const RDKitcxx . . $ RDKit/::RWMolcxx . . $ RDKit/RWMol# &mol) const; |
| 60 | |
| 61 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<bool> get_is_hydrogen_flagscxx . . $ cod/bond_record_container_t#get_is_hydrogen_flags(fd6c020426892eb0).(const RDKitcxx . . $ RDKit/::RWMolcxx . . $ RDKit/RWMol# &rdkm) const; |
| 62 | |
| 63 | double get_bond_distance_from_modelcxx . . $ cod/bond_record_container_t#get_bond_distance_from_model(1b7272d1f01d83b3).(const stdcxx . . $ std/::stringcxx . . $ std/string# &at_name_1, |
| 64 | const stdcxx . . $ std/::stringcxx . . $ std/string# &at_name_2, |
| 65 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *res) const; |
| 66 | |
| 67 | bond_table_record_tcxx . . $ cod/bond_table_record_t# |
| 68 | get_cod_bond_from_tablecxx . . $ cod/bond_record_container_t#get_cod_bond_from_table(f9b5c081c56fe422).(const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_1, |
| 69 | const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_2) const; |
| 70 | |
| 71 | // which uses |
| 72 | bond_table_record_tcxx . . $ cod/bond_table_record_t# |
| 73 | make_bond_from_level_3_vectorcxx . . $ cod/bond_record_container_t#make_bond_from_level_3_vector(f0363c1155f1819b).(const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_1, |
| 74 | const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_2, |
| 75 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<bond_table_record_tcxx . . $ cod/bond_table_record_t#> &v, |
| 76 | bond_table_record_tcxx . . $ cod/bond_table_record_t#::approximation_level_tcxx . . $ cod/bond_table_record_t#approximation_level_t# al) const; |
| 77 | |
| 78 | // generalization |
| 79 | // |
| 80 | bond_table_record_tcxx . . $ cod/bond_table_record_t# |
| 81 | make_bond_from_level_2_mapcxx . . $ cod/bond_record_container_t#make_bond_from_level_2_map(8ac64168fa2e518d).(const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_1, |
| 82 | const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_2, |
| 83 | const stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::vectorcxx . . $ std/vector#<bond_table_record_tcxx . . $ cod/bond_table_record_t#> > > &l3_map, |
| 84 | bond_table_record_tcxx . . $ cod/bond_table_record_t#::approximation_level_tcxx . . $ cod/bond_table_record_t#approximation_level_t# approx_level) const; |
| 85 | |
| 86 | |
| 87 | bond_table_record_tcxx . . $ cod/bond_table_record_t# |
| 88 | consolidate_bondscxx . . $ cod/bond_record_container_t#consolidate_bonds(f0363c1155f1819b).(const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_1, |
| 89 | const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_2, |
| 90 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<bond_table_record_tcxx . . $ cod/bond_table_record_t#> &lb, |
| 91 | bond_table_record_tcxx . . $ cod/bond_table_record_t#::approximation_level_tcxx . . $ cod/bond_table_record_t#approximation_level_t# approx_level) const; |
| 92 | |
| 93 | void t3_miss_diagnosecxx . . $ cod/bond_record_container_t#t3_miss_diagnose(2a06bad0e108e9e7).(const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_1, |
| 94 | const atom_type_tcxx . . $ cod/atom_type_t# &cod_type_2) const; |
| 95 | |
| 96 | #ifdef USE_SQLITE3 |
| 97 | static int db_callback(void *NotUsed, int argc, char **argv, char **azColName); |
| 98 | sqlite3 *make_sqlite_db(const std::string &file_name); |
| 99 | bool db_add_level_4_types(sqlite3 *db); |
| 100 | #endif // USE_SQLITE3 |
| 101 | |
| 102 | clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth# cocxx . . $ cod/bond_record_container_t#co(6ece53504583a6c4).(mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *at) const { return clippercxx . . $ clipper/Coord_orth#Coord_orth(3374d1a184fcc02e).::Coord_orthcxx . . $ clipper/Coord_orth#(at->xcxx . . $ mmdb/Atom#x., at->ycxx . . $ mmdb/Atom#y., at->zcxx . . $ mmdb/Atom#z.); } |
| 103 | |
| 104 | public: |
| 105 | bond_record_container_tcxx . . $ cod/bond_record_container_t#bond_record_container_t(49f6e7a06ebc5aa8).() {} |
| 106 | bond_record_container_tcxx . . $ cod/bond_record_container_t#bond_record_container_t(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &table_dir_name) { |
| 107 | read_acedrg_table_dircxx . . $ cod/bond_record_container_t#read_acedrg_table_dir(9c546c94e5fcce4e).(table_dir_name); |
| 108 | } |
| 109 | bool read_acedrg_tablecxx . . $ cod/bond_record_container_t#read_acedrg_table(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string# &file_name); |
| 110 | |
| 111 | // fill the bonds table |
| 112 | // |
| 113 | void read_acedrg_table_dircxx . . $ cod/bond_record_container_t#read_acedrg_table_dir(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &table_dir_name); |
| 114 | |
| 115 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<bond_table_record_tcxx . . $ cod/bond_table_record_t#> bondscxx . . $ cod/bond_record_container_t#bonds.; |
| 116 | |
| 117 | // Level-4 atom type is the (outer) key and (outer) value |
| 118 | // is a map for which the key is the second level-4 atom type, |
| 119 | // returning a bond record. |
| 120 | // std::map<std::string, std::map<std::string, bond_table_record_t> > bonds_map; |
| 121 | |
| 122 | // the key is a level-3 atom type, the value is |
| 123 | // a map for which the key is a level-3 atom type and the value of that |
| 124 | // map is a vector of bond_table_record_t. |
| 125 | // |
| 126 | // std::map<std::string, std::map<std::string, std::vector<bond_table_record_t> > > |
| 127 | // bonds_map; |
| 128 | |
| 129 | // same again, but with a level-2 type to index first |
| 130 | // |
| 131 | // bonds_map[l2][l2][l3][l3] |
| 132 | // |
| 133 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::vectorcxx . . $ std/vector#<bond_table_record_tcxx . . $ cod/bond_table_record_t#> > > > > bonds_mapcxx . . $ cod/bond_record_container_t#bonds_map.; |
| 134 | |
| 135 | void addcxx . . $ cod/bond_record_container_t#add(6c087abee8b44da6).(const bond_table_record_tcxx . . $ cod/bond_table_record_t# &rec) { |
| 136 | bondscxx . . $ cod/bond_record_container_t#bonds..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(rec); |
| 137 | } |
| 138 | |
| 139 | void add_tablecxx . . $ cod/bond_record_container_t#add_table(6c5f7a4ea625a960).(const bond_record_container_tcxx . . $ cod/bond_record_container_t# &brc); |
| 140 | |
| 141 | unsigned int sizecxx . . $ cod/bond_record_container_t#size(db52760e79bf9054).() { return bondscxx . . $ cod/bond_record_container_t#bonds..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); } |
| 142 | bool writecxx . . $ cod/bond_record_container_t#write(888697e2d51e3aa6).(const stdcxx . . $ std/::stringcxx . . $ std/string# &atom_indices_file_name, |
| 143 | const stdcxx . . $ std/::stringcxx . . $ std/string# &bonds_file_name) const; |
| 144 | |
| 145 | bool readcxx . . $ cod/bond_record_container_t#read(1667653f663d0d88).(const stdcxx . . $ std/::stringcxx . . $ std/string# &atom_type_indices_file_name, |
| 146 | const stdcxx . . $ std/::stringcxx . . $ std/string# &bonds_file_name); |
| 147 | void checkcxx . . $ cod/bond_record_container_t#check(83f5f38750778ac8).() const; |
| 148 | void validatecxx . . $ cod/bond_record_container_t#validate(51e4c6b831ddb141).(mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *res, const cootcxx . . $ coot/::dictionary_residue_restraints_tcxx . . $ coot/dictionary_residue_restraints_t# &rest) const; |
| 149 | void make_dbcxx . . $ cod/bond_record_container_t#make_db(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &file_name); // probably not const |
| 150 | }; |
| 151 | } |