mailr10263 - /branches/bieri_gui/gui_bieri/res/calc_rx.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on January 20, 2010 - 09:21:
Author: bugman
Date: Wed Jan 20 09:21:22 2010
New Revision: 10263

URL: http://svn.gna.org/viewcvs/relax?rev=10263&view=rev
Log:
Created feedback to relaxGUI Log Window during Rx calculation

This corresponds to the calc_rx_patch file attached to 
https://gna.org/task/?6847 by
Michael Bieri (https://gna.org/users/michaelbieri), in the zip file
https://gna.org/support/download.php?file_id=7726.

added:

class RedirectText --> redirect the relax output to relaxGUI Log Window

# Number of Monte Carlo simulations
global montecarlo
montecarlo = int(global_setting[6])

--> set monte carlo value for updating progress bar in log window


# value for progress bar during monte carlo simulation
global progress
progress = 5.0

--> initial progress value before monte carlo simulation



# redirect relax output and errors to relaxGUI - log panel
redir=RedirectText(self)
sys.stdout=redir
sys.stderr=redir

redirecting system output and error to new created class that updates log
window


Modified:
    branches/bieri_gui/gui_bieri/res/calc_rx.py

Modified: branches/bieri_gui/gui_bieri/res/calc_rx.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/res/calc_rx.py?rev=10263&r1=10262&r2=10263&view=diff
==============================================================================
--- branches/bieri_gui/gui_bieri/res/calc_rx.py (original)
+++ branches/bieri_gui/gui_bieri/res/calc_rx.py Wed Jan 20 09:21:22 2010
@@ -29,24 +29,66 @@
 import time
 import sys
 import os
+import wx
 
 # relax module imports.
 from float import floatAsByteArray
 from generic_fns.mol_res_spin import generate_spin_id, spin_index_loop, 
spin_loop
-from generic_fns import pipes
 import generic_fns.structure.main
 from relax_errors import RelaxError
 from specific_fns.setup import relax_fit_obj
 from generic_fns.state import save_state
-from generic_fns import monte_carlo
+from generic_fns import monte_carlo, results, minimise, pipes, 
diffusion_tensor, fix, sequence, spectrum, relax_data, selection, value, 
grace, eliminate
 from minfx.generic import generic_minimise
 
 # relaxGUI module import
 from results_analysis import color_code_noe
-from message import relax_run_ok
-
+from message import relax_run_ok, question
+
+
+####### Class to redirect relax output to relaxGUI - log panel and progress 
bar
+class RedirectText(object):
+    def __init__(self,aWxTextCtrl):
+        self.out=aWxTextCtrl
  
-def make_rx(target_dir, rx_list, relax_times, structure_pdb, nmr_freq, 
r1_r2, freq_no, unres, self, freqno, global_setting, file_setting, 
sequencefile):
+    def write(self,string):
+        global progress
+
+        wx.CallAfter(self.out.log_panel.WriteText, string)
+        time.sleep(0.001)  # allow relaxGUI log panel to get refreshed
+
+        # split print out into list
+        a = str(string)
+        check = []
+        check = a.split()
+        
+        # update progress bar
+        if 'Simulation' in string:          
+            add = round(progress)
+            add_int = int(add)
+            wx.CallAfter(self.out.progress_bar.SetValue, add_int)
+            progress = ( (int(check[1]) * 100) / float(montecarlo + 6)) + 5
+            time.sleep(0.001)  # allow relaxGUI progressbar to get refreshed
+
+
+
+########### Rx Calculation
+ 
+def make_rx(target_dir, rx_list, relax_times, structure_pdb, nmr_freq, 
r1_r2, freq_no, unres, main, freqno, global_setting, file_setting, 
sequencefile, self):
+
+        # Number of Monte Carlo simulations
+        global montecarlo
+        montecarlo = int(global_setting[6]) 
+
+        # value for progress bar during monte carlo simulation
+        global progress
+        progress = 5.0
+
+
+        # redirect relax output and errors to relaxGUI - log panel
+        redir=RedirectText(self)
+        sys.stdout=redir
+        sys.stderr=redir
 
         hetero = global_setting[2]
         prot = global_setting[3]
@@ -60,6 +102,9 @@
         gracedir = str(target_dir) + sep + 'grace'
         savefile = str(target_dir) + sep + 'r' + str(r1_r2) + '.' + 
str(nmr_freq)  + '.out'
 
+        wx.CallAfter(self.log_panel.AppendText, ('Starting R' + str(r1_r2) + 
' calculation\n------------------------------------------\n\n') )
+        time.sleep(0.5)
+
 
         # Select Peak Lists and Relaxation Times 
         peakfiles = rx_list
@@ -74,7 +119,8 @@
 
         #create unresolved file
         if not unres == '':
-           print "\nCreating unresolved file"
+           wx.CallAfter(self.log_panel.AppendText, ('Creating unresolved 
file\n\n'))
+           time.sleep(0.001)
            unres = replace(unres, ",","\n")
            unres = replace(unres, " ","")
            filename2 = target_dir + sep + 'unresolved'
@@ -85,20 +131,29 @@
         pipename = 'Rx ' + str(time.asctime(time.localtime()))
 
         # Create the NOE data pipe.
+        wx.CallAfter(self.log_panel.AppendText, ("pipes.create("+pipename+", 
'relax_fit')\n\n"))
+        time.sleep(0.001)
         pipes.create(pipename, 'relax_fit')
+
+        # update progress bar
+        wx.CallAfter(self.progress_bar.SetValue, (1))
 
         # Load Sequence
         if str(structure_pdb) == '!!! Sequence file selected !!!':
             
              # Read sequence file
-             print "Reading Suquence from "+ sequencefile
+             wx.CallAfter(self.log_panel.AppendText, ("Reading Suquence from 
"+ sequencefile+'\n\n'))
+             time.sleep(0.001)
              sequence.read(sequencefile)
         
         else:
              # Load the backbone amide 15N spins from a PDB file.
-             print "\nReading sequence from " + str(structure_pdb)
+             wx.CallAfter(self.log_panel.AppendText, ("Reading sequence from 
" + str(structure_pdb) + '\n\n'))
              generic_fns.structure.main.read_pdb(str(structure_pdb))
              generic_fns.structure.main.load_spins(spin_id='@N')
+
+        # update progress bar
+        wx.CallAfter(self.progress_bar.SetValue, (2))
 
         # Spectrum names.
         names = peakfiles
@@ -110,7 +165,7 @@
         print '\n'
         for i in xrange(len(names)):
             # Load the peak intensities.
-            print "\nspectrum.read(file=str("+names[i]+"), 
spectrum_id=str("+names[i]+"), int_method='height', 
heteronuc="+str(hetero)+", proton="+str(prot)+")"
+            wx.CallAfter(self.log_panel.AppendText, 
("spectrum.read(file=str("+names[i]+"), spectrum_id=str("+names[i]+"), 
int_method='height', heteronuc="+str(hetero)+", proton="+str(prot)+")\n\n"))
             spectrum.read(file=str(names[i]), spectrum_id=str(names[i]), 
int_method='height', heteronuc=hetero, proton=prot)
 
             # Set the relaxation times.
@@ -123,9 +178,11 @@
             for j in range(i,(len(names))):
                if times[i] == times[j]:
                   if not i == j:
-                     print "spectrum.replicated(spectrum_ids=[" + names[i] + 
", "+names[j]+"])"   
-                     spectrum.replicated(spectrum_ids=[names[i], names[j]])
-
+                     print "spectrum.replicated(spectrum_ids=[" + 
str(names[i]) + ", "+str(names[j])+"])"   
+                     spectrum.replicated(spectrum_ids= [ str(names[i]), 
str(names[j])])
+
+        # update progress bar
+        wx.CallAfter(self.progress_bar.SetValue, (4))
 
         # Peak intensity error analysis.
         print "spectrum.error_analysis()"
@@ -136,6 +193,9 @@
            print '\nDeselect Residues'
            selection.desel_read(file=resultsdir + sep + 'unresolved', 
res_num_col= 1)
 
+        # update progress bar
+        wx.CallAfter(self.progress_bar.SetValue, (5))
+
         # Set the relaxation curve type.
         print "\nrelax_fit_obj._select_model('exp')"
         relax_fit_obj._select_model('exp')
@@ -149,8 +209,8 @@
         minimise.minimise(min_algor='simplex', min_options=6, 
func_tol=1e-25, grad_tol=None, max_iterations=10000000, constraints=False, 
scaling=False, verbosity=1)
         
         # Monte Carlo simulations.
-        print "\nmonte_carlo.setup(number=500)"
-        monte_carlo.setup(number=500)
+        print "\nmonte_carlo.setup(number="+str(montecarlo)+")"
+        monte_carlo.setup(number=montecarlo)
 
         print "\nmonte_carlo.create_data('back_calc')"
         monte_carlo.create_data('back_calc')
@@ -187,30 +247,37 @@
         print ""
         print ""
         print ""
-        print 
"____________________________________________________________________________"
+        print 
"________________________________________________________________________________"
         print ""
         print "calculation finished"
-        print ""
+        print 
"________________________________________________________________________________"
 
         # list files to results
-        self.list_rx.Append(target_dir + sep + 'grace' + sep + 'r' + 
str(r1_r2)+'.' + str(nmr_freq) + '.agr')
-        self.list_rx.Append(target_dir + sep + 'grace' + sep + 
'intensities_norm.' + str(nmr_freq) + '.agr')
+        main.list_rx.Append(target_dir + sep + 'grace' + sep + 'r' + 
str(r1_r2)+'.' + str(nmr_freq) + '.agr')
+        main.list_rx.Append(target_dir + sep + 'grace' + sep + 
'intensities_norm.' + str(nmr_freq) + '.agr')
 
         # add files to model-free tab
         if r1_r2 == 1:
                     if freqno == 1:
-                      self.m_r1_1.SetValue(target_dir + sep + 'r1.' + 
str(nmr_freq) + '.out')
+                      main.m_r1_1.SetValue(target_dir + sep + 'r1.' + 
str(nmr_freq) + '.out')
                     if freqno == 2:
-                      self.m_r1_2.SetValue(target_dir + sep + 'r1.' + 
str(nmr_freq) + '.out')
+                      main.m_r1_2.SetValue(target_dir + sep + 'r1.' + 
str(nmr_freq) + '.out')
                     if freqno == 3:
-                      self.m_r1_3.SetValue(target_dir + sep + 'r1.' + 
str(nmr_freq) + '.out')
+                      main.m_r1_3.SetValue(target_dir + sep + 'r1.' + 
str(nmr_freq) + '.out')
         if r1_r2 == 2:
                     if freqno == 1:
-                      self.m_r2_1.SetValue(target_dir + sep + 'r2.' + 
str(nmr_freq) + '.out')
+                      main.m_r2_1.SetValue(target_dir + sep + 'r2.' + 
str(nmr_freq) + '.out')
                     if freqno == 2:
-                      self.m_r2_2.SetValue(target_dir + sep + 'r2.' + 
str(nmr_freq) + '.out')
+                      main.m_r2_2.SetValue(target_dir + sep + 'r2.' + 
str(nmr_freq) + '.out')
                     if freqno == 3:
-                      self.m_r2_3.SetValue(target_dir + sep + 'r2.' + 
str(nmr_freq) + '.out')
-
-        # Feedback
-        relax_run_ok('T' + str(r1_r2) +' calculation was successful !') 
+                      main.m_r2_3.SetValue(target_dir + sep + 'r2.' + 
str(nmr_freq) + '.out')
+
+        # update progress bar
+        wx.CallAfter(self.progress_bar.SetValue, (100))
+
+        # enable close button and disable cancel button
+        wx.CallAfter(self.close_button.Enable, True)
+        wx.CallAfter(self.cancel_button.Enable, False)
+
+        # close thread 
+        return




Related Messages


Powered by MHonArc, Updated Wed Jan 20 09:40:02 2010