| 1 | /* |
| 2 | * protein_db/protein_db.h |
| 3 | * |
| 4 | * Copyright 2008-2009 by Kevin Cowtan |
| 5 | * Author: Kevin Cowtan |
| 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 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 22 | * 02110-1301, USA |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #ifndef PROTEIN_DB |
| 27 | #define PROTEIN_DBcxx . . $ `protein_db/protein_db.h:27:9`! |
| 28 | |
| 29 | |
| 30 | #include <clipper/clipper.h> |
| 31 | #include <clipper/clipper-minimol.h> |
| 32 | |
| 33 | |
| 34 | namespace ProteinDBcxx . . $ ProteinDB/ { |
| 35 | |
| 36 | |
| 37 | /*! |
| 38 | Class for storing compact amino acid main chain information for use |
| 39 | with Top500 DB. The same class is used for storing residues in the |
| 40 | DB, and also for storing residues for searching against the DB. |
| 41 | This class stores all the information concerning a single residue. |
| 42 | */ |
| 43 | class Residuecxx . . $ ProteinDB/Residue# { |
| 44 | public: |
| 45 | enum FLAGcxx . . $ ProteinDB/Residue#FLAG# {NONEcxx . . $ ProteinDB/Residue#NONE.,NORMALcxx . . $ ProteinDB/Residue#NORMAL.,CALPHAcxx . . $ ProteinDB/Residue#CALPHA.}; |
| 46 | //! Null constructor |
| 47 | Residuecxx . . $ ProteinDB/Residue#Residue(49f6e7a06ebc5aa8).() : flgcxx . . $ ProteinDB/Residue#flg.(char(NONEcxx . . $ ProteinDB/Residue#NONE.)) {} |
| 48 | //! Constructor: from C-alpha coord and residue type |
| 49 | Residuecxx . . $ ProteinDB/Residue#Residue(a27f5a6077cfc42f).( clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth#& ca, const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String#& type ); |
| 50 | //! Constructor: from main chain coords and residue type |
| 51 | Residuecxx . . $ ProteinDB/Residue#Residue(7560a7de66dac2af).( clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth#& cn, clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth#& ca, clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth#& cc, const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String#& type ); |
| 52 | //! Constructor: from MMonomer |
| 53 | Residuecxx . . $ ProteinDB/Residue#Residue(7b11f5e2b02a7bba).( const clippercxx . . $ clipper/::MMonomercxx . . $ clipper/MMonomer#& mm ); |
| 54 | clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth# coord_ncxx . . $ ProteinDB/Residue#coord_n(465b636ddbe0fc84). () const; //!< N atom coordinate |
| 55 | clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth# coord_cacxx . . $ ProteinDB/Residue#coord_ca(465b636ddbe0fc84).() const; //!< C-alpha atom coordinate |
| 56 | clippercxx . . $ clipper/::Coord_orthcxx . . $ clipper/Coord_orth# coord_ccxx . . $ ProteinDB/Residue#coord_c(465b636ddbe0fc84). () const; //!< C atom coordinate |
| 57 | clippercxx . . $ clipper/::MMonomercxx . . $ clipper/MMonomer# mmonomercxx . . $ ProteinDB/Residue#mmonomer(d5314a27a0eb4d22).() const; //!< Build MMonomer |
| 58 | //! Transform by rotation-translation operator |
| 59 | void transformcxx . . $ ProteinDB/Residue#transform(e19fd923a135bced).( const clippercxx . . $ clipper/::RTop_orthcxx . . $ clipper/RTop_orth#& rtop ); |
| 60 | //! Merge other residue coords with this one using given weights |
| 61 | bool mergecxx . . $ ProteinDB/Residue#merge(57757be044f7e99d).( const Residuecxx . . $ ProteinDB/Residue#& other, const double wn, const double wa, const double wc ); |
| 62 | char typecxx . . $ ProteinDB/Residue#type(1b8b762cbef9c2c9).() const { return typcxx . . $ ProteinDB/Residue#typ.; } //!< return residue type (1-char) |
| 63 | FLAGcxx . . $ ProteinDB/Residue#FLAG# flagcxx . . $ ProteinDB/Residue#flag(875fce2ac49b7845).() const { return FLAGcxx . . $ ProteinDB/Residue#FLAG#(flgcxx . . $ ProteinDB/Residue#flg.); } //!< return flag (null,Ca,all) |
| 64 | void set_typecxx . . $ ProteinDB/Residue#set_type(44b6ea1973a07080).( char t ) { typcxx . . $ ProteinDB/Residue#typ. = t; } //!< set residue type (1-char) |
| 65 | void set_flagcxx . . $ ProteinDB/Residue#set_flag(45ad02ae88f64f66).( FLAGcxx . . $ ProteinDB/Residue#FLAG# t ) { flgcxx . . $ ProteinDB/Residue#flg. = char(t); } //!< set flag (null,Ca,all) |
| 66 | void data_importcxx . . $ ProteinDB/Residue#data_import(85c52e162fed56f9).( const char* d ); //!< import from char array |
| 67 | void data_exportcxx . . $ ProteinDB/Residue#data_export(f8c1bc12e132d234).( char* d ) const; //!< export to char array |
| 68 | bool is_nullcxx . . $ ProteinDB/Residue#is_null(50ce9a9e25b4a850).() const { return flgcxx . . $ ProteinDB/Residue#flg. == char(NONEcxx . . $ ProteinDB/Residue#NONE.); } //!< test for null |
| 69 | //! return 1-char residue type from 1 or 3 char string. Space on error. |
| 70 | static char residue_typecxx . . $ ProteinDB/Residue#residue_type(79d47a99472108eb).( const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String#& type ); |
| 71 | |
| 72 | /*! Class for describing a residue type mask, used to describe a |
| 73 | list of allowed residue types. */ |
| 74 | class TypeMaskcxx . . $ ProteinDB/Residue#TypeMask# { |
| 75 | public: |
| 76 | //! Initialise from a residue code, '?' for all |
| 77 | TypeMaskcxx . . $ ProteinDB/Residue#TypeMask#TypeMask(44b6ea1973a07080).( const char t ) { mskcxx . . $ ProteinDB/Residue#TypeMask#msk. = mskscxx . . $ ProteinDB/Residue#TypeMask#msks.[t&0x1f]; } |
| 78 | //! Return mask. Use '&' to test if a mask matches a type. |
| 79 | const int& maskcxx . . $ ProteinDB/Residue#TypeMask#mask(ec45a031f4e09d1e).() const { return mskcxx . . $ ProteinDB/Residue#TypeMask#msk.; } |
| 80 | private: |
| 81 | static const int mskscxx . . $ ProteinDB/Residue#TypeMask#msks.[32]; |
| 82 | int mskcxx . . $ ProteinDB/Residue#TypeMask#msk.; |
| 83 | }; |
| 84 | |
| 85 | private: |
| 86 | static const int ntypecxx . . $ ProteinDB/Residue#ntype. = 22; |
| 87 | static const char rtype1cxx . . $ ProteinDB/Residue#rtype1.[ntypecxx . . $ ProteinDB/Residue#ntype.], rtype3cxx . . $ ProteinDB/Residue#rtype3.[ntypecxx . . $ ProteinDB/Residue#ntype.][4]; |
| 88 | static void unpack_floatcxx . . $ ProteinDB/Residue#unpack_float(e356253467636b33).( const char* d, float& f ) { short s = ((short(d[0])<<8)&0xFF00) | ((short(d[1]))&0x00FF); f = float(s)/100.0; } |
| 89 | static void pack_floatcxx . . $ ProteinDB/Residue#pack_float(5942add0152f2c74).( char* d, const float& f ) { short s = lrintcxx . . $ lrint(e06fd2797df334dc).(100.0*f); d[0] = char((s>>8)&0x00FF); d[1] = char((s)&0x00FF); } |
| 90 | float nnxcxx . . $ ProteinDB/Residue#nnx., nnycxx . . $ ProteinDB/Residue#nny., nnzcxx . . $ ProteinDB/Residue#nnz., caxcxx . . $ ProteinDB/Residue#cax., caycxx . . $ ProteinDB/Residue#cay., cazcxx . . $ ProteinDB/Residue#caz., ccxcxx . . $ ProteinDB/Residue#ccx., ccycxx . . $ ProteinDB/Residue#ccy., cczcxx . . $ ProteinDB/Residue#ccz.; |
| 91 | char typcxx . . $ ProteinDB/Residue#typ., flgcxx . . $ ProteinDB/Residue#flg.; |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | /*! |
| 96 | Class for storing compact amino acid main chain information for use |
| 97 | with Top500 DB. The same class is used for storing residues in the |
| 98 | DB, and also for storing residues for searching against the DB. |
| 99 | This class stores a list of residues representing either a complete |
| 100 | chain or chains (in the DB) or a complete search fragment to be |
| 101 | searched against the DB. |
| 102 | */ |
| 103 | class Chaincxx . . $ ProteinDB/Chain# { |
| 104 | public: |
| 105 | //! Null constructor |
| 106 | Chaincxx . . $ ProteinDB/Chain#Chain(49f6e7a06ebc5aa8).() {} |
| 107 | //! Add a pdb file to this DBchain (NOTE: CHAINS ARE SHIFTED TO ORIGIN) |
| 108 | bool add_pdbcxx . . $ ProteinDB/Chain#add_pdb(af4b7e4d492b8d94).( const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String# file ); |
| 109 | //! Add a residue to this DBchain |
| 110 | void add_residuecxx . . $ ProteinDB/Chain#add_residue(e189c6ce620cc3e4).( const Residuecxx . . $ ProteinDB/Residue#& r ) { dbresiduescxx . . $ ProteinDB/Chain#dbresidues..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).( r ); } |
| 111 | //! Export DB to binary file |
| 112 | bool save_dbcxx . . $ ProteinDB/Chain#save_db(387d8eac660d7969).( const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String# file ) const; |
| 113 | //! Import DB from binary file |
| 114 | bool load_dbcxx . . $ ProteinDB/Chain#load_db(af4b7e4d492b8d94).( const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String# file ); |
| 115 | //! Import DB from binary file |
| 116 | //! Merge other residue coords with this one using given weights |
| 117 | bool mergecxx . . $ ProteinDB/Chain#merge(cf38c280d4a828cd).( const Chaincxx . . $ ProteinDB/Chain#& other, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& wgt ); |
| 118 | //! extract fragment of given length |
| 119 | Chaincxx . . $ ProteinDB/Chain# extractcxx . . $ ProteinDB/Chain#extract(9da133d3dfeb2795).( int offset, int len ) const; |
| 120 | //! check if fragment is continuous |
| 121 | bool is_continuouscxx . . $ ProteinDB/Chain#is_continuous(50ce9a9e25b4a850).() const; |
| 122 | //! Transform by rotation-translation operator |
| 123 | void transformcxx . . $ ProteinDB/Chain#transform(e19fd923a135bced).( const clippercxx . . $ clipper/::RTop_orthcxx . . $ clipper/RTop_orth#& rtop ); |
| 124 | //! get RTop to fit DB fragment to given fragment |
| 125 | void lsq_superposecxx . . $ ProteinDB/Chain#lsq_superpose(d5044e52db332d0b).( const Chaincxx . . $ ProteinDB/Chain#& frag ); |
| 126 | //! get RTop to fit DB fragment to given fragment with weights |
| 127 | void lsq_superposecxx . . $ ProteinDB/Chain#lsq_superpose(2ad2e7b6bf2bf24f).( const Chaincxx . . $ ProteinDB/Chain#& frag, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& wgts ); |
| 128 | //! Get rmsd versus other fragment |
| 129 | double rmsdcxx . . $ ProteinDB/Chain#rmsd(f10cf7d2d9696218).( const Chaincxx . . $ ProteinDB/Chain#& other ) const; |
| 130 | //! Get rmsd versus other fragment |
| 131 | double rmsdcxx . . $ ProteinDB/Chain#rmsd(e69f4725ed36a90c).( const Chaincxx . . $ ProteinDB/Chain#& other, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& wgts ) const; |
| 132 | //! Get residue by position in list |
| 133 | const Residuecxx . . $ ProteinDB/Residue#& operatorcxx . . $ ProteinDB/Chain#`operator[]`(793cb532a5be4d82).[] ( const int& i ) const { return dbresiduescxx . . $ ProteinDB/Chain#dbresidues.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; } |
| 134 | //! Set residue by position in list |
| 135 | Residuecxx . . $ ProteinDB/Residue#& operatorcxx . . $ ProteinDB/Chain#`operator[]`(c8a29b507e1ca93a).[] ( const int& i ) { return dbresiduescxx . . $ ProteinDB/Chain#dbresidues.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; } |
| 136 | //! Get number of residues in list |
| 137 | int sizecxx . . $ ProteinDB/Chain#size(455f465bc33b4cdf).() const { return dbresiduescxx . . $ ProteinDB/Chain#dbresidues..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); } |
| 138 | // output some debug info |
| 139 | void debugcxx . . $ ProteinDB/Chain#debug(83f5f38750778ac8).() const; |
| 140 | protected: |
| 141 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<Residuecxx . . $ ProteinDB/Residue#> dbresiduescxx . . $ ProteinDB/Chain#dbresidues.; |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | /*! |
| 146 | Class for storing compact amino acid main chain information for |
| 147 | use with Top500 DB. The same class is used for storing residues in |
| 148 | the DB, and also for storing residues for searching against the DB. |
| 149 | This class is an extension of Chain, which also adds the fast |
| 150 | distance matrix entries. These are filled out by calling the |
| 151 | calc_distances() method after the chain has been completely |
| 152 | assembled. |
| 153 | */ |
| 154 | class ChainDBcxx . . $ ProteinDB/ChainDB# : public Chaincxx . . $ ProteinDB/Chain# { |
| 155 | public: |
| 156 | static const int ndistcxx . . $ ProteinDB/ChainDB#ndist. = 20; |
| 157 | struct DistVeccxx . . $ ProteinDB/ChainDB#DistVec# { float datacxx . . $ ProteinDB/ChainDB#DistVec#data.[ChainDBcxx . . $ ProteinDB/ChainDB#::ndistcxx . . $ ProteinDB/ChainDB#ndist.]; }; |
| 158 | //! Null constructor |
| 159 | ChainDBcxx . . $ ProteinDB/ChainDB#ChainDB(49f6e7a06ebc5aa8).() {} |
| 160 | //! Constructor: from Chain |
| 161 | ChainDBcxx . . $ ProteinDB/ChainDB#ChainDB(d5044e52db332d0b).( const Chaincxx . . $ ProteinDB/Chain#& chain ) : Chaincxx . . $ ProteinDB/Chain#( chain ) { calc_distancescxx . . $ ProteinDB/ChainDB#calc_distances(49f6e7a06ebc5aa8).(); } |
| 162 | //! Constructor: from binary DB file name |
| 163 | ChainDBcxx . . $ ProteinDB/ChainDB#ChainDB(b4f7366dea7cb22b).( const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String# file ) { initcxx . . $ ProteinDB/ChainDB#init(b4f7366dea7cb22b).( file ); } |
| 164 | //! Initialiser: from binary DB file name |
| 165 | void initcxx . . $ ProteinDB/ChainDB#init(b4f7366dea7cb22b).( const clippercxx . . $ clipper/::Stringcxx . . $ clipper/String# file ); |
| 166 | //! calculate the distance matrix elements |
| 167 | void calc_distancescxx . . $ ProteinDB/ChainDB#calc_distances(49f6e7a06ebc5aa8).(); |
| 168 | //! score a fragment against the nth fragment in the DB |
| 169 | double score_distancecxx . . $ ProteinDB/ChainDB#score_distance(bac24c2f20cdd79).( const ChainDBcxx . . $ ProteinDB/ChainDB#& frag, int offset ) const; |
| 170 | //! score a fragment against the nth fragment in the DB with cutoff |
| 171 | double score_distancecxx . . $ ProteinDB/ChainDB#score_distance(742450ded54d58dd).( const ChainDBcxx . . $ ProteinDB/ChainDB#& frag, int offset, double scut ) const; |
| 172 | //! score a fragment against the nth fragment in the DB with residue masks |
| 173 | double score_distancecxx . . $ ProteinDB/ChainDB#score_distance(d27a18fa259d6d52).( const ChainDBcxx . . $ ProteinDB/ChainDB#& frag, int offset, double scut, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<Residuecxx . . $ ProteinDB/Residue#::TypeMaskcxx . . $ ProteinDB/Residue#TypeMask#>& types ) const; |
| 174 | //! return list of tentative fragment offsets matching a given fragment |
| 175 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> match_fragment_preliminarycxx . . $ ProteinDB/ChainDB#match_fragment_preliminary(b36e9d25d896907f).( const ChainDBcxx . . $ ProteinDB/ChainDB#& fragdb, int nhit ) const; |
| 176 | //! return the best DB fragments matching a given fragment |
| 177 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<Chaincxx . . $ ProteinDB/Chain#> match_fragmentcxx . . $ ProteinDB/ChainDB#match_fragment(335f88576ac20a8d).( const ChainDBcxx . . $ ProteinDB/ChainDB#& fragdb, int nlsq, int nhit=0 ) const; |
| 178 | protected: |
| 179 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<DistVeccxx . . $ ProteinDB/ChainDB#DistVec#> dbdistvecscxx . . $ ProteinDB/ChainDB#dbdistvecs.; |
| 180 | }; |
| 181 | |
| 182 | |
| 183 | } // namespace ProteinDB |
| 184 | |
| 185 | |
| 186 | #endif |