nmrsim icon indicating copy to clipboard operation
nmrsim copied to clipboard

Feat: Add support for spin-1 nuclei

Open klemenpe opened this issue 7 months ago • 1 comments

This Pull Request introduces significant enhancements to nmrsim to enable the simulation of spin-1 nuclei as well as mixed-spin systems, such as those involving both proton (1H) and deuterium (2H) nuclei.

Key Changes & Features:

  • Mixed-Spin Support in SpinSystem: The SpinSystem class now accepts a spin quantum number array (s) during initialization, allowing for accurate Hamiltonian construction and peaklist generation for systems with different nuclear spins (e.g., I=1/2 for 1H, I=1 for 2H) or the same nuclear spins (e.g., two 2H atoms I=1).
  • ppm_to_hz_from_nuclei_info Function: A new utility function, ppm_to_hz_from_nuclei_info, has been added to simplify input by converting chemical shift values in ppm to Hz, correctly accounting for the specific gyromagnetic ratios of different nucleus types.
  • reduce_peaks Function Enhancement: The reduce_peaks function has been updated to robustly handle np.ndarray inputs, improving its general usability.

Validation & Testing:

  • Comprehensive new tests have been added in tests/test_mixed_spin_systems.py.
  • A specific test case simulates the residual 1H signal in the DMSO CD3CD2HSO isotopomer, verifying the correct generation of both the 1H quintet and the 2H doublet signals, demonstrating the end-to-end functionality of these changes.
  • All existing tests pass, and no new failures were introduced. The pre-existing @pytest.mark.xfail tests in test_qm.py continue to behave as expected (failing due to known sparse array boolean conversion issues, unrelated to this feature).

Other Changes:

  • Added *.npz files to .gitignore to prevent generated binary cache files from being tracked in version control.

Potential Documentation Update:

This new functionality would benefit from being documented on the Sphinx page. I am available to assist with writing or clarifying examples if guidance on the documentation structure is provided.

klemenpe avatar Jul 21 '25 15:07 klemenpe

Sorry for the delay. Once my summer semester ends next week I will try to look this over.

sametz avatar Aug 05 '25 20:08 sametz