Skip to content

Commit

Permalink
Updates to flev svg rendering
Browse files Browse the repository at this point in the history
Now many components return a svg_container_t.
There are still problems with scaling and offset, but this
incarnation does the residue circles now.
  • Loading branch information
pemsley committed Oct 2, 2024
1 parent 0b175c6 commit f55368e
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 93 deletions.
6 changes: 4 additions & 2 deletions api/molecules-container-ligand-fitting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ molecules_container_t::get_svg_for_residue_type(int imol, const std::string &com
} else {
svg_molecule_t svg;
svg.import_rdkit_mol(&mol, iconf);
s = svg.render_to_svg_string(dark_bg_flag);
double sf = 400.0;
s = svg.render_to_svg_string(sf, dark_bg_flag);
ligand_svg_store[key] = s;
}
} else {
Expand Down Expand Up @@ -577,7 +578,8 @@ molecules_container_t::get_svg_for_residue_type(int imol, const std::string &com
svg_molecule_t svg;
svg.import_rdkit_mol(&rdkit_mol, conformer_id);
dark_bg_flag = false;
s = svg.render_to_svg_string(dark_bg_flag);
double sf = 400.0;
s = svg.render_to_svg_string(sf, dark_bg_flag);
}
ligand_svg_store[key] = s;
}
Expand Down
16 changes: 13 additions & 3 deletions lidia-core/svg-container.hh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#ifndef COOT_LIDIA_CORE_SVG_CONTAINER_HH
#define COOT_LIDIA_CORE_SVG_CONTAINER_HH

#include <string>

class svg_container_t {

public:
svg_container_t() { init(); }
svg_container_t(const std::string &s) : svg(s) { init(); }
explicit svg_container_t(const std::string &s) : svg(s) { init(); }
std::string svg;
std::string svg_header_1;
std::string svg_header_2;
Expand Down Expand Up @@ -36,8 +38,8 @@ public:
void update_bounds(float min_xx, float min_yy, float max_xx, float max_yy) {
if (min_xx < min_x) min_x = min_xx;
if (min_yy < min_y) min_y = min_yy;
if (max_xx < max_x) max_x = max_xx;
if (max_yy < max_y) max_y = max_yy;
if (max_xx > max_x) max_x = max_xx;
if (max_yy > max_y) max_y = max_yy;
}

std::string make_viewbox_string() const {
Expand All @@ -54,6 +56,11 @@ public:
svg += s;
}

void add(const svg_container_t &svgc_in) {
svg += svgc_in.svg;
update_bounds(svgc_in.min_x, svgc_in.min_y, svgc_in.max_x, svgc_in.max_y);
}

std::string compose() const {

std::string s = svg_header_1;
Expand All @@ -66,3 +73,6 @@ public:

};



#endif // SVG_COOT_LIDIA_CORE_CONTAINER_HH
8 changes: 4 additions & 4 deletions lidia-core/svg-molecule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -849,17 +849,18 @@ svg_atom_t::make_text_item(const lig_build::atom_id_info_t &atom_id_info,
}

std::string
svg_molecule_t::render_to_svg_string(bool dark_background_flag) {
svg_molecule_t::render_to_svg_string(double sf, bool dark_background_flag) {

svg_container_t s = make_svg(dark_background_flag);
// 20241002-PE note sf was 400.0;
svg_container_t s = make_svg(sf, dark_background_flag);

return s.compose();

}


svg_container_t
svg_molecule_t::make_svg(bool dark_background_flag) {
svg_molecule_t::make_svg(double sf, bool dark_background_flag) {

auto make_bond_comment = [] (unsigned int bond_idx, const svg_bond_t &bond) {
std::string s("<!-- ");
Expand All @@ -885,7 +886,6 @@ svg_molecule_t::make_svg(bool dark_background_flag) {

svg_container_t svg;

double sf = 400.0; // scale factor
std::string s; // this can be removed, I think, now
s.reserve(2048);
std::string svg_header_1 = "<svg xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\" ";
Expand Down
4 changes: 2 additions & 2 deletions lidia-core/svg-molecule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class svg_molecule_t : public lig_build::molecule_t<svg_atom_t, svg_bond_t> {
public:
svg_molecule_t() { median_bond_length_ = 1.0; }
void import_rdkit_mol(RDKit::ROMol *mol, int iconf);
std::string render_to_svg_string(bool dark_background_flag);
svg_container_t make_svg(bool dark_background_flag);
std::string render_to_svg_string(double scale_factor, bool dark_background_flag);
svg_container_t make_svg(double scale_factor, bool dark_background_flag);
double median_bond_length_;
double get_scale() const;

Expand Down
Loading

0 comments on commit f55368e

Please sign in to comment.