Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easiest way to export svg/pdf/png? #54

Closed
bananabenana opened this issue Oct 8, 2024 · 4 comments
Closed

Easiest way to export svg/pdf/png? #54

bananabenana opened this issue Oct 8, 2024 · 4 comments

Comments

@bananabenana
Copy link

Hi,

Really love this tool and have made some awesome html-based figures. Do you have any guidance on the best way to export highres svg/pdf/png figures from this? Or natively from the r3dmol object?

# Load pdb file
pdb <- bio3d::read.pdb("I7AVL3.pdb")

# Generate r3dmol
ribbon_structure <- r3dmol() %>% 
  m_add_models(m_bio3d(pdb)) %>% 
  m_set_style(m_style_cartoon(color = "white")) %>% 
  m_set_background_color(gray(0.9)) %>% 
  m_add_outline()

# Save as html
htmltools::save_html(ribbon_structure, file = "ribbon_structure.html")

Thanks

@swsoyee
Copy link
Owner

swsoyee commented Oct 8, 2024

Hi, you could use function m_png to export a png figure
https://swsoyee.github.io/r3dmol/reference/m_png.html

@bananabenana
Copy link
Author

bananabenana commented Oct 8, 2024

Hi, thanks for your fast response. Apologies for not getting this yet.

So if I run the following:

ribbon_structure_png <- r3dmol() %>% 
  m_add_models(m_bio3d(pdb)) %>% 
  m_set_style(m_style_cartoon(color = "white")) %>% 
  m_set_background_color(gray(0.9)) %>% 
  m_add_outline()
  m_png()

How do I then save this object as a .png to disk and control resolution etc? I am using RStudio.

@swsoyee
Copy link
Owner

swsoyee commented Oct 10, 2024

Sorry, it didn't support resolution and save to disk options.

pngURI: (params) => {
viewer.render();
const width = params.width || viewer.getCanvas().getAttribute('width') / 2;
const height = params.height || viewer.getCanvas().getAttribute('height') / 2;
const captureDelay = promiseCalls.length === 0 ? 0 : params.captureDelay;
window.setTimeout(
() => { container.innerHTML = `<img src="${viewer.pngURI()}" width="${width}" height="${height}"/>`; },
captureDelay,
);
},

You could set the size of viewer (https://swsoyee.github.io/r3dmol/reference/init.html), right click and save the image directly.

@bananabenana
Copy link
Author

Okay great, thanks for your help! Also once again, amazing software which we are using in an upcoming paper!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants