Molara-Lab / Molara

Molara is a Python package for the visualization of chemical structures such as molecules or crystals. It provides a graphical user interface for importing structures from output files of popular computational chemistry software as well as for creating custom structures.
GNU General Public License v3.0
11 stars 0 forks source link

Implement export of snapshots with custom resolution #373

Closed adrianusler closed 2 months ago

adrianusler commented 2 months ago

Closes #326

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent updates across Molara's software suite bring enhancements to the GUI components, focusing on exporting images, connecting dialogs, and adopting configurations between structure widgets. These changes aim to improve user interaction and streamline functionality within the application.

Changes

File Path Change Summary
molara/Gui/export_image_dialog.py Updated ExportImageDialog with show_dialog and accept methods for image exporting dialog.
molara/Gui/main_window.py Added ExportImageDialog import, connected export action, and modified supercell dialog usage.
molara/Gui/structure_widget.py Enhanced adopt_config method in StructureWidget for adopting configurations from another widget.
tests/molara/gui/test_export_image_dialog.py Added tests for ExportImageDialog class covering dialog functionality and image export.

🐇🖌️ In the GUI's realm where dialogs dance, Exporting images with a single glance. Structures adopt configurations, a seamless view, Tests ensure all functions, shiny and new. Molara's world evolves, with changes in queue, Thanks to your code, the enhancements grew! 🌟🐾


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 90.07092% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 74.77%. Comparing base (79e3896) to head (81346fa).

Files Patch % Lines
src/molara/Gui/supercell_dialog.py 47.61% 11 Missing :warning:
src/molara/Gui/export_image_dialog.py 87.75% 6 Missing :warning:
src/molara/Structure/crystal.py 73.33% 4 Missing :warning:
src/molara/Gui/main_window.py 62.50% 3 Missing :warning:
src/molara/Gui/structure_widget.py 72.72% 3 Missing :warning:
src/molara/Rendering/camera.py 95.83% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #373 +/- ## ========================================== + Coverage 71.81% 74.77% +2.95% ========================================== Files 40 44 +4 Lines 3474 3731 +257 ========================================== + Hits 2495 2790 +295 + Misses 979 941 -38 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ab5424 commented 2 months ago

I tried to export an image of ferrocene. It only produced a completely white png, and in addition the upper left quadrant of the molara window turned white as well. I can still rotate the molecule and zoom around though.

Bildschirmfoto 2024-05-03 um 18 13 59

This was the corresponding output:

Traceback (most recent call last):
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/export_image_dialog.py", line 39, in accept
    virtual_rendering_window.export_image(self.ui.filenameInput.text(), custom_geometry=(width, height))
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/virtual_rendering_window.py", line 37, in export_image
    virtual_structure_widget.adopt_config(main_structure_widget, custom_geometry)
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/structure_widget.py", line 637, in adopt_config
    self.set_structure(other_widget.structure, reset_view=False)
AttributeError: 'StructureWidget' object has no attribute 'structure'
2024-05-03 18:13:11.230 Python[84535:1030879] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x16ffb0880 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
2024-05-03 18:13:11.327 Python[84535:1030597] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x128c944d0 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
Traceback (most recent call last):
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/export_image_dialog.py", line 39, in accept
    virtual_rendering_window.export_image(self.ui.filenameInput.text(), custom_geometry=(width, height))
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/virtual_rendering_window.py", line 37, in export_image
    virtual_structure_widget.adopt_config(main_structure_widget, custom_geometry)
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/structure_widget.py", line 637, in adopt_config
    self.set_structure(other_widget.structure, reset_view=False)
AttributeError: 'StructureWidget' object has no attribute 'structure'
2024-05-03 18:13:36.747 Python[84535:1030880] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x16e6db1f0 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
2024-05-03 18:13:43.934 Python[84535:1030881] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x16ff52450 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
Traceback (most recent call last):
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/export_image_dialog.py", line 39, in accept
    virtual_rendering_window.export_image(self.ui.filenameInput.text(), custom_geometry=(width, height))
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/virtual_rendering_window.py", line 37, in export_image
    virtual_structure_widget.adopt_config(main_structure_widget, custom_geometry)
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/structure_widget.py", line 637, in adopt_config
    self.set_structure(other_widget.structure, reset_view=False)
AttributeError: 'StructureWidget' object has no attribute 'structure'
Traceback (most recent call last):
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/export_image_dialog.py", line 39, in accept
    virtual_rendering_window.export_image(self.ui.filenameInput.text(), custom_geometry=(width, height))
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/virtual_rendering_window.py", line 37, in export_image
    virtual_structure_widget.adopt_config(main_structure_widget, custom_geometry)
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/structure_widget.py", line 637, in adopt_config
    self.set_structure(other_widget.structure, reset_view=False)
AttributeError: 'StructureWidget' object has no attribute 'structure'
2024-05-03 18:13:49.647 Python[84535:1031499] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x16c67e320 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
2024-05-03 18:14:02.306 Python[84535:1031501] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x139c07630 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
2024-05-03 18:16:11.153 Python[84535:1033234] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x308145190 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
2024-05-03 18:16:12.254 Python[84535:1033272] GLDRendererMetal command buffer completion error: Error Domain=MTLCommandBufferErrorDomain Code=8 "Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)" UserInfo={NSLocalizedDescription=Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory), NSUnderlyingError=0x11fde83a0 {Error Domain=IOGPUCommandQueueErrorDomain Code=8 "(null)"}}
ab5424 commented 2 months ago

I just reduced the image resolution, but I still get the empty png, albeit with less stderr:


Traceback (most recent call last):
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/export_image_dialog.py", line 39, in accept
    virtual_rendering_window.export_image(self.ui.filenameInput.text(), custom_geometry=(width, height))
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/virtual_rendering_window.py", line 37, in export_image
    virtual_structure_widget.adopt_config(main_structure_widget, custom_geometry)
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/structure_widget.py", line 637, in adopt_config
    self.set_structure(other_widget.structure, reset_view=False)
AttributeError: 'StructureWidget' object has no attribute 'structure'
ab5424 commented 2 months ago

Also, the "change file" button does nothing for me

adrianusler commented 2 months ago

Thank you for pointing these bugs out, @ab5424. It is because of the change from StructureWidget possessing a single Structure member to it now possessing a list of structures. I will fix this.

adrianusler commented 2 months ago

I think that the problem with the export is fixed now, @ab5424. I have not implemented the file dialog yet.

adrianusler commented 2 months ago

Update: "change file" now opens a file dialog @ab5424.

Michel-Heinz commented 2 months ago

The export seems to work fine 👍 What did you change in the measurement tool and the trajectory dialog?

ab5424 commented 2 months ago

I think that the problem with the export is fixed now, @ab5424. I have not implemented the file dialog yet.

@adrianusler The image export works fine now but file export fails:

Traceback (most recent call last):
  File "/Users/alexbonkowski/PycharmProjects/Molara/src/molara/Gui/main_window.py", line 170, in export_structure
    if not self.structure_widget.structure:
AttributeError: 'StructureWidget' object has no attribute 'structure'
Michel-Heinz commented 2 months ago

I fixed the structure export @ab5424. But it would be nice to also change the default save location for this feature to the home directory.

adrianusler commented 2 months ago

The export seems to work fine 👍 What did you change in the measurement tool and the trajectory dialog?

I changed the tab order.

adrianusler commented 2 months ago

Ready to merge @ab5424 @Michel-Heinz