Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LocalCoordinateConstraint.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
11 /// @brief
12 
13 // Package Headers
22 #include <core/pose/Pose.hh>
23 #include <core/pose/util.hh>
24 #include <core/id/AtomID.hh>
25 
27 
28 // Utility Headers
29 #include <basic/Tracer.hh>
30 
31 
32 // C++ Headers
33 #include <cstdlib>
34 #include <iostream>
35 // AUTO-REMOVED #include <utility>
36 
37 #include <core/id/NamedStubID.hh>
39 #include <utility/vector1.hh>
40 #include <numeric/xyz.functions.hh>
41 
42 
43 
44 static basic::Tracer tr("core.LocalCoordinateConstraint");
45 
46 namespace core {
47 namespace scoring {
48 namespace constraints {
49 
50 Size
52  std::ostream & out,
53  pose::Pose const & pose,
54  Size verbose_level,
55  Real threshold
56 ) const{
57  if ( verbose_level > 80 ) {
58  out << "CoordConstraint ("
59  << pose.residue_type(atom_.rsd() ).atom_name( atom_.atomno() )
60  << ":" << atom_.atomno() << "," << atom_.rsd() << " ) ";
61  }
62  return func_->show_violations( out, dist( pose ), verbose_level, threshold );
63 }
64 
65 
66 /// @brief Copies the data from this Constraint into a new object and returns an OP
67 /// atoms are mapped to atoms with the same name in dest pose ( e.g. for switch from centroid to fullatom )
68 /// if a sequence_mapping is present it is used to map residue numbers .. NULL = identity mapping
69 /// to the new object. Intended to be implemented by derived classes.
75 
76  if ( smap ) {
77  atom1.rsd() = (*smap)[ atom(1).rsd() ];
78  atom2.rsd() = (*smap)[ atom(2).rsd() ];
79  atom3.rsd() = (*smap)[ atom(3).rsd() ];
80  atom4.rsd() = (*smap)[ atom(4).rsd() ];
81  }
82 
83  //get AtomIDs for target pose
88  if ( id1.valid() && id2.valid() && id3.valid() && id4.valid() ) {
89  return new LocalCoordinateConstraint( id1, id::StubID( id2, id3, id4) , xyz_target_, func_, score_type() );
90  } else {
91  return NULL;
92  }
93 }
94 
97 {
98  if ( seqmap[atom_.rsd()] !=0
99  && seqmap[ fixed_stub_.atom( 1 ).rsd() ] != 0
100  && seqmap[ fixed_stub_.atom( 2 ).rsd() ] != 0
101  && seqmap[ fixed_stub_.atom( 3 ).rsd() ] != 0 ) {
102  id::AtomID remap_a( atom_.atomno(), seqmap[ atom_.rsd() ] );
103  id::AtomID remap_s1( fixed_stub_.atom( 1 ).atomno(), seqmap[ fixed_stub_.atom( 1 ).rsd() ] );
104  id::AtomID remap_s2( fixed_stub_.atom( 2 ).atomno(), seqmap[ fixed_stub_.atom( 2 ).rsd() ] );
105  id::AtomID remap_s3( fixed_stub_.atom( 3 ).atomno(), seqmap[ fixed_stub_.atom( 3 ).rsd() ] );
106  id::StubID remap_stub( remap_s1, remap_s2, remap_s3 );
107  return ConstraintOP( new LocalCoordinateConstraint( remap_a, remap_stub, xyz_target_, this->func_, score_type() ) );
108  } else {
109  return NULL;
110  }
111 }
112 
113 
114 Real
116  conformation::Conformation const & conformation( pose.conformation() );
117  Vector const & xyz( conformation.xyz( atom_ ) );
118  kinematics::Stub my_stub( conformation.stub_from_id( fixed_stub_ ) );
119  return func( xyz_target_.distance( my_stub.global2local( xyz ) ) );
120  return xyz.distance( xyz_target_ );
121 }
122 
123 void
125  conformation::Conformation const & conformation( pose.conformation() );
126  kinematics::Stub my_stub( conformation.stub_from_id( fixed_stub_ ) );
127  xyz_target_ = my_stub.global2local( conformation.xyz( atom_ ) );
128  //tr.Trace << "get local xyz for " << atom_ << " " << xyz_target_.x() << " " << xyz_target_.y() << " " << xyz_target_.z() << " vs global: " // Vector bla( conformation.xyz( atom_ ) );
129  //tr.Trace << bla.x() << " " << bla.y() << " " << bla.z() << " " << std::endl;
130 }
131 
133  tr.Trace << "local target: " << xyz_target_.x() << " " << xyz_target_.y() << " " << xyz_target_.z() << std::endl;
134  conformation::Conformation const & conformation( local_frame_pose.conformation() );
135  kinematics::Stub my_stub( conformation.stub_from_id( fixed_stub_ ) );
136  tr.Trace << "stub: " << my_stub << std::endl;
137  return my_stub.local2global( xyz_target_ );
138 }
139 
140 void LocalCoordinateConstraint::set_xyz_target( Vector const& xyz_in, core::pose::Pose const& local_frame_pose ) {
141  conformation::Conformation const & conformation( local_frame_pose.conformation() );
142  kinematics::Stub my_stub( conformation.stub_from_id( fixed_stub_ ) );
143  xyz_target_=my_stub.global2local( xyz_in );
144 }
145 
146 ///@details one line definition "LocalCoordinateConstraint Atom1_Name Atom1_ResNum Atom2_Name Atom3_Name Atom4_Name Atom234_ResNum Atom1_target_X_coordinate Atom1_target_Y_coordinate Atom1_target_Z_coordinate Func_Type Func_Def"
147 void
149  std::istream& data,
150  core::pose::Pose const& pose,
151  FuncFactory const& func_factory
152 ) {
153  Size res1, res2;
154  std::string tempres1, tempres2;
155  std::string name1, name2, name3, name4;
156  std::string func_type;
158 
159  data
160  >> name1 >> tempres1
161  >> name2 >> name3 >> name4 >> tempres2
162  >> xyz_target_.x()
163  >> xyz_target_.y()
164  >> xyz_target_.z()
165  >> func_type;
166 
167  ConstraintIO::parse_residue( pose, tempres1, res1 );
168  ConstraintIO::parse_residue( pose, tempres2, res2 );
169 
170  tr.Debug << "read: " << name1 << " " << res1 << " " << name2 << " " << name3
171  << " " << name4 << " " << res2 << " func: " << func_type << std::endl;
172  if ( res1 > pose.total_residue() || res2 > pose.total_residue() ) {
173  tr.Warning << "ignored constraint (no such atom in pose!)"
174  << name1 << " " << name2 << " " << res1 << " " << res2 << std::endl;
175  data.setstate( std::ios_base::failbit );
176  return;
177  }
178 
180  fixed_stub_ = id::StubID( core::pose::named_stub_id_to_stub_id( id::NamedStubID( name2, name3, name4, res2 ), pose ));
181  if ( !atom_.valid() || !fixed_stub_.valid() ) {
182  tr.Warning << "Error reading atoms: read in atom names("
183  << name1 << "," << name2 << "), "
184  << "and found AtomIDs (" << atom_ << "," << fixed_stub_ << ")" << std::endl;
185  data.setstate( std::ios_base::failbit );
186  return;
187  }
188 
189  func_ = func_factory.new_func( func_type );
190  func_->read_data( data );
191 
192  if ( data.good() ) {
193  //chu skip the rest of line since this is a single line defintion.
194  while( data.good() && (data.get() != '\n') ) {}
195  if ( !data.good() ) data.setstate( std::ios_base::eofbit );
196  }
197 
198  if ( tr.Debug.visible() ) {
199  func_->show_definition( std::cout );
200  std::cout << std::endl;
201  }
202 } // read_def
203 
204 void
206  std::ostream& out,
207  core::pose::Pose const& pose ) const
208 {
209  out << type() << " " << core::pose::atom_id_to_named_atom_id( atom_, pose ) << " ";
211  out << stubid.atom( 1 ).atom() << " " <<
212  stubid.atom( 2 ).atom() << " " <<
213  stubid.atom( 3 ).atom() << " " << stubid.atom(1).rsd() << " ";
214 
215  out << xyz_target_.x() << " " << xyz_target_.y() << " " << xyz_target_.z() << " " ;
216  func_->show_definition( out );
217 }
218 
219 ///
220 Real
222  Vector const & xyz, //target
223  Vector const & s1, //fixed_stub.a
224  Vector const & s2, //fixed_stub.b
225  Vector const & s3 //fixed_stub.c
226 ) const
227 {
228 
229  kinematics::Stub my_stub( s1, s2, s3 );
230  //tr.Trace << "score: global "<< xyz.x() << " " << xyz.y() << " " << xyz.z() << std::endl;
231  Vector xyz_local( my_stub.global2local( xyz ) );
232  //tr.Trace << xyz_local.x() << " " << xyz_local.y() << " " << xyz_local.z() << " " << std::endl;
233  return func( xyz_target_.distance( my_stub.global2local( xyz ) ) );
234 }
235 
236 } // constraints
237 } // scoring
238 } // core