21 #ifdef USEBOOSTSERIALIZE
27 #include <basic/basic.hh>
28 #include <basic/Tracer.hh>
39 #include <numeric/xyz.functions.hh>
42 #include <utility/assert.hh>
43 #include <utility/PyAssert.hh>
49 #include <utility/vector1.hh>
50 #include <boost/foreach.hpp>
53 #define foreach BOOST_FOREACH
55 namespace conformation {
57 static basic::Tracer
TR(
"core.conformation.Residue");
63 utility::pointer::ReferenceCount(),
64 rsd_type_( rsd_type_in ),
67 chi_( rsd_type_.nchi(), 0.0 ),
68 mainchain_torsions_( rsd_type_.mainchain_atoms().
size(), 0.0 ),
70 nonstandard_polymer_( false ),
71 connect_map_( rsd_type_in.n_residue_connections() )
82 foreach(
core::Size orbital_index, orbital_indices){
105 utility::pointer::ReferenceCount(),
106 rsd_type_( rsd_type_in ),
107 seqpos_( current_rsd.seqpos() ),
108 chain_( current_rsd.chain() ),
109 chi_( rsd_type_.nchi(), 0.0 ),
110 mainchain_torsions_( current_rsd.mainchain_torsions() ),
112 nonstandard_polymer_( current_rsd.nonstandard_polymer_ ),
113 connect_map_( current_rsd.connect_map_ ),
114 connections_to_residues_( current_rsd.connections_to_residues_ ),
115 pseudobonds_( current_rsd.pseudobonds_ )
127 place( current_rsd, conformation, preserve_c_beta );
138 std::cerr <<
"Unable to handle change in the number of residue connections in the presence of pseudobonds!" <<
153 Real const current_chi
155 numeric::dihedral_degrees(
162 chi_[ chino ] = current_chi;
167 foreach(
core::Size orbital_index, orbital_indices){
180 utility::pointer::ReferenceCount(),
181 rsd_type_(src.rsd_type_),
183 orbitals_(src.orbitals_),
184 seqpos_(src.seqpos_),
187 mainchain_torsions_(src.mainchain_torsions_),
188 actcoord_(src.actcoord_),
189 nonstandard_polymer_(src.nonstandard_polymer_),
190 connect_map_(src.connect_map_),
191 connections_to_residues_(src.connections_to_residues_),
192 pseudobonds_(src.pseudobonds_)
211 return atoms_[ atomno ].type();
223 return atoms_[ atm_index ].xyz();
235 atoms_[ atm_index ].xyz( xyz_in );
241 atom( atm_name ).
xyz( xyz_in );
266 for ( std::map< Size, PseudoBondCollectionCOP >::const_iterator
269 iter != iter_end; ++iter ) {
270 std::map< Size, PseudoBondCollectionCOP >::const_iterator other_iter = other.
pseudobonds_.find( iter->first );
271 if ( other_iter == other_iter_end )
return false;
272 if ( iter->second != other_iter->second )
return false;
290 for (
Size i = 1; i<=
chi_.size(); i++){
291 if ( std::abs( this_chi[i] - other_chi[i]) >= 5){
325 std::cerr <<
"Unable to handle change in the number of residue connections in the presence of pseudobonds!" <<
356 if ( this_connid != ii ) {
357 TR.Error <<
"WARNING: Residue connection id changed when creating a new residue at seqpos " <<
seqpos() <<
359 TR.Error <<
"WARNING: ResConnID info stored on residue " << src_rsd.
connect_map( ii ).
resid();
360 TR.Error <<
" is now out of date!" << std::endl;
377 Size which_connection_on_this_atom( 0 );
380 which_connection_on_this_atom = jj;
384 if ( which_connection_on_this_atom == 0 ) {
385 utility_exit_with_message(
"CATASTROPHIC ERROR in Residue::copy_residue_connections. ResidueType connection map integrity error");
387 if ( which_connection_on_this_atom <=
type().residue_connections_for_atom( this_connatom ).
size() ) {
389 type().residue_connections_for_atom( this_connatom )[ which_connection_on_this_atom ],
428 Size center, nbr1, nbr2;
432 assert( center && nbr1 && nbr2 );
450 utility::vector1< std::pair< std::string, std::string > >
const & atom_pairs
456 if( atom_pairs.size() != 3 ){
457 utility_exit_with_message(
"Three atom pairs must be provided in Residue::orient_onto_residue.");
483 rot_midpoint ( 0.5 * (
atom( nbr1 ).
xyz() +
atom( nbr2 ).
xyz() ) ),
484 src_midpoint ( 0.5 * ( src.
atom( src_nbr1 ).
xyz() + src.
atom( src_nbr2 ).
xyz() ) );
498 Vector const new_xyz( src_stub.local2global( rot_stub.global2local( old_xyz ) ) );
499 atoms()[i].xyz( new_xyz );
533 bool any_missing(
false );
551 if ( preserve_c_beta ) {
554 std::string root(
"CA"), mobile_new(
"CB"), mobile_src(
"CB");
565 assert(
xyz( root ) == src.
xyz( root ) );
568 cross(
xyz( mobile_new ) -
xyz( root ), src.
xyz( mobile_src ) - src.
xyz( root ) ) +
xyz( root )
570 Stub new_stub(
xyz( root ), pseudoatom,
xyz( mobile_new ) ),
571 src_stub( src.
xyz( root ), pseudoatom, src.
xyz( mobile_src ) );
579 Vector const new_xyz( src_stub.local2global( new_stub.global2local( old_xyz ) ) );
601 bool still_missing(
true );
602 while ( still_missing ) {
603 still_missing =
false;
610 TR.Warning <<
"[ WARNING ] missing an atom that depends on a nonexistent polymer connection! " <<
611 seqpos_ <<
' ' <<
atom_name(i) << std::endl <<
" --> using existing bogus coordinates!" << std::endl;
615 still_missing =
true;
618 bool stub_atoms_missing(
false );
619 for (
Size j=1; j<= 3; ++j ) {
622 stub_atoms_missing =
true;
623 if (
id.atomno() == i ) {
624 TR.Error <<
"[ ERROR ] missing atom " << i <<
" (" <<
atom_name(i) <<
") in " <<
type().
name() <<
" is its own stub" << std::endl;
625 utility_exit_with_message(
"Endless loop in fill_missing_atoms()");
631 if ( !stub_atoms_missing ) {
689 for (
Size i = 1; i <= num_connections; ++i) {
708 Size const resconn_index,
710 Size const other_connid
766 if ( old_resid == 0 )
continue;
768 Size const new_resid = old2new[ old_resid ];
783 std::map< Size, PseudoBondCollectionCOP > copy_pseudobonds(
pseudobonds_ );
785 for ( std::map< Size, PseudoBondCollectionCOP >::const_iterator
786 pb_iter = copy_pseudobonds.begin(),
787 pb_iter_end = copy_pseudobonds.end();
788 pb_iter != pb_iter_end; ++pb_iter ) {
789 Size old_neighbor_resid = pb_iter->first;
790 Size new_neighbor_resid = old2new[ old_neighbor_resid ];
791 if ( ! new_neighbor_resid )
continue;
792 pseudobonds_[ new_neighbor_resid ] = pb_iter->second->clone_with_new_sequence_numbering( old2new );
802 Size const resconn_index,
809 return ipos.distance( matchpoint );
880 utility_exit_with_message(
"Residue::conect_atom: I'm not bonded to that other residue!!");
887 std::map< Size, PseudoBondCollectionCOP >::const_iterator iter(
pseudobonds_.find( resid ) );
911 Size num_neighbors(0);
914 for (
Size i = 1; i <= intrares_atomnos.size(); ++i) {
915 if (virt || !
is_virtual(intrares_atomnos[i]) ) ++num_neighbors;
920 for (
Size i = 1; i <= num_connections; ++i) {
925 return num_neighbors;
936 int const effchi = (chino==0)? 1 : 0;
937 int const baseatom = (chino==0)? 2 : 3;
948 Vector const v( (setting-current_d)*axis );
954 assert( std::abs( new_d - setting ) < 1e-2 );
963 int const effchi = (chino==0)? 1 : 0;
964 int const baseatom = (chino==0)? 2 : 3;
969 Real const current_theta
974 Vector const axis (v12.cross(v23).normalized());
981 ( numeric::rotation_matrix_degrees( axis, - setting + current_theta ) );
984 Vector const v( chi_atom2_xyz - R * chi_atom2_xyz );
989 ASSERT_ONLY(
Real const new_th(numeric::angle_degrees(
991 assert( std::abs( basic::subtract_degree_angles( new_th, setting ) ) < 1e-2 );
1014 chi_[ chino ] = setting;
1019 Real const current_chi
1032 ( numeric::rotation_matrix_degrees( axis, setting - current_chi ) );
1035 Vector const v( chi_atom3_xyz - R * chi_atom3_xyz );
1041 ASSERT_ONLY(
Real const new_chi
1046 assert( std::abs( basic::subtract_degree_angles( new_chi, setting ) ) <
1088 for (
Size i=1; i<=
nbrs.size(); ++i ) {
1089 int const nbr(
nbrs[i] );
1091 if ( nbr_base == atomno ) {
1092 if ( my_atom_base != nbr ) {
1095 TR.Warning <<
"DANGER: almost got stuck in infinite loop!" << std::endl;
1106 for (
Size atom_idx = 1; atom_idx <=
type().
natoms(); ++atom_idx ) {
1117 (
type().upper_connect_id() == 0 ||
1124 (
type().lower_connect_id() == 0 ||
1138 os << res.
name() <<
' ' << res.
seqpos() <<
": \n";
1142 os << atom.xyz()(1) <<
' ' << atom.xyz()(2) <<
' '<< atom.xyz()(3) << std::endl;
1153 os <<
"Atom type:" << atom.
type() <<
" xyz:" << atom.
xyz().x() <<
' ' << atom.
xyz().y() <<
' ' << atom.
xyz().z();
1164 #ifdef USEBOOSTSERIALIZE
1168 using namespace core::pack::dunbrack;
1172 static_cast< SingleLigandRotamerLibrary const * >
1173 ( RotamerLibrary::get_instance().get_rsd_library( base_res )() ));
1174 if( old_lrots != 0 ) {
1179 for(
core::Size at_ct = 1; at_ct <= new_rot_res->natoms(); at_ct++){
1180 if( !(*oldrot_it)->has( new_rot_res->atom_name( at_ct ) ) ){
1181 std::cerr <<
"Unexpected ERROR: when regenerating ligand rotamer library (for covalent constraints), one atom wasn't found in a template rotamer." << std::endl;
1182 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
1185 new_rot_res->set_xyz( at_ct, (*oldrot_it)->xyz( new_rot_res->atom_name( at_ct ) ) );
1188 new_rot_res->chi( (*oldrot_it)->chi() );
1189 new_rotamers.push_back( new_rot_res );
1191 new_lrots->set_reference_energy( old_lrots->get_reference_energy() );
1192 new_lrots->set_rotamers( new_rotamers );
1194 RotamerLibrary::get_instance().add_residue_library( new_res, new_lrots );