File: PYMOL-3082.py

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (88 lines) | stat: -rw-r--r-- 2,488 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
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
'''
chempy.Atom defaults
'''

import os
import sys
from pymol import cmd, CmdException, testing, stored

@testing.requires_version('1.8.2')
class TestChempyAtom(testing.PyMOLTestCase):
    def _assert_iterate_equal(self, sele, key, value):
        stored.values = []
        cmd.iterate(sele, 'stored.values.append(' + key + ')')
        for v in stored.values:
            self.assertEqual(v, value)

    def test(self):
        cmd.fragment('gly', 'm1')

        cmd.alter('*', 'chain = "ABC"')
        cmd.alter('*', 'segi = "DEF"')

        m = cmd.get_model()

        self.assertEqual(m.atom[0].resn, "GLY")
        self.assertEqual(m.atom[0].chain, "ABC")
        self.assertEqual(m.atom[0].segi, "DEF")

        cmd.alter('*', 'resn = ""')
        cmd.alter('*', 'chain = ""')
        cmd.alter('*', 'segi = ""')
        cmd.alter('*', 'resi = "0"')

        m = cmd.get_model()

        self.assertEqual(m.atom[0].resn, "")
        self.assertEqual(m.atom[0].chain, "")
        self.assertEqual(m.atom[0].segi, "")
        self.assertEqual(m.atom[0].resi, "0")
        self.assertEqual(m.atom[0].resi_number, 0)

        cmd.alter('*', 'resn = "UNK"')
        cmd.alter('*', 'resi = "1A"')

        m = cmd.get_model()

        self.assertEqual(m.atom[0].resn, "UNK")
        self.assertEqual(m.atom[0].resi, "1A")
        self.assertEqual(m.atom[0].resi_number, 1)

        if m.atom[0].has('ins_code'):  # not exported before 2.3
            self.assertEqual(m.atom[0].ins_code, "A")

        cmd.delete('*')
        cmd.load_model(m, 'm1')

        self._assert_iterate_equal('*', 'resi', '1A')
        self._assert_iterate_equal('*', 'resn', 'UNK')

        for a in m.atom:
            a.ins_code = "B"

        cmd.delete('*')
        cmd.load_model(m, 'm1')

        self._assert_iterate_equal('*', 'resi', '1B')

        cmd.alter('*', 'resi = "2"')

        m = cmd.get_model()

        self.assertEqual(m.atom[0].resi, "2")

        if m.atom[0].has('ins_code'):  # not exported before 2.3
            self.assertEqual(m.atom[0].ins_code, "")

        for a in m.atom:
            del a.resi_number  # pre 2.3
            a.resi = "3C"

            # >= 2.3 sets resi_number for resi
            if a.resi_number == 3:
                self.assertEqual(a.ins_code, 'C')

        cmd.delete('*')
        cmd.load_model(m, 'm1')

        self._assert_iterate_equal('*', 'resi', '3C')