Exemple #1
0
    def test_loop_exp_frq_offset_cpmg(self):
        """Unit test of the loop_exp_frq_offset() function.

        This uses the data of the saved state attached to U{bug #21665<https://gna.org/bugs/?21665>}.
        """

        # Load the state.
        statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2'
        state.load_state(statefile, force=True)

        # Original data (exp_type, frq, offset).
        data = [
            ['SQ CPMG', 499862140.0, 0],
            ['SQ CPMG', 599890858.69999993, 0]
        ]

        # Original indices (ei, mi, oi).
        indices = [
            [0, 0, 0],
            [0, 1, 0]
        ]

        # Check the number of iterations.
        print("Checking the number of iterations of the loop.")
        count = 0
        for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
            print(exp_type, frq, offset, ei, mi, oi)
            count += 1
        self.assertEqual(count, 2)

        # Check the values.
        print("Checking the values returned by the loop.")
        index = 0
        for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
            # Check the experiment info.
            self.assertEqual(exp_type, data[index][0])
            self.assertEqual(ei, indices[index][0])

            # Check the frequency info.
            self.assertEqual(frq, data[index][1])
            self.assertEqual(mi, indices[index][1])

            # Check the offset info.
            self.assertEqual(offset, data[index][2])
            self.assertEqual(oi, indices[index][2])

            # Increment the data index.
            index += 1
Exemple #2
0
    def test_loop_exp_frq_offset_cpmg(self):
        """Unit test of the loop_exp_frq_offset() function.

        This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}.
        """

        # Load the state.
        statefile = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'dispersion' + sep + 'bug_21665.bz2'
        state.load_state(statefile, force=True)

        # Original data (exp_type, frq, offset).
        data = [['SQ CPMG', 499862140.0, 0],
                ['SQ CPMG', 599890858.69999993, 0]]

        # Original indices (ei, mi, oi).
        indices = [[0, 0, 0], [0, 1, 0]]

        # Check the number of iterations.
        print("Checking the number of iterations of the loop.")
        count = 0
        for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(
                return_indices=True):
            print(exp_type, frq, offset, ei, mi, oi)
            count += 1
        self.assertEqual(count, 2)

        # Check the values.
        print("Checking the values returned by the loop.")
        index = 0
        for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(
                return_indices=True):
            # Check the experiment info.
            self.assertEqual(exp_type, data[index][0])
            self.assertEqual(ei, indices[index][0])

            # Check the frequency info.
            self.assertEqual(frq, data[index][1])
            self.assertEqual(mi, indices[index][1])

            # Check the offset info.
            self.assertEqual(offset, data[index][2])
            self.assertEqual(oi, indices[index][2])

            # Increment the data index.
            index += 1
Exemple #3
0
def generate_theta_dic():
    # Get the field count
    field_count = cdp.spectrometer_frq_count

    # Get the spin_lock_field points
    spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)

    # Initialize data containers
    all_spin_ids = get_spin_ids()

    # Containers for only selected spins
    cur_spin_ids = []
    cur_spins = []
    for curspin_id in all_spin_ids:
        # Get the spin
        curspin = return_spin(spin_id=curspin_id)

        # Check if is selected
        if curspin.select == True:
            cur_spin_ids.append(curspin_id)
            cur_spins.append(curspin)

    # The offset and R1 data.
    chemical_shifts, offsets, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=cur_spins, spin_ids=cur_spin_ids, field_count=field_count, fields=spin_lock_nu1)
        
    # Loop over the index of spins, then exp_type, frq, offset
    print("Printing the following")    
    print("exp_type curspin_id frq offset{ppm} offsets[ei][si][mi][oi]{rad/s} ei mi oi si di cur_spin.chemical_shift{ppm} chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz} tilt_angles[ei][si][mi][oi]{rad}")
    for si in range(len(cur_spin_ids)):
        theta_spin_dic = dict()
        curspin_id = cur_spin_ids[si]
        cur_spin = cur_spins[si]
        for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
            # Loop over the dispersion points.
            spin_lock_fields = spin_lock_nu1[ei][mi][oi]
            for di in range(len(spin_lock_fields)):
                print("%-8s %-10s %11.1f %8.4f %12.5f %i  %i  %i  %i  %i %7.3f %12.5f %12.5f %12.5f"%(exp_type, curspin_id, frq, offset, offsets[ei][si][mi][oi], ei, mi, oi, si, di, cur_spin.chemical_shift, chemical_shifts[ei][si][mi], spin_lock_fields[di], tilt_angles[ei][si][mi][oi][di]))
                dic_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=spin_lock_fields[di])
                theta_spin_dic["%s"%(dic_key)] = tilt_angles[ei][si][mi][oi][di]
        # Store the data
        cur_spin.theta = theta_spin_dic
    
    print("\nThe theta data now resides in")
    for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
        spin_index = find_index(selection=spin_id, global_index=False)
        print("%s cdp.mol[%i].res[%i].spin[%i].theta"%(spin_id, spin_index[0], spin_index[1], spin_index[2]))
def generate_theta_dic():
    # Get the field count
    field_count = cdp.spectrometer_frq_count

    # Get the spin_lock_field points
    spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)

    # Initialize data containers
    all_spin_ids = get_spin_ids()

    # Containers for only selected spins
    cur_spin_ids = []
    cur_spins = []
    for curspin_id in all_spin_ids:
        # Get the spin
        curspin = return_spin(curspin_id)

        # Check if is selected
        if curspin.select == True:
            cur_spin_ids.append(curspin_id)
            cur_spins.append(curspin)

    # The offset and R1 data.
    chemical_shifts, offsets, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=cur_spins, spin_ids=cur_spin_ids, field_count=field_count, fields=spin_lock_nu1)
        
    # Loop over the index of spins, then exp_type, frq, offset
    print("Printing the following")    
    print("exp_type curspin_id frq offset{ppm} offsets[ei][si][mi][oi]{rad/s} ei mi oi si di cur_spin.chemical_shift{ppm} chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz} tilt_angles[ei][si][mi][oi]{rad}")
    for si in range(len(cur_spin_ids)):
        theta_spin_dic = dict()
        curspin_id = cur_spin_ids[si]
        cur_spin = cur_spins[si]
        for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
            # Loop over the dispersion points.
            spin_lock_fields = spin_lock_nu1[ei][mi][oi]
            for di in range(len(spin_lock_fields)):
                print("%-8s %-10s %11.1f %8.4f %12.5f %i  %i  %i  %i  %i %7.3f %12.5f %12.5f %12.5f"%(exp_type, curspin_id, frq, offset, offsets[ei][si][mi][oi], ei, mi, oi, si, di, cur_spin.chemical_shift, chemical_shifts[ei][si][mi], spin_lock_fields[di], tilt_angles[ei][si][mi][oi][di]))
                dic_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=spin_lock_fields[di])
                theta_spin_dic["%s"%(dic_key)] = tilt_angles[ei][si][mi][oi][di]
        # Store the data
        cur_spin.theta = theta_spin_dic
    
    print("\nThe theta data now resides in")
    for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
        spin_index = find_index(selection=spin_id, global_index=False)
        print("%s cdp.mol[%i].res[%i].spin[%i].theta"%(spin_id, spin_index[0], spin_index[1], spin_index[2]))
Exemple #5
0
    def _assemble_cpmg_data(self, spin_id=None):
        """Assemble the CPMG data.

        @keyword spin_id:   The spin ID string to restrict data to.
        @type spin_id:      str
        """

        # Spin loop.
        for spin, mol_name, res_num, res_name, id in spin_loop(full_info=True, selection=spin_id, return_id=True, skip_desel=True):
            # The residue index.
            res_index = res_num - 1

            # Sanity checks.
            if res_index < 0:
                raise RelaxError("A residue number of less than 1 is not supported in NESSY.")
            elif res_index > 699:
                raise RelaxError("A residue number of greater than 700 is not supported in NESSY.")

            # Loop over all spectrometer frequencies.
            for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
                # Loop over all dispersion points.
                di_new = 0
                for point, di in loop_point(exp_type=exp_type, frq=frq, offset=offset, skip_ref=False, return_indices=True):
                    # The keys.
                    keys = find_intensity_keys(exp_type=exp_type, frq=frq, point=point, time=cdp.relax_time_list[0])

                    # Convert the reference point for NESSY input.
                    if point == None or isNaN(point):
                        point = 0

                    # Loop over the keys.
                    for key in keys:
                        # Another check.
                        if self.cpmg_data[mi][di_new][res_index] != '':
                            raise RelaxError("Only one spin system per residue is supported in NESSY.")

                        # Store the data (if it exists).
                        if key in spin.peak_intensity:
                            self.cpmg_data[mi][di_new][res_index] = str(spin.peak_intensity[key])

                        # The CPMG frequency.
                        self.cpmg_frqs[mi][di_new] = str(point)

                        # Increment the field index.
                        di_new += 1
