sciapp / mogli

simple visualization of molecules in python
MIT License
12 stars 8 forks source link

grafik will closed automatically #8

Closed steto123 closed 1 year ago

steto123 commented 1 year ago

Hi,

i am a newbie in programming pyton. Wenn i use mogli without gr framework (mogli.show) my programm works fine. But using gr, the grafic will not displayed in spyder. Starting from console the grafik window will be open and closed in one second. Can you help me?

I use anaconda on a modern windows 11 pc with nvidia gtx 3080ti grafic card.

And a second one (FYI), when i use mogli.show and close the molecule window in spyder there are some errors like


File ~\anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec exec(code, globals, locals)

File c:\users\wotan\onedrive\dokumente\2023\7tagepython\orca-read(mogli).py:70 mogli.show(molecules[0], bonds_param=1.25)

File ~\anaconda3\lib\site-packages\mogli.py:424 in show gr3.terminate()

File ~\anaconda3\lib\site-packages\gr3__init__.py:313 in terminate _gr3.gr3_terminate()

File ~\anaconda3\lib\site-packages\gr3__init__.py:259 in _error_check raise exception

GR3_Exception: b'gr3.c' (l. 565): GR3_ERROR_OPENGL_ERR


FlorianRhiem commented 1 year ago

Hey @steto123,

for the first question, I assume that the script finishes and the window closes. You could either set the GKS_WSTYPE environment variable to something like png to write out an image instead of opening a window, or you could add something to delay the end of the script, such as reading input with input().

For the second question, it looks like GR3 is trying to terminate but the OpenGL context has already been closed before gr3.terminate() was called, so OpenGL errors are produced which lead to an exception. You can add a try / except around the gr3.terminate() to ignore this exception. It'd only be important if the script would continue, as there's no guarantee that all resources are freed if the termination code fails.

steto123 commented 1 year ago

Many thanks

both answers are really useful.