def id_match(spin_id=None, interatom=None, pipe=None): """Test if the spin ID matches one of the two spins of the given container. @keyword spin_id: The spin ID string of the first atom. @type spin_id: str @keyword interatom: The interatomic data container. @type interatom: InteratomContainer instance @keyword pipe: The data pipe containing the interatomic data container. Defaults to the current data pipe. @type pipe: str or None @return: True if the spin ID matches one of the two spins, False otherwise. @rtype: bool """ # Get the spin containers. spin1 = return_spin(interatom.spin_id1, pipe=pipe) spin2 = return_spin(interatom.spin_id2, pipe=pipe) # No spins. if spin1 == None or spin2 == None: return False # Check if the ID is in the private metadata list. if spin_id in spin1._spin_ids or spin_id in spin2._spin_ids: return True # Nothing found. return False
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 create_interatom(spin_id1=None, spin_id2=None, spin1=None, spin2=None, pipe=None, verbose=False): """Create and return the interatomic data container for the two spins. @keyword spin_id1: The spin ID string of the first atom. @type spin_id1: str @keyword spin_id2: The spin ID string of the second atom. @type spin_id2: str @keyword spin1: The optional spin container for the first atom. This is for speeding up the interatomic data container creation, if the spin containers are already available in the calling function. @type spin1: str @keyword spin2: The optional spin container for the second atom. This is for speeding up the interatomic data container creation, if the spin containers are already available in the calling function. @type spin2: str @keyword pipe: The data pipe to create the interatomic data container for. This defaults to the current data pipe if not supplied. @type pipe: str or None @keyword verbose: A flag which if True will result printouts. @type verbose: bool @return: The newly created interatomic data container. @rtype: data.interatomic.InteratomContainer instance """ # Printout. if verbose: print("Creating an interatomic data container between the spins '%s' and '%s'." % (spin_id1, spin_id2)) # The data pipe. if pipe == None: pipe = pipes.cdp_name() # Get the data pipe. dp = pipes.get_pipe(pipe) # Check that the spin IDs exist. if spin1 == None: spin1 = return_spin(spin_id=spin_id1, pipe=pipe) if spin1 == None: raise RelaxNoSpinError(spin_id1) if spin2 == None: spin2 = return_spin(spin_id=spin_id2, pipe=pipe) if spin2 == None: raise RelaxNoSpinError(spin_id2) # Check if the two spin IDs have already been added. for i in range(len(dp.interatomic)): if spin1._hash != spin2._hash and spin1._hash in [dp.interatomic[i]._spin_hash1, dp.interatomic[i]._spin_hash2] and spin2._hash in [dp.interatomic[i]._spin_hash1, dp.interatomic[i]._spin_hash2]: raise RelaxError("The spin pair %s and %s have already been added." % (spin_id1, spin_id2)) # Add the data. interatom = dp.interatomic.add_item(spin_id1=spin_id1, spin_id2=spin_id2, spin_hash1=spin1._hash, spin_hash2=spin2._hash) # Store the interatom hash in the spin containers. spin1._interatomic_hashes.append(interatom._hash) spin2._interatomic_hashes.append(interatom._hash) # Return the interatomic data container. return interatom
def test_tm_51ns(self): """Test the elimination of a model-free model with the local tm = 51 ns.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'local_tm_model_elimination.py') # Checks. self.assert_(return_spin(':13').select) self.assert_(return_spin(':14').select) self.assert_(not return_spin(':15').select) self.assert_(return_spin(':16').select)
def test_tm_51ns(self): """Test the elimination of a model-free model with the local tm = 51 ns.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'local_tm_model_elimination.py') # Checks. self.assert_(return_spin(spin_id=':13').select) self.assert_(return_spin(spin_id=':14').select) self.assert_(not return_spin(spin_id=':15').select) self.assert_(return_spin(spin_id=':16').select)
def set_dist(spin_id1=None, spin_id2=None, ave_dist=None, unit='meter'): """Set up the magnetic dipole-dipole interaction. @keyword spin_id1: The spin identifier string of the first spin of the pair. @type spin_id1: str @keyword spin_id2: The spin identifier string of the second spin of the pair. @type spin_id2: str @keyword ave_dist: The r^-3 averaged interatomic distance. @type ave_dist: float @keyword unit: The measurement unit. This can be either 'meter' or 'Angstrom'. @type unit: str """ # Check the units. if unit not in ['meter', 'Angstrom']: raise RelaxError("The measurement unit of '%s' must be one of 'meter' or 'Angstrom'." % unit) # Unit conversion. if unit == 'Angstrom': ave_dist = ave_dist * 1e-10 # Generate the selection objects. sel_obj1 = Selection(spin_id1) sel_obj2 = Selection(spin_id2) # Loop over the interatomic containers. data = [] for interatom in interatomic_loop(): # Get the spin info. mol_name1, res_num1, res_name1, spin1 = return_spin(spin_hash=interatom._spin_hash1, full_info=True) mol_name2, res_num2, res_name2, spin2 = return_spin(spin_hash=interatom._spin_hash2, full_info=True) # No match, either way. if not (sel_obj1.contains_spin(spin_num=spin1.num, spin_name=spin1.name, res_num=res_num1, res_name=res_name1, mol=mol_name1) and sel_obj2.contains_spin(spin_num=spin2.num, spin_name=spin2.name, res_num=res_num2, res_name=res_name2, mol=mol_name2)) and not (sel_obj2.contains_spin(spin_num=spin1.num, spin_name=spin1.name, res_num=res_num1, res_name=res_name1, mol=mol_name1) and sel_obj1.contains_spin(spin_num=spin2.num, spin_name=spin2.name, res_num=res_num2, res_name=res_name2, mol=mol_name2)): continue # Store the averaged distance. interatom.r = ave_dist # Store the data for the printout. data.append([repr(interatom.spin_id1), repr(interatom.spin_id2), repr(ave_dist)]) # No data, so fail! if not len(data): raise RelaxError("No data could be set.") # Print out. print("The following averaged distances have been set:\n") write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", "Ave_distance(meters)"], data=data)
def set_dist(spin_id1=None, spin_id2=None, ave_dist=None, unit='meter'): """Set up the magnetic dipole-dipole interaction. @keyword spin_id1: The spin identifier string of the first spin of the pair. @type spin_id1: str @keyword spin_id2: The spin identifier string of the second spin of the pair. @type spin_id2: str @keyword ave_dist: The r^-3 averaged interatomic distance. @type ave_dist: float @keyword unit: The measurement unit. This can be either 'meter' or 'Angstrom'. @type unit: str """ # Check the units. if unit not in ['meter', 'Angstrom']: raise RelaxError("The measurement unit of '%s' must be one of 'meter' or 'Angstrom'." % unit) # Unit conversion. if unit == 'Angstrom': ave_dist = ave_dist * 1e-10 # Generate the selection objects. sel_obj1 = Selection(spin_id1) sel_obj2 = Selection(spin_id2) # Loop over the interatomic containers. data = [] for interatom in interatomic_loop(): # Get the spin info. mol_name1, res_num1, res_name1, spin1 = return_spin(interatom.spin_id1, full_info=True) mol_name2, res_num2, res_name2, spin2 = return_spin(interatom.spin_id2, full_info=True) # No match, either way. if not (sel_obj1.contains_spin(spin_num=spin1.num, spin_name=spin1.name, res_num=res_num1, res_name=res_name1, mol=mol_name1) and sel_obj2.contains_spin(spin_num=spin2.num, spin_name=spin2.name, res_num=res_num2, res_name=res_name2, mol=mol_name2)) and not (sel_obj2.contains_spin(spin_num=spin1.num, spin_name=spin1.name, res_num=res_num1, res_name=res_name1, mol=mol_name1) and sel_obj1.contains_spin(spin_num=spin2.num, spin_name=spin2.name, res_num=res_num2, res_name=res_name2, mol=mol_name2)): continue # Store the averaged distance. interatom.r = ave_dist # Store the data for the printout. data.append([repr(interatom.spin_id1), repr(interatom.spin_id2), repr(ave_dist)]) # No data, so fail! if not len(data): raise RelaxError("No data could be set.") # Print out. print("The following averaged distances have been set:\n") write_data(out=sys.stdout, headings=["Spin_ID_1", "Spin_ID_2", "Ave_distance(meters)"], data=data)
def generate_sequence(N=0, spin_ids=None, spin_nums=None, spin_names=None, res_nums=None, res_names=None, mol_names=None, isotopes=None, elements=None): """Generate the sequence data from the BRMB information. @keyword N: The number of spins. @type N: int @keyword spin_ids: The list of spin IDs. @type spin_ids: list of str @keyword spin_nums: The list of spin numbers. @type spin_nums: list of int or None @keyword spin_names: The list of spin names. @type spin_names: list of str or None @keyword res_nums: The list of residue numbers. @type res_nums: list of int or None @keyword res_names: The list of residue names. @type res_names: list of str or None @keyword mol_names: The list of molecule names. @type mol_names: list of str or None @keyword isotopes: The optional list of isotope types. @type isotopes: list of str or None @keyword elements: The optional list of element types. @type elements: list of str or None """ # The blank data. if not spin_nums: spin_nums = [None] * N if not spin_names: spin_names = [None] * N if not res_nums: res_nums = [None] * N if not res_names: res_names = [None] * N if not mol_names: mol_names = [None] * N # Generate the spin IDs. spin_ids = [] for i in range(N): spin_ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], spin_name=spin_names[i])) # Loop over the spin data. for i in range(N): # The spin already exists. spin = return_spin(spin_ids[i]) if spin: continue # Create the spin. spin = create_spin(spin_num=spin_nums[i], spin_name=spin_names[i], res_num=res_nums[i], res_name=res_names[i], mol_name=mol_names[i]) # Set the spin isotope and element. spin_id = spin._spin_ids[0] if elements: set_spin_element(spin_id=spin_id, element=elements[i], force=True) if isotopes and elements: isotope = "%s%s" % (isotopes[i], elements[i]) set_spin_isotope(spin_id=spin_id, isotope=isotope, force=True) # Clean up the spin metadata. metadata_cleanup()
def _sf_csa_read(self, star): """Place the CSA data from the saveframe records into the spin container. @param star: The NMR-STAR dictionary object. @type star: NMR_STAR instance """ # Get the entities. for data in star.chem_shift_anisotropy.loop(): # The number of spins. N = bmrb.num_spins(data) # No data in the saveframe. if N == 0: continue # The molecule names. mol_names = bmrb.molecule_names(data, N) # Loop over the spins. for i in range(len(data['data_ids'])): # Generate a spin ID. spin_id = mol_res_spin.generate_spin_id_unique(mol_name=mol_names[i], res_num=data['res_nums'][i], spin_name=data['atom_names'][i]) # Obtain the spin. spin = mol_res_spin.return_spin(spin_id) # The CSA value (converted from ppm). setattr(spin, 'csa', data['csa'][i] * 1e-6)
def i0_upper(incs=None, model_info=None): """Find the maximum peak intensity for the cluster. This is for the grid search upper bound for the I0 parameter. @keyword incs: The number of grid search increments. @type incs: int @keyword model_info: The spin containers and the spin ID strings from the model_loop() specific API method. @type model_info: list of SpinContainer instances, list of str @return: The maximum peak intensity of all spins and time points. @rtype: float """ # Alias. spin_ids = model_info # Find the maximum intensity. upper = 0.0 for si in range(len(spin_ids)): spin = return_spin(spin_ids[si]) upper = max(upper, max(spin.peak_intensity.values())) # Multiply the value by 2.0 and then round up to the next order - this will be the upper bound. return round_to_next_order(upper * 2.0)
def prune_spin(self, mol_branch_id, res_branch_id, res_id): """Remove any spins which have been deleted. @param mol_branch_id: The molecule branch ID of the wx.TreeCtrl object. @type mol_branch_id: TreeItemId @param res_branch_id: The residue branch ID of the wx.TreeCtrl object. @type res_branch_id: TreeItemId @param res_id: The residue identification string. @type res_id: str """ # Find if the molecule has been removed. prune_list = [] for key in self.tree_ids[mol_branch_id][res_branch_id]: # Get the python data. info = self.tree.GetItemPyData(key) # No info. if info == None or 'id' not in info: continue # Get the spin. spin = return_spin(spin_id=info['id']) # Add to the prune list if it has been removed or renamed/renumbered. if spin == None or spin.name != info['spin_name'] or spin.num != info['spin_num']: prune_list.append(key) # Delete the data. for key in prune_list: self.tree.Delete(key) self.tree_ids[mol_branch_id][res_branch_id].pop(key)
def data_init(self, data, sim=False): """Initialise the data structures. @param data: The spin ID string from the _base_data_loop_spin() method. @type data: str @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure. @type sim: bool """ # Get the spin container. spin = return_spin(data) # Get the data names. data_names = self.data_names() # Loop over the data structure names. for name in data_names: # Simulation data structures. if sim: # Add '_sim' to the names. name = name + '_sim' # If the name is not in the spin container, add it. if not hasattr(spin, name): # Set the attribute. setattr(spin, name, None)
def _sim_pack_relax_data(self, data_id, sim_data): """Pack the Monte Carlo simulation relaxation data into the corresponding spin container. @param data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @param sim_data: The Monte Carlo simulation data. @type sim_data: list of float """ # Get the spin container. spin = return_spin(spin_id=data_id) # Initialise the data structure. spin.ri_data_sim = {} # Loop over the relaxation data. for i in range(len(cdp.ri_ids)): # The ID. ri_id = cdp.ri_ids[i] # Initialise the MC data list. spin.ri_data_sim[ri_id] = [] # Loop over the simulations. for j in range(cdp.sim_number): spin.ri_data_sim[ri_id].append(sim_data[j][i])
def _return_error_relax_data(self, data_id): """Return the Ri error structure for the corresponding spin. @param data_id: The data identification information, as yielded by the base_data_loop() generator method. @type data_id: str @return: The array of relaxation data error values. @rtype: list of float """ # Get the spin container. spin = return_spin(spin_id=data_id) # Convert to a list. error = [] for ri_id in cdp.ri_ids: # Handle missing data/errors. if ri_id not in spin.ri_data_err: error.append(None) # Append the value. else: error.append(spin.ri_data_err[ri_id]) # Return the list. return error
def _data_init_spin(self, data, sim=False): """Initialise data structures (spin system specific). @param data: The spin ID string from the _base_data_loop_spin() method. @type data: str @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure. @type sim: bool """ # Alias the data and get the spin container. spin_id = data spin = return_spin(spin_id) # Loop over the parameters. for name in self._PARAMS.loop(set="params", scope="spin", error_names=False, sim_names=sim): # Not a parameter of the model. if name not in spin.params: continue # The value already exists. if hasattr(spin, name): continue # The default value. param_type = self._PARAMS.type(name) if param_type == dict: value = {} elif param_type == list: value = [] else: value = None # Set the value. setattr(spin, name, value)
def _sim_pack_relax_data(self, data_id, sim_data): """Pack the Monte Carlo simulation relaxation data into the corresponding spin container. @param data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @param sim_data: The Monte Carlo simulation data. @type sim_data: list of float """ # Get the spin container. spin = return_spin(data_id) # Initialise the data structure. spin.ri_data_sim = {} # Loop over the relaxation data. for i in range(len(cdp.ri_ids)): # The ID. ri_id = cdp.ri_ids[i] # Initialise the MC data list. spin.ri_data_sim[ri_id] = [] # Loop over the simulations. for j in range(cdp.sim_number): spin.ri_data_sim[ri_id].append(sim_data[j][i])
def _return_error_relax_data(self, data_id): """Return the Ri error structure for the corresponding spin. @param data_id: The data identification information, as yielded by the base_data_loop() generator method. @type data_id: str @return: The array of relaxation data error values. @rtype: list of float """ # Get the spin container. spin = return_spin(data_id) # Convert to a list. error = [] for ri_id in cdp.ri_ids: # Handle missing data/errors. if ri_id not in spin.ri_data_err: error.append(None) # Append the value. else: error.append(spin.ri_data_err[ri_id]) # Return the list. return error
def data_init(self, data, sim=False): """Initialise the spin specific data structures. @param data: The spin ID string from the _base_data_loop_spin() method. @type data: str @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure. @type sim: bool """ # Get the spin container. spin = return_spin(spin_id=data) # Loop over the data structure names. for name in self.data_names(set='params'): # Data structures which are initially empty arrays. list_data = [ 'params' ] if name in list_data: init_data = [] # Otherwise initialise the data structure to None. else: init_data = None # If the name is not in the spin container, add it. if not hasattr(spin, name): setattr(spin, name, init_data)
def i0_upper(incs=None, model_info=None): """Find the maximum peak intensity for the cluster. This is for the grid search upper bound for the I0 parameter. @keyword incs: The number of grid search increments. @type incs: int @keyword model_info: The spin containers and the spin ID strings from the model_loop() specific API method. @type model_info: list of SpinContainer instances, list of str @return: The maximum peak intensity of all spins and time points. @rtype: float """ # Alias. spin_ids = model_info # Find the maximum intensity. upper = 0.0 for si in range(len(spin_ids)): spin = return_spin(spin_id=spin_ids[si]) upper = max(upper, max(spin.peak_intensity.values())) # Multiply the value by 2.0 and then round up to the next order - this will be the upper bound. return round_to_next_order(upper * 2.0)
def sf_csa_read(star): """Place the CSA data from the saveframe records into the spin container. @param star: The NMR-STAR dictionary object. @type star: NMR_STAR instance """ # Get the entities. for data in star.chem_shift_anisotropy.loop(): # The number of spins. N = bmrb.num_spins(data) # No data in the saveframe. if N == 0: continue # The molecule names. mol_names = bmrb.molecule_names(data, N) # Loop over the spins. for i in range(len(data['data_ids'])): # Generate a spin ID. spin_id = mol_res_spin.generate_spin_id_unique( mol_name=mol_names[i], res_num=data['res_nums'][i], spin_name=data['atom_names'][i]) # Obtain the spin. spin = mol_res_spin.return_spin(spin_id=spin_id) # The CSA value (converted from ppm). setattr(spin, 'csa', data['csa'][i] * 1e-6)
def hash_update(interatom=None, pipe=None): """Recreate the spin hashes for the interatomic data container. @keyword interatom: The interatomic data container. @type interatom: InteratomContainer instance @keyword pipe: The data pipe containing the interatomic data container. Defaults to the current data pipe. @type pipe: str or None """ # Fetch the spin containers. spin1 = return_spin(spin_hash=interatom._spin_hash1, pipe=pipe) spin2 = return_spin(spin_hash=interatom._spin_hash2, pipe=pipe) # Reset the hashes. interatom._spin_hash1 = spin1._hash interatom._spin_hash2 = spin2._hash
def data_init(self, data, sim=False): """Initialise the spin specific data structures. @param data: The spin ID string from the _base_data_loop_spin() method. @type data: str @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure. @type sim: bool """ # Get the spin container. spin = return_spin(data) # Loop over the data structure names. for name in self.data_names(set='params'): # Data structures which are initially empty arrays. list_data = [ 'params' ] if name in list_data: init_data = [] # Otherwise initialise the data structure to None. else: init_data = None # If the name is not in the spin container, add it. if not hasattr(spin, name): setattr(spin, name, init_data)
def data_init(self, data, sim=False): """Initialise the data structures. @param data: The spin ID string from the _base_data_loop_spin() method. @type data: str @keyword sim: The Monte Carlo simulation flag, which if true will initialise the simulation data structure. @type sim: bool """ # Get the spin container. spin = return_spin(spin_id=data) # Get the data names. data_names = self.data_names() # Loop over the data structure names. for name in data_names: # Simulation data structures. if sim: # Add '_sim' to the names. name = name + '_sim' # If the name is not in the spin container, add it. if not hasattr(spin, name): # Set the attribute. setattr(spin, name, None)
def prune_spin(self, mol_branch_id, res_branch_id, res_id): """Remove any spins which have been deleted. @param mol_branch_id: The molecule branch ID of the wx.TreeCtrl object. @type mol_branch_id: TreeItemId @param res_branch_id: The residue branch ID of the wx.TreeCtrl object. @type res_branch_id: TreeItemId @param res_id: The residue identification string. @type res_id: str """ # Find if the molecule has been removed. prune_list = [] for key in self.tree_ids[mol_branch_id][res_branch_id]: # Get the python data. info = self.tree.GetItemPyData(key) # No info. if info == None or 'id' not in info: continue # Get the spin. spin = return_spin(info['id']) # Add to the prune list if it has been removed or renamed/renumbered. if spin == None or spin.name != info['spin_name'] or spin.num != info['spin_num']: prune_list.append(key) # Delete the data. for key in prune_list: self.tree.Delete(key) self.tree_ids[mol_branch_id][res_branch_id].pop(key)
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 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 set(val=None, error=None, param=None, scaling=None, spin_id=None): """Set global or spin specific minimisation parameters. @keyword val: The parameter values. @type val: number @keyword param: The parameter names. @type param: str @keyword scaling: Unused. @type scaling: float @keyword spin_id: The spin identification string. @type spin_id: str """ # Global minimisation stats. if spin_id == None: # Chi-squared. if param == 'chi2': cdp.chi2 = val # Iteration count. elif param == 'iter': cdp.iter = val # Function call count. elif param == 'f_count': cdp.f_count = val # Gradient call count. elif param == 'g_count': cdp.g_count = val # Hessian call count. elif param == 'h_count': cdp.h_count = val # Residue specific minimisation. else: # Get the spin. spin = return_spin(spin_id) # Chi-squared. if param == 'chi2': spin.chi2 = val # Iteration count. elif param == 'iter': spin.iter = val # Function call count. elif param == 'f_count': spin.f_count = val # Gradient call count. elif param == 'g_count': spin.g_count = val # Hessian call count. elif param == 'h_count': spin.h_count = val
def set(val=None, error=None, param=None, scaling=None, spin_id=None): """Set global or spin specific minimisation parameters. @keyword val: The parameter values. @type val: number @keyword param: The parameter names. @type param: str @keyword scaling: Unused. @type scaling: float @keyword spin_id: The spin identification string. @type spin_id: str """ # Global minimisation stats. if spin_id == None: # Chi-squared. if param == 'chi2': cdp.chi2 = val # Iteration count. elif param == 'iter': cdp.iter = val # Function call count. elif param == 'f_count': cdp.f_count = val # Gradient call count. elif param == 'g_count': cdp.g_count = val # Hessian call count. elif param == 'h_count': cdp.h_count = val # Residue specific minimisation. else: # Get the spin. spin = return_spin(spin_id=spin_id) # Chi-squared. if param == 'chi2': spin.chi2 = val # Iteration count. elif param == 'iter': spin.iter = val # Function call count. elif param == 'f_count': spin.f_count = val # Gradient call count. elif param == 'g_count': spin.g_count = val # Hessian call count. elif param == 'h_count': spin.h_count = val
def test_te_200ns(self): """Test the elimination of a model-free model with te = 200 ns.""" # Read a results file. self.interpreter.results.read(file='final_results_trunc_1.3_v2', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'model_free'+sep+'OMP') # Set the te value for residue 11 Leu to 200 ns. self.interpreter.value.set(200*1e-9, 'te', spin_id=":11") # Model elimination. self.interpreter.eliminate() # Checks. self.assert_(return_spin(spin_id=':9@N').select) self.assert_(return_spin(spin_id=':10@N').select) self.assert_(not return_spin(spin_id=':11@N').select) self.assert_(return_spin(spin_id=':12@N').select)
def test_te_200ns(self): """Test the elimination of a model-free model with te = 200 ns.""" # Read a results file. self.interpreter.results.read(file='final_results_trunc_1.3_v2', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'model_free'+sep+'OMP') # Set the te value for residue 11 Leu to 200 ns. self.interpreter.value.set(200*1e-9, 'te', spin_id=":11") # Model elimination. self.interpreter.eliminate() # Checks. self.assert_(return_spin(':9@N').select) self.assert_(return_spin(':10@N').select) self.assert_(not return_spin(':11@N').select) self.assert_(return_spin(':12@N').select)
def calc_ave_dist(atom1, atom2, exp=1): """Calculate the average distances. The formula used is:: _N_ / 1 \ \ 1/exp <r> = | - > |p1i - p2i|^exp | \ N /__ / i where i are the members of the ensemble, N is the total number of structural models, and p1 and p2 at the two atom positions. @param atom1: The atom identification string of the first atom. @type atom1: str @param atom2: The atom identification string of the second atom. @type atom2: str @keyword exp: The exponent used for the averaging, e.g. 1 for linear averaging and -6 for r^-6 NOE averaging. @type exp: int @return: The average distance between the two atoms. @rtype: float """ # Get the spin containers. spin1 = return_spin(atom1) spin2 = return_spin(atom2) # Loop over each model. num_models = len(spin1.pos) ave_dist = 0.0 for i in range(num_models): # Distance to the minus sixth power. dist = norm(spin1.pos[i] - spin2.pos[i]) ave_dist = ave_dist + dist**(exp) # Average. ave_dist = ave_dist / num_models # The exponent. ave_dist = ave_dist**(1.0/exp) # Return the average distance. return ave_dist
def calc_ave_dist(atom1, atom2, exp=1): """Calculate the average distances. The formula used is:: _N_ / 1 \ \ 1/exp <r> = | - > |p1i - p2i|^exp | \ N /__ / i where i are the members of the ensemble, N is the total number of structural models, and p1 and p2 at the two atom positions. @param atom1: The atom identification string of the first atom. @type atom1: str @param atom2: The atom identification string of the second atom. @type atom2: str @keyword exp: The exponent used for the averaging, e.g. 1 for linear averaging and -6 for r^-6 NOE averaging. @type exp: int @return: The average distance between the two atoms. @rtype: float """ # Get the spin containers. spin1 = return_spin(spin_id=atom1) spin2 = return_spin(spin_id=atom2) # Loop over each model. num_models = len(spin1.pos) ave_dist = 0.0 for i in range(num_models): # Distance to the minus sixth power. dist = norm(spin1.pos[i] - spin2.pos[i]) ave_dist = ave_dist + dist**(exp) # Average. ave_dist = ave_dist / num_models # The exponent. ave_dist = ave_dist**(1.0/exp) # Return the average distance. return ave_dist
def return_error(self, data_id): """Return the RDC or PCS error structure. @param data_id: The data set as yielded by the base_data_loop() generator method. @type data_id: list of str @return: The array of RDC or PCS error values. @rtype: list of float """ # Initialise the MC data structure. mc_errors = [] # The RDC data. if data_id[0] == 'rdc': # Unpack the set. data_type, spin_hash1, spin_hash2, align_id = data_id # Get the interatomic data container. interatom = return_interatom(spin_hash1=spin_hash1, spin_hash2=spin_hash2) # Do errors exist? if not hasattr(interatom, 'rdc_err'): raise RelaxError( "The RDC errors are missing for interatomic data container between spins '%s' and '%s'." % (spin_id1, spin_id2)) # Handle missing data. if align_id not in interatom.rdc_err: mc_errors.append(None) # Append the data. else: mc_errors.append(interatom.rdc_err[align_id]) # The PCS data. elif data_id[0] == 'pcs': # Unpack the set. data_type, spin_id, align_id = data_id # Get the spin container. spin = return_spin(spin_id=spin_id) # Do errors exist? if not hasattr(spin, 'pcs_err'): raise RelaxError("The PCS errors are missing for spin '%s'." % spin_id) # Handle missing data. if align_id not in spin.pcs_err: mc_errors.append(None) # Append the data. else: mc_errors.append(spin.pcs_err[align_id]) # Return the errors. return mc_errors
def create_mc_data(self, data_id=None): """Create the Monte Carlo data by back calculating the RDCs or PCSs. @keyword data_id: The data set as yielded by the base_data_loop() generator method. @type data_id: list of str @return: The Monte Carlo simulation data. @rtype: list of floats """ # Initialise the MC data structure. mc_data = [] # The RDC data. if data_id[0] == 'rdc': # Unpack the set. data_type, spin_hash1, spin_hash2, align_id = data_id # Get the interatomic data container. interatom = return_interatom(spin_hash1=spin_hash1, spin_hash2=spin_hash2) # Does back-calculated data exist? if not hasattr(interatom, 'rdc_bc'): self.calculate() # The data. if not hasattr(interatom, 'rdc_bc') or align_id not in interatom.rdc_bc: data = None else: data = interatom.rdc_bc[align_id] # Append the data. mc_data.append(data) # The PCS data. elif data_id[0] == 'pcs': # Unpack the set. data_type, spin_id, align_id = data_id # Get the spin container. spin = return_spin(spin_id=spin_id) # Does back-calculated data exist? if not hasattr(spin, 'pcs_bc'): self.calculate() # The data. if not hasattr(spin, 'pcs_bc') or align_id not in spin.pcs_bc: data = None else: data = spin.pcs_bc[align_id] # Append the data. mc_data.append(data) # Return the data. return mc_data
def read_spins(file=None, dir=None, dim=1, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None, verbose=True): """Read the peak intensity data. @keyword file: The name of the file containing the peak intensities. @type file: str @keyword dir: The directory where the file is located. @type dir: str @keyword dim: The dimension of the peak list to associate the data with. @type dim: int @keyword spin_id_col: The column containing the spin ID strings (used by the generic intensity file format). If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none. @type spin_id_col: int or None @keyword mol_name_col: The column containing the molecule name information (used by the generic intensity file format). If supplied, spin_id_col must be None. @type mol_name_col: int or None @keyword res_name_col: The column containing the residue name information (used by the generic intensity file format). If supplied, spin_id_col must be None. @type res_name_col: int or None @keyword res_num_col: The column containing the residue number information (used by the generic intensity file format). If supplied, spin_id_col must be None. @type res_num_col: int or None @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format). If supplied, spin_id_col must be None. @type spin_name_col: int or None @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None. @type spin_num_col: int or None @keyword sep: The column separator which, if None, defaults to whitespace. @type sep: str or None @keyword spin_id: The spin ID string used to restrict data loading to a subset of all spins. If 'auto' is provided for a NMRPipe seriesTab formatted file, the ID's are auto generated in form of Z_Ai. @type spin_id: None or str @keyword verbose: A flag which if True will cause all relaxation data loaded to be printed out. @type verbose: bool """ # Data checks. check_pipe() # Check the file name. if file == None: raise RelaxError("The file name must be supplied.") # Read the peak list data. peak_list = read_peak_list(file=file, dir=dir, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id) # Loop over the peak_list. created_spins = [] for assign in peak_list: mol_name = assign.mol_names[dim-1] res_num = assign.res_nums[dim-1] res_name = assign.res_names[dim-1] spin_num = assign.spin_nums[dim-1] spin_name = assign.spin_names[dim-1] # Generate the spin_id. spin_id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_name=spin_name) # Check if the spin already exist. if return_spin(spin_id=spin_id) == None: # Create the spin if not exist. create_spin(spin_num=spin_num, spin_name=spin_name, res_num=res_num, res_name=res_name, mol_name=mol_name) # Test that data exists. check_mol_res_spin_data()
def create_mc_data(self, data_id=None): """Create the Monte Carlo data by back calculating the RDCs or PCSs. @keyword data_id: The data set as yielded by the base_data_loop() generator method. @type data_id: list of str @return: The Monte Carlo simulation data. @rtype: list of floats """ # Initialise the MC data structure. mc_data = [] # The RDC data. if data_id[0] == 'rdc': # Unpack the set. data_type, spin_id1, spin_id2, align_id = data_id # Get the interatomic data container. interatom = return_interatom(spin_id1, spin_id2) # Does back-calculated data exist? if not hasattr(interatom, 'rdc_bc'): self.calculate() # The data. if not hasattr(interatom, 'rdc_bc') or align_id not in interatom.rdc_bc: data = None else: data = interatom.rdc_bc[align_id] # Append the data. mc_data.append(data) # The PCS data. elif data_id[0] == 'pcs': # Unpack the set. data_type, spin_id, align_id = data_id # Get the spin container. spin = return_spin(spin_id) # Does back-calculated data exist? if not hasattr(spin, 'pcs_bc'): self.calculate() # The data. if not hasattr(spin, 'pcs_bc') or align_id not in spin.pcs_bc: data = None else: data = spin.pcs_bc[align_id] # Append the data. mc_data.append(data) # Return the data. return mc_data
def setup_pseudoatom_rdc(): """Make sure that the interatom system is properly set up for pseudo-atoms and RDCs. Interatomic data containers between the non-pseudo-atom and the pseudo-atom members will be deselected. """ # Loop over all interatomic data containers. for interatom in interatomic_loop(): # Get the spins. spin1 = return_spin(interatom.spin_id1) spin2 = return_spin(interatom.spin_id2) # Checks. flag1 = is_pseudoatom(spin1) flag2 = is_pseudoatom(spin2) # No pseudo-atoms, so do nothing. if not (flag1 or flag2): continue # Both are pseudo-atoms. if flag1 and flag2: warn(RelaxWarning("Support for both spins being in a dipole pair being pseudo-atoms is not implemented yet, deselecting the interatomic data container for the spin pair '%s' and '%s'." % (interatom.spin_id1, interatom.spin_id2))) interatom.select = False # Alias the pseudo and normal atoms. pseudospin = spin1 base_spin_id = interatom.spin_id2 pseudospin_id = interatom.spin_id1 if flag2: pseudospin = spin2 base_spin_id = interatom.spin_id1 pseudospin_id = interatom.spin_id2 # Loop over the atoms of the pseudo-atom. for spin, spin_id in pseudoatom_loop(pseudospin, return_id=True): # Get the corresponding interatomic data container. pseudo_interatom = return_interatom(spin_id1=spin_id, spin_id2=base_spin_id) # Deselect if needed. if pseudo_interatom.select: warn(RelaxWarning("Deselecting the interatomic data container for the spin pair '%s' and '%s' as it is part of the pseudo-atom system of the spin pair '%s' and '%s'." % (pseudo_interatom.spin_id1, pseudo_interatom.spin_id2, base_spin_id, pseudospin_id))) pseudo_interatom.select = False
def test_zooming_grid_search(self): """Test the relaxation curve fitting C modules.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit_zooming_grid.py') # Check the curve-fitting results (the values are from the optimisation of test_curve_fitting_height()). spin = return_spin(spin_id=":4@N") self.assertAlmostEqual(spin.chi2, 2.9169526515678883) self.assertAlmostEqual(spin.rx, 8.0814894974893967) self.assertAlmostEqual(spin.i0/1e6, 1996050.9699629977/1e6)
def test_saturation_recovery(self): """Test the fitting for the saturation recovery R1 experiment.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit_saturation_recovery.py') # Check the curve-fitting results. spin = return_spin(spin_id=":17@H") self.assertAlmostEqual(spin.chi2, 0.0) self.assertAlmostEqual(spin.rx, 0.5) self.assertAlmostEqual(spin.iinf/1e15, 1.0)
def return_error(self, data_id): """Return the RDC or PCS error structure. @param data_id: The data set as yielded by the base_data_loop() generator method. @type data_id: list of str @return: The array of RDC or PCS error values. @rtype: list of float """ # Initialise the MC data structure. mc_errors = [] # The RDC data. if data_id[0] == 'rdc': # Unpack the set. data_type, spin_id1, spin_id2, align_id = data_id # Get the interatomic data container. interatom = return_interatom(spin_id1, spin_id2) # Do errors exist? if not hasattr(interatom, 'rdc_err'): raise RelaxError("The RDC errors are missing for interatomic data container between spins '%s' and '%s'." % (spin_id1, spin_id2)) # Handle missing data. if align_id not in interatom.rdc_err: mc_errors.append(None) # Append the data. else: mc_errors.append(interatom.rdc_err[align_id]) # The PCS data. elif data_id[0] == 'pcs': # Unpack the set. data_type, spin_id, align_id = data_id # Get the spin container. spin = return_spin(spin_id) # Do errors exist? if not hasattr(spin, 'pcs_err'): raise RelaxError("The PCS errors are missing for spin '%s'." % spin_id) # Handle missing data. if align_id not in spin.pcs_err: mc_errors.append(None) # Append the data. else: mc_errors.append(spin.pcs_err[align_id]) # Return the errors. return mc_errors
def test_inversion_recovery(self): """Test the fitting for the inversion recovery R1 experiment.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit_exp_3param_inv_neg.py') # Check the curve-fitting results. spin = return_spin(spin_id=":4@N") self.assertAlmostEqual(spin.rx, 1.2) self.assertAlmostEqual(spin.i0, -30.0) self.assertAlmostEqual(spin.iinf, 22.0)
def test_saturation_recovery(self): """Test the fitting for the saturation recovery R1 experiment.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit_saturation_recovery.py') # Check the curve-fitting results. spin = return_spin(":17@H") self.assertAlmostEqual(spin.chi2, 0.0) self.assertAlmostEqual(spin.rx, 0.5) self.assertAlmostEqual(spin.iinf/1e15, 1.0)
def test_inversion_recovery(self): """Test the fitting for the inversion recovery R1 experiment.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit_exp_3param_inv_neg.py') # Check the curve-fitting results. spin = return_spin(":4@N") self.assertAlmostEqual(spin.rx, 1.2) self.assertAlmostEqual(spin.i0, -30.0) self.assertAlmostEqual(spin.iinf, 22.0)
def test_zooming_grid_search(self): """Test the relaxation curve fitting C modules.""" # Execute the script. self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit_zooming_grid.py') # Check the curve-fitting results (the values are from the optimisation of test_curve_fitting_height()). spin = return_spin(":4@N") self.assertAlmostEqual(spin.chi2, 2.9169526515678883) self.assertAlmostEqual(spin.rx, 8.0814894974893967) self.assertAlmostEqual(spin.i0/1e6, 1996050.9699629977/1e6)
def create_interatom(spin_id1=None, spin_id2=None, pipe=None, verbose=False): """Create and return the interatomic data container for the two spins. @keyword spin_id1: The spin ID string of the first atom. @type spin_id1: str @keyword spin_id2: The spin ID string of the second atom. @type spin_id2: str @keyword pipe: The data pipe to create the interatomic data container for. This defaults to the current data pipe if not supplied. @type pipe: str or None @keyword verbose: A flag which if True will result printouts. @type verbose: bool @return: The newly created interatomic data container. @rtype: data.interatomic.InteratomContainer instance """ # Printout. if verbose: print("Creating an interatomic data container between the spins '%s' and '%s'." % (spin_id1, spin_id2)) # The data pipe. if pipe == None: pipe = pipes.cdp_name() # Get the data pipe. dp = pipes.get_pipe(pipe) # Check that the spin IDs exist. spin = return_spin(spin_id1, pipe) if spin == None: raise RelaxNoSpinError(spin_id1) spin = return_spin(spin_id2, pipe) if spin == None: raise RelaxNoSpinError(spin_id2) # Check if the two spin IDs have already been added. for i in range(len(dp.interatomic)): if id_match(spin_id=spin_id1, interatom=dp.interatomic[i], pipe=pipe) and id_match(spin_id=spin_id2, interatom=dp.interatomic[i], pipe=pipe): raise RelaxError("The spin pair %s and %s have already been added." % (spin_id1, spin_id2)) # Add and return the data. return dp.interatomic.add_item(spin_id1=spin_id1, spin_id2=spin_id2)
def is_spin_selected(selection=None): """Query if the spin is selected. @keyword selection: The molecule ID string. @type selection: str """ # Get the spin. spin = return_spin(spin_id=selection) # Return the selected state. return spin.select
def is_spin_selected(selection=None): """Query if the spin is selected. @keyword selection: The molecule ID string. @type selection: str """ # Get the spin. spin = return_spin(selection) # Return the selected state. return spin.select
def metadata_update(interatom_index=None, pipe=None): """Update all of the private look up metadata. @keyword interatom_index: The index of the interatomic data container to update. If not supplied, all containers will be updated. @type interatom_index: int or None @keyword pipe: The data pipe to update, defaulting to the current data pipe. @type pipe: str or None """ # The data pipe. if pipe == None: pipe = pipes.cdp_name() # Test the data pipe. check_pipe(pipe) # Get the data pipe. dp = pipes.get_pipe(pipe) # Loop over the containers. for i in range(len(dp.interatomic)): # Interatom skipping. if interatom_index != None and interatom_index != i: continue # Alias. interatom = dp.interatomic[i] # Get the matching spin from the IDs, rather than from the hashes. spin1 = return_spin(spin_id=interatom.spin_id1, pipe=pipe) spin2 = return_spin(spin_id=interatom.spin_id2, pipe=pipe) # Update the hashes. interatom._spin_hash1 = None interatom._spin_hash2 = None if spin1: interatom._spin_hash1 = spin1._hash if spin2: interatom._spin_hash2 = spin2._hash
def return_data(self, data_id=None): """Function for returning the peak intensity data structure. @keyword data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @return: The peak intensity data structure. @rtype: list of float """ # Get the spin container. spin = return_spin(spin_id=data_id) # Return the peak intensities. return spin.peak_intensity
def return_data(self, data_id=None): """Function for returning the peak intensity data structure. @keyword data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @return: The peak intensity data structure. @rtype: list of float """ # Get the spin container. spin = return_spin(data_id) # Return the peak intensities. return spin.intensities
def sim_pack_data(self, data_id, sim_data): """Pack the Monte Carlo simulation data. @param data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @param sim_data: The Monte Carlo simulation data. @type sim_data: list of float """ # Get the spin container. spin = return_spin(spin_id=data_id) # Create the data structure. spin.peak_intensity_sim = sim_data
def sim_pack_data(self, data_id, sim_data): """Pack the Monte Carlo simulation data. @param data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @param sim_data: The Monte Carlo simulation data. @type sim_data: list of float """ # Get the spin container. spin = return_spin(data_id) # Create the data structure. spin.sim_intensities = sim_data
def test_return_spin(self): """Test the function for returning the desired spin data container. The function tested is pipe_control.mol_res_spin.return_spin(). """ # Ask for a few spins. spin1 = mol_res_spin.return_spin('#Ap4Aase:1') spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2') spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig') spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig') spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig') # Test the data of spin 1. self.assertNotEqual(spin1, None) self.assertEqual(spin1.num, 60) self.assertEqual(spin1.name, 'NH') # Test the data of spin 2. self.assertNotEqual(spin2, None) self.assertEqual(spin2.num, 63) self.assertEqual(spin2.name, 'NH') # Test the data of spin 3. self.assertNotEqual(spin3, None) self.assertEqual(spin3.num, None) self.assertEqual(spin3.name, None) # Test the data of the RNA res -5, spin N5. self.assertNotEqual(spin4, None) self.assertEqual(spin4.num, None) self.assertEqual(spin4.name, 'N5') # Test the data of the RNA res -4, spin 2H. self.assertNotEqual(spin5, None) self.assertEqual(spin5.num, 132) self.assertEqual(spin5.name, '2H')
def test_return_spin(self): """Test the function for returning the desired spin data container. The function tested is pipe_control.mol_res_spin.return_spin(). """ # Ask for a few spins. spin1 = mol_res_spin.return_spin('#Ap4Aase:1') spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2') spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig') spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig') spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig') # Test the data of spin 1. self.assertNotEqual(spin1, None) self.assertEqual(spin1.num, 60) self.assertEqual(spin1.name, 'NH') # Test the data of spin 2. self.assertNotEqual(spin2, None) self.assertEqual(spin2.num, 63) self.assertEqual(spin2.name, 'NH') # Test the data of spin 3. self.assertNotEqual(spin3, None) self.assertEqual(spin3.num, None) self.assertEqual(spin3.name, None) # Test the data of the RNA res -5, spin N5. self.assertNotEqual(spin4, None) self.assertEqual(spin4.num, None) self.assertEqual(spin4.name, 'N5') # Test the data of the RNA res -4, spin 2H. self.assertNotEqual(spin5, None) self.assertEqual(spin5.num, 132) self.assertEqual(spin5.name, '2H')
def return_error(self, data_id): """Return the standard deviation data structure. @param data_id: The spin identification string, as yielded by the base_data_loop() generator method. @type data_id: str @return: The standard deviation data structure. @rtype: list of float """ # Get the spin container. spin = return_spin(spin_id=data_id) # Return the error list. return spin.peak_intensity_err
def action_spin_spin_element(self, event): """Wrapper method. @param event: The wx event. @type event: wx event """ # Get the current spin element. spin = return_spin(spin_id=self.info['id']) element = None if hasattr(spin, 'element'): element = spin.element # Launch the user function wizard. uf_store['spin.element'](wx_parent=self.gui.spin_viewer, spin_id=self.info['id'], element=element)
def action_spin_spin_element(self, event): """Wrapper method. @param event: The wx event. @type event: wx event """ # Get the current spin element. spin = return_spin(self.info['id']) element = None if hasattr(spin, 'element'): element = spin.element # Launch the user function wizard. uf_store['spin.element'](wx_parent=self.gui.spin_viewer, spin_id=self.info['id'], element=element)
def generate_theta_dic(): # Get the field count field_count = cdp.spectrometer_frq_count # Get the spin_lock_field points spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False) # Initialize data containers all_spin_ids = get_spin_ids() # Containers for only selected spins cur_spin_ids = [] cur_spins = [] for curspin_id in all_spin_ids: # Get the spin curspin = return_spin(spin_id=curspin_id) # Check if is selected if curspin.select == True: cur_spin_ids.append(curspin_id) cur_spins.append(curspin) # The offset and R1 data. chemical_shifts, offsets, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=cur_spins, spin_ids=cur_spin_ids, field_count=field_count, fields=spin_lock_nu1) # Loop over the index of spins, then exp_type, frq, offset print("Printing the following") print("exp_type curspin_id frq offset{ppm} offsets[ei][si][mi][oi]{rad/s} ei mi oi si di cur_spin.chemical_shift{ppm} chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz} tilt_angles[ei][si][mi][oi]{rad}") for si in range(len(cur_spin_ids)): theta_spin_dic = dict() curspin_id = cur_spin_ids[si] cur_spin = cur_spins[si] for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True): # Loop over the dispersion points. spin_lock_fields = spin_lock_nu1[ei][mi][oi] for di in range(len(spin_lock_fields)): print("%-8s %-10s %11.1f %8.4f %12.5f %i %i %i %i %i %7.3f %12.5f %12.5f %12.5f"%(exp_type, curspin_id, frq, offset, offsets[ei][si][mi][oi], ei, mi, oi, si, di, cur_spin.chemical_shift, chemical_shifts[ei][si][mi], spin_lock_fields[di], tilt_angles[ei][si][mi][oi][di])) dic_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=spin_lock_fields[di]) theta_spin_dic["%s"%(dic_key)] = tilt_angles[ei][si][mi][oi][di] # Store the data cur_spin.theta = theta_spin_dic print("\nThe theta data now resides in") for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): spin_index = find_index(selection=spin_id, global_index=False) print("%s cdp.mol[%i].res[%i].spin[%i].theta"%(spin_id, spin_index[0], spin_index[1], spin_index[2]))
def save_res(res_spins): res_list = [] for res_name, res_num, spin_name, params in res_spins: cur_spin_id = ":%i@%s"%(res_num, spin_name) cur_spin = return_spin(spin_id=cur_spin_id) # Save all the paramers to loop throgh later. ds.model_analyse_params = cur_spin.params par_dic = {} # Now read the parameters. for mo_param in cur_spin.params: par_dic.update({mo_param : getattr(cur_spin, mo_param) }) # Append result. res_list.append([res_name, res_num, spin_name, par_dic]) return res_list