File: test_io_pdb.py

package info (click to toggle)
openstructure 2.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 206,240 kB
  • sloc: cpp: 188,571; python: 36,686; ansic: 34,298; fortran: 3,275; sh: 312; xml: 146; makefile: 29
file content (90 lines) | stat: -rw-r--r-- 3,376 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import unittest
from ost import *
import subprocess

class TestPDB(unittest.TestCase):
  def setUp(self):
    pass

  def test_compnd_parser(self):
    e=io.LoadPDB('testfiles/pdb/compnd.pdb', restrict_chains="A")
    self.assertEqual(e.GetChainCount(), 1)
    ch = e.FindChain("A");
    self.assertEqual(ch.GetIntProp("mol_id"), 1)

  def test_properly_assigns_profile_properties(self):
    io.profiles['TEST'] = io.IOProfile()
    io.profiles['TEST'].fault_tolerant = False
    self.assertFalse(io.profiles['TEST'].fault_tolerant)
    self.assertFalse(io.profiles['TEST'].Copy().fault_tolerant)
    io.profiles['TEST'].fault_tolerant = True
    self.assertTrue(io.profiles['TEST'].fault_tolerant)
    self.assertTrue(io.profiles['TEST'].Copy().fault_tolerant)
  def test_no_bond_feasibility(self):
    io.profiles['FEAS_CHECK']=io.IOProfile(processor=conop.HeuristicProcessor(check_bond_feasibility=True))
    io.profiles['NO_FEAS_CHECK']=io.IOProfile(processor=conop.HeuristicProcessor(check_bond_feasibility=False))
        
    e1=io.LoadPDB('testfiles/pdb/simple_defective.pdb', restrict_chains="A",profile='FEAS_CHECK')
    e2=io.LoadPDB('testfiles/pdb/simple_defective.pdb', restrict_chains="A",profile='NO_FEAS_CHECK')
    ed=io.LoadPDB('testfiles/pdb/simple_defective.pdb', restrict_chains="A")
    
    res1=e1.FindResidue('A',3)
    res2=e2.FindResidue('A',3)
    resd=ed.FindResidue('A',3)

    self.assertFalse(mol.BondExists(res1.FindAtom("CA"),res1.FindAtom("CB")))
    self.assertTrue(mol.BondExists(res2.FindAtom("CA"),res2.FindAtom("CB")))
    self.assertTrue(mol.BondExists(resd.FindAtom("CA"),resd.FindAtom("CB")))

  @unittest.skip("not running tests requiring network access")
  def test_remote_loading(self):

    if subprocess.call(['ping google.com -c 1'], shell=True,
                       stdout=subprocess.PIPE, stderr=subprocess.PIPE) != 0:
      print("No internet connection (or wrong OS) to test remote loading in "
            "io.LoadPDB: ignoring unit test")
      return

    with self.assertRaises(IOError):
      io.LoadPDB('1ake', remote=True, remote_repo="cheeseisgoodforyou")

    # let's hope that crambin stays the same forever
    crambin_pdb = io.LoadPDB('1crn', remote=True, remote_repo='pdb')
    self.assertEqual(len(crambin_pdb.residues), 46)
    self.assertEqual(len(crambin_pdb.atoms), 327)

  def test_conect(self):
    """ See whether read_conect has an effect on reading CONECT
    """
    prot = io.LoadPDB("testfiles/pdb/conect.pdb")
    res = prot.FindResidue("A", mol.ResNum(3))
    a1 = res.FindAtom("N")
    a2 = res.FindAtom("CA")
    tmp = sorted([str(a1), str(a2)])
    bond = None
    for b in prot.bonds:
      if sorted([str(b.GetFirst()), str(b.GetSecond())]) == tmp:
        bond = b
        break
    self.assertTrue(bond is not None)
    self.assertEqual(bond.bond_order, 1)

    prot = io.LoadPDB("testfiles/pdb/conect.pdb", read_conect=True)
    res = prot.FindResidue("A", mol.ResNum(3))
    a1 = res.FindAtom("N")
    a2 = res.FindAtom("CA")
    tmp = sorted([str(a1), str(a2)])
    bond = None
    for b in prot.bonds:
      if sorted([str(b.GetFirst()), str(b.GetSecond())]) == tmp:
        bond = b
        break
    self.assertTrue(bond is not None)
    self.assertEqual(bond.bond_order, 2) # now it should be two

if __name__== '__main__':
  from ost import testutils
  testutils.RunTests()