This library provides tools for working with JCAMP-DX formatted spectroscopic data, with a focus on NMR (Nuclear Magnetic Resonance) data. It can:
The following Python packages are required:
cd jcampdx
pip install numpy scipy matplotlib
pip install nmrglue
pip install rdkit
conda install -c conda-forge rdkit
To verify that the installation was successful, you can run a simple test:
python -c "import jcamp; print('JCAMP-DX library installed successfully')"
For development purposes, you can install the package in development mode:
pip install -e .
The main entry point for creating JCAMP-DX files is createjcamp.py. It can be used to convert various NMR data formats to JCAMP-DX.
Basic usage:
python createjcamp.py [options...] > output.jdx
To see all available options:
python createjcamp.py --help
NMRML is an XML-based format for NMR data. The library can directly convert NMRML files to JCAMP-DX:
python createjcamp.py --fromnmrml input_file.nmrML > output.jdx
This is a simplified command that handles all the conversion details automatically.
A single JCAMP-DX file can contain multiple blocks of different types. This example creates a file with structure, spectrum, peak list, and assignments:
python createjcamp.py --title "TEST FILE" \
--block STRUCTURE --file structure.mol --title "STRUCTURE" \
--block 1DSPECTRUM --file example_1h_spectrum.txt csv --title "SPECTRUM" --frq 500 --nuc 1H --refcpd DSS --refppm 0 \
--block 1DPEAKS --file example_1h_peaklist.txt csv --title "PEAKS" --frq 500 --nuc 1H --link 1 \
--block ASSIGNMENTS --file example_1h_peaklist.txt csv --title "ASSIGNMENTS" --frq 500 --nuc 1H --link 2 \
> output.jdx
The --link option creates cross-references between blocks, which is useful for connecting related data (e.g., a spectrum and its peak assignments).
python createjcamp.py --title "FROM BRUKER" --block 1DSPECTRUM --file ./nmr.fid/pdata/1/ bruk > output.jdx
For Bruker 2D data:
python createjcamp.py --title "BRUKER 2D" --block 2DSPECTRUM --file ./nmr.fid/pdata/1/ bruk > output_2d.jdx
python createjcamp.py --title "FROM VARIAN" --block 1DSPECTRUM --file ./varian_data/ var > output.jdx
python createjcamp.py --title "VARIAN 2D" --block 2DSPECTRUM --file ./varian_data/ var > output_2d.jdx
import jcamp from jcamp
import FileParser
# Parse a JCAMP-DX file
data = FileParser.parse_jcamp("input.jdx")
# Create a JCAMP-DX object from parsed data
jdx = FileParser.create_jcamp(data)
# Scale the data for optimal representation
jdx.data.scale_x()
jdx.data.scale_y()
# Convert to nmrglue format
udic, d = jdx.to_nmrglue_1d()
# Write to a new JCAMP-DX file
with open("output.jdx", "w") as f:
f.write(jdx.write())
JCAMP-DX (Joint Committee on Atomic and Molecular Physical Data - Data Exchange) is a standardized format for exchanging spectroscopic data. The format consists of:
This library implements JCAMP-DX versions 4.24, 5.01, and 6.00, with a focus on NMR data as specified in the JCAMP-DX standard.
These encoding formats are used to compress the data and reduce file size while maintaining data integrity. The encoding/decoding process is handled by the encode.pyand decode.py modules.
jdx.data.scale_x() # Scale x-axis data
jdx.data.scale_y() # Scale y-axis data to fit in 16-bit integer range
# Convert to nmrglue format
udic, data = jdx.to_nmrglue_1d()
# Create JCAMP-DX from nmrglue data
jdx = NMRSpectrum.from_nmrglue_1d(udic, data)
# For FID data with complex values
fid = NMRFid()
fid.data = NTuples1DFIDData(complex_data)
# Add a molecular structure to a JCAMP-DX file
block = jcamp_dx.blocks[0]
block.add_mol("structure.mol")
# Add peak assignments
block.add_assignments("assignments.csv", filetype="csv")
For Bruker data, the library can remove the digital filter effects that are present in the raw FID data. This is important for accurate processing of Bruker NMR data:
# Remove digital filter effects
grpdly = remove_digital_filter(dic, data)
The algorithm uses the group delay parameter from the Bruker acquisition parameters to correct the phase distortion introduced by the digital filter.
# Create a 2D spectrum
spec2d = NMRSpectrum2D()
spec2d.data = NTuplesNDSpectrumData(data2d, ranges)
import jcamp from jcamp
import FileParser
import matplotlib.pyplot as plt
import numpy as np
# Parse a JCAMP-DX file
data = FileParser.parse_jcamp("spectrum.jdx")
jdx = FileParser.create_jcamp(data)
# Convert to nmrglue format
udic, d = jdx.to_nmrglue_1d()
# Create x-axis in ppm
xaxis = np.fft.fftshift(np.fft.fftfreq(udic[0]['size'], 1/udic[0]['sw']))[::-1]
if udic[0]['car'] != 999.99:
xaxis += udic[0]['car']
xaxis /= udic[0]['obs']
# Plot the spectrum
plt.figure(figsize=(10, 6))
plt.plot(xaxis, d)
plt.xlabel('Chemical Shift (ppm)')
plt.ylabel('Intensity')
plt.title('NMR Spectrum')
plt.gca().invert_xaxis()
plt.show()
This project is licensed under the MIT License - see the LICENSE file for details.
This library uses the following open-source projects: