File: test_xyzrn.py

package info (click to toggle)
python-cogent 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,424 kB
  • ctags: 24,343
  • sloc: python: 134,200; makefile: 100; ansic: 17; sh: 10
file content (45 lines) | stat: -rw-r--r-- 1,487 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python

import os, tempfile
from unittest import main
from cogent.util.unit_test import TestCase

from cogent import FromFilenameStructureParser
from cogent.struct.selection import einput
from cogent.format import xyzrn

__author__ = "Marcin Cieslik"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__contributors__ = ["Marcin Cieslik"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Marcin Cieslik"
__email__ = "mpc4p@virginia.edu"
__status__ = "Development"

class XyzrnTest(TestCase):
    """Tests conversion of PDB files into the informal xyzrn format."""

    def setUp(self):
        self.structure = FromFilenameStructureParser('data/1A1X.pdb')
        self.residues = einput(self.structure, 'R')
        self.atoms = einput(self.structure, 'A')
        self.residue8 = self.residues.values()[8]
        self.atom17 = self.atoms.values()[17]
        self.atom23 = self.atoms.values()[23]
        
    def test_write_atom(self):
        fd, fn = tempfile.mkstemp()
        os.close(fd)
        handle = open(fn, 'wb')
        xyzrn.XYZRNWriter(handle, [self.atom17])
        handle.close()
        handle = open(fn, 'rb')
        coords_radius = [float(n) for n in handle.read().split()[:4]]
        self.atom17.setRadius()
        radius = self.atom17.getRadius()
        self.assertFloatEqualRel(self.atom17.coords, coords_radius[:3])
        self.assertFloatEqualRel(radius, coords_radius[3])
        
if __name__ == '__main__':
    main()