Author: bugman
Date: Wed Feb 25 14:00:53 2015
New Revision: 27720
URL: http://svn.gna.org/viewcvs/relax?rev=27720&view=rev
Log:
Merged revisions 27717-27719 via svnmerge from
svn+ssh://[email protected]/svn/relax/trunk
........
r27717 | bugman | 2015-02-24 12:08:43 +0100 (Tue, 24 Feb 2015) | 3 lines
Improvement for a RelaxError message when assembling structural data but no
coordinates can be found.
........
r27718 | bugman | 2015-02-25 13:46:35 +0100 (Wed, 25 Feb 2015) | 6 lines
Created a series of unit tests for implementing a new internal structural
object feature.
These tests check a new 'inv' argument for the selection() structural object
method for allowing all
atoms not matching the atom ID string to be selected.
........
r27719 | bugman | 2015-02-25 13:58:45 +0100 (Wed, 25 Feb 2015) | 6 lines
Implemented the new 'inv' argument for the selection() structural object
method.
This allows for all atoms not matching the atom ID string to be selected.
The unit tests for this
argument now all pass, validating the implementation.
........
Modified:
branches/frame_order_cleanup/ (props changed)
branches/frame_order_cleanup/lib/structure/internal/object.py
branches/frame_order_cleanup/pipe_control/structure/main.py
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/_structure/test_internal.py
Propchange: branches/frame_order_cleanup/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Feb 25 14:00:53 2015
@@ -1 +1 @@
-/trunk:1-27715
+/trunk:1-27719
Modified: branches/frame_order_cleanup/lib/structure/internal/object.py
URL:
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/lib/structure/internal/object.py?rev=27720&r1=27719&r2=27720&view=diff
==============================================================================
--- branches/frame_order_cleanup/lib/structure/internal/object.py
(original)
+++ branches/frame_order_cleanup/lib/structure/internal/object.py Wed Feb
25 14:00:53 2015
@@ -38,7 +38,7 @@
from lib.check_types import is_float
from lib.errors import RelaxError, RelaxFault, RelaxNoneIntError,
RelaxNoPdbError
from lib.io import file_root, open_read_file
-from lib.selection import Selection
+from lib.selection import Selection, tokenise
from lib.sequence import aa_codes_three_to_one
from lib.structure import pdb_read, pdb_write
from lib.structure.internal.displacements import Displacements
@@ -2630,17 +2630,22 @@
mol.z[i] = pos[2]
- def selection(self, atom_id=None):
+ def selection(self, atom_id=None, inv=False):
"""Convert the atom ID string into a special internal selection object
for speed.
@keyword atom_id: The molecule, residue, and atom identifier string.
Only atoms matching this selection will be used.
@type atom_id: str or None
+ @keyword inv: A flag which if True will cause the selection to
be inverted.
+ @type inv: bool
@return: The internal structural selection object.
@rtype: Internal_selection instance
"""
# Initialise the internal structural selection object.
selection = Internal_selection()
+
+ # Split up the atom ID, to see if a molecule has been specified.
+ mol_token, res_token, spin_token = tokenise(atom_id)
# Generate the atom ID selection object.
sel_obj = None
@@ -2658,8 +2663,14 @@
mol = model.mol[mol_index]
# Skip non-matching molecules.
- if sel_obj and not sel_obj.contains_mol(mol.mol_name):
- continue
+ if not inv:
+ if sel_obj and not sel_obj.contains_mol(mol.mol_name):
+ continue
+
+ # Skip matching molecules.
+ else:
+ if (not sel_obj) or (mol_token != None and
sel_obj.contains_mol(mol.mol_name)):
+ continue
# Add the molecule index.
selection.add_mol(mol_index=mol_index)
@@ -2667,8 +2678,14 @@
# Loop over the atoms.
for i in range(len(mol.atom_num)):
# Skip non-matching atoms.
- if sel_obj and not sel_obj.contains_spin(mol.atom_num[i],
mol.atom_name[i], mol.res_num[i], mol.res_name[i], mol.mol_name):
- continue
+ if not inv:
+ if sel_obj and not sel_obj.contains_spin(mol.atom_num[i],
mol.atom_name[i], mol.res_num[i], mol.res_name[i], mol.mol_name):
+ continue
+
+ # Skip matching atoms.
+ else:
+ if (not sel_obj) or sel_obj.contains_spin(mol.atom_num[i],
mol.atom_name[i], mol.res_num[i], mol.res_name[i], mol.mol_name):
+ continue
# Add the atom index.
selection.add_atom(mol_index=mol_index, atom_index=i)
Modified: branches/frame_order_cleanup/pipe_control/structure/main.py
URL:
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/pipe_control/structure/main.py?rev=27720&r1=27719&r2=27720&view=diff
==============================================================================
--- branches/frame_order_cleanup/pipe_control/structure/main.py (original)
+++ branches/frame_order_cleanup/pipe_control/structure/main.py Wed Feb 25
14:00:53 2015
@@ -134,7 +134,10 @@
# No data.
if mol_names == []:
- raise RelaxError("No structural data matching the atom ID string '%s'
can be found." % atom_id)
+ if atom_id != None:
+ raise RelaxError("No structural data matching the atom ID string
'%s' can be found." % atom_id)
+ else:
+ raise RelaxError("No structural data can be found.")
# Are all molecules the same?
same_mol = True
Modified:
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/_structure/test_internal.py
URL:
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/_structure/test_internal.py?rev=27720&r1=27719&r2=27720&view=diff
==============================================================================
---
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/_structure/test_internal.py
(original)
+++
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/_structure/test_internal.py
Wed Feb 25 14:00:53 2015
@@ -1,6 +1,6 @@
###############################################################################
# #
-# Copyright (C) 2008-2013 Edward d'Auvergne #
+# Copyright (C) 2008-2015 Edward d'Auvergne #
# #
# This file is part of the program relax (http://www.nmr-relax.com). #
# #
@@ -460,6 +460,22 @@
self.assertEqual(atom_count, 150)
+ def test_atom_loop_inv(self):
+ """Test the Internal.atom_loop() method with the inversion flag set."""
+
+ # Load the PDB file.
+ self.data.load_pdb(self.test_pdb_path)
+
+ # Loop over the atoms.
+ atom_count = 0
+ selection = self.data.selection(atom_id=None, inv=True)
+ for atom in self.data.atom_loop(selection=selection):
+ atom_count = atom_count + 1
+
+ # Test the number of atoms looped over.
+ self.assertEqual(atom_count, 0)
+
+
def test_atom_loop_mol_selection(self):
"""Test the Internal.atom_loop() method with the '#XXX' mol
selection."""
@@ -474,6 +490,22 @@
# Test the number of atoms looped over.
self.assertEqual(atom_count, 0)
+
+
+ def test_atom_loop_mol_selection_inv(self):
+ """Test the Internal.atom_loop() method with the '#XXX' mol selection
with the inversion flag set."""
+
+ # Load the PDB file.
+ self.data.load_pdb(self.test_pdb_path)
+
+ # Loop over the atoms.
+ atom_count = 0
+ selection = self.data.selection(atom_id='#XXX', inv=True)
+ for atom in self.data.atom_loop(selection=selection):
+ atom_count = atom_count + 1
+
+ # Test the number of atoms looped over.
+ self.assertEqual(atom_count, 150)
def test_atom_loop_res_selection1(self):
@@ -497,6 +529,26 @@
self.assertEqual(atom_count, 11)
+ def test_atom_loop_res_selection1_inv(self):
+ """Test the Internal.atom_loop() method with the ':8' res selection
with the inversion flag set."""
+
+ # Load the PDB file.
+ self.data.load_pdb(self.test_pdb_path)
+
+ # Loop over the atoms.
+ atom_count = 0
+ selection = self.data.selection(atom_id=':8', inv=True)
+ for res_num, res_name in self.data.atom_loop(selection=selection,
res_num_flag=True, res_name_flag=True):
+ # Test the residue name and number.
+ self.assertNotEqual(res_num, 8)
+
+ # Increment the atom count.
+ atom_count = atom_count + 1
+
+ # Test the number of atoms looped over.
+ self.assertEqual(atom_count, 150-11)
+
+
def test_atom_loop_res_selection2(self):
"""Test the Internal.atom_loop() method with the ':PRO' res
selection."""
@@ -517,6 +569,26 @@
self.assertEqual(atom_count, 42)
+ def test_atom_loop_res_selection2_inv(self):
+ """Test the Internal.atom_loop() method with the ':PRO' res selection
with the inversion flag set."""
+
+ # Load the PDB file.
+ self.data.load_pdb(self.test_pdb_path)
+
+ # Loop over the atoms.
+ atom_count = 0
+ selection = self.data.selection(atom_id=':PRO', inv=True)
+ for atom in self.data.atom_loop(selection=selection,
res_name_flag=True):
+ # Test the residue name.
+ self.assertNotEqual(atom, 'PRO')
+
+ # Increment the atom count.
+ atom_count = atom_count + 1
+
+ # Test the number of atoms looped over.
+ self.assertEqual(atom_count, 150-42)
+
+
def test_atom_loop_spin_selection1(self):
"""Test the Internal.atom_loop() method with the '@CA' spin
selection."""
@@ -535,6 +607,26 @@
# Test the number of atoms looped over.
self.assertEqual(atom_count, 12)
+
+
+ def test_atom_loop_spin_selection1_inv(self):
+ """Test the Internal.atom_loop() method with the '@CA' spin selection
with the inversion flag set."""
+
+ # Load the PDB file.
+ self.data.load_pdb(self.test_pdb_path)
+
+ # Loop over the atoms.
+ atom_count = 0
+ selection = self.data.selection(atom_id='@CA', inv=True)
+ for spin_name in self.data.atom_loop(selection=selection,
atom_name_flag=True):
+ # Test the spin name.
+ self.assertNotEqual(spin_name, 'CA')
+
+ # Increment the atom count.
+ atom_count = atom_count + 1
+
+ # Test the number of atoms looped over.
+ self.assertEqual(atom_count, 150-12)
def test_atom_loop_spin_selection2(self):
@@ -566,6 +658,29 @@
self.assertEqual(atom_count, 1)
+ def test_atom_loop_spin_selection2_inv(self):
+ """Test the Internal.atom_loop() method with the '@163' spin selection
with the inversion flag set."""
+
+ # Load the PDB file.
+ self.data.load_pdb(self.test_pdb_path)
+
+ # Loop over the atoms.
+ atom_count = 0
+ selection = self.data.selection(atom_id='@140', inv=True)
+ for mol_name, res_num, res_name, spin_num, spin_name, element, pos in
self.data.atom_loop(selection=selection, 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):
+ # Test the spin info.
+ self.assertNotEqual(spin_num, 140)
+ self.assertNotEqual(pos[0, 0], float('10.055'))
+ self.assertNotEqual(pos[0, 1], float('-2.74'))
+ self.assertNotEqual(pos[0, 2], float('-13.193'))
+
+ # Increment the atom count.
+ atom_count = atom_count + 1
+
+ # Test the number of atoms looped over.
+ self.assertEqual(atom_count, 150-1)
+
+
def test_load_pdb(self):
"""Load a PDB file using Internal.load_pdb()."""
_______________________________________________
relax (http://www.nmr-relax.com)
This is the relax-commits mailing list
[email protected]
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