Author: bugman Date: Sun Feb 22 00:36:22 2009 New Revision: 8838 URL: http://svn.gna.org/viewcvs/relax?rev=8838&view=rev Log: Shifted all the pystarlib code for the relaxation data into the NMR-STAR dictionary object. Modified: branches/bmrb/bmrblib/nmr_star_dict.py branches/bmrb/specific_fns/model_free/bmrb.py Modified: branches/bmrb/bmrblib/nmr_star_dict.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/bmrblib/nmr_star_dict.py?rev=8838&r1=8837&r2=8838&view=diff ============================================================================== --- branches/bmrb/bmrblib/nmr_star_dict.py (original) +++ branches/bmrb/bmrblib/nmr_star_dict.py Sun Feb 22 00:36:22 2009 @@ -29,6 +29,8 @@ # relax module imports. from pystarlib.File import File +from pystarlib.SaveFrame import SaveFrame +from pystarlib.TagTable import TagTable class NMR_STAR: @@ -46,6 +48,9 @@ # Initialise the pystarlib File object. self.data = File(title=title, filename=file_path) + # Initialise the objects of this class. + self.relax_data = Relaxation_data(self.data.datanodes) + def read(self): """Read the data from a BMRB NMR-STAR formatted file.""" @@ -59,3 +64,86 @@ # Write the contents to the STAR formatted file. self.data.write() + + +class Relaxation_data: + """Base class for relaxation data support.""" + + def __init__(self, datanodes): + """Initialise the class, placing the pystarlib data nodes into the namespace. + + @param datanodes: The pystarlib data nodes object. + @type datanodes: list + """ + + # Place the data nodes into the namespace. + self.datanodes = datanodes + + # The number of relaxation data sets. + self.r1_inc = 0 + self.r2_inc = 0 + self.noe_inc = 0 + + + def add(self, ri_label=None, frq=None, res_nums=None, res_names=None, atom_names=None, data=None, errors=None): + """Add relaxation data to the data nodes. + + @keyword ri_label: The relaxation data label, one of 'R1', 'R2', or 'NOE'. + @type ri_label: str + @keyword frq: The spectrometer proton frequency, in Hz. + @type frq: float + @keyword res_nums: The residue number list. + @type res_nums: list of int + @keyword res_names: The residue name list. + @type res_names: list of str + @keyword atom_names: The atom name list. + @type atom_names: list of str + @keyword data: The relaxation data. + @type data: list of float + @keyword errors: The errors associated with the relaxation data. + @type errors: list of float + """ + + # Data type label. + if ri_label == 'R1': + self.r1_inc = self.r1_inc + 1 + ri_inc = self.r1_inc + label = 'T1' + coherence = 'Nz' + elif ri_label == 'R2': + self.r2_inc = self.r2_inc + 1 + ri_inc = self.r2_inc + label = 'T2' + coherence = 'Ny' + elif ri_label == 'NOE': + self.noe_inc = self.noe_inc + 1 + ri_inc = self.noe_inc + label = 'NOE' + + # Initialise the save frame. + frame = SaveFrame(title='heteronuclear_'+label+'_list_'+`ri_inc`) + + # The save frame category. + frame.tagtables.append(TagTable(free=True, tagnames=['_Saveframe_category'], tagvalues=[[label+'_relaxation']])) + + # Sample info. + frame.tagtables.append(TagTable(free=True, tagnames=['_Sample_label'], tagvalues=[['$sample_1']])) + frame.tagtables.append(TagTable(free=True, tagnames=['_Sample_conditions_label'], tagvalues=[['$conditions_1']])) + + # NMR info. + frame.tagtables.append(TagTable(free=True, tagnames=['_Spectrometer_frequency_1H'], tagvalues=[[str(frq/1e6)]])) + if label in ['T1', 'T2']: + frame.tagtables.append(TagTable(free=True, tagnames=['_'+label+'_coherence_type'], tagvalues=[[coherence]])) + frame.tagtables.append(TagTable(free=True, tagnames=['_'+label+'_value_units'], tagvalues=[['1/s']])) + + # The relaxation tag names. + tag_names = ['_Residue_seq_code', '_Residue_label', '_Atom_name', '_'+label+'_value', '_'+label+'_value_error'] + + # Add the data. + table = TagTable(tagnames=tag_names, tagvalues=[res_nums, res_names, atom_names, data, errors]) + + # Add the tag table to the save frame. + frame.tagtables.append(table) + + # Add the relaxation data save frame. + self.datanodes.append(frame) Modified: branches/bmrb/specific_fns/model_free/bmrb.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/specific_fns/model_free/bmrb.py?rev=8838&r1=8837&r2=8838&view=diff ============================================================================== --- branches/bmrb/specific_fns/model_free/bmrb.py (original) +++ branches/bmrb/specific_fns/model_free/bmrb.py Sun Feb 22 00:36:22 2009 @@ -24,8 +24,6 @@ from bmrblib.nmr_star_dict import NMR_STAR from generic_fns.mol_res_spin import spin_loop from generic_fns.pipes import get_pipe -from pystarlib.SaveFrame import SaveFrame -from pystarlib.TagTable import TagTable class Bmrb: @@ -84,54 +82,9 @@ relax_data_list[i].append(str(spin.relax_data[i])) relax_error_list[i].append(str(spin.relax_error[i])) - # Relaxation data save frames. - r1_inc = 0 - r2_inc = 0 - noe_inc = 0 + # Add the relaxation data. for i in range(cdp.num_ri): - # Data type labels. - if cdp.ri_labels[i] == 'R1': - r1_inc = r1_inc + 1 - ri_inc = r1_inc - ri_label = 'T1' - coherence = 'Nz' - elif cdp.ri_labels[i] == 'R2': - r2_inc = r2_inc + 1 - ri_inc = r2_inc - ri_label = 'T2' - coherence = 'Ny' - elif cdp.ri_labels[i] == 'NOE': - noe_inc = noe_inc + 1 - ri_inc = noe_inc - ri_label = 'NOE' - - # Initialise the save frame. - frame = SaveFrame(title='heteronuclear_'+ri_label+'_list_'+`ri_inc`) - - # The save frame category. - frame.tagtables.append(TagTable(free=True, tagnames=['_Saveframe_category'], tagvalues=[[ri_label+'_relaxation']])) - - # Sample info. - frame.tagtables.append(TagTable(free=True, tagnames=['_Sample_label'], tagvalues=[['$sample_1']])) - frame.tagtables.append(TagTable(free=True, tagnames=['_Sample_conditions_label'], tagvalues=[['$conditions_1']])) - - # NMR info. - frame.tagtables.append(TagTable(free=True, tagnames=['_Spectrometer_frequency_1H'], tagvalues=[[str(cdp.frq[cdp.remap_table[i]]/1e6)]])) - if ri_label in ['T1', 'T2']: - frame.tagtables.append(TagTable(free=True, tagnames=['_'+ri_label+'_coherence_type'], tagvalues=[[coherence]])) - frame.tagtables.append(TagTable(free=True, tagnames=['_'+ri_label+'_value_units'], tagvalues=[['1/s']])) - - # The relaxation tag names. - tag_names = ['_Residue_seq_code', '_Residue_label', '_Atom_name', '_'+ri_label+'_value', '_'+ri_label+'_value_error'] - - # Add the data. - table = TagTable(tagnames=tag_names, tagvalues=[res_num_list, res_name_list, atom_name_list, relax_data_list[i], relax_error_list[i]]) - - # Add the tag table to the save frame. - frame.tagtables.append(table) - - # Add the relaxation data save frame. - star.data.datanodes.append(frame) + star.relax_data.add(ri_label=cdp.ri_labels[i], frq=cdp.frq[cdp.remap_table[i]], res_nums=res_num_list, res_names=res_name_list, atom_names=atom_name_list, data=relax_data_list[i], errors=relax_error_list[i]) # Write the contents to the STAR formatted file. star.write()