APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Cannot integrate OSP AbstractCalculation, AbstractSimulation to python jpype post and replies

Return to the Cannot integrate OSP AbstractCalculation, AbstractSimulation to python jpype thread
Login to post to this thread

OSP Display3DFrame and 3D elements work from Python jpype but not AbstractSimulation - March 7, 2015 at 11:21
9 Posts

I am having some difficulties calling OSP Java libraries from Python using jpype. Specifically, I am not able to properly call AbstractSimulation or AbstractCalculation which are the core and butter of java physics simulation.

Could anybody help me?

This simple example, for instance, works for me. But have tried for hours to call AbstractSimulation or AbstractCalculation without success.


# Display3DFrameApp
import jpype

def init_jvm(jvmpath=None):
    # indicate the java JAR file
    jar_path = 'osp.jar'
    if jpype.isJVMStarted():

    jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % jar_path)

jpype.java.lang.System.out.println("Hello World")

# get the whole OSP package
javaPackage = jpype.JPackage("org").opensourcephysics
Display3DFrame = javaPackage.frames.Display3DFrame
ElementCircle = javaPackage.display3d.simple3d.ElementCircle

import math
import numpy as np
frame = Display3DFrame("Random Circles")

for i in range(0,25):
    ball = ElementCircle()
    ball.setSizeXYZ(0.1, 0.1, 0.1)
    ball.setXYZ(-1.0+2*np.random.random(), -1.0+2*np.random.random(), -1.0+2*np.random.random())

OSP Projects:
Open Source Physics - EJS Modeling
Physlet Physics
Physlet Quantum Physics
STP Book