patrickfuller / imolecule

An embeddable webGL molecule viewer and file format converter.
http://patrickfuller.github.io/imolecule/
MIT License
86 stars 18 forks source link

Save snapshot #25

Closed CorySimon closed 8 years ago

CorySimon commented 8 years ago

This is an excellent and much needed tool, thank you!

Is there a way to save a snapshot of the molecule as e.g. a .png file, such as:

molecule = imolecule.draw("CC1(C(N2C(S1)C(C2=O)NC(=O)CC3=CC=CC=C3)C(=O)O)C")
molecule.savefig("mymolecule.png", format="png")

Further, a way to host this interactive viewer on a website? e.g. some .html code to copy and paste into Jekyll?

patrickfuller commented 8 years ago

The images are definitely doable. According to this stackoverflow post, it shouldn't be much work. I'll do this when I get some time.

Regarding the interactive viewer, you also can. You can use the source code from the examples as a starting point. If you have any questions on implementing, let me know.

CorySimon commented 8 years ago

It looks like mof.html in the examples folder is what I am looking for.

Can you please provide an example of how to use IMolecule or your script format_converter.py to convert e.g. a .cssr file to a JSON to use in mof.html?

patrickfuller commented 8 years ago

The intended use of the library was through the UI. If you pip installed this, typing imolecule will pop open a web UI. Drag and drop your .cssr file in, and then click save as -> json.

If you didn't go this route, there's also a format converter shim I use for testing. From this code, you can run with e.g.

python format_converter.py myfile.cssr cssr json > molecule.json

I should probably rewrite it with argparse and expose it through e.g. imolecule convert, but haven't gotten there.

patrickfuller commented 8 years ago

Saving molecule renders is now possible like so:

screen shot 2015-11-04 at 10 04 59 pm

Setting show_save=True displays a save icon that can be clicked to save the current camera angle on the molecule. Let me know if it works for you.

CorySimon commented 8 years ago

Awesome, thank you. Can you please make an option to change the dpi? The resolution is very low in the images that I save.

patrickfuller commented 8 years ago

The current approach saves a render of the current buffer, so it's tied to the size of the viewing window.

As a short-term solution, you can expand the size of your imolecule render before saving.

As a longer term solution, I like the idea of rendering in an off-screen buffer. Itll be some work to see if it's possible, but it'd make saving more consistent.

On Monday, November 9, 2015, Cory Simon notifications@github.com wrote:

Awesome, thank you. Can you please make an option to change the dpi? The resolution is very low in the images that I save.

— Reply to this email directly or view it on GitHub https://github.com/patrickfuller/imolecule/issues/25#issuecomment-155238389 .

patrickfuller commented 8 years ago

25e6899f8cb27479d88080bf878d47b75202a549 renders at high resolution. Current default is to scale width to 2560px and maintain aspect ratio. Proof:

screen shot 2015-11-11 at 5 28 20 pm

Let me know if this works for you.