def setDataForPlot(self): '''Assembles the data for plotting, calculates the spectrum, then emits''' # Assemble values omega = self.scale.getDomain() npeaks = self.numpeaks.getNumPeaks() k = self.rate.getConvertedRate() Z = self.exchange.getMatrix() self.oldParams = self.peak.getParams() vib, GL, GG, h = self.oldParams # Don's plot if there is some error if k == 0 or k is None: return elif npeaks != len(vib) or isnan(sum(vib)): return elif npeaks != len(GL) or isnan(sum(GL)): return elif npeaks != len(GG) or isnan(sum(GG)): return elif npeaks != len(h) or isnan(sum(h)): return elif npeaks != len(Z): return elif len(omega) == 0: return else: self.hasPlot = True # Calculate spectrum I, self.newParams = spectrum(Z, k, vib, GL, GG, h, omega) # Send spectrum to plotter and new parameters to peak self.plotSpectrum.emit(omega, I) self.peak.setNewParams(*self.newParams) # Store data for later self.rateParams = self.rate.getParams() self.exchangeParams = self.exchange.getParams(npeaks) self.limits = self.scale.getScale()
def run_non_interactive(cmd_line_args): '''Driver to calculate the spectra non-interactively (i.e. from the command line). ''' # Read in the input file that is given try: args = read_input(cmd_line_args.input_file) except (OSError, IOError) as e: print(str(e), file=stderr) # An error occurred when locating the file return 1 except ReaderError as r: print(str(r), file=stderr) # An error occurred when reading the file return 1 # Generate the Z matrix Z = ZMat(len(args.num), args.exchanges, args.exchange_rates, args.symmetric_exchange) # Generate the frequency domain omega = arange(args.xlim[0]-10, args.xlim[1]+10, 0.5) # Calculate the spectrum try: I_omega, new_params = spectrum(Z, args.k, args.vib, args.Gamma_Lorentz, args.Gamma_Gauss, args.heights, omega ) except SpectrumError as se: print(str(se), file=stderr) return 1 # Make a tuple of the old parameters old_params = (args.vib, args.Gamma_Lorentz, args.Gamma_Gauss, args.heights) # Normalize the generated data I_omega = normalize(I_omega) # Repeat for the raw data if given. Clip according to the xlimits if args.raw is not None: args.raw = clip(args.raw, args.xlim) args.raw[:,1] = normalize(args.raw[:,1]) # Plot the data or write to file if cmd_line_args.data: try: write_data(omega, I_omega, cmd_line_args.data) except (IOError, OSError) as e: print(str(e), file=stderr) return 1 else: print('Data written to file {0}'.format(cmd_line_args.data)) return 0 elif cmd_line_args.script: return save_script(omega, I_omega, args.raw, args.xlim, args.reverse, old_params, new_params, cmd_line_args.script, msg=True) elif cmd_line_args.params: return numerics(old_params, new_params, stdout) else: return plot(args, omega, I_omega)