Loading...
Searching...
No Matches
Scripting

SAMSON Python API

SAMSON comes with the Python Scripting Extension which exposes the SAMSON API in Python and provides a Jupyter Qt console embedded in SAMSON (see Python Console). This allows you to script almost everything in SAMSON with Python, model and simulate from scripts, create pipelines, integrate Python packages for deep learning, bioinformatics, statistics, visualization, and more.

You can use SAMSON AI to help you with Python development - it has been trained on the Python Scripting Guide. For that, use /script in the SAMSON AI assistant - it will generate Python scripts based on your requests. With this command, SAMSON AI can draft Python scripts using the SAMSON Python API, tailored to your specific needs.

See the Python Scripting Guide to learn more how to use SAMSON Python API.

Python Console

The Python Console provides the possibility to access SAMSON's functionality using Python and automate your workflow using scripts. The Python Console integrates the Jupyter Qt Console.

To open the Python Console, click on Interface menu > Python Console or press Ctrl + 8 on Windows and Linux or Cmd⌘ + 8 on Mac.

Python Console

Installing Python packages

To install Python packages, in Python Console, go to Edit > Manage packages, provide the name of the package you would like to install, and click Install.

Package manager: install a Python package

Packages are managed using pip and what you provide will be done using pip. This means that you can:

  • Provide a list of packages to install.
  • Specify the package version, if necessary, as you would do when installing using pip, for example:
    • foo==1.2.0 to install the version 1.2.0 of the foo package
    • foo>=2.1.0 to install the foo package with the minimal version of 2.1.0
  • Add various pip flags after the package name, e.g.: foo –upgrade to upgrade to the latest version.

In the package manager, you can also see the list of installed packages and their versions.

Code Editor

SAMSON provides Code editor which integrates Monaco Editor, from the Visual Studio Code. It offers you an intuitive and powerful coding experience, complete with syntax highlighting, auto-completion, and more.

The Code editor provides the possibility to open and modify text files, including Python scripts. It also provides the possibility to run Python files.

To open the Code editor, click on Interface menu > Code editor or press Ctrl + 9 on Windows and Linux or Cmd⌘ + 9 on Mac.

Code editor

To run a Python script, click Run () on the left panel of the Code Editor or in its Run menu or use the integrated Python Console right within SAMSON for quick and easy execution. You get access to the entire SAMSON Python API and can even rapidly create Graphical User Interfaces (GUI) using PyQt.

The Code editor provides a set of Python script templates that demonstrate usages of SAMSON Python API. You can start from them. See the Python Scripting Guide to learn more how to use SAMSON Python API and for more examples.

Embedding Python Scripts and Apps

SAMSON Documents can contain not only molecular models, they enable Universal File Embedding and can embed Python scripts and any number of files and folders. This makes it possible to embed Python scripts and whole Python apps (e.g., machine learning apps), research papers, images, data, and so much more.

To embed files and folders within a Document, drag-and-drop them in SAMSON and you will be asked whether your would like to embed them or use Home menu > Embed files or Home menu > Embed folders.

Folders and files are stored within the Document, making the document self-contained, so you can transfer documents between computers and share documents.

To open an embedded Python script in the Code Editor, simply double-click on it.

You can share/distribute a SAMSON Document via email, GitHub, or the SAMSON Connect - Documents. Your colleagues or students can then open the document and run your embedded Python apps seamlessly.

Here are some of the possibilities:

  • You can collaborate with your colleagues by sharing SAMSON Documents that include project files, meeting notes, and automated workflow scripts.
  • As a researcher, you can attach executable data analysis scripts to their published molecular models, increasing transparency and reproducibility.
  • As a professor, you can distribute SAMSON Documents containing both lecture notes and interactive Python-based exercises for students.
  • As an educator, you can create comprehensive, interactive learning modules that students can execute directly within SAMSON.