Exemplo n.º 1
0
    def process(self):
        """Process the Bruker DC data already present in the section object."""

        # Loop over the data.
        for i in range(len(self._data)):
            # The labelling.
            if self._data[i][0] == 'Labelling:':
                # The spin isotope.
                self.isotope = self._data[i][1]

                # The name of the spins.
                self.spin_name = split('([A-Z]+)', self._data[i][1])[1]

                # The atom name.
                self.atom_name = element_from_isotope(self.isotope)
Exemplo n.º 2
0
def read(ri_id=None, file=None, dir=None):
    """Read the DC data file and place all the data into the relax data store.

    @keyword ri_id: The relaxation data ID string.
    @type ri_id:    str
    @keyword file:  The name of the file to open.
    @type file:     str
    @keyword dir:   The directory containing the file (defaults to the current directory if None).
    @type dir:      str or None
    """

    # Test if the current pipe exists.
    check_pipe()

    # Test if sequence data is loaded.
    if not exists_mol_res_spin_data():
        raise RelaxNoSequenceError

    # Extract the data from the file.
    values, errors, res_nums, int_type, frq, ri_type, spin_name, isotope, version = parse_file(
        file=file, dir=dir)

    # Name the spins if needed.
    name_spin(name=spin_name, force=False)

    # Modify the residue numbers by adding the heteronucleus name.
    if isotope:
        atom_name = element_from_isotope(isotope)
        for i in range(len(res_nums)):
            res_nums[i] += '@' + atom_name

    # Pack the data.
    pack_data(ri_id, ri_type, frq, values, errors, spin_ids=res_nums)

    # Set the integration method.
    peak_intensity_type(ri_id=ri_id, type=int_type)

    # Set the DC as used software.
    software_select('Bruker DC', version=version)
Exemplo n.º 3
0
def read(ri_id=None, file=None, dir=None):
    """Read the DC data file and place all the data into the relax data store.

    @keyword ri_id: The relaxation data ID string.
    @type ri_id:    str
    @keyword file:  The name of the file to open.
    @type file:     str
    @keyword dir:   The directory containing the file (defaults to the current directory if None).
    @type dir:      str or None
    """

    # Test if the current pipe exists.
    check_pipe()

    # Test if sequence data is loaded.
    if not exists_mol_res_spin_data():
        raise RelaxNoSequenceError

    # Extract the data from the file.
    values, errors, res_nums, int_type, frq, ri_type, spin_name, isotope, version = parse_file(file=file, dir=dir)

    # Name the spins if needed.
    name_spin(name=spin_name, force=False)

    # Modify the residue numbers by adding the heteronucleus name.
    if isotope:
        atom_name = element_from_isotope(isotope)
        for i in range(len(res_nums)):
            res_nums[i] += '@' + atom_name

    # Pack the data.
    pack_data(ri_id, ri_type, frq, values, errors, spin_ids=res_nums)

    # Set the integration method.
    peak_intensity_type(ri_id=ri_id, type=int_type)

    # Set the DC as used software.
    software_select('Bruker DC', version=version)
