Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueKinWriter.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 /// @brief Class to write kinemage-formatted output for Residue and Conformation
11 /// @file core/conformation/ResidueKinWriter.cc
12 /// @author Andrew Leaver-Fay
13 
14 
15 // Unit headers
17 
18 // Package headers
23 
24 // C++ headers
25 #include <iostream>
26 
27 #include <utility/vector1.hh>
28 
29 
30 namespace core {
31 namespace conformation {
32 
34  std::ostream & ostr,
35  Size const kin_number,
36  std::string const & title,
37  Vector const & ctr
38 )
39 {
40  ostr << "@kinemage {" << kin_number << "}\n";
41  ostr << "@title { " << title << " }\n";
42  ostr << "@1center " << ctr.x() << " " << ctr.y() << " " << ctr.z() << "\n";
43  ostr << "@1span 25\n";
44 }
45 
46 /// TWO FUNCTIONS STOLEN FROM IAN: and slightly modified.
48  std::ostream & out,
49  int residue_num,
50  int atom_num,
51  core::Vector const & atom_xyz,
52  core::chemical::ResidueType const & res,
53  std::string extras = "" //< P for points, color, width/radius, etc.
54 )
55 {
56  // atom_num is often 0 in fold tree, means no specific atom.
57  // might as well use the first() one:
58  if (atom_num == 0) atom_num = 1;
59  core::chemical::AtomType const & atom_type = res.atom_type(atom_num);
60  // This info appears when you click on the point
61  out << "{" << res.name3() << " " << residue_num
62  << " " << res.atom_name(atom_num) << " (" << atom_type.name() << ")"
63  << "}";
64  // Color, width, etc. followed by coordinates
65  //out << "col" << residue_num << " ";
66  out << extras;
67  out << " " << atom_xyz.x() << " " << atom_xyz.y() << " " << atom_xyz.z() << "\n";
68 }
69 
71  std::ostream & out,
72  int residue_num,
73  int atom_num,
74  core::conformation::Residue const & res,
75  std::string extras = "" //< P for points, color, width/radius, etc.
76 )
77 {
78  print_node( out, residue_num, atom_num, res.xyz( atom_num ), res.type(), extras );
79 }
80 
81 
83  std::ostream & out,
84  int residue_num,
85  std::string atom_name,
86  core::conformation::Residue const & res,
87  std::string extras = "" //< P for points, color, width/radius, etc.
88 )
89 {
90  // atom_num is often 0 in fold tree, means no specific atom.
91  // might as well use the first one:
92 
93  int atom_num;
94  if (atom_name == "") {
95  atom_num = 1;
96  } else {
97  atom_num = res.atom_index( atom_name );
98  }
99  print_node( out, residue_num, atom_num, res, extras );
100 }
101 
103  master_( "" ),
104  dominant_( true ),
105  animate_( true ),
106  group_( true ),
107  write_apolar_hydrogens_( false ),
108  write_polar_hydrogens_( false ),
109  write_backbone_hydrogens_( true ),
110  write_virtual_atoms_( false )
111 {}
112 
114 
116  std::ostream & ostr,
117  core::conformation::Residue const & rsd,
118  core::Size atom_to_center_on,
119  core::Size which_kin
120 ) const
121 {
122  Vector center_point( 0 );
123  if ( atom_to_center_on == 0 ) {
124  center_point = rsd.xyz( rsd.nbr_atom() );
125  } else {
126  center_point = rsd.xyz( atom_to_center_on );
127  }
128  write_kinemage_header( ostr, which_kin, "Residue Kinemage", center_point );
129 }
130 
131 
132 /// @details If you're drawing multiple instances of a single rotamer, use the
133 /// "instance" flag to point to the coordinates already written out
134 /// in this file. This creates a smaller output file.
135 void
137  std::ostream & ostr,
138  core::conformation::Residue const & rsd,
139  bool is_instance /* = false */
140 ) const
141 {
142 
143  // intra-residue connections
144  // do residues in different (~random) colors to help distinguish them
145  //int const num_colors = 6;
146  //std::string colors[num_colors] = {"pinktint", "peachtint", "yellowtint", "greentint", "bluetint", "lilactint"};
147  //std::string color = colors[ rsd.seqpos() % num_colors ];
148  std::string color = "bluetint";
149 
150  std::string tag = "";
151 
152  ostr << "@" << ( group_ ? "group" : "subgroup" ) << " { Res " << rsd.seqpos() << " }";
153  if ( animate_ ) ostr << " animate";
154  if ( dominant_ ) ostr << " dominant";
155  ostr << "\n";
156  ostr << "@vectorlist {";
157  if ( is_instance ) {
158  ostr << rsd.name() << " " << rsd.seqpos() << "i";
159  } else {
160  ostr << rsd.name() << " " << rsd.seqpos();
161  }
162  ostr << "} color= " << color;
163  if ( master_ != "" ) ostr << " master= {" << master_ << "}";
164  if ( is_instance ) {
165  ostr << " instance= {" << rsd.name() << " " << rsd.seqpos() << "}";
166  }
167  ostr << "\n";
168 
169  if ( ! is_instance ) {
170  for( core::Size atom_i = 1; atom_i <= rsd.natoms(); ++atom_i) {
171  core::conformation::Residue::AtomIndices const & nbrs = rsd.nbrs(atom_i);
172  for(core::conformation::Residue::AtomIndices::const_iterator j = nbrs.begin(), end_j = nbrs.end(); j != end_j; ++j) {
173  core::Size atom_j = *j;
174  if(atom_j <= atom_i) continue; // so we draw each bond just once, not twice
175  bool const is_H = rsd.atom_is_hydrogen(atom_j) || rsd.atom_is_hydrogen(atom_i);
176 
177  if ( is_H && ! write_apolar_hydrogens_ && ! write_polar_hydrogens_ ) continue;
178 
179  if ( ! write_virtual_atoms_ && ( rsd.atom_type( atom_i ).element() == "X" || rsd.atom_type( atom_j ).element() == "X" )) continue;
180 
181  /// backbone hydrogens?
182  if ( ! write_backbone_hydrogens_ && rsd.atom_is_backbone( atom_i ) && rsd.atom_is_hydrogen( atom_i ) ) continue;
183  if ( ! write_backbone_hydrogens_ && rsd.atom_is_backbone( atom_j ) && rsd.atom_is_hydrogen( atom_j ) ) continue;
184  std::string const ptmaster = ( is_H ? " 'h'" : "" );
185  print_node( ostr, rsd.seqpos(), atom_i, rsd, tag+"P"+ptmaster);
186  print_node( ostr, rsd.seqpos(), atom_j, rsd, tag+ptmaster);
187  }
188  }
189  }
190 }
191 
192 
193 void ResidueKinWriter::dominant( bool setting ) { dominant_ = setting; }
194 void ResidueKinWriter::animate( bool setting ) { animate_ = setting; }
195 void ResidueKinWriter::group( bool setting ) { group_ = setting; }
196 void ResidueKinWriter::master( std::string const & setting ) { master_ = setting; }
198 void ResidueKinWriter::write_hydrogens( bool setting ) {
199  write_apolar_hydrogens( setting );
200  write_polar_hydrogens( setting );
201  write_backbone_hydrogens( setting );
202 }
203 
207 
209 
210 /// @brief Write out the coordinates for an entire conformation; this includes
211 /// inter-residue bonds that would be missed by the ResidueKinWriter.
212 void
214  std::ostream & ostr,
216  bool is_instance
217 ) const
218 {
219  using namespace core::conformation;
220 
221  ResidueKinWriter rsd_writer;
222  rsd_writer.animate( false );
223  rsd_writer.group( false );
224  ostr << "@group { conformation } dominant on\n";
225 
226  for ( Size ii = 1; ii <= conf.size(); ++ii ) {
227  Residue const & ii_rsd( conf.residue( ii ) );
228  rsd_writer.write_rsd_coords( ostr, ii_rsd, is_instance );
229  /// insert code here to write inter-residue bonds.
230 
231  for ( Size jj = 1; jj <= ii_rsd.n_residue_connections(); ++jj ) {
232  Size const jj_conn_residue = ii_rsd.connected_residue_at_resconn( jj );
233  if ( jj_conn_residue < ii ) continue; // we've already output this connection
234  Residue const & jj_rsd( conf.residue( jj_conn_residue ) );
235  Size const ii_conn_atom = ii_rsd.residue_connect_atom_index( jj );
236  Size const jj_conn_id = ii_rsd.connect_map( jj ).connid();
237  Size const jj_conn_atom = jj_rsd.residue_connect_atom_index( jj_conn_id );
238 
239  print_node( ostr, ii_rsd.seqpos(), ii_conn_atom, ii_rsd, "P");
240  print_node( ostr, jj_rsd.seqpos(), jj_conn_atom, jj_rsd, "");
241 
242  }
243  }
244 }
245 
247 void ConformationKinWriter::master( std::string const & setting ) { master_ = setting; }
248 
249 
250 
251 } // conformation
252 } // core
253