Author: bugman Date: Wed Nov 9 11:55:34 2011 New Revision: 14991 URL: http://svn.gna.org/viewcvs/relax?rev=14991&view=rev Log: Added the atom ID argument to the structure.rotate and structure.translate user functions. This allows subsets of molecules or models to be translated and rotated. Modified: 1.3/generic_fns/structure/api_base.py 1.3/generic_fns/structure/internal.py 1.3/generic_fns/structure/main.py 1.3/prompt/structure.py Modified: 1.3/generic_fns/structure/api_base.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/api_base.py?rev=14991&r1=14990&r2=14991&view=diff ============================================================================== --- 1.3/generic_fns/structure/api_base.py (original) +++ 1.3/generic_fns/structure/api_base.py Wed Nov 9 11:55:34 2011 @@ -539,7 +539,7 @@ model.mol[-1].file_model = orig_model_num[i] - def rotate(self, R=None, origin=None, model=None): + def rotate(self, R=None, origin=None, model=None, atom_id=None): """Method stub for rotating a structure. @keyword R: The forwards rotation matrix. @@ -548,6 +548,8 @@ @type origin: numpy 3D, rank-1 array @keyword model: The model to rotate. If None, all models will be rotated. @type model: int + @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. + @type atom_id: str or None """ # Raise the error. @@ -579,13 +581,15 @@ target.append(file_root(file) + '_mol' + repr(mol_num)) - def translate(self, T=None, model=None): + def translate(self, T=None, model=None, atom_id=None): """Method stub for displacing the structural information by the given translation vector. @keyword T: The translation vector. @type T: numpy 3D, rank-1 array @keyword model: The model to rotate. If None, all models will be rotated. @type model: int + @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. + @type atom_id: str or None """ # Raise the error. Modified: 1.3/generic_fns/structure/internal.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/internal.py?rev=14991&r1=14990&r2=14991&view=diff ============================================================================== --- 1.3/generic_fns/structure/internal.py (original) +++ 1.3/generic_fns/structure/internal.py Wed Nov 9 11:55:34 2011 @@ -1164,7 +1164,7 @@ return True - def rotate(self, R=None, origin=None, model=None): + def rotate(self, R=None, origin=None, model=None, atom_id=None): """Rotate the structural information about the given origin. @keyword R: The forwards rotation matrix. @@ -1173,14 +1173,29 @@ @type origin: numpy 3D, rank-1 array @keyword model: The model to rotate. If None, all models will be rotated. @type model: int - """ + @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. + @type atom_id: str or None + """ + + # Generate the selection object. + sel_obj = None + if atom_id: + sel_obj = Selection(atom_id) # Loop over the models. for model_cont in self.model_loop(model): # Loop over the molecules. for mol in model_cont.mol: + # Skip non-matching molecules. + if sel_obj and not sel_obj.contains_mol(mol.mol_name): + continue + # Loop over the atoms. for i in range(len(mol.atom_num)): + # Skip non-matching atoms. + if sel_obj and not sel_obj.contains_spin(mol.atom_num[i], mol.atom_name[i], mol.res_num[i], mol.res_name[i], mol.mol_name): + continue + # The origin to atom vector. vect = array([mol.x[i], mol.y[i], mol.z[i]], float64) - origin @@ -1194,21 +1209,36 @@ mol.z[i] = pos[2] - def translate(self, T=None, model=None): + def translate(self, T=None, model=None, atom_id=None): """Displace the structural information by the given translation vector. @keyword T: The translation vector. @type T: numpy 3D, rank-1 array @keyword model: The model to rotate. If None, all models will be rotated. @type model: int - """ + @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. + @type atom_id: str or None + """ + + # Generate the selection object. + sel_obj = None + if atom_id: + sel_obj = Selection(atom_id) # Loop over the models. for model_cont in self.model_loop(model): # Loop over the molecules. for mol in model_cont.mol: + # Skip non-matching molecules. + if sel_obj and not sel_obj.contains_mol(mol.mol_name): + continue + # Loop over the atoms. for i in range(len(mol.atom_num)): + # Skip non-matching atoms. + if sel_obj and not sel_obj.contains_spin(mol.atom_num[i], mol.atom_name[i], mol.res_num[i], mol.res_name[i], mol.mol_name): + continue + # Translate. mol.x[i] = mol.x[i] + T[0] mol.y[i] = mol.y[i] + T[1] Modified: 1.3/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/main.py?rev=14991&r1=14990&r2=14991&view=diff ============================================================================== --- 1.3/generic_fns/structure/main.py (original) +++ 1.3/generic_fns/structure/main.py Wed Nov 9 11:55:34 2011 @@ -500,7 +500,7 @@ cdp.structure.load_xyz(file_path, read_mol=read_mol, set_mol_name=set_mol_name, read_model=read_model, set_model_num=set_model_num, verbosity=verbosity) -def rotate(R=None, origin=None, model=None): +def rotate(R=None, origin=None, model=None, atom_id=None): """Rotate the structural data about the origin by the specified forwards rotation. @keyword R: The forwards rotation matrix. @@ -509,6 +509,8 @@ @type origin: numpy 3D, rank-1 array or list of len 3 or None @keyword model: The model to rotate. If None, all models will be rotated. @type model: int + @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. + @type atom_id: str or None """ # Test if the current data pipe exists. @@ -527,7 +529,7 @@ origin = array(origin, float64) # Call the specific code. - cdp.structure.rotate(R=R, origin=origin, model=model) + cdp.structure.rotate(R=R, origin=origin, model=model, atom_id=atom_id) def set_vector(spin=None, xh_vect=None): @@ -589,13 +591,15 @@ rotate(R=R[i], origin=pivot[i], model=models[i]) -def translate(T=None, model=None): +def translate(T=None, model=None, atom_id=None): """Shift the structural data by the specified translation vector. @keyword T: The translation vector. @type T: numpy rank-1, 3D array or list of float @keyword model: The model to translate. If None, all models will be rotated. - @type model: int + @type model: int or None + @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. + @type atom_id: str or None """ # Test if the current data pipe exists. @@ -609,7 +613,7 @@ T = array(T, float64) # Call the specific code. - cdp.structure.translate(T=T, model=model) + cdp.structure.translate(T=T, model=model, atom_id=atom_id) def vectors(attached=None, spin_id=None, model=None, verbosity=1, ave=True, unit=True): Modified: 1.3/prompt/structure.py URL: http://svn.gna.org/viewcvs/relax/1.3/prompt/structure.py?rev=14991&r1=14990&r2=14991&view=diff ============================================================================== --- 1.3/prompt/structure.py (original) +++ 1.3/prompt/structure.py Wed Nov 9 11:55:34 2011 @@ -577,22 +577,24 @@ generic_fns.structure.main.read_xyz(file=file, dir=dir, read_mol=read_mol, set_mol_name=set_mol_name, read_model=read_model, set_model_num=set_model_num) - def rotate(self, R=None, origin=None, model=None): + def rotate(self, R=None, origin=None, model=None, atom_id=None): # Function intro text. if self._exec_info.intro: text = self._exec_info.ps3 + "structure.rotate(" text = text + "R=" + repr(R) text = text + ", origin=" + repr(origin) - text = text + ", model=" + repr(model) + ")" + text = text + ", model=" + repr(model) + text = text + ", atom_id=" + repr(atom_id) + ")" print(text) # The argument checks. arg_check.is_float_matrix(R, 'rotation matrix', dim=(3,3)) arg_check.is_float_array(origin, 'origin of rotation', size=3, can_be_none=True) arg_check.is_int(model, 'model', can_be_none=True) - - # Execute the functional code. - generic_fns.structure.main.rotate(R=R, origin=origin, model=model) + arg_check.is_str(atom_id, 'atom identification string', can_be_none=True) + + # Execute the functional code. + generic_fns.structure.main.rotate(R=R, origin=origin, model=model, atom_id=atom_id) # The function doc info. rotate._doc_title = "Rotate the internal structural object about the given origin by the rotation matrix." @@ -670,27 +672,30 @@ _build_doc(superimpose) - def translate(self, T=None, model=None): + def translate(self, T=None, model=None, atom_id=None): # Function intro text. if self._exec_info.intro: text = self._exec_info.ps3 + "structure.translate(" text = text + "T=" + repr(T) - text = text + ", model=" + repr(model) + ")" + text = text + ", model=" + repr(model) + text = text + ", atom_id=" + repr(atom_id) + ")" print(text) # The argument checks. arg_check.is_float_array(T, 'translation vector', size=3) arg_check.is_int(model, 'model', can_be_none=True) - - # Execute the functional code. - generic_fns.structure.main.translate(T=T, model=model) + arg_check.is_str(atom_id, 'atom identification string', can_be_none=True) + + # Execute the functional code. + generic_fns.structure.main.translate(T=T, model=model, atom_id=atom_id) # The function doc info. translate._doc_title = "Laterally displace the internal structural object by the translation vector." translate._doc_title_short = "Structure translation." translate._doc_args = [ ["T", "The translation vector."], - ["model", "The model to translate (which if not set will cause all models to be translate)."] + ["model", "The model to translate (which if not set will cause all models to be translate)."], + ["atom_id", "The atom identification string."] ] translate._doc_desc = """ This is used to translate the internal structural data by the given translation vector. The model argument can be used to translate specific models.