Author: bugman Date: Sat Mar 23 18:27:27 2013 New Revision: 19073 URL: http://svn.gna.org/viewcvs/relax?rev=19073&view=rev Log: Renamed the generic_fns.relax_re module to lib.regex. Added: trunk/lib/regex.py - copied unchanged from r19067, trunk/generic_fns/relax_re.py trunk/test_suite/unit_tests/_lib/test_regex.py - copied, changed from r19067, trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py Removed: trunk/generic_fns/relax_re.py trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py Modified: trunk/generic_fns/__init__.py trunk/generic_fns/mol_res_spin.py trunk/generic_fns/structure/internal.py trunk/generic_fns/structure/main.py trunk/generic_fns/structure/scientific.py trunk/lib/__init__.py Modified: trunk/generic_fns/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/__init__.py?rev=19073&r1=19072&r2=19073&view=diff ============================================================================== --- trunk/generic_fns/__init__.py (original) +++ trunk/generic_fns/__init__.py Sat Mar 23 18:27:27 2013 @@ -51,7 +51,6 @@ 'pymol_control', 'rdc', 'relax_data', - 'relax_re', 'reset', 'result_files', 'results', Modified: trunk/generic_fns/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/mol_res_spin.py?rev=19073&r1=19072&r2=19073&view=diff ============================================================================== --- trunk/generic_fns/mol_res_spin.py (original) +++ trunk/generic_fns/mol_res_spin.py Sat Mar 23 18:27:27 2013 @@ -41,7 +41,8 @@ # relax module imports. from data_store.mol_res_spin import MoleculeContainer, ResidueContainer, SpinContainer -from generic_fns import exp_info, pipes, relax_re +from generic_fns import exp_info, pipes +from lib import regex from lib.check_types import is_unicode from lib.errors import RelaxError, RelaxNoSpinError, RelaxMultiMolIDError, RelaxMultiResIDError, RelaxMultiSpinIDError, RelaxResSelectDisallowError, RelaxSpinSelectDisallowError from lib.warnings import RelaxWarning @@ -206,7 +207,7 @@ select_mol = True # A true match. - elif relax_re.search(self.molecules, mol.name): + elif regex.search(self.molecules, mol.name): select_mol = True else: # No molecule container sent in, therefore the molecule is assumed to match. @@ -223,7 +224,7 @@ select_res = True # A true match. - elif res.num in self.residues or relax_re.search(self.residues, res.name): + elif res.num in self.residues or regex.search(self.residues, res.name): select_res = True else: # No residue container sent in, therefore the residue is assumed to match. @@ -240,7 +241,7 @@ select_spin = True # A true match. - elif spin.num in self.spins or relax_re.search(self.spins, spin.name): + elif spin.num in self.spins or regex.search(self.spins, spin.name): select_spin = True else: # No spin container sent in, therefore the spin is assumed to match. @@ -292,7 +293,7 @@ return self._intersect[0].contains_mol(mol) and self._intersect[1].contains_mol(mol) # The check. - if relax_re.search(self.molecules, mol): + if regex.search(self.molecules, mol): return True # Nothingness. @@ -331,7 +332,7 @@ select_res = False # The residue checks. - if res_num in self.residues or relax_re.search(self.residues, res_name): + if res_num in self.residues or regex.search(self.residues, res_name): select_res = True # Nothingness. @@ -377,7 +378,7 @@ select_spin = False # The spin checks. - if spin_num in self.spins or relax_re.search(self.spins, spin_name): + if spin_num in self.spins or regex.search(self.spins, spin_name): select_spin = True # Nothingness. Removed: trunk/generic_fns/relax_re.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/relax_re.py?rev=19072&view=auto ============================================================================== --- trunk/generic_fns/relax_re.py (original) +++ trunk/generic_fns/relax_re.py (removed) @@ -1,87 +1,0 @@ -############################################################################### -# # -# Copyright (C) 2003-2012 Edward d'Auvergne # -# # -# This file is part of the program relax (http://www.nmr-relax.com). # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <http://www.gnu.org/licenses/>. # -# # -############################################################################### - -# Module docstring. -"""Module implementing relax regular expression.""" - -# Python module imports. -import re - - -def search(pattern, id): - """Determine if id matches the pattern, or vice versa, allowing for regular expressions. - - This method converts from relax's RE syntax to that of the re python module. - - The changes include: - - 1. All '*' to '.*'. - 2. The identifier is bracketed, '^' is added to the start and '$' to the end. - - After conversion of both the string and patterns, the comparison is then performed both ways from the converted string matching the original string (using re.search()). - - - @param pattern: The pattern to match the string to. This can be a list of patterns. All elements will be converted to strings, so the pattern or list can consist of anything. - @type pattern: anything - @param id: The identification object. - @type id: None, str, or number - @return: True if there is a match, False otherwise. - @rtype: bool - """ - - # Catch None. - if id == None: - return False - - # Convert to a string. - id = str(id) - - # If pattern is not a list, convert it to one. - if not isinstance(pattern, list): - patterns = [pattern] - else: - patterns = pattern - - # Loop over the patterns. - for pattern in patterns: - # Force a conversion to str. - pattern = str(pattern) - - # Quick string check. - if id == pattern: - return True - - # First replace any '*' with '.*' (relax to re conversion). - pattern_re = pattern.replace('*', '.*') - id_re = id.replace('*', '.*') - - # Bracket the pattern. - pattern_re = '^%s$' % pattern_re - id_re = '^%s$' % id_re - - # String matches (both ways). - if re.search(pattern_re, id): - return True - if re.search(id_re, pattern): - return True - - # No matches. - return False Modified: trunk/generic_fns/structure/internal.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/internal.py?rev=19073&r1=19072&r2=19073&view=diff ============================================================================== --- trunk/generic_fns/structure/internal.py (original) +++ trunk/generic_fns/structure/internal.py Sat Mar 23 18:27:27 2013 @@ -33,11 +33,12 @@ # relax module imports. from data_store.relax_xml import fill_object_contents, xml_to_object -from generic_fns import pipes, relax_re +from generic_fns import pipes from generic_fns.mol_res_spin import spin_loop from generic_fns.mol_res_spin import Selection from generic_fns.structure import pdb_read, pdb_write from generic_fns.structure.api_base import Base_struct_API, ModelList, Displacements +from lib import regex from lib.check_types import is_float from lib.errors import RelaxError, RelaxNoneIntError, RelaxNoPdbError from lib.io import file_root, open_read_file @@ -91,7 +92,7 @@ # Loop over the bonded atoms. matching_list = [] for bonded_index in mol.bonded[index]: - if relax_re.search(mol.atom_name[bonded_index], attached_atom): + if regex.search(mol.atom_name[bonded_index], attached_atom): matching_list.append(bonded_index) num_attached = len(matching_list) @@ -107,7 +108,7 @@ # No attached atoms. if num_attached == 0: - if relax_re.search('@*', attached_atom): + if regex.search('@*', attached_atom): matching_list = [] bonded_num=[] bonded_name=[] Modified: trunk/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/main.py?rev=19073&r1=19072&r2=19073&view=diff ============================================================================== --- trunk/generic_fns/structure/main.py (original) +++ trunk/generic_fns/structure/main.py Sat Mar 23 18:27:27 2013 @@ -30,7 +30,7 @@ from warnings import warn # relax module imports. -from generic_fns import molmol, relax_re +from generic_fns import molmol from generic_fns.interatomic import interatomic_loop from generic_fns.mol_res_spin import create_spin, exists_mol_res_spin_data, generate_spin_id_unique, linear_ave, return_molecule, return_residue, return_spin, spin_loop from generic_fns import pipes Modified: trunk/generic_fns/structure/scientific.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/scientific.py?rev=19073&r1=19072&r2=19073&view=diff ============================================================================== --- trunk/generic_fns/structure/scientific.py (original) +++ trunk/generic_fns/structure/scientific.py Sat Mar 23 18:27:27 2013 @@ -37,9 +37,10 @@ # relax module imports. from data_store.relax_xml import fill_object_contents, xml_to_object -from generic_fns import pipes, relax_re +from generic_fns import pipes from generic_fns.mol_res_spin import Selection, generate_spin_id, parse_token, tokenise from generic_fns.structure.api_base import Base_struct_API +from lib import regex from lib.errors import RelaxError, RelaxPdbLoadError from lib.io import file_root from lib.warnings import RelaxWarning, RelaxNoAtomWarning, RelaxNoPDBFileWarning, RelaxZeroVectorWarning @@ -79,7 +80,7 @@ # The find the attached atom in the residue (FIXME). matching_list = [] for atom in list(res.atoms.keys()): - if relax_re.search(atom, attached_atom): + if regex.search(atom, attached_atom): matching_list.append(atom) num_attached = len(matching_list) Modified: trunk/lib/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/__init__.py?rev=19073&r1=19072&r2=19073&view=diff ============================================================================== --- trunk/lib/__init__.py (original) +++ trunk/lib/__init__.py Sat Mar 23 18:27:27 2013 @@ -40,6 +40,7 @@ 'model_selection', 'order', 'physical_constants', + 'regex', 'spectral_densities', 'structure', 'text', Removed: trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py?rev=19072&view=auto ============================================================================== --- trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py (original) +++ trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py (removed) @@ -1,51 +1,0 @@ -############################################################################### -# # -# Copyright (C) 2008 Edward d'Auvergne # -# # -# This file is part of the program relax (http://www.nmr-relax.com). # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <http://www.gnu.org/licenses/>. # -# # -############################################################################### - -# Python module imports. -from unittest import TestCase - -# relax module imports. -from generic_fns import relax_re - - -class Test_relax_re(TestCase): - """Unit tests for the functions of the 'generic_fns.relax_re' module.""" - - # Place the generic_fns.relax_re module into the class namespace. - relax_re_fns = relax_re - - - def test_search(self): - """Test the proper behaviour of the generic_fns.relax_re.search() function.""" - - # Test a number of calls which should return True. - self.assertEqual(True, self.relax_re_fns.search('H', 'H')) - self.assertEqual(True, self.relax_re_fns.search('H*', 'H')) - self.assertEqual(True, self.relax_re_fns.search('H*', 'H1')) - self.assertEqual(True, self.relax_re_fns.search('H1', 'H1')) - self.assertEqual(True, self.relax_re_fns.search('^H*', 'H')) - self.assertEqual(True, self.relax_re_fns.search('^H*$', 'H')) - self.assertEqual(True, self.relax_re_fns.search('^H*$', 'H')) - - # Test a number of calls which should return False. - self.assertEqual(False, self.relax_re_fns.search('H*', 'NH')) - self.assertEqual(False, self.relax_re_fns.search('H', 'HN')) - self.assertEqual(False, self.relax_re_fns.search('H', 'H1')) Copied: trunk/test_suite/unit_tests/_lib/test_regex.py (from r19067, trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py) URL: http://svn.gna.org/viewcvs/relax/trunk/test_suite/unit_tests/_lib/test_regex.py?p2=trunk/test_suite/unit_tests/_lib/test_regex.py&p1=trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py&r1=19067&r2=19073&rev=19073&view=diff ============================================================================== --- trunk/test_suite/unit_tests/_generic_fns/test_relax_re.py (original) +++ trunk/test_suite/unit_tests/_lib/test_regex.py Sat Mar 23 18:27:27 2013 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2008 Edward d'Auvergne # +# Copyright (C) 2008-2013 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -23,29 +23,29 @@ from unittest import TestCase # relax module imports. -from generic_fns import relax_re +from lib import regex -class Test_relax_re(TestCase): - """Unit tests for the functions of the 'generic_fns.relax_re' module.""" +class Test_regex(TestCase): + """Unit tests for the functions of the 'lib.regex' module.""" - # Place the generic_fns.relax_re module into the class namespace. - relax_re_fns = relax_re + # Place the lib.regex module into the class namespace. + regex = regex def test_search(self): - """Test the proper behaviour of the generic_fns.relax_re.search() function.""" + """Test the proper behaviour of the lib.regex.search() function.""" # Test a number of calls which should return True. - self.assertEqual(True, self.relax_re_fns.search('H', 'H')) - self.assertEqual(True, self.relax_re_fns.search('H*', 'H')) - self.assertEqual(True, self.relax_re_fns.search('H*', 'H1')) - self.assertEqual(True, self.relax_re_fns.search('H1', 'H1')) - self.assertEqual(True, self.relax_re_fns.search('^H*', 'H')) - self.assertEqual(True, self.relax_re_fns.search('^H*$', 'H')) - self.assertEqual(True, self.relax_re_fns.search('^H*$', 'H')) + self.assertEqual(True, self.regex.search('H', 'H')) + self.assertEqual(True, self.regex.search('H*', 'H')) + self.assertEqual(True, self.regex.search('H*', 'H1')) + self.assertEqual(True, self.regex.search('H1', 'H1')) + self.assertEqual(True, self.regex.search('^H*', 'H')) + self.assertEqual(True, self.regex.search('^H*$', 'H')) + self.assertEqual(True, self.regex.search('^H*$', 'H')) # Test a number of calls which should return False. - self.assertEqual(False, self.relax_re_fns.search('H*', 'NH')) - self.assertEqual(False, self.relax_re_fns.search('H', 'HN')) - self.assertEqual(False, self.relax_re_fns.search('H', 'H1')) + self.assertEqual(False, self.regex.search('H*', 'NH')) + self.assertEqual(False, self.regex.search('H', 'HN')) + self.assertEqual(False, self.regex.search('H', 'H1'))