Permalink
Browse files

added angle drawing and packaging

  • Loading branch information...
gabrielelanaro committed Jun 23, 2012
1 parent 3e4c0fb commit d5404c3d36549dd073d8087a1498fafb617aec3c
View
@@ -0,0 +1 @@
+include distribute_setup.py
View
@@ -9,4 +9,6 @@ def draw_molecule(molecule):
sphere(atom.coords, 0.4, color)
for bond in molecule.bonds:
- cylinder(bond.start.coords, bond.end.coords, 0.1)
+ cylinder(bond.start.coords, bond.end.coords, 0.1)
+
+
@@ -0,0 +1,4 @@
+import numpy as np
+from numpy.linalg import norm
+def normalized(r):
+ return r / norm(r)
@@ -0,0 +1,3 @@
+import numpy as np
+
+def normalized(norm)
View
@@ -4,6 +4,7 @@
from pyglet.gl import *
import numpy as np
from numpy.linalg import norm
+from mathutils import normalized
import colors
GLfloat_4 = GLfloat * 4
@@ -29,16 +30,54 @@ def cylinder(start, end, radius, color=colors.light_grey):
axis_rot = np.cross(axis_start, axis_end)
_color(*color)
cyl = gluNewQuadric()
-
+
glTranslatef(*start)
glRotatef(angle, *axis_rot)
gluCylinder(cyl, radius, radius, norm(axis_end), 10, 10)
glPopMatrix()
-def _color(r,g,b):
+def arc(r1, r2, r3, color=colors.pink):
+ """Takes three cordinates and draws an arc between the 3
+
+ """
+ x, y, z = r2
+
+ glPushMatrix()
+ glTranslatef(x, y, z)
+ axis_rot = np.cross(normalized(r1-r2),
+ normalized(r3-r2))
+ _rotvec(np.array([0,0,1]), axis_rot)
+ _rotvec(np.array([0,1,0]), normalized(r1-r2))
+ _color(color[0], color[1], color[2], 0.5)
+ arc = gluNewQuadric()
+ gluPartialDisk(arc,
+ 0.0, # Inner radius
+ 1.0, # Outer radius
+ 20, # Slices
+ 20, # Loops
+ 0, # Starting angle
+ - _angle(normalized(r1-r2),
+ normalized(r3-r2))) # disk angle
+ glPopMatrix()
+
+def _rotvec(start, end):
+ """rotate between vector start and end
+
+ """
+ angle =np.degrees(np.arccos(np.dot(end, start)/
+ (norm(end)*norm(start))))
+ axis_rot = np.cross(start, end)
+ glRotatef(angle, *axis_rot)
+
+def _angle(start, end):
+ angle = np.degrees(np.arccos(np.dot(end, start)/
+ (norm(end)*norm(start))))
+ return angle
+
+def _color(r,g,b, a=1.0):
r, g, b = float(r)/255, float(g)/255, float(b)/255
#glMaterialfv(GL_FRONT, GL_AMBIENT,
# GLfloat_4(r, g, b, 1.0))
glMaterialfv(GL_FRONT, GL_DIFFUSE,
- GLfloat_4(r, g, b, 1.0))
+ GLfloat_4(r, g, b, a))
View
@@ -6,9 +6,8 @@
class Viewer(Widget):
def on_draw_scene(self):
-
art.draw_molecule(self.molecule)
-
+
def show(self):
pyglet.app.run()
View
@@ -6,6 +6,7 @@
name = "chemlab",
version = "0.1",
packages = find_packages(),
+ package_data = {'': ['distribute_setup.py']},
install_requires = ["pyglet", "numpy"],
dependency_links = [
"http://pyglet.googlecode.com/files/pyglet-1.1.4.tar.gz"
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit d5404c3

Please sign in to comment.