47 #include <basic/database/open.hh>
48 #include <basic/options/option.hh>
49 #include <utility/io/izstream.hh>
50 #include <basic/Tracer.hh>
53 #include <utility/file/FileName.hh>
64 #include <basic/options/keys/packing.OptionKeys.gen.hh>
65 #include <basic/options/keys/pH.OptionKeys.gen.hh>
66 #include <basic/options/keys/chemical.OptionKeys.gen.hh>
67 #include <basic/options/keys/in.OptionKeys.gen.hh>
71 #include <boost/foreach.hpp>
73 #include <utility/vector1.hh>
74 #define foreach BOOST_FOREACH
80 static basic::Tracer
tr(
"core.chemical.ResidueTypeSet");
87 std::vector< std::string >
const & extra_res_param_files,
88 std::vector< std::string >
const & extra_patch_files
91 database_directory_(directory)
93 using namespace basic::options;
107 std::string const list_filename( directory +
"residue_types.txt" );
108 utility::io::izstream data( list_filename.c_str() );
109 if ( !data.good() ) {
110 utility_exit_with_message(
"Unable to open file: " + list_filename +
'\n' );
113 while ( getline( data,line) ) {
115 if ( line.size() < 1 || line[0] ==
'#' )
continue;
119 bool no_proton_states =
false;
120 if ( line.size() > 20 ){
121 if ( ( !basic::options::option[ basic::options::OptionKeys::pH::pH_mode ].user() ) &&
122 ( line.substr (14,6) ==
"proton" ) ) {
123 no_proton_states =
true;
126 if ( no_proton_states )
continue;
129 if ((!option[OptionKeys::in::include_sugars]) &&
130 (line.substr(0, 27) ==
"residue_types/carbohydrates")) {
135 std::istringstream l( line );
137 if ( tag ==
"ATOM_TYPE_SET" ) {
140 }
else if ( tag ==
"ELEMENT_SET" ) {
143 }
else if ( tag ==
"MM_ATOM_TYPE_SET" ) {
146 }
else if(tag ==
"ORBITAL_TYPE_SET"){
175 if(basic::options::option[ basic::options::OptionKeys::in::add_orbitals]){
187 std::string const list_filename( directory+
"/patches.txt" );
188 utility::io::izstream data( list_filename.c_str() );
190 if ( !data.good() ) {
191 utility_exit_with_message(
"Unable to open patch list file: "+list_filename );
197 std::set< std::string > patches_to_avoid;
198 if ( basic::options::option[ basic::options::OptionKeys::chemical::exclude_patches ].user() ) {
200 for (
Size ii = 1; ii <= avoidlist.size(); ++ii ) {
202 patches_to_avoid.insert( fname.base() );
209 while ( getline( data,line) ) {
210 if ( line.size() < 1 || line[0] ==
'#' )
continue;
214 if ( patches_to_avoid.find( fname.base() ) != patches_to_avoid.end() ) {
215 tr <<
"While generating ResidueTypeSet " << name <<
": Skipping patch " << fname.base() <<
" as requested" << std::endl;
218 patch_filenames.push_back( directory + line );
223 if ( basic::options::option[ basic::options::OptionKeys::chemical::include_patches ].active() ) {
225 for (
Size ii = 1; ii <= includelist.size(); ++ii ) {
227 patch_filenames.push_back( directory + includelist[ ii ]);
228 tr <<
"While generating ResidueTypeSet " << name <<
": Including patch " << fname <<
" as requested" << std::endl;
239 if(basic::options::option[ basic::options::OptionKeys::in::add_orbitals]){
259 tr <<
"Finished initializing " << name <<
" residue type set. Created " <<
residue_types_.size() <<
" residue types" << std::endl;
286 utility::io::izstream data( list_filename.c_str() );
288 while ( getline( data, line ) ) {
290 filenames.push_back( basic::database::full_name( line ) );
295 read_files( filenames, atom_types, elements, mm_atom_types, orbital_types );
309 for (
Size ii=1; ii<= filenames.size(); ++ii ) {
329 ResidueTypeSet::apply_patches(
330 std::string const & list_filename
335 utility::vector1< std::string > filenames;
337 utility::io::izstream data( list_filename.c_str() );
338 if( !data.good() ) { utility_exit_with_message("Unable to open patch list file " + list_filename); }
340 while ( getline( data, line ) ) {
341 // add full database path to the patch filename
342 filenames.push_back( basic::database::full_name( line ) );
347 apply_patches( filenames );
355 ResidueTypeSet::coarsify(
356 pose::Pose &coarse_pose, pose::Pose const &fine_pose
360 coarsifier_->coarsify(coarse_pose,fine_pose);
374 for (
Size ii=1; ii<= filenames.size(); ++ii ) {
378 for (
Size i=1; i<= current_n_residue; ++i ) {
385 if ( new_rsd_type ) {
427 rsdtype_it != rsdtype_end; ++rsdtype_it ) {
442 if (
name_map_.count( rsd_ptr->name() ) ) {
443 std::stringstream err_msg;
444 err_msg <<
"Attempting to add a residue type with name '" + rsd_ptr->name() +
"' ";
445 err_msg <<
"but this name is already taken." << std::endl;
446 err_msg <<
"Please check your residue parameter files." << std::endl;
447 utility_exit_with_message(err_msg.str());
449 name_map_[ rsd_ptr->name() ] = rsd_ptr();
453 if ( rsd_ptr->aa() !=
aa_unk ) {
454 aa_map_[ rsd_ptr->aa() ].push_back( rsd_ptr() );
461 name3_map_[ rsd_ptr->name3() ].push_back( rsd_ptr() );
466 if ( rsd_ptr->name3() != rsd_ptr->name().substr(0,3) ) {
467 name3_map_[ rsd_ptr->name().substr(0,3) ].push_back( rsd_ptr() );
484 ResidueTypeCOPs::iterator aa_it(std::find(
aa_map_[rsd->aa()].begin(),
aa_map_[rsd->aa()].end(),rsd));
485 aa_map_[rsd->aa()].erase(aa_it);
486 if(
aa_map_[rsd->aa()].size() == 0)
495 ResidueTypeCOPs::iterator name3_it(std::find(
name3_map_[rsd->name3()].begin(),
name3_map_[rsd->name3()].end(),rsd));
502 if(rsd->name3() != rsd->name().substr(0,3))
504 name3_it = std::find(
name3_map_[rsd->name3().substr(0,3)].begin(),
name3_map_[rsd->name3().substr(0,3)].end(),rsd);
505 name3_map_[rsd->name3().substr(0,3)].erase(name3_it);
506 if(
name3_map_[rsd->name3().substr(0,3)].size() == 0)
515 std::list< AA >::const_iterator
521 std::list< AA >::const_iterator
537 if ( selector[ **iter ] ) {
538 matches.push_back( (*iter)() );
559 if ( !init_rsd.
has_variant_type(new_type) ) target_variants.push_back( new_type );
561 Size const nvar( target_variants.size() );
565 iter != iter_end; ++iter ) {
569 for (
Size i=1; i<= nvar; ++i ) {
575 if ( match ==
true ) {
580 utility_exit_with_message(
"unable to find desired variant residue: "+init_rsd.
name()+
" "+base_name+
" "+new_type);
596 target_variants.erase( std::find( target_variants.begin(), target_variants.end(), old_type ) );
598 Size const nvar( target_variants.size() );
602 iter != iter_end; ++iter ) {
606 for (
Size i=1; i<= nvar; ++i ) {
612 if ( match ==
true ) {
617 utility_exit_with_message(
"unable to find desired non-variant residue: "+init_rsd.
name()+
" "+base_name+
" "+old_type);
629 utility::options::StringVectorOption & add_set
630 = basic::options::option[ basic::options::OptionKeys::packing::adducts ];
633 if( add_set.size() == 0 )
return;
651 for( AdductMap::iterator add_iter = blank_map.begin(),
652 end_iter = blank_map.end() ;
653 add_iter != end_iter ; ++add_iter ) {
654 add_iter->second = 0;
659 iter != iter_end; ++iter ) {
675 if(basic::options::option[ basic::options::OptionKeys::in::add_orbitals]){
690 utility_exit_with_message(
"ResidueTypeSet does not have a residue called "+name+
" so it cannot be deleted.");
714 if( std::find( add_mask.begin(), add_mask.end(), true ) == add_mask.end() ) {
721 foreach(
bool make, add_mask){
722 std::cout <<
"Adduct " << add_iter->adduct_name() <<
" make is " << make << std::endl;
735 AdductMap::iterator test_iter =
736 ref_map.find( work_iter->adduct_name() );
738 if ( test_iter != ref_map.end() &&
739 count_map[ test_iter->first ] < ref_map[ test_iter->first ] ) {
741 new_count_map[ work_iter->adduct_name() ]++;