Exemple #6
0
    def test_return_offset_data(self):
        """Unit test of the return_offset_data() function for R1rho setup.

        This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}.
        """

        # Load the state.
        statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
        state.load_state(statefile, force=True)

        # Get the field count
        field_count = cdp.spectrometer_frq_count

        # Get the spin_lock_field points
        spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)

        # Initialize data containers
        all_spin_ids = get_spin_ids()

        # Containers for only selected spins
        cur_spin_ids = []
        cur_spins = []
        for curspin_id in all_spin_ids:
            # Get the spin
            curspin = return_spin(curspin_id)

            # Check if is selected
            if curspin.select == True:
                cur_spin_ids.append(curspin_id)
                cur_spins.append(curspin)

        # Get the spectometer frequency
        sfrq = cdp.spectrometer_frq_list[0]

        # Gyromagnetic ratios
        g1H = 26.7522212 * 1e7
        g15N = -2.7126 * 1e7

        # The offset and R1 data.
        offsets, spin_lock_fields_inter, chemical_shifts, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=cur_spins, spin_ids=cur_spin_ids, field_count=field_count, fields=spin_lock_nu1)
        
        # Loop over the index of spins, then exp_type, frq, offset
        print("Printing the following")    
        print("exp_type curspin_id frq offset{ppm} offsets[ei][si][mi][oi]{rad/s} ei mi oi si di cur_spin.chemical_shift{ppm} chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz} tilt_angles[ei][si][mi][oi]{rad}")
        for si in range(len(cur_spin_ids)):
            curspin_id = cur_spin_ids[si]
            cur_spin = cur_spins[si]
            for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
                # Loop over the dispersion points.
                spin_lock_fields = spin_lock_nu1[ei][mi][oi]
                for di in range(len(spin_lock_fields)):
                    print("%-8s %-10s %11.1f %8.4f %12.5f %i  %i  %i  %i  %i %7.3f %12.5f %12.5f %12.5f"%(exp_type, curspin_id, frq, offset, offsets[ei][si][mi][oi], ei, mi, oi, si, di, cur_spin.chemical_shift, chemical_shifts[ei][si][mi], spin_lock_fields[di], tilt_angles[ei][si][mi][oi][di]))
                    # Test chemical shift conversion
                    self.assertEqual(chemical_shifts[ei][si][mi], cur_spin.chemical_shift * 2.0 * pi * sfrq / g1H * g15N * 1e-6)
                    # Test the offset conversion
                    self.assertEqual(offsets[ei][si][mi][oi], offset * 2.0 * pi * sfrq / g1H * g15N * 1e-6)
                    # Test the tiltangle
                    c_omega1 = spin_lock_fields[di] * 2.0 * pi
                    c_Delta_omega = chemical_shifts[ei][si][mi] - offsets[ei][si][mi][oi]
                    if c_omega1 / c_Delta_omega > 0:
                        c_theta = atan(c_omega1 / c_Delta_omega)
                    else:
                        c_theta = pi + atan(c_omega1 / c_Delta_omega)
                    self.assertAlmostEqual(tilt_angles[ei][si][mi][oi][di], c_theta, 15)
