Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PyMolMover.hh
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 protocols/moves/PyMolMover.hh
11 /// @brief Send infromation to PyMol. Contain classes PyMolMover, PyMolObserver and helper classes.
12 /// @author Sergey Lyskov
13 
14 #ifndef INCLUDED_protocols_moves_PyMolMover_hh
15 #define INCLUDED_protocols_moves_PyMolMover_hh
16 
18 
19 
20 // Unit Headers
21 #include <protocols/moves/Mover.hh>
22 #include <core/pose/Pose.fwd.hh>
25 
26 
27 #include <string>
28 
29 #include <utility/vector1.hh>
30 
31 
32 
33 // REQUIRED FOR WINDOWS
34 #ifndef __native_client__
35  #ifdef WIN32
36  #include <winsock.h>
37  #undef min
38  #undef max
39  #else
40  #include <sys/socket.h>
41  #include <netinet/in.h>
42  #include <arpa/inet.h>
43  #endif
44 #endif
45 
46 #ifdef __native_client__
47  typedef int sockaddr_in;
48 #endif
49 
50 //#ifdef WIN_PYROSETTA
51 // typedef int sockaddr_in;
52 //#endif
53 
54 
55 
56 
57 namespace protocols {
58 namespace moves {
59 
60 enum X11Colors {
63  XC_AntiqueWhite = 1, // 250 235 215
64  XC_BlanchedAlmond = 2, // 255 235 205
65  XC_BlueViolet = 3, // 138 43 226
66  XC_CadetBlue = 4, // 95 158 160
67  XC_CornflowerBlue = 5, // 100 149 237
68  XC_DarkBlue = 6, // 0 0 139
69  XC_DarkCyan = 7, // 0 139 139
70  XC_DarkGoldenrod = 8, // 184 134 11
71  XC_DarkGray = 9, // 169 169 169
72  XC_DarkGreen = 10, // 0 100 0
73  XC_DarkGrey = 11, // 169 169 169
74  XC_DarkKhaki = 12, // 189 183 107
75  XC_DarkMagenta = 13, // 139 0 139
76  XC_DarkOliveGreen = 14, // 85 107 47
77  XC_DarkOrange = 15, // 255 140 0
78  XC_DarkOrchid = 16, // 153 50 204
79  XC_DarkRed = 17, // 139 0 0
80  XC_DarkSalmon = 18, // 233 150 122
81  XC_DarkSeaGreen = 19, // 143 188 143
82  XC_DarkSlateBlue = 20, // 72 61 139
83  XC_DarkSlateGray = 21, // 47 79 79
84  XC_DarkSlateGrey = 22, // 47 79 79
85  XC_DarkTurquoise = 23, // 0 206 209
86  XC_DarkViolet = 24, // 148 0 211
87  XC_DebianRed = 25, // 215 7 81
88  XC_DeepPink = 26, // 255 20 147
89  XC_DeepSkyBlue = 27, // 0 191 255
90  XC_DimGray = 28, // 105 105 105
91  XC_DimGrey = 29, // 105 105 105
92  XC_DodgerBlue = 30, // 30 144 255
93  XC_FloralWhite = 31, // 255 250 240
94  XC_ForestGreen = 32, // 34 139 34
95  XC_GhostWhite = 33, // 248 248 255
96  XC_GreenYellow = 34, // 173 255 47
97  XC_HotPink = 35, // 255 105 180
98  XC_IndianRed = 36, // 205 92 92
99  XC_LavenderBlush = 37, // 255 240 245
100  XC_LawnGreen = 38, // 124 252 0
101  XC_LemonChiffon = 39, // 255 250 205
102  XC_LightBlue = 40, // 173 216 230
103  XC_LightCoral = 41, // 240 128 128
104  XC_LightCyan = 42, // 224 255 255
105  XC_LightGoldenrod = 43, // 238 221 130
106  XC_LightGoldenrodYellow = 44, // 250 250 210
107  XC_LightGray = 45, // 211 211 211
108  XC_LightGreen = 46, // 144 238 144
109  XC_LightGrey = 47, // 211 211 211
110  XC_LightPink = 48, // 255 182 193
111  XC_LightSalmon = 49, // 255 160 122
112  XC_LightSeaGreen = 50, // 32 178 170
113  XC_LightSkyBlue = 51, // 135 206 250
114  XC_LightSlateBlue = 52, // 132 112 255
115  XC_LightSlateGray = 53, // 119 136 153
116  XC_LightSlateGrey = 54, // 119 136 153
117  XC_LightSteelBlue = 55, // 176 196 222
118  XC_LightYellow = 56, // 255 255 224
119  XC_LimeGreen = 57, // 50 205 50
120  XC_MediumAquamarine = 58, // 102 205 170
121  XC_MediumBlue = 59, // 0 0 205
122  XC_MediumOrchid = 60, // 186 85 211
123  XC_MediumPurple = 61, // 147 112 219
124  XC_MediumSeaGreen = 62, // 60 179 113
125  XC_MediumSlateBlue = 63, // 123 104 238
126  XC_MediumSpringGreen = 64, // 0 250 154
127  XC_MediumTurquoise = 65, // 72 209 204
128  XC_MediumVioletRed = 66, // 199 21 133
129  XC_MidnightBlue = 67, // 25 25 112
130  XC_MintCream = 68, // 245 255 250
131  XC_MistyRose = 69, // 255 228 225
132  XC_NavajoWhite = 70, // 255 222 173
133  XC_NavyBlue = 71, // 0 0 128
134  XC_OldLace = 72, // 253 245 230
135  XC_OliveDrab = 73, // 107 142 35
136  XC_OrangeRed = 74, // 255 69 0
137  XC_PaleGoldenrod = 75, // 238 232 170
138  XC_PaleGreen = 76, // 152 251 152
139  XC_PaleTurquoise = 77, // 175 238 238
140  XC_PaleVioletRed = 78, // 219 112 147
141  XC_PapayaWhip = 79, // 255 239 213
142  XC_PeachPuff = 80, // 255 218 185
143  XC_PowderBlue = 81, // 176 224 230
144  XC_RosyBrown = 82, // 188 143 143
145  XC_RoyalBlue = 83, // 65 105 225
146  XC_SaddleBrown = 84, // 139 69 19
147  XC_SandyBrown = 85, // 244 164 96
148  XC_SeaGreen = 86, // 46 139 87
149  XC_SkyBlue = 87, // 135 206 235
150  XC_SlateBlue = 88, // 106 90 205
151  XC_SlateGray = 89, // 112 128 144
152  XC_SlateGrey = 90, // 112 128 144
153  XC_SpringGreen = 91, // 0 255 127
154  XC_SteelBlue = 92, // 70 130 180
155  XC_VioletRed = 93, // 208 32 144
156  XC_WhiteSmoke = 94, // 245 245 245
157  XC_YellowGreen = 95, // 154 205 50
158  XC_aquamarine = 96, // 127 255 212
159  XC_azure = 97, // 240 255 255
160  XC_beige = 98, // 245 245 220
161  XC_bisque = 99, // 255 228 196
162  XC_AliceBlue = 100, // 240 248 255
163  XC_blue = 101, // 0 0 255
164  XC_blue1 = 102, // 0 0 255
165  XC_blue2 = 103, // 0 0 238
166  XC_blue3 = 104, // 0 0 205
167  XC_blue4 = 105, // 0 0 139
168  XC_brown = 106, // 165 42 42
169  XC_burlywood = 107, // 222 184 135
170  XC_chartreuse = 108, // 127 255 0
171  XC_chocolate = 109, // 210 105 30
172  XC_coral = 110, // 255 127 80
173  XC_cornsilk = 111, // 255 248 220
174  XC_cyan = 112, // 0 255 255
175  XC_firebrick = 113, // 178 34 34
176  XC_gainsboro = 114, // 220 220 220
177  XC_gold = 115, // 255 215 0
178  XC_goldenrod = 116, // 218 165 32
179  XC_gray = 117, // 190 190 190
180  XC_gray0 = 118, // 0 0 0
181  XC_gray10 = 119, // 26 26 26
182  XC_gray100 = 120, // 255 255 255
183  XC_gray20 = 121, // 51 51 51
184  XC_gray30 = 122, // 77 77 77
185  XC_gray40 = 123, // 102 102 102
186  XC_gray50 = 124, // 127 127 127
187  XC_gray60 = 125, // 153 153 153
188  XC_gray70 = 126, // 179 179 179
189  XC_gray80 = 127, // 204 204 204
190  XC_gray90 = 128, // 229 229 229
191  XC_green = 129, // 0 255 0
192  XC_green1 = 130, // 0 255 0
193  XC_green2 = 131, // 0 238 0
194  XC_green3 = 132, // 0 205 0
195  XC_green4 = 133, // 0 139 0
196  XC_honeydew = 134, // 240 255 240
197  XC_ivory = 135, // 255 255 240
198  XC_khaki = 136, // 240 230 140
199  XC_lavender = 137, // 230 230 250
200  XC_linen = 138, // 250 240 230
201  XC_magenta = 139, // 255 0 255
202  XC_maroon = 140, // 176 48 96
203  XC_moccasin = 141, // 255 228 181
204  XC_navy = 142, // 0 0 128
205  XC_orange = 143, // 255 165 0
206  XC_orchid = 144, // 218 112 214
207  XC_peru = 145, // 205 133 63
208  XC_pink = 146, // 255 192 203
209  XC_plum = 147, // 221 160 221
210  XC_purple = 148, // 160 32 240
211  XC_red = 149, // 255 0 0
212  XC_red1 = 150, // 255 0 0
213  XC_red2 = 151, // 238 0 0
214  XC_red3 = 152, // 205 0 0
215  XC_red4 = 153, // 139 0 0
216  XC_salmon = 154, // 250 128 114
217  XC_seashell = 155, // 255 245 238
218  XC_sienna = 156, // 160 82 45
219  XC_snow = 157, // 255 250 250
220  XC_snow1 = 158, // 255 250 250
221  XC_snow2 = 159, // 238 233 233
222  XC_snow3 = 160, // 205 201 201
223  XC_snow4 = 161, // 139 137 137
224  XC_tan = 162, // 210 180 140
225  XC_thistle = 163, // 216 191 216
226  XC_tomato = 164, // 255 99 71
227  XC_turquoise = 165, // 64 224 208
228  XC_violet = 166, // 238 130 238
229  XC_wheat = 167, // 245 222 179
230  XC_white = 168, // 255 255 255
231  XC_yellow = 169, // 255 255 0
233 };
234 
235 
236 /// @brief PyMolMover helper class. Handle low level UDP transactions stuff.
237 /// This is a port of original Python version of UDP socket client written writen for PyRosetta
239 {
240 public:
241  UDPSocketClient();
243 
244  void sendMessage(std::string msg);
245 
246 private:
247 
248  void sendRAWMessage(int globalPacketID, int packetI, int packetCount, char * msg_begin, char *msg_end);
249 
250  /// @brief last know mximum size of suspenseful sended UDP packet.
251  /// ~64k for local connection and ~10k for inet connection
252  unsigned int max_packet_size_; // last know mximum size of suspenseful sended UDP packet.
253 
254  /// @brief unique id of this socket client
255  union UUID {
256  char bytes_[16];
257  short unsigned int shorts_[8];
258  };
259 
260  /// @brief Almost real UUID, but for simplicity we just use random sequence
262 
263  /// @brief counter for number of packet already sent
265 
266  /// @brief socket address and handle
267  sockaddr_in socket_addr_;
269 };
270 
271 
273 {
274 public:
275  PyMolMover() : update_energy_(false), energy_type_(core::scoring::total_score),
277 
278  virtual ~PyMolMover();
279  virtual std::string get_name() const;
280  virtual void apply( Pose & );
281 
282 
284 
285  /// @brief Actually our mover does not change the Pose object, so we have additional const version...
286  virtual void apply( Pose const & );
287 
288  /// @brief Send message for PyMol to print
289  void print(std::string const & message);
290 
291  /// @brief Send specified energy to PyMOL.
293 
294  /// @brief Send specified energy to PyMOL.
295  void send_energy(Pose const &, std::string const & stype);
296 
297  /// @brief Send RAW energy array for coloring by PyMOL
298  void send_RAW_Energies(Pose const &, std::string energyType, utility::vector1<int> const & energies);
299 
300  /// @brief Tell PyMOL to color protein with supplied custom colors
301  virtual void send_colors(Pose const &, std::map<int, int> const & colors, X11Colors default_color=protocols::moves::XC_blue );
302 
303 
304  bool update_energy() { return update_energy_; }
305  void update_energy(bool f) { update_energy_ = f; }
306 
307 
310 
311  /// @brief Set the keep history flag. If set to True - PyMol will keep track of all frames that
312  /// was sent.
313  void keep_history(bool kh) { keep_history_ = kh; }
314 
315 
316  /// @brief Return current keep_history flag.
317  bool keep_history(void) { return keep_history_; }
318 
319 
320  /// @brief Set current minimum update interval 't' in seconds. Mover will not send anyinformation to
321  /// PyMOL before atleast 't' secons has passes since last packet was sent.
322  /// default value is 0, - no packets are skipped.
324 
325 
326  /// @brief Return current update interval.
328 
329  friend std::ostream &operator<< (std::ostream &os, PyMolMover const &mover)
330  {
331  moves::operator<<(os, mover);
332  os << "Keep history: " << ( ( mover.keep_history_ ) ? ("True") : ("False") ) << std::endl;
333  os << "Update energy: " << ( ( mover.update_energy_ ) ? ("True") : ("False") ) << std::endl;
334  os << "Last packet sent time: " << mover.last_packet_sent_time_ << std::endl;
335  os << "Update interval: " << mover.update_interval_ << std::endl;
336 
337  return os;
338  }
339 
340 private:
341  //void send_message(std::string const & message_type, bool keep_history, std::string const & name, std::string const &message);
342 
343  std::string get_PyMol_model_name(Pose const & pose) const;
344 
345  bool is_it_time();
346 
347  /// @brief Actual link object
349 
351 
353 
354  /// @brief Should PyMol keep history of all models that was sent? - Default is false.
356 
357  /// @brief Update interval in seconds.
359 
360  /// @brief Time stamp from where last packet was sent.
362 
363  /// @brief Name of model in pymol.
365 };
366 
367 
368 
370 {
371 public:
373  virtual ~PyMolObserver() {};
374 
376  pymol_.apply( *ev.pose );
377  };
378 
379  PyMolMover & pymol() { return pymol_; };
380 
381  /// attach/detach observer from the pose object
382  void attach(core::pose::Pose &p);
383  void detach(core::pose::Pose &p);
384 
385 private:
387 
388 // friend PyMolObserverOP AddPyMolObserver(core::pose::Pose &p, bool keep_history);
389 };
390 
391 
392 /// @brief Helper function that create PyMolObserver Object and add it to the give Pose.
393 /// This is the most likely the only function that you need to call...
394 PyMolObserverOP AddPyMolObserver(core::pose::Pose &p, bool keep_history=false, core::Real update_interval=0);
395 
396 
397 
398 } // moves
399 } // protocols
400 
401 
402 #endif // INCLUDED_protocols_moves_PyMolMover_HH