34 #include <basic/options/option.hh>
35 #include <basic/options/keys/symmetry.OptionKeys.gen.hh>
36 #include <basic/options/keys/fold_and_dock.OptionKeys.gen.hh>
38 #include <numeric/random/random.hh>
45 #include <basic/Tracer.hh>
48 #include <ObjexxFCL/FArray1D.hh>
49 #include <ObjexxFCL/FArray2D.hh>
50 #include <numeric/xyzMatrix.hh>
51 #include <numeric/xyzVector.hh>
52 #include <numeric/xyz.functions.hh>
54 #include <utility/vector1.hh>
62 static basic::Tracer
TR(
"core.pose.symmetry.util");
63 static numeric::random::RandomGenerator
RG(408539);
68 return ( dynamic_cast< scoring::symmetry::SymmetricEnergies const * >( &energies ) );
82 return ( dynamic_cast< scoring::symmetry::SymmetricScoreFunction const * >( &scorefxn ) );
91 dynamic_cast<conformation::symmetry::SymmetricConformation const &> ( pose.
conformation()) );
99 return ( dynamic_cast< conformation::symmetry::SymmetricConformation const * >( &conf ) );
179 using namespace basic::options;
182 std::string symm_def = symmdef_file.length()==0 ? option[ OptionKeys::symmetry::symmetry_definition ] : symmdef_file;
183 symmdata.read_symmetry_data_from_file(symm_def);
200 energies->clear_energies();
213 using namespace core::conformation::symmetry;
221 dynamic_cast<SymmetricConformation const & > ( pose_in.
conformation() ) );
224 bool jump_to_next =
false;
225 for(
Size i=1; i<=symm_info->num_total_residues_without_pseudo(); i++ ) {
226 if (!symm_info->bb_is_independent(i))
230 if(residue.type().is_lower_terminus() ||
231 residue.aa() ==
aa_unk || residue.aa() ==
aa_vrt || jump_to_next ) {
233 if( residue.aa() ==
aa_unk || residue.aa() ==
aa_vrt ) {
235 }
else if( jump_to_next ) {
236 jump_to_next =
false;
237 if( ! residue.is_lower_terminus() )
238 TR.Warning <<
"Residue following X, Z, or an upper terminus is _not_ a lower terminus type! Continuing ..." << std::endl;
244 if ( residue.type().is_upper_terminus()) jump_to_next =
true;
249 using basic::options::option;
250 using namespace basic::options::OptionKeys;
256 if( with_virtual_atoms ) {
291 bool jump_to_next =
false;
297 residue.aa() ==
aa_unk || residue.aa() ==
aa_vrt || jump_to_next ) {
299 if( residue.aa() ==
aa_unk || residue.aa() ==
aa_vrt ) {
301 }
else if( jump_to_next ) {
302 jump_to_next =
false;
307 TR.Warning <<
"Residue following X, Z, or an upper terminus is _not_ a lower terminus type! Continuing ..." << std::endl;
317 if ( residue.type().has_variant_type(
UPPER_TERMINUS )) jump_to_next =
true;
332 using namespace core::conformation::symmetry;
337 runtime_assert( pdb_info_target->nres() == pose.
total_residue() );
339 dynamic_cast<SymmetricConformation const & > ( pose.
conformation() ) );
344 for (
Size res=1; res <= pdb_info_src->nres(); ++res ) {
345 char chn_id = pdb_info_src->chain( res );
346 Size chn_idx = chr_chains.find(chn_id);
347 if (chn_idx!=std::string::npos) {
348 lastchnid = std::max( lastchnid, chn_idx );
352 for (
Size res=1; res <= pdb_info_src->nres(); ++res ) {
354 int res_id = pdb_info_src->number( res );
355 pdb_info_target->number( res, res_id );
358 char chn_id = pdb_info_src->chain( res );
359 Size chn_idx = chr_chains.find(chn_id);
360 if (chn_idx==std::string::npos)
362 pdb_info_target->chain( res, chn_id );
365 for (
Size atm=1; atm <= pdb_info_src->natoms(res) ; ++atm) {
366 core::Real b_atm = pdb_info_src->temperature( res, atm );
367 pdb_info_target->temperature( res, atm, b_atm );
371 for ( std::vector< Size>::const_iterator
372 clone = symm_info->bb_clones( res ).begin(),
373 clone_end = symm_info->bb_clones( res ).end();
375 int clone_res( *
clone );
376 pdb_info_target->number( clone_res, res_id );
378 int newchn_idx = chn_idx + (clonecounter++)*(lastchnid+1);
379 pdb_info_target->chain( clone_res, chr_chains[newchn_idx] );
382 for (
Size atm=1; atm <= pdb_info_src->natoms(res) ; ++atm) {
383 pdb_info_target->temperature( clone_res, atm, pdb_info_src->temperature( res, atm ) );
389 pdb_info_target->rebuild_pdb2pose();
392 if(pdb_info_src->header_information()){
395 pdb_info_target->remarks( pdb_info_src->remarks() );
405 using namespace core::conformation::symmetry;
413 dynamic_cast<SymmetricConformation const & > ( pose.
conformation() ) );
416 for (
Size res=1; res <= symm_info->get_nres_subunit(); ++res ) {
417 int res_id = pdb_info_src->number( res );
418 pdb_info_target->number( res, res_id );
420 char chn_id = pdb_info_src->chain( res );
421 pdb_info_target->chain( res, chn_id );
425 pdb_info_target->temperature( res, atm, pdb_info_src->temperature( res, atm ) );
429 pdb_info_target->rebuild_pdb2pose();
432 if(pdb_info_src->header_information()){
435 pdb_info_target->remarks( pdb_info_src->remarks() );
449 using namespace core::conformation::symmetry;
453 dynamic_cast<SymmetricConformation const & > ( pose.
conformation()) );
458 if ( !symm_info->bb_is_independent( i ) ) {
459 movemap.
set_bb ( i,
false );
465 int numNonVrt = symm_info->num_total_residues_without_pseudo();
469 std::map< Size, SymDof > dofs ( symm_info->get_dofs() );
471 std::map< Size, SymDof >::iterator it;
472 std::map< Size, SymDof >::iterator it_begin = dofs.begin();
473 std::map< Size, SymDof >::iterator it_end = dofs.end();
484 if ( symm_info->bb_is_independent( i ) ) {
486 for (
int j=1; j<=n_atoms; ++j ) {
488 if (
id.valid() && pose.
has_dof(
id) )
489 movemap.
set(
id,
true );
497 if ( symm_info->bb_is_independent( i ) ) {
499 for (
int j=1; j<=n_atoms; ++j ) {
501 if (
id.valid() && pose.
has_dof(
id) )
502 movemap.
set(
id,
true );
516 for (
int jump_nbr = 1; jump_nbr <= (
int)pose.
num_jump(); ++jump_nbr) {
519 if ( upstream_resid <= numNonVrt && downstream_resid <= numNonVrt &&
520 symm_info->bb_is_independent(upstream_resid) && symm_info->bb_is_independent(downstream_resid) ) {
521 bool jump_move( movemap_in->get_jump( jump_nbr ) );
524 if ( jump_move || movemap_in->get(
id ) ) {
525 movemap.
set(
id,
true );
534 for ( it = it_begin; it != it_end; ++it ) {
535 int jump_nbr ( (*it).first );
536 SymDof dof( (*it).second );
539 bool jump_move( movemap_in->get_jump( jump_nbr ) );
543 jump_move |= movemap_in->get(
id );
552 movemap.
set(
id,
true );
559 movemap.
set(
id,
true );
565 movemap.
set(
id,
true );
571 movemap.
set(
id,
true );
577 movemap.
set(
id,
true );
583 movemap.
set(
id,
true );
606 for (
int i = 1; f.
num_jump(); ++i ) {
611 utility_exit_with_message(
"No anchor residue is found..." );
623 using namespace core::conformation::symmetry;
627 dynamic_cast<SymmetricConformation & > ( pose.
conformation()) );
630 Size nres_subunit ( symm_info->num_independent_residues() );
634 Size anchor =
static_cast<Size>( RG.uniform() * (nres_subunit/2) ) +
635 (nres_subunit/4) + 1;
637 if ( basic::options::option[ basic::options::OptionKeys::fold_and_dock::set_anchor_at_closest_point ] )
641 for (
Size i = 1; i <= nres_subunit; i++) {
642 Size const j = i + nres_subunit;
644 if ( dist < mindist ){
655 Size num_jumps( f.num_jump() );
656 Size num_cuts( f.num_cutpoint() );
659 ObjexxFCL::FArray1D_int cuts( num_cuts );
660 ObjexxFCL::FArray2D_int jumps( 2, num_jumps );
663 for (
Size i = 1; i<= num_jumps; ++i ) {
664 int down ( f.downstream_jump_residue(i) );
665 int up ( f.upstream_jump_residue(i) );
675 for (
Size i = 1; i<= num_cuts; ++i ) {
676 cuts(i) = cuts_vector[i];
680 if ( symm_info->bb_follows( anchor ) != 0 ) {
684 anchor = symm_info->bb_follows( anchor );
688 int root ( f.root() );
689 int const jump_number ( f.get_jump_that_builds_residue( anchor_start ) );
690 int residue_that_builds_anchor( f.upstream_jump_residue( jump_number ) );
692 jumps(1, jump_number ) = anchor;
693 jumps(2, jump_number ) = residue_that_builds_anchor;
695 bool try_assert (
true );
696 if ( symm_info->bb_follows( anchor_start ) != 0 ) {
697 anchor_start = symm_info->bb_follows( anchor_start );
701 for ( std::vector< Size>::const_iterator
702 clone = symm_info->bb_clones( anchor_start ).begin(),
703 clone_end = symm_info->bb_clones( anchor_start ).end();
705 int jump_clone ( f.get_jump_that_builds_residue( *
clone ) );
706 int takeoff_pos ( f.upstream_jump_residue( jump_clone ) );
707 int new_anchor ( anchor - anchor_start + *
clone );
708 if ( try_assert ) runtime_assert( jumps(1,jump_clone) ==
int( *
clone ) && jumps(2,jump_clone) == takeoff_pos );
709 jumps(1, jump_clone ) = new_anchor;
710 jumps(2, jump_clone ) = takeoff_pos;
725 f.tree_from_jumps_and_cuts( pose.
conformation().
size(), num_jumps, jumps, cuts );
739 int const jump_number ( f.get_jump_that_builds_residue( anchor ) );
740 int coordsys_residue( f.upstream_jump_residue( jump_number ) );
743 float theta = std::atan2( anchor_pos(2), anchor_pos(1) );
746 runtime_assert( pose.
residue( coordsys_residue ).
name() ==
"VRT" );
752 Vector y_axis_nrml( y_axis );
753 y_axis_nrml.normalize();
754 z_axis = z_axis.cross( y_axis_nrml );
760 runtime_assert( std::abs( coordsys_rot.det() - 1.0 ) < 1e-6 );
764 ( -1.0 * numeric::conversions::to_degrees( theta ) ) );
772 base_jump.rotation_by_matrix( upstream_stub, center, coordsys_rot.transpose()*z_rot );
774 pose.
set_jump( jump_number, base_jump );
780 if ( new_anchor_pos(1) < 0 ) {
783 base_jump.rotation_by_matrix( upstream_stub, center, twofold );
784 pose.
set_jump( jump_number, base_jump );
807 ObjexxFCL::FArray1D_bool & partner1
809 using namespace core::kinematics;
812 Size njumps = jump_numbers.size();
813 for (
int i=1; i<=njumps; ++i) {
815 for (
int j=1; j<= clones_i.size(); ++j) {
816 jump_numbers.push_back( clones_i[j] );
822 for (
int i=1; i<=symm_info->num_total_residues_without_pseudo(); ++i) {
823 if (symm_info->bb_is_independent(i)) {
830 partner1( pos1 ) =
true;
832 bool new_member (
true );
833 std::vector< Edge >::const_iterator it_begin( ft.
begin() );
834 std::vector< Edge >::const_iterator it_end ( ft.
end() );
836 while ( new_member ) {
838 for ( std::vector< Edge >::const_iterator it = it_begin; it != it_end; ++it ) {
839 if ( std::find ( jump_numbers.begin(), jump_numbers.end(), it->label() ) != jump_numbers.end() )
continue;
841 int const start( std::min( it->start(), it->stop() ) );
842 int const stop ( std::max( it->start(), it->stop() ) );
843 if ( (partner1( start ) && !partner1( stop )) ||
844 (partner1( stop ) && !partner1( start )) ) {
846 if ( it->is_polymer() ) {
848 for (
int i=start; i<=
stop; ++i ) {
849 partner1( i ) =
true;
853 partner1( start ) =
true;
854 partner1( stop ) =
true;
871 dynamic_cast<conformation::symmetry::SymmetricConformation const & > ( pose.
conformation() ) );
876 for (
Size i=1; i <=symm_info->num_total_residues_with_pseudo(); ++i ){
877 if (symm_info->bb_is_independent(i)) {
885 if (base_clones.size() <= 1)
891 return X.cross( Y ).normalize();
899 dynamic_cast<conformation::symmetry::SymmetricConformation const & > ( p.
conformation() ) );
904 runtime_assert( symm_info->num_total_residues_with_pseudo() == msk.size() );
908 if (msk_i && !symm_info->fa_is_independent( i )) {
910 msk[ symm_info->bb_follows( i ) ] =
true;
920 TR.Error <<
"sealed_symmetric_fold_tree called with assymetric fold tree. Return FoldTree" << std::endl;
929 dynamic_cast<conformation::symmetry::SymmetricConformation const & > ( pose.
conformation() ) );
931 Size nres_subunit ( symm_info->num_independent_residues() );
935 Size num_nonvrt = symm_info->num_total_residues_without_pseudo();
952 if ( up > num_nonvrt && down > num_nonvrt) {
953 new_jumps.push_back( std::pair<Size,Size>(up,down) );
956 if ( up > num_nonvrt && down <= num_nonvrt) {
957 new_jumps.push_back( std::pair<Size,Size>( up, down ) );
960 if ( up <= num_nonvrt && down > num_nonvrt) {
961 new_jumps.push_back( std::pair<Size,Size>( up, down ) );
967 for (
Size i = 1; i<=cuts_vector.size(); ++i ) {
969 if ( cuts_vector[i] >= (
int) num_nonvrt || cuts_vector[i]%nres_subunit == 0 )
970 new_cuts.push_back( cuts_vector[i] );
974 ObjexxFCL::FArray1D_int cuts( new_cuts.size() );
975 ObjexxFCL::FArray2D_int jumps( 2, new_jumps.size() );
977 for (
Size i = 1; i<= new_jumps.size(); ++i ) {
978 jumps(1,i) = std::min( (
int)new_jumps[i].first, (
int)new_jumps[i].second);
979 jumps(2,i) = std::max( (
int)new_jumps[i].first, (
int)new_jumps[i].second);
983 for (
Size i = 1; i<= new_cuts.size(); ++i ) {
984 cuts(i) = (
int)new_cuts[i];
999 using namespace core::conformation::symmetry;
1000 int sym_jump = jump_num;
1003 std::map<Size,SymDof> dofs = sym_info->get_dofs();
1005 Size jump_counter = 0;
1007 for(std::map<Size,SymDof>::iterator i = dofs.begin(); i != dofs.end(); i++) {
1009 if (!i->second.allow_dof(1) && !i->second.allow_dof(2) && !i->second.allow_dof(3))
continue;
1010 if (++jump_counter == jump_num) {
1011 sym_jump = i->first;
1015 if (sym_jump == 0) {
1016 TR.Error <<
"Failed to find sym_dof with index " << jump_num << std::endl;
1017 utility_exit_with_message(
"Symmetric slide DOF "" not found!");
1026 using namespace core::conformation::symmetry;
1029 std::map<Size,SymDof> dofs = syminfo->get_dofs();
1030 for(std::map<Size,SymDof>::iterator i = dofs.begin(); i != dofs.end(); i++) {
1031 names.push_back(syminfo->get_jump_name(i->first));
1043 using namespace core::conformation::symmetry;
1048 ObjexxFCL::FArray1D_bool partition;
1053 std::cout << subs.back() << std::endl;
1057 utility_exit_with_message(
"pose not symmetric!");
1079 return symmetry_info(pose)->get_subunit_name_to_component(vname);
1082 return symmetry_info(pose)->get_jump_name_to_components(jname);
1085 return symmetry_info(pose)->get_jump_name_to_subunits(jname);