Exemple #7
0
    def test_return_offset_data(self):
        """Unit test of the return_offset_data() function for R1rho setup.

        This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}.
        """

        # Load the state.
        statefile = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'dispersion' + sep + 'bug_21344_trunc.bz2'
        state.load_state(statefile, force=True)

        # Get the field count
        field_count = cdp.spectrometer_frq_count

        # Get the spin_lock_field points
        spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)

        # Initialize data containers
        all_spin_ids = get_spin_ids()

        # Containers for only selected spins
        cur_spin_ids = []
        cur_spins = []
        for curspin_id in all_spin_ids:
            # Get the spin
            curspin = return_spin(spin_id=curspin_id)

            # Check if is selected
            if curspin.select == True:
                cur_spin_ids.append(curspin_id)
                cur_spins.append(curspin)

        # Get the spectometer frequency
        sfrq = cdp.spectrometer_frq_list[0]

        # Gyromagnetic ratios
        g1H = 26.7522212 * 1e7
        g15N = -2.7126 * 1e7

        # The offset and R1 data.
        offsets, spin_lock_fields_inter, chemical_shifts, tilt_angles, Delta_omega, w_eff = return_offset_data(
            spins=cur_spins,
            spin_ids=cur_spin_ids,
            field_count=field_count,
            fields=spin_lock_nu1)

        # Loop over the index of spins, then exp_type, frq, offset
        print("Printing the following")
        print(
            "exp_type curspin_id frq offset{ppm} offsets[ei][si][mi][oi]{rad/s} ei mi oi si di cur_spin.chemical_shift{ppm} chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz} tilt_angles[ei][si][mi][oi]{rad}"
        )
        for si in range(len(cur_spin_ids)):
            curspin_id = cur_spin_ids[si]
            cur_spin = cur_spins[si]
            for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(
                    return_indices=True):
                # Loop over the dispersion points.
                spin_lock_fields = spin_lock_nu1[ei][mi][oi]
                for di in range(len(spin_lock_fields)):
                    print(
                        "%-8s %-10s %11.1f %8.4f %12.5f %i  %i  %i  %i  %i %7.3f %12.5f %12.5f %12.5f"
                        % (exp_type, curspin_id, frq, offset,
                           offsets[ei][si][mi][oi], ei, mi, oi, si, di,
                           cur_spin.chemical_shift,
                           chemical_shifts[ei][si][mi], spin_lock_fields[di],
                           tilt_angles[ei][si][mi][oi][di]))
                    # Test chemical shift conversion
                    self.assertEqual(
                        chemical_shifts[ei][si][mi], cur_spin.chemical_shift *
                        2.0 * pi * sfrq / g1H * g15N * 1e-6)
                    # Test the offset conversion
                    self.assertEqual(
                        offsets[ei][si][mi][oi],
                        offset * 2.0 * pi * sfrq / g1H * g15N * 1e-6)
                    # Test the tiltangle
                    c_omega1 = spin_lock_fields[di] * 2.0 * pi
                    c_Delta_omega = chemical_shifts[ei][si][mi] - offsets[ei][
                        si][mi][oi]
                    if c_omega1 / c_Delta_omega > 0:
                        c_theta = atan(c_omega1 / c_Delta_omega)
                    else:
                        c_theta = pi + atan(c_omega1 / c_Delta_omega)
                    self.assertAlmostEqual(tilt_angles[ei][si][mi][oi][di],
                                           c_theta, 15)
Exemple #8
0
    def _assemble_cpmg_data(self, spin_id=None):
        """Assemble the CPMG data.

        @keyword spin_id:   The spin ID string to restrict data to.
        @type spin_id:      str
        """

        # Spin loop.
        for spin, mol_name, res_num, res_name, id in spin_loop(
                full_info=True, selection=spin_id, return_id=True,
                skip_desel=True):
            # The residue index.
            res_index = res_num - 1

            # Sanity checks.
            if res_index < 0:
                raise RelaxError(
                    "A residue number of less than 1 is not supported in NESSY."
                )
            elif res_index > 699:
                raise RelaxError(
                    "A residue number of greater than 700 is not supported in NESSY."
                )

            # Loop over all spectrometer frequencies.
            for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(
                    return_indices=True):
                # Loop over all dispersion points.
                di_new = 0
                for point, di in loop_point(exp_type=exp_type,
                                            frq=frq,
                                            offset=offset,
                                            skip_ref=False,
                                            return_indices=True):
                    # The keys.
                    keys = find_intensity_keys(exp_type=exp_type,
                                               frq=frq,
                                               point=point,
                                               time=cdp.relax_time_list[0])

                    # Convert the reference point for NESSY input.
                    if point == None or isNaN(point):
                        point = 0

                    # Loop over the keys.
                    for key in keys:
                        # Another check.
                        if self.cpmg_data[mi][di_new][res_index] != '':
                            raise RelaxError(
                                "Only one spin system per residue is supported in NESSY."
                            )

                        # Store the data (if it exists).
                        if key in spin.peak_intensity:
                            self.cpmg_data[mi][di_new][res_index] = str(
                                spin.peak_intensity[key])

                        # The CPMG frequency.
                        self.cpmg_frqs[mi][di_new] = str(point)

                        # Increment the field index.
                        di_new += 1