nmrglue
09 Apr 2023nmrglue is a python module to work with nmr data. It supports multiple nmr formats including bruker, varian, sparky, etc. The complete list is in the document.
In this post, I will show how to use nmrglue to process and visualize 2D ucsf(sparky) NMR data.
How to use nmrglue
Installation
The nmrglue can be easily installed with pip:
pip install nmrglue
Read Sparky data
Now we can import and use nmrglue:
Show headers
The headers are now loaded into a dictionary:
Outputs:
ident UCSF NMR
naxis 2
ncomponents 1
encoding 0
version 2
owner asurin
date Mon Apr 03 11:32:34 2023
comment
seek_pos 4194740
scratch
w1 {'nucleus': '13C', 'spectral_shift': 0, 'npoints': 1024, 'size': 1024, 'bsize': 128, 'spectrometer_freq': 125.77224731445312, 'spectral_width': 20752.421875, 'xmtr_freq': 75.00618743896484, 'zero_order': 0.0, 'first_order': 0.0, 'first_pt_scale': 0.0, 'extended': b'\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}
w2 {'nucleus': '1H', 'spectral_shift': 0, 'npoints': 1024, 'size': 1024, 'bsize': 128, 'spectrometer_freq': 500.1524963378906, 'spectral_width': 7142.85693359375, 'xmtr_freq': 5.000030517578125, 'zero_order': 0.0, 'first_order': 0.0, 'first_pt_scale': 0.0, 'extended': b'\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}
I have loaded a hsqc 2D spectrum and w1 and w2 are axis headers for carbon 13 and proton.
Visualization
Convert nmr csv to ucsf with nmrglue
MestReNova is a popular software to visualize and process NMR Spectrum. It has good algorithm to process 2D NMR spectrum, better than even the TopSpin and Vnmrj software. I have tried to manually process a COSY spectrum in vnmrj but could not get it to be as good as the same spectrum processed by my colleague using MestReNova. But when trying to analyze 2D spectrum, I could not find the overlay function for 2D spectrum in MestReNova. To analyze 2D NMR spectrum, I like to use Sparky. But there is no direct way to convert the output of MestReNova to ucsf format for Sparky.
After some research about the ucsf format, I decided to generate NMR csv format from MestReNova, and then use nmrglue to convert the csv format to ucsf format. For the file header and axis headers, I decided to generate ucsf directly from bruker/varian files and then update and use the headers.
So I have one ucsf file with bad data named noesy_varian.ucsf and csv file with good data but no headers called nosey.csv. Then I used the following code to do the conversion:
The output image looks like this:
The generated ucsf file was read by Sparky successfully: