Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SequenceCouplingConstraint.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/scoring/constraints/SequnceCouplingConstraint.cc
11 /// @brief This is a constraint that refers to a core::sequence::SequnceCopuling? in order to influence the scoring of amino acid types based on multiple sequence alignments (i.e. for biasing amino acid choices during design). A note about the SequenceProfile::read_from_checkpoint function that is used to read in scores for amino acid types: the first line of the file will be ignored.
12 /// @author HetuKamisetty
13 
15 
18 #include <core/pose/Pose.hh>
19 
21 
22 #include <basic/Tracer.hh>
23 
24 #include <utility/file/file_sys_util.hh> // file_exists, create_directory
25 
26 // AUTO-REMOVED #include <basic/options/option.hh>
27 // option key includes
28 // AUTO-REMOVED #include <basic/options/keys/in.OptionKeys.gen.hh>
29 
30 //Auto Headers
31 #include <core/id/AtomID.hh>
34 #include <utility/vector1.hh>
35 #include <basic/options/keys/OptionKeys.hh>
36 
37 //#include <core/id/SequenceMapping.hh>
38 
39 
40 namespace protocols {
41 namespace constraints_additional {
42 
43 using namespace core;
44 using namespace chemical;
45 using namespace conformation;
46 using namespace basic::options;
47 using namespace scoring;
48 using namespace constraints;
49 using namespace sequence;
50 
51 using basic::t_warning;
52 using basic::t_info;
53 using basic::t_debug;
54 using basic::t_trace;
55 static basic::Tracer TR("protocols.constraints_additional.SequenceCouplingConstraint");
56 
59  seqpos1_(0),
60  seqpos2_(0),
61  sequence_coupling_(NULL)
62 {}
63 
65  Pose const &,
66  Size seqpos1,
67  Size seqpos2,
68  SequenceCouplingOP coupling/* = NULL */
69 ):
71  seqpos1_(seqpos1),
72  seqpos2_(seqpos2),
73  sequence_coupling_( coupling)
74 {}
75 
77  Size seqpos1,
78  Size seqpos2,
79  SequenceCouplingOP sequence_coupling /* = NULL */
80 ):
82  seqpos1_( seqpos1 ),
83  seqpos2_( seqpos2 ),
84  sequence_coupling_( sequence_coupling )
85 {}
86 
88 
91  return new SequenceCouplingConstraint( *this );
92 }
93 
94 ///@details one line definition "SequenceProfile resindex profilefilename" (profilefilename can also be set to "none" in the constraints file, and specified by -in::file::pssm)
95 void
97  std::istream & is,
98  Pose const & pose,
99  FuncFactory const &
100 )
101 {
102  Size residue_index1(0);
103  Size residue_index2(0);
104  std::string coupling_filename;
105 
106 // note: is >> "SequenceProfile" has already occured
107  is >> residue_index1 >> residue_index2 >> coupling_filename;
108 
109  TR(t_debug) << "reading: " << residue_index1 << " " << residue_index2 << " " << coupling_filename << std::endl;
110  if ( residue_index1 < 1 || residue_index1 > pose.total_residue() ) {
111  std::cerr << "no such residue index " << residue_index1 << " in pose!)" << std::endl;
112  utility_exit();
113  }
114  if ( residue_index2 < 1 || residue_index2 > pose.total_residue() ) {
115  std::cerr << "no such residue index " << residue_index2 << " in pose!)" << std::endl;
116  utility_exit();
117  }
118 
119  seqpos1_ = residue_index1;
120  seqpos2_ = residue_index2;
121 
122  // figure out sequence profile filename
123  using namespace utility::file;
124  // if specified, verify file exists
125  if ( coupling_filename!= "none" ) {
126  if ( ! file_exists( coupling_filename ) ) {
127  utility_exit_with_message( "no such file " + coupling_filename );
128  }
129  // if filename not specified, load from commandline option -pssm only if sequence_coupling_ is NULL
130  } else {
131  utility_exit_with_message("\"none\" is not a valid value for -pssm in this context!");
132  }
133 
134  // if filename is not "none" by this point, read it even if sequence_coupling_ is not currently NULL
135  if ( coupling_filename != "none" ) {
137  sequence_coupling_->read_from_file( FileName(coupling_filename) );
138  }
139 
140  // if sequence_coupling_ is still NULL by this point, it is assumed that the user intended so
141 
142 } // read_def
143 
144 void
145 SequenceCouplingConstraint::show_def( std::ostream & os, Pose const & ) const
146 {
147  show( os );
148 }
149 
150 void
151 SequenceCouplingConstraint::show( std::ostream & os ) const {
152  os << "SequenceCouplingConstraint between seqpos " << seqpos1_ << " " << seqpos2_ << ": ";
153  if ( ! sequence_coupling_ ) os << "(uninitialized sequence profile)";
154 // else {
155 // typedef utility::vector1<Real> RealVec;
156 // RealVec const & aa_scores( sequence_profile_->prof_row( seqpos_ ) );
157 // runtime_assert( aa_scores.size() >= num_canonical_aas );
158 // for ( Size aa(1); aa <= num_canonical_aas; ++aa ) {
159 // os << aa_scores[aa] << " ";
160 // }
161 // }
162  os << '\n';
163 }
164 
165 void
167 {
168  sequence_coupling_ = profile;
169 }
170 
173 
176 
180  pos_list.push_back(seqpos1_);
181  pos_list.push_back(seqpos2_);
182  return pos_list;
183 }
184 
185 /*
186  * hk: how does one fix sequencecoupling on a remap_resid call?
187  *
188 ConstraintOP
189 SequenceCouplingConstraint::remap_resid(
190  SequenceMapping const & seqmap
191 ) const {
192  Size newseqpos1( seqmap[ seqpos1_ ] );
193  if ( newseqpos != 0 ) {
194  TR(t_debug) << "Remapping resid " << seqpos1_ << " to " << newseqpos1 << std::endl;
195 
196  return new SequenceCouplingConstraint( newseqpos1, newseqpos2, sequence_coupling_ );
197  }
198  else return NULL;
199 }
200 */
201 
202 // Calculates a score for this constraint using XYZ_Func, and puts the UNWEIGHTED score into
203 // emap. Although the current set of weights currently is provided, Constraint objects
204 // should put unweighted scores into emap.
205 void
207  XYZ_Func const & xyz_func,
208  EnergyMap const & weights,
209  EnergyMap & emap
210 ) const
211 {
212  if ( weights[ this->score_type() ] == 0 ) return; // what's the point?
213  runtime_assert( sequence_coupling_ );
214 
215  chemical::AA aa1( xyz_func.residue( seqpos1_ ).type().aa() );
216  chemical::AA aa2( xyz_func.residue( seqpos2_ ).type().aa() );
217  if ( seqpos1_ > sequence_coupling_->npos() || seqpos2_ > sequence_coupling_->npos()) return; // safety/relevance check
218 
219  Size edgeId = sequence_coupling_->findEdgeId(seqpos1_, seqpos2_);
220  Real score( 0);
221  if(edgeId<=0){//direction important. if (i,j) edge exists, will not return if (j,i) asked
222  edgeId = sequence_coupling_->findEdgeId(seqpos2_, seqpos1_);
223 
224  //epot = sequence_coupling_->edgePotBetween(edgeId);
225  utility::vector1< utility::vector1 < Real > > const & epot(sequence_coupling_->edgePotBetween(edgeId));
226  //runtime_assert(epot);
227  /*
228  if(epot==NULL){
229  std::cerr << "no such edge " << seqpos1_ << " " << seqpos2_ << " in sequence coupling !)" << std::endl;
230  utility_exit();
231  }
232  */
233  score = epot[aa2][aa1];
234  }else{
235  utility::vector1< utility::vector1 < Real > > const & epot(sequence_coupling_->edgePotBetween(edgeId));
236  //runtime_assert(epot);
237  score = epot[aa1][aa2];
238  }
239 
240  TR(t_trace) << "seqpos1 " << seqpos1_ << " aa1 " << aa1 << " " << "seqpos2 " << seqpos2_<< " aa2 "<< aa2 << " " << score << std::endl;
241 
242  emap[ this->score_type() ] += score;//pot scores are like energies; lower better.
243 }
244 
245 void
247  AtomID const & ,//atom,
248  XYZ_Func const & ,//conformation,
249  Vector & ,//f1,
250  Vector & ,//f2,
251  EnergyMap const & //weights
252 ) const
253 {
254  // Do nothing, as the value of this function doesn't change with respect to
255  // the torsions.
256 }
257 
258 } // namespace constraints_additional
259 } // namespace protocols