mailr17102 - /branches/interatomic/generic_fns/structure/scientific.py


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

Header


Content

Posted by edward on June 28, 2012 - 17:23:
Author: bugman
Date: Thu Jun 28 17:23:49 2012
New Revision: 17102

URL: http://svn.gna.org/viewcvs/relax?rev=17102&view=rev
Log:
Added the are_bonded() and get_molecule() methods for the Scientific Python 
PDB reader.

This is now needed for defining interatomic vectors in the interatomic data 
design.


Modified:
    branches/interatomic/generic_fns/structure/scientific.py

Modified: branches/interatomic/generic_fns/structure/scientific.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/generic_fns/structure/scientific.py?rev=17102&r1=17101&r2=17102&view=diff
==============================================================================
--- branches/interatomic/generic_fns/structure/scientific.py (original)
+++ branches/interatomic/generic_fns/structure/scientific.py Thu Jun 28 
17:23:49 2012
@@ -28,7 +28,7 @@
 
 # Python module imports.
 from math import sqrt
-from numpy import array, dot, float64, zeros
+from numpy import array, dot, float64, linalg, zeros
 import os
 from os import F_OK, access, sep
 from extern.scientific_python.IO import PDB
@@ -152,6 +152,31 @@
 
                 # Yield the residue info.
                 yield res, res.number, res.name, res_index
+
+
+    def are_bonded(self, atom_id1=None, atom_id2=None):
+        """Determine if two atoms are directly bonded to each other.
+
+        @keyword atom_id1:  The molecule, residue, and atom identifier 
string of the first atom.
+        @type atom_id1:     str
+        @keyword atom_id1:  The molecule, residue, and atom identifier 
string of the second atom.
+        @type atom_id1:     str
+        @return:            True if the atoms are directly bonded.
+        @rtype:             bool
+        """
+
+        # Loop over the atoms.
+        for pos1 in self.atom_loop(atom_id=atom_id1, pos_flag=True):
+            for pos2 in self.atom_loop(atom_id=atom_id2, pos_flag=True):
+                # The interatomic distance.
+                dist = linalg.norm(pos2[0]-pos1[0])
+
+                # The atom is within the radius of 1.2 Angstrom.
+                if dist < 1.2:
+                    return True
+
+        # Not bonded.
+        return False
 
 
     def atom_loop(self, atom_id=None, str_id=None, model_num=None, 
model_num_flag=False, mol_name_flag=False, res_num_flag=False, 
res_name_flag=False, atom_num_flag=False, atom_name_flag=False, 
element_flag=False, pos_flag=False, ave=False):
@@ -469,6 +494,42 @@
         return data
 
 
+    def get_molecule(self, molecule, model=None):
+        """Return the molecule.
+
+        Only one model can be specified.
+
+
+        @param molecule:    The molecule name.
+        @type molecule:     int or None
+        @keyword model:     The model number.
+        @type model:        int or None
+        @raises RelaxError: If the model is not specified and there is more 
than one model loaded.
+        @return:            The MolContainer corresponding to the molecule 
name and model number.
+        @rtype:             MolContainer instance or None
+        """
+
+        # Check if the target is a single molecule.
+        if model == None and self.num_models() > 1:
+            raise RelaxError("The target molecule cannot be determined as 
there are %s models already present." % self.num_models())
+
+        # Check the model argument.
+        if not isinstance(model, int) and not model == None:
+            raise RelaxNoneIntError
+
+        # No models.
+        if not len(self.structural_data):
+            return
+
+        # Loop over the models.
+        for model_cont in self.model_loop(model):
+            # Loop over the molecules.
+            for mol in model_cont.mol:
+                # Return the matching molecule.
+                if mol.mol_name == molecule:
+                    return mol
+
+
     def load_pdb(self, file_path, read_mol=None, set_mol_name=None, 
read_model=None, set_model_num=None, verbosity=False):
         """Function for loading the structures from the PDB file.
 




Related Messages


Powered by MHonArc, Updated Thu Jun 28 17:40:02 2012