1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module containing the fast structural selection object."""
24
25
27 """The fast structural selection object."""
28
30 """Set up the object."""
31
32
33 self._mol_indices = []
34
35
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
49 index = self._mol_indices.index(mol_index)
50
51
52 self._atom_indices[index].append(atom_index)
53
54
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
63 self._mol_indices.append(mol_index)
64
65
66 self._atom_indices.append([])
67
68
70 """Return the number of atoms in the selection."""
71
72
73 if self._atom_indices == []:
74 return 0
75
76
77 sum = 0
78 for i in range(len(self._atom_indices)):
79 sum += len(self._atom_indices[i])
80
81
82 return sum
83
84
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
93 for mol_index in self._mol_indices:
94
95 index = self._mol_indices.index(mol_index)
96
97
98 for atom_index in self._atom_indices[index]:
99 yield mol_index, atom_index
100
101
103 """Fast loop over all molecule indices.
104
105 @return: The molecule index.
106 @rtype: int
107 """
108
109
110 for mol_index in self._mol_indices:
111 yield mol_index
112