Skip to content

Commit

Permalink
2nd initial commit to make it work in the first place
Browse files Browse the repository at this point in the history
  • Loading branch information
Flackermann committed Jul 22, 2020
1 parent dd762d3 commit 4d140e4
Show file tree
Hide file tree
Showing 68 changed files with 1,887 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Version 0.0.1
- The subpkg Measurement was added to the build

Version 0.0.0
- SpecModel.set_mathematical_constraints() now resets all mathematical constraints before new assignment, which can be deactivated by setting reset=False

1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 setup.py sdist bdist_wheel
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 15 additions & 1 deletion build/lib/eNMRly/Phasefitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,29 @@ def __init__(self, n_peaks, verbose=False, model='Lorentz'):
if verbose:
self.params.pretty_print()

def set_mathematical_constraints(self, expr):
def set_mathematical_constraints(self, expr=None, reset=True):
"""
expr: mathematical expression without whitespace
reset: will reset all mathematical constraints
example 1:
ph0 should be always equal to ph1
set_mathematical_constraint('ph0=ph1')
example 2:
ph0 should be always ph1 - 90 degree
set_mathematical_constraint('ph0=ph1-90')
"""

if (expr == None) and (reset):
print('model without constraints')
return

elif reset:
for i in self.params:
self.params[i].expr = None
print('constraints were reset before new assignment')

if type(expr) == list:
for e in expr:
a = e.split('=')
Expand All @@ -318,6 +330,8 @@ def set_mathematical_constraints(self, expr):
a = expr.split('=')
self.params[a[0]].expr = a[1]



def set_initial_values(self, par, val):
'''
takes single parameter par or list of parameters
Expand Down
6 changes: 5 additions & 1 deletion build/lib/eNMRly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#__all__ = ['Measurement', 'Phasefitting', 'MOSY']
__all__ = ['SpecModel']
from .Phasefitting import SpecModel
from .MOSY import MOSY
from .Measurement import Pavel as Import_eNMR_Measurement
print('%s imported'%__name__)

Binary file added dist/eNMRly-0.0.0-py3-none-any.whl
Binary file not shown.
Binary file removed dist/eNMRly-0.0.0-py3.8.egg
Binary file not shown.
Binary file modified dist/eNMRly-0.0.0.tar.gz
Binary file not shown.
19 changes: 0 additions & 19 deletions eNMRly.egg-info/SOURCES.txt

This file was deleted.

Binary file removed eNMRly/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions eNMRly.egg-info/PKG-INFO → eNMRpy.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: eNMRly
Version: 0.0.0
Name: eNMRpy
Version: 0.0.1
Summary: nmrglue-based package for the import and analysis of electrophoretic NMR-data
Home-page: UNKNOWN
Author: Florian Ackermann
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
eNMRly
eNMRpy
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added eNMRpy/GUI/module/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
179 changes: 179 additions & 0 deletions eNMRpy/Measurement/Emma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
## coding: utf-8
# This is the eNMR class. THE library for the evaluation of bruker-eNMR-spectra based on the VC-PowerSource of the
# Schönhoff working group.
# It works with the volt-increment method which calculates the respective voltage with the VC-list
# Further Implementation can be asked for at [email protected]



class eNMR_Emma(eNMR_Measurement):
#'''
#This is the subsubclass of Masurement() and subclass of eNMR_Methods specialised to process data obtained from the experimental Schönhoff set-up

#path:
#relative or absolute path to the measurements folder
#measurement:
#the to the experiment corresponding EXPNO
#alias:
#Here you can place an individual name relevant for plotting. If None, the path is taken instead.
#Uink:
#voltage increment. Usually extracted from the title file if defined with e.g. "Uink = 10V"
#If Uink cannot be found or is wrong it can be entered manually during the data import.
#The voltage list is calculated from the voltage increment and the vc list when the incrementation loop is used in the pulse program
#dependency:
#'U': voltage dependent eNMR measurement
#'G': fieldgradient dependent eNMR measurement

#linebroadening:
#setting a standard-value for the linebroadening.
#'''
def __init__(self, path, expno, Uink=None, dependency="U", alias=None, linebroadening=0.5, electrode_distance=2.2e-2):
Measurement.__init__(self, path, expno, linebroadening=linebroadening, alias=alias)
self.dependency = dependency.upper()

self._x_axis = {"U": "U / [V]",
"G": "g in T/m",
"I": "I / mA",
'RI': 'RI / V'
}[self.dependency.upper()]

#self._x_axis = {"G": "g in T/m",
#"U": "U / [V]"}[self.dependency.upper()]

self.difflist = pd.read_csv(self.dateipfad+"/difflist",
names=["g in T/m"])*0.01

self.vcList = pd.DataFrame()

if self.dic['acqus']['PULPROG'][-3:] == 'var':
polarity = 1
print('this is a regular measurement! (non-_pol)')
elif self.dic['acqus']['PULPROG'][-3:] == 'pol':
polarity = -1
print('this is a _pol-Measurement!')
else:
print("no var or pol PULPROG")

