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)
peaklist.write_header(outfn) # Write the header to the output file # Predict the i->i+inc and i->i-inc noe positions if possible # Write each one to the output file as they are calculated count = 0 # A counter that number the output data lines in order res = MINRES # minimum residue number in the set outlist = [] # Holds the output data while (res <= MAXRES): # Predicting the NOE positions based on peak assignment data # is done by supplying the peaklist to and specifying the label # of the origin and detected atom in the NOE transfer as well as # the residues between which the NOE transfer takes places. noe1 = NOEtools.predictNOE(peaklist, "15N2", "H1", res, res + inc) noe2 = NOEtools.predictNOE(peaklist, "15N2", "H1", res, res - inc) # The output of predictNOE is in the form of an xpk entry line # suitable for printing to an output file # Additionally, it is possible to extract information easily from # these output lines by using the xpktools.XpkEntry class entry1 = xpktools.XpkEntry(noe1, peaklist.datalabels) 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.