def paste(self): rs = self.GetGridCursorRow() cs = self.GetGridCursorCol() clipboard = wx.TextDataObject() if wx.TheClipboard.Open(): wx.TheClipboard.GetData(clipboard) wx.TheClipboard.Close() else: return text = clipboard.GetText() idat = self.idata for tpos, line in enumerate(text.splitlines(), rs): if len(idat) == tpos: idat.append([None, None, None]) for rpos, cval in enumerate(line.split("\t"), cs): if rpos >= 3: break try: if rpos == 0: idat[tpos][0] = self.loc_get(atof(cval)) elif rpos == 1: idat[tpos][1] = atof(cval) else: idat[tpos][2] = cval except (ValueError, ZeroDivisionError): idat[tpos][rpos] = None self.show_idata()
def calculate_sq(self, gdata, plot): self.save_state() els = self.get_elements() sqd = {"Elements": els} # only flat \theta-\theta diffractometer is implementet yet exi = self.data.corr_intens() exq = self.data.get_qrange() add_curves = None cmode = self.calc_modes.GetSelection() psp, rho0, op_s, rc_n, rc_e, pspr = self.enables[cmode] if psp: dg_pol = self.pol_spin.GetValue() sqd["Degree of polynomial"] = dg_pol if rho0: sqd["At. dens."] = atof(self.rho0_ea.GetValue()) if op_s: sqd["Sectors"] = self.opt_sects.GetValue() if rc_n: sqd["R_c samps"] = self.rc_num.GetValue() if rc_e: sqd["R_c"] = atof(self.rc_ea.GetValue()) if pspr: sqd["dens. opt. start"] = self.ord_r_spin.GetValue() cmods = "clsc mix pcf pcfi pcfir pblk" sqd["Calculation mode"] = cmods.split()[cmode] if cmode == 0: rsq = sqc.norm_pcompt(exi, exq, sqd) elif 0 < cmode < 6: args = (sqd, ) if cmode == 1: dg_pol *= 2 titl = _("S(Q) by Stetsiv") msg = _("Calculating the structure factor " "by the Stetsiv method (%s)...") % sqd["Calculation mode"] args += (DlgProgressCallb(self.Parent, titl, msg, dg_pol, can_abort=True, cumulative=True), ) rsq, add_curves = sqc.calc_sq_Stetsiv(exq, exi, *args)[:2] gdata["SSF"] = (exq, rsq, sqd) plot_sq(self.internal, exq, rsq, sqd) if add_curves: plts = [] for crv in add_curves: plts.append((exq, crv, 1)) pdata = plot.set_data(PN_BCKGND, plts, r'$s,\, \AA^{-1}$', r'$I(q)/F^2(q)$', 'A^{-1}') pdata.discards.add("liq samp") info = [ "|-\n| %s\n| *\n| x^{%d}\n" % (loc.format("%g", j), i) for i, j in enumerate(reversed(sqd["BG coefs"])) ] info = u"".join(["{|\n"] + info + ["|}\n"]) pdata.set_info(info) else: plot.pop(PN_BCKGND)
def calculate_sq(self, gdata, plot): self.save_state() els = self.get_elements() sqd = {"Elements": els} # only flat \theta-\theta diffractometer is implementet yet exi = self.data.corr_intens() exq = self.data.get_qrange() add_curves = None cmode = self.calc_modes.GetSelection() psp, rho0, op_s, rc_n, rc_e, pspr = self.enables[cmode] if psp: dg_pol = self.pol_spin.GetValue() sqd["Degree of polynomial"] = dg_pol if rho0: sqd["At. dens."] = atof(self.rho0_ea.GetValue()) if op_s: sqd["Sectors"] = self.opt_sects.GetValue() if rc_n: sqd["R_c samps"] = self.rc_num.GetValue() if rc_e: sqd["R_c"] = atof(self.rc_ea.GetValue()) if pspr: sqd["dens. opt. start"] = self.ord_r_spin.GetValue() cmods = "clsc mix pcf pcfi pcfir pblk" sqd["Calculation mode"] = cmods.split()[cmode] if cmode == 0: rsq = sqc.norm_pcompt(exi, exq, sqd) elif 0 < cmode < 6: args = (sqd,) if cmode == 1: dg_pol *= 2 titl = _("S(Q) by Stetsiv") msg = _("Calculating the structure factor " "by the Stetsiv method (%s)...") % sqd["Calculation mode"] args += (DlgProgressCallb(self.Parent, titl, msg, dg_pol, can_abort=True, cumulative=True),) rsq, add_curves = sqc.calc_sq_Stetsiv(exq, exi, *args)[:2] gdata["SSF"] = (exq, rsq, sqd) plot_sq(self.internal, exq, rsq, sqd) if add_curves: plts = [] for crv in add_curves: plts.append((exq, crv, 1)) pdata = plot.set_data(PN_BCKGND, plts, r'$s,\, \AA^{-1}$', r'$I(q)/F^2(q)$', 'A^{-1}') pdata.discards.add("liq samp") info = ["|-\n| %s\n| *\n| x^{%d}\n" % (loc.format("%g", j), i) for i, j in enumerate(reversed(sqd["BG coefs"]))] info = u"".join(["{|\n"] + info + ["|}\n"]) pdata.set_info(info) else: plot.pop(PN_BCKGND)
def get_ses(self): strt = atof(self.start_ea.GetValue()) end = atof(self.end_ea.GetValue()) steps = int(self.steps_spin.GetValue()) if strt > end: strt, end = end, strt if strt == end: end += 1. i = self.internal i["grc_stsrang"] = steps i["grc_start"] = strt i["grc_end"] = end return strt, end, steps
def OnCellChange(self, evt): r = evt.GetRow() c = evt.GetCol() value = self.GetCellValue(r, c) try: if c == 0: self.idata[r][0] = self.loc_get(atof(value)) elif c == 1: self.idata[r][1] = atof(value) elif c == 2: self.idata[r][2] = value else: self.idata[r][3] = value == '1' except (ValueError, ZeroDivisionError): self.idata[r][c] = None
def save_state(self): inter = self.internal inter["rhorccalc_cutoff"] = atof(self.prev_cut_ea.GetValue()) inter["rhorccalc_parsamp"] = self.psamps_spin.GetValue() inter["rhorccalc_searsamp"] = self.ssamps_spin.GetValue() inter["rhorccalc_crude"] = self.tms_spin.GetValue() inter["rhorccalc_accur"] = self.tmsa_spin.GetValue() inter["rhorccalc_prang"] = self.pr_spin.GetValue()
def get_elements(self): lmns = [] pts = [] for lmn in self.elements_ea.GetValue().split(';'): spl = lmn.split() lmns.append(str(spl[0])) pts.append(atof(spl[1])) spts = sum(pts) if spts != 1.: pts = [i / spts for i in pts] return zip(lmns, pts)
def save_state(self): i = self.internal i["sqcalc_mode"] = int(self.calc_modes.GetSelection()) i["sqcalc_polrang"] = int(self.pol_spin.GetValue()) i["sqcalc_polrangrho"] = int(self.ord_r_spin.GetValue()) i["sqcalc_optsects"] = int(self.opt_sects.GetValue()) try: i["sqcalc_rc"] = atof(self.rc_ea.GetValue()) except ValueError: pass i["sqcalc_rc_num"] = int(self.rc_num.GetValue())
def get_gr(self, q, sq): intd = self.internal sqd = intd["data"]["SSF"][2] s0 = atof(self.s_0.GetValue()) drop_tail = self.drop_tail.GetValue() grd = dict(sqd) grd["S(0)"] = s0 grd["drop tail"] = drop_tail intd["drop tail"] = drop_tail rarr = np.linspace(*self.get_ses()) rho = self.get_rho0() intd["RDFd"] = {"rho0": rho, "sqd": grd, "q": q, "sq": sq} return rarr, sqc.calc_gr_arr(rarr, **intd["RDFd"])
def calc_bg(self): plts = [] if self.data: if self.data.x_axis != "q": x = np.sin(self.data.get_theta()) y = self.data.corr_intens() else: x = self.data.get_qrange() y = self.data.get_y() sigmul = atof(self.sigmul_ea.GetValue()) deg = self.bgpol_spin.GetValue() self.idat["bg_polrang"] = deg self.idat["bg_sigmul"] = sigmul self.bckgnd = (x, y) + calc_bg(x, y, deg, sigmul) plts.append((x, y, 1)) plts.append((x, self.bckgnd[2], 1)) plts.append((x, y - self.bckgnd[2], 1)) return self.bckgnd, plts
def test_text(self, text): if len(text) == 0: self.err_msg = _("Field in empty.") return False f2id = f2i.get_f2i_dict() for lmn in text.split(';'): spl = lmn.split() if len(spl) != 2: self.err_msg = _("Syntax error.") return False if not spl[0] in f2id: self.err_msg = _("Element %s not found.") % spl[0] return False try: elpart = atof(spl[1]) except ValueError: self.err_msg = _("Wrong type of float.") + "\n(%s)" % spl[1] return False if 0. >= elpart: self.err_msg = _("Part of element must be > 0.") return False return True
def calc_roho_rc(self, data, plot=None): if self.data is None: return sqd = {} sqd["Elements"] = tuple(self.get_elements()) exi = self.data.corr_intens() exq = self.data.get_qrange() c_tms = self.tms_spin.GetValue() a_tms = self.tmsa_spin.GetValue() p_rng = self.pr_spin.GetValue() sqd["Degree of polynomial"] = p_rng pars = self.psamps_spin.GetValue() sqd["R_c samps"] = pars sear = self.ssamps_spin.GetValue() prc = atof(self.prev_cut_ea.GetValue()) clb = DlgProgressCallb(self.Parent, _("Calc. of prox. at. dens."), _("Calculating proximately atomic density..."), (c_tms + a_tms) * (p_rng + 1), can_abort=True, cumulative=True) rho_col = [] rho = 1. sqd["Calculation mode"] = "pcfi" sqd["R_c"] = prc for i in range(c_tms): sqd["At. dens."] = rho sSQ, crvs, ks = sqc.calc_sq_Stetsiv(exq, exi, sqd, clb) if not clb: return bg0 = crvs[1][0] * ks rho, rcc = sqc.calc_rho_rc(exq, sSQ, bg0, pars, sear, prc) if not clb(1): return if plot is not None: rho_col.append((rho, rcc)) sqd["Calculation mode"] = "pblk" for i in range(a_tms): sqd["At. dens."] = rho sqd["R_c"] = rcc sSQ, crvs, ks = sqc.calc_sq_Stetsiv(exq, exi, sqd, clb) if not clb: return bg0 = crvs[1][0] * ks rho, rcc = sqc.calc_rho_rc(exq, sSQ, bg0, pars, sear, prc, rcc) if not clb(1): return if plot is not None: rho_col.append((rho, rcc)) self.save_state() if plot is not None: rhoa, rca = zip(*rho_col) its = np.arange(1, len(rca) + 1) plts = [(its, rhoa, 1), (its, rca, 2)] pldat = plot.set_data(PN_ADE, plts, _("Iteration"), _(r'At. dens., $\AA^{-3}$'), 'N') pldat.discards.add("liq samp") pldat.set_info(u"""density = %g (blue)\n cutoff = %g (green)\n """ % (rho, rcc)) pldat.journal.log("calc_roho_rc: \\rho: %g; r_c%g: %g" % (rho, rcc)) plot.plot_dataset(PN_ADE) return rho, rcc
def get_rho0(self): rho = atof(self.rho0_ea.GetValue()) self.rho0 = rho return rho
def calc_roho_rc(self, data, plot=None): if self.data is None: return sqd = {} sqd["Elements"] = tuple(self.get_elements()) exi = self.data.corr_intens() exq = self.data.get_qrange() c_tms = self.tms_spin.GetValue() a_tms = self.tmsa_spin.GetValue() p_rng = self.pr_spin.GetValue() sqd["Degree of polynomial"] = p_rng pars = self.psamps_spin.GetValue() sqd["R_c samps"] = pars sear = self.ssamps_spin.GetValue() prc = atof(self.prev_cut_ea.GetValue()) clb = DlgProgressCallb( self.Parent, _("Calc. of prox. at. dens."), _("Calculating proximately atomic density..."), (c_tms + a_tms) * (p_rng + 1), can_abort=True, cumulative=True) rho_col = [] rho = 1. sqd["Calculation mode"] = "pcfi" sqd["R_c"] = prc for i in range(c_tms): sqd["At. dens."] = rho sSQ, crvs, ks = sqc.calc_sq_Stetsiv(exq, exi, sqd, clb) if not clb: return bg0 = crvs[1][0] * ks rho, rcc = sqc.calc_rho_rc(exq, sSQ, bg0, pars, sear, prc) if not clb(1): return if plot is not None: rho_col.append((rho, rcc)) sqd["Calculation mode"] = "pblk" for i in range(a_tms): sqd["At. dens."] = rho sqd["R_c"] = rcc sSQ, crvs, ks = sqc.calc_sq_Stetsiv(exq, exi, sqd, clb) if not clb: return bg0 = crvs[1][0] * ks rho, rcc = sqc.calc_rho_rc(exq, sSQ, bg0, pars, sear, prc, rcc) if not clb(1): return if plot is not None: rho_col.append((rho, rcc)) self.save_state() if plot is not None: rhoa, rca = zip(*rho_col) its = np.arange(1, len(rca) + 1) plts = [(its, rhoa, 1), (its, rca, 2)] pldat = plot.set_data(PN_ADE, plts, _("Iteration"), _(r'At. dens., $\AA^{-3}$'), 'N') pldat.discards.add("liq samp") pldat.set_info(u"""density = %g (blue)\n cutoff = %g (green)\n """ % (rho, rcc)) pldat.journal.log("calc_roho_rc: \\rho: %g; r_c%g: %g" % (rho, rcc)) plot.plot_dataset(PN_ADE) return rho, rcc
def get_elements(self): for lmn in self.elements_ea.GetValue().split(';'): spl = lmn.split() yield str(spl[0]), atof(spl[1])