hqs_nmr.spectrumio
Deserialization and serialization from various NMR spectrum formats.
Functions
|
Read spectral data from a Bruker directory and write it to a JCAMP-DX file. |
|
Read spectral data from Bruker directory. |
|
Read spectral data from a JCAMP-DX (JDX) file. |
|
Parses JDX spectral data from string. |
|
Write a JCAMP-DX file. |
- hqs_nmr.spectrumio._extract_solvent_jcampdx(data: dict[str, Any]) list[str] [source]
Extracts solvent string from a JCAMP-DX data dictionary if available.
With JCAMP-DX version 5.01 a new optional “.SOLVENT NAME” key has been added to store a description of the solvent. According to the specification this may include pH, ionic strength, if relevant. This function does not distinguish the solvent name from such additional data.
A few notes regarding the parsing via the nmrglue package: Since a JCAMP-DX file may contain more than one block (ends with “##END”), nmrglue collects all values of a key in a list. Furthermore, nmrglue normalizes the key in the data dictionary, i.e. while the JCAMP-DX file may contain “##.SOLVENTNAME” or “##.SOLVENT NAME”, the resulting data dictionary only contains a “.SOLVENTNAME” key in both cases.
- Parameters:
data – Data dictionary resulting from parsing with nmrglue.
- Returns:
Solvent string(s) or an empty list if no solvent information was found.
- hqs_nmr.spectrumio._extract_solvent_bruker(data: dict[str, Any]) str [source]
Extracts solvent string from a Bruker data dictionary if available.
The Bruker directory format stores the solvent name in the acquisition file (acqus or acqu) under the non-standard key “##$SOLVENT”. The solvent name is usually enclosed in angle brackets (e.g. <DMSO>), which are stripped of with this function.
- Parameters:
data – Data dictionary resulting from parsing with nmrglue.
- Returns:
Solvent string or an empty string if no solvent information was found.
- hqs_nmr.spectrumio._extract_temperature_jcampdx(data: dict[str, Any]) list[float] [source]
Extracts temperature (in Kelvin) from a JCAMP-DX data dictionary if available.
JCAMP-DX files store the temperature in degrees Celsius in the “##TEMPERATURE” field. Note that this function returns the temperature in Kelvin.
A few notes regarding the parsing via the nmrglue package: Since a JCAMP-DX file may contain more than one block (ends with “##END”), nmrglue collects all values of a key in a list.
- Parameters:
data – Data dictionary resulting from parsing with nmrglue.
- Returns:
Temperature(s) in Kelvin or an empty list if no temperature was found.
- hqs_nmr.spectrumio._extract_temperature_bruker(data: dict[str, Any]) float | None [source]
Extracts temperature (in Kelvin) from a Bruker data dictionary if available.
The Bruker directory format stores the temperature (in Kelvin) in the acquisition file (acqus or acqu) under the non-standard key “##$TE”. The data dictionary produced by nmrglue.bruker.read_pdata holds the temperature already as a float.
- Parameters:
data – Data dictionary resulting from parsing with nmrglue.
- Returns:
Temperature in Kelvin or None if no solvent information was found.
- hqs_nmr.spectrumio._extract_isotopes_jcampdx(data: dict[str, Any]) list[Isotope] [source]
Extracts isotope from a JCAMP-DX data dictionary.
JCAMP-DX files store the isotope in the “##.OBSERVE NUCLEUS” field. The corresponding value usually contains a leading caret (e.g. ^13C), which is removed in this function.
A few notes regarding the parsing via the nmrglue package: Since a JCAMP-DX file may contain more than one block (ends with “##END”), nmrglue collects all values of a key in a list. Furthermore, nmrglue normalizes the key in the data dictionary, i.e. while the JCAMP-DX file may contain “##.OBSERVENUCLEUS” or “##.OBSERVE NUCLEUS”, the resulting data dictionary only contains a “.OBSERVENUCLEUS” key in both cases. NOTE: If both “.OBSERVENUCLEUS” and “.OBSERVE NUCLEUS” exist in the JCAMP-DX file, the nmrglue package unfortunately merges the two keys resulting in additional items in the isotope list. This function ensures that the isotope list has as many elements as the raw data for “.OBSERVEFREQUENCY”.
- Parameters:
data – Data dictionary resulting from parsing with nmrglue.
- Returns:
List of isotopes.
- hqs_nmr.spectrumio._extract_isotope_bruker(data: dict[str, Any]) Isotope [source]
Extracts isotope from a Bruker data dictionary.
The Bruker directory format stores the isotope in the processing file (procs or proc) “##$AXNUC”. The isotope string is usually enclosed in angle brackets (e.g. <1H>). Contrary to the solvent name, the isotope string stored in the data dictionary does not include the angle brackets. If the “##$AXNUC” key cannot be found in the procs file, it is attempted to extract the isotope from the acqus file instead (“##$NUC1” key).
- Parameters:
data – Data dictionary resulting from parsing with nmrglue.
- Returns:
Isotope of observed nucleus.
- hqs_nmr.spectrumio._extract_xdata_jcampdx(jdx_content: str, npoints: int) list[ndarray] [source]
Extracts x-data (chemical shift values) directly from a JCAMP-DX file.
Custom extraction of x-data for the (XY..XY) format, which allows no even spacing along the x-axis. Note that nmrglue does neither support the XYPOINTS data class, nor returning the x array when the (XY..XY) specifier is used as XYDATA.
NOTE: it is assumed that the JCAMP-DX file contains only one block of XYDATA data.
- Parameters:
jdx_content – Content of the JCAMP-DX file.
npoints – Number of points in the spectrum.
- Raises:
ValueError – Inconsistent JDX parameters.
- Returns:
x-data with the real values of the (XY..XY) block.
- hqs_nmr.spectrumio.read_jdx(file: Path | str, source: str = 'Unknown', license_id: str = 'Unknown') NMRExperimentalSpectrum1D [source]
Read spectral data from a JCAMP-DX (JDX) file.
NOTE: it is assumed that the JCAMP-DX file contains only one block, i.e. one spectrum and one isotope.
- Parameters:
file – Path to the JDX file.
source – Owner or producer of the spectrum.
license_id – License associated with the spectrum (as SPDX identifier if possible).
- Raises:
RuntimeError – Parsing failed.
NotImplementedError – Unsupported spectral data.
ValueError – Inconsistent JDX parameters.
- Returns:
A NMRExperimentalSpectrum1D object with chemical shifts (in ppm) and intensities.
- hqs_nmr.spectrumio.read_jdx_string(file_content: str, source: str = 'Unknown', license_id: str = 'Unknown') tuple[ndarray, ndarray] [source]
Parses JDX spectral data from string.
Note this function creates a temporary file in order to match the function interface of nmrglue.jcampdx.read.
- Parameters:
file_content – Content of a JCAMP-DX file.
source – Owner or producer of the spectrum.
license_id – License associated with the spectrum (as SPDX identifier if possible).
- Returns:
A tuple of chemical shifts (in ppm) and intensities.
- hqs_nmr.spectrumio.read_bruker_dir(directory: Path | str, source: str = 'Unknown', license_id: str = 'Unknown') NMRExperimentalSpectrum1D [source]
Read spectral data from Bruker directory.
- Parameters:
directory – Path to the “pdata” subdirectory of the Bruker directory, for example bmse0001230/pdata/1.
source – Owner or producer of the spectrum.
license_id – License associated with the spectrum (as SPDX identifier if possible).
- Returns:
A NMRExperimentalSpectrum1D object containing chemical shifts (in ppm) and intensities.
- hqs_nmr.spectrumio.write_jdx(x_data: ndarray, y_data: ndarray, frequency_MHz: float, molecule_name: str, solvent: str = 'CDCl3', isotope: str = '1H', manual_shift: float | None = None) None [source]
Write a JCAMP-DX file.
This function writes a JCAMP-DX file from given x and y data. It is able of moving the x-axis by a specified amount. This is useful when the experimental spectrum is wrong referenced.
- Parameters:
x_data – X data, shifts in ppm.
y_data – Y data, intensity.
frequency_MHz – Observation frequency in MHz (depends on the isotope).
molecule_name – Molecule name.
solvent – Solvent name. Defaults to “CDCl3”.
isotope – String representation of the isotope as [atomic mass number][symbol]. Defaults to “1H”.
manual_shift – Manual shift in ppm. Defaults to None.