File: the_hammer.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 (85 lines) | stat: -rw-r--r-- 2,531 bytes parent folder | download | duplicates (4)
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
from PyQt5 import QtCore
import math
# remove all objects from scene, just in case
scene.RemoveAll()

class Anim(QtCore.QTimer):
    def __init__(self, a, b):
        QtCore.QTimer.__init__(self)
        self.a=a
        self.b=b
        self.angle=0.0
        self.dir=0.01
        self.edi=self.a.view.handle.EditXCS(mol.UNBUFFERED_EDIT)
        self.timeout.connect(self.OnTimer)
        
    def OnTimer(self):
        self.angle+=self.dir
        if self.angle>math.pi/2:
          self.dir=-self.dir
        if self.angle<0:
          self.dir=-self.dir
        rot=geom.AxisRotation(geom.Vec3(0.0, 0.0, -1.0), self.angle)
        self.edi.SetTransform(geom.Mat4(rot))
        self.edi.UpdateICS()
        for a in self.b.view.atoms:
          score=mol.alg.ClashScore(a.handle, self.a.view)
          a.SetFloatProp('clash', score)
        self.a.UpdatePositions()
        self.b.ReapplyColorOps()


def Hammer(off=geom.Vec3()):
  ent=mol.CreateEntity()
  edi=ent.EditXCS(mol.BUFFERED_EDIT)
  chain=edi.InsertChain("A")
  res=edi.AppendResidue(chain, "QUAD")
  a=edi.InsertAtom(res, "A", off+geom.Vec3(0.0, 0.0, 0.0), "H")
  b=edi.InsertAtom(res, "B", off+geom.Vec3(0.0, 4.0, 0.0), "H")
  c=edi.InsertAtom(res, "C", off+geom.Vec3(2.0, 4.0, 0.0), "H")
  d=edi.InsertAtom(res, "D", off+geom.Vec3(2.0, 5.0, 0.0), "H")
  e=edi.InsertAtom(res, "E", off+geom.Vec3(-2.0, 5.0, 0.0), "H")
  f=edi.InsertAtom(res, "F", off+geom.Vec3(-2.0, 4.0, 0.0), "H")
  edi.Connect(a, b)
  edi.Connect(b, c)
  edi.Connect(c, d)
  edi.Connect(d, e)
  edi.Connect(e, f)
  edi.Connect(f, b)    
  return ent

def TheWall():
  ent=mol.CreateEntity()
  edi=ent.EditXCS(mol.BUFFERED_EDIT)
  chain=edi.InsertChain("A")
  res=edi.AppendResidue(chain, "QUAD")
  index=0
  for i in range(-10, 10):
    for j in range(-10, 10):
      index+=1
      atom=edi.InsertAtom(res, "A%d" % index, geom.Vec3(4.0, -2.0, 0.0)+
                          geom.Vec3(i, 0, j)*0.25)
      atom.radius=0.25
                     
  return ent

a=Hammer()
b=TheWall()

a_go=gfx.Entity("a", gfx.CUSTOM, a)
b_go=gfx.Entity("b", gfx.CUSTOM, b)
for a in a.atoms:
  a.SetFloatProp('clash', 0.0)

scene.Add(a_go)
scene.Add(b_go)

anim=Anim(a_go, b_go)
anim.start(20)
grad=gfx.Gradient()
grad.SetColorAt(0.0, gfx.Color(0.0, 1.0, 0.0))
grad.SetColorAt(0.5, gfx.Color(1.0, 0.0, 1.0))
grad.SetColorAt(1.0, gfx.Color(1.0, 0.0, 0.0))
b_go.ColorBy('clash', gfx.Color(0,1,0), gfx.Color(1,0,0), 0.0, 10.0, mol.Prop.Level.ATOM)
scene.CenterOn(b_go)
print('Demo 7: Illustrating a clash score')