mailr9589 - /1.3/generic_fns/mol_res_spin.py


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

Header


Content

Posted by edward on October 06, 2009 - 17:25:
Author: bugman
Date: Tue Oct  6 17:25:41 2009
New Revision: 9589

URL: http://svn.gna.org/viewcvs/relax?rev=9589&view=rev
Log:
Rewrote the tokenise() function to allow for the '&' boolean operator for 
residues and spins.

This allows ':1&:GLY' or '@453&@N' to be parsed.


Modified:
    1.3/generic_fns/mol_res_spin.py

Modified: 1.3/generic_fns/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/mol_res_spin.py?rev=9589&r1=9588&r2=9589&view=diff
==============================================================================
--- 1.3/generic_fns/mol_res_spin.py (original)
+++ 1.3/generic_fns/mol_res_spin.py Tue Oct  6 17:25:41 2009
@@ -38,7 +38,7 @@
 # Python module imports.
 from numpy import array
 from re import split
-from string import strip
+from string import count, strip
 from textwrap import fill
 from warnings import warn
 
@@ -2098,6 +2098,8 @@
     """
 
     # Split up the spin ID.
+    print id
+    print tokenise(id)
     mol_token, res_token, spin_token = tokenise(id)
     mol_info = parse_token(mol_token)
     res_info = parse_token(res_token)
@@ -2346,73 +2348,137 @@
         return None, None, None
 
 
-    # Atoms.
-    ########
-
-    # Split by '@'.
-    atom_split = split('@', selection)
-
-    # Test that only one '@' character was supplied.
-    if len(atom_split) > 2:
-        raise RelaxError("Only one '@' character is allowed within the 
selection identifier string.")
-
-    # No atom identifier.
-    if len(atom_split) == 1:
-        spin_token = None
+    # Walk along the ID string, separating the molecule, residue, and spin 
data.
+    mol_info = ''
+    res_info = ''
+    spin_info = ''
+    pos = 'mol'
+    for i in range(len(selection)):
+        # Find forbidden boolean operators.
+        if selection[i] == '|':
+            raise RelaxError("The boolean operator '|' is not supported for 
individual spin selections.")
+
+        # Hit the residue position.
+        if selection[i] == ':':
+            if pos == 'spin':
+                raise RelaxError("Invalid selection string '%s'." % 
selection)
+            pos = 'res'
+
+        # Hit the spin position.
+        if selection[i] == '@':
+            pos = 'spin'
+
+        # Append the data.
+        if pos == 'mol':
+            mol_info = mol_info + selection[i]
+        if pos == 'res':
+            res_info = res_info + selection[i]
+        if pos == 'spin':
+            spin_info = spin_info + selection[i]
+
+    print("Mol info: %s" % mol_info)
+    print("Res info: %s" % res_info)
+    print("Spin info: %s" % spin_info)
+
+    # Molecules.
+    ############
+
+    # Molecule identifier.
+    if mol_info:
+        # Find boolean operators.
+        if '&' in mol_info:
+            raise RelaxError("The boolean operator '&' is not supported for 
the molecule component of individual spin IDs.")
+
+        # Checks:
+        #   No residue identification characters are allowed.
+        #   No spin identification characters are allowed.
+        #   First character must be '#'.
+        #   Only 1 '#' allowed.
+        if ':' in mol_info or '@' in mol_info or mol_info[0] != '#' or 
count(mol_info, '#') != 1:
+            raise RelaxError("Invalid molecule selection '%s'." % mol_info)
+
+        # ID.
+        mol_token = mol_info[1:]
+
+    # No molecule identifier.
     else:
-        # Test for out of order identifiers.
-        if ':' in atom_split[1]:
-            raise RelaxError("The atom identifier '@' must come after the 
residue identifier ':'.")
-        elif '#' in atom_split[1]:
-            raise RelaxError("The atom identifier '@' must come after the 
molecule identifier '#'.")
-
-        # The token.
-        spin_token = atom_split[1]
+        mol_token = None
 
 
     # Residues.
     ###########
 
-    # Split by ':'.
-    res_split = split(':', atom_split[0])
-
-    # Test that only one ':' character was supplied.
-    if len(res_split) > 2:
-        raise RelaxError("Only one ':' character is allowed within the 
selection identifier string.")
+    # Residue identifier.
+    if res_info:
+        # Only max 1 '&' allowed.
+        if count(res_info, '&') > 1:
+            raise RelaxError("Only one '&' boolean operator is supported for 
the residue component of individual spin IDs.")
+
+        # Split by '&'.
+        res_token = split('&', res_info)
+
+        # Check and remove the ':' character.
+        for i in range(len(res_token)):
+            # Checks:
+            #   No molecule identification characters are allowed.
+            #   No spin identification characters are allowed.
+            #   First character must be ':'.
+            #   Only 1 ':' allowed.
+            if '#' in res_token[i] or '@' in res_token[i] or res_token[i][0] 
!= ':' or count(res_token[i], ':') != 1:
+                raise RelaxError("Invalid residue selection '%s'." % 
res_info)
+
+            # Strip.
+            res_token[i] = res_token[i][1:]
+
+        # Convert to a string if only a single item.
+        if len(res_token) == 1:
+            res_token = res_token[0]
 
     # No residue identifier.
-    if len(res_split) == 1:
+    else:
         res_token = None
+
+
+    # Spins.
+    ########
+
+    # Spin identifier.
+    if spin_info:
+        # Only max 1 '&' allowed.
+        if count(spin_info, '&') > 1:
+            raise RelaxError("Only one '&' boolean operator is supported for 
the spin component of individual spin IDs.")
+
+        # Split by '&'.
+        spin_token = split('&', spin_info)
+
+        # Check and remove the ':' character.
+        for i in range(len(spin_token)):
+            # Checks:
+            #   No molecule identification characters are allowed.
+            #   No residue identification characters are allowed.
+            #   First character must be '@'.
+            #   Only 1 '@' allowed.
+            if '#' in spin_token[i] or ':' in spin_token[i] or 
spin_token[i][0] != '@' or count(spin_token[i], '@') != 1:
+                raise RelaxError("Invalid spin selection '%s'." % spin_info)
+
+            # Strip.
+            spin_token[i] = spin_token[i][1:]
+
+        # Convert to a string if only a single item.
+        if len(spin_token) == 1:
+            spin_token = spin_token[0]
+
+    # No spin identifier.
     else:
-        # Test for out of order identifiers.
-        if '#' in res_split[1]:
-            raise RelaxError("The residue identifier ':' must come after the 
molecule identifier '#'.")
-
-        # The token.
-        res_token = res_split[1]
-
-
-
-    # Molecules.
-    ############
-
-    # Split by '#'.
-    mol_split = split('#', res_split[0])
-
-    # Test that only one '#' character was supplied.
-    if len(mol_split) > 2:
-        raise RelaxError("Only one '#' character is allowed within the 
selection identifier string.")
-
-    # No molecule identifier.
-    if len(mol_split) == 1:
-        mol_token = None
-    else:
-        mol_token = mol_split[1]
-
+        spin_token = None
+
+
+    # End.
+    ######
 
     # Improper selection string.
     if mol_token == None and res_token == None and spin_token == None:
-        raise RelaxError("The selection string " + repr(selection) + " is 
invalid.")
+        raise RelaxError("The selection string '%s' is invalid." % selection)
 
     # Return the three tokens.
     return mol_token, res_token, spin_token




Related Messages


Powered by MHonArc, Updated Tue Oct 06 17:40:03 2009