| 1 | /* |
| 2 | * coot-utils/coot-h-bonds.hh |
| 3 | * |
| 4 | * Copyright 2010 by University of York |
| 5 | * Author: Paul Emsley |
| 6 | * |
| 7 | * This file is part of Coot |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 3 of the License, or (at |
| 12 | * your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copies of the GNU General Public License and |
| 20 | * the GNU Lesser General Public License along with this program; if not, |
| 21 | * write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 22 | * Fifth Floor, Boston, MA, 02110-1301, USA. |
| 23 | * See http://www.gnu.org/licenses/ |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef COOT_H_BONDS_HH |
| 28 | #define COOT_H_BONDS_HHcxx . . $ `coot-utils/coot-h-bonds.hh:28:9`! |
| 29 | |
| 30 | #include <vector> |
| 31 | #include <map> |
| 32 | #include <algorithm> |
| 33 | |
| 34 | #include "compat/coot-sysdep.h"cxx . . $ `<file>/compat/coot-sysdep.h`/ |
| 35 | |
| 36 | #include <mmdb2/mmdb_manager.h> |
| 37 | |
| 38 | #include "geometry/protein-geometry.hh"cxx . . $ `<file>/geometry/protein-geometry.hh`/ |
| 39 | #include "coot-coord-utils.hh"cxx . . $ `<file>/coot-utils/coot-coord-utils.hh`/ |
| 40 | |
| 41 | namespace cootcxx . . $ coot/ { |
| 42 | |
| 43 | class h_bondcxx . . $ coot/h_bond# { |
| 44 | public: |
| 45 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *hb_hydrogencxx . . $ coot/h_bond#hb_hydrogen.; // McDonald and Thornton H-bond algorithm |
| 46 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *donorcxx . . $ coot/h_bond#donor.; |
| 47 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *acceptorcxx . . $ coot/h_bond#acceptor.; |
| 48 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *donor_neighcxx . . $ coot/h_bond#donor_neigh.; |
| 49 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *acceptor_neighcxx . . $ coot/h_bond#acceptor_neigh.; |
| 50 | double angle_1cxx . . $ coot/h_bond#angle_1.; // degrees |
| 51 | double angle_2cxx . . $ coot/h_bond#angle_2.; |
| 52 | double angle_3cxx . . $ coot/h_bond#angle_3.; |
| 53 | double distcxx . . $ coot/h_bond#dist.; // H-bond length |
| 54 | bool ligand_atom_is_donorcxx . . $ coot/h_bond#ligand_atom_is_donor.; // for use when hb_hydrogen is NULL - |
| 55 | // no hydrogens in H-bond analysis. |
| 56 | bool hydrogen_is_ligand_atomcxx . . $ coot/h_bond#hydrogen_is_ligand_atom.; |
| 57 | bool bond_has_hydrogen_flagcxx . . $ coot/h_bond#bond_has_hydrogen_flag.; |
| 58 | |
| 59 | h_bondcxx . . $ coot/h_bond#h_bond(49f6e7a06ebc5aa8).() { |
| 60 | hb_hydrogencxx . . $ coot/h_bond#hb_hydrogen. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 61 | donorcxx . . $ coot/h_bond#donor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 62 | acceptorcxx . . $ coot/h_bond#acceptor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 63 | donor_neighcxx . . $ coot/h_bond#donor_neigh. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 64 | acceptor_neighcxx . . $ coot/h_bond#acceptor_neigh. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 65 | ligand_atom_is_donorcxx . . $ coot/h_bond#ligand_atom_is_donor. = 1; |
| 66 | angle_1cxx . . $ coot/h_bond#angle_1. = -1; |
| 67 | angle_2cxx . . $ coot/h_bond#angle_2. = -1; |
| 68 | angle_3cxx . . $ coot/h_bond#angle_3. = -1; |
| 69 | hydrogen_is_ligand_atomcxx . . $ coot/h_bond#hydrogen_is_ligand_atom. = 0; // no hydrogen |
| 70 | bond_has_hydrogen_flagcxx . . $ coot/h_bond#bond_has_hydrogen_flag. = 0; |
| 71 | } |
| 72 | h_bondcxx . . $ coot/h_bond#h_bond(1249de241f848bbb).(mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *d, mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *a) { |
| 73 | hb_hydrogencxx . . $ coot/h_bond#hb_hydrogen. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 74 | donorcxx . . $ coot/h_bond#donor. = d; |
| 75 | acceptorcxx . . $ coot/h_bond#acceptor. = a; |
| 76 | donor_neighcxx . . $ coot/h_bond#donor_neigh. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 77 | acceptor_neighcxx . . $ coot/h_bond#acceptor_neigh. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 78 | ligand_atom_is_donorcxx . . $ coot/h_bond#ligand_atom_is_donor. = 0; |
| 79 | distcxx . . $ coot/h_bond#dist. = -1; |
| 80 | angle_1cxx . . $ coot/h_bond#angle_1. = -1; |
| 81 | angle_2cxx . . $ coot/h_bond#angle_2. = -1; |
| 82 | angle_3cxx . . $ coot/h_bond#angle_3. = -1; |
| 83 | hydrogen_is_ligand_atomcxx . . $ coot/h_bond#hydrogen_is_ligand_atom. = 0; // no hydrogen |
| 84 | bond_has_hydrogen_flagcxx . . $ coot/h_bond#bond_has_hydrogen_flag. = 0; |
| 85 | } |
| 86 | |
| 87 | // for McDonald and Thornton H-bonds, where the Hs are explicit. |
| 88 | // One first of these atoms is the hydrogen, the other is the |
| 89 | // acceptor. |
| 90 | // |
| 91 | // pass ligand_atom_is_H_flag as 1 when ligand atom is the H. |
| 92 | // |
| 93 | h_bondcxx . . $ coot/h_bond#h_bond(75cc7cb8405ea3f2).(mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *h, mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *a, bool ligand_atom_is_H_flag) { |
| 94 | hb_hydrogencxx . . $ coot/h_bond#hb_hydrogen. = h; |
| 95 | bond_has_hydrogen_flagcxx . . $ coot/h_bond#bond_has_hydrogen_flag. = 1; |
| 96 | acceptorcxx . . $ coot/h_bond#acceptor. = a; |
| 97 | donorcxx . . $ coot/h_bond#donor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 98 | donor_neighcxx . . $ coot/h_bond#donor_neigh. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 99 | acceptor_neighcxx . . $ coot/h_bond#acceptor_neigh. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 100 | hydrogen_is_ligand_atomcxx . . $ coot/h_bond#hydrogen_is_ligand_atom. = ligand_atom_is_H_flag; |
| 101 | ligand_atom_is_donorcxx . . $ coot/h_bond#ligand_atom_is_donor. = ligand_atom_is_H_flag; |
| 102 | distcxx . . $ coot/h_bond#dist. = -1; |
| 103 | angle_1cxx . . $ coot/h_bond#angle_1. = -1; |
| 104 | angle_2cxx . . $ coot/h_bond#angle_2. = -1; |
| 105 | angle_3cxx . . $ coot/h_bond#angle_3. = -1; |
| 106 | } |
| 107 | bool operatorcxx . . $ coot/h_bond#`operator<`(3841c66c02d6f5bc).<(const h_bondcxx . . $ coot/h_bond# &hb_2) const { |
| 108 | return (residue_spec_tcxx . . $ coot/residue_spec_t#(atom_spec_tcxx . . $ coot/atom_spec_t#(donorcxx . . $ coot/h_bond#donor.)) <cxx . . $ coot/residue_spec_t#`operator<`(da07f135f78f28ba). residue_spec_tcxx . . $ coot/residue_spec_t#residue_spec_t(bda281b0015fccfa).(atom_spec_tcxx . . $ coot/atom_spec_t#(hb_2.donorcxx . . $ coot/h_bond#donor.))); |
| 109 | } |
| 110 | bool operatorcxx . . $ coot/h_bond#`operator==`(3841c66c02d6f5bc).==(const h_bondcxx . . $ coot/h_bond# &hb_2) const { |
| 111 | atom_spec_tcxx . . $ coot/atom_spec_t# sd1cxx . . $ coot/atom_spec_t#atom_spec_t(146ec489276a46d2).(donorcxx . . $ coot/h_bond#donor.); |
| 112 | atom_spec_tcxx . . $ coot/atom_spec_t# sa1cxx . . $ coot/atom_spec_t#atom_spec_t(146ec489276a46d2).(acceptorcxx . . $ coot/h_bond#acceptor.); |
| 113 | atom_spec_tcxx . . $ coot/atom_spec_t# sd2cxx . . $ coot/atom_spec_t#atom_spec_t(146ec489276a46d2).(hb_2.donorcxx . . $ coot/h_bond#donor.); |
| 114 | atom_spec_tcxx . . $ coot/atom_spec_t# sa2cxx . . $ coot/atom_spec_t#atom_spec_t(146ec489276a46d2).(hb_2.acceptorcxx . . $ coot/h_bond#acceptor.); |
| 115 | return ((sd1 ==cxx . . $ coot/atom_spec_t#`operator==`(8471ddb8daaee38f). sd2) && (sa1 ==cxx . . $ coot/atom_spec_t#`operator==`(8471ddb8daaee38f). sa2)); |
| 116 | } |
| 117 | bool has_hydrogencxx . . $ coot/h_bond#has_hydrogen(50ce9a9e25b4a850).() const { return bond_has_hydrogen_flagcxx . . $ coot/h_bond#bond_has_hydrogen_flag.; } |
| 118 | bool ligand_atom_is_Hcxx . . $ coot/h_bond#ligand_atom_is_H(50ce9a9e25b4a850).() const { return hydrogen_is_ligand_atomcxx . . $ coot/h_bond#hydrogen_is_ligand_atom.; } |
| 119 | friend stdcxx . . $ std/::ostreamcxx . . $ std/ostream# & operatorcxx . . $ coot/`operator<<`(b1ee59228672babd).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &s, h_bondcxx . . $ coot/h_bond# hb); |
| 120 | }; |
| 121 | stdcxx . . $ std/::ostreamcxx . . $ std/ostream# & operatorcxx . . $ coot/`operator<<`(b1ee59228672babd).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &s, h_bondcxx . . $ coot/h_bond# hb); |
| 122 | |
| 123 | |
| 124 | class h_bondscxx . . $ coot/h_bonds# { |
| 125 | |
| 126 | // What is the nearest neighbour of the atoms in mol? |
| 127 | // |
| 128 | stdcxx . . $ std/::mapcxx . . $ std/map#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> > > |
| 129 | make_neighbour_mapcxx . . $ coot/h_bonds#make_neighbour_map(57d7cd2ea2c8f654).(int selHnd_1, int selHnd_2, mmdbcxx . . $ mmdb/::Managercxx . . $ mmdb/Manager# *mol); |
| 130 | |
| 131 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, h_bondcxx . . $ coot/h_bond#> |
| 132 | make_h_bond_from_ligand_hydrogencxx . . $ coot/h_bonds#make_h_bond_from_ligand_hydrogen(fae221881067a44).(mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *at_1, // H on ligand |
| 133 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *at_2, // acceptor on residue |
| 134 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> > &nb_1, |
| 135 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> > &nb_2) const; |
| 136 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, h_bondcxx . . $ coot/h_bond#> |
| 137 | make_h_bond_from_environment_residue_hydrogencxx . . $ coot/h_bonds#make_h_bond_from_environment_residue_hydrogen(fae221881067a44).(mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *at_1, // acceptor on ligand |
| 138 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *at_2, // H on residue |
| 139 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> > &nb_1, |
| 140 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> > &nb_2) const; |
| 141 | |
| 142 | public: |
| 143 | h_bondscxx . . $ coot/h_bonds#h_bonds(49f6e7a06ebc5aa8).() {} |
| 144 | |
| 145 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<h_bondcxx . . $ coot/h_bond#> |
| 146 | getcxx . . $ coot/h_bonds#get(1aed48e5f75986cf).(int selHnd_1, int selHnd_2, mmdbcxx . . $ mmdb/::Managercxx . . $ mmdb/Manager# *mol, const protein_geometrycxx . . $ coot/protein_geometry# &geom, int imol); |
| 147 | |
| 148 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<h_bondcxx . . $ coot/h_bond#> |
| 149 | get_mcdonald_and_thorntoncxx . . $ coot/h_bonds#get_mcdonald_and_thornton(c88383f25b816750).(int selHnd_1, int selHnd_2, mmdbcxx . . $ mmdb/::Managercxx . . $ mmdb/Manager# *mol, |
| 150 | const protein_geometrycxx . . $ coot/protein_geometry# &geom, int imol, |
| 151 | mmdbcxx . . $ mmdb/::realtypecxx . . $ mmdb/realtype# max_dist=3.9); |
| 152 | |
| 153 | // Check that some (formally, at least one) of the atoms have a defined HB status |
| 154 | // (energy_lib_atom hb_t). |
| 155 | // |
| 156 | // Return the hb_type_udd_handle as second. |
| 157 | // |
| 158 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, int> |
| 159 | check_hb_statuscxx . . $ coot/h_bonds#check_hb_status(ce1c3538b648fa52).(int selhnd, mmdbcxx . . $ mmdb/::Managercxx . . $ mmdb/Manager# *mol, const protein_geometrycxx . . $ coot/protein_geometry# &geom, int imol); |
| 160 | |
| 161 | // return the udd handle (donor, acceptors and HB hydrogens, that is) |
| 162 | int mark_donors_and_acceptorscxx . . $ coot/h_bonds#mark_donors_and_acceptors(5b5b36ec408e0fae).(int donor_selHnd, int acceptor_selHnd, mmdbcxx . . $ mmdb/::Managercxx . . $ mmdb/Manager# *mol, |
| 163 | const protein_geometrycxx . . $ coot/protein_geometry# &geom, int imol); |
| 164 | |
| 165 | class atom_sortercxx . . $ coot/h_bonds#atom_sorter# { |
| 166 | mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *atcxx . . $ coot/h_bonds#atom_sorter#at.; |
| 167 | cootcxx . . $ coot/::residue_spec_tcxx . . $ coot/residue_spec_t# at_res_speccxx . . $ coot/h_bonds#atom_sorter#at_res_spec.; |
| 168 | public: |
| 169 | explicit atom_sortercxx . . $ coot/h_bonds#atom_sorter#atom_sorter(146ec489276a46d2).(mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *at_in) { |
| 170 | atcxx . . $ coot/h_bonds#atom_sorter#at. = at_in; |
| 171 | at_res_speccxx . . $ coot/h_bonds#atom_sorter#at_res_spec. =cxx . . $ coot/residue_spec_t#`operator=`(c27d2fa585c5afc). residue_spec_tcxx . . $ coot/residue_spec_t#residue_spec_t(199c331f07f0c901).(atcxx . . $ coot/h_bonds#atom_sorter#at.->GetResiduecxx . . $ mmdb/Atom#GetResidue(7d1be562257b41d6).()); |
| 172 | } |
| 173 | bool operatorcxx . . $ coot/h_bonds#atom_sorter#`operator()`(324a0a7c0f7bd5a9).()(const stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> &p1, |
| 174 | const stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Atomcxx . . $ mmdb/Atom# *, float> &p2) const { |
| 175 | |
| 176 | cootcxx . . $ coot/::residue_spec_tcxx . . $ coot/residue_spec_t# n1_res_speccxx . . $ coot/residue_spec_t#residue_spec_t(199c331f07f0c901).(p1.firstcxx . . $ std/pair#first.->GetResiduecxx . . $ mmdb/Atom#GetResidue(7d1be562257b41d6).()); |
| 177 | cootcxx . . $ coot/::residue_spec_tcxx . . $ coot/residue_spec_t# n2_res_speccxx . . $ coot/residue_spec_t#residue_spec_t(199c331f07f0c901).(p2.firstcxx . . $ std/pair#first.->GetResiduecxx . . $ mmdb/Atom#GetResidue(7d1be562257b41d6).()); |
| 178 | |
| 179 | // |
| 180 | if ((n1_res_spec ==cxx . . $ coot/residue_spec_t#`operator==`(da07f135f78f28ba). at_res_speccxx . . $ coot/h_bonds#atom_sorter#at_res_spec.) && (n2_res_spec ==cxx . . $ coot/residue_spec_t#`operator==`(da07f135f78f28ba). at_res_speccxx . . $ coot/h_bonds#atom_sorter#at_res_spec.)) { |
| 181 | // they are both in the same residue as the donor |
| 182 | return (p1.secondcxx . . $ std/pair#second. < p2.secondcxx . . $ std/pair#second.); |
| 183 | } else { |
| 184 | if (n1_res_spec ==cxx . . $ coot/residue_spec_t#`operator==`(da07f135f78f28ba). at_res_speccxx . . $ coot/h_bonds#atom_sorter#at_res_spec.) { |
| 185 | // n_1 is in (and n_2 isn't), therefore n_1 is "shorter" |
| 186 | return 1; |
| 187 | } else { |
| 188 | if (n2_res_spec ==cxx . . $ coot/residue_spec_t#`operator==`(da07f135f78f28ba). at_res_speccxx . . $ coot/h_bonds#atom_sorter#at_res_spec.) { |
| 189 | // n_2 is in (and n_1 isn't), therefore n_2 is "shorter" |
| 190 | return 0; |
| 191 | } else { |
| 192 | // neither of them are in the residue |
| 193 | return (p1.secondcxx . . $ std/pair#second. < p2.secondcxx . . $ std/pair#second.); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | }; |
| 199 | }; |
| 200 | } |
| 201 | |
| 202 | #endif // COOT_H_BONDS_HH |
| 203 |