Package test_suite :: Package unit_tests :: Package _lib :: Package _structure :: Package _internal :: Module test_object
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._lib._structure._internal.test_object

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 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  # relax module imports. 
23  from lib.structure.internal import object 
24  from test_suite.unit_tests.base_classes import UnitTestCase 
25   
26   
27 -class Test_object(UnitTestCase):
28 """Unit tests for the lib.structure.internal.object internal structural object module.""" 29
30 - def test_add_atom_sort(self):
31 """Test for automated atom sequence sorting of the add_atom() method.""" 32 33 # Initialise a structural object and add some atoms. 34 struct = object.Internal() 35 36 # Create three molecules 'X', 'Y', and 'Z' with some connected atoms. 37 struct.add_atom(atom_name='A', res_name='UNK', res_num=1, mol_name='X', pos=[1., 0., -1.], element='S', sort=True) 38 struct.add_atom(atom_name='A', res_name='UNK', res_num=1, mol_name='Y', pos=[0., 0., 0.], element='S', sort=True) 39 struct.add_atom(atom_name='A', res_name='UNK', res_num=1, mol_name='Z', pos=[-1., 0., 1.], element='S', sort=True) 40 struct.add_atom(atom_name='A', res_name='UNK', res_num=3, mol_name='X', pos=[1., 2., -1.], element='S', sort=True) 41 struct.add_atom(atom_name='A', res_name='UNK', res_num=3, mol_name='Y', pos=[0., 2., 0.], element='S', sort=True) 42 struct.add_atom(atom_name='A', res_name='UNK', res_num=3, mol_name='Z', pos=[-1., 2., 1.], element='S', sort=True) 43 struct.connect_atom(mol_name='X', index1=0, index2=1) 44 struct.connect_atom(mol_name='Y', index1=0, index2=1) 45 struct.connect_atom(mol_name='Z', index1=0, index2=1) 46 struct.add_atom(atom_name='A', res_name='UNK', res_num=2, mol_name='X', pos=[1., 20., -1.], element='S', sort=True) 47 struct.add_atom(atom_name='A', res_name='UNK', res_num=2, mol_name='Y', pos=[0., 20., 0.], element='S', sort=True) 48 struct.add_atom(atom_name='A', res_name='UNK', res_num=2, mol_name='Z', pos=[-1., 20., 1.], element='S', sort=True) 49 50 # The sorted data. 51 data = [[ 52 ['A', 'UNK', 1, [1., 0., -1.], 'S', [2]], 53 ['A', 'UNK', 2, [1., 20., -1.], 'S', []], 54 ['A', 'UNK', 3, [1., 2., -1.], 'S', [0]] 55 ], [ 56 ['A', 'UNK', 1, [0., 0., 0.], 'S', [2]], 57 ['A', 'UNK', 2, [0., 20., 0.], 'S', []], 58 ['A', 'UNK', 3, [0., 2., 0.], 'S', [0]] 59 ], [ 60 ['A', 'UNK', 1, [-1., 0., 1.], 'S', [2]], 61 ['A', 'UNK', 2, [-1., 20., 1.], 'S', []], 62 ['A', 'UNK', 3, [-1., 2., 1.], 'S', [0]] 63 ]] 64 mol_names = ['X', 'Y', 'Z'] 65 66 # Test the object. 67 self.assertEqual(len(struct.structural_data), 1) 68 for i in range(len(struct.structural_data[0].mol)): 69 # Alias. 70 mol = struct.structural_data[0].mol[i] 71 72 # Check the molecule data. 73 self.assertEqual(mol.mol_name, mol_names[i]) 74 75 # Loop over the atoms. 76 for j in range(len(mol.atom_name)): 77 self.assertEqual(mol.atom_name[j], data[i][j][0]) 78 self.assertEqual(mol.res_name[j], data[i][j][1]) 79 self.assertEqual(mol.res_num[j], data[i][j][2]) 80 self.assertEqual(mol.x[j], data[i][j][3][0]) 81 self.assertEqual(mol.y[j], data[i][j][3][1]) 82 self.assertEqual(mol.z[j], data[i][j][3][2]) 83 self.assertEqual(mol.element[j], data[i][j][4]) 84 self.assertEqual(mol.bonded[j], data[i][j][5])
85