peaklist¶
Classes¶
Assignment objects encapsulate the three elements of an NMR
assignment: residue type, residue number and atom name.
Spin objects encapsulate all properties of a single NMR spin
resonance in a peak list
Peak objects represent a line in a peak list. They act as lists
of Spin objects and contain additional peak-specific attributes.
PeakList objects represent a peak list. They act as lists of Peak
objects and contain attributes associated with the entire list.
Documentation¶
-
class
nmrpeaklists.peaklist.Assignment¶ -
atom¶ Alias for field number 2
-
res_num¶ Alias for field number 1
-
res_type¶ Alias for field number 0
-
-
class
nmrpeaklists.peaklist.Spin(res_type=None, res_num=None, atom=None, **kwargs)[source]¶ Encapsulate all properties of an NMR spin.
Record the chemical shift and assignment information for an NMR spin. Spins are hashable, and the hash is based on a tuple of the spin’s residue type, residue number, and atom name. Two spins are considered equal if they share the same value for all three assignment attributes. Spins may also be compared to each other for sorting purposes. A spin is considered “less than” another spin, if the former is assigned and the latter is an unassigned spin system. Furthermore, assigned spins are compared to each other first by residue number, then by backbone or sidechain position, and finally by atom number.
Parameters: - res_type : string, optional
Single letter code for residue type. Use
'+'for unassigned spin systems.- res_num : int or string, optional
Residue number
- atom : string, optional
Atom name
Examples
>>> spin = Spin(shift=3.41, spin_id=1012, res_type='D', res_num=54, atom='HB3') >>> print(spin) Spin(shift=3.41, shfit_pts=None, id=1012, res_type='D', res_num=54, atom='HB3')
-
class
nmrpeaklists.peaklist.Peak(spins=None, **kwargs)[source]¶ A list of Spin objects and an associated set of parameters.
Peak objects encapsulate each line of an NMR peak list. Peak specific parameters should be added as attributes. Arbitrary attributes may be added to a Peak with the standard attribute syntax or as keyword arguments upon initialization.
Peaks are hashable, and the hash is based on a frozen set of the peak’s constituent spins. Two peaks are considered equal if their sets of spins are equal. Note that this only depends on the assignments of the spins, not on the spin’s attributes nor the peak’s attributes.
Warning
Peak objects are hashable but still mutable.
Parameters: - spins :
listofSpin, optional Spins comprising the peak
- index : int or string, optional
Peak index
- commented : bool, default False
Whether the peak should be commented in the peak list
Examples
>>> spin0 = Spin(shift=3.41, spin_id=1012, res_type='D', res_num=54, atom='HB3') >>> spin1 = Spin(shift=40.24, spin_id=1013, res_type='D', res_num=54, atom='CB') >>> spin2 = Spin(shift=4.632, spin_id=973, res_type='L', res_num=56, atom='HA') >>> peak = Peak(spins=[spin0, spin1, spin2], index=134, volume=5.432e5) >>> print(peak) Peak(volume=543200.0, index=134, commented=False, spins= [Spin(shift=3.41, shfit_pts=None, id=1012, res_type='D', res_num=54, atom='HB3'), Spin(shift=40.24, shfit_pts=None, id=1013, res_type='D', res_num=54, atom='CB'), Spin(shift=4.63, shfit_pts=None, id=973, res_type='L', res_num=56, atom='HA')]) >>> peak.height = 1.852e3 >>> print(peak) Peak(volume=543200.0, index=134, commented=False, height=1852.0, spins= [Spin(shift=3.41, shfit_pts=None, id=1012, res_type='D', res_num=54, atom='HB3'), Spin(shift=40.24, shfit_pts=None, id=1013, res_type='D', res_num=54, atom='CB'), Spin(shift=4.63, shfit_pts=None, id=973, res_type='L', res_num=56, atom='HA')])
- spins :
-
class
nmrpeaklists.peaklist.PeakList(peaks=None)[source]¶ A list of Peak objects and parameters associated with entire peak lists.
PeakLists are hashable, and the hash is based on a frozen set of the constituent peaks. Two peak lists are considered equal if their sets of peaks are equal. Note that this only depends on the assignments of the spins in each peak, not on any other spin, peak or peak list attributes.
Warning
PeakList objects are hashable but still mutable.
Parameters: - peaks : list of Peak objects, optional
Each peak must have the same number of spins. The dimensionality of the peak list is given with self.dims
Raises: - ValueError
If attempting to insert a peak with a different number of spins than those currently populating the peak list.
Examples
>>> peaklist = PeakList(anchors=[(0,1)], tab_fmt=[('height', 'HEIGHT', '%11.4e'), ('width', '%sW', '%5.2f'), ('CEST_profile', 'Z_A%d', '%6.4f')]) >>> peak = peaklist[0] >>> peak.height 53472000.0 >>> peak.CEST_profile [0.3017, 0.3022, 0.3021, ...] >>> spin = peak[0] >>> spin.width 2.07
-
anchors¶ Detect which spins in each peak make up spin anchors.
-
nmrpeaklists.peaklist.calibrate_peaklist(peaklist, calibration, attr='shift')[source]¶ Calibrate the chemical shifts of each spin in the peak list.
#TODO:
For each spin in the peak list, subtract the corresponding calibration value from its spin.shift attribute.
Parameters: - calibration : list of floats
List of calibrations for each dimension of the peak list, in PPM. The order of the calibration values should match the order of the spins in each peak.
Raises: - ValueError
When the calibration list length doesn’t match the number of pins in the peak.
Examples
>>> peaklist = PeakList(peaks=peaks, dims=3) >>> peaklist.calibrate([0.053, 0.102, -0.018])
-
nmrpeaklists.peaklist.get_spin_link_dict(peaklist)[source]¶ Map each unique spin link to all of its corresponding peaks.
NOESY peak lists represent spin links between Hydrogen atoms. Whether 2D, 3D or 4D, each peak in a NOESY peak list has exactly two Hydrogen spins. Here, a spin link is represented by a frozenset containing the spin.assignment tuples for each Hydrogen atom. This function returns a dictionary mapping each unique spin link to a list of the Peaks in the PeakList that contain those two Hydrogen atoms.
Returns: - out : dictionary
Each key is a frozenset made from two Hydrogen spin.assignment tuples. Each value is a list of peaks containing those two Hydrogen spins.
Examples
>>> spin_link_dict = peaklist.spin_link_dict() >>> spin_link, peaks = spin_link_dict.popitem() >>> spin_link frozenset([Assignment(res_type='Q', res_num=21, atom='HN'), Assignment( res_type='G', res_num=17, atom='HN')]) >>> print(peaks[0]) Peak(spins=[ Spin(res_type=G, res_num=17, atom=HN), Spin(res_type=G, res_num=17, atom=N), Spin(res_type=Q, res_num=21, atom=HN)]) >>> print(peaks[1]) Peak(spins=[ Spin(res_type=Q, res_num=21, atom=HN), Spin(res_type=Q, res_num=21, atom=N), Spin(res_type=G, res_num=17, atom=HN)])
-
nmrpeaklists.peaklist.sort_by_assignments(peaklist, order=None, commented_at_end=False)[source]¶ Sort peaks by the assignments of their constituent spins.
Sort the peaks by the assignments of spins in particular dimensions. The default order sorts the peaks by the dimensions associated with spin anchors first then by the remaining dimensions in the order they appear in each peak. Optionally place all commented peaks at the end of the peak list.
Parameters: - order : list containing ints or tuples of ints
A list of spin indices and anchor tuples indicating the order in which the dimensions should be sorted. The default order sorts anchored spins before unanchored spins, then sorts the remaining spins by their order in the peaks.
- commented_at_end : boolean, default False
Indicate whether commented peaks should be sorted in their normal order or at the end of the peak list
Examples
>>> peaklist.dims 3 >>> peaklist[0][0] Spin(res_type='I', res_num=34, atom='H') >>> peaklist[0][2] Spin(res_type='I', res_num=34, atom='N') >>> peaklist.sort_by_assignments([(0, 2), 1], commented_at_end=True) >>> peaklist[0][0] Spin(res_type='E', res_num=1, atom='H') >>> peaklist[0][2] Spin(res_type='E', res_num=1, atom='N')