Python bindings for my custom model



  • Dear all,

    I would like to have the possibility of using my custom model also when scripting in SAMSON. I haven't found any documentation for this, is it somewhere? If not, it is possible to also use pybind11 with our custom models/apps and what would be the best way to start?

    Thanks in advance and best regards,

    Elisa



  • Dear @Elisa ,

    Yes, you can expose the functionality of your Element yourself. I need to check a few things on how to do it in the best way.
    What kind of custom model do you want to expose (on what SAMSON SDK Class is it based on)?



  • Dear Dmitriy,

    It is based on SBStructuralModel and its related classes (SBStructuralGroup, SBChain, SBResidue, ...). I have an interface through an App to handle it, and I would like to expose it so I can also create this custom structural models using python scripts :) Right now I would just do it in C++ and bind it to a button on the app.

    Thanks and best regards,

    Elisa



  • Dear @Elisa ,

    It would be really great to be able to expose functionality of SAMSON Elements into python. In our plans for one of the future releases, we had an automatic generation of python bindings based on the exposed functionality in SAMSON Elements. So, I have not properly tried to create python bindings for a SAMSON Element due to a problem with dependency on python bindings for SAMSON SDK. I will see how that can be done now and will return to you.

    Best regards,
    Dmitriy



  • Dear @Elisa ,

    Do you need to create bindings for any function which receives or returns specific SAMSON quantities or types, such as SBQuantity, SBPosition3, etc?



  • Dear @Elisa ,

    Just letting you know, that a tutorial on how to create python bindings for a SAMSON Element will be released next week.



  • Hi Dmitriy, yes, in principle it would be useful to have bindings for functions returning SAMSON quantity types, but I think I could work around it if it wasn't available.

    Thanks for your help! Looking forward to the tutorial!



  • Dear @Elisa ,
    Unfortunately, due to some other urgent deadlines, I am not sure that I will have time to prepare a tutorial this week (I will prepare the tutorial either by the end of the week or next week). But if you want to try it this week, you can check a sample SAMSON Element with python bindings I prepared: https://github.com/1A-OneAngstrom/SAMSON-Developer-Tutorials/tree/develop
    It shows how to do some simple python bindings for an App and for custom classes. Feel free to ask any questions.
    SAMSON Element: PyBindTutorial
    Branch: develop



  • Thank you Dmitriy, that's already very helpful!! I will try to get it working :)



  • If you name your module based on the SAMSON Element UUID, as suggested in the sample, then you can import it as follows:

    import SE_F2078F9E_F2CB_BA72_EE86_1E01A10B63D4 as pybindtutorial
    

    Warning: if your SAMSON Element has a python bindings in it, meaning it is linked to a python library, then for users to use this Element they will need to have Python installed, which should be the case if they already use Python Scripting.



  • Hi, I have tried to get it working but Python Scripting has stopped working for me (I think it might be due to changes in my python installation since I first installed it). I'm using Anaconda3, I reinstalled everything with Python 3.7, but was unable to see the Python Scripting module loaded. After a downgrade to python 3.6 I can see the module loaded but not the jupyter qtconsole on it (if I run jupyter qtconsole from conda it runs fine, the versions it displays are: Jupyter QtConsole 4.4.2 and Python 3.6.7)

    I followed the instructions of the documentation but was unable to make it run, maybe I'm missing something?

    Thank you and best regards,

    Elisa



  • Dear @Elisa

    Thank you for reporting it! I will add the tested installations to the installation tutorial.

    I have not tested Python Scripting with python 3.7. I do not expect it to work with python 3.7 since it was compiled against python 3.6 and is linked to python3.6 library.
    The loaded python scripting means that you probably have a proper version of python library. The fact that Jupyter QtConsole is not loaded might mean that its version is not the one against which it was compiled.

    What OS do you use?

    I am using Python Scripting in Linux with Python 3.6.4 and Jupyter QtConsole 4.3.1 from Anaconda 5.1 installation. Anaconda 5.2 installation might also be fine (tested only on Windows).





  • @Elisa

    Is it possible for you to try to downgrade Jupyter QtConsole to v.4.3.1 and check?



  • Hi, I'm using Anaconda 5.3.1 I just downgraded to QtConsole 4.3.1 and python from 3.6.7 to 3.6.5, but I still don't get the jupyter qtconsole on Python Scripting module. The versions I'm using for the rest of dependencies are:
    jupyter 1.0.0
    jupyter_client 5.2.3
    jupyter_console 6.0.0
    jupyter_core 4.4.0
    numpy 1.15.4

    I will try downloading Anaconda 5.2 and reinstalling from there.



  • Sorry for this issue!
    It is really due to linking to particular versions of libraries we do in Python Scripting.

    I will try to reproduce your case and come up with a full list of dependencies and proper versions for required packages.
    In my Anaconda installation on Linux these packages have the following version:

    jupyter                   1.0.0
    jupyter_client            5.2.2
    jupyter_console           5.2.0
    jupyter_core              4.4.0
    numpy                     1.14
    

    On Windows:

    jupyter                   1.0.0
    jupyter_client            5.2.3
    jupyter_console           5.2.0
    jupyter_core              4.4.0
    numpy                     1.14.3
    

    Could you, please, try downgrading numpy to v.1.14?

    If it won't work, it would be nice if you will be able to try the Anaconda3 installation written in the Tested installations section in the documentation.



  • I have run conda install anaconda=5.2, now all the packages match the versions you have, but I still am unable to see the the jupyter qtconsole on the Python Scripting module. Maybe the error is somewhere else, is there a log a could check?



  • What OS do you use?
    Could you, please, check the environment variables for which Python paths are set there?



  • Yes, I'm using Windows 10, and the Path variables for anaconda3 are set (I added them when installing). I will try to install Anaconda3 for all users, in case the problem comes from this.



  • It should not be a problem, it should work for a user installation. On my Windows 10 I have it installed only for my user.



  • To see the SAMSON log on Windows, you can open a terminal (Power Shell) and launch SAMSON from there (provide the full path to the SAMSON executable or launch from where it is installed):

    .\SAMSON-Core.exe --logfile="samson.log"
    

    Then you can open the log file and search for the line: "Python Scripting: initialization ..."
    Could you, please, post here what you have in this log after this line (related to the Python Scripting).


Log in to reply
 

Looks like your connection to SAMSON Connect - Forum was lost, please wait while we try to reconnect.