mailRe: r22427 - /trunk/lib/rotating_frame.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on March 07, 2014 - 16:15:
Oh, I forgot to mention the following.  Whenever you are in the
pipe_control modules and you need data from the specific analyses,
then you need to call the methods of the analysis specific API.  This
is the standardised way in relax to access specific data so that the
code, which is mainly user functions, will operate independently of
the analysis type.  This is how the value.write and grace.write user
functions automatically supports all analysis types.

Regards,

Edward



On 7 March 2014 15:48, Edward d'Auvergne <edward@xxxxxxxxxxxxx> wrote:
Hi,

I think that the value.write function is not the best for this, as
this data is too complicated.  It does not work for the dispersion
points either.  Nevertheless it can be used.  If you look at were the
value is obtained in the pipe_control.value.write_data() function, you
will see the lines:

        # Get the value and error.
        value, error = return_value(spin, param, bc=bc)

To see where return_value() comes from, look to the start of the function:

    # Get the value and error returning function parameter description
function if required.
    if not return_value:
        return_value =
specific_analyses.setup.get_specific_fn('return_value',
pipes.get_type())
    if not return_data_desc:
        return_data_desc =
specific_analyses.setup.get_specific_fn('return_data_desc',
pipes.get_type())

So this is obtaining the function from the analysis specific API.  In
this case, the code is in specific_analyses.relax_disp.api.  Don't
worry about the return_data_desc() function as this defaults to the
descriptions you give in the self.PARAMS data structure.  From the
specific_analyses.relax_disp.api.Relax_disp.__init__() method, you
will see the function aliasing:

        # Place methods into the API.
        self.data_init = self._data_init_spin
        self.model_type = self._model_type_local
        self.return_conversion_factor = self._return_no_conversion_factor
        self.return_value = self._return_value_general
        self.set_param_values = self._set_param_values_spin

So the real function is the _return_value_general() method.  This is
in the specific analysis API common module,
specific_analyses.api_common.  Have a look at that method to
understand what it is doing.

Essentially what you would need to do is to override the method.  So
in specific_analyses.relax_disp.api you would remove the alias and
create a new return_value() method.  For a new method, you start by
copying the stub method in specific_analyses.api_base and the modify
that.  This specific_analyses.api_base module defines the analysis
specific API.

In the new method you would check if the 'param' argument is one of
the 'special' auto-generated parameters.  If so, you make the call to
the specific_analyses.relax_disp.disp_data functions that you need to
obtain the values, and then return them as a dictionary.  If the
parameter is not an auto-generated parameter, then call the API common
self._return_value_general() method (this is so you don't need to
reimplement all of the method).

A different way would be to have something like the
relax_disp.plot_disp_curves, but for writing the dispersion curves to
file.  This already exists in the relax_disp.write_disp_curves, this
creates one file per spin system and can be modified to handle
offsets, tilt angles and omega_eff as well.  Or modifying this
function could be complementary.

This is rather complex!  This is probably your first time working
directly with the analysis specific API, so it might take a little
while to understand it.

Regards,

Edward

On 7 March 2014 13:33, Troels Emtekær Linnet <tlinnet@xxxxxxxxxxxxx> wrote:
Hi Edward.

How should I handle the value.write function?

I was thinking of adding w_eff and Delta_omega as parameters, like these
commits:
r22409 - /trunk/specific_analyses/relax_disp/api.py
http://www.mail-archive.com/relax-commits@xxxxxxx/msg20031.html

r22411 - /trunk/specific_analyses/relax_disp/api.py
http://www.mail-archive.com/relax-commits@xxxxxxx/msg20033.html

If I was about to use the value.write function, how should
I initialize a call to the function to calculate theta, Delta_omega?

Best
Troels



2014-03-07 12:26 GMT+01:00 Edward d'Auvergne <edward@xxxxxxxxxxxxx>:

Hi Troels,

One consideration you need to make for the functions of the relax
library is that these are independent of the relax data store and the
pipe_control package (used to manipulate the data store) and the
specific_analyses package.  I.e. you should be able to use all
functions without the rest of relax, hence it could be distributed
with other GPL v3+ NMR software.  Here you have used a number of
pipe_control.mol_res_spin and specific_analyses.relax_disp.disp_data
functions.  Therefore this indicates that the code would be better
located in the specific_analyses.relax_disp.disp_data module.  A
calc_tilt_angle() function in the relax library would essentially need
to take all its data as arguments (spin-lock field and offset and
chemical shift) and return the tilt angle.

