Author: bugman Date: Tue Sep 23 18:02:05 2014 New Revision: 25971 URL: http://svn.gna.org/viewcvs/relax?rev=25971&view=rev Log: Created a special internal structural object selection object. This will be used for massively speeding up the internal structural object. The use of the lib.selection module by the internal structural object is currently very slow as a huge number of calls to re.search() are required. The idea is to avoid this by using lib.selection once to populate this new selection object, and then reusing this object to loop over molecules and atoms. Added: trunk/lib/structure/internal/selection.py Modified: trunk/lib/structure/internal/__init__.py Modified: trunk/lib/structure/internal/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/__init__.py?rev=25971&r1=25970&r2=25971&view=diff ============================================================================== --- trunk/lib/structure/internal/__init__.py (original) +++ trunk/lib/structure/internal/__init__.py Tue Sep 23 18:02:05 2014 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2013 Edward d'Auvergne # +# Copyright (C) 2013-2014 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -26,5 +26,6 @@ 'displacements', 'models', 'molecules', - 'object' + 'object', + 'selection' ] Added: trunk/lib/structure/internal/selection.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/selection.py?rev=25971&view=auto ============================================================================== --- trunk/lib/structure/internal/selection.py (added) +++ trunk/lib/structure/internal/selection.py Tue Sep 23 18:02:05 2014 @@ -0,0 +1,77 @@ +############################################################################### +# # +# Copyright (C) 2014 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 containing the fast structural selection object.""" + + +class Internal_selection: + """The fast structural selection object.""" + + def __init__(self): + """Set up the object.""" + + # The molecule index list. + self._mol_indices = [] + + # The atom index list of lists. + self._atom_indices = [] + + + def add_atom(self, mol_index=None, atom_index=None): + """Add an atom index to the object. + + @keyword mol_index: The index of the molecule. + @type mol_index: int + @keyword atom_index: The index of the atom. + @type atom_index: int + """ + + # Store the index. + self._atom_indices[mol_index].append(atom_index) + + + def add_mol(self, mol_index=None): + """Add a molecule index to the object. + + @keyword mol_index: The index of the molecule. + @type mol_index: int + """ + + # Store the index. + self._mol_indices.append(mol_index) + + # Add a new atom list. + self._atom_indices.append([]) + + + def loop(self): + """Fast loop over all molecule and atom indices. + + @return: The molecule and atom index pairs for all atoms. + @rtype: int, int + """ + + # Molecule loop. + for mol_index in self._mol_indices: + # Atom loop. + for atom_index in self._atom_indices[mol_index]: + yield mol_index, atom_index