if dependency.upper() == "U":
try:
# takes the title page to extract the volt increment
title = open(self.dateipfad+"/pdata/1/title").read()
# gets the voltage increment using a regular expression
#uimport = findall('[U|u]in[k|c]\s*=?\s*\d+', title)[0]
uimport = findall('[U|u]in[k|c]\s*=+\s*\d+', title)[0]
self.uInk = int(findall('\d+', uimport)[0])
except ValueError:
print('no volt increment found\nyou may want to put it in manually')
self.uInk = Uink
except IndexError:
print('No Uink found! May not be an eNMR experiment.')
self.uInk = Uink

self.vcList["U / [V]"] = [i*self.uInk*polarity for i in range(len(self.difflist))]

elif dependency.upper() == "G":
try:
# takes the title page to extract the volt increment
title = open(self.dateipfad+"/pdata/1/title").read()
# gets the voltage increment using a regular expression
uimport = findall('[U|u]\s*=?\s*\d+', title)[0]
self.uInk = int(findall('\d+', uimport)[0])

except ValueError:
print('no volt increment found\nyou may want to put it in manually')
self.uInk = Uink
except IndexError:
print('No Uink found! May not be an eNMR experiment.')
self.uInk = Uink # Uinktext

#if Uink is not None:
#self.uInk = Uink

self.vcList["U / [V]"] = [self.uInk*polarity for i in range(len(self.difflist))]
#self.vcList["U / [V]"] = [self.vcList["vc"][n]/2*self.uInk if self.vcList["vc"][n] % 2 == 0
#else (self.vcList["vc"][n]+1)/2*self.uInk*-1
#for n in range(len(self.data[:, 0]))]

#if self.dependency.upper() == "U":
#try:
#self.vcList = pd.read_csv(self.dateipfad+"/vclist",
#names=["vc"]).loc[:len(self.data[:, 0])-1]

#except:
#print("There is a Problem with the VC-list or you performed a gradient dependent measurement")
#elif self.dependency.upper() == "G":
#self.vcList = pd.DataFrame(np.ones((len(self.data[:, 0]), 1)),
#columns=["vc"])
#else:
#print("The dependency is not properly selected, try again!")

#self.difflist = pd.read_csv(self.dateipfad+"/difflist",
#names=["g in T/m"])*0.01

#if Uink is not None:
#self.uInk = Uink

#self.vcList["U / [V]"] = [self.vcList["vc"][n]/2*self.uInk if self.vcList["vc"][n] % 2 == 0
#else (self.vcList["vc"][n]+1)/2*self.uInk*-1
#for n in range(len(self.data[:, 0]))]

# try to open phase data, otherwise create new
try:
self.eNMRraw = pd.read_csv(self.path+"phase_data_"+self.expno+".csv",
index_col=0, sep=" ")
# --> update voltage list
self.eNMRraw["U / [V]"] = self.vcList["U / [V]"]
except:
print("eNMRraw was missing and is generated")
self.vcList["ph0"] = np.zeros(len(self.data.real[:, 0]))
self.eNMRraw = self.vcList
finally:
self.eNMRraw["g in T/m"] = self.difflist

self.p1 = self.dic["acqus"]["P"][1]
self.d1 = self.dic["acqus"]["D"][1]

try:
# import of diffusion parameters for newer Spectrometers
import xml.etree.ElementTree as etree
diffpar = etree.parse(self.dateipfad+'/diff.xml')
root = diffpar.getroot()
self.Delta = float(root.findall('DELTA')[0].text)*1e-3
self.delta = float(root.findall('delta')[0].text)*1e-3 # it should be read as in microseconds at this point due to bruker syntax
print('The diffusion parameters were read from the respectie .XML!')
except:
# determination of the diffusion parameters for Emma
self._d2 = self.dic["acqus"]["D"][2]
self._d5 = self.dic["acqus"]["D"][5]
self._d9 = self.dic["acqus"]["D"][9]
self._d11 = self.dic["acqus"]["D"][11]
self._p19, self._p18, self._p17 = self.dic["acqus"]["P"][19],\
self.dic["acqus"]["P"][18],\
self.dic["acqus"]["P"][17]
print('That did not work. Your data is from an old spectrometer!')
# calculating usable parameters
self.delta = self._p17+self._p18
self._Delta_1 = 0.001*(self._p17*2+self._p18)+(self._d2+self._d9+self._d5+self._d11)*1000+0.001*self.p1+self._d11
self._Delta_2 = 0.001*(self._p17*2+self._p18)+(self._d2+self._d9+self._d5+self._d11)*1000+0.001*self.p1*2
self._spoiler = (self._d11+self._p17+self._p19+self._p17)*0.001+self._d2*1000
self.Delta = self._Delta_1+self._Delta_2+2*self._spoiler
self.Delta *=1e-3
self.delta *=1e-6


# Elektrodenabstand in m
self.d = electrode_distance
self.g = self.eNMRraw["g in T/m"][0]

def __add__(self, other):

for obj in [self, other]:
for k in obj.eNMRraw.columns:
if k[:2] == 'ph':
obj.eNMRraw[k] -= obj.eNMRraw.loc[0, k]
print('%s normalized to 0V'%k)
else:
pass
self.eNMRraw = self.eNMRraw.append(other.eNMRraw)
self.eNMRraw.sort_values('U / [V]', inplace=True)
return self
Loading

0 comments on commit 4d140e4

Please sign in to comment.