Package lib :: Package structure :: Package internal :: Module selection
[hide private]
[frames] | no frames]

Source Code for Module lib.structure.internal.selection

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2014-2015 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Module containing the fast structural selection object.""" 
 24   
 25   
26 -class Internal_selection:
27 """The fast structural selection object.""" 28
29 - def __init__(self):
30 """Set up the object.""" 31 32 # The molecule index list. 33 self._mol_indices = [] 34 35 # The atom index list of lists. 36 self._atom_indices = []
37 38
39 - def add_atom(self, mol_index=None, atom_index=None):
40 """Add an atom index to the object. 41 42 @keyword mol_index: The index of the molecule. 43 @type mol_index: int 44 @keyword atom_index: The index of the atom. 45 @type atom_index: int 46 """ 47 48 # Find the molecule index. 49 index = self._mol_indices.index(mol_index) 50 51 # Store the index. 52 self._atom_indices[index].append(atom_index)
53 54
55 - def add_mol(self, mol_index=None):
56 """Add a molecule index to the object. 57 58 @keyword mol_index: The index of the molecule. 59 @type mol_index: int 60 """ 61 62 # Store the index. 63 self._mol_indices.append(mol_index) 64 65 # Add a new atom list. 66 self._atom_indices.append([])
67 68
69 - def count_atoms(self):
70 """Return the number of atoms in the selection.""" 71 72 # No data. 73 if self._atom_indices == []: 74 return 0 75 76 # Sum the atoms of all molecules. 77 sum = 0 78 for i in range(len(self._atom_indices)): 79 sum += len(self._atom_indices[i]) 80 81 # Return the sum. 82 return sum
83 84
85 - def loop(self):
86 """Fast loop over all molecule and atom indices. 87 88 @return: The molecule and atom index pairs for all atoms. 89 @rtype: int, int 90 """ 91 92 # Molecule loop. 93 for mol_index in self._mol_indices: 94 # Find the molecule index. 95 index = self._mol_indices.index(mol_index) 96 97 # Atom loop. 98 for atom_index in self._atom_indices[index]: 99 yield mol_index, atom_index
100 101
102 - def mol_loop(self):
103 """Fast loop over all molecule indices. 104 105 @return: The molecule index. 106 @rtype: int 107 """ 108 109 # Molecule loop. 110 for mol_index in self._mol_indices: 111 yield mol_index
112