Skip to content

Commit

Permalink
Merge branch 'release-0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sametz committed Mar 30, 2020
2 parents fefd2cf + c0a1266 commit 905f5bf
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 46 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@ the author interprets the terms below as follows:
API is stable.
The package is available on PyPI (and perhaps conda).


0.4.0 - 2020-xx-xx (beta release)
0.5.0 - 2020-03-29 (beta release)
---------------------------------
Changed
^^^^^^^
* add_lorentzians moved from nmr.plt to nmr.math.
Besides being more appropriate here,
it fixes a problem where importing from nmrsim.plt also requires importing
from matplotlib/Tkinter.
Some environments
(some Unix systems; BeeWare's Briefcase packaging tool)
do not have Tkinter available.
* nmrsim.plt will substitute the matplotlib "Agg" backend for "TkAgg"
if tkinter is not found on the users system, and print a warning message
that plots will not be visible.

0.4.0 - 2020-02-22 (beta release)
---------------------------------
Changed
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Click the "**Launch Binder**" link above to see how **nmrsim** can be used in Ju

`Documentation on Read the Docs <https://nmrsim.readthedocs.io/>`_

nmrsim (version 0.4.0 beta)
nmrsim (version 0.5.0 beta)
============================

**nmrsim** is a Python library for the simulation of solution-state nuclear magnetic resonance (NMR) spectra.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
author = 'Geoffrey M. Sametz'

# The short X.Y version
version = '0.4'
version = '0.5'
# The full version, including alpha/beta/rc tags
release = '0.4.0-beta'
release = '0.5.0-beta'


# -- General configuration ---------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Introduction to nmrsim v0.4.0 (beta)
Introduction to nmrsim v0.5.0 (beta)
=====================================

**nmrsim** is a library of tools for simulating NMR spectra, starting from
Expand All @@ -13,8 +13,13 @@ feature that you would like to see, or a barrier to you using this library,
feel free to open an issue on GitHub or to send the author email
(sametz at udel dot edu).

The project is inspired by the program `WINDNMR <https://www.chem.wisc.edu/areas/reich/plt/windnmr.htm>`_ by Hans
Reich. The goal for Version 1.0 of **nmrsim** is to provide Python tools for the same types of simulations that
WINDNMR did: first- and second-order simulation of spin-1/2 spin systems, plus simulation of some dynamic NMR (DNMR)
lineshapes. A longer-term goal is to expand the toolset (e.g. to allow higher-spin nuclei, or new DNMR models).
The project is inspired by the program
`WINDNMR <https://www.chem.wisc.edu/areas/reich/plt/windnmr.htm>`_
by Hans Reich.
The goal for Version 1.0 of **nmrsim** is to provide Python tools
for the same types of simulations that WINDNMR did:
first- and second-order simulation of spin-1/2 spin systems,
plus simulation of some dynamic NMR (DNMR) lineshapes.
A longer-term goal is to expand the toolset
(e.g. to allow higher-spin nuclei, or new DNMR models).

2 changes: 1 addition & 1 deletion nmrsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@

from ._classes import Multiplet, SpinSystem, Spectrum # noqa: F401

__version__ = '0.4.0'
__version__ = '0.5.0'
3 changes: 1 addition & 2 deletions nmrsim/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import numpy as np

from nmrsim.firstorder import first_order_spin_system, multiplet
from nmrsim.math import reduce_peaks
from nmrsim.plt import add_lorentzians
from nmrsim.math import reduce_peaks, add_lorentzians
from nmrsim.qm import qm_spinsystem
from nmrsim._utils import low_high

Expand Down
29 changes: 29 additions & 0 deletions nmrsim/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ def lorentz(v, v0, I, w):
return scaling_factor * I * ((0.5 * w) ** 2 / ((0.5 * w) ** 2 + (v - v0) ** 2))


def add_lorentzians(linspace, peaklist, w):
"""
Given a numpy linspace, a peaklist of (frequency, intensity)
tuples, and a linewidth, returns an array of y coordinates for the
total line shape.
Arguments
---------
linspace : array-like
Normally a numpy.linspace of x coordinates corresponding to frequency
in Hz.
peaklist : [(float, float)...]
A list of (frequency, intensity) tuples.
w : float
Peak width at half maximum intensity.
Returns
-------
[float...]
an array of y coordinates corresponding to intensity.
"""
# TODO: consider naming, and confusion with .math.add_peaks
# TODO: function looks clunky. Refactor?
result = lorentz(linspace, peaklist[0][0], peaklist[0][1], w)
for v, i in peaklist[1:]:
result += lorentz(linspace, v, i, w)
return result


def get_intensity(lineshape, x):
"""
A crude method to find the intensity of data point closest to
Expand Down
46 changes: 16 additions & 30 deletions nmrsim/plt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,30 @@
* mplplot_lineshape: Creates a lineshape plot from provided x, y lineshape data
and returns the x, y plot data.
"""

import matplotlib.pyplot as plt
import numpy as np

from nmrsim.math import lorentz
from nmrsim.math import add_lorentzians
from nmrsim._utils import low_high

# Pyplot assumes a TkAgg backend as a default. This can cause problems in
# environments where Tkinter is not available (e.g. some Unix systems;
# BeeWare's Briefcase packaging for Windows).
import matplotlib
try:
import tkinter as tk # noqa: F401
except ImportError:
matplotlib.use('Agg')
print('WARNING: Tkinter not found--plots will not display on screen!')

def add_lorentzians(linspace, peaklist, w):
"""
Given a numpy linspace, a peaklist of (frequency, intensity)
tuples, and a linewidth, returns an array of y coordinates for the
total line shape.
Arguments
---------
linspace : array-like
Normally a numpy.linspace of x coordinates corresponding to frequency
in Hz.
peaklist : [(float, float)...]
A list of (frequency, intensity) tuples.
w : float
Peak width at half maximum intensity.
Returns
-------
[float...]
an array of y coordinates corresponding to intensity.
"""
# TODO: consider naming, and confusion with .math.add_peaks
# TODO: function looks clunky. Refactor?
result = lorentz(linspace, peaklist[0][0], peaklist[0][1], w)
for v, i in peaklist[1:]:
result += lorentz(linspace, v, i, w)
return result
import matplotlib.pyplot as plt

# TODO: especially considering the possible swap to the 'Agg' backend,
# makes more intuitive sense for plot functions to return a plot object
# and not the coordinates.

# TODO: possibly refactor plot routines to avoid repetitive code


def mplplot(peaklist, w=1, y_min=-0.01, y_max=1, points=800, limits=None):
"""
A matplotlib plot of the simulated lineshape for a peaklist.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="nmrsim",
version="0.4.0rc1",
version="0.5.0",
author="Geoffrey M. Sametz",
author_email="[email protected]",
description="A library for simulating nuclear magnetic resonance (NMR) spectra.",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nmrsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nmrsim import Multiplet, SpinSystem, Spectrum
from nmrsim._classes import extract_components
from nmrsim.firstorder import first_order_spin_system
from nmrsim.plt import add_lorentzians
from nmrsim.math import add_lorentzians
from tests.accepted_data import SPECTRUM_RIOUX
from tests.qm_arguments import rioux

Expand Down
3 changes: 2 additions & 1 deletion tests/test_plt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
import pytest

from nmrsim.plt import add_lorentzians, mplplot, mplplot_stick, mplplot_lineshape
from nmrsim.plt import mplplot, mplplot_stick, mplplot_lineshape
from nmrsim.math import add_lorentzians
from tests.accepted_data import ADD_SIGNALS_DATASET
from tests.dnmr_standards import TWOSPIN_SLOW

Expand Down

0 comments on commit 905f5bf

Please sign in to comment.