superstar54 / weas-widget

A widget to visualize and edit atomic structures in Jupyter Notebook
https://weas-widget.readthedocs.io/en/latest/index.html
MIT License
19 stars 3 forks source link

Export a figure by given a path #21

Closed AndresOrtegaGuerrero closed 6 months ago

AndresOrtegaGuerrero commented 6 months ago

It could be really useful to add a method that can export the figure given a path

as viewer.export_image("/User/Document/Orbital/cube.png")

superstar54 commented 6 months ago

@AndresOrtegaGuerrero I just found that direct file system access like this is not possible on standard web pages due to security constraints. In my notebook, when I run viewer.download_image('filename.png'), it will download the image to the Download folder directly without open a panel. So, you can write a loop and save your images with different names.

AndresOrtegaGuerrero commented 6 months ago

@superstar54 I tested in my notebook, in my folder it cant directly save the file. Also it only shows the panel if i display the viewer in the jupyter notebook.

superstar54 commented 6 months ago

Please try to change the browser settings to save downloads to their Downloads folder automatically. This could be different for different browsers.

AndresOrtegaGuerrero commented 6 months ago

I was working in visual studio

superstar54 commented 6 months ago

Hi @AndresOrtegaGuerrero , I tried to fix this issue since it is an important use case. Please use the latest version (0.0.11), or install the latest version from source, first clone the repository and then run:

cd weas-widget
npm install
npm run build
pip install -e .

Here is an example script:

from weas_widget import WeasWidget
from ase.io.cube import read_cube_data
volume, atoms = read_cube_data("./datas/h2o-homo.cube")
# use different camera position
for pos in [[0, 0, 100], [0, 100, 0]]:
  viewer = WeasWidget()
  viewer.from_ase(atoms)
  viewer.volumetricData = {"values": volume}
  viewer.isoSettings = [{"mode": 0}]
  display(viewer)
  name = "-".join([str(x) for x in pos])
  viewer.save_image(f"/home/xing/h2o-homo-{name}.png", 
                    camera_position = pos)
AndresOrtegaGuerrero commented 6 months ago

Hi @superstar54 I just tested it works!