def spectrum_cb(self, name): spectrum = sputil.name_to_spectrum(name, self.session) if spectrum and spectrum.dimension == 2: for a in range(2): self.matrix_size.variables[a].set(spectrum.data_size[a]) self.save_path.set(spectrum.data_path + '.corma')
def spectrum_cb(self, name): spectrum = sputil.name_to_spectrum(name, self.session) if spectrum == None: return if spectrum.dimension == 3: self.w3_range_widget.pack(side='left', anchor='w') self.line_format = '%20s %5s %7s %s' else: self.w3_range_widget.pack_forget() self.line_format = '%15s %5s %7s %s' default_ppm_range = {'1H': .02, '13C': .2, '15N': .2} for a in range(spectrum.dimension): nucleus = spectrum.nuclei[a] if default_ppm_range.has_key(nucleus): ppm_range = default_ppm_range[nucleus] else: ppm_range = .02 self.ppm_range[a].set('%.2f' % ppm_range)
def spectrum_cb(self, name): spectrum = sputil.name_to_spectrum(name, self.session) if spectrum == None: return if spectrum.dimension == 3: self.w3_range_widget.pack(side = 'left', anchor = 'w') self.line_format = '%20s %s %7s %s' else: self.w3_range_widget.pack_forget() self.line_format = '%15s %s %7s %s' default_ppm_range = {'1H':.02, '13C':.2, '15N':.2} for a in range(spectrum.dimension): nucleus = spectrum.nuclei[a] if default_ppm_range.has_key(nucleus): ppm_range = default_ppm_range[nucleus] else: ppm_range = .02 self.ppm_range[a].set('%.2f' % ppm_range)
'15380') # this bmrb code is GB1 from Rienstra group elif idx == 2: # SHIFTX reference_shift = \ s.show_inputdialog('SHIFTX2', 'Paste SHIFTX2 CSV URL path or drop the file.', 'http://www.shiftx2.ca/wkdir/1611508737/2KQ4.cs') # this shiftx2 url is my prediction with 2KQ4 PDB (also GB1) else: # use pacsy chemical shift database prediction (default) reference_shift = 'pacsy' # use existing assignments use_resonances = True # spectrum to be simulated from sputil import name_to_spectrum spec = name_to_spectrum(spec_name, s) if spec == None: s.show_message('Error', 'Spectrum is not set properly.') raise SystemExit exp_list = ['2D-NCA', '2D-NCACB', '2D-NCO', '2D-CC', 'NCACB', 'NCACX', 'NCACO', 'NCOCA', 'NCOCACB', 'NCOCX', 'CANCO', 'CAN(CO)CX'] if spec.dimension == 2: avail_exp_list = exp_list[0:4] elif spec.dimension == 3: avail_exp_list = exp_list[4:] else: s.show_message('Error', '4D spectrum is not set supported.') raise SystemExit idx = s.show_selectionexdialog('Experiment',
# To run this script: # In Poky Notepad, # File -> Run Python Module # # import numpy as np import nmrglue as ng from skimage.restoration import denoise_tv_bregman from sputil import name_to_spectrum # POKY libraries import __main__ s = __main__.main_session specname = s.show_spectrumselectiondialog('Select a spectrum', 0) sp = name_to_spectrum(specname, s) if sp == None: raise SystemError import os.path noisy_path = s.save_filedialog('Provide a name for saving the noisy spectrum', 'UCSF (*.ucsf);; Any (*)', os.path.dirname(sp.data_path)) if noisy_path == '': raise SystemError denoise_path = s.save_filedialog( 'Provide a name for saving the de-noised spectrum', 'UCSF (*.ucsf);; Any (*)', os.path.dirname(sp.data_path))
return a * np.exp(-1 * x / b) from sputil import name_to_spectrum, sort_peaks_by_assignment import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit from matplotlib import use as matplotlib_use matplotlib_use('TkAgg') # (time) parameters xdataT1 = np.array(list(map(lambda sp: sp[1], T1_spec_list))) xdataT2 = np.array(list(map(lambda sp: sp[1], T2_spec_list))) # get spectrum instances first spT1_list = list(map(lambda sp: name_to_spectrum(sp[0], s), T1_spec_list)) spT2_list = list(map(lambda sp: name_to_spectrum(sp[0], s), T2_spec_list)) if None in spT1_list: none_name = T1_spec_list[spT1_list.index(None)][0] print('T1 experiment (' + none_name + ') does not exist in your spectrum list.') raise SystemExit if None in spT2_list: none_name = T2_spec_list[spT2_list.index(None)][0] print('T2 experiment (' + none_name + ') does not exist in your spectrum list.') raise SystemExit
# Exclude from cond_list using excl_cond_list cond_list = [x for x in cond_list if x not in excl_cond_list] # define function for making ROI list # this can be replaced by custom definition like above # we can use view name. we do not cluster by view names here # however, it can be considered to make a rule to do that. def make_ROIs(spec): ROI_list = [] for view in s.project.view_list(): if view.spectrum == spec and view.name != spec.name: ROI_list.append([view.name, view.name]) return ROI_list # for unit conversion ref_spec = name_to_spectrum(ref_specname, s) ppm_per_pt = (ref_spec.spectrum_width[0] / (ref_spec.data_size[0] - 1), ref_spec.spectrum_width[1] / (ref_spec.data_size[1] - 1)) # define function for boxing integration # spec is a spectrum to analyze from itertools import product def box_sum(spec, region): npoints = (int((region[1][0] - region[0][0]) / ppm_per_pt[0]), int((region[1][1] - region[0][1]) / ppm_per_pt[1])) it_list = list(product(range(npoints[0]), range(npoints[1]))) hts = [] for i in range(npoints[0]): x = region[1][0] - ppm_per_pt[0] * i for j in range(npoints[1]):
exp_func = t_exp_func #exp_func = sea_exp_func # if sea-hsqc experiments from sputil import name_to_spectrum import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit from matplotlib import use as matplotlib_use matplotlib_use('TkAgg') # (time) parameters xdata = np.array(list(map(lambda sp: sp[1], spec_list))) # get spectrum instances first sp_list = list(map(lambda sp: name_to_spectrum(sp[0], s), spec_list)) if None in sp_list: none_name = spec_list[sp_list.index(None)][0] print(none_name + ' does not exist in your spectrum list.') raise SystemExit # collect reference peaks and positions from the first spectrum # assignment needed! ref_peaks = sp_list[0].peak_list() # ref_peaks = sp_list[0].selected_peaks() # if only selected peaks preferred # sort peaks by assignment from sputil import sort_peaks_by_assignment sorted_peaks = sort_peaks_by_assignment(ref_peaks, False)
outName = s.save_filedialog('Save your new restraint file as...', 'DIANA UPL file (*.upl);; XPLOR TBL file (*.tbl);; Any (*)', '') # Processing start from sputil import name_to_spectrum, sort_peaks_by_assignment, parse_assignment_entirely import numpy as np A_dict = {'C': 'CYS', 'D': 'ASP', 'S': 'SER', 'Q': 'GLN', 'K': 'LYS', 'I': 'ILE', 'P': 'PRO', 'T': 'THR', 'F': 'PHE', 'N': 'ASN', 'G': 'GLY', 'H': 'HIS', 'L': 'LEU', 'R': 'ARG', 'W': 'TRP', 'A': 'ALA', 'V':'VAL', 'E': 'GLU', 'Y': 'TYR', 'M': 'MET'} import nomenclature upl_list = [] for sp in spec_list: spec = name_to_spectrum(sp, s) if spec == None: print('%s spectrum does not exist.' % (sp)) raise SystemError dMin, dMax = 10**13, -10**13 peaks = spec.spectrum().peak_list() if len(peaks) == 0: continue peak_list = [] for peak in peaks: nuc = spec.nuclei freq = peak.frequency if peak.is_assigned == 0 or peak.data_height == None: continue if no_diagonal and abs(freq[0] - freq[1]) < res[nuc[0]]: continue
print('------------------------------------------------------') import __main__ s = __main__.main_session proj = s.project # Parameters ref_spec_name = s.show_spectrumselectiondialog('Reference spectrum', 0).strip() noe_spec_name = s.show_spectrumselectiondialog('NOE spectrum', 0).strip() only_selected = False # Use all assigned peaks if False error_bar = True # Draw error bar if True # Processing start from sputil import name_to_spectrum, sort_peaks_by_assignment ref_spec = name_to_spectrum(ref_spec_name, s) noe_spec = name_to_spectrum(noe_spec_name, s) if ref_spec == None: print('Reference spectrum name %s is wrong.' % ref_spec_name) raise SystemExit if noe_spec == None: print('NOE spectrum name %s is wrong.' % ref_spec_name) raise SystemExit # collect peaks and sort by number temp_peaks = [] for p in ref_spec.peak_list(): if only_selected and p.selected == 0: continue if None not in p.resonances() and p.is_assigned == 1:
# To run this script: # In Poky Notepad, # File -> Run Python Module # # import numpy as np import nmrglue as ng from sputil import name_to_spectrum # POKY libraries import __main__ s = __main__.main_session specname = s.show_spectrumselectiondialog('Select spectrum one', 0) sp = name_to_spectrum(specname, s) if sp == None: raise SystemError specname2 = s.show_spectrumselectiondialog('Select spectrum two', 0) sp2 = name_to_spectrum(specname2, s) if sp2 == None: raise SystemError scale_offset = np.array(sp.scale_offset) - np.array(sp2.scale_offset) import os.path new_path = s.save_filedialog('New spectrum name', 'UCSF (*.ucsf);; Any (*)', os.path.dirname(sp.data_path))
def spectrum(self): return sputil.name_to_spectrum(self.get(), self.session)