Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import matplotlib.pyplot as plt
  4. import nmrglue
  5. import numpy as np
  6. import os
  7. import sys
  8.  
  9.  
  10. def getMaxIndex(pdata, x_ticks, position, epsilon=1.0):
  11.     indexes = np.where((x_ticks > position - epsilon) & (x_ticks < position + epsilon))[0]
  12.     return np.argmax(pdata[:,indexes].sum(axis=1))
  13.  
  14.  
  15. def calcMobility(angle, distance, bigDelta, gradPower, smallDelta):
  16.     # bigDelta - d20
  17.     # smallDelta - p30
  18.     return angle * distance * np.pi * 10 ** 8 / (bigDelta * (2.68 * 10 ** 8) * gradPower * 180 * smallDelta)
  19.  
  20.  
  21. def getXRange(params):
  22.     O1P = params['acqus']['O1']/params['acqus']['SFO1']
  23.     SW = params['acqus']['SW']
  24.  
  25.     Y_O1P = params['acqu2s']['O1']/params['acqu2s']['SFO1']
  26.     Y_SW = params['acqu2s']['SW']
  27.  
  28.     return O1P + SW / 2, O1P - SW / 2
  29.  
  30.  
  31. def getYRange(pdata, x_ticks):
  32.     y_sum = pdata.sum(axis=1)
  33.  
  34.     # calculcate deltaC based on known mobility
  35.     #c = calcMobility(angle=0.6875, distance=0.0377, bigDelta=(300 * 10 ** -3), gradPower=35 * 10 ** -3, smallDelta=(10 ** -3)) / 10
  36.     #max_index = np.argmax(y_sum)
  37.     #zero_index = getMaxIndex(pdata, x_ticks, 4.79)
  38.     #deltaC = (max_index - zero_index) / c
  39.     #print(deltaC)
  40.  
  41.     # use hardcoded deltaC when mobility is not known
  42.     zero_index = np.argmax(y_sum)
  43.     deltaC = 2.4882422732549014
  44.     return (0 - zero_index) / deltaC, (pdata.shape[0] - 1 - zero_index) / deltaC
  45.  
  46.  
  47. left, width = 0.1, 0.65
  48. bottom, height = 0.1, 0.65
  49. spacing = 0.005
  50. spacing = 0.03
  51.  
  52. countour = [left, bottom, width, height]
  53. spectrum_x = [left, bottom + height + spacing, width, 0.2]
  54. #spectrum_y = [left + width + spacing, bottom, 0.2, height]
  55.  
  56. plt.figure(figsize = (15,8))
  57.  
  58. countour = plt.axes(countour)
  59. countour.tick_params(direction='in', top=True, right=True)
  60. spectrum_x = plt.axes(spectrum_x)
  61. spectrum_x.tick_params(direction='in', labelbottom=False)
  62. #spectrum_y = plt.axes(spectrum_y)
  63. #spectrum_y.tick_params(direction='in', labelleft=False)
  64.  
  65. path = os.path.abspath(sys.argv[1] if len(sys.argv) == 2 else os.getcwd())
  66. params, pdata = nmrglue.fileio.bruker.read_pdata(dir=os.path.join(path, 'pdata', '1'))
  67.  
  68. x_min, x_max = getXRange(params)
  69. x_ticks = np.linspace(x_min, x_max, pdata.shape[1])
  70.  
  71. y_min, y_max = getYRange(pdata, x_ticks)
  72. y_ticks = np.linspace(y_min, y_max, pdata.shape[0])
  73.  
  74. X, Y = np.meshgrid(x_ticks, y_ticks)
  75.  
  76. levels = np.linspace(np.min(pdata), np.max(pdata), 40)
  77.  
  78. x_sum = pdata.sum(axis=0)
  79. #y_sum = pdata.sum(axis=1)
  80.  
  81. countour.contourf(X, Y, pdata, levels=levels[2:5])
  82. #countour.contour(X, Y, pdata, levels=20)
  83. countour.set_xlabel('Chemical shift, ppm')
  84. countour.set_xlim(x_min, x_max)
  85. countour.set_ylim(y_min, y_max)
  86. countour.set_ylabel('Electrophoretic Mobility (10 ** -8)')
  87.  
  88. spectrum_x.plot(x_ticks, x_sum)
  89. spectrum_x.set_xlim(x_min, x_max)
  90. spectrum_x.axis('off')
  91.  
  92. #spectrum_y.plot(y_sum, y_ticks)
  93. #spectrum_y.set_ylim(y_min, y_max)
  94. #spectrum_y.axis('off')
  95.  
  96. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement