Ejemplo n.º 1
0
  def place_peaks(self, spectrum):
    
    hc_axes = pyutil.order(('1H', '13C'), spectrum.nuclei)
    if spectrum.dimension != 2 or hc_axes == None:
      self.progress_report('Spectrum must 2D with H and C axes.')
      return

    molecule = spectrum.molecule
    condition = spectrum.condition
    self.stoppable_loop('resonances', 50)
    for rH in condition.resonance_list():
      self.check_for_stop()
      if rH.atom.nucleus == '1H':
        catom = atoms.attached_heavy_atom(rH.atom, molecule)
        if catom and catom.nucleus == '13C':
          rC = condition.find_resonance(catom)
          if rC:
            assignment = pyutil.permute((rH, rC), hc_axes)
            if not spectrum.find_peak(assignment):
              freq = pyutil.permute((rH.frequency, rC.frequency), hc_axes)
              pos = sputil.alias_onto_spectrum(freq, spectrum)
              peak = spectrum.place_peak(pos)
              peak.assign(hc_axes[0], rH.group.name, rH.atom.name)
              peak.assign(hc_axes[1], rC.group.name, rC.atom.name)
              if freq != pos:
                peak.alias = pyutil.subtract_tuples(freq, pos)
              peak.show_assignment_label()
Ejemplo n.º 2
0
    def move_peak_onto_spectrum(self, peak):

        freq = peak.frequency
        pos = sputil.alias_onto_spectrum(freq, peak.spectrum)
        if pos != freq:
            peak.position = pos
            peak.alias = pyutil.subtract_tuples(freq, pos)
Ejemplo n.º 3
0
  def peak_strips(self, peak, spectra_3d):

    peak_xyz_axes = self.peak_strip_axes(peak, spectra_3d)
    if peak_xyz_axes == None:
      return []

    paX, paY, paZ = peak_xyz_axes
    if paY == None:
      xyz_freq = (peak.frequency[paX], 0, peak.frequency[paZ])
    else:
      xyz_freq = pyutil.permute(peak.frequency, peak_xyz_axes)

    nuclei = peak.spectrum.nuclei
    xz_nuclei = (nuclei[paX], nuclei[paZ])

    label = self.peak_strip_label(peak, paX, paZ)
    
    strips = []
    for spectrum in spectra_3d:
      xyz_axes = self.xyz_axes(spectrum)
      if xyz_axes:
        aX, aY, aZ = xyz_axes
        if (spectrum.nuclei[aX], spectrum.nuclei[aZ]) == xz_nuclei:
          if self.spectrum_label:
            label = spectrum.name + '\n' + label
          center = pyutil.unpermute(xyz_freq, xyz_axes)
          center = sputil.alias_onto_spectrum(center, spectrum)
          strip = self.spectrum_strip(spectrum, xyz_axes, center, label)
          strips.append(strip)
          label = '\n\n'

    return strips
Ejemplo n.º 4
0
  def move_peak_onto_spectrum(self, peak):

    freq = peak.frequency
    pos = sputil.alias_onto_spectrum(freq, peak.spectrum)
    if pos != freq:
      peak.position = pos
      peak.alias = pyutil.subtract_tuples(freq, pos)
Ejemplo n.º 5
0
  def center_on_point(self, spectrum, point):

    view_to_center = self.view_to_center
    if view_to_center:
      center = self.map_point(spectrum, point,
                              view_to_center.spectrum, view_to_center.center)
      center = sputil.alias_onto_spectrum(center, view_to_center.spectrum)
      view_to_center.center = center
Ejemplo n.º 6
0
  def goto_peak_cb(self, event):

    list_data = self.peak_list.event_line_data(event)
    if self.is_assignment(list_data):
      epeak, dpeak = list_data
      sputil.show_peak(dpeak)
    elif self.is_position(list_data):
      spectrum, freq = list_data
      pos = sputil.alias_onto_spectrum(freq, spectrum)
      sputil.show_spectrum_position(spectrum, pos)
Ejemplo n.º 7
0
    def goto_peak_cb(self, event):

        list_data = self.peak_list.event_line_data(event)
        if self.is_assignment(list_data):
            epeak, dpeak = list_data
            sputil.show_peak(dpeak)
        elif self.is_position(list_data):
            spectrum, freq = list_data
            pos = sputil.alias_onto_spectrum(freq, spectrum)
            sputil.show_spectrum_position(spectrum, pos)
Ejemplo n.º 8
0
  def strip_center(self, epeak, xyz_axes):

    aX, aY, aZ = xyz_axes
    spectrum = epeak.peak_set.spectrum
    rmin, rmax = spectrum.region
    shift = self.assignments.resonance_shift
    freq = [0,0,0]
    freq[aX] = shift(epeak.resonances[aX])
    freq[aY] = .5 * (rmin[aY] + rmax[aY])
    freq[aZ] = shift(epeak.resonances[aZ])
    center = sputil.alias_onto_spectrum(freq, spectrum)
    return center
Ejemplo n.º 9
0
    def strip_center(self, epeak, xyz_axes):

        aX, aY, aZ = xyz_axes
        spectrum = epeak.peak_set.spectrum
        rmin, rmax = spectrum.region
        shift = self.assignments.resonance_shift
        freq = [0, 0, 0]
        freq[aX] = shift(epeak.resonances[aX])
        freq[aY] = .5 * (rmin[aY] + rmax[aY])
        freq[aZ] = shift(epeak.resonances[aZ])
        center = sputil.alias_onto_spectrum(freq, spectrum)
        return center
Ejemplo n.º 10
0
  def assigned_strip(self, spectrum, xz_assignment):

    c = spectrum.condition
    x_assignment, z_assignment = xz_assignment
    rX = apply(c.find_resonance, x_assignment)
    rZ = apply(c.find_resonance, z_assignment)
    if rX and rZ:
      freq = [0,0,0]
      xyz_axes = self.xyz_axes(spectrum)
      aX, aY, aZ = xyz_axes
      freq[aX] = rX.frequency
      freq[aZ] = rZ.frequency
      center = sputil.alias_onto_spectrum(freq, spectrum)
      group_name = x_assignment[0]
      atom_name = x_assignment[1]
      label = '%.4g\n%.4g\n%s %s' % (center[aX], center[aZ], group_name, atom_name)
      if self.spectrum_label:
        spectrum_name = spectrum.name
        label = spectrum_name + '\n' + label 
      strip = self.spectrum_strip(spectrum, xyz_axes, center, label)
      strip.xz_assignment = xz_assignment
      return strip
    return None
Ejemplo n.º 11
0
  def assignment_text(self, epeak, dpeak, freq, show_assignment):

    sp = epeak.peak_set.spectrum
    if show_assignment:
      spectrum = sp.name
      assignment = epeak.assignment_text()
    else:
      spectrum = ''
      assignment = ''

    if dpeak:
      position = self.position_text(freq, dpeak.frequency)
      height = sputil.peak_height(dpeak) / sp.noise
      assigned = dpeak.assignment
    else:
      position = ''
      pos = sputil.alias_onto_spectrum(freq, sp)
      height = sp.data_height(pos) / sp.noise
      assigned = ''
      
    text = ('%10s %20s %21s %5.1f %s'
            % (spectrum, assignment, position, height, assigned))
    
    return text
Ejemplo n.º 12
0
    def assignment_text(self, epeak, dpeak, freq, show_assignment):

        sp = epeak.peak_set.spectrum
        if show_assignment:
            spectrum = sp.name
            assignment = epeak.assignment_text()
        else:
            spectrum = ''
            assignment = ''

        if dpeak:
            position = self.position_text(freq, dpeak.frequency)
            height = sputil.peak_height(dpeak) / sp.noise
            assigned = dpeak.assignment
        else:
            position = ''
            pos = sputil.alias_onto_spectrum(freq, sp)
            height = sp.data_height(pos) / sp.noise
            assigned = ''

        text = ('%10s %20s %21s %5.1f %s' %
                (spectrum, assignment, position, height, assigned))

        return text
Ejemplo n.º 13
0
  return dict(dim_list)

# place assigned peaks
from sputil import split_group_atom, alias_onto_spectrum
from pyutil import subtract_tuples
dim_dict = detect_dimension(peak_list, spec)
if dim_dict == None:
  s.show_message('Error', 
            'Spectrum does not look the correct experiment to use.')
  raise SystemExit

for peak in peak_list:
  gas, freqs = peak[0], peak[1]
  gas2, freqs2 = list(gas), list(freqs)
  for a in range(spec.dimension):
    b = dim_dict[a]
    gas2[b], freqs2[b] = gas[a], freqs[a]
  peak = spec.place_peak(freqs2)

  # alias if edge of the spectrum
  freqs3 = alias_onto_spectrum(freqs2, spec)
  if freqs2 != freqs3:
    peak.position = freqs3
    peak.alias = subtract_tuples(freqs2, freqs3)

  # attach assignment labels
  for i in range(spec.dimension):
    g, a = split_group_atom(gas2[i])
    peak.assign(i, g, a)
  peak.show_assignment_label()