TopSpin Python Interface

Python is the most popular programming language in the scientific community. The Python Package Index (PyPI), the official repository for third-party Python software, contains more than 290,000 packages with a wide range of features.

Jython interpreter (based on Python 2.7 ) has been part of TopSpin as a standard component for scripting and application development for 20 years. The Jython scripts are executed in the same Java virtual machine that runs the TopSpin user interface. This offers numerous possibilities, but also comes with some limitations.

Why not combine the capabilities of TopSpin, as the standard software for processing of NMR spectra, with Python 3 scripts and harness the power of all available packages?

The new Python application programming interface of TopSpin allows users to access TopSpin from any Python 3.9+ environment and is an alternative to, but does not replace, the well-established TopSpin Jython interpreter.

Get the latest Python Interface package for free. Just register / log in to download it.

New features

  • Advanced data analysis
  • Data mining
  • Publication quality image generation


The following functions are available

  • Reading/writing of parameters
  • Reading of data vectors, peak lists, integration regions...
  • Auxiliary functions such as NMR data search, data set display in TopSpin…
  • Execution of any TopSpin command

Data access is currently limited to one- and two-dimensional spectra. You can either read entire data vectors, or selected parts such as individual rows in a "ser" file, or columns from a 2D spectrum.

During the development of the Python programming interfaces, special emphasis was placed on user-friendliness. Whenever possible, a familiar syntax is used. For example, handling parameters or sending commands to TopSpin use the same syntax as typing in TopSpin command line.  The interfaces used for data access are identical for Python and Jython. This allows the code to be shared for different use cases.

Availability


Topspin 4.1.3 for Windows and Linux includes Python 3.9 environment, Bruker Python packages are pre-installed. Documentation and sample scripts are also available.

The required license is a part of the free TopSpin processing license for academia.

For industrial customers, a free evaluation license is available on demand.

Figure 1 TopSpin as a Service The Python 3 interpreter is a standalone application. Therefore, the easiest way to bridge between the Python application and TopSpin is to use a network connection. Bruker has implemented Python 3 packages that connect to the embedded web service in Topspin. In this way, NMR data can be read from the Python script, or TopSpin commands can be executed.

 

 

Figure 2 NMR titration of Pyridine at 80 MHz This is the output of a Python example script for evaluating titration data acquired with a Fourier 80 spectrometer. The Python script read the data using the TopSpin API and calculated the titration curves and estimate of Kb. The whole script (processing the spectra, calculating the results, and generating the images using NumPy) was about 150 lines long.