Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomICoor.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 declaration of implementation class for abstract class Residue
12 /// @author Phil Bradley
13 /// @author Modified by Sergey Lyskov
14 
15 
16 // Unit headers
18 
19 // Project headers
22 #include <basic/Tracer.hh>
23 
24 // Numeric headers
25 // Commented by inclean daemon #include <numeric/xyz.functions.hh>
26 
27 // Utility headers
28 // Commented by inclean daemon #include <utility/exit.hh>
29 
30 // AUTO-REMOVED #include <ObjexxFCL/ObjexxFCL.hh>
31 #include <ObjexxFCL/string.functions.hh>
32 
33 #include <utility/vector1.hh>
34 #include <numeric/xyz.functions.hh>
35 
36 //Auto using namespaces
37 namespace ObjexxFCL { } using namespace ObjexxFCL; // AUTO USING NS
38 //Auto using namespaces end
39 
40 
41 // C++ headers
42 // Commented by inclean daemon #include <string>
43 
44 
45 namespace core {
46 namespace chemical {
47 
48 static basic::Tracer tw( "core.chemical.AtomICoor", basic::t_warning );
49 
50 //////////////////////////////////////////////////////////////////////////////////////////////////
51 /**
52  After atom name is read in from residue param file, ICoorAtomID type_ and atomno_ is defined as:
53 
54  - Anything less than four character is considered as INTERNAL atom name and its atom index
55  number is assigned as atomno_;
56 
57  - "LOWER" and "UPPER" for polymer lower and upper connections. Since they are unique, no atomno_
58  is given ( e.g., 0)
59 
60  - Non-polymer connections are flagged by "CONN*" in which * represents the index number of
61  this connection in the ResidueType ( from 1 to ResidueType.n_connection() ). This number is assigned
62  as atomno_.
63  */
64 ICoorAtomID::ICoorAtomID(
65  std::string name,
66  ResidueType const & rsd_type
67 )
68 {
69  if ( name.size() <= 4 ) {
70  type_ = INTERNAL;
71  atomno_ = rsd_type.atom_index( name );
72  } else if ( name.substr(0,4) == "CONN" ) {
73  type_ = CONNECT;
74  assert( is_int( name.substr(4) ) );
75  atomno_ = int_of( name.substr(4) );
76  assert( atomno_ > 0 && atomno_ <= rsd_type.n_residue_connections() );
77  } else if ( name == "LOWER" ) {
78  type_ = POLYMER_LOWER; atomno_ = 0;
79  // atomno is unused
80  } else if ( name == "UPPER" ) {
81  type_ = POLYMER_UPPER;
82  atomno_ = 0; // atomno is unused
83  } else {
84  utility_exit_with_message( "ICoorAtomID: unable to parse atom_name: "+name );
85  }
86 }
87 
88 //////////////////////////////////////////////////////////////////////////////////////////////////
89 Vector const &
91  Residue const & rsd,
92  Conformation const & conformation
93 ) const
94 {
95  static Vector NullVector( 0, 0, 0 );
96 
97  //std::cout << "ICoorAtomID::xyz " << rsd.name() << ' ' << type_ << ' ' << atomno_ << std::endl;
98  if ( type_ == INTERNAL ) {
99  //std::cout << "ICoorAtomID::xyz " << rsd.name() << ' ' << atomno_ << ' ' << rsd.atom_is_backbone(atomno_) <<
100  // ' ' << rsd.atom_name( atomno_ ) << ' ' <<
101  // rsd.atom( atomno_ ).xyz()(1) << ' ' <<
102  // rsd.atom( atomno_ ).xyz()(2) << ' ' <<
103  // rsd.atom( atomno_ ).xyz()(3) << std::endl;
104  return rsd.atom( atomno_ ).xyz();
105  } else if ( type_ == POLYMER_LOWER ) {
106  int const seqpos( rsd.seqpos() - 1 );
107  int const atomno( conformation.residue_type( seqpos ).upper_connect_atom() );
108  return conformation.xyz( id::AtomID( atomno, seqpos ) );
109  // Residue const & rsd_lower( conformation.residue( rsd.seqpos() - 1 ) );
110  // return rsd_lower.atom( rsd_lower.upper_connect_atom() ).xyz();
111  } else if ( type_ == POLYMER_UPPER ) {
112  int const seqpos( rsd.seqpos() + 1 );
113  int const atomno( conformation.residue_type( seqpos ).lower_connect_atom() );
114  return conformation.xyz( id::AtomID( atomno, seqpos ) );
115  // Residue const & rsd_upper( conformation.residue( rsd.seqpos() + 1 ) );
116  // return rsd_upper.atom( rsd_upper.lower_connect_atom() ).xyz();
117  } else if ( type_ == CONNECT ) {
118  // in this case atomno_ is the connection identifer (index)
119  Size const connid( atomno_ );
120  int const partner_seqpos( rsd.residue_connection_partner( connid ) );
121  if ( partner_seqpos < 1 || partner_seqpos > int( conformation.size() ) ) {
122  tw << "ICoorAtomID xyz depends on invalid residue connection, returning BOGUS coords: this_rsd= " << rsd.name() <<
123  ' ' << rsd.seqpos() << " connid= " << connid << " partner_seqpos= " << partner_seqpos << '\n';
124  return NullVector;
125  }
126  Size const partner_connid( rsd.residue_connection_conn_id( connid ) );
127  Size const partner_atomno( conformation.residue_type( partner_seqpos ).residue_connect_atom_index( partner_connid));
128  return conformation.xyz( id::AtomID( partner_atomno, partner_seqpos ) );
129  } else {
130  utility_exit_with_message( "unrecognized stub atom id type!" );
131  }
132 
133  // to appease the compiler
134  return NullVector;
135 }
136 
137 
138 //////////////////////////////////////////////////////////////////////////////////////////////////
139 Vector // const &
141  ResidueType const & rsd_type
142 ) const
143 {
144  if ( type_ == INTERNAL ) {
145  return rsd_type.atom( atomno_ ).ideal_xyz();
146  } else if ( type_ == POLYMER_LOWER ) {
147  return rsd_type.lower_connect().icoor().build( rsd_type );
148  } else if ( type_ == POLYMER_UPPER ) {
149  return rsd_type.upper_connect().icoor().build( rsd_type );
150  } else if ( type_ == CONNECT ) {
151  return rsd_type.residue_connection( atomno_ ).icoor().build( rsd_type );
152  } else {
153  utility_exit_with_message( "unrecognized stub atom id type!" );
154  }
155 
156  // to appease the compiler
157  static Vector NullVector( 0, 0, 0 );
158  return NullVector;
159 }
160 
161 //////////////////////////////////////////////////////////////////////////////////////////////////
162 /// @brief WARNING: Slightly dangerous function intended for black magic use only.
163 /// Only to be used for situations where you *know* the ICoorAtomID can't be anything but
164 /// a real atom on the given residue, and where a conformation is absolutely not availible.
165 /// If you /can/ use ICoorAtomID::xyz( Residue const &, Conformation const &), you /should/.
166 Vector const &
168 {
169  runtime_assert( type_ == INTERNAL ); // I warned you!
170  return rsd.atom( atomno_ ).xyz();
171 }
172 
173 
174 //////////////////////////////////////////////////////////////////////////////////////////////////
176 ICoorAtomID::atom_id( Size const seqpos, Conformation const & conformation ) const
177 {
178  using id::AtomID;
179  switch ( type_ ) {
180  case INTERNAL:
181  return AtomID( atomno_, seqpos );
182  case POLYMER_LOWER:
183  return AtomID( conformation.residue_type( seqpos-1 ).upper_connect_atom(), seqpos - 1 );
184  case POLYMER_UPPER:
185  return AtomID( conformation.residue_type( seqpos+1 ).lower_connect_atom(), seqpos + 1 );
186  case CONNECT:
187  // in this case atomno_ is the connection identifer (index)
188  return conformation.inter_residue_connection_partner( seqpos, atomno_ );
189  default:
190  return id::BOGUS_ATOM_ID;
191  }
192  return id::BOGUS_ATOM_ID;
193 }
194 
195 //////////////////////////////////////////////////////////////////////////////////////////////////
196 Vector
197 AtomICoor::build(
198  conformation::Residue const & rsd,
199  conformation::Conformation const & conformation
200 ) const
201 {
202  assert( kinematics::Stub( stub_atom1_.xyz( rsd, conformation ),
203  stub_atom2_.xyz( rsd, conformation ),
204  stub_atom3_.xyz( rsd, conformation ) ).is_orthogonal( 0.001 ) );
205 
206  return kinematics::Stub( stub_atom1_.xyz( rsd, conformation ),
207  stub_atom2_.xyz( rsd, conformation ),
208  stub_atom3_.xyz( rsd, conformation ) ).spherical( phi_, theta_, d_ );
209 }
210 
211 Vector
212 AtomICoor::build(
213  ResidueType const & rsd_type
214 ) const
215 {
216  assert( kinematics::Stub( stub_atom1_.xyz( rsd_type ),
217  stub_atom2_.xyz( rsd_type ),
218  stub_atom3_.xyz( rsd_type ) ).is_orthogonal( 0.001 ) );
219 
220  return kinematics::Stub( stub_atom1_.xyz( rsd_type ),
221  stub_atom2_.xyz( rsd_type ),
222  stub_atom3_.xyz( rsd_type ) ).spherical( phi_, theta_, d_ );
223 }
224 
225 
226 /// @brief WARNING: Slightly dangerous function intended for black magic use only.
227 /// Only to be used for situations where you *know* the AtomICoor /and all it's stub atoms/ can't be
228 /// anything but real atoms on the given residue, and where a conformation is absolutely not availible.
229 /// If you /can/ use AtomICoor::build( Residue const &, Conformation const &), you /should/.
230 Vector
231 AtomICoor::build( conformation::Residue const & rsd ) const
232 {
233  assert( kinematics::Stub( stub_atom1_.xyz( rsd ),
234  stub_atom2_.xyz( rsd ),
235  stub_atom3_.xyz( rsd ) ).is_orthogonal( 0.001 ) );
236 
237  return kinematics::Stub( stub_atom1_.xyz( rsd ),
238  stub_atom2_.xyz( rsd ),
239  stub_atom3_.xyz( rsd ) ).spherical( phi_, theta_, d_ );
240 }
241 
242 
243 } // chemical
244 } // core