def _read_1_2_results(self, file_data, verbosity=1): """Read the relax 1.2 model-free results file. @param file_data: The processed results file data. @type file_data: list of lists of str @keyword verbosity: A variable specifying the amount of information to print. The higher the value, the greater the verbosity. @type verbosity: int """ # Extract and remove the header. header = file_data[0] file_data = file_data[1:] # Sort the column numbers. col = self._read_1_2_col_numbers(header) # Test the file. if len(col) < 2: raise RelaxInvalidDataError # Initialise some data structures and flags. sim_num = None sims = [] all_select_sim = [] diff_data_set = False diff_error_set = False diff_sim_set = None model_type = None pdb = False pdb_model = None pdb_heteronuc = None pdb_proton = None ri_labels = None # Generate the sequence. if verbosity: print("\nGenerating the sequence.") for file_line in file_data: # The data set. data_set = file_line[col['data_set']] # Stop creating the sequence once the data_set is no longer 'value'. if data_set != 'value': break # Sequence. self._generate_sequence(file_line, col, verbosity) # Count the number of simulations. for file_line in file_data: # The data set. data_set = file_line[col['data_set']] # Simulation number. if data_set != 'value' and data_set != 'error': # Extract the number from the data_set string. sim_num = data_set.split('_') try: sim_num = int(sim_num[1]) except: raise RelaxError("The simulation number '%s' is invalid." % sim_num) if sim_num != None: cdp.sim_number = sim_num + 1 # Loop over the lines of the file data. for file_line in file_data: # The data set. data_set = file_line[col['data_set']] # The spin info (for relax 1.2). if 'num' in col: mol_name = None res_num = int(file_line[col['num']]) res_name = file_line[col['name']] spin_num = None spin_name = None if col['nucleus'] < len(file_line) and search('N', file_line[col['nucleus']]): spin_name = 'N' if col['nucleus'] < len(file_line) and search('C', file_line[col['nucleus']]): spin_name = 'C' # The spin info. else: mol_name = file_line[col['mol_name']] res_num = int(file_line[col['res_num']]) res_name = file_line[col['res_name']] spin_num = int(file_line[col['spin_num']]) spin_name = file_line[col['spin_name']] # Create the spin ID. spin_id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name) # Get the spin container. spin = return_spin(spin_id) # Create a new spin container for the proton, then set up a dipole interaction between the two spins. if data_set == 'value' and spin_name: h_spin = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_name='H') h_spin.select = False h_spin.element = 'H' h_spin.isotope = '1H' spin_id2 = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_name='H') define(spin_id, spin_id2, verbose=False) # Backwards compatibility for the reading of the results file from versions 1.2.0 to 1.2.9. if len(file_line) == 4: continue # Set the nuclear isotope types and spin names (absent from the 1.2 results file). if data_set == 'value': if file_line[col['nucleus']] != 'None': if search('N', file_line[col['nucleus']]): spin.isotope = '15N' if spin.name == None: spin.name = 'N' elif search('C', file_line[col['nucleus']]): spin.isotope = '13C' if spin.name == None: spin.name = 'C' # Simulation number. if data_set != 'value' and data_set != 'error': # Extract the number from the data_set string. sim_num = data_set.split('_') try: sim_num = int(sim_num[1]) except: raise RelaxError("The simulation number '%s' is invalid." % sim_num) # A new simulation number. if sim_num not in sims: # Update the sims array and append an empty array to the selected sims array. sims.append(sim_num) all_select_sim.append([]) # Selected simulations. all_select_sim[-1].append(bool(file_line[col['select']])) # Initial printout for the simulation. if verbosity: if diff_sim_set == None: print("\nLoading simulations.") if sim_num != diff_sim_set: print(data_set) # Diffusion tensor data. if data_set == 'value' and not diff_data_set: self._read_1_2_set_diff_tensor(file_line, col, data_set, verbosity, sim_num=sim_num) diff_data_set = True # Diffusion tensor errors. elif data_set == 'error' and not diff_error_set: self._read_1_2_set_diff_tensor(file_line, col, data_set, verbosity, sim_num=sim_num) diff_error_set = True # Diffusion tensor simulation data. elif data_set != 'value' and data_set != 'error' and sim_num != diff_sim_set: # Set up the diffusion tensor. if not hasattr(cdp.diff_tensor, '_sim_num') or cdp.diff_tensor._sim_num == None: cdp.diff_tensor.set_sim_num(cdp.sim_number) self._read_1_2_set_diff_tensor(file_line, col, data_set, verbosity, sim_num=sim_num) diff_sim_set = sim_num # Model type. if model_type == None: self._fix_params(file_line, col, verbosity) # PDB. if not pdb: if self._load_structure(file_line, col, verbosity): pdb = True # XH vector, heteronucleus, and proton. if data_set == 'value': self._set_xh_vect(file_line, col, spin, spin_id1=spin_id, spin_id2=spin_id2, verbosity=verbosity) # Relaxation data. self._load_relax_data(file_line, col, data_set, spin, verbosity) # Model-free data. self._load_model_free_data(file_line, col, data_set, spin, spin_id, verbosity) # Set up the simulations. if len(sims): # Convert the selected simulation array of arrays into a Numeric matrix, transpose it, then convert back to a Python list. all_select_sim = transpose(array(all_select_sim)) all_select_sim = all_select_sim.tolist() # Set up the Monte Carlo simulations. pipe_control.monte_carlo.setup(number=len(sims), all_select_sim=all_select_sim) # Turn the simulation state to off! cdp.sim_state = False
def bmrb_read(star, sample_conditions=None): """Read the relaxation data from the NMR-STAR dictionary object. @param star: The NMR-STAR dictionary object. @type star: NMR_STAR instance @keyword sample_conditions: The sample condition label to read. Only one sample condition can be read per data pipe. @type sample_conditions: None or str """ # Get the relaxation data. for data in star.relaxation.loop(): # Store the keys. keys = list(data.keys()) # Sample conditions do not match (remove the $ sign). if 'sample_cond_list_label' in keys and sample_conditions and data['sample_cond_list_label'].replace('$', '') != sample_conditions: continue # Create the labels. ri_type = data['data_type'] frq = float(data['frq']) * 1e6 # Round the label to the nearest factor of 10. frq_label = create_frq_label(float(data['frq']) * 1e6) # The ID string. ri_id = "%s_%s" % (ri_type, frq_label) # 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) # Generate the sequence if needed. bmrb.generate_sequence(N, spin_names=data['atom_names'], res_nums=data['res_nums'], res_names=data['res_names'], mol_names=mol_names, isotopes=data['isotope'], elements=data['atom_types']) # The attached protons. if 'atom_names_2' in data: # Generate the proton spins. bmrb.generate_sequence(N, spin_names=data['atom_names_2'], res_nums=data['res_nums'], res_names=data['res_names'], mol_names=mol_names, isotopes=data['isotope_2'], elements=data['atom_types_2']) # Define the dipolar interaction. for i in range(len(data['atom_names'])): # The spin IDs. spin_id1 = generate_spin_id_unique(spin_name=data['atom_names'][i], res_num=data['res_nums'][i], res_name=data['res_names'][i], mol_name=mol_names[i]) spin_id2 = generate_spin_id_unique(spin_name=data['atom_names_2'][i], res_num=data['res_nums'][i], res_name=data['res_names'][i], mol_name=mol_names[i]) # Check if the container exists. if return_interatom(spin_id1=spin_id1, spin_id2=spin_id2): continue # Define. define(spin_id1=spin_id1, spin_id2=spin_id2, verbose=False) # The data and error. vals = data['data'] errors = data['errors'] if vals == None: vals = [None] * N if errors == None: errors = [None] * N # Data transformation. if vals != None and 'units' in keys: # Scaling. if data['units'] == 'ms': # Loop over the data. for i in range(N): # The value. if vals[i] != None: vals[i] = vals[i] / 1000 # The error. if errors[i] != None: errors[i] = errors[i] / 1000 # Invert. if data['units'] in ['s', 'ms']: # Loop over the data. for i in range(len(vals)): # The value. if vals[i] != None: vals[i] = 1.0 / vals[i] # The error. if vals[i] != None and errors[i] != None: errors[i] = errors[i] * vals[i]**2 # Pack the data. pack_data(ri_id, ri_type, frq, vals, errors, mol_names=mol_names, res_nums=data['res_nums'], res_names=data['res_names'], spin_nums=None, spin_names=data['atom_names'], gen_seq=True, verbose=False) # Store the temperature calibration and control. if data['temp_calibration']: temp_calibration(ri_id=ri_id, method=data['temp_calibration']) if data['temp_control']: temp_control(ri_id=ri_id, method=data['temp_control']) # Peak intensity type. if data['peak_intensity_type']: peak_intensity_type(ri_id=ri_id, type=data['peak_intensity_type'])