From 476becedd95184d528654f63d2eb72f417c6fc26 Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Thu, 25 Mar 2010 13:47:57 +0000
Subject: [PATCH] added repulsive force to harmony example

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1888 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 examples/harmony/glwin.py   |  2 +-
 examples/harmony/harmony.py | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/examples/harmony/glwin.py b/examples/harmony/glwin.py
index 5558c70d7..8e0549cec 100644
--- a/examples/harmony/glwin.py
+++ b/examples/harmony/glwin.py
@@ -17,7 +17,7 @@ class DokkGLCanvas(QGLWidget):
     self.atom=mol.AtomHandle()
   def initializeGL(self):
     gfx.Scene().InitGL()
-    self.startTimer(20)
+    self.startTimer(10)
   def paintGL(self):
     gfx.Scene().RenderGL()
   def paintEvent(self, event):
diff --git a/examples/harmony/harmony.py b/examples/harmony/harmony.py
index df4914e75..0e1ddc0d4 100644
--- a/examples/harmony/harmony.py
+++ b/examples/harmony/harmony.py
@@ -31,18 +31,29 @@ class World:
         break
   def Update(self):
     last_atom=mol.AtomHandle()
-    for index, atom in enumerate(self.atom_string.atoms):
+    atoms=self.atom_string.atoms
+    for index, atom in enumerate(atoms):
       if last_atom.IsValid():
         diff=last_atom.pos-atom.pos
         length=geom.Length(diff)
         diff/=length
-        force=(1.0-length)**2*diff
+        force=(length-1)**2*diff*100
+        if length<1.0:
+          force*=-1
         self.forces[index-1]-=force
         self.forces[index]+=force
       last_atom=atom
+    for i in range(len(atoms)):
+      for j in range(i+2, len(atoms)):
+        diff=atoms[i].pos-atoms[j].pos
+        length=geom.Length(diff)
+        diff/=length
+        force=((1.0/length)**12-(1.0/length)**6)*diff
+        self.forces[i]+=force
+        self.forces[j]-=force
     edi=self.atom_string.RequestXCSEditor(mol.EditMode.BUFFERED_EDIT)
     for force, atom in zip(self.forces, self.atom_string.atoms):
-      edi.SetAtomPos(atom, atom.pos+force*0.01)
+      edi.SetAtomPos(atom, atom.pos+force*0.004)
     self.go.Rebuild()
     for i in range(len(self.last_positions)):
       self.forces[i]=geom.Vec3()
-- 
GitLab