14 #include <basic/Tracer.hh>
26 #include <numeric/constants.hh>
27 #include <numeric/xyz.functions.hh>
30 #include <ObjexxFCL/format.hh>
31 #include <ObjexxFCL/string.functions.hh>
37 #include <utility/vector1.hh>
45 static basic::Tracer
TR(
"protocols.kinmatchFunGroupTK");
70 using numeric::constants::d::pi;
71 using numeric::conversions::degrees;
72 using utility::io::ozstream;
73 using ObjexxFCL::fmt::I;
74 using ObjexxFCL::fmt::F;
82 template<
typename T >
87 return ObjexxFCL::string_of(t);
90 template<
typename T >
98 return ObjexxFCL::lead_zero_string_of(t,w);
122 for(
Size i = 1; i <=n; ++i) v[i] = i;
129 std::cerr <<
"cmd.load_cgo(Vec( " << v.x() <<
"," << v.y() <<
"," << v.z() <<
").cgo(), '"+l+
"')" << std::endl;
137 KRSQuery::KRSQuery(
KRSQueryType typ ) : type(typ),cen(0,0,0),axs(1,0,0),ori(0,1,0),disth(0.5),angth(0.0175),clash( 2.8) {}
138 KRSQuery::KRSQuery(
KRSQueryType typ,
Vec c,
Vec a,
Vec o,
Real dt,
Real at,
Real clsh ) : type(typ),cen( c ),axs( a ),ori( o ),disth( dt),angth( at ),clash(clsh) {}
139 KRSQuery::KRSQuery(
KRSQueryType typ,
Vec c,
Vec a,
Real dt,
Real at,
Real clsh ) : type(typ),cen( c ),axs( a ),ori(0,0,0),disth( dt),angth( at ),clash(clsh) {}
151 res_types.push_back(
"ASP");
152 res_types.push_back(
"CYS");
153 res_types.push_back(
"HIS");
158 stb_[*it].push_back(
Stub(rsd->xyz(5),rsd->xyz(2),rsd->xyz(1)));
181 Real cbd2 = q.
cen.distance_squared(is->v);
182 if(*ip==qrsd.
seqpos())
continue;
183 if( cbd2 > 14.0 )
continue;
187 rsd->set_xyz(11, rsd->xyz(
"SG") + 2.1*(rsd->xyz(
"HG")-rsd->xyz(
"SG")).normalized() );
188 for(
Real ch1 = 0; ch1 <= 360; ch1+=3.0) {
190 Vec sg = rsd->xyz(
"SG");
191 if( sg.distance_squared(q.
cen) > 8.0 )
continue;
192 for(
Real ch2 = 0; ch2 <= 360; ch2+=3.0) {
194 Vec hg = rsd->xyz(
"HG");
195 Vec cen = sg+2.1*((hg-sg).normalized());
196 Real const dsq = cen.distance_squared(q.
cen);
198 Vec axs = ((sg-q.
cen).normalized());
199 Real const da = numeric::angle_radians( axs,
Vec(0,0,0), q.
axs);
208 if( fabs(da-q.
ori.x()) > q.
angth )
continue;
210 for(
Size ia = 6; ia <= rsd->nheavyatoms(); ++ia) {
211 if(!
ifc().
clash_check(rsd->xyz(ia),*ip) ) { clash =
true;
break; }
212 for(
Size ja = 1; ja <= qrsd.
nheavyatoms(); ++ja)
if( qrsd.
xyz(ja).distance_squared(rsd->xyz(ia)) < q.
clash ) { clash =
true;
break; }
218 bestrsd = rsd->clone();
224 hits.push_back(bestrsd);
239 Real cbd2 = q.
cen.distance_squared(is->v);
240 if(*ip==qrsd.
seqpos())
continue;
241 if( cbd2 > 14.0 )
continue;
245 rsd->set_xyz(11, rsd->xyz(
"SG") + 2.1*(rsd->xyz(
"HG")-rsd->xyz(
"SG")).normalized() );
246 for(
Real ch1 = 0; ch1 <= 360; ch1+=3.0) {
248 Vec sg = rsd->xyz(
"SG");
249 if( sg.distance_squared(q.
cen) > 8.0 )
continue;
250 for(
Real ch2 = 0; ch2 <= 360; ch2+=3.0) {
252 Vec hg = rsd->xyz(
"HG");
253 Vec cen = sg+2.1*((hg-sg).normalized());
254 Real const dsq = cen.distance_squared(q.
cen);
256 Vec axs = ((sg-q.
cen).normalized());
257 Real const da = numeric::angle_radians( axs,
Vec(0,0,0), q.
axs);
266 if( fabs(da-q.
ori.x()) > q.
angth )
continue;
268 for(
Size ia = 6; ia <= rsd->nheavyatoms(); ++ia) {
269 if(!
ifc().
clash_check(rsd->xyz(ia),*ip) ) { clash =
true;
break; }
270 for(
Size ja = 1; ja <= qrsd.
nheavyatoms(); ++ja)
if( qrsd.
xyz(ja).distance_squared(rsd->xyz(ia)) < q.
clash ) { clash =
true;
break; }
276 bestrsd = rsd->clone();
282 hits.push_back(bestrsd);
297 Real cbd2 = q.
cen.distance_squared(is->v);
298 if(*ip==qrsd.
seqpos())
continue;
299 if( cbd2 > 36.0 )
continue;
303 Vec cb = rsd->xyz(
"CB");
304 for(
Real ch1 = 0; ch1 <= 360; ch1+=3.0) {
306 Vec cg = rsd->xyz(
"CG");
307 if( cg.distance_squared(q.
cen) > 25.0 )
continue;
308 for(
Real ch2 = 0; ch2 <= 360; ch2+=3.0) {
310 Vec od1 = rsd->xyz(
"OD1");
311 Vec od2 = rsd->xyz(
"OD2");
312 for(
int od12 = 0; od12 <= 1; ++od12) {
314 for(
int prpp = 0; prpp <= 1; ++prpp) {
315 Vec const oda(od12?od1:od2);
316 Vec const odb(od12?od2:od1);
317 Vec const axs( ((prpp?(cg-cb):(oda-odb)).normalized()) );
318 Vec const cen = oda + 1.8 * axs;
319 Real const dsq = cen.distance_squared(q.
cen);
321 Real const dt( axs.dot(q.
axs) );
322 if( dt < q.
angth )
continue;
324 for(
Size ia = 6; ia <= rsd->nheavyatoms()-2; ++ia) {
325 if(!
ifc().
clash_check(rsd->xyz(ia),*ip) ) { clash =
true;
break; }
326 for(
Size ja = 1; ja <= qrsd.
nheavyatoms(); ++ja)
if( qrsd.
xyz(ja).distance_squared(rsd->xyz(ia)) < q.
clash ) { clash =
true;
break; }
330 Real const da = dsq - 5*dt;
333 bestrsd = rsd->clone();
341 hits.push_back(bestrsd);
359 #define CYS_CB_HG_DIS 2.911171 // 3.388379 // 2.771698
360 #define CYS_SG_CB_H 0.7494478 // height of SG "above" CB
361 #define CYS_HG_SG_PRJLEN 2.088496 //1.818653 // sin(CB-SG-HG)*len(HG-SG)
362 #define CYS_1oSIN_CB_SG_HG 1.092026 //
363 #define CYS_HG_SG_X_DROP 0.0998 // h drop due measured, 2.1*tan((90-84.011803)/180*pi)*tan((90-65.522644)/180*pi)
364 #define CYS_CB_SG_PERP 1.646237
365 if( fabs(q.
axs.length()-1.0) > 0.0000001 ) utility_exit_with_message(
"place_c query axs not kormalized()!");
366 Real const r3o2 = sqrt(3.0)/2.0;
373 if(*ip==qrsd.
seqpos())
continue;
375 Real const cbd2 = q.
cen.distance_squared(is->v);
376 if( dis2ub < cbd2 || cbd2 < dis2lb )
continue;
377 Vec const qcen0(is->global2local(q.
cen));
379 Size const NPOS = (pdis > 0.2) ? 7 : 1;
380 Vec const Y =
Vec(0,1,0).cross(qcen0).normalized();
381 Vec const Z = Y.cross(qcen0).normalized();
383 for(
int flp = -1; flp <= 1; flp+=2) {
384 Real best_angerr = 9e9, best_ch1=0.0, best_ch2=0.0, mn_ang=9e9, mx_ang=-9e9;
385 for(
Size ipos = 0; ipos < NPOS; ++ipos) {
387 if (ipos==1) { y = 1.0; z = 0.0; }
388 else if(ipos==2) { y = 0.5; z = r3o2; }
389 else if(ipos==3) { y = -0.5; z = r3o2; }
390 else if(ipos==4) { y = -1.0; z = 0.0; }
391 else if(ipos==5) { y = -0.5; z = -r3o2; }
392 else if(ipos==6) { y = 0.5; z = -r3o2; }
393 Vec const qcen = qcen0 + y*Y*pdis + z*Z*pdis;
395 Real const lqcen = qcen.length();
401 Real const lqcenpx = sqrt(qcen.y()*qcen.y()+qcen.z()*qcen.z());
402 Real const ch1_0 = (qcen.y()>0)? asin(qcen.z()/lqcenpx) : pi-asin(qcen.z()/lqcenpx);
405 Real const ch1_ofst = asin( hgz/hgdzy );
406 Real const ch1 = ch1_0 + flp*ch1_ofst;
407 Real const ch2 = pi + flp*ch2_0 ;
410 if(!
ifc().clash_check(sg,*ip) )
continue;
412 Real const bang = acos( (sg-q.
cen).normalized().dot(q.
axs) );
428 mn_ang = min(bang,mn_ang);
429 mx_ang = max(bang,mx_ang);
430 Real const angerr = fabs( bang - q.
ori.x() );
431 if( angerr < best_angerr ) {
432 best_angerr = angerr;
440 rtmp->set_chi(1,degrees(best_ch1));
441 rtmp->set_chi(2,degrees(best_ch2));
447 hits.push_back(rtmp->clone());
462 hits_out.insert(hits_out.end(),hits.begin(),hits.end());
473 #define HIS_CB_HG_DIS 5.6570235
474 #define HIS_CB_HG_PAR 3.946279
475 #define HIS_CG_CB_H 0.6019999
476 #define HIS_HE2_CG_PRJLEN 1.5392682574
477 #define HIS_1oSIN_CA_CB_CG 1.092026358 // 1/sina(ca-cb-cg)
478 #define HIS_HE2_CG_X_DROP (2.4821480185 - 0.087) // 5.6570235*math.tan((90-66.309441 )*math.pi/180)
479 #define HIS_CB_CG_PERP 1.371000
481 if( fabs(q.
axs.length()-1.0) > 0.0000001 ) utility_exit_with_message(
"place_h query axs not kormalized()!");
482 Real const r3o2 = sqrt(3.0)/2.0;
489 if(*ip==qrsd.
seqpos())
continue;
500 Real const cbd2 = q.
cen.distance_squared(is->v);
501 if( dis2ub < cbd2 || cbd2 < dis2lb )
continue;
502 Vec const qcen0(is->global2local(q.
cen));
504 Size const NPOS = (pdis > 0.2) ? 7 : 1;
505 Vec const Y =
Vec(0,1,0).cross(qcen0).normalized();
506 Vec const Z = Y.cross(qcen0).normalized();
508 for(
int flp = -1; flp <= 1; flp+=2) {
509 Real best_angerr = 9e9, best_ch1=0.0, best_ch2=0.0, mn_ang=9e9, mx_ang=-9e9;
510 for(
Size ipos = 0; ipos < NPOS; ++ipos) {
512 if (ipos==1) { y = 1.0; z = 0.0; }
513 else if(ipos==2) { y = 0.5; z = r3o2; }
514 else if(ipos==3) { y = -0.5; z = r3o2; }
515 else if(ipos==4) { y = -1.0; z = 0.0; }
516 else if(ipos==5) { y = -0.5; z = -r3o2; }
517 else if(ipos==6) { y = 0.5; z = -r3o2; }
518 Vec const qcen = qcen0 + y*Y*pdis + z*Z*pdis;
520 Real const lqcen = qcen.length();
526 Real const lqcenpx = sqrt(qcen.y()*qcen.y()+qcen.z()*qcen.z());
527 Real const ch1_0 = (qcen.y()>0)? asin(qcen.z()/lqcenpx) : pi-asin(qcen.z()/lqcenpx);
530 Real const ch1_ofst = asin( hgz/hgdzy );
531 Real const ch1 = ch1_0 - flp*ch1_ofst;
532 Real const ch2 = pi + flp*ch2_0 ;
534 Vec const ne2 = is->local2global(rotation_matrix(
Vec(1,0,0),ch1)*rotation_matrix(
Vec(0.602000, 1.371000, 0.000000),ch2) *
Vec(1.884000, 3.152000, -0.001000));
536 if(!
ifc().clash_check(ne2,*ip) )
continue;
538 Real const bang = acos( (ne2-q.
cen).normalized().dot(q.
axs) );
566 mn_ang = min(bang,mn_ang);
567 mx_ang = max(bang,mx_ang);
568 Real const angerr = fabs( bang - q.
ori.x() );
569 if( angerr < best_angerr ) {
570 best_angerr = angerr;
578 rtmp->set_chi(1,degrees(best_ch1));
579 rtmp->set_chi(2,degrees(best_ch2));
585 hits.push_back(rtmp->clone());
600 hits_out.insert(hits_out.end(),hits.begin(),hits.end());
613 #define HIS_CB_HG_DIS 5.6570235
614 #define HIS_CB_HG_PAR 3.946279
615 #define HIS_CG_CB_H 0.6019999
616 #define HIS_HE2_CG_PRJLEN 1.5392682574
617 #define HIS_1oSIN_CA_CB_CG 1.092026358 // 1/sina(ca-cb-cg)
618 #define HIS_HE2_CG_X_DROP (2.4821480185 - 0.087) // 5.6570235*math.tan((90-66.309441 )*math.pi/180)
619 #define HIS_CB_CG_PERP 1.371000
621 if( fabs(q.
axs.length()-1.0) > 0.0000001 ) utility_exit_with_message(
"place_h query axs not kormalized()!");
622 Real const r3o2 = sqrt(3.0)/2.0;
629 if(*ip==qrsd.
seqpos())
continue;
640 Real const cbd2 = q.
cen.distance_squared(is->v);
641 if( dis2ub < cbd2 || cbd2 < dis2lb )
continue;
642 Vec const qcen0(is->global2local(q.
cen));
644 Size const NPOS = (pdis > 0.2) ? 7 : 1;
645 Vec const Y =
Vec(0,1,0).cross(qcen0).normalized();
646 Vec const Z = Y.cross(qcen0).normalized();
648 for(
int flp = -1; flp <= 1; flp+=2) {
649 Real best_angerr = 9e9, best_ch1=0.0, best_ch2=0.0, mn_ang=9e9, mx_ang=-9e9;
650 for(
Size ipos = 0; ipos < NPOS; ++ipos) {
652 if (ipos==1) { y = 1.0; z = 0.0; }
653 else if(ipos==2) { y = 0.5; z = r3o2; }
654 else if(ipos==3) { y = -0.5; z = r3o2; }
655 else if(ipos==4) { y = -1.0; z = 0.0; }
656 else if(ipos==5) { y = -0.5; z = -r3o2; }
657 else if(ipos==6) { y = 0.5; z = -r3o2; }
658 Vec const qcen = qcen0 + y*Y*pdis + z*Z*pdis;
660 Real const lqcen = qcen.length();
666 Real const lqcenpx = sqrt(qcen.y()*qcen.y()+qcen.z()*qcen.z());
667 Real const ch1_0 = (qcen.y()>0)? asin(qcen.z()/lqcenpx) : pi-asin(qcen.z()/lqcenpx);
670 Real const ch1_ofst = asin( hgz/hgdzy );
671 Real const ch1 = ch1_0 - flp*ch1_ofst;
672 Real const ch2 = pi + flp*ch2_0 ;
674 Vec const ne2 = is->local2global(rotation_matrix(
Vec(1,0,0),ch1)*rotation_matrix(
Vec(0.602000, 1.371000, 0.000000),ch2) *
Vec(1.884000, 3.152000, -0.001000));
676 if(!
ifc().clash_check(ne2,*ip) )
continue;
678 Real const bang = acos( (ne2-q.
cen).normalized().dot(q.
axs) );
706 mn_ang = min(bang,mn_ang);
707 mx_ang = max(bang,mx_ang);
708 Real const angerr = fabs( bang - q.
ori.x() );
709 if( angerr < best_angerr ) {
710 best_angerr = angerr;
718 rtmp->set_chi(1,degrees(best_ch1));
719 rtmp->set_chi(2,degrees(best_ch2));
725 hits.push_back(rtmp->clone());
740 hits_out.insert(hits_out.end(),hits.begin(),hits.end());