def return_attached_protons(spin_id=None): """Return a list of all proton spin containers attached to the given spin. @keyword spin_id: The spin ID string. @type spin_id: str @return: The list of proton spin containers attached to the given spin. @rtype: list of SpinContainer instances """ # Initialise. spin_list = [] # Get all interatomic data containers. interatoms = return_interatom_list(spin_id) # No containers. if not len(interatoms): return spin_list # Loop over the containers. for i in range(len(interatoms)): # Get the attached spin. if interatoms[i].spin_id1 == spin_id: attached = return_spin(interatoms[i].spin_id2) else: attached = return_spin(interatoms[i].spin_id1) # Is it a proton? if (hasattr(attached, 'element') and attached.element == 'H') or attached.name == 'H': spin_list.append(attached) # Return the list. return spin_list
def return_attached_protons(spin_hash=None): """Return a list of all proton spin containers attached to the given spin. @keyword spin_hash: The unique spin hash. @type spin_hash: str @return: The list of proton spin containers attached to the given spin. @rtype: list of SpinContainer instances """ # Initialise. spin_list = [] # Get all interatomic data containers. interatoms = return_interatom_list(spin_hash=spin_hash) # No containers. if not len(interatoms): return spin_list # Loop over the containers. for i in range(len(interatoms)): # Get the attached spin. if interatoms[i]._spin_hash1 == spin_hash: attached = return_spin(spin_hash=interatoms[i]._spin_hash2) else: attached = return_spin(spin_hash=interatoms[i]._spin_hash1) # Is it a proton? if (hasattr(attached, 'element') and attached.element == 'H') or attached.name == 'H': spin_list.append(attached) # Return the list. return spin_list
def attach_protons(): """Attach a single proton to all heteronuclei.""" # Loop over all spins. mol_names = [] res_nums = [] res_names = [] for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True): # The spin is already a proton. if hasattr(spin, 'element') and spin.element == 'H': continue # Get the interatomic data container. interatoms = return_interatom_list(spin_hash=spin._hash) proton_found = False if len(interatoms): for i in range(len(interatoms)): # Get the attached spin. spin_attached = return_spin(spin_hash=interatoms[i]._spin_hash1) if id(spin_attached) == id(spin): spin_attached = return_spin(spin_hash=interatoms[i]._spin_hash2) # Is it a proton? if hasattr(spin_attached, 'element') and spin_attached.element == 'H' or spin.name == 'H': proton_found = True break # Attached proton found. if proton_found: continue # Store the sequence info. mol_names.append(mol_name) res_nums.append(res_num) res_names.append(res_name) # Create all protons (this must be done out of the spin loop, as it affects the looping!). ids = [] for i in range(len(mol_names)): # Create the spin container. spin = create_spin(spin_name='H', res_name=res_names[i], res_num=res_nums[i], mol_name=mol_names[i])[0] ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name='H')) print("Creating the spins %s." % ids) # Set the element and spin type. set_spin_element(spin_id='@H', element='H') set_spin_isotope(spin_id='@H', isotope='1H')
def attach_protons(): """Attach a single proton to all heteronuclei.""" # Loop over all spins. mol_names = [] res_nums = [] res_names = [] for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True): # The spin is already a proton. if hasattr(spin, 'element') and spin.element == 'H': continue # Get the interatomic data container. interatoms = return_interatom_list(spin_id) proton_found = False if len(interatoms): for i in range(len(interatoms)): # Get the attached spin. spin_attached = return_spin(interatoms[i].spin_id1) if id(spin_attached) == id(spin): spin_attached = return_spin(interatoms[i].spin_id2) # Is it a proton? if hasattr(spin_attached, 'element') and spin_attached.element == 'H' or spin.name == 'H': proton_found = True break # Attached proton found. if proton_found: continue # Store the sequence info. mol_names.append(mol_name) res_nums.append(res_num) res_names.append(res_name) # Create all protons (this must be done out of the spin loop, as it affects the looping!). ids = [] for i in range(len(mol_names)): # Create the spin container. spin = create_spin(spin_name='H', res_name=res_names[i], res_num=res_nums[i], mol_name=mol_names[i]) ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name='H')) print("Creating the spins %s." % ids) # Set the element and spin type. set_spin_element(spin_id='@H', element='H') set_spin_isotope(spin_id='@H', isotope='1H')
def create_mfpar(file, spin=None, spin_id=None, res_num=None, atom1=None, atom2=None): """Create the Modelfree4 input file 'mfpar'. @param file: The writable file object. @type file: file object @keyword spin: The spin container. @type spin: SpinContainer instance @keyword spin_id: The spin identification string. @type spin_id str @keyword res_num: The residue number from the PDB file corresponding to the spin. @type res_num: int @keyword atom1: The name of the heteronucleus in the PDB file. @type atom1: str @keyword atom2: The name of the proton in the PDB file. @type atom2: str """ # Get the interatomic data containers. interatoms = return_interatom_list(spin_hash=spin._hash) if len(interatoms) == 0: raise RelaxNoInteratomError elif len(interatoms) > 1: raise RelaxError( "Only one interatomic data container, hence dipole-dipole interaction, is supported per spin." ) # Spin title. file.write("\nspin " + spin_id + "\n") file.write('%-14s' % "constants") file.write('%-6i' % res_num) file.write('%-7s' % spin.isotope) file.write('%-8.4f' % (periodic_table.gyromagnetic_ratio(spin.isotope) / 1e7)) file.write('%-8.3f' % (interatoms[0].r * 1e10)) file.write('%-8.3f\n' % (spin.csa * 1e6)) file.write('%-10s' % "vector") file.write('%-4s' % atom1) file.write('%-4s\n' % atom2)
def create_mfpar(file, spin=None, spin_id=None, res_num=None, atom1=None, atom2=None): """Create the Modelfree4 input file 'mfpar'. @param file: The writable file object. @type file: file object @keyword spin: The spin container. @type spin: SpinContainer instance @keyword spin_id: The spin identification string. @type spin_id str @keyword res_num: The residue number from the PDB file corresponding to the spin. @type res_num: int @keyword atom1: The name of the heteronucleus in the PDB file. @type atom1: str @keyword atom2: The name of the proton in the PDB file. @type atom2: str """ # Get the interatomic data containers. interatoms = return_interatom_list(spin_id) if len(interatoms) == 0: raise RelaxNoInteratomError elif len(interatoms) > 1: raise RelaxError("Only one interatomic data container, hence dipole-dipole interaction, is supported per spin.") # Spin title. file.write("\nspin " + spin_id + "\n") file.write('%-14s' % "constants") file.write('%-6i' % res_num) file.write('%-7s' % spin.isotope) file.write('%-8.4f' % (return_gyromagnetic_ratio(spin.isotope) / 1e7)) file.write('%-8.3f' % (interatoms[0].r * 1e10)) file.write('%-8.3f\n' % (spin.csa * 1e6)) file.write('%-10s' % "vector") file.write('%-4s' % atom1) file.write('%-4s\n' % atom2)
def bmrb_write(self, file_path, version=None): """Write the model-free results to a BMRB NMR-STAR v3.1 formatted file. @param file_path: The full file path. @type file_path: str @keyword version: The BMRB NMR-STAR dictionary format to output to. @type version: str """ # Alias the current data pipe. cdp = pipes.get_pipe() # Initialise the NMR-STAR data object. star = bmrblib.create_nmr_star('relax_model_free_results', file_path, version) # Global minimisation stats. global_chi2 = None if hasattr(cdp, 'chi2'): global_chi2 = cdp.chi2 # Rex frq. rex_frq = cdp.spectrometer_frq[cdp.ri_ids[0]] # Initialise the spin specific data lists. mol_name_list = [] res_num_list = [] res_name_list = [] atom_name_list = [] csa_list = [] r_list = [] isotope_list = [] element_list = [] local_tm_list = [] s2_list = [] s2f_list = [] s2s_list = [] te_list = [] tf_list = [] ts_list = [] rex_list = [] local_tm_err_list = [] s2_err_list = [] s2f_err_list = [] s2s_err_list = [] te_err_list = [] tf_err_list = [] ts_err_list = [] rex_err_list = [] chi2_list = [] model_list = [] # Store the spin specific data in lists for later use. for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True): # Skip the protons. if spin.name == 'H' or (hasattr(spin, 'element') and spin.element == 'H'): warn(RelaxWarning("Skipping the proton spin '%s'." % spin_id)) continue # Check the data for None (not allowed in BMRB!). if res_num == None: raise RelaxError("For the BMRB, the residue of spin '%s' must be numbered." % spin_id) if res_name == None: raise RelaxError("For the BMRB, the residue of spin '%s' must be named." % spin_id) if spin.name == None: raise RelaxError("For the BMRB, the spin '%s' must be named." % spin_id) if not hasattr(spin, 'isotope') or spin.isotope == None: raise RelaxError("For the BMRB, the spin isotope type of '%s' must be specified." % spin_id) if not hasattr(spin, 'element') or spin.element == None: raise RelaxError("For the BMRB, the spin element type of '%s' must be specified. Please use the spin user function for setting the element type." % spin_id) # The molecule/residue/spin info. mol_name_list.append(mol_name) res_num_list.append(res_num) res_name_list.append(res_name) atom_name_list.append(spin.name) # CSA values. if hasattr(spin, 'csa'): csa_list.append(spin.csa * 1e6) # In ppm. else: csa_list.append(None) # Interatomic distances. interatoms = return_interatom_list(spin_id) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # Add the interatomic distance. if hasattr(interatoms[i], 'r'): r_list.append(interatoms[i].r) else: r_list.append(None) # Stop adding. break # The nuclear isotope. if hasattr(spin, 'isotope'): isotope_list.append(int(spin.isotope.strip(string.ascii_letters))) else: isotope_list.append(None) # The element. if hasattr(spin, 'element'): element_list.append(spin.element) else: element_list.append(None) # Diffusion tensor. if hasattr(spin, 'local_tm'): local_tm_list.append(spin.local_tm) else: local_tm_list.append(None) if hasattr(spin, 'local_tm_err'): local_tm_err_list.append(spin.local_tm_err) else: local_tm_err_list.append(None) # Model-free parameter values. s2_list.append(spin.s2) s2f_list.append(spin.s2f) s2s_list.append(spin.s2s) te_list.append(spin.te) tf_list.append(spin.tf) ts_list.append(spin.ts) if spin.rex == None: rex_list.append(None) else: rex_list.append(spin.rex / (2.0*pi*rex_frq**2)) # Model-free parameter errors. params = ['s2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex'] for param in params: # The error list. err_list = locals()[param+'_err_list'] # Append the error. if hasattr(spin, param+'_err'): # The value. val = getattr(spin, param+'_err') # Scaling. if param == 'rex' and val != None: val = val / (2.0*pi*rex_frq**2) # Append. err_list.append(val) # Or None. else: err_list.append(None) # Opt stats. chi2_list.append(spin.chi2) # Model-free model. model_list.append(self._to_bmrb_model(spin.model)) # Convert the molecule names into the entity IDs. entity_ids = zeros(len(mol_name_list), int32) mol_names = get_molecule_names() for i in range(len(mol_name_list)): for j in range(len(mol_names)): if mol_name_list[i] == mol_names[j]: entity_ids[i] = j+1 # Create Supergroup 2 : The citations. ###################################### # Generate the citations saveframe. exp_info.bmrb_write_citations(star) # Create Supergroup 3 : The molecular assembly saveframes. ########################################################## # Generate the entity saveframe. mol_res_spin.bmrb_write_entity(star) # Create Supergroup 4: The experimental descriptions saveframes. ################################################################# # Generate the method saveframes. exp_info.bmrb_write_methods(star) # Generate the software saveframe. software_ids, software_labels = exp_info.bmrb_write_software(star) # Create Supergroup 5 : The NMR parameters saveframes. ###################################################### # Generate the CSA saveframe. star.chem_shift_anisotropy.add(entity_ids=entity_ids, res_nums=res_num_list, res_names=res_name_list, atom_names=atom_name_list, atom_types=element_list, isotope=isotope_list, csa=csa_list) # Create Supergroup 6 : The kinetic data saveframes. #################################################### # Generate the relaxation data saveframes. relax_data.bmrb_write(star) # Create Supergroup 7 : The thermodynamics saveframes. ###################################################### # Get the relax software id. for i in range(len(software_ids)): if software_labels[i] == 'relax': software_id = software_ids[i] # Generate the model-free data saveframe. star.model_free.add(global_chi2=global_chi2, software_ids=[software_id], software_labels=['relax'], entity_ids=entity_ids, res_nums=res_num_list, res_names=res_name_list, atom_names=atom_name_list, atom_types=element_list, isotope=isotope_list, bond_length=r_list, local_tc=local_tm_list, s2=s2_list, s2f=s2f_list, s2s=s2s_list, te=te_list, tf=tf_list, ts=ts_list, rex=rex_list, local_tc_err=local_tm_err_list, s2_err=s2_err_list, s2f_err=s2f_err_list, s2s_err=s2s_err_list, te_err=te_err_list, tf_err=tf_err_list, ts_err=ts_err_list, rex_err=rex_err_list, rex_frq=rex_frq, chi2=chi2_list, model_fit=model_list) # Create Supergroup 8 : The structure determination saveframes. ############################################################### # Generate the diffusion tensor saveframes. diffusion_tensor.bmrb_write(star) # Write the contents to the STAR formatted file. star.write()
def minimise_data_setup(data_store, min_algor, num_data_sets, min_options, spin=None, sim_index=None): """Set up all the data required for minimisation. @param data_store: A data storage container. @type data_store: class instance @param min_algor: The minimisation algorithm to use. @type min_algor: str @param num_data_sets: The number of data sets. @type num_data_sets: int @param min_options: The minimisation options array. @type min_options: list @keyword spin: The spin data container. @type spin: SpinContainer instance @keyword sim_index: The optional MC simulation index. @type sim_index: int @return: An insane tuple. The full tuple is (ri_data, ri_data_err, equations, param_types, param_values, r, csa, num_frq, frq, num_ri, remap_table, noe_r1_table, ri_types, num_params, xh_unit_vectors, diff_type, diff_params) @rtype: tuple """ # Initialise the data structures for the model-free function. data_store.ri_data = [] data_store.ri_data_err = [] data_store.equations = [] data_store.param_types = [] data_store.param_values = None data_store.r = [] data_store.csa = [] data_store.num_frq = [] data_store.frq = [] data_store.num_ri = [] data_store.remap_table = [] data_store.noe_r1_table = [] data_store.ri_types = [] data_store.gx = [] data_store.gh = [] data_store.num_params = [] data_store.xh_unit_vectors = [] if data_store.model_type == "local_tm": data_store.mf_params = [] elif data_store.model_type == "diff": data_store.param_values = [] # Set up the data for the back_calc function. if min_algor == "back_calc": # The spin data. data_store.ri_data = [0.0] data_store.ri_data_err = [0.000001] data_store.equations = [spin.equation] data_store.param_types = [spin.params] data_store.csa = [spin.csa] data_store.num_frq = [1] data_store.frq = [[min_options[3]]] data_store.num_ri = [1] data_store.remap_table = [[0]] data_store.noe_r1_table = [[None]] data_store.ri_types = [[min_options[2]]] data_store.gx = [periodic_table.gyromagnetic_ratio(spin.isotope)] # The interatomic data. interatoms = return_interatom_list(data_store.spin_id) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if data_store.spin_id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id2) # The data. data_store.r = [interatoms[i].r] data_store.gh = [periodic_table.gyromagnetic_ratio(spin2.isotope)] if data_store.model_type != "local_tm" and cdp.diff_tensor.type != "sphere": data_store.xh_unit_vectors = [interatoms[i].vector] else: data_store.xh_unit_vectors = [None] # Count the number of model-free parameters for the spin index. data_store.num_params = [len(spin.params)] # Loop over the number of data sets. for j in range(num_data_sets): # Set the spin index and get the spin, if not already set. if data_store.model_type == "diff" or data_store.model_type == "all": spin_index = j spin, data_store.spin_id = return_spin_from_index(global_index=spin_index, return_spin_id=True) # Skip deselected spins. if not spin.select: continue # Skip spins where there is no data or errors. if not hasattr(spin, "ri_data") or not hasattr(spin, "ri_data_err"): continue # Make sure that the errors are strictly positive numbers. for ri_id in cdp.ri_ids: # Skip missing data. if not ri_id in spin.ri_data_err: continue # Alias. err = spin.ri_data_err[ri_id] # Checks. if err != None and err == 0.0: raise RelaxError( "Zero error for spin '%s' for the relaxation data ID '%s', minimisation not possible." % (data_store.spin_id, ri_id) ) elif err != None and err < 0.0: raise RelaxError( "Negative error of %s for spin '%s' for the relaxation data ID '%s', minimisation not possible." % (err, data_store.spin_id, ri_id) ) # The relaxation data optimisation structures. data = relax_data_opt_structs(spin, sim_index=sim_index) # Append the data. data_store.ri_data.append(data[0]) data_store.ri_data_err.append(data[1]) data_store.num_frq.append(data[2]) data_store.num_ri.append(data[3]) data_store.ri_types.append(data[4]) data_store.frq.append(data[5]) data_store.remap_table.append(data[6]) data_store.noe_r1_table.append(data[7]) if sim_index == None or data_store.model_type == "diff": data_store.csa.append(spin.csa) else: data_store.csa.append(spin.csa_sim[sim_index]) # Repackage the spin data. data_store.equations.append(spin.equation) data_store.param_types.append(spin.params) data_store.gx.append(periodic_table.gyromagnetic_ratio(spin.isotope)) # Repackage the interatomic data. interatoms = return_interatom_list(data_store.spin_id) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if data_store.spin_id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id2) # The data. data_store.gh.append(periodic_table.gyromagnetic_ratio(spin2.isotope)) if sim_index == None or data_store.model_type == "diff" or not hasattr(interatoms[i], "r_sim"): data_store.r.append(interatoms[i].r) else: data_store.r.append(interatoms[i].r_sim[sim_index]) # Vectors. if data_store.model_type != "local_tm" and cdp.diff_tensor.type != "sphere": # Check that this is a single vector! if lib.arg_check.is_num_list(interatoms[i].vector[0], raise_error=False): raise RelaxMultiVectorError(data_store.spin_id) # Store the vector. data_store.xh_unit_vectors.append(interatoms[i].vector) # No vector. else: data_store.xh_unit_vectors.append(None) # Stop - only one mechanism is current supported. break # Model-free parameter values. if data_store.model_type == "local_tm": pass # Count the number of model-free parameters for the spin index. data_store.num_params.append(len(spin.params)) # Repackage the parameter values for minimising just the diffusion tensor parameters. if data_store.model_type == "diff": data_store.param_values.append(assemble_param_vector(model_type="mf")) # Convert to numpy arrays. for k in range(len(data_store.ri_data)): data_store.ri_data[k] = array(data_store.ri_data[k], float64) data_store.ri_data_err[k] = array(data_store.ri_data_err[k], float64) # Diffusion tensor type. if data_store.model_type == "local_tm": data_store.diff_type = "sphere" else: data_store.diff_type = cdp.diff_tensor.type # Package the diffusion tensor parameters. data_store.diff_params = None if data_store.model_type == "mf": # Spherical diffusion. if data_store.diff_type == "sphere": data_store.diff_params = [cdp.diff_tensor.tm] # Spheroidal diffusion. elif data_store.diff_type == "spheroid": data_store.diff_params = [ cdp.diff_tensor.tm, cdp.diff_tensor.Da, cdp.diff_tensor.theta, cdp.diff_tensor.phi, ] # Ellipsoidal diffusion. elif data_store.diff_type == "ellipsoid": data_store.diff_params = [ cdp.diff_tensor.tm, cdp.diff_tensor.Da, cdp.diff_tensor.Dr, cdp.diff_tensor.alpha, cdp.diff_tensor.beta, cdp.diff_tensor.gamma, ] elif min_algor == "back_calc" and data_store.model_type == "local_tm": # Spherical diffusion. data_store.diff_params = [spin.local_tm]
def bmrb_write(star): """Generate the relaxation data saveframes for the NMR-STAR dictionary object. @param star: The NMR-STAR dictionary object. @type star: NMR_STAR instance """ # Get the current data pipe. cdp = pipes.get_pipe() # Initialise the spin specific data lists. mol_name_list = [] res_num_list = [] res_name_list = [] atom_name_list = [] isotope_list = [] element_list = [] attached_atom_name_list = [] attached_isotope_list = [] attached_element_list = [] ri_data_list = [] ri_data_err_list = [] for i in range(len(cdp.ri_ids)): ri_data_list.append([]) ri_data_err_list.append([]) # Relax data labels. labels = cdp.ri_ids exp_label = [] spectro_ids = [] spectro_labels = [] # Store the spin specific data in lists for later use. for spin, mol_name, res_num, res_name, spin_id in spin_loop( full_info=True, return_id=True): # Skip spins with no relaxation data. if not hasattr(spin, 'ri_data'): continue # Check the data for None (not allowed in BMRB!). if res_num == None: raise RelaxError( "For the BMRB, the residue of spin '%s' must be numbered." % spin_id) if res_name == None: raise RelaxError( "For the BMRB, the residue of spin '%s' must be named." % spin_id) if spin.name == None: raise RelaxError("For the BMRB, the spin '%s' must be named." % spin_id) if spin.isotope == None: raise RelaxError( "For the BMRB, the spin isotope type of '%s' must be specified." % spin_id) # The molecule/residue/spin info. mol_name_list.append(mol_name) res_num_list.append(str(res_num)) res_name_list.append(str(res_name)) atom_name_list.append(str(spin.name)) # Interatomic info. interatoms = return_interatom_list(spin_hash=spin._hash) if len(interatoms) == 0: raise RelaxError( "No interatomic interactions are defined for the spin '%s'." % spin_id) if len(interatoms) > 1: raise RelaxError( "The BMRB only handles a signal interatomic interaction for the spin '%s'." % spin_id) # Get the attached spin. spin_attached = return_spin(spin_hash=interatoms[0]._spin_hash1) if id(spin_attached) == id(spin): spin_attached = return_spin(spin_hash=interatoms[0]._spin_hash2) # The attached atom info. if hasattr(spin_attached, 'name'): attached_atom_name_list.append(str(spin_attached.name)) else: attached_atom_name_list.append(None) if hasattr(spin_attached, 'isotope'): attached_element_list.append( element_from_isotope(spin_attached.isotope)) attached_isotope_list.append( str(number_from_isotope(spin_attached.isotope))) else: attached_element_list.append(None) attached_isotope_list.append(None) # The relaxation data. used_index = -ones(len(cdp.ri_ids)) for i in range(len(cdp.ri_ids)): # Data exists. if cdp.ri_ids[i] in spin.ri_data: ri_data_list[i].append(str(spin.ri_data[cdp.ri_ids[i]])) ri_data_err_list[i].append(str( spin.ri_data_err[cdp.ri_ids[i]])) else: ri_data_list[i].append(None) ri_data_err_list[i].append(None) # Other info. isotope_list.append(int(spin.isotope.strip(string.ascii_letters))) element_list.append(spin.element) # Convert the molecule names into the entity IDs. entity_ids = zeros(len(mol_name_list), int32) mol_names = get_molecule_names() for i in range(len(mol_name_list)): for j in range(len(mol_names)): if mol_name_list[i] == mol_names[j]: entity_ids[i] = j + 1 # Check the temperature control methods. if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_calibration'): raise RelaxError( "The temperature calibration methods have not been specified.") if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_control'): raise RelaxError( "The temperature control methods have not been specified.") # Check the peak intensity type. if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'peak_intensity_type'): raise RelaxError( "The peak intensity types measured for the relaxation data have not been specified." ) # Loop over the relaxation data. for i in range(len(cdp.ri_ids)): # Alias. ri_id = cdp.ri_ids[i] ri_type = cdp.ri_type[ri_id] # Convert to MHz. frq = cdp.spectrometer_frq[ri_id] * 1e-6 # Get the temperature control methods. temp_calib = cdp.exp_info.temp_calibration[ri_id] temp_control = cdp.exp_info.temp_control[ri_id] # Get the peak intensity type. peak_intensity_type = cdp.exp_info.peak_intensity_type[ri_id] # Check. if not temp_calib: raise RelaxError( "The temperature calibration method for the '%s' relaxation data ID string has not been specified." % ri_id) if not temp_control: raise RelaxError( "The temperature control method for the '%s' relaxation data ID string has not been specified." % ri_id) # Add the relaxation data. star.relaxation.add(data_type=ri_type, frq=frq, entity_ids=entity_ids, res_nums=res_num_list, res_names=res_name_list, atom_names=atom_name_list, atom_types=element_list, isotope=isotope_list, entity_ids_2=entity_ids, res_nums_2=res_num_list, res_names_2=res_name_list, atom_names_2=attached_atom_name_list, atom_types_2=attached_element_list, isotope_2=attached_isotope_list, data=ri_data_list[i], errors=ri_data_err_list[i], temp_calibration=temp_calib, temp_control=temp_control, peak_intensity_type=peak_intensity_type) # The experimental label. if ri_type == 'NOE': exp_name = 'steady-state NOE' else: exp_name = ri_type exp_label.append("%s MHz %s" % (frq, exp_name)) # Spectrometer info. frq_num = 1 for frq in loop_frequencies(): if frq == cdp.spectrometer_frq[ri_id]: break frq_num += 1 spectro_ids.append(frq_num) spectro_labels.append("$spectrometer_%s" % spectro_ids[-1]) # Add the spectrometer info. num = 1 for frq in loop_frequencies(): star.nmr_spectrometer.add(name="$spectrometer_%s" % num, manufacturer=None, model=None, frq=int(frq / 1e6)) num += 1 # Add the experiment saveframe. star.experiment.add(name=exp_label, spectrometer_ids=spectro_ids, spectrometer_labels=spectro_labels)
def calculate(self, spin_id=None, scaling_matrix=None, verbosity=1, sim_index=None): """Calculation of the consistency functions. @keyword spin_id: The spin identification string. @type spin_id: None or str @keyword scaling_matrix: The per-model list of diagonal and square scaling matrices. @type scaling_matrix: list of numpy rank-2, float64 array or list of None @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int @keyword sim_index: The optional MC simulation index. @type sim_index: None or int """ # Test if the frequency has been set. if not hasattr(cdp, 'ct_frq') or not isinstance(cdp.ct_frq, float): raise RelaxError("The frequency has not been set up.") # Test if the sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Test if the spin data has been set. for spin, id in spin_loop(spin_id, return_id=True): # Skip deselected spins. if not spin.select: continue # Test if the nuclear isotope type has been set. if not hasattr(spin, 'isotope'): raise RelaxSpinTypeError # Test if the CSA value has been set. if not hasattr(spin, 'csa') or spin.csa == None: raise RelaxNoValueError("CSA") # Test if the angle Theta has been set. if not hasattr(spin, 'orientation') or spin.orientation == None: raise RelaxNoValueError("angle Theta") # Test if the correlation time has been set. if not hasattr(spin, 'tc') or spin.tc == None: raise RelaxNoValueError("correlation time") # Test the interatomic data. interatoms = return_interatom_list(spin_hash=spin._hash) for interatom in interatoms: # No relaxation mechanism. if not interatom.dipole_pair: continue # The interacting spin. if id != interatom.spin_id1: spin_id2 = interatom.spin_id1 else: spin_id2 = interatom.spin_id2 spin2 = return_spin(spin_id=spin_id2) # Test if the nuclear isotope type has been set. if not hasattr(spin2, 'isotope'): raise RelaxSpinTypeError # Test if the interatomic distance has been set. if not hasattr(interatom, 'r') or interatom.r == None: raise RelaxNoValueError("interatomic distance", spin_id=spin_id, spin_id2=spin_id2) # Frequency index. if cdp.ct_frq not in list(cdp.spectrometer_frq.values()): raise RelaxError("No relaxation data corresponding to the frequency %s has been loaded." % cdp.ct_frq) # Consistency testing. for spin, id in spin_loop(spin_id, return_id=True): # Skip deselected spins. if not spin.select: continue # Set the r1, r2, and NOE to None. r1 = None r2 = None noe = None # Get the R1, R2, and NOE values corresponding to the set frequency. for ri_id in cdp.ri_ids: # The frequency does not match. if cdp.spectrometer_frq[ri_id] != cdp.ct_frq: continue # R1. if cdp.ri_type[ri_id] == 'R1': if sim_index == None: r1 = spin.ri_data[ri_id] else: r1 = spin.ri_data_sim[ri_id][sim_index] # R2. if cdp.ri_type[ri_id] == 'R2': if sim_index == None: r2 = spin.ri_data[ri_id] else: r2 = spin.ri_data_sim[ri_id][sim_index] # NOE. if cdp.ri_type[ri_id] == 'NOE': if sim_index == None: noe = spin.ri_data[ri_id] else: noe = spin.ri_data_sim[ri_id][sim_index] # Skip the spin if not all of the three value exist. if r1 == None or r2 == None or noe == None: continue # Loop over the interatomic data. interatoms = return_interatom_list(spin_hash=spin._hash) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id=spin_id2) # Gyromagnetic ratios. gx = periodic_table.gyromagnetic_ratio(spin.isotope) gh = periodic_table.gyromagnetic_ratio(spin2.isotope) # The interatomic distance. r = interatoms[i].r # Initialise the function to calculate. ct = Consistency(frq=cdp.ct_frq, gx=gx, gh=gh, mu0=mu0, h_bar=h_bar) # Calculate the consistency tests values. j0, f_eta, f_r2 = ct.func(orientation=spin.orientation, tc=spin.tc, r=r, csa=spin.csa, r1=r1, r2=r2, noe=noe) # Consistency tests values. if sim_index == None: spin.j0 = j0 spin.f_eta = f_eta spin.f_r2 = f_r2 # Monte Carlo simulated consistency tests values. else: # Initialise the simulation data structures. self.data_init(id, sim=1) if spin.j0_sim == None: spin.j0_sim = [] spin.f_eta_sim = [] spin.f_r2_sim = [] # Consistency tests values. spin.j0_sim.append(j0) spin.f_eta_sim.append(f_eta) spin.f_r2_sim.append(f_r2)
def overfit_deselect(self, data_check=True, verbose=True): """Deselect spins which have insufficient data to support calculation. @keyword data_check: A flag to signal if the presence of base data is to be checked for. @type data_check: bool @keyword verbose: A flag which if True will allow printouts. @type verbose: bool """ # Print out. if verbose: print("\nOver-fit spin deselection:") # Test the sequence data exists. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Loop over spin data. deselect_flag = False spin_count = 0 for spin, spin_id in spin_loop(return_id=True): # Skip deselected spins. if not spin.select: continue # The interatomic data. interatoms = return_interatom_list(spin_hash=spin._hash) # Loop over the interatomic data. dipole_relax = False for i in range(len(interatoms)): # No dipolar relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if spin_id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id=spin_id2) # Dipolar relaxation flag. dipole_relax = True # No relaxation mechanism. if not dipole_relax or not hasattr(spin, 'csa') or spin.csa == None: warn(RelaxDeselectWarning(spin_id, 'an absence of relaxation mechanisms')) spin.select = False deselect_flag = True continue # Data checks. if data_check: # The number of relaxation data points (and for infinite data). data_points = 0 inf_data = False if hasattr(cdp, 'ri_ids') and hasattr(spin, 'ri_data'): for id in cdp.ri_ids: if id in spin.ri_data and spin.ri_data[id] != None: data_points += 1 # Infinite data! if isInf(spin.ri_data[id]): inf_data = True # Infinite data. if inf_data: warn(RelaxDeselectWarning(spin_id, 'infinite relaxation data')) spin.select = False deselect_flag = True continue # Relaxation data must exist! if not hasattr(spin, 'ri_data'): warn(RelaxDeselectWarning(spin_id, 'missing relaxation data')) spin.select = False deselect_flag = True continue # Require 3 or more relaxation data points. if data_points < 3: warn(RelaxDeselectWarning(spin_id, 'insufficient relaxation data, 3 or more data points are required')) spin.select = False deselect_flag = True continue # Increment the spin number. spin_count += 1 # No spins selected, so fail hard to prevent the user from going any further. if spin_count == 0: warn(RelaxWarning("No spins are selected therefore the optimisation or calculation cannot proceed.")) # Final printout. if verbose and not deselect_flag: print("No spins have been deselected.")
def minimise_data_setup(data_store, min_algor, num_data_sets, min_options, spin=None, sim_index=None): """Set up all the data required for minimisation. @param data_store: A data storage container. @type data_store: class instance @param min_algor: The minimisation algorithm to use. @type min_algor: str @param num_data_sets: The number of data sets. @type num_data_sets: int @param min_options: The minimisation options array. @type min_options: list @keyword spin: The spin data container. @type spin: SpinContainer instance @keyword sim_index: The optional MC simulation index. @type sim_index: int @return: An insane tuple. The full tuple is (ri_data, ri_data_err, equations, param_types, param_values, r, csa, num_frq, frq, num_ri, remap_table, noe_r1_table, ri_types, num_params, xh_unit_vectors, diff_type, diff_params) @rtype: tuple """ # Initialise the data structures for the model-free function. data_store.ri_data = [] data_store.ri_data_err = [] data_store.equations = [] data_store.param_types = [] data_store.param_values = None data_store.r = [] data_store.csa = [] data_store.num_frq = [] data_store.frq = [] data_store.num_ri = [] data_store.remap_table = [] data_store.noe_r1_table = [] data_store.ri_types = [] data_store.gx = [] data_store.gh = [] data_store.num_params = [] data_store.xh_unit_vectors = [] if data_store.model_type == 'local_tm': data_store.mf_params = [] elif data_store.model_type == 'diff': data_store.param_values = [] # Set up the data for the back_calc function. if min_algor == 'back_calc': # The spin data. data_store.ri_data = [0.0] data_store.ri_data_err = [0.000001] data_store.equations = [spin.equation] data_store.param_types = [spin.params] data_store.csa = [spin.csa] data_store.num_frq = [1] data_store.frq = [[min_options[3]]] data_store.num_ri = [1] data_store.remap_table = [[0]] data_store.noe_r1_table = [[None]] data_store.ri_types = [[min_options[2]]] data_store.gx = [periodic_table.gyromagnetic_ratio(spin.isotope)] # The interatomic data. interatoms = return_interatom_list(spin_hash=spin._hash) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if data_store.spin_id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id=spin_id2) # The data. data_store.r = [interatoms[i].r] data_store.gh = [periodic_table.gyromagnetic_ratio(spin2.isotope)] if data_store.model_type != 'local_tm' and cdp.diff_tensor.type != 'sphere': data_store.xh_unit_vectors = [interatoms[i].vector] else: data_store.xh_unit_vectors = [None] # Count the number of model-free parameters for the spin index. data_store.num_params = [len(spin.params)] # Loop over the number of data sets. for j in range(num_data_sets): # Set the spin index and get the spin, if not already set. if data_store.model_type == 'diff' or data_store.model_type == 'all': spin_index = j spin, data_store.spin_id = return_spin_from_index( global_index=spin_index, return_spin_id=True) # Skip deselected spins. if not spin.select: continue # Skip spins where there is no data or errors. if not hasattr(spin, 'ri_data') or not hasattr(spin, 'ri_data_err'): continue # Make sure that the errors are strictly positive numbers. for ri_id in cdp.ri_ids: # Skip missing data. if not ri_id in spin.ri_data_err: continue # Alias. err = spin.ri_data_err[ri_id] # Checks. if err != None and err == 0.0: raise RelaxError( "Zero error for spin '%s' for the relaxation data ID '%s', minimisation not possible." % (data_store.spin_id, ri_id)) elif err != None and err < 0.0: raise RelaxError( "Negative error of %s for spin '%s' for the relaxation data ID '%s', minimisation not possible." % (err, data_store.spin_id, ri_id)) # The relaxation data optimisation structures. data = relax_data_opt_structs(spin, sim_index=sim_index) # Append the data. data_store.ri_data.append(data[0]) data_store.ri_data_err.append(data[1]) data_store.num_frq.append(data[2]) data_store.num_ri.append(data[3]) data_store.ri_types.append(data[4]) data_store.frq.append(data[5]) data_store.remap_table.append(data[6]) data_store.noe_r1_table.append(data[7]) if sim_index == None or data_store.model_type == 'diff': data_store.csa.append(spin.csa) else: data_store.csa.append(spin.csa_sim[sim_index]) # Repackage the spin data. data_store.equations.append(spin.equation) data_store.param_types.append(spin.params) data_store.gx.append(periodic_table.gyromagnetic_ratio(spin.isotope)) # Repackage the interatomic data. interatoms = return_interatom_list(spin_hash=spin._hash) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if data_store.spin_id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id=spin_id2) # The data. data_store.gh.append( periodic_table.gyromagnetic_ratio(spin2.isotope)) if sim_index == None or data_store.model_type == 'diff' or not hasattr( interatoms[i], 'r_sim'): data_store.r.append(interatoms[i].r) else: data_store.r.append(interatoms[i].r_sim[sim_index]) # Vectors. if data_store.model_type != 'local_tm' and cdp.diff_tensor.type != 'sphere': # Check that this is a single vector! if lib.arg_check.is_num_list(interatoms[i].vector[0], raise_error=False): raise RelaxMultiVectorError(data_store.spin_id) # Store the vector. data_store.xh_unit_vectors.append(interatoms[i].vector) # No vector. else: data_store.xh_unit_vectors.append(None) # Stop - only one mechanism is current supported. break # Model-free parameter values. if data_store.model_type == 'local_tm': pass # Count the number of model-free parameters for the spin index. data_store.num_params.append(len(spin.params)) # Repackage the parameter values for minimising just the diffusion tensor parameters. if data_store.model_type == 'diff': data_store.param_values.append( assemble_param_vector(model_type='mf')) # Convert to numpy arrays. for k in range(len(data_store.ri_data)): data_store.ri_data[k] = array(data_store.ri_data[k], float64) data_store.ri_data_err[k] = array(data_store.ri_data_err[k], float64) # Diffusion tensor type. if data_store.model_type == 'local_tm': data_store.diff_type = 'sphere' else: data_store.diff_type = cdp.diff_tensor.type # Package the diffusion tensor parameters. data_store.diff_params = None if data_store.model_type == 'mf': # Spherical diffusion. if data_store.diff_type == 'sphere': data_store.diff_params = [cdp.diff_tensor.tm] # Spheroidal diffusion. elif data_store.diff_type == 'spheroid': data_store.diff_params = [ cdp.diff_tensor.tm, cdp.diff_tensor.Da, cdp.diff_tensor.theta, cdp.diff_tensor.phi ] # Ellipsoidal diffusion. elif data_store.diff_type == 'ellipsoid': data_store.diff_params = [ cdp.diff_tensor.tm, cdp.diff_tensor.Da, cdp.diff_tensor.Dr, cdp.diff_tensor.alpha, cdp.diff_tensor.beta, cdp.diff_tensor.gamma ] elif min_algor == 'back_calc' and data_store.model_type == 'local_tm': # Spherical diffusion. data_store.diff_params = [spin.local_tm]
def calculate(self, spin_id=None, verbosity=1, sim_index=None): """Calculation of the consistency functions. @keyword spin_id: The spin identification string. @type spin_id: None or str @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int @keyword sim_index: The optional MC simulation index. @type sim_index: None or int """ # Test if the frequency has been set. if not hasattr(cdp, 'ct_frq') or not isinstance(cdp.ct_frq, float): raise RelaxError("The frequency has not been set up.") # Test if the sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Test if the spin data has been set. for spin, id in spin_loop(spin_id, return_id=True): # Skip deselected spins. if not spin.select: continue # Test if the nuclear isotope type has been set. if not hasattr(spin, 'isotope'): raise RelaxSpinTypeError # Test if the CSA value has been set. if not hasattr(spin, 'csa') or spin.csa == None: raise RelaxNoValueError("CSA") # Test if the angle Theta has been set. if not hasattr(spin, 'orientation') or spin.orientation == None: raise RelaxNoValueError("angle Theta") # Test if the correlation time has been set. if not hasattr(spin, 'tc') or spin.tc == None: raise RelaxNoValueError("correlation time") # Test the interatomic data. interatoms = return_interatom_list(id) for interatom in interatoms: # No relaxation mechanism. if not interatom.dipole_pair: continue # The interacting spin. if id != interatom.spin_id1: spin_id2 = interatom.spin_id1 else: spin_id2 = interatom.spin_id2 spin2 = return_spin(spin_id2) # Test if the nuclear isotope type has been set. if not hasattr(spin2, 'isotope'): raise RelaxSpinTypeError # Test if the interatomic distance has been set. if not hasattr(interatom, 'r') or interatom.r == None: raise RelaxNoValueError("interatomic distance", spin_id=spin_id, spin_id2=spin_id2) # Frequency index. if cdp.ct_frq not in cdp.spectrometer_frq.values(): raise RelaxError("No relaxation data corresponding to the frequency %s has been loaded." % cdp.ct_frq) # Consistency testing. for spin, id in spin_loop(spin_id, return_id=True): # Skip deselected spins. if not spin.select: continue # Set the r1, r2, and NOE to None. r1 = None r2 = None noe = None # Get the R1, R2, and NOE values corresponding to the set frequency. for ri_id in cdp.ri_ids: # The frequency does not match. if cdp.spectrometer_frq[ri_id] != cdp.ct_frq: continue # R1. if cdp.ri_type[ri_id] == 'R1': if sim_index == None: r1 = spin.ri_data[ri_id] else: r1 = spin.ri_data_sim[ri_id][sim_index] # R2. if cdp.ri_type[ri_id] == 'R2': if sim_index == None: r2 = spin.ri_data[ri_id] else: r2 = spin.ri_data_sim[ri_id][sim_index] # NOE. if cdp.ri_type[ri_id] == 'NOE': if sim_index == None: noe = spin.ri_data[ri_id] else: noe = spin.ri_data_sim[ri_id][sim_index] # Skip the spin if not all of the three value exist. if r1 == None or r2 == None or noe == None: continue # Loop over the interatomic data. interatoms = return_interatom_list(id) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id2) # Gyromagnetic ratios. gx = return_gyromagnetic_ratio(spin.isotope) gh = return_gyromagnetic_ratio(spin2.isotope) # The interatomic distance. r = interatoms[i].r # Initialise the function to calculate. self.ct = Consistency(frq=cdp.ct_frq, gx=gx, gh=gh, mu0=mu0, h_bar=h_bar) # Calculate the consistency tests values. j0, f_eta, f_r2 = self.ct.func(orientation=spin.orientation, tc=spin.tc, r=r, csa=spin.csa, r1=r1, r2=r2, noe=noe) # Consistency tests values. if sim_index == None: spin.j0 = j0 spin.f_eta = f_eta spin.f_r2 = f_r2 # Monte Carlo simulated consistency tests values. else: # Initialise the simulation data structures. self.data_init(spin, sim=1) if spin.j0_sim == None: spin.j0_sim = [] spin.f_eta_sim = [] spin.f_r2_sim = [] # Consistency tests values. spin.j0_sim.append(j0) spin.f_eta_sim.append(f_eta) spin.f_r2_sim.append(f_r2)
def _load_model_free_data(self, spin_line, col, data_set, spin, spin_id, verbosity=1): """Read the model-free data for the spin. @param spin_line: The line of data for a single spin. @type spin_line: list of str @param col: The column indices. @type col: dict of int @param data_set: The data set type, one of 'value', 'error', or 'sim_xxx' (where xxx is a number). @type data_set: str @param spin: The spin container. @type spin: SpinContainer instance @param spin_id: The spin identification string. @type spin_id: str @keyword verbosity: A variable specifying the amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int """ # Set up the model-free models. if data_set == 'value': # Get the model-free model. model = spin_line[col['model']] if model == 'None': model = None # Get the model-free equation. equation = spin_line[col['eqi']] if equation == 'None': equation = None # Get the model-free parameters. params = eval(spin_line[col['params']]) # Loop over and convert the parameters. if params: for i in range(len(params)): # Fix for the 1.2 relax versions whereby the parameter 'tm' was renamed to 'local_tm' (which occurred in version 1.2.5). if params[i] == 'tm': params[i] = 'local_tm' # Lower case conversion. params[i] = params[i].lower() # Set up the model-free model. self._model_setup(model=model, equation=equation, params=params, spin_id=spin_id) # The model type. model_type = spin_line[col['param_set']] # Get the interatomic data container. interatom = return_interatom_list(spin_id)[0] # Values. if data_set == 'value': # S2. try: spin.s2 = float(spin_line[col['s2']]) * self.return_conversion_factor('s2') except ValueError: spin.s2 = None # S2f. try: spin.s2f = float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f') except ValueError: spin.s2f = None # S2s. try: spin.s2s = float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s') except ValueError: spin.s2s = None # Local tm. try: spin.local_tm = float(spin_line[col['local_tm']]) * self.return_conversion_factor('local_tm') except ValueError: spin.local_tm = None # te. try: spin.te = float(spin_line[col['te']]) * self.return_conversion_factor('te') except ValueError: spin.te = None # tf. try: spin.tf = float(spin_line[col['tf']]) * self.return_conversion_factor('tf') except ValueError: spin.tf = None # ts. try: spin.ts = float(spin_line[col['ts']]) * self.return_conversion_factor('ts') except ValueError: spin.ts = None # Rex. try: spin.rex = float(spin_line[col['rex']]) * self.return_conversion_factor('rex') except ValueError: spin.rex = None # CSA. try: spin.csa = float(spin_line[col['csa']]) * self.return_conversion_factor('csa') except ValueError: spin.csa = None # Minimisation details (global minimisation results). if model_type == 'diff' or model_type == 'all': cdp.chi2 = eval(spin_line[col['chi2']]) cdp.iter = eval(spin_line[col['iter']]) cdp.f_count = eval(spin_line[col['f_count']]) cdp.g_count = eval(spin_line[col['g_count']]) cdp.h_count = eval(spin_line[col['h_count']]) if spin_line[col['warn']] == 'None': cdp.warning = None else: cdp.warning = spin_line[col['warn']].replace('_', ' ') # Minimisation details (individual residue results). else: spin.chi2 = eval(spin_line[col['chi2']]) spin.iter = eval(spin_line[col['iter']]) spin.f_count = eval(spin_line[col['f_count']]) spin.g_count = eval(spin_line[col['g_count']]) spin.h_count = eval(spin_line[col['h_count']]) if spin_line[col['warn']] == 'None': spin.warning = None else: spin.warning = spin_line[col['warn']].replace('_', ' ') # Interatomic distances. try: interatom.r = float(spin_line[col['r']]) * 1e-10 except ValueError: interatom.r = None # Errors. if data_set == 'error': # S2. try: spin.s2_err = float(spin_line[col['s2']]) * self.return_conversion_factor('s2') except ValueError: spin.s2_err = None # S2f. try: spin.s2f_err = float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f') except ValueError: spin.s2f_err = None # S2s. try: spin.s2s_err = float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s') except ValueError: spin.s2s_err = None # Local tm. try: spin.local_tm_err = float(spin_line[col['local_tm']]) * self.return_conversion_factor('local_tm') except ValueError: spin.local_tm_err = None # te. try: spin.te_err = float(spin_line[col['te']]) * self.return_conversion_factor('te') except ValueError: spin.te_err = None # tf. try: spin.tf_err = float(spin_line[col['tf']]) * self.return_conversion_factor('tf') except ValueError: spin.tf_err = None # ts. try: spin.ts_err = float(spin_line[col['ts']]) * self.return_conversion_factor('ts') except ValueError: spin.ts_err = None # Rex. try: spin.rex_err = float(spin_line[col['rex']]) * self.return_conversion_factor('rex') except ValueError: spin.rex_err = None # CSA. try: spin.csa_err = float(spin_line[col['csa']]) * self.return_conversion_factor('csa') except ValueError: spin.csa_err = None # Construct the simulation data structures. if data_set == 'sim_0': # Get the parameter object names. param_names = self.data_names(set='params', scope='spin') # Get the minimisation statistic object names. min_names = self.data_names(set='min', scope='spin') # Loop over all the parameter names. for object_name in param_names: # Name for the simulation object. sim_object_name = object_name + '_sim' # Create the simulation object. setattr(spin, sim_object_name, []) # Loop over all the minimisation object names. for object_name in min_names: # Name for the simulation object. sim_object_name = object_name + '_sim' # Create the simulation object. if model_type == 'diff' or model_type == 'all': setattr(cdp, sim_object_name, []) object = getattr(cdp, sim_object_name) object = [] else: setattr(spin, sim_object_name, []) # Simulations. if data_set != 'value' and data_set != 'error': # S2. try: spin.s2_sim.append(float(spin_line[col['s2']]) * self.return_conversion_factor('s2')) except ValueError: spin.s2_sim.append(None) # S2f. try: spin.s2f_sim.append(float(spin_line[col['s2f']]) * self.return_conversion_factor('s2f')) except ValueError: spin.s2f_sim.append(None) # S2s. try: spin.s2s_sim.append(float(spin_line[col['s2s']]) * self.return_conversion_factor('s2s')) except ValueError: spin.s2s_sim.append(None) # Local tm. try: spin.local_tm_sim.append(float(spin_line[col['local_tm']]) * self.return_conversion_factor('local_tm')) except ValueError: spin.local_tm_sim.append(None) # te. try: spin.te_sim.append(float(spin_line[col['te']]) * self.return_conversion_factor('te')) except ValueError: spin.te_sim.append(None) # tf. try: spin.tf_sim.append(float(spin_line[col['tf']]) * self.return_conversion_factor('tf')) except ValueError: spin.tf_sim.append(None) # ts. try: spin.ts_sim.append(float(spin_line[col['ts']]) * self.return_conversion_factor('ts')) except ValueError: spin.ts_sim.append(None) # Rex. try: spin.rex_sim.append(float(spin_line[col['rex']]) * self.return_conversion_factor('rex')) except ValueError: spin.rex_sim.append(None) # CSA. try: spin.csa_sim.append(float(spin_line[col['csa']]) * self.return_conversion_factor('csa')) except ValueError: spin.csa_sim.append(None) # Minimisation details (global minimisation results). if model_type == 'diff' or model_type == 'all': # The simulation index. index = int(data_set.split('_')[1]) # Already loaded. if len(cdp.chi2_sim) == index + 1: return # Set the values. cdp.chi2_sim.append(eval(spin_line[col['chi2']])) cdp.iter_sim.append(eval(spin_line[col['iter']])) cdp.f_count_sim.append(eval(spin_line[col['f_count']])) cdp.g_count_sim.append(eval(spin_line[col['g_count']])) cdp.h_count_sim.append(eval(spin_line[col['h_count']])) if spin_line[col['warn']] == 'None': cdp.warning_sim.append(None) else: cdp.warning_sim.append(spin_line[col['warn']].replace('_', ' ')) # Minimisation details (individual residue results). else: spin.chi2_sim.append(eval(spin_line[col['chi2']])) spin.iter_sim.append(eval(spin_line[col['iter']])) spin.f_count_sim.append(eval(spin_line[col['f_count']])) spin.g_count_sim.append(eval(spin_line[col['g_count']])) spin.h_count_sim.append(eval(spin_line[col['h_count']])) if spin_line[col['warn']] == 'None': spin.warning_sim.append(None) else: spin.warning_sim.append(spin_line[col['warn']].replace('_', ' '))
def load_model_free_data(spin_line, col, data_set, spin, spin_id, verbosity=1): """Read the model-free data for the spin. @param spin_line: The line of data for a single spin. @type spin_line: list of str @param col: The column indices. @type col: dict of int @param data_set: The data set type, one of 'value', 'error', or 'sim_xxx' (where xxx is a number). @type data_set: str @param spin: The spin container. @type spin: SpinContainer instance @param spin_id: The spin identification string. @type spin_id: str @keyword verbosity: A variable specifying the amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int """ # Set up the model-free models. if data_set == 'value': # Get the model-free model. model = spin_line[col['model']] if model == 'None': model = None # Get the model-free equation. equation = spin_line[col['eqi']] if equation == 'None': equation = None # Get the model-free parameters. params = eval(spin_line[col['params']]) # Loop over and convert the parameters. if params: for i in range(len(params)): # Fix for the 1.2 relax versions whereby the parameter 'tm' was renamed to 'local_tm' (which occurred in version 1.2.5). if params[i] == 'tm': params[i] = 'local_tm' # Lower case conversion. params[i] = params[i].lower() # Set up the model-free model. model_setup(model=model, equation=equation, params=params, spin_id=spin_id) # The model type. model_type = spin_line[col['param_set']] # Get the interatomic data container. spin = return_spin(spin_id) interatom = return_interatom_list(spin_hash=spin._hash)[0] # Values. if data_set == 'value': # S2. try: spin.s2 = float(spin_line[ col['s2']]) * api_model_free.return_conversion_factor('s2') except ValueError: spin.s2 = None # S2f. try: spin.s2f = float(spin_line[ col['s2f']]) * api_model_free.return_conversion_factor('s2f') except ValueError: spin.s2f = None # S2s. try: spin.s2s = float(spin_line[ col['s2s']]) * api_model_free.return_conversion_factor('s2s') except ValueError: spin.s2s = None # Local tm. try: spin.local_tm = float( spin_line[col['local_tm']] ) * api_model_free.return_conversion_factor('local_tm') except ValueError: spin.local_tm = None # te. try: spin.te = float(spin_line[ col['te']]) * api_model_free.return_conversion_factor('te') except ValueError: spin.te = None # tf. try: spin.tf = float(spin_line[ col['tf']]) * api_model_free.return_conversion_factor('tf') except ValueError: spin.tf = None # ts. try: spin.ts = float(spin_line[ col['ts']]) * api_model_free.return_conversion_factor('ts') except ValueError: spin.ts = None # Rex. try: spin.rex = float(spin_line[ col['rex']]) * api_model_free.return_conversion_factor('rex') except ValueError: spin.rex = None # CSA. try: spin.csa = float(spin_line[ col['csa']]) * api_model_free.return_conversion_factor('csa') except ValueError: spin.csa = None # Minimisation details (global minimisation results). if model_type == 'diff' or model_type == 'all': cdp.chi2 = eval(spin_line[col['chi2']]) cdp.iter = eval(spin_line[col['iter']]) cdp.f_count = eval(spin_line[col['f_count']]) cdp.g_count = eval(spin_line[col['g_count']]) cdp.h_count = eval(spin_line[col['h_count']]) if spin_line[col['warn']] == 'None': cdp.warning = None else: cdp.warning = spin_line[col['warn']].replace('_', ' ') # Minimisation details (individual residue results). else: spin.chi2 = eval(spin_line[col['chi2']]) spin.iter = eval(spin_line[col['iter']]) spin.f_count = eval(spin_line[col['f_count']]) spin.g_count = eval(spin_line[col['g_count']]) spin.h_count = eval(spin_line[col['h_count']]) if spin_line[col['warn']] == 'None': spin.warning = None else: spin.warning = spin_line[col['warn']].replace('_', ' ') # Interatomic distances. try: interatom.r = float(spin_line[col['r']]) * 1e-10 except ValueError: interatom.r = None # Errors. if data_set == 'error': # S2. try: spin.s2_err = float(spin_line[ col['s2']]) * api_model_free.return_conversion_factor('s2') except ValueError: spin.s2_err = None # S2f. try: spin.s2f_err = float(spin_line[ col['s2f']]) * api_model_free.return_conversion_factor('s2f') except ValueError: spin.s2f_err = None # S2s. try: spin.s2s_err = float(spin_line[ col['s2s']]) * api_model_free.return_conversion_factor('s2s') except ValueError: spin.s2s_err = None # Local tm. try: spin.local_tm_err = float( spin_line[col['local_tm']] ) * api_model_free.return_conversion_factor('local_tm') except ValueError: spin.local_tm_err = None # te. try: spin.te_err = float(spin_line[ col['te']]) * api_model_free.return_conversion_factor('te') except ValueError: spin.te_err = None # tf. try: spin.tf_err = float(spin_line[ col['tf']]) * api_model_free.return_conversion_factor('tf') except ValueError: spin.tf_err = None # ts. try: spin.ts_err = float(spin_line[ col['ts']]) * api_model_free.return_conversion_factor('ts') except ValueError: spin.ts_err = None # Rex. try: spin.rex_err = float(spin_line[ col['rex']]) * api_model_free.return_conversion_factor('rex') except ValueError: spin.rex_err = None # CSA. try: spin.csa_err = float(spin_line[ col['csa']]) * api_model_free.return_conversion_factor('csa') except ValueError: spin.csa_err = None # Construct the simulation data structures. if data_set == 'sim_0': # Get the parameter object names. param_names = api_model_free.data_names(set='params', scope='spin') # Get the minimisation statistic object names. min_names = api_model_free.data_names(set='min', scope='spin') # Loop over all the parameter names. for object_name in param_names: # Name for the simulation object. sim_object_name = object_name + '_sim' # Create the simulation object. setattr(spin, sim_object_name, []) # Loop over all the minimisation object names. for object_name in min_names: # Name for the simulation object. sim_object_name = object_name + '_sim' # Create the simulation object. if model_type == 'diff' or model_type == 'all': setattr(cdp, sim_object_name, []) object = getattr(cdp, sim_object_name) object = [] else: setattr(spin, sim_object_name, []) # Simulations. if data_set != 'value' and data_set != 'error': # S2. try: spin.s2_sim.append( float(spin_line[col['s2']]) * api_model_free.return_conversion_factor('s2')) except ValueError: spin.s2_sim.append(None) # S2f. try: spin.s2f_sim.append( float(spin_line[col['s2f']]) * api_model_free.return_conversion_factor('s2f')) except ValueError: spin.s2f_sim.append(None) # S2s. try: spin.s2s_sim.append( float(spin_line[col['s2s']]) * api_model_free.return_conversion_factor('s2s')) except ValueError: spin.s2s_sim.append(None) # Local tm. try: spin.local_tm_sim.append( float(spin_line[col['local_tm']]) * api_model_free.return_conversion_factor('local_tm')) except ValueError: spin.local_tm_sim.append(None) # te. try: spin.te_sim.append( float(spin_line[col['te']]) * api_model_free.return_conversion_factor('te')) except ValueError: spin.te_sim.append(None) # tf. try: spin.tf_sim.append( float(spin_line[col['tf']]) * api_model_free.return_conversion_factor('tf')) except ValueError: spin.tf_sim.append(None) # ts. try: spin.ts_sim.append( float(spin_line[col['ts']]) * api_model_free.return_conversion_factor('ts')) except ValueError: spin.ts_sim.append(None) # Rex. try: spin.rex_sim.append( float(spin_line[col['rex']]) * api_model_free.return_conversion_factor('rex')) except ValueError: spin.rex_sim.append(None) # CSA. try: spin.csa_sim.append( float(spin_line[col['csa']]) * api_model_free.return_conversion_factor('csa')) except ValueError: spin.csa_sim.append(None) # Minimisation details (global minimisation results). if model_type == 'diff' or model_type == 'all': # The simulation index. index = int(data_set.split('_')[1]) # Already loaded. if len(cdp.chi2_sim) == index + 1: return # Set the values. cdp.chi2_sim.append(eval(spin_line[col['chi2']])) cdp.iter_sim.append(eval(spin_line[col['iter']])) cdp.f_count_sim.append(eval(spin_line[col['f_count']])) cdp.g_count_sim.append(eval(spin_line[col['g_count']])) cdp.h_count_sim.append(eval(spin_line[col['h_count']])) if spin_line[col['warn']] == 'None': cdp.warning_sim.append(None) else: cdp.warning_sim.append(spin_line[col['warn']].replace( '_', ' ')) # Minimisation details (individual residue results). else: spin.chi2_sim.append(eval(spin_line[col['chi2']])) spin.iter_sim.append(eval(spin_line[col['iter']])) spin.f_count_sim.append(eval(spin_line[col['f_count']])) spin.g_count_sim.append(eval(spin_line[col['g_count']])) spin.h_count_sim.append(eval(spin_line[col['h_count']])) if spin_line[col['warn']] == 'None': spin.warning_sim.append(None) else: spin.warning_sim.append(spin_line[col['warn']].replace( '_', ' '))
def test_angles(self): """The user function angles().""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'angles.py') # Res info. res_name = ['GLY', 'PRO', 'LEU', 'GLY', 'SER', 'MET', 'ASP', 'SER', 'PRO', 'PRO', 'GLU', 'GLY'] spin_num = [1, 10, 24, 43, 50, 61, 78, 90, 101, 115, 129, 144] spin_name = ['N']*12 attached_atoms = [None, None, 'H', 'H', 'H', 'H', 'H', 'H', None, None, 'H', 'H'] xh_vects = [ None, None, [0.408991870425, -0.805744582632, 0.428370537602], [-0.114123686687, -0.989411605119, -0.0896686109685], [-0.0162975723187, -0.975817142584, 0.217980029763], [-0.255934111969, -0.960517663248, -0.109103386377], [0.922628022844, 0.38092966093, 0.0604162634271], [0.926402811426, 0.281593806116, 0.249965516299], None, None, [0.820296708196, 0.570330671495, -0.0428513205774], [-0.223383112106, -0.034680483158, -0.974113571055] ] alpha = [None, None, 2.8102691247870459, 2.6063738282640672, 2.9263088853837358, 2.5181004004450211, 1.3361463581932049, 1.5031623128368377, None, None, 1.0968465542222101, 1.1932423104331247] # Molecule checks. self.assertEqual(len(cdp.mol), 1) self.assertEqual(cdp.mol[0].name, 'Ap4Aase_res1-12_mol1') self.assertEqual(len(cdp.mol[0].res), 12) # Checks for the first 12 residues. for i in range(12): # Check the residue and spin info. self.assertEqual(cdp.mol[0].res[i].num, i+1) self.assertEqual(cdp.mol[0].res[i].name, res_name[i]) self.assertEqual(cdp.mol[0].res[i].spin[0].num, spin_num[i]) self.assertEqual(cdp.mol[0].res[i].spin[0].name, spin_name[i]) # Get the interatomic container. interatoms = return_interatom_list(cdp.mol[0].res[i].spin[0]._spin_ids[0]) # Check the containers. self.assert_(len(interatoms) <= 1) # No interatomic container. if not interatoms: # The spin info. self.assertEqual(len(cdp.mol[0].res[i].spin), 1) # Check the interatomic info. else: # The spin info. self.assertEqual(len(cdp.mol[0].res[i].spin), 2) self.assertEqual(cdp.mol[0].res[i].spin[1].name, attached_atoms[i]) # The vector. for j in range(3): self.assertAlmostEqual(interatoms[0].vector[j], xh_vects[i][j]) # Check the alpha angles. self.assertAlmostEqual(interatoms[0].alpha, alpha[i])
def bmrb_write(star): """Generate the relaxation data saveframes for the NMR-STAR dictionary object. @param star: The NMR-STAR dictionary object. @type star: NMR_STAR instance """ # Get the current data pipe. cdp = pipes.get_pipe() # Initialise the spin specific data lists. mol_name_list = [] res_num_list = [] res_name_list = [] atom_name_list = [] isotope_list = [] element_list = [] attached_atom_name_list = [] attached_isotope_list = [] attached_element_list = [] ri_data_list = [] ri_data_err_list = [] for i in range(len(cdp.ri_ids)): ri_data_list.append([]) ri_data_err_list.append([]) # Relax data labels. labels = cdp.ri_ids exp_label = [] spectro_ids = [] spectro_labels = [] # Store the spin specific data in lists for later use. for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True): # Skip spins with no relaxation data. if not hasattr(spin, 'ri_data'): continue # Check the data for None (not allowed in BMRB!). if res_num == None: raise RelaxError("For the BMRB, the residue of spin '%s' must be numbered." % spin_id) if res_name == None: raise RelaxError("For the BMRB, the residue of spin '%s' must be named." % spin_id) if spin.name == None: raise RelaxError("For the BMRB, the spin '%s' must be named." % spin_id) if spin.isotope == None: raise RelaxError("For the BMRB, the spin isotope type of '%s' must be specified." % spin_id) # The molecule/residue/spin info. mol_name_list.append(mol_name) res_num_list.append(str(res_num)) res_name_list.append(str(res_name)) atom_name_list.append(str(spin.name)) # Interatomic info. interatoms = return_interatom_list(spin_id) if len(interatoms) == 0: raise RelaxError("No interatomic interactions are defined for the spin '%s'." % spin_id) if len(interatoms) > 1: raise RelaxError("The BMRB only handles a signal interatomic interaction for the spin '%s'." % spin_id) # Get the attached spin. spin_attached = return_spin(interatoms[0].spin_id1) if id(spin_attached) == id(spin): spin_attached = return_spin(interatoms[0].spin_id2) # The attached atom info. if hasattr(spin_attached, 'name'): attached_atom_name_list.append(str(spin_attached.name)) else: attached_atom_name_list.append(None) if hasattr(spin_attached, 'isotope'): attached_element_list.append(element_from_isotope(spin_attached.isotope)) attached_isotope_list.append(str(number_from_isotope(spin_attached.isotope))) else: attached_element_list.append(None) attached_isotope_list.append(None) # The relaxation data. used_index = -ones(len(cdp.ri_ids)) for i in range(len(cdp.ri_ids)): # Data exists. if cdp.ri_ids[i] in list(spin.ri_data.keys()): ri_data_list[i].append(str(spin.ri_data[cdp.ri_ids[i]])) ri_data_err_list[i].append(str(spin.ri_data_err[cdp.ri_ids[i]])) else: ri_data_list[i].append(None) ri_data_err_list[i].append(None) # Other info. isotope_list.append(int(spin.isotope.strip(string.ascii_letters))) element_list.append(spin.element) # Convert the molecule names into the entity IDs. entity_ids = zeros(len(mol_name_list), int32) mol_names = get_molecule_names() for i in range(len(mol_name_list)): for j in range(len(mol_names)): if mol_name_list[i] == mol_names[j]: entity_ids[i] = j+1 # Check the temperature control methods. if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_calibration'): raise RelaxError("The temperature calibration methods have not been specified.") if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_control'): raise RelaxError("The temperature control methods have not been specified.") # Check the peak intensity type. if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'peak_intensity_type'): raise RelaxError("The peak intensity types measured for the relaxation data have not been specified.") # Loop over the relaxation data. for i in range(len(cdp.ri_ids)): # Alias. ri_id = cdp.ri_ids[i] ri_type = cdp.ri_type[ri_id] # Convert to MHz. frq = cdp.spectrometer_frq[ri_id] * 1e-6 # Get the temperature control methods. temp_calib = cdp.exp_info.temp_calibration[ri_id] temp_control = cdp.exp_info.temp_control[ri_id] # Get the peak intensity type. peak_intensity_type = cdp.exp_info.peak_intensity_type[ri_id] # Check. if not temp_calib: raise RelaxError("The temperature calibration method for the '%s' relaxation data ID string has not been specified." % ri_id) if not temp_control: raise RelaxError("The temperature control method for the '%s' relaxation data ID string has not been specified." % ri_id) # Add the relaxation data. star.relaxation.add(data_type=ri_type, frq=frq, entity_ids=entity_ids, res_nums=res_num_list, res_names=res_name_list, atom_names=atom_name_list, atom_types=element_list, isotope=isotope_list, entity_ids_2=entity_ids, res_nums_2=res_num_list, res_names_2=res_name_list, atom_names_2=attached_atom_name_list, atom_types_2=attached_element_list, isotope_2=attached_isotope_list, data=ri_data_list[i], errors=ri_data_err_list[i], temp_calibration=temp_calib, temp_control=temp_control, peak_intensity_type=peak_intensity_type) # The experimental label. if ri_type == 'NOE': exp_name = 'steady-state NOE' else: exp_name = ri_type exp_label.append("%s MHz %s" % (frq, exp_name)) # Spectrometer info. frq_num = 1 for frq in loop_frequencies(): if frq == cdp.spectrometer_frq[ri_id]: break frq_num += 1 spectro_ids.append(frq_num) spectro_labels.append("$spectrometer_%s" % spectro_ids[-1]) # Add the spectrometer info. num = 1 for frq in loop_frequencies(): star.nmr_spectrometer.add(name="$spectrometer_%s" % num, manufacturer=None, model=None, frq=int(frq/1e6)) num += 1 # Add the experiment saveframe. star.experiment.add(name=exp_label, spectrometer_ids=spectro_ids, spectrometer_labels=spectro_labels)
def create_script(file, model_type, algor): """Create the Dasha script file. @param file: The opened file descriptor. @type file: file object @param model_type: The model-free model type. @type model_type: str @param algor: The optimisation algorithm to use. This can be the Levenberg-Marquardt algorithm 'LM' or the Newton-Raphson algorithm 'NR'. @type algor: str """ # Delete all data. file.write("# Delete all data.\n") file.write("del 1 10000\n") # Nucleus type. file.write("\n# Nucleus type.\n") nucleus = None for spin in spin_loop(): # Skip protons. if spin.isotope == '1H': continue # Can only handle one spin type. if nucleus and spin.isotope != nucleus: raise RelaxError( "The nuclei '%s' and '%s' do not match, relax can only handle one nucleus type in Dasha." % (nucleus, spin.isotope)) # Set the nucleus. if not nucleus: nucleus = spin.isotope # Convert the name and write it. if nucleus == '15N': nucleus = 'N15' elif nucleus == '13C': nucleus = 'C13' else: raise RelaxError("Cannot handle the nucleus type '%s' within Dasha." % nucleus) file.write("set nucl %s\n" % nucleus) # Number of frequencies. file.write("\n# Number of frequencies.\n") file.write("set n_freq %s\n" % cdp.spectrometer_frq_count) # Frequency values. file.write("\n# Frequency values.\n") count = 1 for frq in loop_frequencies(): file.write("set H1_freq %s %s\n" % (frq / 1e6, count)) count += 1 # Set the diffusion tensor. file.write("\n# Set the diffusion tensor.\n") if model_type != 'local_tm': # Sphere. if cdp.diff_tensor.type == 'sphere': file.write("set tr %s\n" % (cdp.diff_tensor.tm / 1e-9)) # Spheroid. elif cdp.diff_tensor.type == 'spheroid': file.write('set tr %s\n' % (cdp.diff_tensor.tm / 1e-9)) # Ellipsoid. elif cdp.diff_tensor.type == 'ellipsoid': # Get the eigenvales. Dx, Dy, Dz = diffusion_tensor.return_eigenvalues() # Geometric parameters. file.write("set tr %s\n" % (cdp.diff_tensor.tm / 1e-9)) file.write("set D1/D3 %s\n" % (Dx / Dz)) file.write("set D2/D3 %s\n" % (Dy / Dz)) # Orientational parameters. file.write("set alfa %s\n" % (cdp.diff_tensor.alpha / (2.0 * pi) * 360.0)) file.write("set betta %s\n" % (cdp.diff_tensor.beta / (2.0 * pi) * 360.0)) file.write("set gamma %s\n" % (cdp.diff_tensor.gamma / (2.0 * pi) * 360.0)) # Reading the relaxation data. file.write("\n# Reading the relaxation data.\n") file.write("echo Reading the relaxation data.\n") noe_index = 1 r1_index = 1 r2_index = 1 for ri_id in cdp.ri_ids: # NOE. if cdp.ri_type[ri_id] == 'NOE': # Data set number. number = noe_index # Data type. data_type = 'noe' # Increment the data set index. noe_index = noe_index + 1 # R1. elif cdp.ri_type[ri_id] == 'R1': # Data set number. number = r1_index # Data type. data_type = '1/T1' # Increment the data set index. r1_index = r1_index + 1 # R2. elif cdp.ri_type[ri_id] == 'R2': # Data set number. number = r2_index # Data type. data_type = '1/T2' # Increment the data set index. r2_index = r2_index + 1 # Set the data type. if number == 1: file.write("\nread < %s\n" % data_type) else: file.write("\nread < %s %s\n" % (data_type, number)) # The relaxation data. for residue in residue_loop(): # Alias the spin. spin = residue.spin[0] # Skip deselected spins. if not spin.select: continue # Skip and deselect spins for which relaxation data is missing. if len(spin.ri_data) != len( cdp.ri_ids) or spin.ri_data[ri_id] == None: spin.select = False continue # Data and errors. file.write( "%s %s %s\n" % (residue.num, spin.ri_data[ri_id], spin.ri_data_err[ri_id])) # Terminate the reading. file.write("exit\n") # Individual residue optimisation. if model_type == 'mf': # Loop over the residues. for residue in residue_loop(): # Alias the spin. spin = residue.spin[0] # Skip deselected spins. if not spin.select: continue # Get the interatomic data containers. interatoms = return_interatom_list(spin_hash=spin._hash) if len(interatoms) == 0: raise RelaxNoInteratomError elif len(interatoms) > 1: raise RelaxError( "Only one interatomic data container, hence dipole-dipole interaction, is supported per spin." ) # Comment. file.write("\n\n\n# Residue %s\n\n" % residue.num) # Echo. file.write("echo Optimisation of residue %s\n" % residue.num) # Select the spin. file.write("\n# Select the residue.\n") file.write("set cres %s\n" % residue.num) # The angle alpha of the XH vector in the spheroid diffusion frame. if cdp.diff_tensor.type == 'spheroid': file.write("set teta %s\n" % spin.alpha) # The angles theta and phi of the XH vector in the ellipsoid diffusion frame. elif cdp.diff_tensor.type == 'ellipsoid': file.write( "\n# Setting the spherical angles of the XH vector in the ellipsoid diffusion frame.\n" ) file.write("set teta %s\n" % spin.theta) file.write("set fi %s\n" % spin.phi) # The 'jmode'. if 'ts' in spin.params: jmode = 3 elif 'te' in spin.params: jmode = 2 elif 's2' in spin.params: jmode = 1 # Chemical exchange. if 'rex' in spin.params: exch = True else: exch = False # Anisotropic diffusion. if cdp.diff_tensor.type == 'sphere': anis = False else: anis = True # Axial symmetry. if cdp.diff_tensor.type == 'spheroid': sym = True else: sym = False # Set the jmode. file.write("\n# Set the jmode.\n") file.write("set def jmode %s" % jmode) if exch: file.write(" exch") if anis: file.write(" anis") if sym: file.write(" sym") file.write("\n") # Parameter default values. file.write("\n# Parameter default values.\n") file.write("reset jmode %s\n" % residue.num) # Bond length. file.write("\n# Bond length.\n") file.write("set r_hx %s\n" % (interatoms[0].r / 1e-10)) # CSA value. file.write("\n# CSA value.\n") file.write("set csa %s\n" % (spin.csa / 1e-6)) # Fix the tf parameter if it isn't in the model. if not 'tf' in spin.params and jmode == 3: file.write("\n# Fix the tf parameter.\n") file.write("fix tf 0\n") # Optimisation of all residues. file.write("\n\n\n# Optimisation of all residues.\n") if algor == 'LM': file.write("lmin %s %s" % (first_residue_num(), last_residue_num())) elif algor == 'NR': file.write("min %s %s" % (first_residue_num(), last_residue_num())) # Show the results. file.write("\n# Show the results.\n") file.write("echo\n") file.write("show all\n") # Write the results. file.write("\n# Write the results.\n") file.write("write s2.out S\n") file.write("write s2f.out Sf\n") file.write("write s2s.out Ss\n") file.write("write te.out te\n") file.write("write tf.out tf\n") file.write("write ts.out ts\n") file.write("write rex.out rex\n") file.write("write chi2.out F\n") else: raise RelaxError( "Optimisation of the parameter set '%s' currently not supported." % model_type)
def create_script(file, model_type, algor): """Create the Dasha script file. @param file: The opened file descriptor. @type file: file object @param model_type: The model-free model type. @type model_type: str @param algor: The optimisation algorithm to use. This can be the Levenberg-Marquardt algorithm 'LM' or the Newton-Raphson algorithm 'NR'. @type algor: str """ # Delete all data. file.write("# Delete all data.\n") file.write("del 1 10000\n") # Nucleus type. file.write("\n# Nucleus type.\n") nucleus = None for spin in spin_loop(): # Skip protons. if spin.isotope == '1H': continue # Can only handle one spin type. if nucleus and spin.isotope != nucleus: raise RelaxError("The nuclei '%s' and '%s' do not match, relax can only handle one nucleus type in Dasha." % (nucleus, spin.isotope)) # Set the nucleus. if not nucleus: nucleus = spin.isotope # Convert the name and write it. if nucleus == '15N': nucleus = 'N15' elif nucleus == '13C': nucleus = 'C13' else: raise RelaxError("Cannot handle the nucleus type '%s' within Dasha." % nucleus) file.write("set nucl %s\n" % nucleus) # Number of frequencies. file.write("\n# Number of frequencies.\n") file.write("set n_freq %s\n" % cdp.spectrometer_frq_count) # Frequency values. file.write("\n# Frequency values.\n") count = 1 for frq in loop_frequencies(): file.write("set H1_freq %s %s\n" % (frq / 1e6, count)) count += 1 # Set the diffusion tensor. file.write("\n# Set the diffusion tensor.\n") if model_type != 'local_tm': # Sphere. if cdp.diff_tensor.type == 'sphere': file.write("set tr %s\n" % (cdp.diff_tensor.tm / 1e-9)) # Spheroid. elif cdp.diff_tensor.type == 'spheroid': file.write('set tr %s\n' % (cdp.diff_tensor.tm / 1e-9)) # Ellipsoid. elif cdp.diff_tensor.type == 'ellipsoid': # Get the eigenvales. Dx, Dy, Dz = diffusion_tensor.return_eigenvalues() # Geometric parameters. file.write("set tr %s\n" % (cdp.diff_tensor.tm / 1e-9)) file.write("set D1/D3 %s\n" % (Dx / Dz)) file.write("set D2/D3 %s\n" % (Dy / Dz)) # Orientational parameters. file.write("set alfa %s\n" % (cdp.diff_tensor.alpha / (2.0 * pi) * 360.0)) file.write("set betta %s\n" % (cdp.diff_tensor.beta / (2.0 * pi) * 360.0)) file.write("set gamma %s\n" % (cdp.diff_tensor.gamma / (2.0 * pi) * 360.0)) # Reading the relaxation data. file.write("\n# Reading the relaxation data.\n") file.write("echo Reading the relaxation data.\n") noe_index = 1 r1_index = 1 r2_index = 1 for ri_id in cdp.ri_ids: # NOE. if cdp.ri_type[ri_id] == 'NOE': # Data set number. number = noe_index # Data type. data_type = 'noe' # Increment the data set index. noe_index = noe_index + 1 # R1. elif cdp.ri_type[ri_id] == 'R1': # Data set number. number = r1_index # Data type. data_type = '1/T1' # Increment the data set index. r1_index = r1_index + 1 # R2. elif cdp.ri_type[ri_id] == 'R2': # Data set number. number = r2_index # Data type. data_type = '1/T2' # Increment the data set index. r2_index = r2_index + 1 # Set the data type. if number == 1: file.write("\nread < %s\n" % data_type) else: file.write("\nread < %s %s\n" % (data_type, number)) # The relaxation data. for residue in residue_loop(): # Alias the spin. spin = residue.spin[0] # Skip deselected spins. if not spin.select: continue # Skip and deselect spins for which relaxation data is missing. if len(spin.ri_data) != len(cdp.ri_ids) or spin.ri_data[ri_id] == None: spin.select = False continue # Data and errors. file.write("%s %s %s\n" % (residue.num, spin.ri_data[ri_id], spin.ri_data_err[ri_id])) # Terminate the reading. file.write("exit\n") # Individual residue optimisation. if model_type == 'mf': # Loop over the residues. for residue in residue_loop(): # Alias the spin. spin = residue.spin[0] # Skip deselected spins. if not spin.select: continue # Get the interatomic data containers. interatoms = return_interatom_list(spin._spin_ids[0]) if len(interatoms) == 0: raise RelaxNoInteratomError elif len(interatoms) > 1: raise RelaxError("Only one interatomic data container, hence dipole-dipole interaction, is supported per spin.") # Comment. file.write("\n\n\n# Residue %s\n\n" % residue.num) # Echo. file.write("echo Optimisation of residue %s\n" % residue.num) # Select the spin. file.write("\n# Select the residue.\n") file.write("set cres %s\n" % residue.num) # The angle alpha of the XH vector in the spheroid diffusion frame. if cdp.diff_tensor.type == 'spheroid': file.write("set teta %s\n" % spin.alpha) # The angles theta and phi of the XH vector in the ellipsoid diffusion frame. elif cdp.diff_tensor.type == 'ellipsoid': file.write("\n# Setting the spherical angles of the XH vector in the ellipsoid diffusion frame.\n") file.write("set teta %s\n" % spin.theta) file.write("set fi %s\n" % spin.phi) # The 'jmode'. if 'ts' in spin.params: jmode = 3 elif 'te' in spin.params: jmode = 2 elif 's2' in spin.params: jmode = 1 # Chemical exchange. if 'rex' in spin.params: exch = True else: exch = False # Anisotropic diffusion. if cdp.diff_tensor.type == 'sphere': anis = False else: anis = True # Axial symmetry. if cdp.diff_tensor.type == 'spheroid': sym = True else: sym = False # Set the jmode. file.write("\n# Set the jmode.\n") file.write("set def jmode %s" % jmode) if exch: file.write(" exch") if anis: file.write(" anis") if sym: file.write(" sym") file.write("\n") # Parameter default values. file.write("\n# Parameter default values.\n") file.write("reset jmode %s\n" % residue.num) # Bond length. file.write("\n# Bond length.\n") file.write("set r_hx %s\n" % (interatoms[0].r / 1e-10)) # CSA value. file.write("\n# CSA value.\n") file.write("set csa %s\n" % (spin.csa / 1e-6)) # Fix the tf parameter if it isn't in the model. if not 'tf' in spin.params and jmode == 3: file.write("\n# Fix the tf parameter.\n") file.write("fix tf 0\n") # Optimisation of all residues. file.write("\n\n\n# Optimisation of all residues.\n") if algor == 'LM': file.write("lmin %s %s" % (first_residue_num(), last_residue_num())) elif algor == 'NR': file.write("min %s %s" % (first_residue_num(), last_residue_num())) # Show the results. file.write("\n# Show the results.\n") file.write("echo\n") file.write("show all\n") # Write the results. file.write("\n# Write the results.\n") file.write("write s2.out S\n") file.write("write s2f.out Sf\n") file.write("write s2s.out Ss\n") file.write("write te.out te\n") file.write("write tf.out tf\n") file.write("write ts.out ts\n") file.write("write rex.out rex\n") file.write("write chi2.out F\n") else: raise RelaxError("Optimisation of the parameter set '%s' currently not supported." % model_type)
def calculate(self, spin_id=None, scaling_matrix=None, verbosity=1, sim_index=None): """Calculation of the spectral density values. @keyword spin_id: The spin identification string. @type spin_id: None or str @keyword scaling_matrix: The per-model list of diagonal and square scaling matrices. @type scaling_matrix: list of numpy rank-2, float64 array or list of None @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int @keyword sim_index: The optional MC simulation index. @type sim_index: None or int """ # Test if the frequency has been set. if not hasattr(cdp, 'jw_frq') or not isinstance(cdp.jw_frq, float): raise RelaxError("The frequency has not been set up.") # Test if the sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Test if the spin data has been set. for spin, id in spin_loop(spin_id, return_id=True): # Skip deselected spins. if not spin.select: continue # Test if the nuclear isotope type has been set. if not hasattr(spin, 'isotope'): raise RelaxSpinTypeError # Test if the CSA value has been set. if not hasattr(spin, 'csa') or spin.csa == None: raise RelaxNoValueError("CSA") # Test the interatomic data. interatoms = return_interatom_list(id) for interatom in interatoms: # No relaxation mechanism. if not interatom.dipole_pair: continue # The interacting spin. if id != interatom.spin_id1: spin_id2 = interatom.spin_id1 else: spin_id2 = interatom.spin_id2 spin2 = return_spin(spin_id2) # Test if the nuclear isotope type has been set. if not hasattr(spin2, 'isotope'): raise RelaxSpinTypeError # Test if the interatomic distance has been set. if not hasattr(interatom, 'r') or interatom.r == None: raise RelaxNoValueError("interatomic distance", spin_id=spin_id, spin_id2=spin_id2) # Frequency index. if cdp.jw_frq not in list(cdp.spectrometer_frq.values()): raise RelaxError("No relaxation data corresponding to the frequency " + repr(cdp.jw_frq) + " has been loaded.") # Reduced spectral density mapping. for spin, id in spin_loop(spin_id, return_id=True): # Skip deselected spins. if not spin.select: continue # Set the r1, r2, and NOE to None. r1 = None r2 = None noe = None # Get the R1, R2, and NOE values corresponding to the set frequency. for ri_id in cdp.ri_ids: # The frequency does not match. if cdp.spectrometer_frq[ri_id] != cdp.jw_frq: continue # R1. if cdp.ri_type[ri_id] == 'R1': if sim_index == None: r1 = spin.ri_data[ri_id] else: r1 = spin.ri_data_sim[ri_id][sim_index] # R2. if cdp.ri_type[ri_id] == 'R2': if sim_index == None: r2 = spin.ri_data[ri_id] else: r2 = spin.ri_data_sim[ri_id][sim_index] # NOE. if cdp.ri_type[ri_id] == 'NOE': if sim_index == None: noe = spin.ri_data[ri_id] else: noe = spin.ri_data_sim[ri_id][sim_index] # Skip the spin if not all of the three value exist. if r1 == None or r2 == None or noe == None: continue # Loop over the interatomic data. interatoms = return_interatom_list(id) for i in range(len(interatoms)): # No relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id2) # Gyromagnetic ratios. gx = periodic_table.gyromagnetic_ratio(spin.isotope) gh = periodic_table.gyromagnetic_ratio(spin2.isotope) # The interatomic distance. r = interatoms[i].r # Initialise the function to calculate. jw = Mapping(frq=cdp.jw_frq, gx=gx, gh=gh, mu0=mu0, h_bar=h_bar) # Calculate the spectral density values. j0, jwx, jwh = jw.func(r=r, csa=spin.csa, r1=r1, r2=r2, noe=noe) # Reduced spectral density values. if sim_index == None: spin.j0 = j0 spin.jwx = jwx spin.jwh = jwh # Monte Carlo simulated reduced spectral density values. else: # Initialise the simulation data structures. self.data_init(id, sim=1) if spin.j0_sim == None: spin.j0_sim = [] spin.jwx_sim = [] spin.jwh_sim = [] # Reduced spectral density values. spin.j0_sim.append(j0) spin.jwx_sim.append(jwx) spin.jwh_sim.append(jwh)
def overfit_deselect(self, data_check=True, verbose=True): """Deselect spins which have insufficient data to support calculation. @keyword data_check: A flag to signal if the presence of base data is to be checked for. @type data_check: bool @keyword verbose: A flag which if True will allow printouts. @type verbose: bool """ # Print out. if verbose: print("\nOver-fit spin deselection:") # Test the sequence data exists. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError # Loop over spin data. deselect_flag = False spin_count = 0 for spin, spin_id in spin_loop(return_id=True): # Skip deselected spins. if not spin.select: continue # The interatomic data. interatoms = return_interatom_list(spin_id) # Loop over the interatomic data. dipole_relax = False for i in range(len(interatoms)): # No dipolar relaxation mechanism. if not interatoms[i].dipole_pair: continue # The surrounding spins. if spin_id != interatoms[i].spin_id1: spin_id2 = interatoms[i].spin_id1 else: spin_id2 = interatoms[i].spin_id2 spin2 = return_spin(spin_id2) # Dipolar relaxation flag. dipole_relax = True # No relaxation mechanism. if not dipole_relax or not hasattr(spin, 'csa') or spin.csa == None: warn(RelaxDeselectWarning(spin_id, 'an absence of relaxation mechanisms')) spin.select = False deselect_flag = True continue # Data checks. if data_check: # The number of relaxation data points (and for infinite data). data_points = 0 inf_data = False if hasattr(cdp, 'ri_ids') and hasattr(spin, 'ri_data'): for id in cdp.ri_ids: if id in spin.ri_data and spin.ri_data[id] != None: data_points += 1 # Infinite data! if isInf(spin.ri_data[id]): inf_data = True # Infinite data. if inf_data: warn(RelaxDeselectWarning(spin_id, 'infinite relaxation data')) spin.select = False deselect_flag = True continue # Relaxation data must exist! if not hasattr(spin, 'ri_data'): warn(RelaxDeselectWarning(spin_id, 'missing relaxation data')) spin.select = False deselect_flag = True continue # Require 3 or more relaxation data points. if data_points < 3: warn(RelaxDeselectWarning(spin_id, 'insufficient relaxation data, 3 or more data points are required')) spin.select = False deselect_flag = True continue # Increment the spin number. spin_count += 1 # No spins selected, so fail hard to prevent the user from going any further. if spin_count == 0: warn(RelaxWarning("No spins are selected therefore the optimisation or calculation cannot proceed.")) # Final printout. if verbose and not deselect_flag: print("No spins have been deselected.")
def load_model_free_data(spin_line, col, data_set, spin, spin_id, verbosity=1): """Read the model-free data for the spin. @param spin_line: The line of data for a single spin. @type spin_line: list of str @param col: The column indices. @type col: dict of int @param data_set: The data set type, one of 'value', 'error', or 'sim_xxx' (where xxx is a number). @type data_set: str @param spin: The spin container. @type spin: SpinContainer instance @param spin_id: The spin identification string. @type spin_id: str @keyword verbosity: A variable specifying the amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int """ # Set up the model-free models. if data_set == "value": # Get the model-free model. model = spin_line[col["model"]] if model == "None": model = None # Get the model-free equation. equation = spin_line[col["eqi"]] if equation == "None": equation = None # Get the model-free parameters. params = eval(spin_line[col["params"]]) # Loop over and convert the parameters. if params: for i in range(len(params)): # Fix for the 1.2 relax versions whereby the parameter 'tm' was renamed to 'local_tm' (which occurred in version 1.2.5). if params[i] == "tm": params[i] = "local_tm" # Lower case conversion. params[i] = params[i].lower() # Set up the model-free model. model_setup(model=model, equation=equation, params=params, spin_id=spin_id) # The model type. model_type = spin_line[col["param_set"]] # Get the interatomic data container. interatom = return_interatom_list(spin_id)[0] # Values. if data_set == "value": # S2. try: spin.s2 = float(spin_line[col["s2"]]) * api_model_free.return_conversion_factor("s2") except ValueError: spin.s2 = None # S2f. try: spin.s2f = float(spin_line[col["s2f"]]) * api_model_free.return_conversion_factor("s2f") except ValueError: spin.s2f = None # S2s. try: spin.s2s = float(spin_line[col["s2s"]]) * api_model_free.return_conversion_factor("s2s") except ValueError: spin.s2s = None # Local tm. try: spin.local_tm = float(spin_line[col["local_tm"]]) * api_model_free.return_conversion_factor("local_tm") except ValueError: spin.local_tm = None # te. try: spin.te = float(spin_line[col["te"]]) * api_model_free.return_conversion_factor("te") except ValueError: spin.te = None # tf. try: spin.tf = float(spin_line[col["tf"]]) * api_model_free.return_conversion_factor("tf") except ValueError: spin.tf = None # ts. try: spin.ts = float(spin_line[col["ts"]]) * api_model_free.return_conversion_factor("ts") except ValueError: spin.ts = None # Rex. try: spin.rex = float(spin_line[col["rex"]]) * api_model_free.return_conversion_factor("rex") except ValueError: spin.rex = None # CSA. try: spin.csa = float(spin_line[col["csa"]]) * api_model_free.return_conversion_factor("csa") except ValueError: spin.csa = None # Minimisation details (global minimisation results). if model_type == "diff" or model_type == "all": cdp.chi2 = eval(spin_line[col["chi2"]]) cdp.iter = eval(spin_line[col["iter"]]) cdp.f_count = eval(spin_line[col["f_count"]]) cdp.g_count = eval(spin_line[col["g_count"]]) cdp.h_count = eval(spin_line[col["h_count"]]) if spin_line[col["warn"]] == "None": cdp.warning = None else: cdp.warning = spin_line[col["warn"]].replace("_", " ") # Minimisation details (individual residue results). else: spin.chi2 = eval(spin_line[col["chi2"]]) spin.iter = eval(spin_line[col["iter"]]) spin.f_count = eval(spin_line[col["f_count"]]) spin.g_count = eval(spin_line[col["g_count"]]) spin.h_count = eval(spin_line[col["h_count"]]) if spin_line[col["warn"]] == "None": spin.warning = None else: spin.warning = spin_line[col["warn"]].replace("_", " ") # Interatomic distances. try: interatom.r = float(spin_line[col["r"]]) * 1e-10 except ValueError: interatom.r = None # Errors. if data_set == "error": # S2. try: spin.s2_err = float(spin_line[col["s2"]]) * api_model_free.return_conversion_factor("s2") except ValueError: spin.s2_err = None # S2f. try: spin.s2f_err = float(spin_line[col["s2f"]]) * api_model_free.return_conversion_factor("s2f") except ValueError: spin.s2f_err = None # S2s. try: spin.s2s_err = float(spin_line[col["s2s"]]) * api_model_free.return_conversion_factor("s2s") except ValueError: spin.s2s_err = None # Local tm. try: spin.local_tm_err = float(spin_line[col["local_tm"]]) * api_model_free.return_conversion_factor("local_tm") except ValueError: spin.local_tm_err = None # te. try: spin.te_err = float(spin_line[col["te"]]) * api_model_free.return_conversion_factor("te") except ValueError: spin.te_err = None # tf. try: spin.tf_err = float(spin_line[col["tf"]]) * api_model_free.return_conversion_factor("tf") except ValueError: spin.tf_err = None # ts. try: spin.ts_err = float(spin_line[col["ts"]]) * api_model_free.return_conversion_factor("ts") except ValueError: spin.ts_err = None # Rex. try: spin.rex_err = float(spin_line[col["rex"]]) * api_model_free.return_conversion_factor("rex") except ValueError: spin.rex_err = None # CSA. try: spin.csa_err = float(spin_line[col["csa"]]) * api_model_free.return_conversion_factor("csa") except ValueError: spin.csa_err = None # Construct the simulation data structures. if data_set == "sim_0": # Get the parameter object names. param_names = api_model_free.data_names(set="params", scope="spin") # Get the minimisation statistic object names. min_names = api_model_free.data_names(set="min", scope="spin") # Loop over all the parameter names. for object_name in param_names: # Name for the simulation object. sim_object_name = object_name + "_sim" # Create the simulation object. setattr(spin, sim_object_name, []) # Loop over all the minimisation object names. for object_name in min_names: # Name for the simulation object. sim_object_name = object_name + "_sim" # Create the simulation object. if model_type == "diff" or model_type == "all": setattr(cdp, sim_object_name, []) object = getattr(cdp, sim_object_name) object = [] else: setattr(spin, sim_object_name, []) # Simulations. if data_set != "value" and data_set != "error": # S2. try: spin.s2_sim.append(float(spin_line[col["s2"]]) * api_model_free.return_conversion_factor("s2")) except ValueError: spin.s2_sim.append(None) # S2f. try: spin.s2f_sim.append(float(spin_line[col["s2f"]]) * api_model_free.return_conversion_factor("s2f")) except ValueError: spin.s2f_sim.append(None) # S2s. try: spin.s2s_sim.append(float(spin_line[col["s2s"]]) * api_model_free.return_conversion_factor("s2s")) except ValueError: spin.s2s_sim.append(None) # Local tm. try: spin.local_tm_sim.append( float(spin_line[col["local_tm"]]) * api_model_free.return_conversion_factor("local_tm") ) except ValueError: spin.local_tm_sim.append(None) # te. try: spin.te_sim.append(float(spin_line[col["te"]]) * api_model_free.return_conversion_factor("te")) except ValueError: spin.te_sim.append(None) # tf. try: spin.tf_sim.append(float(spin_line[col["tf"]]) * api_model_free.return_conversion_factor("tf")) except ValueError: spin.tf_sim.append(None) # ts. try: spin.ts_sim.append(float(spin_line[col["ts"]]) * api_model_free.return_conversion_factor("ts")) except ValueError: spin.ts_sim.append(None) # Rex. try: spin.rex_sim.append(float(spin_line[col["rex"]]) * api_model_free.return_conversion_factor("rex")) except ValueError: spin.rex_sim.append(None) # CSA. try: spin.csa_sim.append(float(spin_line[col["csa"]]) * api_model_free.return_conversion_factor("csa")) except ValueError: spin.csa_sim.append(None) # Minimisation details (global minimisation results). if model_type == "diff" or model_type == "all": # The simulation index. index = int(data_set.split("_")[1]) # Already loaded. if len(cdp.chi2_sim) == index + 1: return # Set the values. cdp.chi2_sim.append(eval(spin_line[col["chi2"]])) cdp.iter_sim.append(eval(spin_line[col["iter"]])) cdp.f_count_sim.append(eval(spin_line[col["f_count"]])) cdp.g_count_sim.append(eval(spin_line[col["g_count"]])) cdp.h_count_sim.append(eval(spin_line[col["h_count"]])) if spin_line[col["warn"]] == "None": cdp.warning_sim.append(None) else: cdp.warning_sim.append(spin_line[col["warn"]].replace("_", " ")) # Minimisation details (individual residue results). else: spin.chi2_sim.append(eval(spin_line[col["chi2"]])) spin.iter_sim.append(eval(spin_line[col["iter"]])) spin.f_count_sim.append(eval(spin_line[col["f_count"]])) spin.g_count_sim.append(eval(spin_line[col["g_count"]])) spin.h_count_sim.append(eval(spin_line[col["h_count"]])) if spin_line[col["warn"]] == "None": spin.warning_sim.append(None) else: spin.warning_sim.append(spin_line[col["warn"]].replace("_", " "))