nmrglue NMR Processing

nmrglue NMR Processing

by:

@OpenSourceBuffGuy

📚 Education & Research

Processes raw one-dimensional NMR free-induction decays into phased spectra, peak candidates and integrated regions with nmrglue, with axis checks and a processing report.

Skill files4 files

assets/

references/

scripts/

SKILL.md139 lines
1
---
2
name: nmrglue
3
description: Processes calibrated one-dimensional complex NMR free-induction decays with nmrglue into phased spectra, peak candidates, and signed integration regions. Use for raw 1D NMR processing, ppm-axis verification, apodization, Fourier transformation, manual phasing, baseline correction, or reproducible spectral integration.
4
license: MIT
5
compatibility: Requires Python 3.12+, nmrglue, NumPy 2+, and SciPy. Installation needs network access; processing is local and needs no credentials.
6
metadata:
7
version: "1.1"
8
skill-author: K-Dense Inc.
9
tested-package-version: "0.12"
10
last-reviewed: "2026-10-01"
11
---
12
13
# nmrglue: calibrated 1D FID processing
14
15
## When to use
16
17
Use for a uniformly sampled complex 1D FID whose acquisition parameters and complex
18
frequency convention are available. The helper produces a descending ppm spectrum,
19
positive peak candidates, signed region integrals, and a reproducible processing report.
20
It does not identify compounds or assign resonances.
21
22
The executable accepts a NumPy `.npz` containing exactly one complex `fid` array or a
23
canonical 1D complex time-domain NMRPipe file. NMRPipe reading is tested with a synthetic
24
write/read round trip, known-spectrum recovery, and a small upstream NMRPipe-generated
25
binary fixture. Experimental Bruker, Varian, and JEOL
26
imports are **not verified by this suite**. For those formats, first inspect the relevant
27
nmrglue reader and acquisition metadata. Opening a converted file does not validate the
28
original acquisition decoding.
29
Read [references/acquisition-and-validation.md](references/acquisition-and-validation.md)
30
for conversion boundaries, axis calibration, and quantitative limits.
31
32
## Workflow
33
34
1. Preserve the raw FID. Establish spectral width in Hz, positive observation frequency
35
in MHz, carrier in ppm, observed nucleus, and the sign convention from the acquisition
36
or a known reference. Determine whether digital-filter/group-delay removal has already
37
occurred. Do not infer these from array length or typical instrument defaults.
38
2. Copy [assets/processing.json](assets/processing.json) and replace its synthetic example
39
values with the measured parameters and explicit processing choices. Its sign `-i`
40
means a resonance at offset `f = (ppm - carrier_ppm) * observation_mhz` has time
41
dependence `exp(-2*pi*i*f*t)`. Select `+i` only for the opposite convention; the helper
42
conjugates it before processing. Validate with a known reference peak.
43
3. Choose nonnegative exponential line broadening (Hz), an even zero-filled size at
44
least as large as the acquired FID, first-point scaling, and phase angles.
45
Zero filling improves interpolation, not acquired spectral resolution.
46
First-point scaling `0.5` is suitable for the supplied causal synthetic example;
47
acquisition and prior preprocessing may require another value.
48
4. Run the helper, inspect the real and imaginary spectra, and revise manual phase if
49
needed. `phase0_deg + phase1_deg * index / zero_fill_points` is applied after FT;
50
index zero is the high-ppm edge. There is no implicit pivot or automatic phase estimate.
51
5. Only fit a linear baseline when explicitly supplied ppm regions are signal-free.
52
Set `baseline` to `linear` and add `baseline_regions_ppm` containing at least two
53
regions. Inspect residuals and broad peaks; fitting through signals biases integrals.
54
6. Compare peak positions with references, inspect peak candidates for artifacts, and
55
integrate specified regions. Report overlapped peaks as overlapped. Preserve negative
56
areas as diagnostic evidence of phase/baseline problems instead of taking absolute values.
57
58
## Execute
59
60
Tested with Python 3.12, nmrglue 0.12, NumPy 2.5.3, and SciPy 1.18.1:
61
62
```bash
63
uv run --no-project --python 3.12 --with nmrglue==0.12 --with numpy==2.5.3 --with scipy==1.18.1 \
64
python skills/nmrglue/scripts/process_1d.py fid.npz processing.json nmr-result
65
```
66
67
Paths assume the collection root. Adjust them when installed elsewhere. The output
68
directory must be new, so repeated processing keeps previous results reviewable.
69
70
For an existing 1D NMRPipe FID, add `--input-format nmrpipe` and supply its path in place
71
of `fid.npz`. The helper requires the canonical FDF2 direct dimension, complex quadrature,
72
a time-domain flag, and agreement between header and JSON spectral width, observation
73
frequency, and carrier. JSON settings remain explicit; a mismatch fails instead of silently
74
recalibrating. `FDF2TDSIZE` must equal the stored complex-point count, and `FDF2CENTER` /
75
`FDF2ORIG` must describe a canonical centered axis. Previously zero-filled, truncated,
76
or recentered files need a separate acquisition-aware workflow. The nucleus/complex sign
77
and previous digital-filter corrections still need acquisition evidence. A time-domain
78
flag alone does not establish an unprocessed FID.
79
80
This executable synthetic example matches the supplied settings, generates resonances
81
at 3 and 7 ppm in a 1:2 amplitude ratio, and does not represent an experimental sample:
82
83
```python
84
import numpy as np
85
86
t = np.arange(8192) / 4000.0
87
fid = sum(a * np.exp(-np.pi * 2.0 * t)
88
* np.exp(-2j * np.pi * (ppm - 5.0) * 400.0 * t)
89
for ppm, a in [(3.0, 1.0), (7.0, 2.0)])
90
np.savez("fid.npz", fid=fid)
91
```
92
93
Run it with `assets/processing.json` as the settings argument. The repository suite
94
executes this signal and the CLI, checks both peak locations within 0.001 ppm, checks
95
integral ratio and analytic area, and checks phase and baseline recovery. The NMRPipe
96
round-trip test writes this FID using `ng.pipe.create_dic`/`ng.pipe.write`, reads it through
97
the CLI, and verifies the recovered peaks and integral ratio. Processed frequency-domain
98
files and conflicting calibration metadata are rejected.
99
100
The 2,176-byte upstream fixture checks complex sample order and header calibration using
101
a file generated by NMRPipe's `simTimeND` / `SET` tools. Those native tools were not run
102
in this review; this is fixture compatibility, not a live NMRPipe processing comparison.
103
104
## Deliverables and interpretation
105
106
- `spectrum.csv`: descending ppm, real signal after baseline correction, phased imaginary
107
signal, and the fitted real baseline. Plot NMR with the high-ppm end on the left.
108
- `report.json`: input/settings SHA-256, package versions, all settings, acquired duration,
109
zero-filled digital spacing, positive peak candidates, and signed region areas.
110
111
Integrals use endpoint interpolation and trapezoidal integration along increasing ppm;
112
area units are arbitrary signal times ppm, independent of display direction. Regions
113
outside the sampled ppm axis fail rather than being silently clipped. Peak prominence
114
is a fraction of the largest positive real intensity; it is not a noise-derived detection
115
limit. Strong solvent signals can obscure weak candidates at the default threshold.
116
117
For quantitative NMR, additionally establish relaxation delay, pulse angle, saturation,
118
receiver behavior, internal/external reference amount, and integration uncertainty.
119
The helper does not calculate concentrations or correct unequal relaxation. Preserve
120
these limits with the result rather than converting arbitrary areas to molecule counts.
121
122
## Upstream contracts
123
124
- [Processing functions](https://nmrglue.readthedocs.io/en/latest/reference/proc_base.html):
125
exponential apodization, zero filling, FFT, and phase operations.
126
- [File and axis utilities](https://nmrglue.readthedocs.io/en/latest/reference/fileiobase.html):
127
unit conversion uses spectral width in Hz, observation frequency in MHz, carrier in Hz.
128
- [NMRPipe reader/writer](https://nmrglue.readthedocs.io/en/latest/reference/pipe.html):
129
the validated ingestion path is a synthetic canonical 1D time-domain round trip.
130
- [nmrglue project](https://github.com/jjhelmus/nmrglue): upstream source and format readers.
131
132
The hosted `latest` documentation identified itself as 0.9-dev when checked; the actual
133
0.12 package APIs and numerical behavior were tested. Its `proc_base.fft` uses the
134
negative-exponent NumPy FFT followed by `fftshift`; NMRPipe's FT convention corresponds
135
to `fft_positive`, so do not substitute it without revisiting the FID sign and phase.
136
See the [v0.12 processing source](https://github.com/jjhelmus/nmrglue/blob/v0.12/nmrglue/process/proc_base.py).
137
Multidimensional processing, nonuniform sampling, automated assignment, and experimental vendor imports remain outside
138
this helper's validated scope.
139

© K-Dense Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…