48 #include <ObjexxFCL/string.functions.hh>
49 #include <ObjexxFCL/format.hh>
59 #include <basic/Tracer.hh>
61 #include <utility/vector1.hh>
62 #include <numeric/NumericTraits.hh>
63 #include <numeric/random/random.fwd.hh>
66 using namespace ObjexxFCL;
67 using namespace ObjexxFCL::fmt;
72 static basic::Tracer
TR(
"core.optimization.md");
74 float sqr(
float t){
return t*
t; }
77 MolecularDynamics::MolecularDynamics(
90 pose->energies().set_use_nblist( *
pose, dmap,
true );
123 using namespace core;
125 Size const nres(
pose->total_residue() );
127 for (
Size ir = 1; ir <= nres; ++ir ) {
129 for (
Size i = 1; i <= rsd.natoms(); i++ ){
153 using namespace core;
164 using namespace core;
174 using namespace core;
185 using namespace core;
187 int number=-1;
int i;
188 for ( i = 1; i <= (
int)
cartom.size(); i ++ ){
189 if( (
cartom[i].atom_id.rsd() == id1.
rsd() ) &&
191 ) { number = i;
break; }
193 if( i > (
int)
cartom.size()) number = -1;
201 using namespace core;
203 using namespace core::optimization;
204 Size const nres(
pose->total_residue() );
207 for (
Size ir = 1; ir <= nres; ++ir ) {
209 for (
Size i = 1; i <= rsd.natoms(); i++ ){
226 it != ite; ++it, ++imap ) {
255 if( deriv == 0 )
continue;
262 pose->conformation().get_torsion_angle_atom_ids(
270 int no1=
findCartomAtom( id1 );
if( no1 < 0 ) std::cerr <<
"ERROR ERROR ERROR id1 \n";
271 int no2=
findCartomAtom( id2 );
if( no2 < 0 ) std::cerr <<
"ERROR ERROR ERROR id2 \n";
272 int no3=
findCartomAtom( id3 );
if( no3 < 0 ) std::cerr <<
"ERROR ERROR ERROR id3 \n";
273 int no4=
findCartomAtom( id4 );
if( no4 < 0 ) std::cerr <<
"ERROR ERROR ERROR id4 \n";
288 float sin_phi, cos_phi;
291 float inv_nrml1_mag, inv_nrml2_mag, inv_nrml3_mag;
300 vti_vta.x() =
cartom[no1].position.x() -
cartom[no2].position.x();
301 vti_vta.y() =
cartom[no1].position.y() -
cartom[no2].position.y();
302 vti_vta.z() =
cartom[no1].position.z() -
cartom[no2].position.z();
304 vta_vtb.x() =
cartom[no2].position.x() -
cartom[no3].position.x();
305 vta_vtb.y() =
cartom[no2].position.y() -
cartom[no3].position.y();
306 vta_vtb.z() =
cartom[no2].position.z() -
cartom[no3].position.z();
308 vtb_vtj.x() =
cartom[no3].position.x() -
cartom[no4].position.x();
309 vtb_vtj.y() =
cartom[no3].position.y() -
cartom[no4].position.y();
310 vtb_vtj.z() =
cartom[no3].position.z() -
cartom[no4].position.z();
322 nrml1.x() = (vti_vta.y() * vta_vtb.z() - vti_vta.z() * vta_vtb.y());
323 nrml1.y() = (vti_vta.z() * vta_vtb.x() - vti_vta.x() * vta_vtb.z());
324 nrml1.z() = (vti_vta.x() * vta_vtb.y() - vti_vta.y() * vta_vtb.x());
326 nrml2.x() = (vta_vtb.y() * vtb_vtj.z() - vta_vtb.z() * vtb_vtj.y());
327 nrml2.y() = (vta_vtb.z() * vtb_vtj.x() - vta_vtb.x() * vtb_vtj.z());
328 nrml2.z() = (vta_vtb.x() * vtb_vtj.y() - vta_vtb.y() * vtb_vtj.x());
330 nrml3.x() = (vta_vtb.y() * nrml1.z() - vta_vtb.z() * nrml1.y());
331 nrml3.y() = (vta_vtb.z() * nrml1.x() - vta_vtb.x() * nrml1.z());
332 nrml3.z() = (vta_vtb.x() * nrml1.y() - vta_vtb.y() * nrml1.x());
334 inv_nrml1_mag = 1.0 / sqrt(
sqr(nrml1.x()) +
sqr(nrml1.y()) +
sqr(nrml1.z()));
335 inv_nrml2_mag = 1.0 / sqrt(
sqr(nrml2.x()) +
sqr(nrml2.y()) +
sqr(nrml2.z()));
336 inv_nrml3_mag = 1.0 / sqrt(
sqr(nrml3.x()) +
sqr(nrml3.y()) +
sqr(nrml3.z()));
338 cos_phi = (nrml1.x() * nrml2.x() + nrml1.y() * nrml2.y() + nrml1.z() * nrml2.z()) * inv_nrml1_mag * inv_nrml2_mag;
339 sin_phi = (nrml3.x() * nrml2.x() + nrml3.y() * nrml2.y() + nrml3.z() * nrml2.z()) * inv_nrml3_mag * inv_nrml2_mag;
341 nrml2.x() *= inv_nrml2_mag;
342 nrml2.y() *= inv_nrml2_mag;
343 nrml2.z() *= inv_nrml2_mag;
347 if(fabs(sin_phi) > 0.1) {
348 nrml1.x() *= inv_nrml1_mag;
349 nrml1.y() *= inv_nrml1_mag;
350 nrml1.z() *= inv_nrml1_mag;
352 dcosdnrml1.x() = inv_nrml1_mag * (nrml1.x() * cos_phi - nrml2.x());
353 dcosdnrml1.y() = inv_nrml1_mag * (nrml1.y() * cos_phi - nrml2.y());
354 dcosdnrml1.z() = inv_nrml1_mag * (nrml1.z() * cos_phi - nrml2.z());
356 dcosdnrml2.x() = inv_nrml2_mag * (nrml2.x() * cos_phi - nrml1.x());
357 dcosdnrml2.y() = inv_nrml2_mag * (nrml2.y() * cos_phi - nrml1.y());
358 dcosdnrml2.z() = inv_nrml2_mag * (nrml2.z() * cos_phi - nrml1.z());
361 nrml3.x() *= inv_nrml3_mag;
362 nrml3.y() *= inv_nrml3_mag;
363 nrml3.z() *= inv_nrml3_mag;
365 dsindnrml3.x() = inv_nrml3_mag * (nrml3.x() * sin_phi - nrml2.x());
366 dsindnrml3.y() = inv_nrml3_mag * (nrml3.y() * sin_phi - nrml2.y());
367 dsindnrml3.z() = inv_nrml3_mag * (nrml3.z() * sin_phi - nrml2.z());
369 dsindnrml2.x() = inv_nrml2_mag * (nrml2.x() * sin_phi - nrml3.x());
370 dsindnrml2.y() = inv_nrml2_mag * (nrml2.y() * sin_phi - nrml3.y());
371 dsindnrml2.z() = inv_nrml2_mag * (nrml2.z() * sin_phi - nrml3.z());
379 if(fabs(sin_phi) > 0.1) {
381 fi.x() += deriv * (vta_vtb.y() * dcosdnrml1.z() - vta_vtb.z() * dcosdnrml1.y());
382 fi.y() += deriv * (vta_vtb.z() * dcosdnrml1.x() - vta_vtb.x() * dcosdnrml1.z());
383 fi.z() += deriv * (vta_vtb.x() * dcosdnrml1.y() - vta_vtb.y() * dcosdnrml1.x());
385 fj.x() += deriv * (vta_vtb.z() * dcosdnrml2.y() - vta_vtb.y() * dcosdnrml2.z());
386 fj.y() += deriv * (vta_vtb.x() * dcosdnrml2.z() - vta_vtb.z() * dcosdnrml2.x());
387 fj.z() += deriv * (vta_vtb.y() * dcosdnrml2.x() - vta_vtb.x() * dcosdnrml2.y());
389 fab.x() += deriv * (vti_vta.z() * dcosdnrml1.y() - vti_vta.y() * dcosdnrml1.z() + vtb_vtj.y() * dcosdnrml2.z() - vtb_vtj.z() * dcosdnrml2.y());
390 fab.y() += deriv * (vti_vta.x() * dcosdnrml1.z() - vti_vta.z() * dcosdnrml1.x() + vtb_vtj.z() * dcosdnrml2.x() - vtb_vtj.x() * dcosdnrml2.z());
391 fab.z() += deriv * (vti_vta.y() * dcosdnrml1.x() - vti_vta.x() * dcosdnrml1.y() + vtb_vtj.x() * dcosdnrml2.y() - vtb_vtj.y() * dcosdnrml2.x());
396 fi.x() += deriv * ((vta_vtb.y() * vta_vtb.y() + vta_vtb.z() * vta_vtb.z()) * dsindnrml3.x() - vta_vtb.x() * vta_vtb.y() * dsindnrml3.y() - vta_vtb.x() * vta_vtb.z() * dsindnrml3.z());
397 fi.y() += deriv * ((vta_vtb.z() * vta_vtb.z() + vta_vtb.x() * vta_vtb.x()) * dsindnrml3.y() - vta_vtb.y() * vta_vtb.z() * dsindnrml3.z() - vta_vtb.y() * vta_vtb.x() * dsindnrml3.x());
398 fi.z() += deriv * ((vta_vtb.x() * vta_vtb.x() + vta_vtb.y() * vta_vtb.y()) * dsindnrml3.z() - vta_vtb.z() * vta_vtb.x() * dsindnrml3.x() - vta_vtb.z() * vta_vtb.y() * dsindnrml3.y());
400 fj.x() += deriv * (dsindnrml2.y() * vta_vtb.z() - dsindnrml2.z() * vta_vtb.y());
401 fj.y() += deriv * (dsindnrml2.z() * vta_vtb.x() - dsindnrml2.x() * vta_vtb.z());
402 fj.z() += deriv * (dsindnrml2.x() * vta_vtb.y() - dsindnrml2.y() * vta_vtb.x());
404 fab.x() += deriv * (-(vta_vtb.y() * vti_vta.y() + vta_vtb.z() * vti_vta.z()) * dsindnrml3.x()
405 + (2.0 * vta_vtb.x() * vti_vta.y() - vti_vta.x() * vta_vtb.y()) * dsindnrml3.y()
406 + (2.0 * vta_vtb.x() * vti_vta.z() - vti_vta.x() * vta_vtb.z()) * dsindnrml3.z() + dsindnrml2.z() * vtb_vtj.y() - dsindnrml2.y() * vtb_vtj.z());
407 fab.y() += deriv * (-(vta_vtb.z() * vti_vta.z() + vta_vtb.x() * vti_vta.x()) * dsindnrml3.y()
408 + (2.0 * vta_vtb.y() * vti_vta.z() - vti_vta.y() * vta_vtb.z()) * dsindnrml3.z()
409 + (2.0 * vta_vtb.y() * vti_vta.x() - vti_vta.y() * vta_vtb.x()) * dsindnrml3.x() + dsindnrml2.x() * vtb_vtj.z() - dsindnrml2.z() * vtb_vtj.x());
410 fab.z() += deriv * (-(vta_vtb.x() * vti_vta.x() + vta_vtb.y() * vti_vta.y()) * dsindnrml3.z()
411 + (2.0 * vta_vtb.z() * vti_vta.x() - vti_vta.z() * vta_vtb.x()) * dsindnrml3.x()
412 + (2.0 * vta_vtb.z() * vti_vta.y() - vti_vta.z() * vta_vtb.y()) * dsindnrml3.y() + dsindnrml2.y() * vtb_vtj.x() - dsindnrml2.x() * vtb_vtj.y());
439 cartom[no1].force.x() += fi.x();
440 cartom[no1].force.y() += fi.y();
441 cartom[no1].force.z() += fi.z();
443 cartom[no2].force.x() += fab.x() - fi.x();
444 cartom[no2].force.y() += fab.y() - fi.y();
445 cartom[no2].force.z() += fab.z() - fi.z();
447 cartom[no3].force.x() += fj.x() - fab.x();
448 cartom[no3].force.y() += fj.y() - fab.y();
449 cartom[no3].force.z() += fj.z() - fab.z();
451 cartom[no4].force.x() -= fj.x();
452 cartom[no4].force.y() -= fj.y();
453 cartom[no4].force.z() -= fj.z();
471 using namespace core;
473 Size const nres(
pose->total_residue() );
480 for (
Size j = 1; j <= indices.size(); j++ ){
481 if(
int(indices[j]) <
int(
cartom[i].atom_id.atomno()) )
continue;
494 for (
Size ir = 1; ir < nres; ++ir ) {
498 if( !rsd1.is_bonded( rsd2 ) )
continue;
503 int atom2 = rsd2.connect_atom( rsd1 );
523 if(
bondlist[i].index1 <= 0) std::cout <<
"CODE ERROR!\n";
524 if(
bondlist[i].index2 <= 0) std::cout <<
"CODE ERROR!\n";
550 using namespace core;
620 using namespace core;
633 if( (newdihed.index1 < 0) ) std::cout <<
"Can't find" << name1 << std::endl;
634 if( (newdihed.index2 < 0) ) std::cout <<
"Can't find" << name2 << std::endl;
635 if( (newdihed.index3 < 0) ) std::cout <<
"Can't find" << name3 << std::endl;
636 if( (newdihed.index4 < 0) ) std::cout <<
"Can't find" << name4 << std::endl;
638 (newdihed.index1 < 0) ||
639 (newdihed.index2 < 0) ||
640 (newdihed.index3 < 0) ||
641 (newdihed.index4 < 0)
648 << newdihed.atom_id_1.rsd() <<
" "
649 << newdihed.atom_id_2.rsd() <<
" "
650 << newdihed.atom_id_3.rsd() <<
" "
651 << newdihed.atom_id_4.rsd() <<
" "
652 << newdihed.atom_id_1.atomno() <<
" "
653 << newdihed.atom_id_2.atomno() <<
" "
654 << newdihed.atom_id_3.atomno() <<
" "
655 << newdihed.atom_id_4.atomno() <<
" "
673 using namespace core;
685 if( (newdihed.index1 < 0) ) std::cout <<
"Can't find" << name1 << std::endl;
686 if( (newdihed.index2 < 0) ) std::cout <<
"Can't find" << name2 << std::endl;
687 if( (newdihed.index3 < 0) ) std::cout <<
"Can't find" << name3 << std::endl;
688 if( (newdihed.index4 < 0) ) std::cout <<
"Can't find" << name4 << std::endl;
690 (newdihed.index1 < 0) ||
691 (newdihed.index2 < 0) ||
692 (newdihed.index3 < 0) ||
693 (newdihed.index4 < 0)
700 << newdihed.atom_id_1.rsd() <<
" "
701 << newdihed.atom_id_2.rsd() <<
" "
702 << newdihed.atom_id_3.rsd() <<
" "
703 << newdihed.atom_id_4.rsd() <<
" "
704 << newdihed.atom_id_1.atomno() <<
" "
705 << newdihed.atom_id_2.atomno() <<
" "
706 << newdihed.atom_id_3.atomno() <<
" "
707 << newdihed.atom_id_4.atomno() <<
" "
719 using namespace core;
721 for( ir = 1; ir < (
int)
pose->total_residue(); ir ++ ){
727 ( ir < ( (
int)
pose->total_residue() - 1 ) )
731 pose->residue( ir - 1 ),
735 "C",
"CA",
"N",
"H" ) );
739 pose->residue( ir + 1 ),
742 "CA",
"N",
"C",
"O" ) );
794 if( rsd.
has(
"HE2" ) ){
967 using namespace core;
980 float phi, sin_phi, cos_phi;
983 float inv_nrml1_mag, inv_nrml2_mag, inv_nrml3_mag;
990 vti_vta.x() =
cartom[no1].position.x() -
cartom[no2].position.x();
991 vti_vta.y() =
cartom[no1].position.y() -
cartom[no2].position.y();
992 vti_vta.z() =
cartom[no1].position.z() -
cartom[no2].position.z();
994 vta_vtb.x() =
cartom[no2].position.x() -
cartom[no3].position.x();
995 vta_vtb.y() =
cartom[no2].position.y() -
cartom[no3].position.y();
996 vta_vtb.z() =
cartom[no2].position.z() -
cartom[no3].position.z();
998 vtb_vtj.x() =
cartom[no3].position.x() -
cartom[no4].position.x();
999 vtb_vtj.y() =
cartom[no3].position.y() -
cartom[no4].position.y();
1000 vtb_vtj.z() =
cartom[no3].position.z() -
cartom[no4].position.z();
1002 nrml1.x() = (vti_vta.y() * vta_vtb.z() - vti_vta.z() * vta_vtb.y());
1003 nrml1.y() = (vti_vta.z() * vta_vtb.x() - vti_vta.x() * vta_vtb.z());
1004 nrml1.z() = (vti_vta.x() * vta_vtb.y() - vti_vta.y() * vta_vtb.x());
1006 nrml2.x() = (vta_vtb.y() * vtb_vtj.z() - vta_vtb.z() * vtb_vtj.y());
1007 nrml2.y() = (vta_vtb.z() * vtb_vtj.x() - vta_vtb.x() * vtb_vtj.z());
1008 nrml2.z() = (vta_vtb.x() * vtb_vtj.y() - vta_vtb.y() * vtb_vtj.x());
1010 nrml3.x() = (vta_vtb.y() * nrml1.z() - vta_vtb.z() * nrml1.y());
1011 nrml3.y() = (vta_vtb.z() * nrml1.x() - vta_vtb.x() * nrml1.z());
1012 nrml3.z() = (vta_vtb.x() * nrml1.y() - vta_vtb.y() * nrml1.x());
1014 inv_nrml1_mag = 1.0 / sqrt(
sqr(nrml1.x()) +
sqr(nrml1.y()) +
sqr(nrml1.z()));
1015 inv_nrml2_mag = 1.0 / sqrt(
sqr(nrml2.x()) +
sqr(nrml2.y()) +
sqr(nrml2.z()));
1016 inv_nrml3_mag = 1.0 / sqrt(
sqr(nrml3.x()) +
sqr(nrml3.y()) +
sqr(nrml3.z()));
1018 cos_phi = (nrml1.x() * nrml2.x() + nrml1.y() * nrml2.y() + nrml1.z() * nrml2.z()) * inv_nrml1_mag * inv_nrml2_mag;
1019 sin_phi = (nrml3.x() * nrml2.x() + nrml3.y() * nrml2.y() + nrml3.z() * nrml2.z()) * inv_nrml3_mag * inv_nrml2_mag;
1021 nrml2.x() *= inv_nrml2_mag;
1022 nrml2.y() *= inv_nrml2_mag;
1023 nrml2.z() *= inv_nrml2_mag;
1025 phi = -atan2(sin_phi, cos_phi);
1037 using namespace core;
1045 totalepot += 0.5 * k *
sqr(length -
bondlist[i].length);
1047 float deriv = k * (length -
bondlist[i].length);
1049 f2 *= deriv / length;
1061 using namespace core;
1069 totalepot += 0.5 * k *
sqr(length -
anglelist[i].length);
1071 float deriv = k * (length -
anglelist[i].length);
1073 f2 *= deriv / length;
1087 using namespace core;
1104 float phi, sin_phi, cos_phi;
1107 float inv_nrml1_mag, inv_nrml2_mag, inv_nrml3_mag;
1116 vti_vta.x() =
cartom[no1].position.x() -
cartom[no2].position.x();
1117 vti_vta.y() =
cartom[no1].position.y() -
cartom[no2].position.y();
1118 vti_vta.z() =
cartom[no1].position.z() -
cartom[no2].position.z();
1120 vta_vtb.x() =
cartom[no2].position.x() -
cartom[no3].position.x();
1121 vta_vtb.y() =
cartom[no2].position.y() -
cartom[no3].position.y();
1122 vta_vtb.z() =
cartom[no2].position.z() -
cartom[no3].position.z();
1124 vtb_vtj.x() =
cartom[no3].position.x() -
cartom[no4].position.x();
1125 vtb_vtj.y() =
cartom[no3].position.y() -
cartom[no4].position.y();
1126 vtb_vtj.z() =
cartom[no3].position.z() -
cartom[no4].position.z();
1138 nrml1.x() = (vti_vta.y() * vta_vtb.z() - vti_vta.z() * vta_vtb.y());
1139 nrml1.y() = (vti_vta.z() * vta_vtb.x() - vti_vta.x() * vta_vtb.z());
1140 nrml1.z() = (vti_vta.x() * vta_vtb.y() - vti_vta.y() * vta_vtb.x());
1142 nrml2.x() = (vta_vtb.y() * vtb_vtj.z() - vta_vtb.z() * vtb_vtj.y());
1143 nrml2.y() = (vta_vtb.z() * vtb_vtj.x() - vta_vtb.x() * vtb_vtj.z());
1144 nrml2.z() = (vta_vtb.x() * vtb_vtj.y() - vta_vtb.y() * vtb_vtj.x());
1146 nrml3.x() = (vta_vtb.y() * nrml1.z() - vta_vtb.z() * nrml1.y());
1147 nrml3.y() = (vta_vtb.z() * nrml1.x() - vta_vtb.x() * nrml1.z());
1148 nrml3.z() = (vta_vtb.x() * nrml1.y() - vta_vtb.y() * nrml1.x());
1150 inv_nrml1_mag = 1.0 / sqrt(
sqr(nrml1.x()) +
sqr(nrml1.y()) +
sqr(nrml1.z()));
1151 inv_nrml2_mag = 1.0 / sqrt(
sqr(nrml2.x()) +
sqr(nrml2.y()) +
sqr(nrml2.z()));
1152 inv_nrml3_mag = 1.0 / sqrt(
sqr(nrml3.x()) +
sqr(nrml3.y()) +
sqr(nrml3.z()));
1154 cos_phi = (nrml1.x() * nrml2.x() + nrml1.y() * nrml2.y() + nrml1.z() * nrml2.z()) * inv_nrml1_mag * inv_nrml2_mag;
1155 sin_phi = (nrml3.x() * nrml2.x() + nrml3.y() * nrml2.y() + nrml3.z() * nrml2.z()) * inv_nrml3_mag * inv_nrml2_mag;
1157 nrml2.x() *= inv_nrml2_mag;
1158 nrml2.y() *= inv_nrml2_mag;
1159 nrml2.z() *= inv_nrml2_mag;
1161 phi = -atan2(sin_phi, cos_phi);
1163 if(fabs(sin_phi) > 0.1) {
1164 nrml1.x() *= inv_nrml1_mag;
1165 nrml1.y() *= inv_nrml1_mag;
1166 nrml1.z() *= inv_nrml1_mag;
1168 dcosdnrml1.x() = inv_nrml1_mag * (nrml1.x() * cos_phi - nrml2.x());
1169 dcosdnrml1.y() = inv_nrml1_mag * (nrml1.y() * cos_phi - nrml2.y());
1170 dcosdnrml1.z() = inv_nrml1_mag * (nrml1.z() * cos_phi - nrml2.z());
1172 dcosdnrml2.x() = inv_nrml2_mag * (nrml2.x() * cos_phi - nrml1.x());
1173 dcosdnrml2.y() = inv_nrml2_mag * (nrml2.y() * cos_phi - nrml1.y());
1174 dcosdnrml2.z() = inv_nrml2_mag * (nrml2.z() * cos_phi - nrml1.z());
1177 nrml3.x() *= inv_nrml3_mag;
1178 nrml3.y() *= inv_nrml3_mag;
1179 nrml3.z() *= inv_nrml3_mag;
1181 dsindnrml3.x() = inv_nrml3_mag * (nrml3.x() * sin_phi - nrml2.x());
1182 dsindnrml3.y() = inv_nrml3_mag * (nrml3.y() * sin_phi - nrml2.y());
1183 dsindnrml3.z() = inv_nrml3_mag * (nrml3.z() * sin_phi - nrml2.z());
1185 dsindnrml2.x() = inv_nrml2_mag * (nrml2.x() * sin_phi - nrml3.x());
1186 dsindnrml2.y() = inv_nrml2_mag * (nrml2.y() * sin_phi - nrml3.y());
1187 dsindnrml2.z() = inv_nrml2_mag * (nrml2.z() * sin_phi - nrml3.z());
1191 if(diff < -numeric::NumericTraits< double >::pi() ) diff += 2*numeric::NumericTraits< double >::pi();
1192 if(diff < -numeric::NumericTraits< double >::pi() ) diff += 2*numeric::NumericTraits< double >::pi();
1193 if(diff > numeric::NumericTraits< double >::pi() ) diff -= 2*numeric::NumericTraits< double >::pi();
1194 if(diff > numeric::NumericTraits< double >::pi() ) diff -= 2*numeric::NumericTraits< double >::pi();
1195 totalepot += k *
sqr(diff);
1196 double deriv = -2.0 * k * diff;
1199 if(fabs(sin_phi) > 0.1) {
1201 fi.x() += deriv * (vta_vtb.y() * dcosdnrml1.z() - vta_vtb.z() * dcosdnrml1.y());
1202 fi.y() += deriv * (vta_vtb.z() * dcosdnrml1.x() - vta_vtb.x() * dcosdnrml1.z());
1203 fi.z() += deriv * (vta_vtb.x() * dcosdnrml1.y() - vta_vtb.y() * dcosdnrml1.x());
1205 fj.x() += deriv * (vta_vtb.z() * dcosdnrml2.y() - vta_vtb.y() * dcosdnrml2.z());
1206 fj.y() += deriv * (vta_vtb.x() * dcosdnrml2.z() - vta_vtb.z() * dcosdnrml2.x());
1207 fj.z() += deriv * (vta_vtb.y() * dcosdnrml2.x() - vta_vtb.x() * dcosdnrml2.y());
1209 fab.x() += deriv * (vti_vta.z() * dcosdnrml1.y() - vti_vta.y() * dcosdnrml1.z() + vtb_vtj.y() * dcosdnrml2.z() - vtb_vtj.z() * dcosdnrml2.y());
1210 fab.y() += deriv * (vti_vta.x() * dcosdnrml1.z() - vti_vta.z() * dcosdnrml1.x() + vtb_vtj.z() * dcosdnrml2.x() - vtb_vtj.x() * dcosdnrml2.z());
1211 fab.z() += deriv * (vti_vta.y() * dcosdnrml1.x() - vti_vta.x() * dcosdnrml1.y() + vtb_vtj.x() * dcosdnrml2.y() - vtb_vtj.y() * dcosdnrml2.x());
1216 fi.x() += deriv * ((vta_vtb.y() * vta_vtb.y() + vta_vtb.z() * vta_vtb.z()) * dsindnrml3.x() - vta_vtb.x() * vta_vtb.y() * dsindnrml3.y() - vta_vtb.x() * vta_vtb.z() * dsindnrml3.z());
1217 fi.y() += deriv * ((vta_vtb.z() * vta_vtb.z() + vta_vtb.x() * vta_vtb.x()) * dsindnrml3.y() - vta_vtb.y() * vta_vtb.z() * dsindnrml3.z() - vta_vtb.y() * vta_vtb.x() * dsindnrml3.x());
1218 fi.z() += deriv * ((vta_vtb.x() * vta_vtb.x() + vta_vtb.y() * vta_vtb.y()) * dsindnrml3.z() - vta_vtb.z() * vta_vtb.x() * dsindnrml3.x() - vta_vtb.z() * vta_vtb.y() * dsindnrml3.y());
1220 fj.x() += deriv * (dsindnrml2.y() * vta_vtb.z() - dsindnrml2.z() * vta_vtb.y());
1221 fj.y() += deriv * (dsindnrml2.z() * vta_vtb.x() - dsindnrml2.x() * vta_vtb.z());
1222 fj.z() += deriv * (dsindnrml2.x() * vta_vtb.y() - dsindnrml2.y() * vta_vtb.x());
1224 fab.x() += deriv * (-(vta_vtb.y() * vti_vta.y() + vta_vtb.z() * vti_vta.z()) * dsindnrml3.x()
1225 + (2.0 * vta_vtb.x() * vti_vta.y() - vti_vta.x() * vta_vtb.y()) * dsindnrml3.y()
1226 + (2.0 * vta_vtb.x() * vti_vta.z() - vti_vta.x() * vta_vtb.z()) * dsindnrml3.z() + dsindnrml2.z() * vtb_vtj.y() - dsindnrml2.y() * vtb_vtj.z());
1227 fab.y() += deriv * (-(vta_vtb.z() * vti_vta.z() + vta_vtb.x() * vti_vta.x()) * dsindnrml3.y()
1228 + (2.0 * vta_vtb.y() * vti_vta.z() - vti_vta.y() * vta_vtb.z()) * dsindnrml3.z()
1229 + (2.0 * vta_vtb.y() * vti_vta.x() - vti_vta.y() * vta_vtb.x()) * dsindnrml3.x() + dsindnrml2.x() * vtb_vtj.z() - dsindnrml2.z() * vtb_vtj.x());
1230 fab.z() += deriv * (-(vta_vtb.x() * vti_vta.x() + vta_vtb.y() * vti_vta.y()) * dsindnrml3.z()
1231 + (2.0 * vta_vtb.z() * vti_vta.x() - vti_vta.z() * vta_vtb.x()) * dsindnrml3.x()
1232 + (2.0 * vta_vtb.z() * vti_vta.y() - vti_vta.z() * vta_vtb.y()) * dsindnrml3.y() + dsindnrml2.y() * vtb_vtj.x() - dsindnrml2.x() * vtb_vtj.y());
1241 cartom[no1].force.x() += fi.x();
1242 cartom[no1].force.y() += fi.y();
1243 cartom[no1].force.z() += fi.z();
1245 cartom[no2].force.x() += fab.x() - fi.x();
1246 cartom[no2].force.y() += fab.y() - fi.y();
1247 cartom[no2].force.z() += fab.z() - fi.z();
1249 cartom[no3].force.x() += fj.x() - fab.x();
1250 cartom[no3].force.y() += fj.y() - fab.y();
1251 cartom[no3].force.z() += fj.z() - fab.z();
1253 cartom[no4].force.x() -= fj.x();
1254 cartom[no4].force.y() -= fj.y();
1255 cartom[no4].force.z() -= fj.z();
1263 using namespace core;
1265 Size const nres(
pose->total_residue() );
1269 for (
Size ir = 1; ir <= nres; ++ir ) {
1276 for (
Size i = 1; i <= rsd.natoms(); i++ ){
1303 using namespace core;
1309 sigma = sqrt( 1.38065
E-23 * tgtTemp / (
cartom[i].mass * 1.66053878
E-27) );
1310 cartom[i].velocity.x() = numeric::random::gaussian() * sigma;
1311 cartom[i].velocity.y() = numeric::random::gaussian() * sigma;
1312 cartom[i].velocity.z() = numeric::random::gaussian() * sigma;
1322 using namespace core;
1327 ekin += (0.5 *
cartom[i].mass * 1.66053878E-27 * inner_product(
cartom[i].velocity,
cartom[i].velocity));
1331 Temp = 2.0 * ekin / (3 *
cartom.size() * 8.31 / 6.022E23 );
1341 using namespace core;
1353 float forcemul = -( 1E10 / 6.0221418E23 * 4184.0);
1357 tinvmass =
t / (6.0 * (
cartom[i].mass * 1.66053878E-27 ) );
1360 dv.x() = ((2.0) *
cartom[i].force.x() * forcemul ) * tinvmass;
1361 dv.y() = ((2.0) *
cartom[i].force.y() * forcemul ) * tinvmass;
1362 dv.z() = ((2.0) *
cartom[i].force.z() * forcemul ) * tinvmass;
1363 cartom[i].velocity += dv;
1368 kin *= 6.0221418E23 / 4184.0;
1375 tinvmass =
t / (6.0 *
cartom[i].mass * 1.66053878E-27 );
1378 dr.x() =
t * (
cartom[i].velocity.x() + (4.0 *
cartom[i].force.x() -
cartom[i].old_force.x()) * forcemul* tinvmass);
1379 dr.y() =
t * (
cartom[i].velocity.y() + (4.0 *
cartom[i].force.y() -
cartom[i].old_force.y()) * forcemul* tinvmass);
1380 dr.z() =
t * (
cartom[i].velocity.z() + (4.0 *
cartom[i].force.z() -
cartom[i].old_force.z()) * forcemul* tinvmass);
1384 dv.x() = (5.0 *
cartom[i].force.x() -
cartom[i].old_force.x()) * forcemul* tinvmass;
1385 dv.y() = (5.0 *
cartom[i].force.y() -
cartom[i].old_force.y()) * forcemul* tinvmass;
1386 dv.z() = (5.0 *
cartom[i].force.z() -
cartom[i].old_force.z()) * forcemul* tinvmass;
1390 cartom[i].position += dr;
1391 cartom[i].velocity += dv;
1407 using namespace core;
1412 float forcemul = -( 1E10 / 6.0221418E23 * 4184.0);
1414 double gamma = 10E12;
1415 double gammat = gamma *
t;
1417 double gt2 = gt * gt;
1418 double gt3 = gt * gt2;
1419 double gt4 = gt2 * gt2;
1420 double gt5 = gt2 * gt3;
1421 double gt6 = gt3 * gt3;
1422 double gt7 = gt3 * gt4;
1423 double gt8 = gt4 * gt4;
1424 double gt9 = gt4 * gt5;
1448 c1 = (1 - c0) / gammat;
1449 c2 = (1 - c1) / gammat;
1451 egammat = exp(-gammat);
1452 varv = (1.0 -
sqr(egammat));
1453 varr = (2.0 * gammat - 3.0 + (4.0 - egammat) * egammat);
1454 crv =
sqr(1.0 - egammat) / (sqrt(varv * varr));
1459 1 - gt + 0.5 * gt2 - gt3 / 6.0 + gt4 / 24.0 - gt5 / 120.0 + gt6 / 720.0 - gt7 / 5040.0 + gt8 / 40320.0 -
1462 1 - (0.5 * gt - gt2 / 6.0 + gt3 / 24.0 - gt4 / 120.0 + gt5 / 720.0 - gt6 / 5040.0 + gt7 / 40320.0 -
1465 0.5 - gt / 6.0 + gt2 / 24.0 - gt3 / 120.0 + gt4 / 720.0 - gt5 / 5040.0 + gt6 / 40320.0 - gt7 / 362880.0;
1467 varr = 2.0 * gt3 / 3.0 - gt4 / 2.0 + 7.0 * gt5 / 30.0 - gt6 / 12.0
1468 + 31.0 * gt7 / 1260.0 - gt8 / 160.0 + 127.0 * gt9 / 90720.0;
1469 varv = 2.0 * gt - 2.0 * gt2 + 4.0 * gt3 / 3.0 - 2.0 * gt4 / 3.0 + 4.0 * gt5 / 15.0
1470 - 4.0 * gt6 / 45.0 + 8.0 * gt7 / 315.0 - 2.0 * gt8 / 315.0 + 4.0 * gt9 / 2835.0;
1471 crv = sqrt(3.0) * (0.5 - 3.0 * gt / 16.0 - 17.0 * gt2 / 1280.0 + 17.0 * gt3 / 6144.0
1472 + 40967.0 * gt4 / 34406400.0 - 57203.0 * gt5 / 275251200.0 -
1473 1429487.0 * gt6 / 13212057600.0);
1479 tinvmass =
t / (
cartom[i].mass * 1.66053878E-27);
1482 dv.x() = (1.0 - c0 / c1) *
cartom[i].force.x() * forcemul * tinvmass / gammat;
1483 dv.y() = (1.0 - c0 / c1) *
cartom[i].force.y() * forcemul * tinvmass / gammat;
1484 dv.z() = (1.0 - c0 / c1) *
cartom[i].force.z() * forcemul * tinvmass / gammat;
1485 cartom[i].velocity += dv;
1495 kin *= 6.0221418E23 / 4184.0;
1500 tinvmass =
t / (
cartom[i].mass * 1.66053878E-27);
1502 kTdivm = 1.38065E-23 * T / (
cartom[i].mass * 1.66053878E-27);
1503 sigmav = sqrt(kTdivm * varv);
1504 sigmar = sqrt(kTdivm * varr) / gamma;
1506 n1x = numeric::random::gaussian();
1507 n2y = numeric::random::gaussian();
1508 n2x = numeric::random::gaussian();
1509 n1z = numeric::random::gaussian();
1510 n1y = numeric::random::gaussian();
1511 n2z = numeric::random::gaussian();
1513 deltav =
core::Vector(sigmav * (crv * n1x + sqrt(1.0 -
sqr(crv)) * n2x),
1514 sigmav * (crv * n1y + sqrt(1.0 -
sqr(crv)) * n2y),
1515 sigmav * (crv * n1z + sqrt(1.0 -
sqr(crv)) * n2z));
1516 deltar =
core::Vector(sigmar * n1x, sigmar * n1y, sigmar * n1z);
1519 dr.x() =
t * (c1 *
cartom[i].velocity.x() + c2 *
cartom[i].force.x() * forcemul * tinvmass) + deltar.x();
1520 dr.y() =
t * (c1 *
cartom[i].velocity.y() + c2 *
cartom[i].force.y() * forcemul * tinvmass) + deltar.y();
1521 dr.z() =
t * (c1 *
cartom[i].velocity.z() + c2 *
cartom[i].force.z() * forcemul * tinvmass) + deltar.z();
1525 dv.x() = (c0 * c2) *
cartom[i].force.x() * forcemul * tinvmass / c1 + deltav.x();
1526 dv.y() = (c0 * c2) *
cartom[i].force.y() * forcemul * tinvmass / c1 + deltav.y();
1527 dv.z() = (c0 * c2) *
cartom[i].force.z() * forcemul * tinvmass / c1 + deltav.z();
1529 cartom[i].position += dr;
1530 cartom[i].velocity *= c0;
1531 cartom[i].velocity += dv;
1542 float ¤t_energy,
1546 using namespace core;
1549 static double m_StepMultiplier = 1.0;
1550 float StepSize = 0.000001;
1556 if((current_energy < m_OldEnergy)) {
1559 double fmagold, fmagnew, gamma;
1560 m_StepMultiplier *= 1.2;
1564 for (
Size i = 1; i <=
cartom.size(); i ++ ) {
1565 fmagold +=
cartom[i].old_force.dot(
cartom[i].old_force );
1567 fmagnew += ftemp.dot(
cartom[i].force );
1573 gamma = fmagnew / fmagold;
1577 if (gamma < 0 ) gamma = 0;
1578 std::cout <<
"gamma: " << gamma << std::endl;
1581 for (
Size i = 1; i <=
cartom.size(); i ++ ) {
1583 cartom[i].velocity *= gamma;
1590 m_OldEnergy = current_energy;
1599 m_StepMultiplier *= 0.5 / 1.2;
1600 for (
Size i = 1; i <=
cartom.size(); i ++ ) {
1617 m_OldEnergy = current_energy;
1620 for (
Size i = 1; i <=
cartom.size(); i ++ ) {
1622 f *= StepSize * m_StepMultiplier;
1637 using namespace core;
1639 const int Steps = 400;
1646 std::ofstream pdbfile;
1648 pdbfile.open( filename.c_str() , std::ios::out );
1654 float current_energy;
1657 for( Step = 0; Step < Steps; Step ++ ){
1659 current_energy = scorefxn( pose2 );
1660 pot = current_energy;
1668 current_energy += cov_epot;
1670 std::cout << Step <<
" " << pot <<
" " << cov_epot <<
" " << kin <<
" " << pot+kin << std::endl;
1672 if(Step == 0 ) m_OldEnergy = current_energy;
1678 pdbfile <<
"MODEL " << I(5, mcount ) << std::endl;
1679 pose->dump_pdb( pdbfile );
1680 pdbfile <<
"ENDMDL" << std::endl;
1700 using namespace core;
1709 std::ofstream pdbfile;
1711 pdbfile.open( filename.c_str() , std::ios::out );
1714 float TargetTemp=startTemp;
1715 for( Step = 0; Step < Steps; Step ++ ){
1717 pot += scorefxn( pose2 );
1718 if( ( Step % 20 ) == 0 ){
1719 std::cout << Step <<
" " << pot <<
" " << cov_epot <<
" " << kin <<
" " << pot+kin+cov_epot <<
" " << temp <<
"(" << TargetTemp <<
")" << std::endl;
1729 float ratio = (float)Step/(
float)Steps;
1730 TargetTemp = std::max(0.01, ratio*endTemp + (1.0-ratio)*startTemp );
1736 if( ( Step % 100 ) == 0 ){
1737 pdbfile <<
"MODEL " << I(5, mcount ) << std::endl;
1738 pose->dump_pdb( pdbfile );
1739 pdbfile <<
"ENDMDL" << std::endl;
1780 using namespace core;
1783 Real start_score = scorefxn( *
pose );
1785 std::cout <<
"STARTSCORE: " << start_score << std::endl;
1805 const float dd = 0.00001;
1814 std::cout <<
"Calculating derivatives \n";
1821 pose->energies().reset_nblist();
1822 std::cout <<
"STARTSCORE: --------- " << std::endl;
1823 start_score = scorefxn( *
pose );
1829 Size const nres(
pose->total_residue() );
1831 for (
Size ir = 1; ir <= nres; ++ir ) {
1834 std::cout <<
"IR: " << ir << std::endl;
1836 for (
Size i = 1; i <= rsd.natoms(); i++ ){
1839 pose->energies().clear();
1840 start_score = scorefxn( *
pose );
1846 pose->set_xyz( atom_id, safepos + dx );
1847 pose->energies().clear();
1848 new_score = scorefxn( *
pose );
1849 deriv = (new_score - start_score)/dd;
1850 deriv_vector.x(deriv);
1852 pose->set_xyz( atom_id, safepos + dy );
1853 pose->energies().clear();
1854 new_score = scorefxn( *
pose );
1855 deriv = (new_score - start_score)/dd;
1856 deriv_vector.y(deriv);
1859 pose->set_xyz( atom_id, safepos + dz );
1860 pose->energies().clear();
1861 new_score = scorefxn( *
pose );
1862 deriv = (new_score - start_score)/dd;
1863 deriv_vector.z(deriv);
1864 pose->set_xyz( atom_id, safepos );
1866 numeriv.push_back( deriv_vector );
1874 if( ( fabs(
cartom[i].force.x() - numeriv[i].x() ) > 0.1 ) ||
1875 ( fabs(
cartom[i].force.y() - numeriv[i].y() ) > 0.1 ) ||
1876 ( fabs(
cartom[i].force.z() - numeriv[i].z() ) > 0.1 ) ) {
1877 std::cout <<
"DRV: "
1879 <<
cartom[i].index <<
" "
1880 <<
cartom[i].force.x() <<
" "
1881 <<
cartom[i].force.y() <<
" "
1882 <<
cartom[i].force.z() <<
" "
1883 << numeriv[i].x() <<
" "
1884 << numeriv[i].y() <<
" "
1885 << numeriv[i].z() <<
" "
1890 std::cout <<
"DRVT: "
1892 <<
cartom[i].index <<
" "
1893 <<
cartom[i].force.x() <<
" "
1894 <<
cartom[i].force.y() <<
" "
1895 <<
cartom[i].force.z() <<
" "
1896 << numeriv[i].x() <<
" "
1897 << numeriv[i].y() <<
" "
1898 << numeriv[i].z() <<
" "