Author: bugman Date: Mon Dec 10 17:33:32 2012 New Revision: 18095 URL: http://svn.gna.org/viewcvs/relax?rev=18095&view=rev Log: Merged revisions 18087-18091 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r18087 | bugman | 2012-12-10 15:11:12 +0100 (Mon, 10 Dec 2012) | 5 lines Created the interatomic.copy and interatomic.create user functions. This is simply new front ends for the user for the functions of generic_fns.interatomic. ........ r18088 | bugman | 2012-12-10 15:12:10 +0100 (Mon, 10 Dec 2012) | 3 lines The generic_fns.interatomic.copy() function now accepts spin IDs as arguments to partially copy the data. ........ r18089 | bugman | 2012-12-10 17:20:45 +0100 (Mon, 10 Dec 2012) | 3 lines Expanded the RelaxNoSpinError class to accept the data pipe name for the error printout. ........ r18090 | bugman | 2012-12-10 17:29:16 +0100 (Mon, 10 Dec 2012) | 3 lines Created the Interatomic.test_copy system test to check the interatomic.copy user function. ........ r18091 | bugman | 2012-12-10 17:30:10 +0100 (Mon, 10 Dec 2012) | 3 lines Fixes for the checks in the interatomic.copy user function backend. ........ Added: branches/relax_disp/user_functions/interatomic.py - copied unchanged from r18091, trunk/user_functions/interatomic.py Modified: branches/relax_disp/ (props changed) branches/relax_disp/generic_fns/interatomic.py branches/relax_disp/relax_errors.py branches/relax_disp/test_suite/system_tests/interatomic.py branches/relax_disp/user_functions/__init__.py Propchange: branches/relax_disp/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Mon Dec 10 17:33:32 2012 @@ -1,1 +1,1 @@ -/trunk:1-18081 +/trunk:1-18091 Modified: branches/relax_disp/generic_fns/interatomic.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/generic_fns/interatomic.py?rev=18095&r1=18094&r2=18095&view=diff ============================================================================== --- branches/relax_disp/generic_fns/interatomic.py (original) +++ branches/relax_disp/generic_fns/interatomic.py Mon Dec 10 17:33:32 2012 @@ -29,19 +29,22 @@ # relax module imports. from generic_fns import pipes -from generic_fns.mol_res_spin import Selection, return_spin -from relax_errors import RelaxError, RelaxInteratomError, RelaxNoInteratomError +from generic_fns.mol_res_spin import Selection, count_spins, return_spin +from relax_errors import RelaxError, RelaxInteratomError, RelaxNoInteratomError, RelaxNoSpinError from relax_io import write_data -from relax_warnings import RelaxNoSpinWarning - - -def copy(pipe_from=None, pipe_to=None, verbose=True): + + +def copy(pipe_from=None, pipe_to=None, spin_id1=None, spin_id2=None, verbose=True): """Copy the interatomic data from one data pipe to another. @keyword pipe_from: The data pipe to copy the interatomic data from. This defaults to the current data pipe. @type pipe_from: str @keyword pipe_to: The data pipe to copy the interatomic data to. This defaults to the current data pipe. @type pipe_to: str + @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 verbose: A flag which if True will cause info about each spin pair to be printed out. @type verbose: bool """ @@ -58,17 +61,25 @@ pipes.test(pipe_from) pipes.test(pipe_to) + # Check that the spin IDs exist. + if spin_id1: + if count_spins(selection=spin_id1, pipe=pipe_from, skip_desel=False) == 0: + raise RelaxNoSpinError(spin_id1, pipe_from) + if count_spins(selection=spin_id1, pipe=pipe_to, skip_desel=False) == 0: + raise RelaxNoSpinError(spin_id1, pipe_to) + if spin_id2: + if count_spins(selection=spin_id2, pipe=pipe_from, skip_desel=False) == 0: + raise RelaxNoSpinError(spin_id2, pipe_from) + if count_spins(selection=spin_id2, pipe=pipe_to, skip_desel=False) == 0: + raise RelaxNoSpinError(spin_id2, pipe_to) + # Test if pipe_from contains interatomic data (skipping the rest of the function if it is missing). if not exists_data(pipe_from): return - # Test if pipe_to contains interatomic data. - if exists_data(pipe_to): - raise RelaxInteratomError - # Loop over the interatomic data of the pipe_from data pipe. ids = [] - for interatom in interatomic_loop(pipe=pipe_from): + for interatom in interatomic_loop(selection1=spin_id1, selection2=spin_id2, pipe=pipe_from): # Create a new container. new_interatom = create_interatom(spin_id1=interatom.spin_id1, spin_id2=interatom.spin_id2, pipe=pipe_to) @@ -103,7 +114,7 @@ @keyword spin_id1: The spin ID string of the first atom. @type spin_id1: str - @keyword spin_id2: The spin ID string of the first atom. + @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 Modified: branches/relax_disp/relax_errors.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/relax_errors.py?rev=18095&r1=18094&r2=18095&view=diff ============================================================================== --- branches/relax_disp/relax_errors.py (original) +++ branches/relax_disp/relax_errors.py Mon Dec 10 17:33:32 2012 @@ -672,8 +672,11 @@ # Cannot find the spin in the sequence. class RelaxNoSpinError(BaseError): - def __init__(self, id): - self.text = "The spin " + repr(id) + " does not exist." + def __init__(self, id, pipe=None): + if pipe == None: + self.text = "The spin '%s' does not exist." % id + else: + self.text = "The spin '%s' does not exist in the '%s' data pipe." % (id, pipe) # The sequence data is not valid. class RelaxInvalidSeqError(BaseError): Modified: branches/relax_disp/test_suite/system_tests/interatomic.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/test_suite/system_tests/interatomic.py?rev=18095&r1=18094&r2=18095&view=diff ============================================================================== --- branches/relax_disp/test_suite/system_tests/interatomic.py (original) +++ branches/relax_disp/test_suite/system_tests/interatomic.py Mon Dec 10 17:33:32 2012 @@ -35,6 +35,55 @@ class Interatomic(SystemTestCase): """Class for testing the interatomic functions.""" + def test_copy(self): + """Test the operation of the interatomic.copy user function.""" + + # Create an initial data pipe. + self.interpreter.pipe.create(pipe_name="orig", pipe_type='N-state') + + # Create some sequence data. + self.interpreter.molecule.create(mol_name='Test mol') + self.interpreter.residue.create(mol_name='Test mol', res_name='His', res_num=1) + self.interpreter.residue.create(mol_name='Test mol', res_name='His', res_num=2) + self.interpreter.spin.create(res_num=1, spin_name='N') + self.interpreter.spin.create(res_num=1, spin_name='H') + self.interpreter.spin.create(res_num=2, spin_name='N') + self.interpreter.spin.create(res_num=2, spin_name='H') + + # Define the interatomic interaction. + self.interpreter.interatomic.create(spin_id1=':1@N', spin_id2=':1@H') + self.interpreter.interatomic.create(spin_id1=':2@N', spin_id2=':2@H') + + # Add some test data. + cdp.interatomic[0].x = 1 + cdp.interatomic[1].y = 2 + + # Create a new data pipe to copy the data to. + self.interpreter.pipe.create(pipe_name="new", pipe_type='N-state') + + # Copy the data. + self.interpreter.sequence.copy(pipe_from='orig') + self.interpreter.interatomic.copy(pipe_from='orig', spin_id1=':2@N', spin_id2=':2@H') + self.interpreter.interatomic.copy(pipe_from='orig', spin_id1=':1@H', spin_id2=':1@N') + + # Check the sequence data. + self.assertEqual(cdp.mol[0].name, 'Test mol') + self.assertEqual(cdp.mol[0].res[0].name, 'His') + self.assertEqual(cdp.mol[0].res[0].spin[0].name, 'N') + self.assertEqual(cdp.mol[0].res[0].spin[1].name, 'H') + self.assertEqual(cdp.mol[0].res[1].name, 'His') + self.assertEqual(cdp.mol[0].res[1].spin[0].name, 'N') + self.assertEqual(cdp.mol[0].res[1].spin[1].name, 'H') + + # Check the interatomic data. + self.assertEqual(cdp.interatomic[0].spin_id1, ':2@N') + self.assertEqual(cdp.interatomic[0].spin_id2, ':2@H') + self.assertEqual(cdp.interatomic[0].y, 2) + self.assertEqual(cdp.interatomic[1].spin_id1, ':1@N') + self.assertEqual(cdp.interatomic[1].spin_id2, ':1@H') + self.assertEqual(cdp.interatomic[1].x, 1) + + def test_manipulation(self): """Test the manipulation of interatomic data containers.""" Modified: branches/relax_disp/user_functions/__init__.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/user_functions/__init__.py?rev=18095&r1=18094&r2=18095&view=diff ============================================================================== --- branches/relax_disp/user_functions/__init__.py (original) +++ branches/relax_disp/user_functions/__init__.py Mon Dec 10 17:33:32 2012 @@ -48,6 +48,7 @@ 'frame_order', 'frq', 'grace', + 'interatomic', 'jw_mapping', 'minimisation', 'model_free', @@ -97,6 +98,7 @@ import user_functions.frame_order import user_functions.frq import user_functions.grace +import user_functions.interatomic import user_functions.jw_mapping import user_functions.minimisation import user_functions.model_free