def test_value_set_r1_rit(self): """Test of the pipe_control.value.set() function.""" # Set the current data pipe to 'mf'. pipes.switch('relax_disp') # Set variables. exp_type = 'R1rho' frq = 800.1 * 1E6 # Set an experiment type to the pipe. set_exp_type(spectrum_id='test', exp_type=exp_type) # Set a frequency to loop through. spectrometer.set_frequency(id='test', frq=frq, units='Hz') # Generate dic key. r20_key = generate_r20_key(exp_type=exp_type, frq=frq) # Set first similar to r2. value.set(val=None, param='r2') self.assertEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], 10.0) # Then set for r1. value.set(val=None, param='r1') print(cdp.mol[0].res[0].spin[0]) self.assertEqual(cdp.mol[0].res[0].spin[0].r1[r20_key], 2.0)
def calc_point_par_chi2(self): """Function for chi2 value for the points.""" # Print out. print("\nCalculate chi2 value for the point parameters.") # Define nested listed, which holds parameter values and chi2 value. par_chi2_vals = [] # Loop over the points. for i in range(self.num_points): i_point = self.point[i] # Set the parameter values. if self.spin_id: value.set(val=i_point, param=self.params, spin_id=self.spin_id, force=True) else: value.set(val=i_point, param=self.params, force=True) # Calculate the function values. if self.spin_id: self.api.calculate(spin_id=self.spin_id, verbosity=0) else: self.api.calculate(verbosity=0) # Get the minimisation statistics for the model. if self.spin_id: k, n, chi2 = self.api.model_statistics(spin_id=self.spin_id) else: k, n, chi2 = self.api.model_statistics(model_info=0) # Assign value to nested list. par_chi2_vals.append([i, i_point[0], i_point[1], i_point[2], chi2]) # Return list return par_chi2_vals
def map_3D_text(self, map_file): """Function for creating the text of a 3D map.""" # Initialise. values = zeros(3, float64) percent = 0.0 percent_inc = 100.0 / (self.inc + 1.0)**(self.n - 1.0) print("%-10s%8.3f%-1s" % ("Progress:", percent, "%")) # Collect all chi2, to help finding a reasobale chi level for the Innermost, Inner, Middle and Outer Isosurface. all_chi = [] # Fix the diffusion tensor. unfix = False if hasattr(cdp, 'diff_tensor') and not cdp.diff_tensor.fixed: cdp.diff_tensor.fixed = True unfix = True # Initial value of the first parameter. values[0] = self.bounds[0, 0] # Define counter counter = 0 # Loop over the first parameter. for i in range((self.inc + 1)): # Initial value of the second parameter. values[1] = self.bounds[1, 0] # Loop over the second parameter. for j in range((self.inc + 1)): # Initial value of the third parameter. values[2] = self.bounds[2, 0] # Loop over the third parameter. for k in range((self.inc + 1)): # Set the parameter values. if self.spin_id: value.set(val=values, param=self.params, spin_id=self.spin_id, verbosity=0, force=True) else: value.set(val=values, param=self.params, verbosity=0, force=True) # Calculate the function values. if self.spin_id: self.api.calculate(spin_id=self.spin_id, verbosity=0) else: self.api.calculate(verbosity=0) # Get the minimisation statistics for the model. if self.spin_id: k, n, chi2 = self.api.model_statistics( spin_id=self.spin_id) else: k, n, chi2 = self.api.model_statistics(model_info=0) # Set maximum value to 1e20 to stop the OpenDX server connection from breaking. if chi2 > 1e20: map_file.write("%30f\n" % 1e20) else: map_file.write("%30f\n" % chi2) # Save all values of chi2. To help find reasonale level for the Innermost, Inner, Middle and Outer Isosurface. all_chi.append(chi2) # Assign value to nested list. self.par_chi2_vals.append( [counter, values[0], values[1], values[2], chi2]) # Add to counter. counter += 1 # Increment the value of the third parameter. values[2] = values[2] + self.step_size[2] # Progress incrementation and printout. percent = percent + percent_inc print("%-10s%8.3f%-8s%-8g" % ("Progress:", percent, "%, " + repr(values) + ", f(x): ", chi2)) # Increment the value of the second parameter. values[1] = values[1] + self.step_size[1] # Increment the value of the first parameter. values[0] = values[0] + self.step_size[0] # Unfix the diffusion tensor. if unfix: cdp.diff_tensor.fixed = False # Save all chi2 values. self.all_chi = all_chi
def map_3D_text(self, map_file): """Function for creating the text of a 3D map.""" # Initialise. values = zeros(3, float64) percent = 0.0 percent_inc = 100.0 / (self.inc + 1.0)**(self.n - 1.0) print("%-10s%8.3f%-1s" % ("Progress:", percent, "%")) # Collect all chi2, to help finding a reasobale chi level for the Innermost, Inner, Middle and Outer Isosurface. all_chi = [] # Fix the diffusion tensor. unfix = False if hasattr(cdp, 'diff_tensor') and not cdp.diff_tensor.fixed: cdp.diff_tensor.fixed = True unfix = True # Initial value of the first parameter. values[0] = self.bounds[0, 0] # Define counter counter = 0 # Loop over the first parameter. for i in range((self.inc + 1)): # Initial value of the second parameter. values[1] = self.bounds[1, 0] # Loop over the second parameter. for j in range((self.inc + 1)): # Initial value of the third parameter. values[2] = self.bounds[2, 0] # Loop over the third parameter. for k in range((self.inc + 1)): # Set the parameter values. if self.spin_id: value.set(val=values, param=self.params, spin_id=self.spin_id, verbosity=0, force=True) else: value.set(val=values, param=self.params, verbosity=0, force=True) # Calculate the function values. if self.spin_id: self.api.calculate(spin_id=self.spin_id, verbosity=0) else: self.api.calculate(verbosity=0) # Get the minimisation statistics for the model. if self.spin_id: k, n, chi2 = self.api.model_statistics(spin_id=self.spin_id) else: k, n, chi2 = self.api.model_statistics(model_info=0) # Set maximum value to 1e20 to stop the OpenDX server connection from breaking. if chi2 > 1e20: map_file.write("%30f\n" % 1e20) else: map_file.write("%30f\n" % chi2) # Save all values of chi2. To help find reasonale level for the Innermost, Inner, Middle and Outer Isosurface. all_chi.append(chi2) # Assign value to nested list. self.par_chi2_vals.append([counter, values[0], values[1], values[2], chi2]) # Add to counter. counter += 1 # Increment the value of the third parameter. values[2] = values[2] + self.step_size[2] # Progress incrementation and printout. percent = percent + percent_inc print("%-10s%8.3f%-8s%-8g" % ("Progress:", percent, "%, " + repr(values) + ", f(x): ", chi2)) # Increment the value of the second parameter. values[1] = values[1] + self.step_size[1] # Increment the value of the first parameter. values[0] = values[0] + self.step_size[0] # Unfix the diffusion tensor. if unfix: cdp.diff_tensor.fixed = False # Save all chi2 values. self.all_chi = all_chi
cur_spin_ids = cluster_spin_ids[0] # Display spins #display_spin() # Loop over the first parameter. # Start counter from 1003, so values correspond to line number. counter = 1003 for i in range((dx_inc + 1)): # Initial value of the second parameter. values[1] = bounds[1, 0] # Loop over the second parameter. for j in range((dx_inc + 1)): # Set the value. value.set(val=values, param=params, spin_id=cur_spin_id, force=True) # Calculate the function values. api.calculate(spin_id=cur_spin_id, verbosity=0) # Now copy the spin new_res_name = "%s_%s=%1.1f_%s=%1.1f" % (cur_resn, params[0], values[0], params[1], values[1]) #spin.create(spin_name=cur_spin_name, spin_num=cur_spin_num, res_name=new_res_name, res_num=counter, mol_name=mol_name) residue.create(res_num=counter, res_name=new_res_name, mol_name=mol_name) new_spin_id = ":%i@%s"%(counter, 'N') spin.copy(pipe_from=None, spin_from=cur_spin_id, pipe_to=None, spin_to=new_spin_id) # Get the minimisation statistics for the model. k_stat, n_stat, chi2 = api.model_statistics(spin_id=cur_spin_id) #print(k_stat, n_stat, chi2, "point is %s=%3.3f, %s=%3.3f"% (params[0], values[0], params[1], values[1]))
def extract(dir): """Extract the data from the Dasha results files. @param dir: The optional directory where the results file is located. @type dir: str or None """ # Test if sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # The directory. if dir == None: dir = pipes.cdp_name() if not access(dir, F_OK): raise RelaxDirError('Dasha', dir) # Loop over the parameters. for param in ['s2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex']: # The file name. file_name = dir + sep + param + '.out' # Test if the file exists. if not access(file_name, F_OK): raise RelaxFileError('Dasha', file_name) # Scaling. if param in ['te', 'tf', 'ts']: scaling = 1e-9 elif param == 'rex': scaling = 1.0 / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]]) ** 2 else: scaling = 1.0 # Read the values. data = read_results(file=file_name, scaling=scaling) # Set the values. for i in range(len(data)): value.set(val=data[i][1], param=param, spin_id=data[i][0]) value.set(val=data[i][0], param=param, spin_id=data[i][0], error=True) # Clean up of non-existent parameters (set the parameter to None!). for spin in spin_loop(): # Skip the spin (don't set the parameter to None) if the parameter exists in the model. if param in spin.params: continue # Set the parameter to None. setattr(spin, param.lower(), None) # Extract the chi-squared values. file_name = dir + sep+'chi2.out' # Test if the file exists. if not access(file_name, F_OK): raise RelaxFileError('Dasha', file_name) # Read the values. data = read_results(file=file_name) # Set the values. for i in range(len(data)): spin = return_spin(data[i][0]) spin.chi2 = data[i][1]
all_chi = [] # Collect data. data = [] # Append point as first data. data.append(["%3.3f" % pcm[0], "%3.3f" % pcm[1], "%3.3f" % pre_chi2]) # Loop over the first parameter. for i in range((dx_inc + 1)): # Initial value of the second parameter. values[1] = bounds[1, 0] # Loop over the second parameter. for j in range((dx_inc + 1)): # Set the value. value.set(val=values, param=params, spin_id=cur_spin_id, force=True) # Calculate the function values. api.calculate(spin_id=cur_spin_id, verbosity=0) # Get the minimisation statistics for the model. k_stat, n_stat, chi2 = api.model_statistics(spin_id=cur_spin_id) #print(k_stat, n_stat, chi2, "point is %s=%3.3f, %s=%3.3f"% (params[0], values[0], params[1], values[1])) # Progress incrementation and printout. percent = percent + percent_inc print( "%-10s%8.3f%-8s%-8g" % ("Progress:", percent, "%, " + repr(values) + ", f(x): ", chi2)) # Append to data.
def map_3D_text(self, map_file): """Function for creating the text of a 3D map.""" # Initialise. values = zeros(3, float64) percent = 0.0 percent_inc = 100.0 / (self.inc + 1.0)**(self.n - 1.0) print("%-10s%8.3f%-1s" % ("Progress:", percent, "%")) # Fix the diffusion tensor. unfix = False if hasattr(cdp, 'diff_tensor') and not cdp.diff_tensor.fixed: cdp.diff_tensor.fixed = True unfix = True # Initial value of the first parameter. values[0] = self.bounds[0, 0] # The model identifier. # Loop over the first parameter. for i in range((self.inc + 1)): # Initial value of the second parameter. values[1] = self.bounds[1, 0] # Loop over the second parameter. for j in range((self.inc + 1)): # Initial value of the third parameter. values[2] = self.bounds[2, 0] # Loop over the third parameter. for k in range((self.inc + 1)): # Set the parameter values. if self.spin_id: value.set(val=values, param=self.params, spin_id=self.spin_id, force=True) else: value.set(val=values, param=self.params, force=True) # Calculate the function values. if self.spin_id: self.calculate(spin_id=self.spin_id, verbosity=0) else: self.calculate(verbosity=0) # Get the minimisation statistics for the model. if self.spin_id: k, n, chi2 = self.model_stats(spin_id=self.spin_id) else: k, n, chi2 = self.model_stats(model_info=0) # Set maximum value to 1e20 to stop the OpenDX server connection from breaking. if chi2 > 1e20: map_file.write("%30f\n" % 1e20) else: map_file.write("%30f\n" % chi2) # Increment the value of the third parameter. values[2] = values[2] + self.step_size[2] # Progress incrementation and printout. percent = percent + percent_inc print("%-10s%8.3f%-8s%-8g" % ("Progress:", percent, "%, " + repr(values) + ", f(x): ", chi2)) # Increment the value of the second parameter. values[1] = values[1] + self.step_size[1] # Increment the value of the first parameter. values[0] = values[0] + self.step_size[0] # Unfix the diffusion tensor. if unfix: cdp.diff_tensor.fixed = False
def extract(dir): """Extract the data from the Dasha results files. @param dir: The optional directory where the results file is located. @type dir: str or None """ # Test if sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # The directory. if dir == None: dir = pipes.cdp_name() if not access(dir, F_OK): raise RelaxDirError('Dasha', dir) # Loop over the parameters. for param in ['s2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex']: # The file name. file_name = dir + sep + param + '.out' # Test if the file exists. if not access(file_name, F_OK): raise RelaxFileError('Dasha', file_name) # Scaling. if param in ['te', 'tf', 'ts']: scaling = 1e-9 elif param == 'rex': scaling = 1.0 / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2 else: scaling = 1.0 # Read the values. data = read_results(file=file_name, scaling=scaling) # Set the values. for i in range(len(data)): value.set(val=data[i][1], param=param, spin_id=data[i][0]) value.set(val=data[i][0], param=param, spin_id=data[i][0], error=True) # Clean up of non-existent parameters (set the parameter to None!). for spin in spin_loop(): # Skip the spin (don't set the parameter to None) if the parameter exists in the model. if param in spin.params: continue # Set the parameter to None. setattr(spin, param.lower(), None) # Extract the chi-squared values. file_name = dir + sep + 'chi2.out' # Test if the file exists. if not access(file_name, F_OK): raise RelaxFileError('Dasha', file_name) # Read the values. data = read_results(file=file_name) # Set the values. for i in range(len(data)): spin = return_spin(spin_id=data[i][0]) spin.chi2 = data[i][1]