mailr5911 - /1.3/generic_fns/structure/main.py


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

Header


Content

Posted by edward on April 21, 2008 - 13:21:
Author: bugman
Date: Mon Apr 21 13:21:46 2008
New Revision: 5911

URL: http://svn.gna.org/viewcvs/relax?rev=5911&view=rev
Log:
Completed the vectors() function.

The vector is now fetched, averaged over all models, and placed into 
spin.xh_vect.  All the old code
has been axed.


Modified:
    1.3/generic_fns/structure/main.py

Modified: 1.3/generic_fns/structure/main.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/main.py?rev=5911&r1=5910&r2=5911&view=diff
==============================================================================
--- 1.3/generic_fns/structure/main.py (original)
+++ 1.3/generic_fns/structure/main.py Mon Apr 21 13:21:46 2008
@@ -22,7 +22,7 @@
 
 # Python module imports.
 from math import sqrt
-from numpy import dot, ndarray
+from numpy import dot, float64, ndarray, zeros
 from os import F_OK, access
 import sys
 from warnings import warn
@@ -225,9 +225,9 @@
     # Print out.
     if verbosity:
         if cdp.structure.num_models() > 1:
-            print "\nCalculating and averaging the unit XH vectors from all 
structures."
+            print "\nCalculating and averaging the following unit XH vectors 
from all models:"
         else:
-            print "\nCalculating the unit XH vectors from the structure."
+            print "\nCalculating the following unit XH vectors from the 
structure:"
 
     # Header print out.
     write_header(sys.stdout, mol_name_flag=True, res_num_flag=True, 
res_name_flag=True, spin_num_flag=True, spin_name_flag=True)
@@ -253,91 +253,36 @@
         if not bond_vectors:
             continue
 
-        # Print out.
-        print bond_vectors
-
-
-
-
-
-
-    # Loop over all the structural data.
-    first_model = None
-    spin_list = []
-    for atom in cdp.structure.atom_loop(atom_id=spin_id, 
model_num_flag=True, mol_name_flag=True, res_num_flag=True, 
res_name_flag=True, atom_num_flag=True, atom_name_flag=True, 
element_flag=True, pos_flag=True):
-        # Unpack the data.
-        model_num, mol_name, res_num, res_name, atom_num, atom_name, 
element, pos = atom
-
-        # The spin identification string.
-        spin_id = generate_spin_id(mol_name, res_num, res_name, atom_num, 
atom_name)
-
-        # Get the corresponding spin.
-        spin = return_spin(selection=spin_id)
-
-        # Proton name does not match, so skip the atom.
-        if proton != atom_name:
-            continue
-
-        # No matching spin, so skip the atom.
-        if not spin:
-            continue
-
-        # Skip deselected spins.
-        if not spin.select:
-            continue
-
-        # The first model.
-        if first_model == None:
-            first_model = model_num
-
-        # The XH vector already exists.
-        if first_model == model_num and hasattr(spin, 'xh_vect'):
-            warn(RelaxWarning("The XH vector for the spin " + `spin_id` + " 
already exists"))
-            continue
-
-        # Store the spin_id.
-        if first_model == model_num:
-            spin_list.append(spin_id)
-
         # Set the attached proton name.
         if not hasattr(spin, 'attached_proton'):
             spin.attached_proton = proton
         elif spin.attached_proton != proton:
             raise RelaxError, "The attached proton " + 
`spin.attached_proton` + " does not match the proton argument " + `proton` + 
"."
 
-        # Set the heteronucleus and proton positions.
-        posX = spin.pos
-        posH = pos
-
-        # Calculate the XH bond vector.
-        vector = posH - posX
-
-        # Unit vector.
-        if unit:
-            # Normalisation factor.
-            norm_factor = sqrt(dot(vector, vector))
-
-            # Test for zero length.
-            if norm_factor == 0.0:
-                warn(RelaxZeroVectorWarning(spin_id))
-
-            # Calculate the normalised vector.
-            else:
-                vector = vector / norm_factor
-
-        # Set the vector and deselect the spin if the vector doesn't exist.
-        if not hasattr(spin, 'xh_vect'):
-            spin.xh_vect = vector
-        else:
-            spin.xh_vect = spin.xh_vect + vector
-
-    # Loop over all the modified spins.
-    for spin_id in spin_list:
-        # Get the spin.
-        mol_name, res_num, res_name, spin = return_spin(selection=spin_id, 
full_info=True)
+        # Loop over the individual vectors.
+        ave_vector = zeros(3, float64)
+        for vector in bond_vectors:
+            # Unit vector.
+            if unit:
+                # Normalisation factor.
+                norm_factor = sqrt(dot(vector, vector))
+
+                # Test for zero length.
+                if norm_factor == 0.0:
+                    warn(RelaxZeroVectorWarning(spin_id))
+
+                # Calculate the normalised vector.
+                else:
+                    vector = vector / norm_factor
+
+            # Sum the vectors.
+            ave_vector = ave_vector + vector
+
+        # Average.
+        ave_vector = ave_vector / float(len(bond_vectors))
+
+        # Set the vector.
+        spin.xh_vect = ave_vector
 
         # Print out of modified spins.
-        write_line(sys.stdout, mol_name, res_num, res_name, atom_num, 
atom_name, mol_name_flag=True, res_num_flag=True, res_name_flag=True, 
spin_num_flag=True, spin_name_flag=True)
-
-        # Average the XH vectors for all models.
-        spin.xh_vect = spin.xh_vect / cdp.structure.num_models()
+        write_line(sys.stdout, mol_name, res_num, res_name, spin.num, 
spin.name, mol_name_flag=True, res_num_flag=True, res_name_flag=True, 
spin_num_flag=True, spin_name_flag=True)




Related Messages


Powered by MHonArc, Updated Mon Apr 21 14:20:21 2008