mailr16928 - /branches/interatomic/generic_fns/structure/internal.py


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

Header


Content

Posted by edward on June 18, 2012 - 11:06:
Author: bugman
Date: Mon Jun 18 11:06:35 2012
New Revision: 16928

URL: http://svn.gna.org/viewcvs/relax?rev=16928&view=rev
Log:
Implemented the are_bonded() structural API method for the internal 
structural object.


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

Modified: branches/interatomic/generic_fns/structure/internal.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/generic_fns/structure/internal.py?rev=16928&r1=16927&r2=16928&view=diff
==============================================================================
--- branches/interatomic/generic_fns/structure/internal.py (original)
+++ branches/interatomic/generic_fns/structure/internal.py Mon Jun 18 
11:06:35 2012
@@ -667,6 +667,59 @@
         for i in range(len(self.structural_data)):
             # Add the molecule.
             self.structural_data[i].mol.add_item(mol_name=name, 
mol_cont=MolContainer())
+
+
+    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
+        """
+
+        # Generate the selection objects.
+        sel_obj1 = Selection(atom_id1)
+        sel_obj2 = Selection(atom_id2)
+
+        # Build the connectivities if needed.
+        for mol in self.structural_data[0].mol:
+            for i in range(len(mol.atom_num)):
+                if not len(mol.bonded[i]):
+                    self._find_bonded_atoms(i, mol, radius=2)
+
+        # Loop over the molecules.
+        for mol in self.structural_data[0].mol:
+            # Skip non-matching molecules.
+            if not sel_obj1.contains_mol(mol.mol_name):
+                continue
+            if not sel_obj2.contains_mol(mol.mol_name):
+                continue
+
+            # Find the first atom.
+            index1 = None
+            for i in range(len(mol.atom_num)):
+                # Skip a non-matching first atom.
+                if sel_obj1.contains_spin(mol.atom_num[i], mol.atom_name[i], 
mol.res_num[i], mol.res_name[i], mol.mol_name):
+                    index1 = i
+                    break
+
+            # Find the second atom.
+            index2 = None
+            for i in range(len(mol.atom_num)):
+                # Skip a non-matching first atom.
+                if sel_obj2.contains_spin(mol.atom_num[i], mol.atom_name[i], 
mol.res_num[i], mol.res_name[i], mol.mol_name):
+                    index2 = i
+                    break
+
+            # Connectivities exist.
+            if index1 < len(mol.bonded):
+                if index2 in mol.bonded[index1]:
+                    return True
+                else:
+                    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):




Related Messages


Powered by MHonArc, Updated Mon Jun 18 11:20:04 2012