espressomd / espresso

The ESPResSo package
https://espressomd.org
GNU General Public License v3.0
230 stars 188 forks source link

Look into PyStar #4382

Open jngrad opened 3 years ago

jngrad commented 3 years ago

Source code: alexander.d.kazakov/pystar

Installation: pip3 install simlearn

Running PyStar:

import espressomd
from simlearn import PyStar
PyStar.run()

At the time of writing, this requires ESPResSo 4.1.4 (4.2-dev doesn't work out-of-the-box).

Most of the GUI python code was automatically generated from .ui files with pyuic5.

Tasks for the coding day:

RudolfWeeber commented 3 years ago

More generally, it needs to be determined, what exactly can be tought using the program, and if/how this could/should tie in with our other Espresso teaching activities.

RiccardoFrenner commented 2 years ago

I will look into it tomorrow.

RiccardoFrenner commented 2 years ago

Visualization

Usage

As teacher

Use predefined example systems or create own systems to

Predefined example systems

LJ fluid 2D/3D

Create own systems

Conclusion

RudolfWeeber commented 2 years ago

Thanks, Riccardo.

Peter, maybe you can add on how you are using it.

How difficult is it, to modify the gui (as I understand it, a generator is used)

Would it be difficult to adapt to the current Python developr branch?

Would it be possible with reasonable effort (short of remote-controlling the gui) to automatically test one of the simple systems?

RiccardoFrenner commented 2 years ago

PyQt5 allows for automated testing with the QTest module. Here is a small example which automatically starts the LJ fluid example of the PyStar application:

import sys
import unittest as ut

from PyQt5 import QtCore
from PyQt5.QtTest import QTest
from PyQt5.QtWidgets import QApplication

from pystar.application.simlearn import PyStar

class TestLJ2D(ut.TestCase):
    def setUp(self):
        self.app = QApplication(sys.argv)
        self.main_window = PyStar.WelcomeWindow()

    def tearDown(self):
        self.app.exec_()

    def test(self):
        LEFT_MB = QtCore.Qt.MouseButton.LeftButton
        QTest.mouseClick(self.main_window.LJ2D_button, LEFT_MB)
        QTest.mouseClick(self.main_window.current_task.uim.run_button, LEFT_MB)

if __name__ == '__main__':
    ut.main()

However, if I don't call self.app.exec_() in tearDown() the application crashes after test finishes executing. But calling self.app.exec_() causes the app to be launched as a user would do, which is not ideal. I am sure there is a way around that but I am not familiar with Qt at all. So I think it is relatively simple to test a system.

RiccardoFrenner commented 2 years ago

Changing the GUI should also be easy. The .ui files can be generated with QTCreator and editing the files by hand is also possible.

Regarding the port to develop, I don't know what has changed since 4.14, so I am not sure how much work it is. Each PyStar example system uses some Espresso calls directly, more complex routines, like warming up the system, are wrapped in functions and need less work. If I had to guess I would say it's equivalent to porting two Espresso scripts with each 300 lines of code.