Author: bugman Date: Wed Nov 20 17:30:11 2013 New Revision: 21549 URL: http://svn.gna.org/viewcvs/relax?rev=21549&view=rev Log: Created the relax_disp.write_disp_curves user function. This is based on feedback from Nikolai Skrynnikov. The user function will generate one file per spin system and dump all of the R2eff values (measured, back calculated, and errors) into the file. Modified: branches/relax_disp/specific_analyses/relax_disp/disp_data.py branches/relax_disp/user_functions/relax_disp.py Modified: branches/relax_disp/specific_analyses/relax_disp/disp_data.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/disp_data.py?rev=21549&r1=21548&r2=21549&view=diff ============================================================================== --- branches/relax_disp/specific_analyses/relax_disp/disp_data.py (original) +++ branches/relax_disp/specific_analyses/relax_disp/disp_data.py Wed Nov 20 17:30:11 2013 @@ -2452,3 +2452,86 @@ # Printout. print("Setting the '%s' spectrum spin-lock offset to %s ppm." % (spectrum_id, cdp.spin_lock_offset[spectrum_id])) + + +def write_disp_curves(dir=None, force=None): + """Write out the dispersion curves to text files. + + One file will be created per spin system. + + + @keyword dir: The optional directory to place the file into. + @type dir: str + @param force: If True, the files will be overwritten if they already exists. + @type force: bool + """ + + # Checks. + pipes.test() + check_mol_res_spin_data() + + # The formatting strings. + format_head = "# %-18s %-20s %-20s %-20s %-20s %-20s\n" + format = "%-20s %20s %20s %20s %20s %20s\n" + + # Loop over each spin. + for spin, spin_id in spin_loop(return_id=True, skip_desel=True): + # Skip protons for MMQ data. + if spin.model in MODEL_LIST_MMQ and spin.isotope == '1H': + continue + + # MMQ flags. + proton_sq_flag = has_proton_sq_cpmg() + proton_mq_flag = has_proton_mq_cpmg() + proton_mmq_flag = proton_sq_flag or proton_mq_flag + + # Get the attached proton. + proton = None + if proton_mmq_flag: + proton = return_attached_protons(spin_id)[0] + + # The unique file name. + file_name = "disp%s.out" % spin_id.replace('#', '_').replace(':', '_').replace('@', '_') + + # Open the file for writing. + file_path = get_file_path(file_name, dir) + file = open_write_file(file_name, dir, force) + + # Write a header. + file.write(format_head % ("Experiment_name", "Field_strength_(MHz)", "Disp_point_(Hz)", "R2eff_(measured)", "R2eff_(back_calc)", "R2eff_errors")) + + # Loop over the dispersion points. + for exp_type, frq, point, exp_type_index, frq_index, point_index in loop_exp_frq_point(return_indices=True): + # Alias the correct spin. + current_spin = spin + if exp_type in [EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_PROTON_MQ]: + current_spin = proton + + # The data key. + key = return_param_key_from_data(exp_type=exp_type, frq=frq, point=point) + + # Format the R2eff data. + r2eff = "-" + if key in current_spin.r2eff: + r2eff = "%.15f" % current_spin.r2eff[key] + + # Format the R2eff back calc data. + r2eff_bc = "-" + if hasattr(current_spin, 'r2eff_bc') and key in current_spin.r2eff_bc: + r2eff_bc = "%.15f" % current_spin.r2eff_bc[key] + + # Format the R2eff errors. + r2eff_err = "-" + if key in current_spin.r2eff_err: + r2eff_err = "%.15f" % current_spin.r2eff_err[key] + + # Write out the data. + frq_text = "%.3f" % frq + point_text = "%.6f" % point + file.write(format % (repr(exp_type), frq_text, point_text, r2eff, r2eff_bc, r2eff_err)) + + # Close the file. + file.close() + + # Add the file to the results file list. + add_result_file(type='text', label='Text', file=file_path) Modified: branches/relax_disp/user_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/user_functions/relax_disp.py?rev=21549&r1=21548&r2=21549&view=diff ============================================================================== --- branches/relax_disp/user_functions/relax_disp.py (original) +++ branches/relax_disp/user_functions/relax_disp.py Wed Nov 20 17:30:11 2013 @@ -38,7 +38,7 @@ from pipe_control.mol_res_spin import get_spin_ids from specific_analyses.relax_disp.catia import catia_execute, catia_input from specific_analyses.relax_disp.cpmgfit import cpmgfit_execute, cpmgfit_input -from specific_analyses.relax_disp.disp_data import cpmg_frq, insignificance, plot_disp_curves, plot_exp_curves, r2eff_read, r2eff_read_spin, relax_time, set_exp_type, spin_lock_field, spin_lock_offset +from specific_analyses.relax_disp.disp_data import cpmg_frq, insignificance, plot_disp_curves, plot_exp_curves, r2eff_read, r2eff_read_spin, relax_time, set_exp_type, spin_lock_field, spin_lock_offset, write_disp_curves from specific_analyses.relax_disp.nessy import nessy_input from specific_analyses.relax_disp.parameters import copy from specific_analyses.relax_disp.sherekhan import sherekhan_input @@ -962,3 +962,32 @@ uf.menu_text = "spin_lock_&offset" uf.wizard_size = (800, 500) uf.wizard_image = ANALYSIS_IMAGE_PATH + 'relax_disp_200x200.png' + + +# The relax_disp.write_disp_curves user function. +uf = uf_info.add_uf('relax_disp.write_disp_curves') +uf.title = "Create text files of the dispersion curves for each spin system." +uf.title_short = "Dispersion curve writing." +uf.add_keyarg( + name = "dir", + py_type = "str", + arg_type = "dir sel", + desc_short = "directory name", + desc = "The directory name to place all of the spin system files into.", + can_be_none = True +) +uf.add_keyarg( + name = "force", + default = False, + py_type = "bool", + desc_short = "force flag", + desc = "A flag which, if set to True, will cause the files to be overwritten." +) +# Description. +uf.desc.append(Desc_container()) +uf.desc[-1].add_paragraph("This is used to created text files of the dispersion curves of R2eff/R1rho values, both measured and back calculated from the optimised dispersion model. The columns of the text file will be the experiment name, the magnetic field strength (as the proton frequency in MHz), dispersion point (nu_CPMG or the spin-lock field strength), the experimental R2eff value, the back-calculated R2eff value, and the experimental R2eff error. One file will be created per spin system with the name 'disp_x.out', where x is the spin ID string.") +uf.backend = write_disp_curves +uf.menu_text = "&write_disp_curves" +uf.gui_icon = "oxygen.actions.document-save" +uf.wizard_size = (700, 500) +uf.wizard_image = ANALYSIS_IMAGE_PATH + 'relax_disp_200x200.png'