Exemplo n.º 4
0
def bmrb_write(star):
    """Generate the relaxation data saveframes for the NMR-STAR dictionary object.

    @param star:    The NMR-STAR dictionary object.
    @type star:     NMR_STAR instance
    """

    # Get the current data pipe.
    cdp = pipes.get_pipe()

    # Initialise the spin specific data lists.
    mol_name_list = []
    res_num_list = []
    res_name_list = []
    atom_name_list = []
    isotope_list = []
    element_list = []
    attached_atom_name_list = []
    attached_isotope_list = []
    attached_element_list = []
    ri_data_list = []
    ri_data_err_list = []
    for i in range(len(cdp.ri_ids)):
        ri_data_list.append([])
        ri_data_err_list.append([])

    # Relax data labels.
    labels = cdp.ri_ids
    exp_label = []
    spectro_ids = []
    spectro_labels = []

    # Store the spin specific data in lists for later use.
    for spin, mol_name, res_num, res_name, spin_id in spin_loop(
            full_info=True, return_id=True):
        # Skip spins with no relaxation data.
        if not hasattr(spin, 'ri_data'):
            continue

        # Check the data for None (not allowed in BMRB!).
        if res_num == None:
            raise RelaxError(
                "For the BMRB, the residue of spin '%s' must be numbered." %
                spin_id)
        if res_name == None:
            raise RelaxError(
                "For the BMRB, the residue of spin '%s' must be named." %
                spin_id)
        if spin.name == None:
            raise RelaxError("For the BMRB, the spin '%s' must be named." %
                             spin_id)
        if spin.isotope == None:
            raise RelaxError(
                "For the BMRB, the spin isotope type of '%s' must be specified."
                % spin_id)

        # The molecule/residue/spin info.
        mol_name_list.append(mol_name)
        res_num_list.append(str(res_num))
        res_name_list.append(str(res_name))
        atom_name_list.append(str(spin.name))

        # Interatomic info.
        interatoms = return_interatom_list(spin_hash=spin._hash)
        if len(interatoms) == 0:
            raise RelaxError(
                "No interatomic interactions are defined for the spin '%s'." %
                spin_id)
        if len(interatoms) > 1:
            raise RelaxError(
                "The BMRB only handles a signal interatomic interaction for the spin '%s'."
                % spin_id)

        # Get the attached spin.
        spin_attached = return_spin(spin_hash=interatoms[0]._spin_hash1)
        if id(spin_attached) == id(spin):
            spin_attached = return_spin(spin_hash=interatoms[0]._spin_hash2)

        # The attached atom info.
        if hasattr(spin_attached, 'name'):
            attached_atom_name_list.append(str(spin_attached.name))
        else:
            attached_atom_name_list.append(None)
        if hasattr(spin_attached, 'isotope'):
            attached_element_list.append(
                element_from_isotope(spin_attached.isotope))
            attached_isotope_list.append(
                str(number_from_isotope(spin_attached.isotope)))
        else:
            attached_element_list.append(None)
            attached_isotope_list.append(None)

        # The relaxation data.
        used_index = -ones(len(cdp.ri_ids))
        for i in range(len(cdp.ri_ids)):
            # Data exists.
            if cdp.ri_ids[i] in spin.ri_data:
                ri_data_list[i].append(str(spin.ri_data[cdp.ri_ids[i]]))
                ri_data_err_list[i].append(str(
                    spin.ri_data_err[cdp.ri_ids[i]]))
            else:
                ri_data_list[i].append(None)
                ri_data_err_list[i].append(None)

        # Other info.
        isotope_list.append(int(spin.isotope.strip(string.ascii_letters)))
        element_list.append(spin.element)

    # Convert the molecule names into the entity IDs.
    entity_ids = zeros(len(mol_name_list), int32)
    mol_names = get_molecule_names()
    for i in range(len(mol_name_list)):
        for j in range(len(mol_names)):
            if mol_name_list[i] == mol_names[j]:
                entity_ids[i] = j + 1

    # Check the temperature control methods.
    if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info,
                                                   'temp_calibration'):
        raise RelaxError(
            "The temperature calibration methods have not been specified.")
    if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info,
                                                   'temp_control'):
        raise RelaxError(
            "The temperature control methods have not been specified.")

    # Check the peak intensity type.
    if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info,
                                                   'peak_intensity_type'):
        raise RelaxError(
            "The peak intensity types measured for the relaxation data have not been specified."
        )

    # Loop over the relaxation data.
    for i in range(len(cdp.ri_ids)):
        # Alias.
        ri_id = cdp.ri_ids[i]
        ri_type = cdp.ri_type[ri_id]

        # Convert to MHz.
        frq = cdp.spectrometer_frq[ri_id] * 1e-6

        # Get the temperature control methods.
        temp_calib = cdp.exp_info.temp_calibration[ri_id]
        temp_control = cdp.exp_info.temp_control[ri_id]

        # Get the peak intensity type.
        peak_intensity_type = cdp.exp_info.peak_intensity_type[ri_id]

        # Check.
        if not temp_calib:
            raise RelaxError(
                "The temperature calibration method for the '%s' relaxation data ID string has not been specified."
                % ri_id)
        if not temp_control:
            raise RelaxError(
                "The temperature control method for the '%s' relaxation data ID string has not been specified."
                % ri_id)

        # Add the relaxation data.
        star.relaxation.add(data_type=ri_type,
                            frq=frq,
                            entity_ids=entity_ids,
                            res_nums=res_num_list,
                            res_names=res_name_list,
                            atom_names=atom_name_list,
                            atom_types=element_list,
                            isotope=isotope_list,
                            entity_ids_2=entity_ids,
                            res_nums_2=res_num_list,
                            res_names_2=res_name_list,
                            atom_names_2=attached_atom_name_list,
                            atom_types_2=attached_element_list,
                            isotope_2=attached_isotope_list,
                            data=ri_data_list[i],
                            errors=ri_data_err_list[i],
                            temp_calibration=temp_calib,
                            temp_control=temp_control,
                            peak_intensity_type=peak_intensity_type)

        # The experimental label.
        if ri_type == 'NOE':
            exp_name = 'steady-state NOE'
        else:
            exp_name = ri_type
        exp_label.append("%s MHz %s" % (frq, exp_name))

        # Spectrometer info.
        frq_num = 1
        for frq in loop_frequencies():
            if frq == cdp.spectrometer_frq[ri_id]:
                break
            frq_num += 1
        spectro_ids.append(frq_num)
        spectro_labels.append("$spectrometer_%s" % spectro_ids[-1])

    # Add the spectrometer info.
    num = 1
    for frq in loop_frequencies():
        star.nmr_spectrometer.add(name="$spectrometer_%s" % num,
                                  manufacturer=None,
                                  model=None,
                                  frq=int(frq / 1e6))
        num += 1

    # Add the experiment saveframe.
    star.experiment.add(name=exp_label,
                        spectrometer_ids=spectro_ids,
                        spectrometer_labels=spectro_labels)
