15 #ifndef INCLUDED_core_pack_dunbrack_RotamericSingleResidueDunbrackLibrary_tmpl_hh
16 #define INCLUDED_core_pack_dunbrack_RotamericSingleResidueDunbrackLibrary_tmpl_hh
18 #if (defined WIN32) && (!defined WIN_PYROSETTA)
19 #define ZLIB_WINAPI // REQUIRED FOR WINDOWS
39 #include <basic/basic.hh>
40 #include <basic/interpolate.hh>
41 #include <basic/options/option.hh>
42 #include <basic/options/keys/corrections.OptionKeys.gen.hh>
45 #include <ObjexxFCL/FArray2D.hh>
46 #include <ObjexxFCL/FArray3D.hh>
49 #include <utility/exit.hh>
50 #include <utility/io/izstream.hh>
51 #include <utility/io/ozstream.hh>
52 #include <utility/LexicographicalIterator.hh>
55 #include <numeric/random/random.hh>
56 #include <numeric/xyz.functions.hh>
57 #include <numeric/interpolation/spline/Bicubic_spline.hh>
60 #include <boost/cstdint.hpp>
63 #include <platform/types.hh>
136 #include <utility/Bound.fwd.hh>
137 #include <utility/Bound.hh>
138 #include <utility/LexicographicalIterator.fwd.hh>
139 #include <utility/assert.hh>
140 #include <utility/down_cast.hh>
141 #include <utility/fixedsizearray1.fwd.hh>
142 #include <utility/fixedsizearray1.hh>
143 #include <utility/stream_util.hh>
144 #include <utility/string_util.hh>
145 #include <utility/vector1.fwd.hh>
146 #include <utility/vector1.hh>
147 #include <utility/vector1_bool.hh>
148 #include <utility/vectorL.fwd.hh>
149 #include <utility/vectorL.hh>
150 #include <utility/vectorL_Selector.hh>
151 #include <utility/vectorL_bool.hh>
152 #include <utility/file/FileName.fwd.hh>
153 #include <utility/file/FileName.hh>
154 #include <utility/file/PathName.fwd.hh>
155 #include <utility/file/PathName.hh>
156 #include <utility/file/gzip_util.hh>
157 #include <utility/io/irstream.fwd.hh>
158 #include <utility/io/irstream.hh>
159 #include <utility/io/izstream.fwd.hh>
160 #include <utility/io/mpistream.hh>
161 #include <utility/io/mpistream.ipp>
162 #include <utility/io/orstream.fwd.hh>
163 #include <utility/io/orstream.hh>
164 #include <utility/io/ozstream.fwd.hh>
165 #include <utility/io/zipstream.hpp>
166 #include <utility/io/zipstream.ipp>
167 #include <utility/keys/AutoKey.fwd.hh>
168 #include <utility/keys/AutoKey.hh>
169 #include <utility/keys/Key.fwd.hh>
170 #include <utility/keys/Key.hh>
171 #include <utility/keys/Key2Tuple.fwd.hh>
172 #include <utility/keys/Key2Tuple.hh>
173 #include <utility/keys/Key3Tuple.fwd.hh>
174 #include <utility/keys/Key3Tuple.hh>
175 #include <utility/keys/Key4Tuple.fwd.hh>
176 #include <utility/keys/Key4Tuple.hh>
177 #include <utility/keys/KeyLess.fwd.hh>
178 #include <utility/keys/KeyLookup.fwd.hh>
179 #include <utility/keys/KeyLookup.hh>
180 #include <utility/keys/NoClient.fwd.hh>
181 #include <utility/keys/NoClient.hh>
182 #include <utility/keys/SmallKeyVector.fwd.hh>
183 #include <utility/keys/SmallKeyVector.hh>
184 #include <utility/keys/UserKey.fwd.hh>
185 #include <utility/keys/VariantKey.fwd.hh>
186 #include <utility/keys/VariantKey.hh>
187 #include <utility/options/AnyOption.fwd.hh>
188 #include <utility/options/AnyOption.hh>
189 #include <utility/options/AnyVectorOption.fwd.hh>
190 #include <utility/options/AnyVectorOption.hh>
191 #include <utility/options/BooleanOption.fwd.hh>
192 #include <utility/options/BooleanOption.hh>
193 #include <utility/options/BooleanVectorOption.fwd.hh>
194 #include <utility/options/BooleanVectorOption.hh>
195 #include <utility/options/FileOption.fwd.hh>
196 #include <utility/options/FileOption.hh>
197 #include <utility/options/FileVectorOption.fwd.hh>
198 #include <utility/options/FileVectorOption.hh>
199 #include <utility/options/IntegerOption.fwd.hh>
200 #include <utility/options/IntegerOption.hh>
201 #include <utility/options/IntegerVectorOption.fwd.hh>
202 #include <utility/options/IntegerVectorOption.hh>
203 #include <utility/options/Option.fwd.hh>
204 #include <utility/options/Option.hh>
205 #include <utility/options/OptionCollection.fwd.hh>
206 #include <utility/options/OptionCollection.hh>
207 #include <utility/options/PathOption.fwd.hh>
208 #include <utility/options/PathOption.hh>
209 #include <utility/options/PathVectorOption.fwd.hh>
210 #include <utility/options/PathVectorOption.hh>
211 #include <utility/options/RealOption.fwd.hh>
212 #include <utility/options/RealOption.hh>
213 #include <utility/options/RealVectorOption.fwd.hh>
214 #include <utility/options/RealVectorOption.hh>
215 #include <utility/options/ScalarOption.fwd.hh>
216 #include <utility/options/ScalarOption.hh>
217 #include <utility/options/ScalarOption_T_.fwd.hh>
218 #include <utility/options/ScalarOption_T_.hh>
219 #include <utility/options/StringOption.fwd.hh>
220 #include <utility/options/StringOption.hh>
221 #include <utility/options/StringVectorOption.fwd.hh>
222 #include <utility/options/StringVectorOption.hh>
223 #include <utility/options/VariantOption.fwd.hh>
224 #include <utility/options/VariantOption.hh>
225 #include <utility/options/VectorOption.fwd.hh>
226 #include <utility/options/VectorOption.hh>
227 #include <utility/options/VectorOption_T_.fwd.hh>
228 #include <utility/options/VectorOption_T_.hh>
229 #include <utility/options/mpi_stderr.hh>
230 #include <utility/options/keys/AnyOptionKey.fwd.hh>
231 #include <utility/options/keys/AnyOptionKey.hh>
232 #include <utility/options/keys/AnyVectorOptionKey.fwd.hh>
233 #include <utility/options/keys/AnyVectorOptionKey.hh>
234 #include <utility/options/keys/BooleanOptionKey.fwd.hh>
235 #include <utility/options/keys/BooleanOptionKey.hh>
236 #include <utility/options/keys/BooleanVectorOptionKey.fwd.hh>
237 #include <utility/options/keys/BooleanVectorOptionKey.hh>
238 #include <utility/options/keys/FileOptionKey.fwd.hh>
239 #include <utility/options/keys/FileOptionKey.hh>
240 #include <utility/options/keys/FileVectorOptionKey.fwd.hh>
241 #include <utility/options/keys/FileVectorOptionKey.hh>
242 #include <utility/options/keys/IntegerOptionKey.fwd.hh>
243 #include <utility/options/keys/IntegerOptionKey.hh>
244 #include <utility/options/keys/IntegerVectorOptionKey.fwd.hh>
245 #include <utility/options/keys/IntegerVectorOptionKey.hh>
246 #include <utility/options/keys/OptionKey.fwd.hh>
247 #include <utility/options/keys/OptionKey.hh>
248 #include <utility/options/keys/OptionKeys.hh>
249 #include <utility/options/keys/PathOptionKey.fwd.hh>
250 #include <utility/options/keys/PathOptionKey.hh>
251 #include <utility/options/keys/PathVectorOptionKey.fwd.hh>
252 #include <utility/options/keys/PathVectorOptionKey.hh>
253 #include <utility/options/keys/RealOptionKey.fwd.hh>
254 #include <utility/options/keys/RealOptionKey.hh>
255 #include <utility/options/keys/RealVectorOptionKey.fwd.hh>
256 #include <utility/options/keys/RealVectorOptionKey.hh>
257 #include <utility/options/keys/ScalarOptionKey.fwd.hh>
258 #include <utility/options/keys/ScalarOptionKey.hh>
259 #include <utility/options/keys/StringOptionKey.fwd.hh>
260 #include <utility/options/keys/StringOptionKey.hh>
261 #include <utility/options/keys/StringVectorOptionKey.fwd.hh>
262 #include <utility/options/keys/StringVectorOptionKey.hh>
263 #include <utility/options/keys/VectorOptionKey.fwd.hh>
264 #include <utility/options/keys/VectorOptionKey.hh>
265 #include <utility/options/keys/all.hh>
266 #include <utility/pointer/ReferenceCount.fwd.hh>
267 #include <utility/pointer/ReferenceCount.hh>
268 #include <utility/pointer/access_ptr.fwd.hh>
269 #include <utility/pointer/access_ptr.hh>
270 #include <utility/pointer/owning_ptr.functions.hh>
271 #include <utility/pointer/owning_ptr.fwd.hh>
272 #include <utility/pointer/owning_ptr.hh>
273 #include <utility/signals/BufferedSignalHub.fwd.hh>
274 #include <utility/signals/BufferedSignalHub.hh>
275 #include <utility/signals/Link.fwd.hh>
276 #include <utility/signals/Link.hh>
277 #include <utility/signals/LinkUnit.fwd.hh>
278 #include <utility/signals/LinkUnit.hh>
279 #include <utility/signals/SignalHub.fwd.hh>
280 #include <utility/signals/SignalHub.hh>
281 #include <numeric/NumericTraits.hh>
282 #include <numeric/constants.hh>
283 #include <numeric/conversions.hh>
284 #include <numeric/numeric.functions.hh>
285 #include <numeric/sphericalVector.fwd.hh>
286 #include <numeric/sphericalVector.hh>
287 #include <numeric/trig.functions.hh>
288 #include <numeric/types.hh>
289 #include <numeric/xyz.functions.fwd.hh>
290 #include <numeric/xyzMatrix.fwd.hh>
291 #include <numeric/xyzMatrix.hh>
292 #include <numeric/xyzVector.fwd.hh>
293 #include <numeric/xyzVector.hh>
294 #include <numeric/internal/ColPointers.hh>
295 #include <numeric/internal/ColVectors.hh>
296 #include <numeric/internal/ColsPointer.hh>
297 #include <numeric/internal/RowPointers.hh>
298 #include <numeric/internal/RowVectors.hh>
299 #include <numeric/internal/RowsPointer.hh>
300 #include <numeric/random/random.fwd.hh>
301 #include <numeric/random/uniform.fwd.hh>
302 #include <numeric/random/uniform.hh>
303 #include <ObjexxFCL/Dimension.fwd.hh>
304 #include <ObjexxFCL/Dimension.hh>
305 #include <ObjexxFCL/DimensionExpression.hh>
306 #include <ObjexxFCL/DynamicIndexRange.fwd.hh>
307 #include <ObjexxFCL/DynamicIndexRange.hh>
308 #include <ObjexxFCL/FArray.all.fwd.hh>
309 #include <ObjexxFCL/FArray.fwd.hh>
310 #include <ObjexxFCL/FArray.hh>
311 #include <ObjexxFCL/FArray1.all.fwd.hh>
312 #include <ObjexxFCL/FArray1.fwd.hh>
313 #include <ObjexxFCL/FArray1A.fwd.hh>
314 #include <ObjexxFCL/FArray1D.fwd.hh>
315 #include <ObjexxFCL/FArray1P.fwd.hh>
316 #include <ObjexxFCL/FArray2.all.fwd.hh>
317 #include <ObjexxFCL/FArray2.fwd.hh>
318 #include <ObjexxFCL/FArray2.hh>
319 #include <ObjexxFCL/FArray2A.fwd.hh>
320 #include <ObjexxFCL/FArray2A.hh>
321 #include <ObjexxFCL/FArray2D.fwd.hh>
322 #include <ObjexxFCL/FArray2P.fwd.hh>
323 #include <ObjexxFCL/FArray2P.hh>
324 #include <ObjexxFCL/FArray3.all.fwd.hh>
325 #include <ObjexxFCL/FArray3.fwd.hh>
326 #include <ObjexxFCL/FArray3.hh>
327 #include <ObjexxFCL/FArray3A.fwd.hh>
328 #include <ObjexxFCL/FArray3D.fwd.hh>
329 #include <ObjexxFCL/FArray3P.fwd.hh>
330 #include <ObjexxFCL/FArray4.all.fwd.hh>
331 #include <ObjexxFCL/FArray4.fwd.hh>
332 #include <ObjexxFCL/FArray4A.fwd.hh>
333 #include <ObjexxFCL/FArray4D.fwd.hh>
334 #include <ObjexxFCL/FArray4P.fwd.hh>
335 #include <ObjexxFCL/FArray5.all.fwd.hh>
336 #include <ObjexxFCL/FArray5.fwd.hh>
337 #include <ObjexxFCL/FArray5A.fwd.hh>
338 #include <ObjexxFCL/FArray5D.fwd.hh>
339 #include <ObjexxFCL/FArray5P.fwd.hh>
340 #include <ObjexxFCL/FArray6.all.fwd.hh>
341 #include <ObjexxFCL/FArray6.fwd.hh>
342 #include <ObjexxFCL/FArray6A.fwd.hh>
343 #include <ObjexxFCL/FArray6D.fwd.hh>
344 #include <ObjexxFCL/FArray6P.fwd.hh>
345 #include <ObjexxFCL/FArrayInitializer.fwd.hh>
346 #include <ObjexxFCL/FArrayInitializer.hh>
347 #include <ObjexxFCL/FArraySection.fwd.hh>
348 #include <ObjexxFCL/FArraySection.hh>
349 #include <ObjexxFCL/FArrayTraits.fwd.hh>
350 #include <ObjexxFCL/FArrayTraits.hh>
351 #include <ObjexxFCL/Fmath.hh>
352 #include <ObjexxFCL/IndexRange.fwd.hh>
353 #include <ObjexxFCL/IndexRange.hh>
354 #include <ObjexxFCL/InitializerSentinel.hh>
355 #include <ObjexxFCL/KeyFArray1D.fwd.hh>
356 #include <ObjexxFCL/KeyFArray2D.fwd.hh>
357 #include <ObjexxFCL/KeyFArray3D.fwd.hh>
358 #include <ObjexxFCL/KeyFArray4D.fwd.hh>
359 #include <ObjexxFCL/KeyFArray5D.fwd.hh>
360 #include <ObjexxFCL/KeyFArray6D.fwd.hh>
361 #include <ObjexxFCL/Observer.fwd.hh>
362 #include <ObjexxFCL/Observer.hh>
363 #include <ObjexxFCL/ObserverMulti.hh>
364 #include <ObjexxFCL/ObserverSingle.hh>
365 #include <ObjexxFCL/ProxySentinel.hh>
366 #include <ObjexxFCL/SetWrapper.fwd.hh>
367 #include <ObjexxFCL/Star.fwd.hh>
368 #include <ObjexxFCL/Star.hh>
369 #include <ObjexxFCL/StaticIndexRange.fwd.hh>
370 #include <ObjexxFCL/StaticIndexRange.hh>
371 #include <ObjexxFCL/TypeTraits.hh>
372 #include <ObjexxFCL/char.functions.hh>
373 #include <ObjexxFCL/proxy_const_assert.hh>
374 #include <ObjexxFCL/string.functions.hh>
398 #include <basic/MetricValue.fwd.hh>
399 #include <basic/datacache/BasicDataCache.fwd.hh>
400 #include <basic/options/keys/OptionKeys.hh>
401 #include <basic/options/option.hh>
402 #include <boost/algorithm/string/erase.hpp>
403 #include <boost/bind.hpp>
404 #include <boost/config.hpp>
405 #include <boost/function.hpp>
406 #include <boost/pool/detail/mutex.hpp>
407 #include <boost/pool/poolfwd.hpp>
408 #include <zlib/zlib.h>
409 #include <zlib/zutil.h>
416 Real const RotamericSingleResidueDunbrackLibrary< T >::PHIPSI_BINRANGE = 10.0;
439 return eval_rotameric_energy_deriv( rsd, scratch,
false );
451 Real score = eval_rotameric_energy_deriv( rsd, scratch,
true );
453 if ( score != score ) {
455 std::cerr <<
"NaN at residue rsd: " << rsd.
seqpos() <<
" " << rsd.
name() << std::endl;
458 if ( score > 1e16 ) {
459 std::cerr <<
"inf at residue rsd: " << rsd.
seqpos() <<
" " << rsd.
name() <<
" " << score << std::endl;
476 Real const invp( ( rotprob ==
Real( 0.0 ) ) ? 0.0 : -1.0 / rotprob );
478 for (
Size i=1; i<= nbb; ++i ) {
479 if ( basic::options::option[ basic::options::OptionKeys::corrections::score::use_bicubic_interpolation ] ) {
490 for (
Size i=1; i<=
T; ++i ) {
495 correct_termini_derivatives( rsd, scratch );
509 assert( rsd.
aa() == aa() );
534 std::fill( chimean.begin(), chimean.end(), 0.0 );
535 std::fill( chisd.begin(), chisd.end(), 0.0 );
536 std::fill( chidev.begin(), chidev.end(), 0.0 );
537 std::fill( chidevpen.begin(), chidevpen.end(), 0.0 );
538 std::fill( drotprob_dbb.begin(), drotprob_dbb.end(), 0.0 );
539 std::fill( dneglnrotprob_dbb.begin(), dneglnrotprob_dbb.end(), 0.0 );
540 std::fill( dchidevpen_dbb.begin(), dchidevpen_dbb.end(), 0.0 );
541 std::fill( dchidevpen_dchi.begin(), dchidevpen_dchi.end(), 0.0 );
542 std::fill( dchimean_dphi.begin(), dchimean_dphi.end(), 0.0 );
543 std::fill( dchimean_dpsi.begin(), dchimean_dpsi.end(), 0.0 );
544 std::fill( dchisd_dphi.begin(), dchisd_dphi.end(), 0.0 );
545 std::fill( dchisd_dpsi.begin(), dchisd_dpsi.end(), 0.0 );
560 Size packed_rotno( rotwell_2_packed_rotno( rotwell ));
561 if ( packed_rotno == 0 ) {
565 packed_rotno = find_another_representative_for_unlikely_rotamer( rsd, rotwell );
574 for (
Size ii = 1; ii <=
T; ++ii ) { chidev[ ii ] = basic::periodic_range( chi[ ii ] - chimean[ ii ], 360 ); }
587 for (
Size ii = 1; ii <=
T; ++ii ) {
593 chidevpen[ ii ] = chidev[ ii ]*chidev[ ii ] / ( 2 * chisd[ ii ] * chisd[ ii ] );
600 if ( basic::options::option[ basic::options::OptionKeys::corrections::score::dun_normsd ] ) {
601 chidevpen[ ii ] += std::log(chisd[ii]);
605 Real chidevpensum( 0.0 );
606 for (
Size ii = 1; ii <=
T; ++ii ) {
607 chidevpensum += chidevpen[ ii ];
610 if ( basic::options::option[ basic::options::OptionKeys::corrections::score::use_bicubic_interpolation ] ) {
623 if ( ! eval_deriv )
return score;
627 for (
Size ii = 1; ii <=
T; ++ii ) {
635 Real const f = chidev[ ii ]*chidev[ ii ];
636 Real const fprime = -2*chidev[ ii ];
637 Real const g = 2*chisd[ ii ]*chisd[ ii ];
638 Real const gprime = 4*chisd[ ii ];
639 Real const invgg = 1 / (g*g);
644 ( g*fprime*dchimean_dphi[ ii ] - f*gprime*dchisd_dphi[ ii ] ) * invgg;
646 ( g*fprime*dchimean_dphi[ ii ] - f*gprime*dchisd_dphi[ ii ] ) * invgg;
649 if ( basic::options::option[ basic::options::OptionKeys::corrections::score::dun_normsd ] ) {
651 scratch.
dE_dphi_dev()[ ii ] += 1/chisd[ii]*dchisd_dphi[ii];
655 ( g*fprime*dchimean_dpsi[ ii ] - f*gprime*dchisd_dpsi[ ii ] ) * invgg;
657 ( g*fprime*dchimean_dpsi[ ii ] - f*gprime*dchisd_dpsi[ ii ] ) * invgg;
660 if ( basic::options::option[ basic::options::OptionKeys::corrections::score::dun_normsd ] ) {
662 scratch.
dE_dpsi_dev()[ ii ] += 1/chisd[ii]*dchisd_dpsi[ii];
665 dchidevpen_dchi[ ii ] = chidev[ ii ] / ( chisd[ ii ] * chisd[ ii ] );
676 numeric::random::RandomGenerator &
RG,
678 bool perturb_from_rotamer_center
681 Size packed_rotno( 0 );
682 assign_random_rotamer( rsd, scratch, RG, new_chi_angles, perturb_from_rotamer_center, packed_rotno );
690 numeric::random::RandomGenerator &
RG,
692 bool perturb_from_rotamer_center,
696 Real random_prob = RG.uniform();
698 Real const phi( get_phi_from_rsd( rsd ) );
699 Real const psi( get_psi_from_rsd( rsd ) );
701 Size phibin, psibin, phibin_next, psibin_next;
702 Real phi_alpha, psi_alpha;
703 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next,phi_alpha, psi_alpha );
709 while ( random_prob > 0 ) {
710 packed_rotno = rotamers_( phibin, psibin, ++count ).
packed_rotno();
712 phibin, psibin, phibin_next, psibin_next,phi_alpha, psi_alpha,
713 interpolated_rotamer );
719 if ( count == rotamers_.size3() )
break;
721 assign_chi_for_interpolated_rotamer( interpolated_rotamer, rsd, RG, new_chi_angles, perturb_from_rotamer_center );
730 numeric::random::RandomGenerator &
RG,
732 bool perturb_from_rotamer_center
735 new_chi_angles.resize( rsd.
nchi() );
736 if ( ! perturb_from_rotamer_center ) {
737 for (
Size ii = 1; ii <=
T; ++ii ) {
738 new_chi_angles[ ii ] = interpolated_rotamer.
chi_mean( ii );
741 for (
Size ii = 1; ii <=
T; ++ii ) {
742 new_chi_angles[ ii ] = interpolated_rotamer.
chi_mean(ii) + RG.gaussian() * interpolated_rotamer.
chi_sd(ii);
747 for (
Size ii =
T + 1; ii <= rsd.
nchi(); ++ii ) {
748 new_chi_angles[ ii ] = RG.uniform()*360.0 - 180.0;
774 for (
Size ii =
T; ii >= 1; --ii ) {
775 Size ii_orig_value = rotwell[ ii ];
776 for (
Size jj = 1; jj <= 3; ++jj ) {
777 if ( jj == ii_orig_value )
continue;
779 Size new_packed_rotno = rotwell_2_packed_rotno( rotwell );
780 if ( new_packed_rotno != 0 ) {
781 return new_packed_rotno;
785 rotwell[ ii ] = ii_orig_value;
793 Size phibin, psibin, phibin_next, psibin_next;
794 Real phi_alpha, psi_alpha;
796 get_phi_from_rsd( rsd ), get_psi_from_rsd( rsd ),
797 phibin, psibin, phibin_next, psibin_next,phi_alpha, psi_alpha );
799 Size packed_rotno = rotamers_( phibin, psibin, 1 ).packed_rotno();
800 packed_rotno_2_rotwell( packed_rotno, rotwell );
838 bool curr_rotamer_only,
844 if ( curr_rotamer_only ) {
847 Size const packed_rotno = rotwell_2_packed_rotno( rotwell );
854 Real const phi( get_phi_from_rsd( rsd ) );
855 Real const psi( get_psi_from_rsd( rsd ) );
857 Size phibin, psibin, phibin_next, psibin_next;
858 Real phi_alpha, psi_alpha;
859 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next,phi_alpha, psi_alpha );
864 packed_rotnos[ 1 ] = rotamers_( phibin, psibin, 1 ).packed_rotno();
865 packed_rotnos[ 2 ] = rotamers_( phibin_next, psibin, 1 ).packed_rotno();
866 packed_rotnos[ 3 ] = rotamers_( phibin, psibin_next, 1 ).packed_rotno();
867 packed_rotnos[ 4 ] = rotamers_( phibin_next, psibin_next, 1 ).packed_rotno();
870 for (
Size ii = 1; ii <= 4; ++ii ) {
885 return -1 * std::log( maxprob );
915 parent::bin_angle( -180.0, PHIPSI_BINRANGE, 360.0, N_PHIPSI_BINS, basic::periodic_range( phi, 360 ), phibin, phibin_next, phi_alpha );
916 parent::bin_angle( -180.0, PHIPSI_BINRANGE, 360.0, N_PHIPSI_BINS, basic::periodic_range( psi, 360 ), psibin, psibin_next, psi_alpha );
918 verify_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next );
930 Size phibin_next, psibin_next;
931 Real phi_alpha, psi_alpha;
932 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next, phi_alpha, psi_alpha );
940 Size const packed_rotno,
944 Real phi( get_phi_from_rsd( rsd ) );
945 Real psi( get_psi_from_rsd( rsd ) );
947 Size phibin, psibin, phibin_next, psibin_next;
948 Real phi_alpha, psi_alpha;
949 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next,phi_alpha, psi_alpha );
952 phibin_next, psibin_next,phi_alpha, psi_alpha,
953 interpolated_rotamer );
983 Size const packed_rotno,
986 Size const phibin_next,
987 Size const psibin_next,
988 Real const phi_alpha,
989 Real const psi_alpha,
993 using namespace basic;
997 sorted_rotno_00( packed_rotno_2_sorted_rotno_( phibin , psibin , packed_rotno )),
998 sorted_rotno_01( packed_rotno_2_sorted_rotno_( phibin , psibin_next, packed_rotno )),
999 sorted_rotno_10( packed_rotno_2_sorted_rotno_( phibin_next, psibin , packed_rotno )),
1000 sorted_rotno_11( packed_rotno_2_sorted_rotno_( phibin_next, psibin_next, packed_rotno ));
1003 rot00( rotamers_( phibin , psibin , sorted_rotno_00 ) ),
1004 rot01( rotamers_( phibin , psibin_next, sorted_rotno_01 ) ),
1005 rot10( rotamers_( phibin_next, psibin , sorted_rotno_10 ) ),
1006 rot11( rotamers_( phibin_next, psibin_next, sorted_rotno_11 ) );
1013 basic::interpolate_bilinear_by_value(
1014 static_cast< Real > ( rot00.rotamer_probability()),
1015 static_cast< Real > ( rot10.rotamer_probability()),
1016 static_cast< Real > ( rot01.rotamer_probability()),
1018 phi_alpha, psi_alpha, PHIPSI_BINRANGE,
false,
1024 if ( basic::options::option[ basic::options::OptionKeys::corrections::score::use_bicubic_interpolation ] ) {
1026 rot00.rotE(), rot00.rotE_dsecophi(), rot00.rotE_dsecopsi(), rot00.rotE_dsecophipsi(),
1027 rot01.rotE(), rot01.rotE_dsecophi(), rot01.rotE_dsecopsi(), rot01.rotE_dsecophipsi(),
1028 rot10.rotE(), rot10.rotE_dsecophi(), rot10.rotE_dsecopsi(), rot10.rotE_dsecophipsi(),
1030 phi_alpha, psi_alpha,
1031 PHIPSI_BINRANGE, PHIPSI_BINRANGE,
1041 for (
Size ii = 1; ii <=
T; ++ii ) {
1043 interpolate_bilinear_by_value(
1044 static_cast< Real > ( rot00.chi_mean(ii)),
1045 static_cast< Real > ( rot10.chi_mean(ii)),
1046 static_cast< Real > ( rot01.chi_mean(ii)),
1047 static_cast< Real > ( rot11.
chi_mean(ii)),
1048 phi_alpha, psi_alpha, PHIPSI_BINRANGE,
true ,
1052 interpolate_bilinear_by_value(
1053 static_cast< Real > ( rot00.chi_sd(ii)),
1054 static_cast< Real > ( rot10.chi_sd(ii)),
1055 static_cast< Real > ( rot01.chi_sd(ii)),
1056 static_cast< Real > ( rot11.
chi_sd(ii)),
1057 phi_alpha, psi_alpha, PHIPSI_BINRANGE,
false ,
1059 interpolated_rotamer.
chi_sd( ii ) = scratch.
chisd()[ii];
1073 static Size const RSD_PHI_INDEX = 1;
1086 static Size const RSD_PSI_INDEX = 2;
1108 Real phi( get_phi_from_rsd( existing_residue ) );
1109 Real psi( get_psi_from_rsd( existing_residue ) );
1110 Size phibin, psibin, phibin_next, psibin_next;
1111 Real phi_alpha, psi_alpha;
1112 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next, phi_alpha, psi_alpha );
1114 Real const requisit_probability = probability_to_accumulate_while_building_rotamers( buried );
1115 Real accumulated_probability( 0.0 );
1117 Size const max_rots_that_can_be_built = n_packed_rots();
1118 Size count_rotamers_built = 0;
1119 while ( accumulated_probability < requisit_probability ) {
1121 ++count_rotamers_built;
1123 Size const packed_rotno00 = rotamers_( phibin, psibin, count_rotamers_built ).packed_rotno();
1127 scratch, packed_rotno00,
1129 phibin_next, psibin_next,phi_alpha, psi_alpha,
1130 interpolated_rotamer );
1133 pose, scorefxn, task, packer_neighbor_graph,
1134 concrete_residue, existing_residue, extra_chi_steps, buried, rotamers,
1135 interpolated_rotamer );
1138 if ( count_rotamers_built == max_rots_that_can_be_built )
break;
1151 Size phibin, psibin, phibin_next, psibin_next;
1152 Real phi_alpha, psi_alpha;
1153 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next, phi_alpha, psi_alpha );
1155 Size const n_rots = n_packed_rots();
1157 all_rots.reserve( n_rots );
1159 for (
Size ii = 1; ii <= n_rots; ++ii ) {
1161 Size const packed_rotno00 = rotamers_( phibin, psibin, ii ).packed_rotno();
1165 scratch, packed_rotno00,
1167 phibin_next, psibin_next,phi_alpha, psi_alpha,
1168 interpolated_rotamer );
1177 all_rots.push_back( sample );
1190 Size phibin, psibin, phibin_next, psibin_next;
1191 Real phi_alpha, psi_alpha;
1192 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next, phi_alpha, psi_alpha );
1198 sorted_rotno_01( packed_rotno_2_sorted_rotno_( phibin , psibin_next, packed_rotno00 )),
1199 sorted_rotno_10( packed_rotno_2_sorted_rotno_( phibin_next, psibin , packed_rotno00 )),
1200 sorted_rotno_11( packed_rotno_2_sorted_rotno_( phibin_next, psibin_next, packed_rotno00 ));
1203 rot01( rotamers_( phibin , psibin_next, sorted_rotno_01 ) ),
1204 rot10( rotamers_( phibin_next, psibin , sorted_rotno_10 ) ),
1205 rot11( rotamers_( phibin_next, psibin_next, sorted_rotno_11 ) );
1207 Real rot_prob, dummy1, dummy2;
1209 basic::interpolate_bilinear_by_value(
1211 static_cast< Real > ( rot10.rotamer_probability()),
1212 static_cast< Real > ( rot01.rotamer_probability()),
1214 phi_alpha, psi_alpha, PHIPSI_BINRANGE,
false ,
1215 rot_prob, dummy1, dummy2
1230 Size phibin, psibin, phibin_next, psibin_next;
1231 Real phi_alpha, psi_alpha;
1232 get_phipsi_bins( phi, psi, phibin, psibin, phibin_next, psibin_next, phi_alpha, psi_alpha );
1238 scratch, packed_rotno00,
1240 phibin_next, psibin_next,phi_alpha, psi_alpha,
1241 interpolated_rotamer );
1265 return parent::n_possible_rots();
1298 *concrete_residue, task, existing_residue.
seqpos(), buried,
1299 rotameric_rotamer_building_data,
1300 extra_chi_steps, chi_set_vector );
1302 create_rotamers_from_chisets(
1303 pose, scorefxn, task,
1304 packer_neighbor_graph, concrete_residue, existing_residue,
1305 chi_set_vector, rotamers );
1315 Size const phibin_next,
1316 Size const psibin_next
1319 if (( phibin < 1 || phibin > 36 ) || (psibin < 1 || psibin > 36 ) ||
1320 ( phibin_next < 1 || phibin_next > 36 ) || (psibin_next < 1 || psibin_next > 36 )) {
1321 std::cerr <<
"ERROR: phi/psi bin out of range: " <<
1322 aa() <<
" " << phi <<
" " <<
psi;
1323 std::cerr << phibin <<
" " << phibin_next <<
" " << psibin <<
" " << psibin_next << std::endl;
1343 using namespace utility;
1348 chi_set != chi_set_vector.end(); ++chi_set ) {
1351 for (
Size jj = 1; jj <= (*chi_set)->chi.size(); ++jj ) {
1352 rotamer->set_chi( jj, (*chi_set)->chi[ jj ] );
1356 for ( pack::rotamer_set::RotamerOperations::const_iterator
1359 reject |= ! (**op)( rotamer, pose, scorefxn, rtask, packer_neighbor_graph, *chi_set );
1361 if ( !reject ) rotamers.push_back( rotamer );
1373 for (
Size ii = 1; ii <=
T; ++ii ) {
1397 using namespace utility;
1399 Size const nchi( rsd_type.
nchi() );
1408 for (
Size ii = 1; ii <= nchi; ++ii ) {
1409 chisamples_for_rotamer_and_chi(
1410 rsd_type, rtask, buried, ii, rotamer_data, extra_chi_steps[ ii ],
1411 total_chi[ ii ], total_rot[ ii ], total_ex_steps[ ii ], chisample_prob[ ii ]
1417 Size exchi_product = 1;
1419 for (
Size ii = 1; ii <= nchi; ++ii ) {
1420 lex_sizes[ ii ] = total_chi[ii].size();
1421 exchi_product *= total_chi[ii].size();
1424 chi_set_vector.reserve( exchi_product );
1427 Real const minimum_probability_for_extra_rotamers = 0.001;
1429 bool first_rotamer(
true );
1430 for ( utility::LexicographicalIterator lex( lex_sizes ); ! lex.at_end(); ++lex ) {
1431 Real chi_set_prob = base_probability;
1433 runtime_assert( nchi <= lex.size() );
1434 runtime_assert( nchi <= chisample_prob.size() );
1436 for (
Size ii = 1; ii <= nchi; ++ii ) {
1437 if( chisample_prob[ ii ].
size() >= lex[ ii ] ){
1438 chi_set_prob *= chisample_prob[ ii ][ lex[ ii ] ];
1441 if ( ! first_rotamer && chi_set_prob < minimum_probability_for_extra_rotamers ) {
1444 first_rotamer =
false;
1447 for (
Size ii = 1; ii <= nchi; ++ii ) {
1448 chi_set->chi[ ii ] = total_chi[ ii ][ lex[ ii ] ];
1449 chi_set->ex_chi_steps[ ii ] = total_ex_steps[ ii ][ lex[ ii ] ];
1450 chi_set->rot[ ii ] = total_rot[ ii ][ lex[ ii ] ];
1452 chi_set_vector.push_back( chi_set );
1464 Size const chi_index,
1480 if ( chi_index >
T ) {
1484 if ( ! chi_rotamers.empty() ) {
1486 for (
Size j=1; j<= chi_rotamers.size(); ++j ) {
1487 Real const rot_chi_mean( chi_rotamers[j].first );
1488 Real const rot_chi_sdev( chi_rotamers[j].second );
1489 total_chi.push_back( rot_chi_mean );
1490 total_ex_steps.push_back( 0. );
1491 total_rot.push_back( j );
1492 for (
Size k=1; k<= extra_steps.size(); ++k ) {
1493 total_chi.push_back( rot_chi_mean + extra_steps[k] * rot_chi_sdev );
1494 total_ex_steps.push_back( extra_steps[k] );
1495 total_rot.push_back( j );
1496 chisample_prob.push_back( 1.0 );
1508 for (
Size ii = 1; ii <= samples.size(); ++ii ) {
1509 total_chi.push_back( samples[ ii ] );
1510 total_ex_steps.push_back( 0.0 );
1511 total_rot.push_back( 1 );
1512 chisample_prob.push_back( 1.0 );
1514 if ( skip_extra_proton_chi_samples )
continue;
1516 for (
Size jj = 1; jj <= extra_samples.size(); ++jj ) {
1517 total_chi.push_back( samples[ ii ] + extra_samples[ jj ] );
1518 total_ex_steps.push_back( 0.0 );
1519 total_rot.push_back( 1 );
1520 chisample_prob.push_back( 1.0 );
1522 total_chi.push_back( samples[ ii ] - extra_samples[ jj ] );
1523 total_ex_steps.push_back( 0.0 );
1524 total_rot.push_back( 1 );
1525 chisample_prob.push_back( 1.0 );
1532 Real const icoor_chi( numeric::dihedral(
1533 rsd_type.
atom( rsd_type.
chi_atoms( chi_index )[1] ).ideal_xyz(),
1534 rsd_type.
atom( rsd_type.
chi_atoms( chi_index )[2] ).ideal_xyz(),
1535 rsd_type.
atom( rsd_type.
chi_atoms( chi_index )[3] ).ideal_xyz(),
1536 rsd_type.
atom( rsd_type.
chi_atoms( chi_index )[4] ).ideal_xyz()
1538 total_chi.push_back( icoor_chi );
1539 total_ex_steps.push_back( 0. );
1540 total_rot.push_back( 1 );
1541 chisample_prob.push_back( 1.0 );
1547 total_ex_steps.push_back( 0. );
1548 total_rot.push_back( rotamer_data.
rotamer().
rotwell( chi_index ) );
1549 chisample_prob.push_back( 1.0 );
1552 if ( rotamer_data.
rotamer().
chi_sd( chi_index ) <= min_extrachi_sd )
return;
1554 for (
Size k=1; k<= extra_steps.size(); ++k ) {
1556 + extra_steps[k] * rotamer_data.
rotamer().
chi_sd( chi_index ) );
1557 total_ex_steps.push_back( extra_steps[k] );
1558 total_rot.push_back( rotamer_data.
rotamer().
rotwell( chi_index ) );
1562 chisample_prob.push_back( std::exp( -0.5 * (extra_steps[ k ]*extra_steps[ k ])) );
1584 utility_exit_with_message(
"Unimplemented!");
1591 using namespace boost;
1593 parent::write_to_binary( out );
1597 Size const ntotalrot = N_PHIPSI_BINS * N_PHIPSI_BINS * parent::n_packed_rots();
1598 Size const ntotalchi = ntotalrot *
T;
1612 Size count_chi( 0 ), count_rots( 0 );
1613 for (
Size ii = 1; ii <= parent::n_packed_rots(); ++ii ) {
1614 for (
Size jj = 1; jj <= N_PHIPSI_BINS; ++jj ) {
1615 for (
Size kk = 1; kk <= N_PHIPSI_BINS; ++kk ) {
1616 for (
Size ll = 1; ll <=
T; ++ll ) {
1617 rotamer_means[ count_chi ] = rotamers_( kk, jj, ii ).chi_mean( ll );
1618 rotamer_stdvs[ count_chi ] = rotamers_( kk, jj, ii ).chi_sd( ll );
1621 rotamer_probs[ count_rots ] = rotamers_( kk, jj, ii ).rotamer_probability();
1622 rotamer_neglnprobs[ count_rots ] = rotamers_( kk, jj, ii ).rotE();
1623 rotamer_neglnprob_d2dphi2[ count_rots ] = rotamers_( kk, jj, ii ).rotE_dsecophi();
1624 rotamer_neglnprob_d2dpsi2[ count_rots ] = rotamers_( kk, jj, ii ).rotE_dsecopsi();
1625 rotamer_neglnprob_d4dphi2psi2[ count_rots ] = rotamers_( kk, jj, ii ).rotE_dsecophipsi();
1626 packed_rotnos[ count_rots ] = rotamers_( kk, jj, ii ).packed_rotno();
1631 out.write( (
char*) rotamer_means, ntotalchi *
sizeof(
DunbrackReal ));
1632 out.write( (
char*) rotamer_stdvs, ntotalchi *
sizeof(
DunbrackReal ));
1633 out.write( (
char*) rotamer_probs, ntotalrot *
sizeof(
DunbrackReal ));
1634 out.write( (
char*) rotamer_neglnprobs, ntotalrot *
sizeof(
DunbrackReal ));
1635 out.write( (
char*) rotamer_neglnprob_d2dphi2, ntotalrot *
sizeof(
DunbrackReal ));
1636 out.write( (
char*) rotamer_neglnprob_d2dpsi2, ntotalrot *
sizeof(
DunbrackReal ));
1637 out.write( (
char*) rotamer_neglnprob_d4dphi2psi2, ntotalrot *
sizeof(
DunbrackReal ));
1638 out.write( (
char*) packed_rotnos, ntotalrot *
sizeof(
DunbrackReal ));
1639 delete [] rotamer_means;
1640 delete [] rotamer_stdvs;
1641 delete [] rotamer_probs;
1642 delete [] rotamer_neglnprobs;
1643 delete [] rotamer_neglnprob_d2dphi2;
1644 delete [] rotamer_neglnprob_d2dpsi2;
1645 delete [] rotamer_neglnprob_d4dphi2psi2;
1646 delete [] packed_rotnos;
1651 Size const ntotalpackedrots = N_PHIPSI_BINS * N_PHIPSI_BINS * parent::n_packed_rots();
1652 boost::int32_t * packed_rotno_2_sorted_rotno =
new boost::int32_t[ ntotalpackedrots ];
1654 for (
Size ii = 1; ii <= parent::n_packed_rots(); ++ii ) {
1655 for (
Size jj = 1; jj <= N_PHIPSI_BINS; ++jj ) {
1656 for (
Size kk = 1; kk <= N_PHIPSI_BINS; ++kk ) {
1657 packed_rotno_2_sorted_rotno[ count ] = packed_rotno_2_sorted_rotno_( kk, jj, ii );
1662 out.write( (
char*) packed_rotno_2_sorted_rotno, ntotalpackedrots *
sizeof( boost::int32_t ) );
1663 delete [] packed_rotno_2_sorted_rotno;
1671 parent::read_from_binary( in );
1674 Size const ntotalrot = N_PHIPSI_BINS * N_PHIPSI_BINS * parent::n_packed_rots();
1675 Size const ntotalchi = ntotalrot *
T;
1676 rotamers_.dimension( N_PHIPSI_BINS, N_PHIPSI_BINS, parent::n_packed_rots() );
1691 in.read( (
char*) rotamer_means, ntotalchi *
sizeof(
DunbrackReal ));
1692 in.read( (
char*) rotamer_stdvs, ntotalchi *
sizeof(
DunbrackReal ));
1693 in.read( (
char*) rotamer_probs, ntotalrot *
sizeof(
DunbrackReal ));
1694 in.read( (
char*) rotamer_neglnprobs, ntotalrot *
sizeof(
DunbrackReal ));
1695 in.read( (
char*) rotamer_neglnprob_d2dphi2, ntotalrot *
sizeof(
DunbrackReal ));
1696 in.read( (
char*) rotamer_neglnprob_d2dpsi2, ntotalrot *
sizeof(
DunbrackReal ));
1697 in.read( (
char*) rotamer_neglnprob_d4dphi2psi2, ntotalrot *
sizeof(
DunbrackReal ));
1698 in.read( (
char*) packed_rotnos, ntotalrot *
sizeof(
DunbrackReal ));
1700 Size count_chi( 0 ), count_rots( 0 );
1701 for (
Size ii = 1; ii <= parent::n_packed_rots(); ++ii ) {
1702 for (
Size jj = 1; jj <= N_PHIPSI_BINS; ++jj ) {
1703 for (
Size kk = 1; kk <= N_PHIPSI_BINS; ++kk ) {
1704 for (
Size ll = 1; ll <=
T; ++ll ) {
1705 rotamers_( kk, jj, ii ).chi_mean( ll ) = rotamer_means[ count_chi ];
1706 rotamers_( kk, jj, ii ).chi_sd( ll ) = rotamer_stdvs[ count_chi ];
1709 rotamers_( kk, jj, ii ).rotamer_probability() = rotamer_probs[ count_rots ];
1710 rotamers_( kk, jj, ii ).rotE() = rotamer_neglnprobs[ count_rots ];
1711 rotamers_( kk, jj, ii ).rotE_dsecophi() = rotamer_neglnprob_d2dphi2[ count_rots ];
1712 rotamers_( kk, jj, ii ).rotE_dsecopsi() = rotamer_neglnprob_d2dpsi2[ count_rots ];
1713 rotamers_( kk, jj, ii ).rotE_dsecophipsi() = rotamer_neglnprob_d4dphi2psi2[ count_rots ];
1714 rotamers_( kk, jj, ii ).packed_rotno() = (
Size ) packed_rotnos[ count_rots ];
1719 delete [] rotamer_means;
1720 delete [] rotamer_stdvs;
1721 delete [] rotamer_probs;
1722 delete [] rotamer_neglnprobs;
1723 delete [] rotamer_neglnprob_d2dphi2;
1724 delete [] rotamer_neglnprob_d2dpsi2;
1725 delete [] rotamer_neglnprob_d4dphi2psi2;
1726 delete [] packed_rotnos;
1731 Size const ntotalpackedrots = N_PHIPSI_BINS * N_PHIPSI_BINS * parent::n_packed_rots();
1732 boost::int32_t * packed_rotno_2_sorted_rotno =
new boost::int32_t[ ntotalpackedrots ];
1733 in.read( (
char*) packed_rotno_2_sorted_rotno, ntotalpackedrots *
sizeof( boost::int32_t ) );
1735 packed_rotno_2_sorted_rotno_.dimension( N_PHIPSI_BINS, N_PHIPSI_BINS, parent::n_packed_rots() );
1736 for (
Size ii = 1; ii <= parent::n_packed_rots(); ++ii ) {
1737 for (
Size jj = 1; jj <= N_PHIPSI_BINS; ++jj ) {
1738 for (
Size kk = 1; kk <= N_PHIPSI_BINS; ++kk ) {
1739 packed_rotno_2_sorted_rotno_( kk, jj, ii ) = packed_rotno_2_sorted_rotno[ count ];
1744 delete [] packed_rotno_2_sorted_rotno;
1753 utility::io::izstream & infile,
1754 bool first_line_three_letter_code_already_read
1764 first_phipsibin_data.reserve( n_possible_rots() );
1767 Size phibin(0), psibin(0), lastphibin(0), lastpsibin(0), count(0);
1768 bool very_first_rotamer(
true );
1769 bool finished_first_phipsi_bin(
false );
1770 Size count_in_this_phipsi_bin( 1 );
1775 Size count_read_rotamers(0);
1780 char first_char = infile.peek();
1781 if ( first_char ==
'#' ) {
1783 infile.getline( line );
1797 if ( first_line_three_letter_code_already_read ) {
1800 first_line_three_letter_code_already_read =
false;
1802 infile >> three_letter_code;
1803 if ( three_letter_code != my_name ) {
1804 next_name = three_letter_code;
1805 initialize_bicubic_splines();
1811 infile >>
phi >>
psi >> count;
1812 infile >> rotwell[ 1 ] >> rotwell[ 2 ] >> rotwell[ 3 ] >> rotwell[ 4 ];
1813 infile >> probability;
1814 infile >> chimean[ 1 ] >> chimean[ 2 ] >> chimean[ 3 ] >> chimean[ 4 ];
1815 infile >> chisd[ 1 ] >> chisd[ 2 ] >> chisd[ 3 ] >> chisd[ 4 ];
1817 if (
phi == 180 ||
psi == 180 )
continue;
1818 ++count_read_rotamers;
1821 for (
Size ii = 1; ii <=
T; ++ii ) {
1822 if ( chisd[ ii ] == 0.0 ) {
1826 if ( probability == 0.0 ) {
1833 get_phipsi_bins(
phi,
psi, phibin, psibin );
1834 if ( finished_first_phipsi_bin ) {
1835 Size const packed_rotno = rotwell_2_packed_rotno( rotwell );
1836 if ( packed_rotno < 1 || packed_rotno > parent::n_packed_rots() ) {
1837 std::cerr <<
"ERROR in converting rotwell to packed rotno: ";
1838 for (
Size ii = 1; ii <=
T; ++ii ) std::cerr <<
" " << rotwell[ ii ];
1839 std::cerr <<
" " << packed_rotno << std::endl;
1843 if ( phibin != lastphibin || psibin != lastpsibin ) {
1844 count_in_this_phipsi_bin = 1;
1848 rotamers_( phibin, psibin, count_in_this_phipsi_bin ) = rotamer;
1849 packed_rotno_2_sorted_rotno_( phibin, psibin, packed_rotno ) = count_in_this_phipsi_bin;
1851 ++count_in_this_phipsi_bin;
1852 lastphibin = phibin; lastpsibin = psibin;
1854 if ( !very_first_rotamer && (phibin != lastphibin || psibin != lastpsibin )) {
1862 declare_all_existing_rotwells_encountered();
1864 rotamers_.dimension( N_PHIPSI_BINS, N_PHIPSI_BINS, n_packed_rots() );
1865 packed_rotno_2_sorted_rotno_.dimension( N_PHIPSI_BINS, N_PHIPSI_BINS, n_packed_rots() );
1868 for (
Size ii = 1; ii <= first_phipsibin_data.size(); ++ii ) {
1869 for (
Size jj = 1; jj <=
T; ++jj ) {
1870 first_bin_rotwell[ jj ] = first_phipsibin_data[ ii ].rotwell( jj );
1872 Size const packed_rotno = rotwell_2_packed_rotno( first_bin_rotwell );
1874 if ( packed_rotno < 1 || packed_rotno > parent::n_packed_rots() ) {
1875 std::cerr <<
"ERROR in converting rotwell to packed rotno: ";
1876 for (
Size ii = 1; ii <=
T; ++ii ) std::cerr <<
" " << rotwell[ ii ];
1877 std::cerr <<
" " << packed_rotno << std::endl;
1883 packed_rotno_2_sorted_rotno_( lastphibin, lastpsibin, packed_rotno ) = ii;
1887 assert( count_in_this_phipsi_bin == 1 );
1888 Size const packed_rotno = rotwell_2_packed_rotno( rotwell );
1890 rotamers_( phibin, psibin, count_in_this_phipsi_bin ) = rotamer;
1891 packed_rotno_2_sorted_rotno_( phibin, psibin, packed_rotno ) = count_in_this_phipsi_bin;
1892 ++count_in_this_phipsi_bin;
1893 lastphibin = phibin; lastpsibin = psibin;
1895 finished_first_phipsi_bin =
true;
1897 very_first_rotamer =
false;
1898 mark_rotwell_exists( rotwell );
1899 first_phipsibin_data.push_back(
DunbrackRotamer< T >( chimean, chisd, probability, rotwell ) );
1900 lastphibin = phibin; lastpsibin = psibin;
1904 initialize_bicubic_splines();
1913 for (
Size ii = 1; ii <= n_packed_rots(); ++ii ) {
1914 using namespace numeric;
1915 using namespace numeric::interpolation::spline;
1917 BicubicSpline rotEspline;
1918 MathMatrix< Real > energy_vals( N_PHIPSI_BINS, N_PHIPSI_BINS );
1919 for (
Size jj = 0; jj < N_PHIPSI_BINS; ++jj ) {
1920 for (
Size kk = 0; kk < N_PHIPSI_BINS; ++kk ) {
1921 Size sortedrotno = packed_rotno_2_sorted_rotno_( jj+1, kk+1, ii );
1924 rot.
rotE() = rotamer_energy;
1925 energy_vals( jj, kk ) = rotamer_energy;
1928 BorderFlag periodic_boundary[2] = { e_Periodic, e_Periodic };
1929 Real start_vals[2] = {0.0, 0.0};
1930 Real deltas[2] = {10.0, 10.0};
1931 bool lincont[2] = {
false,
false};
1932 std::pair< Real, Real > unused[2];
1933 unused[0] = std::make_pair( 0.0, 0.0 );
1934 unused[1] = std::make_pair( 0.0, 0.0 );
1935 rotEspline.train( periodic_boundary, start_vals, deltas, energy_vals, lincont, unused );
1936 for (
Size jj = 0; jj < N_PHIPSI_BINS; ++jj ) {
1937 for (
Size kk = 0; kk < N_PHIPSI_BINS; ++kk ) {
1938 Size sortedrotno = packed_rotno_2_sorted_rotno_( jj+1, kk+1, ii );
1963 Size total = parent::memory_usage_dynamic();
1965 total += packed_rotno_2_sorted_rotno_.size() *
sizeof(
Size );
1978 get_rotamer_from_chi_static( chi, rot4 );
1979 rot.resize( chi.size() );
1980 for (
Size ii = 1; ii <=
T; ++ii ) rot[ ii ] = rot4[ ii ];
1981 for (
Size ii =
T+1; ii <= chi.size(); ++ii ) rot[ ii ] = 0;
1992 for (
Size ii = 1; ii <=
T; ++ii ) chi4[ ii ] = chi[ ii ];
1993 get_rotamer_from_chi_static( chi4, rot );
2005 assert( chi.size() >=
T );
2008 for (
Size ii = 1; ii <=
T; ++ii ) {
2009 rot[ ii ] = bin_rotameric_chi( basic::periodic_range( chi[ ii ], 360 ), ii );
2018 #endif // INCLUDED_core_pack_dunbrack_RotamericSingleResidueDunbrackLibrary_TMPL_HH