Skip to content
Snippets Groups Projects
Commit 476beced authored by marco's avatar marco
Browse files

added repulsive force to harmony example

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1888 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 7180656f
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ class DokkGLCanvas(QGLWidget): ...@@ -17,7 +17,7 @@ class DokkGLCanvas(QGLWidget):
self.atom=mol.AtomHandle() self.atom=mol.AtomHandle()
def initializeGL(self): def initializeGL(self):
gfx.Scene().InitGL() gfx.Scene().InitGL()
self.startTimer(20) self.startTimer(10)
def paintGL(self): def paintGL(self):
gfx.Scene().RenderGL() gfx.Scene().RenderGL()
def paintEvent(self, event): def paintEvent(self, event):
......
...@@ -31,18 +31,29 @@ class World: ...@@ -31,18 +31,29 @@ class World:
break break
def Update(self): def Update(self):
last_atom=mol.AtomHandle() 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(): if last_atom.IsValid():
diff=last_atom.pos-atom.pos diff=last_atom.pos-atom.pos
length=geom.Length(diff) length=geom.Length(diff)
diff/=length 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-1]-=force
self.forces[index]+=force self.forces[index]+=force
last_atom=atom 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) edi=self.atom_string.RequestXCSEditor(mol.EditMode.BUFFERED_EDIT)
for force, atom in zip(self.forces, self.atom_string.atoms): 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() self.go.Rebuild()
for i in range(len(self.last_positions)): for i in range(len(self.last_positions)):
self.forces[i]=geom.Vec3() self.forces[i]=geom.Vec3()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment