Exemplo n.º 1
0
def plot_from_context(context):
  do_plot, x, y, options, p = context
  if do_plot:
    if p is None:
      master = options.pop('master', None)
      title = options.pop('title', '')
      if master is None:
        master = Tk.Toplevel()
        master.title(title)
      figsize = options.pop('figsize', None)
      if x is None:
        p = pygmyplot.xy_plot(y, master=master, figsize=figsize)
      else:
        p = pygmyplot.xy_plot(x, y, master=master, figsize=figsize)
      options['figsize'] = figsize
      options['title'] = title
      options['master'] = master
    else:
      # xlim = p.axes.get_xlim()
      # ylim = p.axes.get_ylim()
      p.plot(x, y)
      # p.axes.set_xlim(*xlim)
      # p.axes.set_ylim(*ylim)
      # p.refresh()
      p.zoom_all()
      p.refresh()
    if 'label' in options:
      p.axes.legend()
    xlim = options.pop('xlim', None)
    if xlim is None:
      xlim = p.axes.get_xlim()
    p.axes.set_xlim(xlim)
    # trying to change number font
    p.canvas.show()
    options['xlim'] = xlim
    return p
Exemplo n.º 2
0
def powder_main():
  if len(sys.argv) != 2:
    usage()
  else:
    y = yaml.load(open(sys.argv[1]).read())

  uicfg = y['general']
  config = y['simulation']
  experiment = y['experiment']
  pltcfg = y['plot']

  powderx_version = __version__.rsplit(".", 1)[0]
  if uicfg['powderx_version'] != str(powderx_version):
    tplt = "Config file should be version '%s'."
    raise VersionError(tplt % powderx_version)

  log_level = getattr(logging, uicfg['verbosity'])
  logger = phyles.basic_logger(__name__, level=log_level)

  tk = TK.Tk()

  # logger.info("Reading mtz: '%s'", config['mtz_name'])
  # mtz_file = mtz.object(config['mtz_name'])

  # logger.info("Constructing Miller dict from mtz.")
  # mtz_miller_dict = mtz_file.as_miller_arrays_dict()
  # mtz_key = tuple(config['mtz_column'])
  # sf_mtz = mtz_miller_dict[mtz_key]

  logger.info("Reading pdb: '%s'", config['pdb_name'])
  pdb_inp = pdb.input(file_name=config['pdb_name'])

  logger.info("Creating structure factors from pdb.")
  structure = pdb_inp.xray_structure_simple()
  sf_pdb = structure.structure_factors(d_min=config['d_min']).f_calc()

  ec_x = config.get("extinction_correction_x", None)

  if ec_x is not None:
    # sf_mtz = sf_mtz.apply_shelxl_extinction_correction(ec_x,
    #                                       experiment['WAVELENGTH'])
    sf_pdb = sf_pdb.apply_shelxl_extinction_correction(ec_x,
                                          experiment['WAVELENGTH'])

  # logger.info("Plotting powder from mtz: '%s'", config['mtz_name'])
  # p = plot_powder(sf_mtz, config, pltcfg, experiment, master=tk)

  # logger.info("Plotting powder from pdb: '%s'", config['pdb_name'])
  # p = plot_powder(sf_pdb, config, pltcfg, experiment, master=tk)

  logger.info("Creating integrated intensity pattern from pdb.")
  pattern = integrated_intensity(sf_pdb,
                       experiment['WAVELENGTH'],
                       config['d_max'],
                       config['d_min'],
                       v=config['v'],
                       w=config['w'],
                       B=config['B'],
                       apply_Lp = config['apply_Lp'],
                       pattern_bins=config['pattern_shells'],
                       peakwidths=config['peak_widths'],
                       bin_reflections=config['combine_reflections'])

  p = pygmyplot.xy_plot(numpy.degrees(pattern[0]),
                        pattern[1], master=tk)
  p.axes.set_xlabel("$2\\theta$ (degrees)")
  p.axes.set_ylabel("Integrated Intensity")

  adj = {"left": pltcfg['left'],
         "right": pltcfg['right'],
         "top": pltcfg['top'],
         "bottom": pltcfg['bottom'],
         "wspace": None,
         "hspace": None}

  _radialx.plot_adjust(p, adj)

  tk.title(pltcfg['window_name'])

  p.refresh()

  _radialx.write_spectrum(config['pattern_name'],
                          config['pdb_name'],
                          pattern[0], pattern[1], False)

  TK.Button(tk, text="Quit", command=tk.destroy).pack()
  tk.mainloop()
Exemplo n.º 3
0
def plot_powder(sf, config, pltcfg, experiment, master=None,
                                                plot=None):
  """
  Returns an instance of :class:`pygmyplot.MyXYPlot` with intensity per
  detector area plotted over ``config['d_max']`` - ``config['d_min']``.

  Args:
    `sf`:
       structure factors as a :class:`cctbx.miller.array`
    `pltcfg`:
       mapping object with keys of
         - ``plot_points``: number of bins for the plot
         - ``n_ticks``: number of ticks for the x-axis
    `config`:
       mapping object with keys of
         - ``d_max``: maximum d-spacing in Angstroms
         - ``d_min``: minimum d-spacing in Angstroms
    `experiment`:
       mapping object with keys of
         - ``'WAVELENGTH'``: x-ray wavelength Angstroms
         - ``'DISTANCE'``: detector distance in mm
    `master`:
       Tkinter widget
    `plot`:
       a :class:`pygmyplot.MyPlot` to which the plot is added
  """
  if (master is not None) and (plot is not None):
    msg = "Either or both of master and plot should be None."
    raise GUIError(msg)

  max_min = sf.d_max_min()

  d_max = config['d_max']
  d_min = config['d_min']
  plot_bins = pltcfg['plot_points']
  n_ticks = pltcfg['x_ticks']

  I = sf.intensities()
  borders = _radialx.make_borders_rho(plot_bins, d_max, d_min, experiment)
  binner = Binner(I, borders, experiment)

  values = getattr(binner, config['values'])()
  x_labels = [("%4.1f" % c) for c in binner.centers_res]

  tick_step = int(math.floor(plot_bins / n_ticks))

  if plot is None:
    plot = pygmyplot.xy_plot(binner.centers, values, master=master)
  else:
    plot.plot(binner.centers, values)

  plot.axes.set_xticks(binner.centers[::tick_step])
  plot.axes.set_xticklabels(x_labels[::tick_step])
  plot.axes.set_xlabel('Resolution ($\\AA$)')
  plot.axes.set_ylabel('intensity')


  adj = {"left": pltcfg['left'],
         "right": pltcfg['right'],
         "top": pltcfg['top'],
         "bottom": pltcfg['bottom']}

  _radialx.plot_adjust(plot, adj)

  plot.canvas.draw()

  return plot