File: moving.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 (298 lines) | stat: -rw-r--r-- 7,639 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

from pymol import cmd, testing, stored

class TestMoving(testing.PyMOLTestCase):

    def prep_movie(self):
        cmd.mset("1x60")
    
    def testAccept(self):
        cmd.accept
        self.skipTest("TODO")

    def testBackward(self):
        self.prep_movie()
        cmd.middle()
        cmd.backward()
        self.assertEquals(cmd.get_frame(),30)

        cmd.frame(1)
        cmd.backward()
        self.assertEquals(cmd.get_frame(),1)
        

    def testDecline(self):
        cmd.decline
        self.skipTest("TODO")

    def testEnding(self):
        self.prep_movie()
        cmd.ending()
        self.assertEquals(cmd.get_frame(),60)

    def testForward(self):
        self.prep_movie()
        cmd.forward()
        self.assertEquals(cmd.get_frame(),2)
        cmd.forward()
        self.assertEquals(cmd.get_frame(),3)
        cmd.frame(30)
        self.assertEquals(cmd.get_frame(),30)
        cmd.frame(60)
        cmd.forward()
        self.assertEquals(cmd.get_frame(),60)

        cmd.frame(60)
        cmd.forward()
        self.assertEquals(cmd.get_frame(),60)

    def testFrame(self):
        self.prep_movie()
        cmd.frame(30)
        self.assertEquals(cmd.get_frame(),30)

        cmd.frame(60)
        self.assertEquals(cmd.get_frame(),60)

        cmd.frame(65)
        self.assertEquals(cmd.get_frame(),60)

        cmd.frame(-5)
        self.assertEquals(cmd.get_frame(),1)

        cmd.frame(10)
        cmd.frame(1)
        self.assertEquals(cmd.get_frame(),1)


    def testGetFrame(self):
        self.prep_movie()
        cmd.frame(30)
        self.assertEquals(cmd.get_frame(),30)

        cmd.frame(60)
        self.assertEquals(cmd.get_frame(),60)

        cmd.frame(65)
        self.assertEquals(cmd.get_frame(),60)

        cmd.frame(-5)
        self.assertEquals(cmd.get_frame(),1)

        cmd.frame(10)
        cmd.frame(1)
        self.assertEquals(cmd.get_frame(),1)

    def testGetMoviePlaying(self):
        self.prep_movie()
        cmd.mplay()
        self.assertEquals(cmd.get_movie_playing(),1)

        cmd.mstop()
        self.assertEquals(cmd.get_movie_playing(),0)
        

    def testGetState(self):
        cmd.get_state
        self.skipTest("TODO")

    def testMadd(self):
        # test clearing
        self.prep_movie()
        self.assertEquals(cmd.count_frames(),60)

        # test states and frame mapping
        cmd.madd("1x10 1 -10 10 -1")
        self.assertEquals(cmd.count_frames(),90)
        
        cmd.frame(1)
        self.assertEquals(cmd.get_frame(),1)
        self.assertEquals(cmd.get("state"),"1")
        cmd.frame(10)
        self.assertEquals(cmd.get_frame(),10)
        self.assertEquals(cmd.get("state"),"1")
        cmd.frame(72)
        self.assertEquals(cmd.get_frame(),72)
        self.assertEquals(cmd.get("state"),"2")
        cmd.frame(82)
        self.assertEquals(cmd.get_frame(),82)
        self.assertEquals(cmd.get("state"),"9")
        cmd.frame(90)
        self.assertEquals(cmd.get_frame(),90)
        self.assertEquals(cmd.get("state"),"1")

    def testMappend(self):
        self.prep_movie()
        cmd.fragment("ala")
        cmd.mappend(5,"delete *")
        cmd.mappend(5,"frame 1")
        cmd.frame(5)
        self.assertEquals(len(cmd.get_names()),0)
        self.assertEquals(cmd.get_frame(),1)

        
    def testMclear(self):
        cmd.mclear
        self.skipTest("TODO")

    def testMcopy(self):
        cmd.mcopy
        self.skipTest("TODO")

    def testMdelete(self):
        cmd.mset("1x10 1 -10 10 -1")

        # 1-10 = state 1
        # 11-20 = states 1..10
        # 21-30 = states 10..1

        cmd.mdelete(count=10, frame=11)
        # simple delete
        self.assertEquals(cmd.count_frames(),20)

        # test state mapping
        cmd.frame(1)
        self.assertEquals(cmd.get("state"),"1")
        cmd.frame(11)
        self.assertEquals(cmd.get("state"),"10")
        cmd.frame(20)
        self.assertEquals(cmd.get("state"),"1")

    def testMdo(self):
        self.prep_movie()
        cmd.fragment("ala")
        cmd.mdo(5,"delete *")
        cmd.frame(5)
        self.assertEquals(len(cmd.get_names()),0)

    def testMdump(self):
        cmd.mdump
        self.skipTest("TODO: This prints to console, not sure how to test.")

    def testMiddle(self):
        self.prep_movie()
        cmd.middle()
        self.assertEquals(cmd.get_frame(),31)

    def testMinsert(self):
        self.prep_movie()
        cmd.minsert(20)
        self.assertEquals(cmd.count_frames(),80)

        # need a more sophisticated test for this
        

    def testMmatrix(self):
        cmd.mmatrix
        self.skipTest("TODO")

    def testMmove(self):
        cmd.mmove
        self.skipTest("TODO")

    def testMplay(self):
        self.prep_movie()
        cmd.mplay()
        self.assertEquals(cmd.get_movie_playing(),1)
        cmd.mstop()

    @testing.foreach(0, 1)
    @testing.requires_version('1.8.6')
    def testMpng(self, modal):
        import glob, os

        shape2 = (100, 100)
        cmd.mset("1x4")
        cmd.mdo(1, 'bg_color red')
        cmd.mdo(3, 'bg_color blue')

        with testing.mkdtemp() as dirname:
            cmd.mpng(os.path.join(dirname, 'image'), width=shape2[0], height=shape2[1])
            filenames = glob.glob(os.path.join(dirname, 'image*.png'))
            filenames.sort()

            self.assertEqual(4, len(filenames))

            img = self.get_imagearray(filenames[0])
            self.assertEqual(img.shape[:2], shape2)
            self.assertImageHasColor('red', img)

            img = self.get_imagearray(filenames[-1])
            self.assertEqual(img.shape[:2], shape2)
            self.assertImageHasColor('blue', img)

    def testMset(self):
        # basic tet
        self.prep_movie()
        self.assertEquals(cmd.count_frames(),60)

        # test clearing
        cmd.mset()
        self.assertEquals(cmd.count_frames(),0)

        # test states and frame mapping
        cmd.mset("1x10 1 -10 10 -1")
        cmd.frame(1)
        self.assertEquals(cmd.get_frame(),1)
        self.assertEquals(cmd.get("state"),"1")
        cmd.frame(10)
        self.assertEquals(cmd.get_frame(),10)
        self.assertEquals(cmd.get("state"),"1")
        cmd.frame(12)
        self.assertEquals(cmd.get_frame(),12)
        self.assertEquals(cmd.get("state"),"2")
        cmd.frame(22)
        self.assertEquals(cmd.get_frame(),22)
        self.assertEquals(cmd.get("state"),"9")
        cmd.frame(30)
        self.assertEquals(cmd.get_frame(),30)
        self.assertEquals(cmd.get("state"),"1")

    def testMstop(self):
        self.prep_movie()
        cmd.mplay()
        cmd.mstop()
        self.assertEquals(cmd.get_movie_playing(),0)

    def testMtoggle(self):
        self.prep_movie()
        cmd.mstop()
        
        # toggle on
        cmd.mtoggle()
        self.assertEquals(cmd.get_movie_playing(),1)
        # toggle off
        cmd.mtoggle()
        self.assertEquals(cmd.get_movie_playing(),0)


    def testMview(self):
        cmd.mview
        self.skipTest("TODO")

    def testRewind(self):
        self.prep_movie()
        cmd.frame(30)
        self.assertEquals(cmd.get_frame(), 30)

        cmd.rewind()
        self.assertEquals(cmd.get_frame(), 1)

        
    def testSetFrame(self):

        self.prep_movie()

        # within
        cmd.set_frame(30)
        self.assertEquals(cmd.get_frame(),30)

        # extent < 
        cmd.set_frame(-1)
        self.assertEquals(cmd.get_frame(),1)

        # extent > 
        cmd.set_frame(300)
        self.assertEquals(cmd.get_frame(),60)