/** * \file JmolWriter.cpp \brief outputs javascript for jmol display * * Copyright 2007-2013 IMP Inventors. All rights reserved. * */ #include "JmolWriter.h" #include "ColorCoder.h" #include "Gnuplot.h" #include #include #include #include std::string JmolWriter::display_selection_ = "frame 0#;restrict selection;\ select selection and (protein, nucleic); ribbons only;\ select selection and not (protein, nucleic); spacefill only;\ if (!{*}.ribbons) { select selection and (protein, nucleic);spacefill only; };"; unsigned int JmolWriter::MAX_DISPLAY_NUM_ = 30; void JmolWriter::prepare_jmol_script( const std::vector& fps, const std::vector& particles_vec, const std::string filename) { std::string html_filename = filename + ".html"; std::string pdb_filename = filename + ".pdb"; unsigned int model_num = std::min((unsigned int)fps.size(), MAX_DISPLAY_NUM_); std::string pdb_colors = prepare_coloring_string(model_num); prepare_PDB_file(fps, particles_vec, pdb_filename); std::ofstream outstream(html_filename.c_str()); outstream << prepare_gnuplot_init_selection_string(model_num, true); outstream << jmol_script("/foxs/jmol"); std::string init = "select all;" + display_selection_; std::string selection_init = "define selection model =1"; init += selection_init + "; " + pdb_colors + display_selection_ + "; background white; hide hydrogens;"; // load applet with molecules outstream <<"
\n" << "
\n \n"; std::string show_all_checkbox_str = show_all_checkbox(model_num, true); outstream.precision(2); outstream.setf(std::ios::fixed,std::ios::floatfield); // output table bool showMolecule = true; char hex_color[10]="ZZZZZZ"; outstream << ""; outstream << " " << "" << "" << "" << "\n"; for(unsigned int i=0; i(fps[i].get_profile_file_name().c_str()))); std::string fit_file_name = pdb_name + "_" + profile_name + ".dat"; float rg = IMP::saxs::radius_of_gyration(particles_vec[fps[i].get_mol_index()]); outstream << "\n\n"; } outstream << "
PDB file " << show_all_checkbox_str << "
χ
c1
c2
Rg
# atoms
fit file
"; if(i"; outstream << pdb_name; if(i"; outstream<< "
" << std::endl; if(i>0) showMolecule = false; if(i
" << fps[i].get_chi() << "
" << fps[i].get_c1() << "
" << fps[i].get_c2() << "
" << rg << "
" << particles_vec[fps[i].get_mol_index()].size() << "
" << "" << fit_file_name << "
\n"; outstream << group_checkbox(model_num); outstream.close(); } void JmolWriter::prepare_jmol_script(const std::vector& pdbs, const std::vector& particles_vec, const std::string filename) { std::string html_filename = filename + ".html"; std::string pdb_filename = filename + ".pdb"; unsigned int model_num = std::min((unsigned int)pdbs.size(),MAX_DISPLAY_NUM_); std::string pdb_colors = prepare_coloring_string(model_num); prepare_PDB_file(particles_vec, pdb_filename); std::ofstream outstream(html_filename.c_str()); outstream << prepare_gnuplot_init_selection_string(model_num, false); outstream << jmol_script("/foxs/jmol"); std::string init = "select all;" + display_selection_; std::string selection_init = "define selection model =1"; init += selection_init + "; " + pdb_colors + display_selection_ + "; background white; hide hydrogens;"; // load applet with molecules outstream <<"
\n" << "
\n \n"; std::string show_all_checkbox_str = show_all_checkbox(model_num, false); outstream.precision(2); outstream.setf(std::ios::fixed,std::ios::floatfield); // output table bool showMolecule = true; char hex_color[10]="ZZZZZZ"; outstream << ""; outstream << "" << "" << "" << "\n"; for(unsigned int i=0; i\n\n"; } outstream << "
PDB file " << show_all_checkbox_str << "
Rg
# atoms
Profile file
"; if(i"; outstream << pdb_name; if(i"; outstream << "
" << std::endl; if(i>0) showMolecule = false; if(i
" << rg << "
" << particles_vec[i].size() << "
" << profile_name << "
\n"; outstream << group_checkbox(model_num); outstream.close(); } void JmolWriter::prepare_PDB_file( const std::vector& fps, const std::vector& particles_vec, const std::string filename) { std::ofstream out_file(filename.c_str()); // center coordinates and join into a single PDB for(unsigned int i=0; i coordinates; IMP::saxs::get_coordinates(particles_vec[mol_index], coordinates); IMP::algebra::Vector3D m = std::accumulate(coordinates.begin(), coordinates.end(), IMP::algebra::Vector3D(0.0, 0.0, 0.0)); m /= particles_vec[mol_index].size(); // output file out_file << "MODEL " << i+1 << std::endl; for(unsigned int j=0; j< particles_vec[mol_index].size(); j++) { // centering IMP::algebra::Vector3D v = IMP::core::XYZ(particles_vec[mol_index][j]).get_coordinates()-m; IMP::atom::Atom ad(particles_vec[mol_index][j]); IMP::atom::Residue rd = get_residue(ad); IMP::atom::Chain c = get_chain(rd); char chain = c.get_id(); out_file << IMP::atom::get_pdb_string(v, ad.get_input_index(), ad.get_atom_type(), rd.get_residue_type(), chain, rd.get_index(), rd.get_insertion_code(), ad.get_occupancy(), ad.get_temperature_factor(), ad.get_element()); } out_file << "ENDMDL" << std::endl; } out_file.close(); } void JmolWriter::prepare_PDB_file( const std::vector& particles_vec, const std::string filename) { std::ofstream out_file(filename.c_str()); // center coordinates and join into a single PDB for(unsigned int i=0; i coordinates; IMP::saxs::get_coordinates(particles_vec[i], coordinates); IMP::algebra::Vector3D m = std::accumulate(coordinates.begin(), coordinates.end(), IMP::algebra::Vector3D(0.0, 0.0, 0.0)); m /= particles_vec[i].size(); // output file out_file << "MODEL " << i+1 << std::endl; for(unsigned int j=0; j< particles_vec[i].size(); j++) { // centering IMP::algebra::Vector3D v = IMP::core::XYZ(particles_vec[i][j]).get_coordinates()-m; IMP::atom::Atom ad(particles_vec[i][j]); IMP::atom::Residue rd = get_residue(ad); IMP::atom::Chain c = get_chain(rd); char chain = c.get_id(); out_file << IMP::atom::get_pdb_string(v, ad.get_input_index(), ad.get_atom_type(), rd.get_residue_type(), chain, rd.get_index(), rd.get_insertion_code(), ad.get_occupancy(), ad.get_temperature_factor(), ad.get_element()); } out_file << "ENDMDL" << std::endl; } out_file.close(); } std::string JmolWriter::prepare_gnuplot_init_selection_string( unsigned int model_num, bool exp) { std::string gnuplot_string = ""; for(unsigned int i=0; i(i+3)) + "\");"; } else { gnuplot_string += ""; } } return gnuplot_string; } std::string JmolWriter::prepare_coloring_string(unsigned int model_num) { char dec_color[20]; std::string coloring_string = ""; for(unsigned int i=0; i(i+1)) + "; color " + std::string(dec_color) + ";"; } return coloring_string; } std::string JmolWriter::jmol_script(std::string jmol_path) { std::string js_string = ""; js_string += "\n"; js_string += "\n"; return js_string; } std::string JmolWriter::model_checkbox(unsigned int model_num, bool is_checked, bool exp) { std::string model_num_string = std::string(boost::lexical_cast(model_num+1)); std::string model_num_string2 = model_num_string; if(exp) model_num_string2 = std::string(boost::lexical_cast(model_num+2)); std::string checkbox_string = "\n"; return checkbox_string; } std::string JmolWriter::show_all_checkbox(unsigned int model_num, bool exp) { if(model_num == 1) return "show/hide"; std::string show_string = "select all;define selection all;frame 0#;" + display_selection_; std::string hide_string = "define selection not all;frame 0#;restrict not all;"; for(unsigned int i=0; i(plotnum)); show_string += "javascript gnuplot.show_plot(\"jsoutput_1_plot_" + plotnum_str + "\");"; hide_string += "javascript gnuplot.hide_plot(\"jsoutput_1_plot_" + plotnum_str + "\");"; } std::string ret = " show all/hide all"; return ret; } std::string JmolWriter::group_checkbox(unsigned int model_num) { if(model_num == 1) return ""; std::string ret = " \n"; return ret; }