14 #include <utility/fixedsizearray1.hh>
33 #include <basic/Tracer.hh>
41 #include <utility/string_util.hh>
42 #include <utility/io/izstream.hh>
51 #include <utility/vector1.hh>
59 static basic::Tracer
TR(
"core.pack.dunbrack.SingleLigandRotamerLibrary");
65 std::ofstream out( filename.c_str() );
66 for(
Size i = 1; i <= rotamers.size(); ++i) {
94 rotamers_( rotamers_in ),
95 ref_energy_( ref_E_in )
107 utility::io::izstream data( filename.c_str() );
108 if ( !data.good() ) {
109 utility_exit_with_message(
"Unable to open file: " + filename +
'\n' );
113 std::set< std::string > skipped_atom_names;
115 bool found_ref_energy =
false;
124 while( std::getline( (std::istream&)data, line) ) {
125 if( utility::startswith(line,
"ATOM ") || utility::startswith(line,
"HETATM") ) {
126 if( line.length() < 54 ) {
127 TR <<
"ATOM/HETATM line too short in PDB-format rotamer file!" << std::endl;
132 x = std::atof( line.substr(30,8).c_str() );
133 y = std::atof( line.substr(38,8).c_str() );
134 z = std::atof( line.substr(46,8).c_str() );
136 if( rsd.get() == NULL ) {
138 missing.clear(); missing.resize( restype->natoms(), true );
141 if( rsd->has( atom_name ) ) {
143 missing[ rsd->atom_index(atom_name) ] =
false;
145 }
else if( skipped_atom_names.count(atom_name) == 0 ) {
146 TR.Warning <<
"Skipping unrecognized atom '" << atom_name <<
"' in library for " << restype->name() << std::endl;
147 skipped_atom_names.insert(atom_name);
149 }
else if( utility::startswith(line,
"REF_EN") ) {
150 if( found_ref_energy ) {
151 TR.Error <<
"Reference energy specified more than once in PDB-format rotamer file!" << std::endl;
153 found_ref_energy =
true;
155 TR <<
"Reference energy for " << restype->name() <<
" is " <<
ref_energy_ << std::endl;
157 if( rsd.get() != NULL ) {
165 if( rsd.get() != NULL ) {
177 TR <<
"Read in " <<
rotamers_.size() <<
" rotamers for " << restype->name() <<
"!" << std::endl;
197 std::fill( dE_dbb.begin(), dE_dbb.end(), 0 );
198 std::fill( dE_dchi.begin(), dE_dchi.end(), 0 );
296 newrsd->chain( existing.
chain() );
297 newrsd->seqpos( existing.
seqpos() );
298 newrsd->copy_residue_connections_from( existing );
320 int const start_size = rotamers.size();
323 Size const max_total_rotamers = 21654;
328 if ( expand_proton_chi ) {
330 for (
Size ii = 1; ii <= concrete_residue->n_proton_chi(); ++ii ) {
334 concrete_residue->proton_chi_2_chi( ii ),
337 ii, proton_chi_chisets);
341 if(
rotamers_.size()*proton_chi_chisets.size() > max_total_rotamers ) {
342 TR.Warning <<
"Aborting proton_chi expansion for " << concrete_residue->name() <<
" because we would exceed " << max_total_rotamers <<
" rotamers!" << std::endl;
343 proton_chi_chisets.resize( max_total_rotamers /
rotamers_.size() );
347 new_rotamers.reserve(
rotamers_.size()*proton_chi_chisets.size() );
349 new_rotamers.reserve(
rotamers_.size() );
355 assert( concrete_residue->name() ==
rotamers_[i]->name() );
356 assert( concrete_residue->residue_type_set().name() ==
rotamers_[i]->residue_type_set().name() );
357 if ( expand_proton_chi ) {
358 for (
Size ii = 1; ii <= proton_chi_chisets.size(); ++ii ) {
360 new_rotamers.push_back( newrsd );
361 for (
Size jj = 1; jj <= concrete_residue->n_proton_chi(); ++jj ) {
363 concrete_residue->proton_chi_2_chi( jj ),
364 proton_chi_chisets[ ii ]->chi[ jj ] );
371 new_rotamers.push_back( newrsd );
400 rotamers.reserve( rotamers.size() + new_rotamers.size() );
401 for(
Size k = 1, k_end = new_rotamers.size(); k <= k_end; ++k) {
405 rotamers.push_back(newrsd);
409 int const end_size = rotamers.size();
410 TR <<
"Added " << end_size - start_size <<
" rotamers for " << concrete_residue->name() << std::endl;
421 assert( missing.size() == rsd->natoms() );
426 for (
Size i=1; i<= rsd->natoms(); ++i ) {
428 if ( ! rsd->atom_is_hydrogen( i ) && ! rsd->is_virtual( i ) ) {
429 utility_exit_with_message(
"Non-virtual heavy atom "+rsd->atom_name(i)+
" is missing in rotamer library for residue "+rsd->name()+
"!");
434 for (
Size j=1; j<= 3; ++j ) {
435 Size stubno( ic.stub_atom(j).atomno() );
436 if ( missing[ stubno ] ) {
437 TR.Error <<
"[ ERROR ] Missing atom " << stubno <<
" (" << rsd->atom_name(stubno) <<
") when trying to place atom " <<
438 i <<
" (" << rsd->atom_name(i) <<
") in " << rsd->name() << std::endl;
439 utility_exit_with_message(
"Cannot build missing atoms in ligand rotamer library");
445 rsd->set_xyz( i, ic.build( *rsd ) );
446 if( ! missed[ i ] ) {
448 TR <<
"Atom " << rsd->atom_name(i) <<
" from residue " << rsd->name() <<
" not found in PDB_ROTAMERS library, creating based on idealized geometry." << std::endl;
458 SingleResidueRotamerLibraryOP
459 SingleLigandRotamerLibrary::coarsify(coarse::Translator const & map) const
461 utility_exit_with_message("Ligand residue rotamers can't be coarsified!");
462 return NULL; // make compiler happy
473 utility_exit_with_message(
"Ligand residue rotamers can't be written to file!");