Example #1
0
    def test_noetools(self):
        """Self test for NMR.NOEtools.

        Calculate and compare crosspeak peaklist files
        Adapted from Doc/examples/nmr/simplepredict.py by Robert Bussell, Jr.
        """
        self.xpk_i_file = os.path.join("NMR", "noed.xpk")
        # out_example.xpk is created by running Doc/examples/nmr/simplepredict.py
        # with noed.xpk as an input file.
        self.xpk_expected = os.path.join("NMR", "out_example.xpk")

        self.f_number, self.f_predicted = tempfile.mkstemp()
        os.close(self.f_number)

        # Calculate crosspeak from a peaklist input file
        # and save to a temporal file for comparison.
        try:
            self.peaklist = xpktools.Peaklist(self.xpk_i_file)
            self.res_dict = self.peaklist.residue_dict("H1")
            max_res = self.res_dict["maxres"]
            min_res = self.res_dict["minres"]

            self.peaklist.write_header(self.f_predicted)

            inc = 1  # The NOE increment (n where i->i+n and i->i-n are noes)
            count = 0  # A counter that number the output data lines in order
            res = min_res  # minimum residue number in the set
            out_list = []  # Holds the output data

            while res <= max_res:
                noe1 = NOEtools.predictNOE(self.peaklist, "15N2", "H1", res,
                                           res + inc)
                noe2 = NOEtools.predictNOE(self.peaklist, "15N2", "H1", res,
                                           res - inc)

                if noe1 != "":
                    noe1 = noe1 + "\012"
                    noe1 = xpktools.replace_entry(noe1, 1, count)
                    out_list.append(noe1)
                    count += 1

                    if noe2 != "":
                        noe2 = noe2 + "\012"
                        noe2 = xpktools.replace_entry(noe2, 1, count)
                        out_list.append(noe2)
                        count += 1
                res += 1

            # Open the output file and write the data
            with open(self.f_predicted, "a") as outfile:
                outfile.writelines(
                    out_list)  # Write the output lines to the file

            # Compare the content of the predicted output file with expected file
            pre_content = open(self.f_predicted).read()
            exp_content = open(self.xpk_expected).read()
            self.assertEqual(pre_content, exp_content)

        finally:
            os.remove(self.f_predicted)
Example #2
0
    if noe1 != "":

        # Here I'm using the XpkEntry class to gain access to
        # specific fields in the that make the information
        # more readable and suitable for creating data tables
        # This output will be printed to the screen.
        # The data table contains the assignment, coordinates and
        # intensity of the resonance.

        print(string.split(entry1.fields["15N2.L"], ".")[0], "-->",
            string.split(entry1.fields["N15.L"], ".")[0], "\t",
            entry1.fields["H1.P"], entry1.fields["N15.P"],
            entry1.fields["15N2.P"], entry1.fields["int"])

        noe1 = noe1 + "\012"
        noe1 = xpktools.replace_entry(noe1, 1, count)
        outlist.append(noe1)
        count += 1

        if noe2 != "":
            noe2 = noe2 + "\012"
            noe2 = xpktools.replace_entry(noe2, 1, count)
            outlist.append(noe2)
            count += 1
    res += 1

# Open the output file and write the data
with open(outfn, 'a') as outfile:
    outfile.writelines(outlist)  # Write the output lines to the file