Advertisement
Guest User

Untitled

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