| 1 | #ifndef ISOLDE_ROTA
|
|---|
| 2 | #define ISOLDE_ROTA
|
|---|
| 3 |
|
|---|
| 4 | #include <thread> //testing
|
|---|
| 5 |
|
|---|
| 6 | #include <string>
|
|---|
| 7 | #include "../atomic_cpp/dihedral.h"
|
|---|
| 8 | #include "../atomic_cpp/dihedral_mgr.h"
|
|---|
| 9 | #include "../interpolation/nd_interp.h"
|
|---|
| 10 | #include "../colors.h"
|
|---|
| 11 | #include "../geometry/geometry.h"
|
|---|
| 12 | #include <atomstruct/destruct.h>
|
|---|
| 13 | #include <atomstruct/string_types.h>
|
|---|
| 14 | #include <pyinstance/PythonInstance.declare.h>
|
|---|
| 15 | #include <atomstruct/Residue.h>
|
|---|
| 16 | #include <atomstruct/Bond.h>
|
|---|
| 17 | using namespace atomstruct;
|
|---|
| 18 |
|
|---|
| 19 | namespace isolde
|
|---|
| 20 | {
|
|---|
| 21 |
|
|---|
| 22 | class Rota_Mgr;
|
|---|
| 23 |
|
|---|
| 24 | struct Rota_Def
|
|---|
| 25 | {
|
|---|
| 26 | size_t n_chi;
|
|---|
| 27 | bool symmetric;
|
|---|
| 28 | Rota_Def() {}
|
|---|
| 29 | Rota_Def(size_t n, bool sym): n_chi(n), symmetric(sym) {}
|
|---|
| 30 | };
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | class Rotamer: public pyinstance::PythonInstance<Rotamer>
|
|---|
| 34 | {
|
|---|
| 35 |
|
|---|
| 36 | public:
|
|---|
| 37 | Rotamer() {} // null constructor
|
|---|
| 38 | ~Rotamer() { auto du = DestructionUser(this); }
|
|---|
| 39 | Rotamer(Residue *res, Rota_Mgr *mgr);
|
|---|
| 40 |
|
|---|
| 41 | const std::vector<Dihedral *> &dihedrals() {return _chi_dihedrals; }
|
|---|
| 42 | const size_t& n_chi() const { return _def->n_chi; }
|
|---|
| 43 | void angles(std::vector<double> &angles) const;
|
|---|
| 44 | void angles(double *angles) const;
|
|---|
| 45 | std::vector<double> angles() const;
|
|---|
| 46 | float32_t score() const;
|
|---|
| 47 | Residue* residue() const {return _residue;}
|
|---|
| 48 | Bond* ca_cb_bond() const { return _chi_dihedrals[0]->axial_bond(); }
|
|---|
| 49 | bool is_symmetric() const {return _def->symmetric;}
|
|---|
| 50 |
|
|---|
| 51 | private:
|
|---|
| 52 | Residue* _residue;
|
|---|
| 53 | Rota_Mgr* _mgr;
|
|---|
| 54 | std::vector<Dihedral *> _chi_dihedrals;
|
|---|
| 55 | Rota_Def *_def;
|
|---|
| 56 | // size_t _n_chi;
|
|---|
| 57 | // bool _symmetric = false;
|
|---|
| 58 |
|
|---|
| 59 | }; // class Rotamer
|
|---|
| 60 |
|
|---|
| 61 | class Rota_Mgr: public DestructionObserver, public pyinstance::PythonInstance<Rota_Mgr>
|
|---|
| 62 | {
|
|---|
| 63 |
|
|---|
| 64 | public:
|
|---|
| 65 | enum Rota_Bins {FAVORED=0, ALLOWED=1, OUTLIER=2, BIN_NA=-1};
|
|---|
| 66 | Rota_Mgr() {} // null constructor
|
|---|
| 67 | Rota_Mgr(Proper_Dihedral_Mgr *dmgr): _dmgr(dmgr) {};
|
|---|
| 68 | ~Rota_Mgr();
|
|---|
| 69 |
|
|---|
| 70 | struct cutoffs
|
|---|
| 71 | {
|
|---|
| 72 | double allowed;
|
|---|
| 73 | double log_allowed;
|
|---|
| 74 | double outlier;
|
|---|
| 75 | double log_outlier;
|
|---|
| 76 | cutoffs() {}
|
|---|
| 77 | cutoffs(double a, double o): allowed(a), log_allowed(log(a)), outlier(o), log_outlier(log(o)) {}
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | void set_cutoffs(const double &allowed, const double &outlier) {_cutoffs = cutoffs(allowed, outlier);}
|
|---|
| 81 | cutoffs* get_cutoffs() {return &_cutoffs;}
|
|---|
| 82 |
|
|---|
| 83 | void set_colors(uint8_t *max, uint8_t *mid, uint8_t *min);
|
|---|
| 84 | colors::colormap *get_colors() {return &_colors;}
|
|---|
| 85 |
|
|---|
| 86 | void add_rotamer_def(const std::string &resname, size_t n_chi, bool symmetric);
|
|---|
| 87 | Rota_Def* get_rotamer_def(const std::string &resname);
|
|---|
| 88 | Rota_Def* get_rotamer_def(const ResName &resname);
|
|---|
| 89 | Rotamer* new_rotamer(Residue* residue);
|
|---|
| 90 | Rotamer* get_rotamer(Residue* residue);
|
|---|
| 91 |
|
|---|
| 92 | void add_interpolator(const std::string &resname, const size_t &dim,
|
|---|
| 93 | uint32_t *n, double *min, double *max, double *data);
|
|---|
| 94 | RegularGridInterpolator<double>* get_interpolator(const std::string &resname)
|
|---|
| 95 | {
|
|---|
| 96 | return &(_interpolators.at(resname));
|
|---|
| 97 | }
|
|---|
| 98 | RegularGridInterpolator<double>* get_interpolator(const ResName &resname)
|
|---|
| 99 | {
|
|---|
| 100 | return &(_interpolators.at(std::string(resname)));
|
|---|
| 101 | }
|
|---|
| 102 | Proper_Dihedral_Mgr* dihedral_mgr() { return _dmgr; }
|
|---|
| 103 | void validate(Rotamer** rotamers, size_t n, double* scores);
|
|---|
| 104 | void validate(Residue** residues, size_t n, double* scores);
|
|---|
| 105 |
|
|---|
| 106 | /**********TESTING***********/
|
|---|
| 107 | void validate_threaded(Rotamer **rotamers, size_t n, double* scores);
|
|---|
| 108 | bool thread_running() const { return _thread_running; }
|
|---|
| 109 | bool thread_done() const { return _thread_done; }
|
|---|
| 110 | void finalize_thread() { _validation_thread.join(); _thread_running=false; }
|
|---|
| 111 | /******END TESTING***********/
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | int32_t bin_score(const double &score);
|
|---|
| 115 | void color_by_score(double *score, size_t n, uint8_t *out);
|
|---|
| 116 | virtual void destructors_done(const std::set<void*>& destroyed);
|
|---|
| 117 |
|
|---|
| 118 | private:
|
|---|
| 119 | Proper_Dihedral_Mgr* _dmgr;
|
|---|
| 120 | std::unordered_map<Residue*, Rotamer*> _residue_to_rotamer;
|
|---|
| 121 | std::unordered_map<std::string, Rota_Def> _resname_to_rota_def;
|
|---|
| 122 | std::unordered_map<std::string, RegularGridInterpolator<double>> _interpolators;
|
|---|
| 123 | colors::colormap _colors;
|
|---|
| 124 | cutoffs _cutoffs;
|
|---|
| 125 |
|
|---|
| 126 | /*************TESTING********/
|
|---|
| 127 | void _validate_from_thread(Rotamer **rotamers, size_t n, double* scores);
|
|---|
| 128 | std::thread _validation_thread;
|
|---|
| 129 | bool _thread_done = false;
|
|---|
| 130 | bool _thread_running = false;
|
|---|
| 131 |
|
|---|
| 132 | /*********END TESTING********/
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 | }; // class Rota_Mgr
|
|---|
| 136 | } //namespace isolde
|
|---|
| 137 |
|
|---|
| 138 | #endif //ISOLDE_ROTA
|
|---|