IMP  2.0.1
The Integrative Modeling Platform
rmf_display.cpp
1 /**
2  * Copyright 2007-2013 IMP Inventors. All rights reserved.
3  */
4 #include <IMP/rmf/atom_io.h>
5 #include <RMF/FileHandle.h>
6 #include <IMP/rmf/particle_io.h>
8 #include <IMP/display/Writer.h>
10 #include <IMP/rmf/geometry_io.h>
12 #include <IMP/rmf/restraint_io.h>
13 #include <IMP/rmf/frames.h>
14 #include <IMP/base/flags.h>
15 
16 int main(int argc, char **argv) {
17  try {
18  bool recolor = false;
19  double score = std::numeric_limits<double>::max();
20  std::string file_type = "auto";
21  boost::int64_t frame = 0;
22  boost::int64_t frame_step = 0;
23  IMP::base::AddBoolFlag abf("recolor",
24  "Recolor the hierarchies using the display colors",
25  &recolor);
26  IMP::base::AddFloatFlag aff("score",
27  "The upper bound for the restraints scores to"\
28  " color the "\
29  "restraints by score.", &score);
30  IMP::base::AddStringFlag asf("type",
31  "pymol, chimera or auto (to use suffix)",
32  &file_type);
33  IMP::base::AddIntFlag aif("frame",
34  "The frame index or a negative number for every"
35  " f frames", &frame);
36  IMP::base::AddIntFlag aiff("frame_step",
37  "If non-zero output every n frames", &frame_step);
38  IMP::Strings io
39  = IMP::base::setup_from_argv(argc, argv,
40  "Export an RMF file to a viewer",
41  "input.rmf [output]",
42  -1);
43  std::string output;
44  if (io.size() > 1) {
45  output = io[1];
46  }
47  if (frame < 0) {
49  return 1;
50  }
51  bool exec=false;
52  if (output.empty()) {
53  exec=true;
54  if (file_type=="auto") {
56  return 1;
57  }
58  if (file_type=="pymol") {
59  output= IMP::create_temporary_file_name("display", ".pym");
60  } else if (file_type=="chimera") {
61  output= IMP::create_temporary_file_name("display", ".py");
62  } else {
64  return 1;
65  }
66  }
67  std::cout<< "writing to file " << output << std::endl;
68  RMF::FileConstHandle rh= RMF::open_rmf_file_read_only(io[0]);
69  IMP_NEW(IMP::Model, m, ());
70  IMP::atom::Hierarchies hs= IMP::rmf::create_hierarchies(rh, m);
71  IMP::ParticlesTemp ps= IMP::rmf::create_particles(rh, m);
74 
75  IMP::Pointer<IMP::display::Writer> w
77  if (frame_step == 0) frame_step = std::numeric_limits<int>::max();
78  int cur_frame=0;
79  for (unsigned int frame_iteration = frame;
80  frame_iteration < rh.get_number_of_frames();
81  frame_iteration += frame_step) {
82  w->set_frame(cur_frame++);
83  IMP::rmf::load_frame(rh, frame_iteration);
84  for (unsigned int i=0; i< hs.size(); ++i) {
86  if (recolor) {
87  g->set_color(IMP::display::get_display_color(i));
88  }
89  w->add_geometry(g);
90  }
91  for (unsigned int i=0; i< ps.size(); ++i) {
92  /*if (frame!= 0) {
93  IMP::rmf::load_configuration(rh, hs[i], frame);
94  }*/
96  IMP::core::XYZR d(ps[i]);
97  IMP_NEW(IMP::core::XYZRGeometry, g, (ps[i]));
98  if (recolor) {
99  g->set_color(IMP::display::get_display_color(i));
100  }
101  w->add_geometry(g);
102  }
103  }
104  w->add_geometry(gs);
105  for (unsigned int i=0; i< ps.size(); ++i) {
107  w->add_geometry(g);
108  }
109  }
110  if (exec) {
111  if (file_type=="pymol") {
112  std::cout << "launching pymol..." << std::endl;
113  return system((std::string("pymol")+" "+output).c_str());
114  } else {
115  std::cout << "launching chimera..." << std::endl;
116  return system((std::string("chimera")+" "+output).c_str());
117  }
118  } else {
119  return 0;
120  }
121  } catch (const IMP::Exception &e) {
122  std::cerr << "Error: " << e.what() << std::endl;
123  return 1;
124  } catch (const std::exception &e) {
125  std::cerr << "Error: " << e.what() << std::endl;
126  }
127 }