File: test_undo_editing.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 (100 lines) | stat: -rw-r--r-- 2,666 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
'''
Testing: pymol.editing
'''

import pytest

from pymol import cmd


def test_undo_protect():
    cmd.pseudoatom('m1', pos=[0., 0., 0.])
    cmd.pseudoatom('m1', pos=[1., 0., 0.])
    cmd.protect('m1`1')
    cmd.undo()
    cmd.translate([0., 0., 1.])
    assert [0., 0., 1.] == cmd.get_atom_coords('m1`1')
    assert [1., 0., 1.] == cmd.get_atom_coords('m1`2')
    cmd.protect('m1`1')
    cmd.undo()
    cmd.redo()
    cmd.translate([0., 1., 0.])
    assert [0., 0., 1.] == cmd.get_atom_coords('m1`1')
    assert [1., 1., 1.] == cmd.get_atom_coords('m1`2')


def test_undo_deprotect():
    cmd.pseudoatom('m1', pos=[0., 0., 0.])
    cmd.pseudoatom('m1', pos=[1., 0., 0.])
    cmd.protect('m1`1')
    cmd.deprotect()
    cmd.undo()
    cmd.translate([0., 0., 1.])
    assert [0., 0., 0.] == cmd.get_atom_coords('m1`1')
    assert [1., 0., 1.] == cmd.get_atom_coords('m1`2')
    cmd.protect('m1`1')
    cmd.deprotect()
    cmd.undo()
    cmd.redo()
    cmd.translate([0., 1., 0.])
    assert [0., 1., 0.] == cmd.get_atom_coords('m1`1')
    assert [1., 1., 1.] == cmd.get_atom_coords('m1`2')


def assert_array_equal(arr1, arr2, _not=False):
    import numpy

    a1 = numpy.asarray(arr1)
    a2 = numpy.asarray(arr2)

    assert a1.shape == a2.shape
    assert not _not == numpy.allclose(a1, a2, 0, 0)


def assert_array_not_equal(arr1, arr2):
    assert_array_equal(arr1, arr2, True)


def test_undo_update():
    # 3 states
    cmd.fragment('gly', 'm1')
    cmd.create('m1', 'm1', 1, 2)
    cmd.create('m1', 'm1', 1, 3)
    # second object, 90 degree rotates
    cmd.copy('m2', 'm1')
    cmd.rotate('x', 90, '(m2)', state=0)
    # reference coordsets
    cs = cmd.get_coordset
    cs1 = cs('m1', 1)
    cs2 = cs('m2', 1)
    # m2/3 will change (pre-check)
    assert_array_equal(cs2, cs('m2', 3))
    assert_array_not_equal(cs1, cs('m2', 3))
    # update explicit state
    cmd.update('m2', 'm1', 3, 2)
    # m2/3 has changed
    assert_array_equal(cs1, cs('m2', 3))
    assert_array_not_equal(cs2, cs('m2', 3))
    cmd.undo()
    assert_array_not_equal(cs1, cs('m2', 3))
    assert_array_equal(cs2, cs('m2', 3))
    cmd.redo()
    assert_array_equal(cs1, cs('m2', 3))
    assert_array_not_equal(cs2, cs('m2', 3))


def test_undo_fit():
    cmd.fragment("gly", "m1")
    cmd.create("m2", "m1")
    cmd.rotate("y", "90", "m2")
    rms = cmd.rms_cur("m1", "m2")
    assert rms != pytest.approx(0.0)
    cmd.fit("m1", "m2")
    rms = cmd.rms_cur("m1", "m2")
    assert rms == pytest.approx(0.0)
    cmd.undo()
    rms = cmd.rms_cur("m1", "m2")
    assert rms != pytest.approx(0.0)
    cmd.redo()
    rms = cmd.rms_cur("m1", "m2")
    assert rms == pytest.approx(0.0)