Author: bugman Date: Tue Mar 28 08:45:33 2006 New Revision: 2425 URL: http://svn.gna.org/viewcvs/relax?rev=2425&view=rev Log: Bug fix for bug #5559. The idea for the __getattr__ function to generate the non-standard diffusion tensor parameters on the fly comes from the changes made by Chris MacRaild (c.a.macraild at leeds.ac.uk) in trying to fix bug #5501 located at https://gna.org/bugs/?func=detailitem&item_id=5501. The bug can be found at https://gna.org/bugs/?func=detailitem&item_id=5559. Firstly the Da parameter in the relax test suite is now set to reasonable values. A special dictionary type class for the diffusion tensor data has been created and is called DiffTensorData and inherits functions from the base class SpecificData. The 'add_item' function has been replaced so that the element added is now DiffTensorElement(). The DiffTensorElement data container has been created and inherits its functions from the base class Element. The __getattr__ function has been added to pick up any references to non-existent structures. If the name asked for is one of Diso, Da, Dper, Dpar, Dratio, Dx, Dy, or Dz, then the values of these parameters are calculated for the parameters set in this DiffTensorElement container. Recursion is used when the equations to calculate the value contains one of the other non-standard parameters. The relax test suite element 'Test of the user function diffusion_tensor.display()' now passes. Modified: branches/diff_tensor_bug_5559_fix/data.py branches/diff_tensor_bug_5559_fix/test_suite/diffusion_tensor.py Modified: branches/diff_tensor_bug_5559_fix/data.py URL: http://svn.gna.org/viewcvs/relax/branches/diff_tensor_bug_5559_fix/data.py?rev=2425&r1=2424&r2=2425&view=diff ============================================================================== --- branches/diff_tensor_bug_5559_fix/data.py (original) +++ branches/diff_tensor_bug_5559_fix/data.py Tue Mar 28 08:45:33 2006 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003, 2004 Edward d'Auvergne # +# Copyright (C) 2003, 2004, 2006 Edward d'Auvergne # # # # This file is part of the program relax. # # # @@ -43,7 +43,7 @@ self.pdb = SpecificData() # Diffusion data. - self.diff = SpecificData() + self.diff = DiffTensorData() # The residue specific data. self.res = Residue() @@ -134,6 +134,80 @@ +# Diffusion tensor specific data. +################################# + +class DiffTensorData(SpecificData): + def __init__(self): + """Dictionary type class for the diffusion tensor data. + + The non-default diffusion parameters are calculated on the fly. + """ + + + def add_item(self, key): + """Function for adding an empty container to the dictionary. + + This overwrites the function from the parent class SpecificData. + """ + + self[key] = DiffTensorElement() + + + +class DiffTensorElement(Element): + def __init__(self): + """An empty data container for the diffusion tensor elements.""" + + + def __getattr__(self, name): + """Function for calculating the parameters on the fly.""" + + # All tensor types. + ################### + + # Diso. + if name == 'Diso': + return 1.0 / (6.0 * self.tm) + + + # Spheroidal diffusion. + ####################### + + # Dper = Diso - 1/3Da. + if name == 'Dper': + return self.Diso - 1.0/3.0 * self.Da + + # Dpar = Diso + 2/3Da. + if name == 'Dpar': + return self.Diso + 2.0/3.0 * self.Da + + # Dratio = Dpar / Dper. + if name == 'Dratio': + return self.Dpar / self.Dper + + + # Ellipsoidal diffusion. + ######################## + + # Dx = Diso - 1/3Da(1 + 3Dr). + if name == 'Dx': + return self.Diso - 1.0/3.0 * self.Da * (1.0 + 3.0*self.Dr) + + # Dy = Diso - 1/3Da(1 - 3Dr). + if name == 'Dy': + return self.Diso - 1.0/3.0 * self.Da * (1.0 - 3.0*self.Dr) + + # Dz = Diso + 2/3Da. + if name == 'Dz': + return self.Diso + 2.0/3.0 * self.Da + + + # The attribute asked for does not exist. + raise AttributeError, name + + + # Residue specific data. ######################## Modified: branches/diff_tensor_bug_5559_fix/test_suite/diffusion_tensor.py URL: http://svn.gna.org/viewcvs/relax/branches/diff_tensor_bug_5559_fix/test_suite/diffusion_tensor.py?rev=2425&r1=2424&r2=2425&view=diff ============================================================================== --- branches/diff_tensor_bug_5559_fix/test_suite/diffusion_tensor.py (original) +++ branches/diff_tensor_bug_5559_fix/test_suite/diffusion_tensor.py Tue Mar 28 08:45:33 2006 @@ -120,5 +120,5 @@ # Initialise some data. self.relax.interpreter._Diffusion_tensor.init('sphere', 10e-9, fixed=1) - self.relax.interpreter._Diffusion_tensor.init('spheroid', (2e-8, 1.3, 60-360, 290), spheroid_type='prolate', fixed=1) - self.relax.interpreter._Diffusion_tensor.init('ellipsoid', (9e-8, 0.5, 0.3, 60+360, 290, 100), fixed=0) + self.relax.interpreter._Diffusion_tensor.init('spheroid', (2e-8, 1.3, 60-360, 290), param_types=2, spheroid_type='prolate', fixed=1) + self.relax.interpreter._Diffusion_tensor.init('ellipsoid', (9e-8, 5e6, 0.3, 60+360, 290, 100), fixed=0)