29 #include <ObjexxFCL/format.hh>
32 #include <utility/PyAssert.hh>
33 #include <utility/io/izstream.hh>
34 #include <utility/string_util.hh>
36 #include <utility/vector1.hh>
39 using namespace ObjexxFCL;
40 using namespace ObjexxFCL::fmt;
43 namespace kinematics {
46 MoveMap::~MoveMap() {}
48 void MoveMap::set_ranges_unmodifiable(
const std::vector<std::pair<Size, Size> >& ranges) {
53 vector<pair<Size, Size> >::const_iterator i;
54 for (i = ranges.begin(); i != ranges.end(); ++i) {
55 Size begin = i->first;
62 for (
Size i = begin; i <=
end; ++i) set_bb(i,
false);
71 torsion_type_map_.clear();
72 move_map_torsion_id_map_.clear();
73 torsion_id_map_.clear();
75 dof_type_map_.clear();
83 MoveMap::set_jump(
id::JumpID const & jump,
bool const setting ) {
84 jump_id_map_[ jump ] = setting;
95 torsion_type_map_[
t] = setting;
98 std::vector< MoveMapTorsionID > l;
100 for ( MoveMapTorsionID_Map::const_iterator
101 it=move_map_torsion_id_map_.begin(), it_end = move_map_torsion_id_map_.end(); it != it_end; ++it ) {
105 if ( it->first.second == t ) l.push_back( it->first );
108 for ( std::vector< MoveMapTorsionID >::const_iterator it=l.begin(), it_end=l.end(); it != it_end; ++it ) {
109 move_map_torsion_id_map_.erase( move_map_torsion_id_map_.find( *it ) );
114 std::vector< TorsionID > l;
115 for ( TorsionID_Map::const_iterator
116 it=torsion_id_map_.begin(), it_end = torsion_id_map_.end(); it != it_end; ++it ) {
117 if ( it->first.type() ==
t ) l.push_back( it->first );
120 for ( std::vector< TorsionID >::const_iterator it=l.begin(), it_end=l.end(); it != it_end; ++it ) {
121 torsion_id_map_.erase( torsion_id_map_.find( *it ) );
127 jump_id_map_.clear();
139 move_map_torsion_id_map_[ id ] = setting;
142 Size const seqpos(
id.first );
144 std::vector< TorsionID > l;
145 for ( TorsionID_Map::const_iterator
146 it=torsion_id_map_.begin(), it_end = torsion_id_map_.end(); it != it_end; ++it ) {
147 if ( it->first.type() == torsion_type && it->first.rsd() == seqpos ) l.push_back( it->first );
150 for ( std::vector< TorsionID >::const_iterator it=l.begin(), it_end=l.end(); it != it_end; ++it ) {
151 torsion_id_map_.erase( torsion_id_map_.find( *it ) );
159 MoveMap::set(
TorsionID const &
id,
bool const setting )
162 torsion_id_map_[ id ] = setting;
184 dof_type_map_[
t ] = setting;
188 std::vector< DOF_ID > l;
189 for ( DOF_ID_Map::const_iterator it=dof_id_map_.begin(),
190 it_end=dof_id_map_.end(); it != it_end; ++it ) {
191 if ( it->first.type() ==
t ) {
192 l.push_back( it->first );
196 for ( std::vector< DOF_ID >::const_iterator it=l.begin(), it_end=l.end();
197 it != it_end; ++it ) {
198 dof_id_map_.erase( dof_id_map_.find( *it ) );
211 if (
get(
id) == setting )
return;
213 dof_id_map_[ id ] = setting;
219 JumpID_Map::const_iterator jid = jump_id_map_.find( jump );
220 if ( jid != jump_id_map_.end() ) {
233 TorsionTypeMap::const_iterator i = torsion_type_map_.find( t );
234 if ( i == torsion_type_map_.end() ) {
247 MoveMapTorsionID_Map::const_iterator i = move_map_torsion_id_map_.find(
id );
248 if ( i == move_map_torsion_id_map_.end() ) {
263 if ( !
id.valid() )
return false;
265 TorsionID_Map::const_iterator i = torsion_id_map_.find(
id );
266 if ( i == torsion_id_map_.end() ) {
268 return get( move_map_torsion_id );
280 DOF_TypeMap::const_iterator iter( dof_type_map_.find( type ) );
281 if ( iter == dof_type_map_.end() ) {
294 if ( !
id.valid() )
return false;
296 DOF_ID_Map::const_iterator iter( dof_id_map_.find(
id ) );
297 if ( iter == dof_id_map_.end() ) {
298 return get(
id.type() );
309 MoveMap::TorsionTypeMap::const_iterator
311 return torsion_type_map_.find( t );
320 MoveMap::MoveMapTorsionID_Map::const_iterator
322 return move_map_torsion_id_map_.find(
id );
331 MoveMap::TorsionID_Map::const_iterator
333 return torsion_id_map_.find(
id );
341 MoveMap::JumpID_Map::const_iterator
343 return jump_id_map_.find( jump );
351 MoveMap::DOF_TypeMap::const_iterator
353 return dof_type_map_.find( t );
361 MoveMap::DOF_ID_Map::const_iterator
362 MoveMap::find(
DOF_ID const &
id )
const {
363 return dof_id_map_.find(
id );
382 utility::io::izstream data( filename.c_str() );
384 utility_exit_with_message(
"ERROR: could not open file " + filename );
407 bool res_default_set=
false, jump_default_set=
false;
408 while( getline(data,line) ) {
409 if ( line.substr(0,1) ==
"#" )
continue;
410 if ( line ==
"" )
continue;
413 if( tokens.size() > 0 ) {
414 if ( tokens[1] ==
"JUMP" || tokens[1] ==
"jump" ) {
415 if (tokens.size() < 2) {
416 utility_exit_with_message(
"Error reading movemap at line: " + line );
419 if ( tokens[2] ==
"*" ) {
420 if (jump_default_set) {
421 utility_exit_with_message(
"Error reading movemap: default jump set multiple times!" );
423 jump_default_set=
true;
424 if ( tokens.size() < 3 || tokens[3] ==
"YES" || tokens[3] ==
"yes" ) {
426 }
else if (tokens[3] ==
"NO" || tokens[3] ==
"no" ){
429 utility_exit_with_message(
"Error reading movemap at line: " + line );
434 if ( tokens.size() < 3 || tokens[3] ==
"YES" || tokens[3] ==
"yes" ) {
435 set_jump( jump_num,
true );
436 }
else if (tokens[3] ==
"NO" || tokens[3] ==
"no" ){
437 set_jump( jump_num,
false );
439 utility_exit_with_message(
"Error reading movemap at line: " + line );
442 }
else if ( tokens[1] ==
"RESIDUE" || tokens[1] ==
"residue" ) {
443 if (tokens.size() < 3) {
444 utility_exit_with_message(
"Error reading movemap at line: " + line );
446 if ( tokens[2] ==
"*" ) {
447 if (res_default_set) {
448 utility_exit_with_message(
"Error reading movemap: default residue set multiple times!" );
450 res_default_set=
true;
451 if ( tokens[3] ==
"BB" || tokens[3] ==
"bb" ) {
452 set_bb(
true ); set_chi(
false );
453 }
else if (tokens[3] ==
"CHI" || tokens[3] ==
"chi" ){
454 set_bb(
false ); set_chi(
true );
455 }
else if (tokens[3] ==
"BBCHI" || tokens[3] ==
"bbchi" ){
456 set_bb(
true ); set_chi(
true );
457 }
else if (tokens[3] ==
"NO" || tokens[3] ==
"no" ){
458 set_bb(
false ); set_chi(
false );
460 utility_exit_with_message(
"Error reading movemap at line: " + line );
463 }
else if (tokens.size() == 3) {
465 if ( tokens[3] ==
"BB" || tokens[3] ==
"bb" ) {
466 set_bb( start_res,
true ); set_chi( start_res,
false );
467 }
else if (tokens[3] ==
"CHI" || tokens[3] ==
"chi" ){
468 set_bb( start_res,
false ); set_chi( start_res,
true );
469 }
else if (tokens[3] ==
"BBCHI" || tokens[3] ==
"bbchi" ){
470 set_bb( start_res,
true ); set_chi( start_res,
true );
471 }
else if (tokens[3] ==
"NO" || tokens[3] ==
"no" ){
472 set_bb( start_res,
false ); set_chi( start_res,
false );
474 utility_exit_with_message(
"Error reading movemap at line: " + line );
479 if ( start_res > end_res ) {
480 utility_exit_with_message(
"Error reading movemap at line: " + line );
482 if ( tokens[4] ==
"BB" || tokens[4] ==
"bb" ) {
483 for (
core::Size i = start_res; i<= end_res; ++i) {
484 set_bb( i,
true ); set_chi( i,
false );
486 }
else if (tokens[4] ==
"CHI" || tokens[4] ==
"chi" ){
487 for (
core::Size i = start_res; i<= end_res; ++i) {
488 set_bb( i,
false ); set_chi( i,
true );
490 }
else if (tokens[4] ==
"BBCHI" || tokens[4] ==
"bbchi" ){
491 for (
core::Size i = start_res; i<= end_res; ++i) {
492 set_bb( i,
true ); set_chi( i,
true );
494 }
else if (tokens[4] ==
"NO" || tokens[4] ==
"no" ){
495 for (
core::Size i = start_res; i<= end_res; ++i) {
496 set_bb( i,
false ); set_chi( i,
false );
499 utility_exit_with_message(
"Error reading movemap at line: " + line );
503 utility_exit_with_message(
"Error reading movemap at line: " + line );
511 MoveMap::show( std::ostream & out,
Size total_residue)
const
513 PyAssert( (total_residue>0),
"MoveMap::show( std::ostream & out , Size total_residue ): input variable total_residue has a meaningless value");
514 out <<
A(8,
"resnum")<<
' '<<
A(8,
"BB") <<
' '<<
A(8,
"CHI")<<std::endl;
515 for (
Size i = 1; i <= total_residue; i++){
518 if (get_bb(i)) bb =
"TRUE ";
519 if (get_chi(i)) chi =
"TRUE ";
520 out << I(8,3,i) <<
' '<<
A(8, bb)<<
' ' <<
A(8, chi)<<
'\n';
525 MoveMap::show( std::ostream & out )
const
527 out <<
"-------------------------------\n";
528 out <<
A(8,
"resnum")<<
' '<<
A(8,
"Type") <<
' '<<
A(12,
"TRUE/FALSE ")<<std::endl;
529 out <<
"-------------------------------\n";
533 for (MoveMapTorsionID_Map::const_iterator it = movemap_torsion_id_begin(), it_end = movemap_torsion_id_end(); it != it_end; ++it){
535 bool boolean = it->second;
536 Size res = mmtorsionID.first;
541 if (torsiontype == 1) {type =
"BB ";}
542 else if (torsiontype == 2) {type =
"SC ";}
543 else if (torsiontype == 3) {
544 type =
"JUMP"; jumpbool.push_back(
boolean); jumpnum.push_back(res);}
547 if ((prev_resnum == mmtorsionID.first) && (type !=
"JUMP")) {
548 out <<
A(8,
' ') <<
' '<<
A(8,type) <<
' '<<
A(8,(
boolean ?
"TRUE":
"FALSE"))<<
"\n";
550 else if ((prev_resnum != mmtorsionID.first) && (type !=
"JUMP")) {
551 out << I(8,3,res) <<
' '<<
A(8,type) <<
' '<<
A(8,(
boolean ?
"TRUE":
"FALSE"))<<
"\n";
557 out <<
"-------------------------------\n";
558 out <<
A(8,
"jumpnum")<<
' '<<
A(8,
"Type") <<
' '<<
A(12,
"TRUE/FALSE ")<<std::endl;
559 out <<
"-------------------------------\n";
560 for (
Size i = 1; i <= jumpnum.size(); ++i) {
561 out << I(8,3,jumpnum[i])<<
' '<<
A(8,
"JUMP") <<
' '<<
A(8,(jumpbool[i] ?
"TRUE":
"FALSE"))<<
"\n";
574 bool const import_true_settings,
575 bool const import_false_settings
585 if ( ( import_true_settings && i->second ) || ( import_false_settings && !i->second ) ) {
586 set( i->first, i->second );
593 if ( ( import_true_settings && i->second ) || ( import_false_settings && !i->second ) ) {
594 set( i->first, i->second );
601 if ( ( import_true_settings && i->second ) || ( import_false_settings && !i->second ) ) {
602 set( i->first, i->second );
610 if ( ( import_true_settings && i->second ) || ( import_false_settings && !i->second ) ) {
611 set( i->first, i->second );
618 if ( ( import_true_settings && i->second ) || ( import_false_settings && !i->second ) ) {
619 set( i->first, i->second );
627 if ( ( import_true_settings && i->second ) || ( import_false_settings && !i->second ) ) {
628 set_jump( i->first, i->second );