The other problem is the storing of theta in the spin containers.
This should not be done as the user can change the(spin-lock field,
offset, or chemical shift and hence the tilt angle theta will change.
It is much better to generate theta when needed by the
relax_disp.plot_disp_curves user function, and then not store it (so
it is destroyed automatically by Python).  Such non-permanent
parameters are used extensively throughout relax, especially in the
N-state or ensemble analysis code.

Regards,

Edward


On 7 March 2014 11:42,  <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet
Date: Fri Mar  7 11:42:36 2014
New Revision: 22427

URL: http://svn.gna.org/viewcvs/relax?rev=22427&view=rev
Log:
Added lib.rotating_frame module containing functions related to rotating
frame NMR calculations.

Regarding sr #3124, (https://gna.org/support/index.php?3124) - Grace
graphs production for R1rho analysis with R2_eff as function of 
Omega_eff.

Added:
    trunk/lib/rotating_frame.py

Added: trunk/lib/rotating_frame.py
URL:
http://svn.gna.org/viewcvs/relax/trunk/lib/rotating_frame.py?rev=22427&view=auto

==============================================================================
--- trunk/lib/rotating_frame.py (added)
+++ trunk/lib/rotating_frame.py Fri Mar  7 11:42:36 2014
@@ -0,0 +1,77 @@

+###############################################################################
+#
#
+# Copyright (C) 2014 Troels E. Linnet
#
+#
#
+# This file is part of the program relax (http://www.nmr-relax.com).
#
+#
#
+# This program is free software: you can redistribute it and/or modify
#
+# it under the terms of the GNU General Public License as published by
#
+# the Free Software Foundation, either version 3 of the License, or
#
+# (at your option) any later version.
#
+#
#
+# This program is distributed in the hope that it will be useful,
#
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#
+# GNU General Public License for more details.
#
+#
#
+# You should have received a copy of the GNU General Public License
#
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
+#
#

+###############################################################################
+
+# Module docstring.
+"""Module containing functions related to rotating frame NMR
calculations."""
+
+# Python module imports.
+from os import sep
+
+# relax module imports.
+from pipe_control.mol_res_spin import find_index, get_spin_ids,
index_molecule, index_residue, return_spin, spin_loop
+from specific_analyses.relax_disp.disp_data import loop_exp_frq_offset,
return_offset_data, return_param_key_from_data, return_spin_lock_nu1
+
+def calc_tilt_angle():
+    # Get the field count
+    field_count = cdp.spectrometer_frq_count
+
+    # Get the spin_lock_field points
+    spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)
+
+    # Initialize data containers
+    all_spin_ids = get_spin_ids()
+
+    # Containers for only selected spins
+    cur_spin_ids = []
+    cur_spins = []
+    for curspin_id in all_spin_ids:
+        # Get the spin
+        curspin = return_spin(curspin_id)
+
+        # Check if is selected
+        if curspin.select == True:
+            cur_spin_ids.append(curspin_id)
+            cur_spins.append(curspin)
+
+    # The offset and R1 data.
+    chemical_shifts, offsets, tilt_angles =
return_offset_data(spins=cur_spins, spin_ids=cur_spin_ids,
field_count=field_count, fields=spin_lock_nu1)
+
+    # Loop over the index of spins, then exp_type, frq, offset
+    print("Printing the following")
+    print("exp_type curspin_id frq offset{ppm}
offsets[ei][si][mi][oi]{rad/s} ei mi oi si di 
cur_spin.chemical_shift{ppm}
chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz}
tilt_angles[ei][si][mi][oi]{rad}")
+    for si in range(len(cur_spin_ids)):
+        theta_spin_dic = dict()
+        curspin_id = cur_spin_ids[si]
+        cur_spin = cur_spins[si]
+        for exp_type, frq, offset, ei, mi, oi in
loop_exp_frq_offset(return_indices=True):
+            # Loop over the dispersion points.
+            spin_lock_fields = spin_lock_nu1[ei][mi][oi]
+            for di in range(len(spin_lock_fields)):
+                print("%-8s %-10s %11.1f %8.4f %12.5f %i  %i  %i  %i
%i %7.3f %12.5f %12.5f %12.5f"%(exp_type, curspin_id, frq, offset,
offsets[ei][si][mi][oi], ei, mi, oi, si, di, cur_spin.chemical_shift,
chemical_shifts[ei][si][mi], spin_lock_fields[di],
tilt_angles[ei][si][mi][oi][di]))
+                dic_key = return_param_key_from_data(exp_type=exp_type,
frq=frq, offset=offset, point=spin_lock_fields[di])
+                theta_spin_dic["%s"%(dic_key)] =
tilt_angles[ei][si][mi][oi][di]
+        # Store the data
+        cur_spin.theta = theta_spin_dic
+
+    print("\nThe theta data now resides in")
+    for curspin, mol_name, res_num, res_name, spin_id in
spin_loop(full_info=True, return_id=True, skip_desel=True):
+        spin_index = find_index(selection=spin_id, global_index=False)
+        print("%s cdp.mol[%i].res[%i].spin[%i].theta"%(spin_id,
spin_index[0], spin_index[1], spin_index[2]))


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits

_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-devel mailing list
relax-devel@xxxxxxx


To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-devel





Related Messages


Powered by MHonArc, Updated Wed Mar 12 12:20:22 2014