示例#1
0
    def _test_frame_property(self, obj_type, obj_id, getter):
        # Test frame property works correctly
        molid = VMD.molecule.load('psf', data('water.psf'), 'pdb',
                                  data('water.pdb'))
        VMD.molecule.read(molid, 'dcd', data('water.1.dcd'), waitfor=-1)
        mol = Molecule(molid)
        # To check frame works correctly, check the 'x' coordinate of the object's first atom.

        # Create residue linked to the molecule frame
        obj = obj_type(obj_id)
        self.assertEqual(obj.frame, NOW)
        self.assertAlmostEqual(getter(obj), -1.3421925)
        # Change the molecule frame, the object will follow
        mol.frame = 0
        self.assertEqual(obj.frame, NOW)
        self.assertAlmostEqual(getter(obj), -1.493)
        mol.frame = 4
        self.assertEqual(obj.frame, NOW)
        self.assertAlmostEqual(getter(obj), -1.4773947)

        # Define the object's frame
        obj.frame = 9
        self.assertEqual(obj.frame, 9)
        self.assertAlmostEqual(getter(obj), -1.4120502)
        # Change the molecule frame, the object keeps its frame
        mol.frame = 11
        self.assertEqual(obj.frame, 9)
        self.assertAlmostEqual(getter(obj), -1.4120502)

        # Set the object's frame back to the molecule's frame
        obj.frame = NOW
        self.assertEqual(obj.frame, NOW)
        self.assertAlmostEqual(getter(obj), -1.3674825)
示例#2
0
    def test_molecule_properties(self):
        # Test basic properties of Molecule
        mol = Molecule(self.molid)

        # Check frame property
        mol.frame = 3
        self.assertEqual(VMD.molecule.get_frame(self.molid), 3)
        self.assertEqual(mol.frame, 3)

        mol.frame = 8
        self.assertEqual(VMD.molecule.get_frame(self.molid), 8)
        self.assertEqual(mol.frame, 8)

        # Check name property
        mol.name = 'My precious'
        self.assertEqual(mol.name, 'My precious')
        self.assertEqual(VMD.molecule.name(self.molid), 'My precious')
        mol.name = 'The Ring'
        self.assertEqual(mol.name, 'The Ring')
        self.assertEqual(VMD.molecule.name(self.molid), 'The Ring')

        # Check molecule property
        self.assertIsInstance(mol.molecule, _Molecule)

        # Check error if molecule does not exists
        self.assertRaises(ValueError, Molecule, 66000)
示例#3
0
    def test_selection_updates(self):
        # Test selection updates if frame is changed
        molid = VMD.molecule.load('psf', data('water.psf'), 'pdb',
                                  data('water.pdb'))
        VMD.molecule.read(molid, 'dcd', data('water.1.dcd'), waitfor=-1)
        mol = Molecule(molid)

        # Create selection linked to the molecule frame
        sel = Selection('x < -1.4')
        self.assertEqual(list(sel), [Atom(9), Atom(18), Atom(19), Atom(20)])
        # Change the molecule frame, the selection should follow
        mol.frame = 0
        self.assertEqual(list(sel), [
            Atom(0),
            Atom(1),
            Atom(9),
            Atom(10),
            Atom(18),
            Atom(19),
            Atom(20)
        ])
        mol.frame = 4
        self.assertEqual(
            list(sel),
            [Atom(0), Atom(1),
             Atom(9), Atom(18),
             Atom(19), Atom(20)])

        # Define the selection's frame
        result = [
            Atom(0, frame=9),
            Atom(1, frame=9),
            Atom(9, frame=9),
            Atom(18, frame=9),
            Atom(19, frame=9),
            Atom(20, frame=9)
        ]
        sel.frame = 9
        self.assertEqual(list(sel), result)
        # Change the molecule frame, the selection keeps its frame
        mol.frame = 11
        self.assertEqual(list(sel), result)

        # Set the selection's frame back to the molecule's frame
        sel.frame = NOW
        self.assertEqual(list(sel), [Atom(9), Atom(18), Atom(19), Atom(20)])
示例#4
0
    def test_frames(self):
        # Test frames wrapper

        # Utility to get x coordinate through the trajectory to check results
        sel = VMD.atomsel.atomsel('index 0', molid=self.molid)

        def _get_x_coord():
            # Utility to get x coordinate through trajectory
            values = []
            for frame in xrange(VMD.molecule.numframes(self.molid)):
                sel.frame = frame
                values.append(sel.get('x')[0])
            return values

        # Check number of frames and iterator
        mol = Molecule(self.molid)
        self.assertEqual(len(mol.frames), 13)
        self.assertEqual(list(mol.frames), range(13))

        # Test frame duplication - duplicate focused frame
        mol.frame = 3
        mol.frames.copy()

        # Check there is one more frame
        self.assertEqual(len(mol.frames), 14)
        coords = [-1.493, -1.4911567, -1.4851371, -1.4858487, -1.4773947, -1.4746015, -1.4673382, -1.4535547,
                  -1.4307435, -1.4120502, -1.3853478, -1.3674825, -1.3421925, -1.4858487]
        self.assertAlmostEqualSeqs(_get_x_coord(), coords)
        # Check molecule is focused to the new frame
        self.assertEqual(mol.frame, 13)

        # Test frame duplication - duplicate defined frame
        mol.frames.copy(4)
        # Check there is one more frame
        self.assertEqual(len(mol.frames), 15)
        coords = [-1.493, -1.4911567, -1.4851371, -1.4858487, -1.4773947, -1.4746015, -1.4673382, -1.4535547,
                  -1.4307435, -1.4120502, -1.3853478, -1.3674825, -1.3421925, -1.4858487, -1.4773947]
        self.assertAlmostEqualSeqs(_get_x_coord(), coords)
        # Molecule is focused to the new frame
        self.assertEqual(mol.frame, 14)

        # Test frame deletion - positive index
        del mol.frames[14]
        self.assertEqual(len(mol.frames), 14)
        coords = [-1.493, -1.4911567, -1.4851371, -1.4858487, -1.4773947, -1.4746015, -1.4673382, -1.4535547,
                  -1.4307435, -1.4120502, -1.3853478, -1.3674825, -1.3421925, -1.4858487]
        self.assertAlmostEqualSeqs(_get_x_coord(), coords)

        # Test frame deletion - negative index
        del mol.frames[-2]
        self.assertEqual(len(mol.frames), 13)
        coords = [-1.493, -1.4911567, -1.4851371, -1.4858487, -1.4773947, -1.4746015, -1.4673382, -1.4535547,
                  -1.4307435, -1.4120502, -1.3853478, -1.3674825, -1.4858487]
        self.assertAlmostEqualSeqs(_get_x_coord(), coords)

        # Check deletion of frame slice
        del mol.frames[2:11:3]
        self.assertEqual(len(mol.frames), 10)
        coords = [-1.493, -1.4911567, -1.4858487, -1.4773947, -1.4673382, -1.4535547, -1.4120502, -1.3853478,
                  -1.3674825, -1.4858487]
        self.assertAlmostEqualSeqs(_get_x_coord(), coords)

        # Invalid key for slice
        with self.assertRaises(TypeError):
            del mol.frames[None]