Author: bugman Date: Tue Oct 27 20:22:12 2009 New Revision: 9812 URL: http://svn.gna.org/viewcvs/relax?rev=9812&view=rev Log: Merged revisions 9794,9799-9800 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3 ........ r9794 | bugman | 2009-10-27 10:59:25 +0100 (Tue, 27 Oct 2009) | 7 lines Added user variable checking to the full_analysis.py script. This is in response to Tiago Pais's <tpais att itqb dot unl dot pt> post at https://mail.gna.org/public/relax-users/2009-10/msg00009.html (Message-id: <E45CDDF4A4E54B34A36BFBA62E6BFF20@Mercurio>). ........ r9799 | bugman | 2009-10-27 15:24:25 +0100 (Tue, 27 Oct 2009) | 3 lines Fix for the frame order grid search. ........ r9800 | bugman | 2009-10-27 15:25:08 +0100 (Tue, 27 Oct 2009) | 3 lines Created the structure.get_pos() user function for extracting atomic positions. ........ Modified: branches/bmrb/ (props changed) branches/bmrb/generic_fns/structure/main.py branches/bmrb/prompt/structure.py branches/bmrb/sample_scripts/full_analysis.py branches/bmrb/specific_fns/frame_order.py Propchange: branches/bmrb/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Tue Oct 27 20:22:12 2009 @@ -1,1 +1,1 @@ -/1.3:1-9792 +/1.3:1-9811 Modified: branches/bmrb/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/generic_fns/structure/main.py?rev=9812&r1=9811&r2=9812&view=diff ============================================================================== --- branches/bmrb/generic_fns/structure/main.py (original) +++ branches/bmrb/generic_fns/structure/main.py Tue Oct 27 20:22:12 2009 @@ -31,7 +31,7 @@ # relax module imports. from generic_fns import molmol, relax_re -from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id, return_molecule, return_residue, return_spin, spin_loop +from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id, linear_ave, return_molecule, return_residue, return_spin, spin_loop from generic_fns import pipes from generic_fns.structure.internal import Internal from generic_fns.structure.scientific import Scientific_data @@ -59,7 +59,89 @@ if hasattr(spin, 'xh_vect'): del spin.xh_vect - + +def get_pos(spin_id=None, str_id=None, ave_pos=False): + """Load the spins from the structural object into the relax data store. + + @keyword spin_id: The molecule, residue, and spin identifier string. + @type spin_id: str + @keyword str_id: The structure identifier. This can be the file name, model number, + or structure number. + @type str_id: int or str + @keyword ave_pos: A flag specifying if the average atom position or the atom position + from all loaded structures is loaded into the SpinContainer. + @type ave_pos: bool + """ + + # Test if the current data pipe exists. + pipes.test() + + # Test if the structure exists. + if not hasattr(cdp, 'structure') or not cdp.structure.num_models() or not cdp.structure.num_molecules(): + raise RelaxNoPdbError + + # Loop over all atoms of the spin_id selection. + model_index = -1 + last_model = None + for model_num, mol_name, res_num, res_name, atom_num, atom_name, element, pos in cdp.structure.atom_loop(atom_id=spin_id, str_id=str_id, model_num_flag=True, mol_name_flag=True, res_num_flag=True, res_name_flag=True, atom_num_flag=True, atom_name_flag=True, element_flag=True, pos_flag=True, ave=ave_pos): + # Update the model info. + if last_model != model_num: + model_index = model_index + 1 + last_model = model_num + + # Remove the '+' regular expression character from the mol, res, and spin names! + if mol_name and search('\+', mol_name): + mol_name = replace(mol_name, '+', '') + if res_name and search('\+', res_name): + res_name = replace(res_name, '+', '') + if atom_name and search('\+', atom_name): + atom_name = replace(atom_name, '+', '') + + # The spin identification string. The residue name and spin num is not included to allow molecules with point mutations to be used as different models. + id = generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=None, spin_name=atom_name) + + # Get the spin container. + spin_cont = return_spin(id) + + # Skip the spin if it doesn't exist. + if spin_cont == None: + continue + + # Add the position vector to the spin container. + if ave_pos: + spin_cont.pos = pos + else: + if not hasattr(spin_cont, 'pos'): + spin_cont.pos = [] + spin_cont.pos.append(pos) + + # Update pseudo-atoms. + for spin in spin_loop(): + if hasattr(spin, 'members'): + # Get the spin positions. + positions = [] + for atom in spin.members: + # Get the spin container. + subspin = return_spin(atom) + + # Test that the spin exists. + if subspin == None: + raise RelaxNoSpinError(atom) + + # Test the position. + if not hasattr(subspin, 'pos') or not subspin.pos: + raise RelaxError("Positional information is not available for the atom '%s'." % atom) + + # Store the position. + positions.append([]) + for i in range(len(subspin.pos)): + positions[-1].append(subspin.pos[i].tolist()) + + # The averaging. + if spin.averaging == 'linear': + spin.pos = linear_ave(positions) + + def load_spins(spin_id=None, str_id=None, combine_models=True, ave_pos=False): """Load the spins from the structural object into the relax data store. @@ -200,7 +282,7 @@ ======= A number of parsers are available for reading PDB files. These include: - + - 'scientific', the Scientific Python PDB parser. - 'internal', a low quality yet fast PDB parser built into relax. Modified: branches/bmrb/prompt/structure.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/prompt/structure.py?rev=9812&r1=9811&r2=9812&view=diff ============================================================================== --- branches/bmrb/prompt/structure.py (original) +++ branches/bmrb/prompt/structure.py Tue Oct 27 20:22:12 2009 @@ -204,6 +204,55 @@ generic_fns.structure.geometric.create_vector_dist(length=length, symmetry=symmetry, file=file, dir=dir, force=force) + def get_pos(self, spin_id=None, ave_pos=True): + """Extract the atomic positions from the loaded structures for the given spins. + + Keyword Arguments + ~~~~~~~~~~~~~~~~~ + + spin_id: The spin identification string. + + ave_pos: A flag specifying if the position of the atom is to be averaged across models. + + + Description + ~~~~~~~~~~~ + + This function allows the atomic positions of the spins to be extracted from the loaded + structures. This is automatically performed by the structure.load_spins() user function, + but if the sequence information is generated in other ways, this user function allows the + structural information to be obtained. + + If the ave_pos flag is True, the average position of all models will be loaded into the spin + container. If False, then the positions from all models will be loaded. + + + Example + ~~~~~~~ + + For a model-free backbone amide nitrogen analysis whereby the N spins have already been + created, to obtain the backbone N positions from the file '1F3Y.pdb' (which is a single + protein), type the following two user functions: + + relax> structure.read_pdb('1F3Y.pdb') + relax> structure.get_pos(spin_id='@N') + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "structure.get_pos(" + text = text + "spin_id=" + repr(spin_id) + text = text + ", ave_pos=" + repr(ave_pos) + ")" + print(text) + + # The argument checks. + check.is_str(spin_id, 'spin identification string', can_be_none=True) + check.is_bool(ave_pos, 'average position flag') + + # Execute the functional code. + generic_fns.structure.main.get_pos(spin_id=spin_id, ave_pos=ave_pos) + + def delete(self): """Delete all structural information from the current data pipe. @@ -241,7 +290,7 @@ combine_models: A flag which specifies if spins from separate models should be combined. - ave_pos: A flag specifying if the position of the atom is to be averaged. + ave_pos: A flag specifying if the position of the atom is to be averaged across models. Description @@ -256,15 +305,15 @@ If the combine_models flag is True, then the spins from only a single structure from the ensemble of models will be taken. If False, then spins will be loaded for each model. - If the ave_pos flag is True, the average position of all structures will be loaded into the spin - container. If False, then the positions from all structures will be loaded. + If the ave_pos flag is True, the average position of all models will be loaded into the spin + container. If False, then the positions from all models will be loaded. Example ~~~~~~~ For a model-free backbone amide nitrogen analysis, to load just the backbone N sequence from - the file '1F3Y.pdb' (which is a single protein), type the follow two user functions: + the file '1F3Y.pdb' (which is a single protein), type the following two user functions: relax> structure.read_pdb('1F3Y.pdb') relax> structure.load_spins(spin_id='@N') @@ -278,7 +327,6 @@ relax> structure.load_spins(spin_id=':G@C8&@N1') relax> structure.load_spins(spin_id=':C@C5&@C6') relax> structure.load_spins(spin_id=':U@N3&@C5&@C6') - """ # Function intro text. Modified: branches/bmrb/sample_scripts/full_analysis.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/sample_scripts/full_analysis.py?rev=9812&r1=9811&r2=9812&view=diff ============================================================================== --- branches/bmrb/sample_scripts/full_analysis.py (original) +++ branches/bmrb/sample_scripts/full_analysis.py Tue Oct 27 20:22:12 2009 @@ -211,6 +211,9 @@ # Setup. self.relax = relax + # User variable checks. + self.check_vars() + # MI - Local tm. ################ @@ -387,6 +390,94 @@ raise RelaxError("Unknown diffusion model, change the value of 'DIFF_MODEL'") + def check_vars(self): + """Check that the user has set the variables correctly.""" + + # The diff model. + valid_models = ['local_tm', 'sphere', 'oblate', 'prolate', 'ellipsoid', 'final'] + if DIFF_MODEL not in valid_models: + raise RelaxError("The DIFF_MODEL user variable '%s' is incorrectly set. It must be one of %s." % (DIFF_MODEL, valid_models)) + + # Model-free models. + mf_models = ['m0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9'] + local_tm_models = ['tm0', 'tm1', 'tm2', 'tm3', 'tm4', 'tm5', 'tm6', 'tm7', 'tm8', 'tm9'] + if not isinstance(MF_MODELS, list): + raise RelaxError("The MF_MODELS user variable must be a list.") + if not isinstance(LOCAL_TM_MODELS, list): + raise RelaxError("The LOCAL_TM_MODELS user variable must be a list.") + for i in range(len(MF_MODELS)): + if MF_MODELS[i] not in mf_models: + raise RelaxError("The MF_MODELS user variable '%s' is incorrectly set. It must be one of %s." % (MF_MODELS, mf_models)) + for i in range(len(LOCAL_TM_MODELS)): + if LOCAL_TM_MODELS[i] not in local_tm_models: + raise RelaxError("The LOCAL_TM_MODELS user variable '%s' is incorrectly set. It must be one of %s." % (LOCAL_TM_MODELS, local_tm_models)) + + # PDB file. + if PDB_FILE and not isinstance(PDB_FILE, str): + raise RelaxError("The PDB_FILE user variable '%s' is incorrectly set. It should either be a string or None." % PDB_FILE) + + # Sequence data. + if not isinstance(SEQ_ARGS, list): + raise RelaxError("The SEQ_ARGS user variable '%s' must be a list." % SEQ_ARGS) + if len(SEQ_ARGS) != 8: + raise RelaxError("The SEQ_ARGS user variable '%s' must be a list with eight elements." % SEQ_ARGS) + if not isinstance(SEQ_ARGS[0], str): + raise RelaxError("The file name component of the SEQ_ARGS user variable '%s' must be a string." % SEQ_ARGS) + for i in range(1, 8): + if SEQ_ARGS[i] != None and not isinstance(SEQ_ARGS[i], int): + raise RelaxError("The column components of the SEQ_ARGS user variable '%s' must be either None or integers." % SEQ_ARGS) + + # Atom name. + if not isinstance(HET_NAME, str): + raise RelaxError("The HET_NAME heteronucleus atom name user variable '%s' must be a string." % HET_NAME) + + # Relaxation data. + if not isinstance(RELAX_DATA, list): + raise RelaxError("The RELAX_DATA user variable '%s' must be a list." % RELAX_DATA) + for i in range(len(RELAX_DATA)): + if len(RELAX_DATA[i]) != 13: + raise RelaxError("The RELAX_DATA user variable component '%s' must be a list of 13 elements." % RELAX_DATA[i]) + if not isinstance(RELAX_DATA[i][0], str): + raise RelaxError("The data type component '%s' of the RELAX_DATA user variable must be a string." % RELAX_DATA[i][0]) + if not isinstance(RELAX_DATA[i][1], str): + raise RelaxError("The frequency label component '%s' of the RELAX_DATA user variable must be a string." % RELAX_DATA[i][1]) + if not isinstance(RELAX_DATA[i][2], float): + raise RelaxError("The frequency component '%s' of the RELAX_DATA user variable must be a floating point number." % RELAX_DATA[i][2]) + if not isinstance(RELAX_DATA[i][3], str): + raise RelaxError("The file name component '%s' of the RELAX_DATA user variable must be a string." % RELAX_DATA[i][3]) + for j in range(4, 13): + if RELAX_DATA[i][j] != None and not isinstance(RELAX_DATA[i][j], int): + raise RelaxError("The column components of the RELAX_DATA user variable '%s' must be either None or integers." % RELAX_DATA[i]) + + # Unresolved and exclude files. + if UNRES and not isinstance(UNRES, str): + raise RelaxError("The UNRES user variable '%s' is incorrectly set. It should either be a string or None." % UNRES) + if EXCLUDE and not isinstance(EXCLUDE, str): + raise RelaxError("The EXCLUDE user variable '%s' is incorrectly set. It should either be a string or None." % EXCLUDE) + + # Spin vars. + if not isinstance(BOND_LENGTH, float): + raise RelaxError("The BOND_LENGTH user variable '%s' is incorrectly set. It should be a floating point number." % BOND_LENGTH) + if not isinstance(CSA, float): + raise RelaxError("The CSA user variable '%s' is incorrectly set. It should be a floating point number." % CSA) + if not isinstance(HETNUC, str): + raise RelaxError("The HETNUC user variable '%s' is incorrectly set. It should be a string." % HETNUC) + if not isinstance(PROTON, str): + raise RelaxError("The PROTON user variable '%s' is incorrectly set. It should be a string." % PROTON) + + # Min vars. + if not isinstance(GRID_INC, int): + raise RelaxError("The GRID_INC user variable '%s' is incorrectly set. It should be an integer." % GRID_INC) + if not isinstance(MIN_ALGOR, str): + raise RelaxError("The MIN_ALGOR user variable '%s' is incorrectly set. It should be a string." % MIN_ALGOR) + if not isinstance(MC_NUM, int): + raise RelaxError("The MC_NUM user variable '%s' is incorrectly set. It should be an integer." % MC_NUM) + + # Looping. + if not isinstance(CONV_LOOP, bool): + raise RelaxError("The CONV_LOOP user variable '%s' is incorrectly set. It should be one of the booleans True or False." % CONV_LOOP) + + def convergence(self): """Test for the convergence of the global model.""" Modified: branches/bmrb/specific_fns/frame_order.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/specific_fns/frame_order.py?rev=9812&r1=9811&r2=9812&view=diff ============================================================================== --- branches/bmrb/specific_fns/frame_order.py (original) +++ branches/bmrb/specific_fns/frame_order.py Tue Oct 27 20:22:12 2009 @@ -730,7 +730,7 @@ # Set the default bounds. if default_bounds: lower.append(0.0) - upper.append(pi * (1.0 - 1.0/incs[i])) + upper.append(pi) # Get the grid row. if not row: