Debian Codegraph @

ideal/zo-rama.hh

raw symbols SCIP
1 /*
2 * ideal/zo-rama.hh
3 *
4 * Copyright 2017 by Medical Research Council
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 * 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 ZO_RAMA_HH
28 #define ZO_RAMA_HHcxx . . $ `ideal/zo-rama.hh:28:9`!
29
30 #include <utility>
31 #include <vector>
32 #include <stdexcept>
33 #include <string>
34 #include <map>
35 #include <fstream>
36 #include <cmath>
37
38 #define PNG_SKIP_SETJMP_CHECKcxx . . $ `ideal/zo-rama.hh:38:9`! true
39 #define PNG_DEBUGcxx . . $ `ideal/zo-rama.hh:39:9`! 3
40 #include <png.h>
41
42 #include "utils/coot-utils.hh"cxx . . $ `<file>/utils/coot-utils.hh`/
43 #include "phi-psi.hh"cxx . . $ `<file>/ideal/phi-psi.hh`/
44
45 namespace zocxx . . $ zo/ {
46
47 typedef double realtypecxx . . $ zo/realtype#;
48
49 class rama_coeffscxx . . $ zo/rama_coeffs# {
50 public:
51 double A_cccxx . . $ zo/rama_coeffs#A_cc.;
52 double A_cscxx . . $ zo/rama_coeffs#A_cs.;
53 double A_sccxx . . $ zo/rama_coeffs#A_sc.;
54 double A_sscxx . . $ zo/rama_coeffs#A_ss.;
55 int order_phicxx . . $ zo/rama_coeffs#order_phi., order_psicxx . . $ zo/rama_coeffs#order_psi.;
56
57 rama_coeffscxx . . $ zo/rama_coeffs#rama_coeffs(49f6e7a06ebc5aa8).() {}
58 rama_coeffscxx . . $ zo/rama_coeffs#rama_coeffs(343e06826365af61).(int order_phi_in, int order_psi_in,
59 const double &A_1, const double &A_2,
60 const double &A_3, const double &A_4) :
61 A_cccxx . . $ zo/rama_coeffs#A_cc.(A_1), A_cscxx . . $ zo/rama_coeffs#A_cs.(A_2), A_sccxx . . $ zo/rama_coeffs#A_sc.(A_3), A_sscxx . . $ zo/rama_coeffs#A_ss.(A_4),
62 order_phicxx . . $ zo/rama_coeffs#order_phi.(order_phi_in), order_psicxx . . $ zo/rama_coeffs#order_psi.(order_psi_in) { }
63
64 realtypecxx . . $ zo/realtype# valuecxx . . $ zo/rama_coeffs#value(99c14de11d83fb75).(const realtypecxx . . $ zo/realtype# &rama_phi, const realtypecxx . . $ zo/realtype# &rama_psi) const {
65
66 // things here can be sped up because
67 //
68 // cos(2a) = cos^2(a) - sin^2(a)
69 // sin(2a) = 2cos(a)sin(a)
70 //
71 // or more generally
72 //
73 // cos(a+b) = cos(a)cos(b) - sin(a)sin(b)
74 // sin(a+b) = cos(a)sin(b) + sin(a)cos(b)
75
76 double v;
77 v = A_cccxx . . $ zo/rama_coeffs#A_cc. * cosf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * cosf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
78 v += A_cscxx . . $ zo/rama_coeffs#A_cs. * cosf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * sinf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
79 v += A_sccxx . . $ zo/rama_coeffs#A_sc. * sinf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * cosf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
80 v += A_sscxx . . $ zo/rama_coeffs#A_ss. * sinf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * sinf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
81
82 return v;
83 }
84
85 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#, realtypecxx . . $ zo/realtype#> dfcxx . . $ zo/rama_coeffs#df(d877fb70c988af79).(const realtypecxx . . $ zo/realtype# &rama_phi, const realtypecxx . . $ zo/realtype# &rama_psi) const {
86
87 realtypecxx . . $ zo/realtype# d1 = 0, d2 = 0;
88 d1 = A_cccxx . . $ zo/rama_coeffs#A_cc. * order_phicxx . . $ zo/rama_coeffs#order_phi. * -sinf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * cosf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
89 d1 += A_cscxx . . $ zo/rama_coeffs#A_cs. * order_phicxx . . $ zo/rama_coeffs#order_phi. * -sinf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * sinf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
90 d1 += A_sccxx . . $ zo/rama_coeffs#A_sc. * order_phicxx . . $ zo/rama_coeffs#order_phi. * cosf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * cosf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
91 d1 += A_sscxx . . $ zo/rama_coeffs#A_ss. * order_phicxx . . $ zo/rama_coeffs#order_phi. * cosf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * sinf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
92
93 d2 = A_cccxx . . $ zo/rama_coeffs#A_cc. * cosf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * order_psicxx . . $ zo/rama_coeffs#order_psi. * -sinf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
94 d2 += A_cscxx . . $ zo/rama_coeffs#A_cs. * cosf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * order_psicxx . . $ zo/rama_coeffs#order_psi. * cosf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
95 d2 += A_sccxx . . $ zo/rama_coeffs#A_sc. * sinf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * order_psicxx . . $ zo/rama_coeffs#order_psi. * -sinf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
96 d2 += A_sscxx . . $ zo/rama_coeffs#A_ss. * sinf(order_phicxx . . $ zo/rama_coeffs#order_phi. * rama_phi) * order_psicxx . . $ zo/rama_coeffs#order_psi. * cosf(order_psicxx . . $ zo/rama_coeffs#order_psi. * rama_psi);
97
98 return stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#, realtypecxx . . $ zo/realtype#> (d1, d2);
99 }
100 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> df_numericalcxx . . $ zo/rama_coeffs#df_numerical(d877fb70c988af79).(const realtypecxx . . $ zo/realtype# &rama_phi,
101 const realtypecxx . . $ zo/realtype# &rama_psi) const {
102 realtypecxx . . $ zo/realtype# bit = 0.01;
103 realtypecxx . . $ zo/realtype# rc_1 = valuecxx . . $ zo/rama_coeffs#value(99c14de11d83fb75).(rama_phi-bit, rama_psi);
104 realtypecxx . . $ zo/realtype# rc_2 = valuecxx . . $ zo/rama_coeffs#value(99c14de11d83fb75).(rama_phi+bit, rama_psi);
105 realtypecxx . . $ zo/realtype# rc_3 = valuecxx . . $ zo/rama_coeffs#value(99c14de11d83fb75).(rama_phi, rama_psi-bit);
106 realtypecxx . . $ zo/realtype# rc_4 = valuecxx . . $ zo/rama_coeffs#value(99c14de11d83fb75).(rama_phi, rama_psi+bit);
107 realtypecxx . . $ zo/realtype# d1 = (rc_2-rc_1)/(2.0 * bit);
108 realtypecxx . . $ zo/realtype# d2 = (rc_4-rc_3)/(2.0 * bit);
109 return stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#, realtypecxx . . $ zo/realtype#> (d1, d2);
110 }
111 };
112
113
114 const int N_COEFFScxx . . $ zo/N_COEFFS. = 5;
115
116 // can throw a runtime_error exception.
117 class rama_tablecxx . . $ zo/rama_table# {
118
119 public:
120 stdcxx . . $ std/::vectorcxx . . $ std/vector#<rama_coeffscxx . . $ zo/rama_coeffs#> rama_veccxx . . $ zo/rama_table#rama_vec.;
121
122 // this can throw a runtime_error
123 rama_tablecxx . . $ zo/rama_table#rama_table(49f6e7a06ebc5aa8).() {
124 // old style single table in file
125 // std::string fn = "all-non-pre-pro.tab";
126 // init(fn);
127 }
128
129 void make_a_pngcxx . . $ zo/rama_table#make_a_png(8afd1a062aafdef8).(int n_pixels, const stdcxx . . $ std/::stringcxx . . $ std/string# &file_name) const;
130
131 void test_analytical_derivscxx . . $ zo/rama_table#test_analytical_derivs(83f5f38750778ac8).() const;
132
133 realtypecxx . . $ zo/realtype# valuecxx . . $ zo/rama_table#value(99c14de11d83fb75).(const realtypecxx . . $ zo/realtype# &phi_in, const realtypecxx . . $ zo/realtype# &psi_in) const {
134 realtypecxx . . $ zo/realtype# sum = 0;
135 for (stdcxx . . $ std/::size_tcxx . . $ std/size_t# i=0; i<rama_veccxx . . $ zo/rama_table#rama_vec..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
136 sum += rama_veccxx . . $ zo/rama_table#rama_vec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].valuecxx . . $ zo/rama_coeffs#value(99c14de11d83fb75).(phi_in, psi_in);
137 }
138 return sum;
139 }
140
141 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> dfcxx . . $ zo/rama_table#df(d877fb70c988af79).(const realtypecxx . . $ zo/realtype# &phi_in, const realtypecxx . . $ zo/realtype# &psi_in) const {
142 realtypecxx . . $ zo/realtype# sum_1 = 0;
143 realtypecxx . . $ zo/realtype# sum_2 = 0;
144 for (stdcxx . . $ std/::size_tcxx . . $ std/size_t# i=0; i<rama_veccxx . . $ zo/rama_table#rama_vec..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
145 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> v = rama_veccxx . . $ zo/rama_table#rama_vec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].dfcxx . . $ zo/rama_coeffs#df(d877fb70c988af79).(phi_in, psi_in);
146 sum_1 += v.firstcxx . . $ std/pair#first.;
147 sum_2 += v.secondcxx . . $ std/pair#second.;
148 }
149 return stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> (sum_1, sum_2);
150 }
151
152 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> df_numericalcxx . . $ zo/rama_table#df_numerical(d877fb70c988af79).(const realtypecxx . . $ zo/realtype# &phi_in, const realtypecxx . . $ zo/realtype# &psi_in) const {
153 realtypecxx . . $ zo/realtype# sum_1 = 0;
154 realtypecxx . . $ zo/realtype# sum_2 = 0;
155 for (stdcxx . . $ std/::size_tcxx . . $ std/size_t# i=0; i<rama_veccxx . . $ zo/rama_table#rama_vec..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
156 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> v = rama_veccxx . . $ zo/rama_table#rama_vec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].df_numericalcxx . . $ zo/rama_coeffs#df_numerical(d877fb70c988af79).(phi_in, psi_in);
157 sum_1 += v.firstcxx . . $ std/pair#first.;
158 sum_2 += v.firstcxx . . $ std/pair#first.;
159 }
160 return stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> (sum_1, sum_2);
161
162 }
163
164 // this can throw a runtime_error.
165 //
166 void readcxx . . $ zo/rama_table#read(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &file_name);
167
168 // this can throw a runtime_error
169 void initcxx . . $ zo/rama_table#init(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &local_file_name) {
170 stdcxx . . $ std/::stringcxx . . $ std/string# dir1 = cootcxx . . $ coot/::package_data_dircxx . . $ coot/package_data_dir(efd28698952f529a).();
171 stdcxx . . $ std/::stringcxx . . $ std/string# dir2 = cootcxx . . $ coot/::utilcxx . . $ coot/util/::append_dir_dircxx . . $ coot/util/append_dir_dir(203b42cd324c6c40).(dir1, "data"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
172 stdcxx . . $ std/::stringcxx . . $ std/string# dir3 = cootcxx . . $ coot/::utilcxx . . $ coot/util/::append_dir_dircxx . . $ coot/util/append_dir_dir(203b42cd324c6c40).(dir2, "rama"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
173 stdcxx . . $ std/::stringcxx . . $ std/string# dir4 = cootcxx . . $ coot/::utilcxx . . $ coot/util/::append_dir_dircxx . . $ coot/util/append_dir_dir(203b42cd324c6c40).(dir3, "zo-tables"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
174
175 stdcxx . . $ std/::stringcxx . . $ std/string# full = cootcxx . . $ coot/::utilcxx . . $ coot/util/::append_dir_filecxx . . $ coot/util/append_dir_file(203b42cd324c6c40).(dir4, local_file_name);
176 readcxx . . $ zo/rama_table#read(9c546c94e5fcce4e).(full);
177 }
178
179 };
180
181 // void make_a_png(const rama_coeffs &rama_coeff_table[N_COEFFS][N_COEFFS],
182 // int width, int height, const std::string &file_name);
183
184 void write_png_filecxx . . $ zo/write_png_file(716104b43162c446).(int width, int height, png_bytepcxx . . $ png_bytep# *row_pointers,
185 const stdcxx . . $ std/::stringcxx . . $ std/string# &file_name);
186
187 // rama_table_set is a container for rama tables.
188 // each rama table is for a particular residue type (e.g. pre-PRO, GLY, PRO, LIV etc)
189 // this rama_table_set is a container for these different types.
190 // we will select the right table based on the residue type
191 //
192 class rama_table_setcxx . . $ zo/rama_table_set# {
193 public:
194 // enum type_t { ALL_NON_PRE_PRO, PRE_PRO, LIV };
195 stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, rama_tablecxx . . $ zo/rama_table#> table_mapcxx . . $ zo/rama_table_set#table_map.;
196
197 rama_table_setcxx . . $ zo/rama_table_set#rama_table_set(49f6e7a06ebc5aa8).() { initcxx . . $ zo/rama_table_set#init(49f6e7a06ebc5aa8).(); }
198
199 stdcxx . . $ std/::stringcxx . . $ std/string# get_residue_typecxx . . $ zo/rama_table_set#get_residue_type(ee8c6c2661a93592).(const stdcxx . . $ std/::stringcxx . . $ std/string# &this_residue_type,
200 const stdcxx . . $ std/::stringcxx . . $ std/string# &next_residue_type) const;
201
202 // fill the table_map with tables
203 //
204 // should this be public?
205 //
206 void initcxx . . $ zo/rama_table_set#init(49f6e7a06ebc5aa8).();
207
208 // residue type eg "ALL!nP" "ALLnP" "GLY!nP" "GLYnP" "PRO!nP"
209 //
210 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> dfcxx . . $ zo/rama_table_set#df(9634d3235c93ae68).(const stdcxx . . $ std/::stringcxx . . $ std/string# &residue_type,
211 const realtypecxx . . $ zo/realtype# &phi, const realtypecxx . . $ zo/realtype# &psi) const;
212
213 stdcxx . . $ std/::paircxx . . $ std/pair#<realtypecxx . . $ zo/realtype#,realtypecxx . . $ zo/realtype#> dfcxx . . $ zo/rama_table_set#df(762ee3dcb90d9432).(const cootcxx . . $ coot/::phi_psi_tcxx . . $ coot/phi_psi_t# &pp,
214 const stdcxx . . $ std/::stringcxx . . $ std/string# &residue_type) const {
215 return dfcxx . . $ zo/rama_table_set#df(9634d3235c93ae68).(residue_type, pp.phicxx . . $ coot/phi_psi_t#phi., pp.psicxx . . $ coot/phi_psi_t#psi.);
216 }
217
218 // residue type eg "ALL!nP" "ALLnP" "GLY!nP" "GLYnP" "PRO!nP"
219 //
220 realtypecxx . . $ zo/realtype# valuecxx . . $ zo/rama_table_set#value(d728f85a2b862bb5).(const stdcxx . . $ std/::stringcxx . . $ std/string# &residue_type, const realtypecxx . . $ zo/realtype# &phi, const realtypecxx . . $ zo/realtype# &psi) const;
221 realtypecxx . . $ zo/realtype# valuecxx . . $ zo/rama_table_set#value(6d82d2ddce3721c8).(const cootcxx . . $ coot/::phi_psi_tcxx . . $ coot/phi_psi_t# &pp, const stdcxx . . $ std/::stringcxx . . $ std/string# &residue_type) const {
222 return valuecxx . . $ zo/rama_table_set#value(d728f85a2b862bb5).(residue_type, pp.phicxx . . $ coot/phi_psi_t#phi., pp.psicxx . . $ coot/phi_psi_t#psi.);
223 }
224
225 };
226 }
227
228 #endif /// ZO_RAMA_HH