Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NamedAtomPairConstraint.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/NamedAtomPairConstraint.cc
11 ///
12 /// @brief
13 /// @author Oliver Lange
14 
15 // Unit Headers
17 
18 // Package Headers
21 
22 // Project Headers
25 #include <core/id/NamedAtomID.hh>
26 #include <core/id/AtomID.hh>
27 #include <core/pose/Pose.hh>
28 #include <core/pose/util.hh>
29 #include <core/id/Exceptions.hh>
30 
31 // Utility Headers
32 #include <basic/Tracer.hh>
33 
36 #include <utility/vector1.hh>
37 
38 //Auto Headers
39 #include <core/id/types.hh>
40 
41 static basic::Tracer tr("core.io.constraints");
42 
43 
44 namespace core {
45 namespace scoring {
46 namespace constraints {
47 
48 /// @details Auto-generated virtual destructor
50 
51 
52 /// @brief Copies the data from this Constraint into a new object and returns an OP
53 /// atoms are mapped to atoms with the same name in dest pose ( e.g. for switch from centroid to fullatom )
54 /// if a sequence_mapping is present it is used to map residue numbers .. NULL = identity mapping
55 /// to the new object. Intended to be implemented by derived classes.
59 
60  if ( smap ) {
61  atom1.rsd() = (*smap)[ atom1_.rsd() ];
62  atom2.rsd() = (*smap)[ atom2_.rsd() ];
63  }
64 
65  //get AtomIDs for target pose
68  if ( id1.valid() && id2.valid() ) {
69  return new NamedAtomPairConstraint( atom1, atom2, func_, score_type() );
70  } else {
71  return NULL;
72  }
73 }
74 
75 void
77  // if ( pose_chemical_checksum_ == pose.get_current_chemical_checksum() )
78  core::Size type1_id_now = (core::Size)&( xyz.residue( named_atom1_.rsd() ).type() );
79  core::Size type2_id_now = (core::Size)&( xyz.residue( named_atom2_.rsd() ).type() );
80  if ( type1_id_ != type1_id_now || type2_id_ != type2_id_now ) {
81  atom1_ = id::AtomID( xyz.residue( named_atom1_.rsd() ).atom_index( named_atom1_.atom() ), named_atom1_.rsd() );
82  atom2_ = id::AtomID( xyz.residue( named_atom2_.rsd() ).atom_index( named_atom2_.atom() ), named_atom2_.rsd() );
83  if ( !atom1_.valid() || !atom2_.valid() ) {
84  tr.Warning << "[WARNING] can't find atom for constraint"; show_def_nopose( tr.Warning );
85  tr.Warning << std::endl;
86  }
87  if ( !atom1_.valid() ) {
89  }
90  if ( !atom2_.valid() ) {
92  }
93  }
94 }
95 
96 void NamedAtomPairConstraint::show_def( std::ostream& out, pose::Pose const& ) const {
97  show_def_nopose( out );
98 }
99 
100 void NamedAtomPairConstraint::show_def_nopose( std::ostream& out ) const {
101  out << type() << " " << named_atom1_ << " " << named_atom2_ << " ";
102  func_->show_definition( out );
103 }
104 
105 ///@details one line definition "AtomPairs atom1 res1 atom2 res2 function_type function_definition"
106 void
108  std::istream& data,
109  core::pose::Pose const& pose,
110  FuncFactory const& func_factory
111 ) {
112  Size res1, res2;
113  std::string tempres1, tempres2;
114  std::string name1, name2;
115  std::string func_type;
117 
118  data
119  >> name1 >> tempres1
120  >> name2 >> tempres2
121  >> func_type;
122 
123  ConstraintIO::parse_residue( pose, tempres1, res1 );
124  ConstraintIO::parse_residue( pose, tempres2, res2 );
125 
126  tr.Debug << "read: " << name1 << " " << name2 << " " << res1 << " " << res2 << " func: " << func_type << std::endl;
127  if ( res1 > pose.total_residue() || res2 > pose.total_residue() ) {
128  tr.Warning << "ignored constraint (no such atom in pose!)"
129  << name1 << " " << name2 << " " << res1 << " " << res2 << std::endl;
130  data.setstate( std::ios_base::failbit );
131  return;
132  }
133 
134  named_atom1_ = id::NamedAtomID( name1, res1 );
135  named_atom2_ = id::NamedAtomID( name2, res2 );
138  if ( atom1_.atomno() == 0 || atom2_.atomno() == 0 ) {
139  tr.Warning << "Error reading atoms: read in atom names("
140  << name1 << "," << name2 << "), "
141  << "and found AtomIDs (" << atom1_ << "," << atom2_ << ")" << std::endl;
142  data.setstate( std::ios_base::failbit );
143  return;
144  }
145 
146  func_ = func_factory.new_func( func_type );
147  func_->read_data( data );
148 
149  //chu skip the rest of line since this is a single line defintion.
150  while( data.good() && (data.get() != '\n') ) {}
151 
152  if ( tr.Debug.visible() ) {
153  func_->show_definition( tr.Debug );
154  tr.Debug << std::endl;
155  }
156 } // read_def
157 
158 
160  AtomPairConstraintOP cst_in,
161  pose::Pose const& ref_pose ) :
162  atom1_( core::pose::atom_id_to_named_atom_id(cst_in->atom( 1 ), ref_pose )),
163  atom2_( core::pose::atom_id_to_named_atom_id(cst_in->atom( 2 ), ref_pose )),
164  cst_( cst_in )
165 {}
166 
168  NamedAtomID const& atom1,
169  NamedAtomID const& atom2,
170  AtomPairConstraintOP cst ) :
171  atom1_( atom1 ),
172  atom2_( atom2 ),
173  cst_( cst )
174 {}
175 
178  id::SequenceMapping const& map,
179  pose::Pose const& pose ) const
180 {
181  //get AtomIDs for target sequence and target pose
184  if ( id1.valid() && id2.valid() ) {
185  return new AtomPairConstraint( id1, id2, cst_->get_func().clone(), cst_->score_type() );
186  }
187  return NULL; // if translation not possible
188 }
189 
192 {
193  NamedAtomID id1 ( atom1_ );
194  NamedAtomID id2 ( atom2_ );
195  id1.rsd() = map[ id1.rsd() ];
196  id2.rsd() = map[ id2.rsd() ];
197  if ( id1.valid() && id2.valid() ) {
198  return new Obsolet_NamedAtomPairConstraint( id1, id2, cst_ );
199  }
200  return NULL;
201 }
202 
207  if ( id1.valid() && id2.valid() ) {
208  return new AtomPairConstraint( id1, id2, cst_->get_func().clone(), cst_->score_type() );
209  }
210  return NULL;
211 }
212 
213 std::ostream& operator<< ( std::ostream& out, Obsolet_NamedAtomPairConstraint const& cst ) {
214  return out << cst.atom1_ << " " << cst.atom2_ << " " << cst.cst_;
215 }
216 
217 
218 }
219 }
220 }