Exemplo n.º 5
0
def bmrb_write(star):
    """Generate the relaxation data saveframes for the NMR-STAR dictionary object.

    @param star:    The NMR-STAR dictionary object.
    @type star:     NMR_STAR instance
    """

    # Get the current data pipe.
    cdp = pipes.get_pipe()

    # Initialise the spin specific data lists.
    mol_name_list = []
    res_num_list = []
    res_name_list = []
    atom_name_list = []
    isotope_list = []
    element_list = []
    attached_atom_name_list = []
    attached_isotope_list = []
    attached_element_list = []
    ri_data_list = []
    ri_data_err_list = []
    for i in range(len(cdp.ri_ids)):
        ri_data_list.append([])
        ri_data_err_list.append([])

    # Relax data labels.
    labels = cdp.ri_ids
    exp_label = []
    spectro_ids = []
    spectro_labels = []

    # Store the spin specific data in lists for later use.
    for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True):
        # Skip spins with no relaxation data.
        if not hasattr(spin, 'ri_data'):
            continue

        # Check the data for None (not allowed in BMRB!).
        if res_num == None:
            raise RelaxError("For the BMRB, the residue of spin '%s' must be numbered." % spin_id)
        if res_name == None:
            raise RelaxError("For the BMRB, the residue of spin '%s' must be named." % spin_id)
        if spin.name == None:
            raise RelaxError("For the BMRB, the spin '%s' must be named." % spin_id)
        if spin.isotope == None:
            raise RelaxError("For the BMRB, the spin isotope type of '%s' must be specified." % spin_id)

        # The molecule/residue/spin info.
        mol_name_list.append(mol_name)
        res_num_list.append(str(res_num))
        res_name_list.append(str(res_name))
        atom_name_list.append(str(spin.name))

        # Interatomic info.
        interatoms = return_interatom_list(spin_id)
        if len(interatoms) == 0:
            raise RelaxError("No interatomic interactions are defined for the spin '%s'." % spin_id)
        if len(interatoms) > 1:
            raise RelaxError("The BMRB only handles a signal interatomic interaction for the spin '%s'." % spin_id)

        # Get the attached spin.
        spin_attached = return_spin(interatoms[0].spin_id1)
        if id(spin_attached) == id(spin):
            spin_attached = return_spin(interatoms[0].spin_id2)

        # The attached atom info.
        if hasattr(spin_attached, 'name'):
            attached_atom_name_list.append(str(spin_attached.name))
        else:
            attached_atom_name_list.append(None)
        if hasattr(spin_attached, 'isotope'):
            attached_element_list.append(element_from_isotope(spin_attached.isotope))
            attached_isotope_list.append(str(number_from_isotope(spin_attached.isotope)))
        else:
            attached_element_list.append(None)
            attached_isotope_list.append(None)

        # The relaxation data.
        used_index = -ones(len(cdp.ri_ids))
        for i in range(len(cdp.ri_ids)):
            # Data exists.
            if cdp.ri_ids[i] in list(spin.ri_data.keys()):
                ri_data_list[i].append(str(spin.ri_data[cdp.ri_ids[i]]))
                ri_data_err_list[i].append(str(spin.ri_data_err[cdp.ri_ids[i]]))
            else:
                ri_data_list[i].append(None)
                ri_data_err_list[i].append(None)

        # Other info.
        isotope_list.append(int(spin.isotope.strip(string.ascii_letters)))
        element_list.append(spin.element)

    # Convert the molecule names into the entity IDs.
    entity_ids = zeros(len(mol_name_list), int32)
    mol_names = get_molecule_names()
    for i in range(len(mol_name_list)):
        for j in range(len(mol_names)):
            if mol_name_list[i] == mol_names[j]:
                entity_ids[i] = j+1

    # Check the temperature control methods.
    if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_calibration'):
        raise RelaxError("The temperature calibration methods have not been specified.")
    if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_control'):
        raise RelaxError("The temperature control methods have not been specified.")

    # Check the peak intensity type.
    if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'peak_intensity_type'):
        raise RelaxError("The peak intensity types measured for the relaxation data have not been specified.")

    # Loop over the relaxation data.
    for i in range(len(cdp.ri_ids)):
        # Alias.
        ri_id = cdp.ri_ids[i]
        ri_type = cdp.ri_type[ri_id]

        # Convert to MHz.
        frq = cdp.spectrometer_frq[ri_id] * 1e-6

        # Get the temperature control methods.
        temp_calib = cdp.exp_info.temp_calibration[ri_id]
        temp_control = cdp.exp_info.temp_control[ri_id]

        # Get the peak intensity type.
        peak_intensity_type = cdp.exp_info.peak_intensity_type[ri_id]

        # Check.
        if not temp_calib:
            raise RelaxError("The temperature calibration method for the '%s' relaxation data ID string has not been specified." % ri_id)
        if not temp_control:
            raise RelaxError("The temperature control method for the '%s' relaxation data ID string has not been specified." % ri_id)

        # Add the relaxation data.
        star.relaxation.add(data_type=ri_type, frq=frq, entity_ids=entity_ids, res_nums=res_num_list, res_names=res_name_list, atom_names=atom_name_list, atom_types=element_list, isotope=isotope_list, entity_ids_2=entity_ids, res_nums_2=res_num_list, res_names_2=res_name_list, atom_names_2=attached_atom_name_list, atom_types_2=attached_element_list, isotope_2=attached_isotope_list, data=ri_data_list[i], errors=ri_data_err_list[i], temp_calibration=temp_calib, temp_control=temp_control, peak_intensity_type=peak_intensity_type)

        # The experimental label.
        if ri_type == 'NOE':
            exp_name = 'steady-state NOE'
        else:
            exp_name = ri_type
        exp_label.append("%s MHz %s" % (frq, exp_name))

        # Spectrometer info.
        frq_num = 1
        for frq in loop_frequencies():
            if frq == cdp.spectrometer_frq[ri_id]:
                break
            frq_num += 1
        spectro_ids.append(frq_num)
        spectro_labels.append("$spectrometer_%s" % spectro_ids[-1])

    # Add the spectrometer info.
    num = 1
    for frq in loop_frequencies():
        star.nmr_spectrometer.add(name="$spectrometer_%s" % num, manufacturer=None, model=None, frq=int(frq/1e6))
        num += 1

    # Add the experiment saveframe.
    star.experiment.add(name=exp_label, spectrometer_ids=spectro_ids, spectrometer_labels=spectro_labels)