Dynamic recalculation of clash score for a moving object. The real-valued clash score is then color-mapped onto the objects.
1from PyQt5 import QtCore
2import math
3
4scene.RemoveAll()
5
6class Anim(QtCore.QTimer):
7 def __init__(self, a, b):
8 QtCore.QTimer.__init__(self)
9 self.a=a
10 self.b=b
11 self.angle=0.0
12 self.dir=0.01
13 self.edi=self.a.view.handle.EditXCS(mol.UNBUFFERED_EDIT)
14 self.timeout.connect(self.OnTimer)
15
16 def OnTimer(self):
17 self.angle+=self.dir
18 if self.angle>math.pi/2:
19 self.dir=-self.dir
20 if self.angle<0:
21 self.dir=-self.dir
24 self.edi.UpdateICS()
25 for a in self.b.view.atoms:
26 score=mol.alg.ClashScore(a.handle, self.a.view)
27 a.SetFloatProp('clash', score)
28 self.a.UpdatePositions()
29 self.b.ReapplyColorOps()
30
31
32def Hammer(off=geom.Vec3()):
33 ent=mol.CreateEntity()
34 edi=ent.EditXCS(mol.BUFFERED_EDIT)
35 chain=edi.InsertChain("A")
36 res=edi.AppendResidue(chain, "QUAD")
37 a=edi.InsertAtom(res,
"A", off+
geom.Vec3(0.0, 0.0, 0.0),
"H")
38 b=edi.InsertAtom(res,
"B", off+
geom.Vec3(0.0, 4.0, 0.0),
"H")
39 c=edi.InsertAtom(res,
"C", off+
geom.Vec3(2.0, 4.0, 0.0),
"H")
40 d=edi.InsertAtom(res,
"D", off+
geom.Vec3(2.0, 5.0, 0.0),
"H")
41 e=edi.InsertAtom(res,
"E", off+
geom.Vec3(-2.0, 5.0, 0.0),
"H")
42 f=edi.InsertAtom(res,
"F", off+
geom.Vec3(-2.0, 4.0, 0.0),
"H")
43 edi.Connect(a, b)
44 edi.Connect(b, c)
45 edi.Connect(c, d)
46 edi.Connect(d, e)
47 edi.Connect(e, f)
48 edi.Connect(f, b)
49 return ent
50
51def TheWall():
52 ent=mol.CreateEntity()
53 edi=ent.EditXCS(mol.BUFFERED_EDIT)
54 chain=edi.InsertChain("A")
55 res=edi.AppendResidue(chain, "QUAD")
56 index=0
57 for i in range(-10, 10):
58 for j in range(-10, 10):
59 index+=1
60 atom=edi.InsertAtom(res,
"A%d" % index,
geom.Vec3(4.0, -2.0, 0.0)+
62 atom.radius=0.25
63
64 return ent
65
66a=Hammer()
67b=TheWall()
68
69a_go=gfx.Entity("a", gfx.CUSTOM, a)
70b_go=gfx.Entity("b", gfx.CUSTOM, b)
71for a in a.atoms:
72 a.SetFloatProp('clash', 0.0)
73
74scene.Add(a_go)
75scene.Add(b_go)
76
77anim=Anim(a_go, b_go)
78anim.start(20)
79grad=gfx.Gradient()
80grad.SetColorAt(0.0, gfx.Color(0.0, 1.0, 0.0))
81grad.SetColorAt(0.5, gfx.Color(1.0, 0.0, 1.0))
82grad.SetColorAt(1.0, gfx.Color(1.0, 0.0, 0.0))
83b_go.ColorBy('clash', gfx.Color(0,1,0), gfx.Color(1,0,0), 0.0, 10.0, mol.Prop.Level.ATOM)
84scene.CenterOn(b_go)
85print('Demo 7: Illustrating a clash score')
Three dimensional vector class, using Real precision.
Mat3 DLLEXPORT_OST_GEOM AxisRotation(const Vec3 &axis, Real angle)