From ba39f64b65ed844aa704025e9f0b759d291b569e Mon Sep 17 00:00:00 2001 From: meganrm Date: Mon, 29 Jan 2024 12:32:26 -0800 Subject: [PATCH 1/2] remove pandas3d --- cellpack/autopack/Compartment.py | 380 +------------- cellpack/autopack/Environment.py | 370 +------------- cellpack/autopack/IOutils.py | 5 - cellpack/autopack/ingredient/Ingredient.py | 410 +-------------- cellpack/autopack/ingredient/grow.py | 482 +----------------- .../autopack/ingredient/multi_cylinder.py | 29 -- cellpack/autopack/ingredient/multi_sphere.py | 15 - cellpack/autopack/ingredient/single_cube.py | 17 - .../autopack/ingredient/single_cylinder.py | 29 -- cellpack/autopack/ingredient/single_sphere.py | 27 - cellpack/autopack/ingredient/utils.py | 30 -- cellpack/autopack/loaders/config_loader.py | 3 - .../tests/recipes/v2/test_recipe_loader.json | 2 +- cellpack/tests/test_config.py | 2 +- docs/RECIPE_SCHEMA.md | 8 +- examples/recipes/v2/example.json | 2 +- setup.py | 2 +- 17 files changed, 28 insertions(+), 1785 deletions(-) diff --git a/cellpack/autopack/Compartment.py b/cellpack/autopack/Compartment.py index 6d93c80f7..5a1147634 100644 --- a/cellpack/autopack/Compartment.py +++ b/cellpack/autopack/Compartment.py @@ -82,14 +82,6 @@ vdiff, ) -try: - import panda3d - from panda3d.core import Mat3, Mat4, Point3, TransformState, BitMask32 - from panda3d.bullet import BulletCapsuleShape, BulletRigidBodyNode -except Exception as e: - panda3d = None - print("Failed to get Panda ", e) - helper = autopack.helper AFDIR = autopack.__path__[0] @@ -280,25 +272,6 @@ def store_packed_object(self, env): ) env.packed_objects.add(packed_object) - def addShapeRB(self, env): - # in case our shape is a regular primitive - if self.stype == "capsule": - shape = BulletCapsuleShape(self.radius, self.height, self.axis) - else: - shape = self.addMeshRB() - inodenp = env.worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - inodenp.node().addShape( - shape, TransformState.makePos(Point3(0, 0, 0)) - ) # rotation ? - - inodenp.setCollideMask(BitMask32.allOn()) - inodenp.node().setAngularDamping(1.0) - inodenp.node().setLinearDamping(1.0) - env.world.attachRigidBody(inodenp.node()) - inodenp = inodenp.node() - return inodenp - def setGeomFaces(self, tris, face): # have to add vertices one by one since they are not in order if len(face) == 2: @@ -307,132 +280,10 @@ def setGeomFaces(self, tris, face): tris.addVertex(i) tris.closePrimitive() - # #form = GeomVertexFormat.getV3() - # form = GeomVertexArrayFormat.getV3() - # vdata = GeomVertexData("vertices", form, Geom.UHDynamic)#UHStatic) - # - # vdatastring = npdata.tostring() - # vdata = GeomVertexArrayData ("vertices", form, Geom.UHStatic) - # vdata.modifyArray(0).modifyHandle().setData(vdatastring) - # - # pts = GeomPoints(Geom.UHStatic) - # geomFaceNumpyData = numpy.array(range(count),dtype=numpy.uint32) - # #add some data to face-array - # pts.setIndexType(GeomEnums.NTUint32) - # faceDataString = geomFaceNumpyData.tostring() - # geomFacesDataArray = pts.modifyVertices() - # geomFacesDataArray.modifyHandle().setData(faceDataString) - # pts.setVertices(geomFacesDataArray) - # - - def addMeshRB(self): - from panda3d.core import GeomEnums - from panda3d.core import ( - GeomVertexFormat, - GeomVertexData, - Geom, - GeomTriangles, - ) - from panda3d.bullet import ( - BulletTriangleMesh, - BulletTriangleMeshShape, - ) - - # step 1) create GeomVertexData and add vertex information - - # can do it from numpy array directly...should be faster - format = GeomVertexFormat.getV3() - vdata = GeomVertexData("vertices", format, Geom.UHStatic) - vdatastring = self.vertices.tostring() - vdata.modifyArray(0).modifyHandle().setData(vdatastring) - - # vertexWriter=GeomVertexWriter(vdata, "vertex") - # [vertexWriter.addData3f(v[0],v[1],v[2]) for v in self.vertices] - - # step 2) make primitives and assign vertices to them - tris = GeomTriangles(Geom.UHStatic) - geomFaceNumpyData = numpy.array(self.faces, dtype=numpy.uint32) - # add some data to face-array - tris.setIndexType(GeomEnums.NTUint32) - faceDataString = geomFaceNumpyData.tostring() - geomFacesDataArray = tris.modifyVertices() - geomFacesDataArray.modifyHandle().setData(faceDataString) - tris.setVertices(geomFacesDataArray) - - # [self.setGeomFaces(tris,face) for face in self.faces] - - # step 3) make a Geom object to hold the primitives - geom = Geom(vdata) - geom.addPrimitive(tris) - # step 4) create the bullet mesh and node - # if ingr.convex_hull: - # shape = BulletConvexHullShape() - # shape.add_geom(geom) - # else : - mesh = BulletTriangleMesh() - mesh.addGeom(geom) - shape = BulletTriangleMeshShape(mesh, dynamic=False) # BulletConvexHullShape - self.log.info("shape ok %r", shape) - # inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode(ingr.name)) - # inodenp.node().setMass(1.0) - # inodenp.node().addShape(shape)#,TransformState.makePos(Point3(0, 0, 0)))#, pMat)#TransformState.makePos(Point3(jtrans[0],jtrans[1],jtrans[2])))#rotation ? - return shape - def create_rbnode(self): # Sphere - if panda3d is None: - return None - trans = [0, 0, 0] - rotMat = mat = numpy.identity(4) - mat = mat.transpose().reshape((16,)) - mat3x3 = Mat3( - mat[0], - mat[1], - mat[2], - mat[4], - mat[5], - mat[6], - mat[8], - mat[9], - mat[10], - ) - pmat = Mat4( - mat[0], - mat[1], - mat[2], - mat[3], - mat[4], - mat[5], - mat[6], - mat[7], - mat[8], - mat[9], - mat[10], - mat[11], - trans[0], - trans[1], - trans[2], - mat[15], - ) - pMat = TransformState.makeMat(pmat) - if self.parent.panda_solver == "ode": - pMat = mat3x3 - inodenp = self.addMeshRB(pMat, trans, rotMat) - if self.panda_solver == "bullet": - inodenp.setCollideMask(BitMask32.allOn()) - inodenp.node().setAngularDamping(1.0) - inodenp.node().setLinearDamping(1.0) - inodenp.setMat(pmat) - self.parent.world.attachRigidBody(inodenp.node()) - inodenp = inodenp.node() - elif self.panda_solver == "ode": - inodenp.setCollideBits(BitMask32(0x00000002)) - inodenp.setCategoryBits(BitMask32(0x00000001)) - # boxGeom.setBody(boxBody) - self.parent.rb_panda.append(inodenp) - # self.moveRBnode(inodenp.node(), trans, rotMat) - return inodenp - + return None + def get_rb_model(self): if self.rbnode is None: self.rbnode = self.create_rbnode() @@ -3239,233 +3090,6 @@ def create_voxelization( return image_data - def getSurfaceInnerPointsPandaRay( - self, boundingBox, spacing, display=False, useFix=False - ): - """ - Only compute the inner point. No grid. - This is independant from the packing. Help build ingredient sphere tree and representation - """ - # should use the ray and see if it gave better reslt - from autopack.pandautil import PandaUtil - - pud = PandaUtil() - from autopack.Environment import Grid - - self.grid = grid = Grid() - grid.boundingBox = boundingBox - grid.gridSpacing = spacing # = self.smallestProteinSize*1.1547 # 2/sqrt(3)???? - helper.progressBar(label="BuildGRid") - grid.gridVolume, grid.nbGridPoints = grid.computeGridNumberOfPoint( - boundingBox, spacing - ) - grid.create3DPointLookup() - nbPoints = grid.gridVolume - grid.compartment_ids = [0] * nbPoints - xl, yl, zl = boundingBox[0] - xr, yr, zr = boundingBox[1] - # distToClosestSurf is set to self.diag initially - # grid.diag = diag = vlen( vdiff((xr,yr,zr), (xl,yl,zl) ) ) - # grid.distToClosestSurf = [diag]*nbPoints - # distances = grid.distToClosestSurf - # idarray = grid.compartment_ids - # diag = grid.diag - grdPos = grid.masterGridPositions - insidePoints = [] - surfacePoints = self.vertices - pud.addMeshRB(self.vertices, self.faces) - # then sed ray from pointgrid to closest surface oint and see if collide ? - # distance ? dot ? angle - grid.diag = diag = vlen(vdiff((xr, yr, zr), (xl, yl, zl))) - grid.distToClosestSurf = [diag] * nbPoints - idarray = grid.compartment_ids - diag = grid.diag - - self.ogsurfacePoints = self.vertices[:] - self.ogsurfacePointsNormals = helper.FixNormals( - self.vertices, self.faces, self.vnormals, fn=self.fnormals - ) - surfacePoints = srfPts = self.ogsurfacePoints - self.OGsrfPtsBht = bht = spatial.cKDTree(tuple(srfPts), leafsize=10) - - res = numpy.zeros(len(srfPts), "f") - - number = self.number - ogNormals = numpy.array(self.ogsurfacePointsNormals) - insidePoints = [] - - # find closest off grid surface point for each grid point - # FIXME sould be diag of compartment BB inside fillBB - grdPos = grid.masterGridPositions - returnNullIfFail = 0 - closest = bht.closestPointsArray( - tuple(grdPos), diag, returnNullIfFail - ) # diag is cutoff ? meanin max distance ? - - self.closestId = closest - helper.resetProgressBar() - # helper.progressBar(label="checking point %d" % point) - # what abou intractive display ? - if display: - sph = helper.Sphere("gPts", res=10, radius=20.0)[0] - sph2 = helper.Sphere("sPts", res=10, radius=20.0)[0] - sph3 = helper.Sphere("hitPos", res=10, radius=20.0)[0] - helper.oneCylinder("normal", [0.0, 0.0, 0.0], [1.0, 1.0, 1.0], radius=20.0) - helper.oneCylinder("V", [0.0, 0.0, 0.0], [1.0, 1.0, 1.0], radius=20.0) - helper.changeObjColorMat(sph2, (0.0, 0.0, 1.0)) - for ptInd in range(len(grdPos)): # len(grdPos)): - inside = False - sptInd = closest[ptInd] - v = -numpy.array(grdPos[ptInd]) + numpy.array(srfPts[closest[ptInd]]) - an = nx, ny, nz = numpy.array(ogNormals[sptInd]) - # start = Point3(grdPos[i][0],grdPos[i][1],grdPos[i][2]) - if display: - helper.setTranslation(sph, grdPos[ptInd]) - helper.setTranslation(sph2, srfPts[closest[ptInd]]) - helper.update() - # end = Point3(srfPts[closest[i]][0]*diag,srfPts[closest[i]][1]*diag,srfPts[closest[i]][2]*diag) - # raycats and see what it it on the mesh - # or result = world.sweepTestClosest(shape, tsFrom, tsTo, penetration) - res = pud.rayCast( - grdPos[ptInd], - (numpy.array(grdPos[ptInd]) + v) * 99999, - closest=True, - ) # world.rayTestAll(start, end) - # can we get the number of hit? - if res.hasHit(): - h = res - # hit=res.getHits() - # for h in hit : - # if len(hit): - # h = hit[0] - n = numpy.array(h.getHitNormal()) - a = helper.angle_between_vectors(v, n) - dot = numpy.dot(v, n) - dot2 = numpy.dot(an, v) - a2 = helper.angle_between_vectors(-v, an) - print( - "hit with ", - a, - math.degrees(a), - a2, - math.degrees(a2), - dot, - dot2, - ) - if display: - helper.setTranslation(sph3, numpy.array(h.getHitPos())) - helper.updateOneCylinder( - "normal", - srfPts[sptInd], - numpy.array(srfPts[sptInd]) + (n * spacing * 10.0), - radius=10.0, - ) - helper.updateOneCylinder( - "V", - grdPos[ptInd], - numpy.array(grdPos[ptInd]) + (v), - radius=10.0, - ) - helper.update() - # if dot < 0 :#and dot < (-1.*10E-5): # inside ? - if ( - dot < 0.0 and dot2 < 0.0 - ): # a2 < (math.pi/2.)+0.1 and a > (math.pi/2.):# and a < (math.pi/2.) :#and a > (math.pi+(math.pi/2.)): - print("INSIDE", dot, a, math.degrees(a)) - inside = True - if inside: - idarray[ptInd] = -number - insidePoints.append(grdPos[ptInd]) - if display: - helper.changeObjColorMat(sph, (1.0, 0.0, 0.0)) - helper.update() - res = helper.drawQuestion( - title="Inside?", - question="%0.2f %0.2f %0.2f %0.2f %s" - % (dot, dot2, a, math.degrees(a), str(inside)), - ) - if not res: - return insidePoints, surfacePoints - p = (ptInd / float(len(grdPos))) * 100.0 - helper.progressBar( - progress=int(p), - label=str(ptInd) + "/" + str(len(grdPos)) + " inside " + str(inside), - ) - - return insidePoints, surfacePoints - - def getSurfaceInnerPointsPanda( - self, boundingBox, spacing, display=False, useFix=False - ): - """ - Only compute the inner point. No grid. - This is independant from the packing. Help build ingredient sphere tree and representation - """ - # work for small object - from autopack.pandautil import PandaUtil - - pud = PandaUtil() - from autopack.Environment import Grid - - self.grid = grid = Grid() - grid.boundingBox = boundingBox - grid.gridSpacing = spacing # = self.smallestProteinSize*1.1547 # 2/sqrt(3)???? - t = time() - helper.progressBar(label="BuildGRid") - grid.gridVolume, grid.nbGridPoints = grid.computeGridNumberOfPoint( - boundingBox, spacing - ) - grid.create3DPointLookup() - nbPoints = grid.gridVolume - grid.compartment_ids = [0] * nbPoints - xl, yl, zl = boundingBox[0] - xr, yr, zr = boundingBox[1] - # distToClosestSurf is set to self.diag initially - # grid.diag = diag = vlen( vdiff((xr,yr,zr), (xl,yl,zl) ) ) - # grid.distToClosestSurf = [diag]*nbPoints - # distances = grid.distToClosestSurf - # idarray = grid.compartment_ids - # diag = grid.diag - grdPos = grid.masterGridPositions - insidePoints = [] - surfacePoints = self.vertices - NPT = len(grdPos) - rads = [spacing] * NPT - helper.progressBar(label="BuildWorldAndNode") - t = time() - - def addSphere(r, pos, i): - node = pud.addSingleSphereRB(r, name=str(i)) - node.setPos(pos[0], pos[1], pos[2]) - helper.progressBar( - progress=int((i / float(NPT)) * 100.0), - label=str(i) + "/" + str(NPT), - ) - return node - - [addSphere(rads[i], grdPos[i], i) for i in range(NPT)] - # node = pud.addMultiSphereRB(rads,grdPos) - helper.progressBar( - label="OK SPHERE %0.2f" % (time() - t) - ) # ("time sphere ",time()-t) - t = time() - # add the mesh - meshnode = pud.addMeshRB(self.vertices, self.faces) - helper.progressBar(label="OK MESH %0.2f" % (time() - t)) # - # computeCollisionTest - t = time() - iPtList = [] - meshcontacts = pud.world.contactTest(meshnode.node()) - meshcontacts.getNumContacts() - for ct in meshcontacts.getContacts(): - i = eval(ct.getNode0().getName()) - if i not in iPtList: - insidePoints.append(grdPos[i]) - iPtList.append(i) - print("N", len(insidePoints), NPT) - print("time contact", time() - t) - return insidePoints, surfacePoints - def printFillInfo(self): """print some info about the compartment and its recipe""" print("compartment %d" % self.number) diff --git a/cellpack/autopack/Environment.py b/cellpack/autopack/Environment.py index a61cb22bb..889d86fed 100644 --- a/cellpack/autopack/Environment.py +++ b/cellpack/autopack/Environment.py @@ -57,13 +57,6 @@ from json import encoder import logging from collections import OrderedDict - -# PANDA3D Physics engine ODE and Bullet -import panda3d - -from panda3d.core import Mat3, Mat4, Vec3, BitMask32, NodePath -from panda3d.bullet import BulletRigidBodyNode - import cellpack.autopack as autopack from cellpack.autopack.MeshStore import MeshStore import cellpack.autopack.ingredient as ingredient @@ -172,7 +165,6 @@ def __init__(self, config=None, recipe=None): self.timeUpDistLoopTotal = 0 self.exteriorRecipe = None self.hgrid = [] - self.world = None # panda world for collision self.octree = None # ongoing octree test, no need if openvdb wrapped to python self.grid = None # Grid() # the main grid self.encapsulatingGrid = ( @@ -258,7 +250,6 @@ def __init__(self, config=None, recipe=None): self.packed_objects = PackedObjects() # should be part of an independent module - self.panda_solver = "bullet" # or bullet # could be a problem here for pp # can't pickle this dictionary self.rb_func_dic = {} @@ -1313,19 +1304,7 @@ def onePrevIngredient(self, i, mingrs, distance, nbFreePoints, marray): dpad=dpad, centT=centT, ) - # update free points - if len(insidePoints) and self.place_method.find("panda") != -1: - print(ingr.name, " is inside") - self.checkPtIndIngr(ingr, insidePoints, i, ptInd, marray) - # ingr.inside_current_grid = True - else: - # not in the grid - print(ingr.name, " is outside") - # rbnode = ingr.rbnode[ptInd] - # ingr.rbnode.pop(ptInd) - marray[i][3] = -ptInd # uniq Id ? - # ingr.rbnode[-1] = rbnode - # doesnt seem to work properly... + marray[i][3] = -ptInd # uniq Id ? nbFreePoints = BaseGrid.updateDistances( self, insidePoints, @@ -1348,25 +1327,6 @@ def onePrevIngredient(self, i, mingrs, distance, nbFreePoints, marray): del ingr.allIngrPts # Graham here on 5/16/12 are these two lines safe? return nbFreePoints - def checkPtIndIngr(self, ingr, insidePoints, i, ptInd, marray): - """ - We need to check if the point indice is correct in the case of panda packing. - as the pt indice in the result array have a different meaning. - """ - # change key for rbnode too - rbnode = None - if ptInd in ingr.rbnode: - rbnode = ingr.rbnode[ptInd] - ingr.rbnode.pop(ptInd) - elif -ptInd in ingr.rbnode: - rbnode = ingr.rbnode[-ptInd] - ingr.rbnode.pop(-ptInd) - else: - print("ptInd " + str(ptInd) + " not in ingr.rbnode") - if i < len(marray): - marray[i][3] = insidePoints.keys()[0] - ingr.rbnode[insidePoints.keys()[0]] = rbnode - def getSortedActiveIngredients(self, allIngredients): """ Sort the active ingredient according their pirority and radius. @@ -1489,13 +1449,6 @@ def reset(self): self.resetIngrRecip(rs) ri = orga.innerRecipe self.resetIngrRecip(ri) - if self.world is not None: - # need to clear all node - # nodes = self.rb_panda[:] - # for node in nodes: - # self.delRB(node) - self.static = [] - self.moving = None if self.octree is not None: del self.octree self.octree = None @@ -2000,9 +1953,6 @@ def pack_grid( PlacedMols = 0 vThreshStart = 0.0 # Added back by Graham on July 5, 2012 from Sept 25, 2011 thesis version - # if bullet build the organel rbnode - if self.place_method == "pandaBullet": - self.setupPanda() # ============================================================================== # #the big loop @@ -2689,8 +2639,6 @@ def finishWithWater(self, free_points=None, nbFreePoints=None): # ============================================================================== # AFter this point, features development around physics engine and algo # octree - # panda bullet - # panda ode # ============================================================================== def setupOctree( @@ -2701,325 +2649,27 @@ def setupOctree( self.grid.getRadius(), helper=helper ) # Octree((0,0,0),self.grid.getRadius()) #0,0,0 or center of grid? - def setupPanda(self): - try: - import panda3d - except Exception: - return - from panda3d.core import loadPrcFileData - - if self.grid is not None: - loadPrcFileData( - "", "bullet-sap-extents " + str(self.grid.diag) - ) # grid may not be setup - if self.world is None: - if panda3d is None: - return - loadPrcFileData( - "", - """ - load-display p3tinydisplay # to force CPU only rendering (to make it available as an option if everything else fail, use aux-display p3tinydisplay) - audio-library-name null # Prevent ALSA errors - show-frame-rate-meter 0 - sync-video 0 - bullet-max-objects 10240 - bullet-broadphase-algorithm sap - bullet-sap-extents 10000.0 - textures-power-2 up - textures-auto-power-2 #t - """, - ) - # loadPrcFileData("", "window-type none" ) - # Make sure we don't need a graphics engine - # (Will also prevent X errors / Display errors when starting on linux without X server) - # loadPrcFileData("", "audio-library-name null" ) # Prevent ALSA errors - # loadPrcFileData('', 'bullet-enable-contact-events true') - # loadPrcFileData('', 'bullet-max-objects 10240')#10240 - # loadPrcFileData('', 'bullet-broadphase-algorithm sap')#aabb - # loadPrcFileData('', 'bullet-sap-extents 10000.0')# - if autopack.helper is not None and autopack.helper.nogui: - loadPrcFileData("", "window-type offscreen") - else: - loadPrcFileData("", "window-type None") - - from direct.showbase.ShowBase import ShowBase - - base = ShowBase() - base.disableMouse() - self.base = base - from panda3d.core import Vec3 - - if self.panda_solver == "bullet": - from panda3d.bullet import BulletWorld - - # global variable from panda3d - self.worldNP = render.attachNewNode("World") # noqa: F821 - self.world = BulletWorld() - self.BitMask32 = BitMask32 - elif self.panda_solver == "ode": - from panda3d.ode import OdeWorld, OdeHashSpace - - self.world = OdeWorld() - # or hashspace ? - self.ode_space = ( - OdeHashSpace() - ) # OdeQuadTreeSpace(center,extends,depth) - self.ode_space.set_levels(-2, 6) - self.ode_space.setAutoCollideWorld(self.world) - - self.world.setGravity(Vec3(0, 0, 0)) - self.static = [] - self.moving = None - self.rb_panda = [] - base.destroy() - - for compartment in self.compartments: - if compartment.rbnode is None: - compartment.rbnode = compartment.addShapeRB( - self - ) # addMeshRBOrganelle(o) - - def add_rb_node(self, ingr, trans, mat): - if ingr.type == "Mesh": - return ingr.add_rb_mesh(self.worldNP) - elif self.panda_solver == "ode" and ingr.type == "Sphere": - mat3x3 = Mat3( - mat[0], mat[1], mat[2], mat[4], mat[5], mat[6], mat[8], mat[9], mat[10] - ) - return ingr.add_rb_node_ode(self.world, trans, mat3x3) - return ingr.add_rb_node(self.worldNP) - def delRB(self, node): - if panda3d is None: - return - if self.panda_solver == "bullet": - self.world.removeRigidBody(node) - np = NodePath(node) - if np is not None: - np.removeNode() - elif self.panda_solver == "ode": - node.destroy() - - if node in self.rb_panda: - self.rb_panda.pop(self.rb_panda.index(node)) - if node in self.static: - self.static.pop(self.static.index(node)) - if node == self.moving: - self.moving = None + return None def setGeomFaces(self, tris, face): - if panda3d is None: - return - # have to add vertices one by one since they are not in order - if len(face) == 2: - face = numpy.array([face[0], face[1], face[1], face[1]], dtype="int") - for i in face: - tris.addVertex(i) - tris.closePrimitive() + return None def addMeshRBOrganelle(self, o): - if panda3d is None: - return - helper = autopack.helper - if not autopack.helper.nogui: - geom = helper.getObject(o.gname) - if geom is None: - o.gname = "%s_Mesh" % o.name - geom = helper.getObject(o.gname) - faces, vertices, vnormals = helper.DecomposeMesh( - geom, edit=False, copy=False, tri=True, transform=True - ) - else: - faces = o.faces - vertices = o.vertices - inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode(o.name)) - inodenp.node().setMass(1.0) - - from panda3d.core import ( - GeomVertexFormat, - GeomVertexWriter, - GeomVertexData, - Geom, - GeomTriangles, - ) - from panda3d.bullet import ( - BulletTriangleMesh, - BulletTriangleMeshShape, - ) - - # step 1) create GeomVertexData and add vertex information - format = GeomVertexFormat.getV3() - vdata = GeomVertexData("vertices", format, Geom.UHStatic) - vertexWriter = GeomVertexWriter(vdata, "vertex") - [vertexWriter.addData3f(v[0], v[1], v[2]) for v in vertices] - - # step 2) make primitives and assign vertices to them - tris = GeomTriangles(Geom.UHStatic) - [self.setGeomFaces(tris, face) for face in faces] - - # step 3) make a Geom object to hold the primitives - geom = Geom(vdata) - geom.addPrimitive(tris) - # step 4) create the bullet mesh and node - mesh = BulletTriangleMesh() - mesh.addGeom(geom) - shape = BulletTriangleMeshShape(mesh, dynamic=False) # BulletConvexHullShape - # or - # shape = BulletConvexHullShape() - # shape.add_geom(geom) - # inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode(ingr.name)) - # inodenp.node().setMass(1.0) - inodenp.node().addShape( - shape - ) # ,TransformState.makePos(Point3(0, 0, 0)))#, pMat) - # TransformState.makePos(Point3(jtrans[0],jtrans[1],jtrans[2])))#rotation ? - - if self.panda_solver == "bullet": - inodenp.setCollideMask(BitMask32.allOn()) - inodenp.node().setAngularDamping(1.0) - inodenp.node().setLinearDamping(1.0) - # inodenp.setMat(pmat) - self.world.attachRigidBody(inodenp.node()) - inodenp = inodenp.node() - return inodenp + return None def addRB(self, ingr, trans, rotMat, rtype="single_sphere", static=False): - # Sphere - if panda3d is None: - return None - mat = rotMat.copy() - # mat[:3, 3] = trans - # mat = mat.transpose() - mat = mat.transpose().reshape((16,)) - - pmat = Mat4( - mat[0], - mat[1], - mat[2], - mat[3], - mat[4], - mat[5], - mat[6], - mat[7], - mat[8], - mat[9], - mat[10], - mat[11], - trans[0], - trans[1], - trans[2], - mat[15], - ) - inodenp = None - inodenp = self.add_rb_node(ingr, trans, mat) - if self.panda_solver == "bullet": - inodenp.setCollideMask(BitMask32.allOn()) - inodenp.node().setAngularDamping(1.0) - inodenp.node().setLinearDamping(1.0) - inodenp.setMat(pmat) - self.world.attachRigidBody(inodenp.node()) - inodenp = inodenp.node() - elif self.panda_solver == "ode": - inodenp.setCollideBits(BitMask32(0x00000002)) - inodenp.setCategoryBits(BitMask32(0x00000001)) - # boxGeom.setBody(boxBody) - self.rb_panda.append(inodenp) - # self.moveRBnode(inodenp.node(), trans, rotMat) - return inodenp - + return None + def moveRBnode(self, node, trans, rotMat): - if panda3d is None: - return - rotation_matrix = rotMat.copy() - # mat[:3, 3] = trans - # mat = mat.transpose() - rotation_matrix = rotation_matrix.transpose().reshape((16,)) - if True in numpy.isnan(rotation_matrix).flatten(): - print("problem Matrix", node) - return - if self.panda_solver == "bullet": - pMat = Mat4( - rotation_matrix[0], - rotation_matrix[1], - rotation_matrix[2], - rotation_matrix[3], - rotation_matrix[4], - rotation_matrix[5], - rotation_matrix[6], - rotation_matrix[7], - rotation_matrix[8], - rotation_matrix[9], - rotation_matrix[10], - rotation_matrix[11], - trans[0], - trans[1], - trans[2], - rotation_matrix[15], - ) - nodenp = NodePath(node) - nodenp.setMat(pMat) - elif self.panda_solver == "ode": - mat3x3 = Mat3( - rotation_matrix[0], - rotation_matrix[1], - rotation_matrix[2], - rotation_matrix[4], - rotation_matrix[5], - rotation_matrix[6], - rotation_matrix[8], - rotation_matrix[9], - rotation_matrix[10], - ) - body = node.get_body() - body.setPosition(Vec3(trans[0], trans[1], trans[2])) - body.setRotation(mat3x3) + return None def getRotTransRB(self, node): - if panda3d is None: - return - nodenp = NodePath(node) - m = nodenp.getMat() - M = numpy.array(m) - rRot = numpy.identity(4) - rRot[:3, :3] = M[:3, :3] - rTrans = M[3, :3] - return rTrans, rRot + return None def runBullet(self, ingr, simulationTimes, runTimeDisplay): - if panda3d is None: - return - done = False - t1 = time() - simulationTimes = 5.0 - while not done: - # should do it after a jitter run - # for i in xrange(10): - dt = globalClock.getDt() # noqa: F821, global variable from panda3d - self.world.doPhysics( - dt, 100, 1.0 / 500.0 - ) # world.doPhysics(dt, 10, 1.0/180.0)100, 1./500.#2, 1.0/120.0 - # check number of contact betwee currrent and rest ? - r = [ - (self.world.contactTestPair(self.moving, n).getNumContacts() > 0) - for n in self.static - ] - done = not (True in r) - if runTimeDisplay: - # move self.moving and update - nodenp = NodePath(self.moving) - ma = nodenp.getMat() - self.afviewer.vi.setObjectMatrix( - ingr.moving_geom, numpy.array(ma), transpose=False - ) # transpose ? - self.afviewer.vi.update() - if (time() - t1) > simulationTimes: - done = True - break - - # ============================================================================== - # Export -> another file ? - # ============================================================================== - + return None + def exportToBD_BOX(self, res_filename=None, output=None, bd_type="flex"): # , call the BD_BOX exporter, plugin ? better if result store somewhere. # only sphere + boudary ? diff --git a/cellpack/autopack/IOutils.py b/cellpack/autopack/IOutils.py index aa3285817..fe51fa5c0 100644 --- a/cellpack/autopack/IOutils.py +++ b/cellpack/autopack/IOutils.py @@ -1250,11 +1250,6 @@ def setupFromJsonDic( # restore env.molecules if any resuylt was loaded env.loopThroughIngr(env.restore_molecules_array) - -# if env.place_method.find("panda") != -1 : -# env.setupPanda() - - def load_MixedasJson(env, resultfilename=None, transpose=True): # from upy.hostHelper import Helper as helper if resultfilename is None: diff --git a/cellpack/autopack/ingredient/Ingredient.py b/cellpack/autopack/ingredient/Ingredient.py index e37d420f8..fa817dd8a 100644 --- a/cellpack/autopack/ingredient/Ingredient.py +++ b/cellpack/autopack/ingredient/Ingredient.py @@ -44,7 +44,6 @@ # TODO: Describe Ingredient class here at high level from scipy import spatial -from panda3d.bullet import BulletRigidBodyNode import numpy import logging import collada @@ -487,59 +486,6 @@ def DecomposeMesh(self, poly, edit=True, copy=False, tri=True, transform=True): ) return faces, vertices, vnormals - def addRBsegment(self, pt1, pt2): - # ovewrite by grow ingredient - pass - - def add_rb_mesh(self, worldNP): - inodenp = worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - if self.mesh is None: - return - self.getData() - if not len(self.vertices): - return inodenp - from panda3d.core import ( - GeomVertexFormat, - GeomVertexWriter, - GeomVertexData, - Geom, - GeomTriangles, - ) - from panda3d.bullet import ( - BulletTriangleMesh, - BulletTriangleMeshShape, - ) - - # step 1) create GeomVertexData and add vertex information - format = GeomVertexFormat.getV3() - vdata = GeomVertexData("vertices", format, Geom.UHStatic) - vertexWriter = GeomVertexWriter(vdata, "vertex") - [vertexWriter.addData3f(v[0], v[1], v[2]) for v in self.vertices] - - # step 2) make primitives and assign vertices to them - tris = GeomTriangles(Geom.UHStatic) - [self.setGeomFaces(tris, face) for face in self.faces] - - # step 3) make a Geom object to hold the primitives - geom = Geom(vdata) - geom.addPrimitive(tris) - # step 4) create the bullet mesh and node - # if ingr.convex_hull: - # shape = BulletConvexHullShape() - # shape.add_geom(geom) - # else : - mesh = BulletTriangleMesh() - mesh.addGeom(geom) - shape = BulletTriangleMeshShape(mesh, dynamic=False) # BulletConvexHullShape - print("shape ok", shape) - # inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode(ingr.name)) - # inodenp.node().setMass(1.0) - inodenp.node().addShape( - shape - ) # ,TransformState.makePos(Point3(0, 0, 0)))#, pMat)#TransformState.makePos(Point3(jtrans[0],jtrans[1],jtrans[2])))#rotation ? - return inodenp - def getEncapsulatingRadius(self, mesh=None): if self.vertices is None or not len(self.vertices): if self.mesh: @@ -1592,7 +1538,6 @@ def attempt_to_pack_at_grid_location( is_fiber = self.type == "Grow" or self.type == "Actine" collision_possible = True if collision_possible or is_fiber: - # grow doesnt use panda.......but could use all the geom produce by the grow as rb if is_fiber: success, jtrans, rotMatj, insidePoints, newDistPoints = self.grow_place( env, @@ -1635,47 +1580,7 @@ def attempt_to_pack_at_grid_location( grid_point_distances, dpad, ) - elif self.place_method == "pandaBullet": - ( - success, - jtrans, - rotMatj, - insidePoints, - newDistPoints, - ) = self.pandaBullet_place( - env, - ptInd, - grid_point_distances, - dpad, - env.afviewer, - compartment, - gridPointsCoords, - rotation_matrix, - target_grid_point_position, - current_visual_instance, - usePP=usePP, - ) - elif ( - self.place_method == "pandaBulletRelax" - or self.place_method == "pandaBulletSpring" - ): - ( - success, - jtrans, - rotMatj, - insidePoints, - newDistPoints, - ) = self.pandaBullet_relax( - env, - ptInd, - compartment, - target_grid_point_position, - rotation_matrix, - grid_point_distances, - dpad, - current_visual_instance, - dpad, - ) + else: self.log.error("Can't pack using this method %s", self.place_method) self.reject() @@ -2162,36 +2067,6 @@ def lookForNeighbours(self, env, trans, rotMat, organelle): self.log.info("no partner found") return targetPoint, rotMat, found - def pandaBullet_collision(self, pos, rot, rbnode, getnodes=False): - collision = False - liste_nodes = [] - if len(self.env.rTrans) != 0: - closesbody_indice = self.env.get_closest_ingredients( - pos, - cutoff=self.env.largestProteinSize + self.encapsulating_radius * 2.0, - ) # vself.radii[0][0]*2.0 - if len(closesbody_indice["indices"]) != 0: - self.log.info("get RB %d", len(closesbody_indice["indices"])) - if rbnode is None: - rbnode = self.get_rb_model() - self.env.moveRBnode(rbnode, pos, rot) - self.log.info("get RB for %s", self.name) - liste_nodes = self.get_rbNodes(closesbody_indice, pos, getInfo=True) - self.log.info("test collision against %d", len(liste_nodes)) - for node in liste_nodes: - self.log.info("collision test with %r", node) - self.env.moveRBnode(node[0], node[1], node[2]) # Pb here ? - collision = ( - self.env.world.contactTestPair(rbnode, node[0]).getNumContacts() - > 0 - ) - if collision: - break - if getnodes: - return collision, liste_nodes - else: - return collision - def get_compartment(self, env): if self.compartment_id == 0: return env @@ -2229,153 +2104,6 @@ def handle_real_time_visualization(self, helper, ptInd, target_point, rot_mat): return instance_id - def pandaBullet_place( - self, - env, - ptInd, - distance, - dpad, - afvi, - compartment, - gridPointsCoords, - rot_matrix, - target_point, - moving, - usePP=False, - ): - """ - drop the ingredient on grid point ptInd - """ - env.setupPanda() - is_realtime = moving is not None - # we need to change here in case tilling, the pos,rot ade deduced fromte tilling. - if self.packing_mode[-4:] == "tile": - if self.tilling is None: - self.setTilling(compartment) - if self.counter != 0: - # pick the next Hexa pos/rot. - t, collision_results = self.tilling.getNextHexaPosRot() - if len(t): - rot_matrix = collision_results - trans = t - target_point = trans - if is_realtime: - self.update_display_rt(moving, target_point, rot_matrix) - else: - return False, None, None, {}, {} # ,targetPoint, rotMat - else: - self.tilling.init_seed(env.seed_used) - - packing_location = None - level = self.collisionLevel - - for jitter_attempt in range(self.jitter_attempts): - env.totnbJitter += 1 - - ( - packing_location, - packing_rotation, - ) = self.get_new_jitter_location_and_rotation( - env, - target_point, - rot_matrix, - ) - - if is_realtime: - self.update_display_rt(moving, target_point, rot_matrix) - - if not self.point_is_available(packing_location): - # jittered into wrong compartment, - # go to next jitter - continue - - collision_results = [] - rbnode = self.get_rb_model() - - points_to_check = self.get_all_positions_to_check( - packing_location - ) # includes periodic points, if appropriate - for pt in points_to_check: - env.callFunction( - env.moveRBnode, - ( - rbnode, - pt, - packing_rotation, - ), - ) - collision = self.pandaBullet_collision(pt, packing_rotation, rbnode) - collision_results.extend([collision]) - if True in collision_results: - # break out of point check loop, not this jitter loop - break - t = time() - # checked packing location and periodic positions - if True in collision_results: - # found a collision, should check next jitter - continue - - # need to check compartment too - self.log.info("no additional collisions, checking compartment") - if self.compareCompartment: - collisionComp = self.compareCompartmentPrimitive( - level, - packing_location, - packing_rotation, - gridPointsCoords, - distance, - ) - collision_results.extend([collisionComp]) - if self.collides_with_compartment(env, packing_location, packing_rotation): - continue - - # got all the way through the checks with no collision - if True not in collision_results: - inside_points = {} - new_dist_points = {} - t3 = time() - self.env.static.append(rbnode) - self.env.moving = None - - for pt in points_to_check: - - self.pack_at_grid_pt_location( - env, - pt, - packing_rotation, - dpad, - distance, - inside_points, - new_dist_points, - ptInd, - ) - self.log.info("compute distance loop %d", time() - t3) - - if self.packing_mode[-4:] == "tile": - self.tilling.dropTile( - self.tilling.idc, - self.tilling.edge_id, - packing_location, - packing_rotation, - ) - - success = True - return ( - success, - packing_location, - packing_rotation, - inside_points, - new_dist_points, - ) - - # never found a place to pack - success = False - if self.packing_mode[-4:] == "tile": - if self.tilling.start.nvisit[self.tilling.edge_id] >= 2: - self.tilling.start.free_pos[self.tilling.edge_id] = 0 - - return success, None, None, {}, {} - def spheres_SST_place( self, env, @@ -2390,7 +2118,6 @@ def spheres_SST_place( """ drop the ingredient on grid point ptInd """ - env.setupPanda() is_realtime = moving is not None targetPoint = target_grid_point_position @@ -2500,138 +2227,3 @@ def spheres_SST_place( success = False return success, packing_location, packing_rotation, insidePoints, newDistPoints - - def pandaBullet_relax( - self, - env, - ptInd, - compartment, - target_grid_point_position, - rotation_matrix, - distance, - dpad, - moving, - drop=True, - ): - """ - drop the ingredient on grid point ptInd - """ - env.setupPanda() - afvi = env.afviewer - simulationTimes = env.simulationTimes - runTimeDisplay = env.runTimeDisplay - is_realtime = moving is not None - gridPointsCoords = env.grid.masterGridPositions - insidePoints = {} - newDistPoints = {} - jtrans, rotMatj = self.oneJitter( - env, target_grid_point_position, rotation_matrix - ) - # here should go the simulation - # 1- we build the ingredient if not already and place the ingredient at jtrans, rotMatj - targetPoint = jtrans - if is_realtime: - if hasattr(self, "mesh_3d"): - # create an instance of mesh3d and place it - name = self.name + str(ptInd) - if self.mesh_3d is None: - self.moving_geom = afvi.vi.Sphere( - name, radius=self.radii[0][0], parent=afvi.movingMesh - )[0] - afvi.vi.setTranslation(self.moving_geom, pos=jtrans) - else: - self.moving_geom = afvi.vi.newInstance( - name, - self.mesh_3d, - matrice=rotMatj, - location=jtrans, - parent=afvi.movingMesh, - ) - # 2- get the neighboring object from ptInd - if env.ingrLookForNeighbours: - near_by_ingredients, placed_partners = self.get_partners( - env, jtrans, rotation_matrix, compartment, afvi - ) - for i, elem in enumerate(near_by_ingredients): - ing = elem[2] - t = elem[0] - r = elem[1] - ind = elem[3] - if hasattr(ing, "mesh_3d"): - # create an instance of mesh3d and place it - name = ing.name + str(ind) - if ing.mesh_3d is None: - ipoly = afvi.vi.Sphere( - name, radius=self.radii[0][0], parent=afvi.staticMesh - )[0] - afvi.vi.setTranslation(ipoly, pos=t) - else: - ipoly = afvi.vi.newInstance( - name, - ing.mesh_3d, - matrice=r, - location=t, - parent=afvi.staticMesh, - ) - elif ing.type == "Grow": - name = ing.name + str(ind) - ipoly = afvi.vi.newInstance( - name, afvi.orgaToMasterGeom[ing], parent=afvi.staticMesh - ) - - if placed_partners: - self.log.info(f"len listePartner: {len(placed_partners)}") - if not self.force_random: - targetPoint = self.pick_partner_grid_index( - near_by_ingredients, - placed_partners, - current_packing_position=jtrans, - ) - if targetPoint is None: - targetPoint = jtrans - else: - targetPoint = jtrans - # should be panda util - # add the rigid body - self.env.moving = rbnode = self.env.callFunction( - self.env.addRB, - ( - self, - jtrans, - rotation_matrix, - ), - {"rtype": self.type}, - ) - self.env.callFunction( - self.env.moveRBnode, - ( - rbnode, - jtrans, - rotMatj, - ), - ) - # run he simulation for simulationTimes - env.callFunction( - self.env.runBullet, - ( - self, - simulationTimes, - runTimeDisplay, - ), - ) - # cb=self.getTransfo) - rTrans, rRot = self.env.getRotTransRB(rbnode) - # 5- we get the resuling transofrmation matrix and decompose ->rTrans rRot - # use - # r=[ (self.env.world.contactTestPair(rbnode, n).getNumContacts() > 0 ) for n in self.env.static] - self.env.static.append(rbnode) - - jtrans = rTrans[:] - rotMatj = rRot[:] - insidePoints, newDistPoints = self.get_new_distance_values( - jtrans, rotMatj, gridPointsCoords, distance, dpad - ) - self.rRot.append(rotMatj) - self.tTrans.append(jtrans) - success = True - return success, jtrans, rotMatj, insidePoints, newDistPoints diff --git a/cellpack/autopack/ingredient/grow.py b/cellpack/autopack/ingredient/grow.py index e993220cc..07c6fabdb 100644 --- a/cellpack/autopack/ingredient/grow.py +++ b/cellpack/autopack/ingredient/grow.py @@ -4,8 +4,6 @@ from scipy import spatial from numpy import matrix from math import pi, sqrt -from panda3d.core import Point3, TransformState -from panda3d.bullet import BulletSphereShape, BulletRigidBodyNode from random import uniform, gauss, random import math from cellpack.autopack.ingredient.Ingredient import Ingredient @@ -816,7 +814,6 @@ def walkSphere( # histoVol.grid.masterGridPositions, # distance, # histoVol) - # use panda ? collision, _, _ = self.checkCylCollisions( [numpy.array(pt2).flatten()], [newPt], @@ -867,433 +864,6 @@ def getInterpolatedSphere(self, pt1, pt2): r.append(self.min_radius) return [r, p] - def addRBsegment(self, pt1, pt2, nodeid=""): - # build a rigid body of multisphere along pt1topt2 - r, p = self.getInterpolatedSphere(pt1, pt2) - print("pos len", len(p), " ", len(r)) - inodenp = self.add_rb_multi_sphere() - print("node build ", inodenp) - inodenp.setCollideMask(self.env.BitMask32.allOn()) - inodenp.node().setAngularDamping(1.0) - inodenp.node().setLinearDamping(1.0) - print("attach node to world") - # inodenp.setMat(pmat) - self.env.world.attachRigidBody(inodenp.node()) - print("node attached to world") - inodenp = inodenp.node() - print("add msphere ", inodenp) - self.env.rb_panda.append(inodenp) - return inodenp - - def walkSpherePanda( - self, pt1, pt2, distance, histoVol, marge=90.0, checkcollision=True, usePP=False - ): - """use a random point on a sphere of radius uLength, and useCylinder collision on the grid""" - v, d = self.vi.measure_distance(pt1, pt2, vec=True) - found = False - attempted = 0 - pt = [0.0, 0.0, 0.0] - safetycutoff = self.rejection_threshold - if self.constraintMarge: - safetycutoff = self.rejection_threshold - if self.runTimeDisplay: - name = "walking" + self.name - sp = self.vi.getObject(name) - if sp is None: - sp = self.vi.Sphere(name, radius=2.0)[0] - # sp.SetAbsPos(self.vi.FromVec(startingPoint)) - self.vi.update() - liste_nodes = [] - cutoff = self.env.largestProteinSize + self.uLength - closesbody_indice = self.env.get_closest_ingredients( - pt2, self.env, cutoff=cutoff - ) - liste_nodes = self.get_rbNodes( - closesbody_indice, pt2, prevpoint=pt1, getInfo=True - ) - alternate, ia = self.pick_alternate() - print("pick alternate", alternate, ia, self.prev_alt) - if self.prev_was_alternate: - alternate = None - p_alternate = None # self.partners[alternate]#self.env.getIngrFromNameInRecipe(alternate,self.recipe ) - # if p_alternate.getProperties("bend"): - nextPoint = None # p_alternate.getProperties("pt2") - marge_in = None # p_alternate.getProperties("marge_in") - dihedral = None # p_alternate.getProperties("diehdral")#for next point - length = None # p_alternate.getProperties("length")#for next point - # prepare halton if needed - newPt = None - newPts = [] - if self.prev_alt is not None: # and self.prev_alt_pt is not None: - p_alternate = self.partners[self.prev_alt] - dihedral = p_alternate.dihedral - nextPoint = p_alternate.get_point(1) - marge_out = p_alternate.margin_out # marge out ? - if dihedral is not None: - self.mask_sphere_points( - v, - pt1, - marge_out, - liste_nodes, - 0, - pv=self.prev_vec, - marge_diedral=dihedral, - v3=self.prev_v3, - ) - alternate = None - if self.prev_alt is not None: - point_is_not_available = True - elif alternate and not self.prev_was_alternate: - # next point shouldnt be an alternate - p_alternate = self.partners[ - alternate - ] # self.env.getIngrFromNameInRecipe(alternate,self.recipe ) - entrypoint = p_alternate.get_point(0) - nextPoint = p_alternate.get_point(1) - marge_in = p_alternate.margin_in - dihedral = p_alternate.dihedral # for next point - length = p_alternate.length # for next point - if entrypoint is not None: - self.mask_sphere_points( - v, - pt2, - marge_in, - liste_nodes, - 0, - pv=None, - marge_diedral=None, - alternate=alternate, - ) - elif marge_in is not None: - self.mask_sphere_points( - v, pt2, marge_in, liste_nodes, 0, pv=None, marge_diedral=None - ) - else: - self.mask_sphere_points(v, pt2, marge + 2.0, liste_nodes, 0) - self.prev_was_alternate = True - elif self.useHalton: - self.mask_sphere_points(v, pt2, marge + 2.0, liste_nodes, 0) - if histoVol.runTimeDisplay: - points_mask = numpy.nonzero(self.sphere_points_mask)[0] - verts = self.sphere_points[points_mask] * self.uLength + pt2 - name = "Hcloud" + self.name - pc = self.vi.getObject(name) - if pc is None: - pc = self.vi.PointCloudObject(name, vertices=verts)[0] - else: - self.vi.updateMesh(pc, vertices=verts) - self.vi.update() - - while not found: - print("attempt ", attempted, marge) - # main loop thattryto found the next point (similar to jitter) - if attempted >= safetycutoff: - print("break too much attempt ", attempted, safetycutoff) - return None, False # numpy.array(pt2).flatten()+numpy.array(pt),False - # pt = numpy.array(self.vi.randpoint_onsphere(self.uLength,biased=(uniform(0.,1.0)*marge)/360.0))*numpy.array([1,1,0]) - point_is_not_available = True - newPt = None - if self.prev_alt is not None: - if dihedral is not None: - newPt = self.pickAlternateHalton(pt1, pt2, None) - elif nextPoint is not None: - newPt = self.prev_alt_pt - if newPt is None: - print( - "no sphere points available with prev_alt", dihedral, nextPoint - ) - self.prev_alt = None - return None, False - attempted += 1 # ? - continue - elif alternate: - if marge_in is not None: - newPt = self.pickAlternateHalton(pt1, pt2, length) - if newPt is None: - print("no sphere points available with marge_in") - return None, False - jtrans, rotMatj = self.get_alternate_position( - alternate, ia, v, pt2, newPt - ) - elif nextPoint is not None: - newPts, jtrans, rotMatj = self.place_alternate( - alternate, ia, v, pt1, pt2 - ) - # found = self.check_alternate_collision(pt2,newPts,jtrans,rotMatj) - newPt = newPts[0] - # attempted should be to safetycutoff - attempted = safetycutoff - if newPt is None: - print("no points available place_alternate") - return None, False - else: # no constraint we just place alternate relatively to the given halton new points - newPt = self.pickAlternateHalton(pt1, pt2, length) - if newPt is None: - print("no sphere points available with marge_in") - return None, False - jtrans, rotMatj = self.get_alternate_position( - alternate, ia, v, pt2, newPt - ) - elif self.useHalton: - newPt = self.pickHalton(pt1, pt2) - if newPt is None: - print("no sphere points available with marge_in") - return None, False - else: - newPt = self.pickRandomSphere(pt1, pt2, marge, v) - if histoVol.runTimeDisplay: - self.vi.setTranslation(sp, newPt) - self.vi.update() - print("picked point", newPt) - if newPt is None: - print("no points available") - return None, False - r = [False] - point_is_not_available = not self.point_is_available(newPt) - print( - "point is available", - point_is_not_available, - self.constraintMarge, - marge, - attempted, - self.rejection_threshold, - ) - if point_is_not_available: - if not self.constraintMarge: - if marge >= 175: - attempted += 1 - continue - if ( - attempted % (self.rejection_threshold / 3) == 0 - and not alternate - ): - marge += 1 - attempted = 0 - # need to recompute the mask - if not alternate and self.useHalton and self.prev_alt is None: - self.sphere_points_mask = numpy.ones( - self.sphere_points_nb, "i" - ) - self.mask_sphere_points(v, pt2, marge + 2.0, liste_nodes, 0) - if histoVol.runTimeDisplay: - points_mask = numpy.nonzero(self.sphere_points_mask)[0] - verts = ( - self.sphere_points[points_mask] * self.uLength + pt2 - ) - name = "Hcloud" + self.name - pc = self.vi.getObject(name) - if pc is None: - pc = self.vi.PointCloudObject(name, vertices=verts)[ - 0 - ] - else: - self.vi.updateMesh(pc, vertices=verts) - self.vi.update() - attempted += 1 - continue - if checkcollision: - collision = False - cutoff = histoVol.largestProteinSize + self.uLength - if not alternate: - prev = None - if len(histoVol.rTrans) > 2: - prev = histoVol.rTrans[-1] - - a = numpy.array(newPt) - numpy.array(pt2).flatten() - numpy.array(pt2).flatten() + a - # this s where we use panda - rotMatj = [ - [1.0, 0.0, 0.0, 0.0], - [0.0, 1.0, 0.0, 0.0], - [0.0, 0.0, 1.0, 0.0], - [0.0, 0.0, 0.0, 1.0], - ] - jtrans = [0.0, 0.0, 0.0] - # move it or generate it inplace - # oldpos1=self.positions - # oldpos2=self.positions2 - # self.positions=[[numpy.array(pt2).flatten()],] - # self.positions2=[[newPt],] - # if self.use_rbsphere : - # rbnode = self.addRBsegment(numpy.array(pt2).flatten(),newPt) - # else : - # rbnode = histoVol.callFunction(histoVol.addRB,(self, numpy.array(jtrans), numpy.array(rotMatj),),{"rtype":self.type},)#cylinder - # #histoVol.callFunction(histoVol.moveRBnode,(rbnode, jtrans, rotMatj,)) - # if inside organelle check for collision with it ? - # self.positions=oldpos1 - # self.positions2=oldpos2 - rotMatj, jtrans = self.getJtransRot( - numpy.array(pt2).flatten(), newPt - ) - rbnode = self.get_rb_model() - self.env.callFunction( - self.env.moveRBnode, - ( - rbnode, - jtrans, - rotMatj, - ), - ) - if len(self.env.rTrans) == 0: - r = [False] - else: - prev = None - if len(self.env.rTrans) > 2: - prev = self.env.rTrans[-1] - closesbody_indice = self.env.get_closest_ingredients( - newPt, histoVol, cutoff=cutoff - ) # vself.radii[0][0]*2.0 - if len(closesbody_indice) == 0: - print("No CloseBody") - r = [False] # closesbody_indice[0] == -1 - else: - print("collision get RB ", len(closesbody_indice)) - liste_nodes = self.get_rbNodes( - closesbody_indice, jtrans, prevpoint=prev, getInfo=True - ) - if usePP: - # use self.grab_cb and self.pp_server - # Divide the task or just submit job - n = 0 - self.env.grab_cb.reset() - for i in range(len(liste_nodes) / autopack.ncpus): - for c in range(autopack.ncpus): - self.env.pp_server.submit( - self.env.world.contactTestPair, - (rbnode, liste_nodes[n][0]), - callback=self.env.grab_cb.grab, - ) - n += 1 - self.env.pp_server.wait() - r.extend(self.env.grab_cb.collision[:]) - if True in r: - break - else: - for node in liste_nodes: - self.env.moveRBnode(node[0], node[1], node[2]) - col = ( - self.env.world.contactTestPair( - rbnode, node[0] - ).getNumContacts() - > 0 - ) - print("collision? ", col) - r = [col] - if col: - break - collision = True in r - if not collision: - self.alternate_interval += 1 - if self.alternate_interval >= self.mini_interval: - self.prev_was_alternate = False - self.prev_alt = None - self.prev_vec = None - self.update_data_tree( - numpy.array(pt2).flatten(), rotMatj, pt1=pt2, pt2=newPt - ) # jtrans - # histoVol.callFunction(histoVol.delRB,(rbnode,)) - return newPt, True - - else: - print("alternate collision") - rotMatj1, jtrans1 = self.getJtransRot_r( - numpy.array(pt2).flatten(), newPt - ) - # collision,liste_nodes = self.collision_rapid(jtrans1,rotMatj1,cutoff=cutoff,usePP=usePP,point=newPt) - # the collision shouldnt look for previous cylinder - collision_alternate, liste_nodes = self.partners[ - alternate - ].ingr.pandaBullet_collision(jtrans, rotMatj, None, getnodes=True) - collision = ( - collision_alternate # (collision or collision_alternate) - ) - if not collision: - # what about point in curve and result - # self.update_data_tree(jtrans1,rotMatj1,pt1=pt2,pt2=newPt) - # self.update_data_tree(jtrans1,rotMatj1,pt1=newPt,pt2=newPts[1]) - self.partners[alternate].ingr.update_data_tree(jtrans, rotMatj) - self.compartment.molecules.append( - [ - jtrans, - rotMatj, - self.partners[alternate].ingr, - 0, - self.partners[alternate].ingr.radius, - ] - ) # transpose ? - newv, d1 = self.vi.measure_distance(pt2, newPt, vec=True) - # v,d2 = self.vi.measure_distance(newPt,newPts[1],vec=True) - # self.currentLength += d1 - if dihedral is not None: - self.prev_alt = alternate - self.prev_v3 = self.getV3( - numpy.array(pt2).flatten(), newPt, alternate - ) - self.prev_vec = v - if nextPoint is not None and dihedral is None: - self.prev_alt_pt = newPts[1] - - self.alternate_interval = 0 - return newPt, True - else: - self.prev_alt_pt = None # print (" collide ?",collision) - if collision: # increment the range - if alternate: - attempted = safetycutoff - elif not self.constraintMarge: - if marge >= 180: # pi - attempted += 1 - continue - if ( - attempted % (self.rejection_threshold / 3) == 0 - and not alternate - ): - marge += 1 - attempted = 0 - # need to recompute the mask - if ( - not alternate - and self.useHalton - and self.prev_alt is None - ): - self.sphere_points_mask = numpy.ones( - self.sphere_points_nb, "i" - ) - self.mask_sphere_points( - v, pt2, marge + 2.0, liste_nodes, 0 - ) - if self.runTimeDisplay: - points_mask = numpy.nonzero( - self.sphere_points_mask - )[0] - v = ( - self.sphere_points[points_mask] * self.uLength - + pt2 - ) - name = "Hcloud" + self.name - sp = self.vi.getObject(name) - if sp is None: - pc = self.vi.PointCloudObject( - "bbpoint", vertices=v - )[0] - else: - self.vi.updateMesh(pc, vertices=v) - self.vi.update() - else: - attempted += 1 - else: - attempted += 1 - print("rejected collision") - continue - else: - found = True - # histoVol.callFunction(histoVol.delRB,(rbnode,)) - return numpy.array(pt2).flatten() + numpy.array(pt), True - print("end loop add attempt ", attempted) - attempted += 1 - # histoVol.callFunction(histoVol.delRB,(rbnode,)) - return numpy.array(pt2).flatten() + numpy.array(pt), True - def pickHalton(self, pt1, pt2): p = self.getNextPoint() if p is None: @@ -1401,28 +971,15 @@ def grow( self.vi.update() # pick next point and test collision. if self.walkingMode == "sphere": - if self.place_method == "pandaBullet": - secondPoint, success = self.walkSpherePanda( - previousPoint, - startingPoint, - distance, - histoVol, - marge=self.marge, - checkcollision=True, - usePP=usePP, - ) - if secondPoint is None: - return False, nbFreePoints, free_points - else: - secondPoint, success = self.walkSphere( - previousPoint, - startingPoint, - distance, - histoVol, - dpad, - marge=self.marge, - checkcollision=True, - ) + secondPoint, success = self.walkSphere( + previousPoint, + startingPoint, + distance, + histoVol, + dpad, + marge=self.marge, + checkcollision=True, + ) if self.walkingMode == "lattice" and self.compartment_id > 0: secondPoint, success, mask = self.walkLatticeSurface( startingPoint, @@ -1692,19 +1249,6 @@ def getFirstPoint(self, ptInd, seed=0): self.vi.update() return secondPoint - def add_rb_multi_sphere(self): - inodenp = self.env.worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - level = self.deepest_level - centers = self.positions[level] - radii = self.radii[level] - for radc, posc in zip(radii, centers): - shape = BulletSphereShape(radc) - inodenp.node().addShape( - shape, TransformState.makePos(Point3(posc[0], posc[1], posc[2])) - ) # - return inodenp - def grow_place( self, env, @@ -1767,14 +1311,6 @@ def grow_place( # test for collision # return success, nbFreePoints self.results.append([jtrans, rotMatj]) - if self.place_method == "pandaBullet": - self.env.nb_ingredient += 1 - self.env.rTrans.append(numpy.array(startingPoint).flatten()) - self.env.rRot.append(numpy.array(numpy.identity(4))) # rotMatj - self.env.rIngr.append(self) - self.env.result.append( - [[numpy.array(startingPoint).flatten(), secondPoint], rotMatj, self, 0] - ) # rebuild kdtree if len(self.env.rTrans) > 1: diff --git a/cellpack/autopack/ingredient/multi_cylinder.py b/cellpack/autopack/ingredient/multi_cylinder.py index 55086ad65..cdca69364 100644 --- a/cellpack/autopack/ingredient/multi_cylinder.py +++ b/cellpack/autopack/ingredient/multi_cylinder.py @@ -1,12 +1,8 @@ import numpy import math from math import pi, sqrt -from panda3d.core import Point3, TransformState -from panda3d.bullet import BulletCylinderShape, BulletRigidBodyNode - from .Ingredient import Ingredient import cellpack.autopack as autopack -from .utils import pandaMatrice helper = autopack.helper @@ -241,31 +237,6 @@ def collision_jitter( dpad, ) - def add_rb_node(self, worldNP): - inodenp = worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - centT1 = self.positions[ - 0 - ] # ingr.transformPoints(jtrans, rotMat, ingr.positions[0]) - centT2 = self.positions2[ - 0 - ] # ingr.transformPoints(jtrans, rotMat, ingr.positions2[0]) - for radc, p1, p2 in zip(self.radii[0], centT1, centT2): - length, mat = autopack.helper.getTubePropertiesMatrix(p1, p2) - pMat = pandaMatrice(mat) - # d = numpy.array(p1) - numpy.array(p2) - # s = numpy.sum(d*d) - Point3( - self.principal_vector[0], - self.principal_vector[1], - self.principal_vector[2], - ) - shape = BulletCylinderShape( - radc, length, 1 - ) # math.sqrt(s), 1)# { XUp = 0, YUp = 1, ZUp = 2 } or LVector3f const half_extents - inodenp.node().addShape(shape, TransformState.makeMat(pMat)) # - return inodenp - def checkCylCollisions( self, centers1, diff --git a/cellpack/autopack/ingredient/multi_sphere.py b/cellpack/autopack/ingredient/multi_sphere.py index 7a8a00722..132569341 100644 --- a/cellpack/autopack/ingredient/multi_sphere.py +++ b/cellpack/autopack/ingredient/multi_sphere.py @@ -1,5 +1,3 @@ -from panda3d.core import Point3, TransformState -from panda3d.bullet import BulletSphereShape, BulletRigidBodyNode from math import pi import numpy @@ -248,19 +246,6 @@ def collision_jitter( ) return False, insidePoints, newDistPoints - def add_rb_node(self, worldNP): - inodenp = worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - level = self.deepest_level - centers = self.positions[level] - radii = self.radii[level] - for radc, posc in zip(radii, centers): - shape = BulletSphereShape(radc) - inodenp.node().addShape( - shape, TransformState.makePos(Point3(posc[0], posc[1], posc[2])) - ) # - return inodenp - def get_signed_distance( self, packing_location, diff --git a/cellpack/autopack/ingredient/single_cube.py b/cellpack/autopack/ingredient/single_cube.py index 6dd639df6..2d0f65be9 100644 --- a/cellpack/autopack/ingredient/single_cube.py +++ b/cellpack/autopack/ingredient/single_cube.py @@ -1,8 +1,5 @@ from math import sqrt, pi import numpy -from panda3d.core import Point3, TransformState, Vec3 -from panda3d.bullet import BulletBoxShape, BulletRigidBodyNode - from .Ingredient import Ingredient from .utils import ApplyMatrix import cellpack.autopack as autopack @@ -330,20 +327,6 @@ def get_new_distance_values( newDistPoints[pt] = d return insidePoints, newDistPoints - def add_rb_node(self, worldNP): - halfextents = self.bb[1] - shape = BulletBoxShape( - Vec3(halfextents[0], halfextents[1], halfextents[2]) - ) # halfExtents - inodenp = worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - # inodenp.node().addShape(shape) - inodenp.node().addShape( - shape, TransformState.makePos(Point3(0, 0, 0)) - ) # , pMat)#TransformState.makePos(Point3(jtrans[0],jtrans[1],jtrans[2])))#rotation ? - # spherenp.setPos(-2, 0, 4) - return inodenp - def cube_surface_distance( self, point, diff --git a/cellpack/autopack/ingredient/single_cylinder.py b/cellpack/autopack/ingredient/single_cylinder.py index b1e291f76..01c003a2e 100644 --- a/cellpack/autopack/ingredient/single_cylinder.py +++ b/cellpack/autopack/ingredient/single_cylinder.py @@ -1,14 +1,10 @@ import numpy import math from math import pi, sqrt -from panda3d.core import Point3, TransformState -from panda3d.bullet import BulletCylinderShape, BulletRigidBodyNode - from cellpack.autopack.utils import get_distance from .Ingredient import Ingredient import cellpack.autopack as autopack -from .utils import pandaMatrice helper = autopack.helper @@ -242,31 +238,6 @@ def collision_jitter( dpad, ) - def add_rb_node(self, worldNP): - inodenp = worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - centT1 = self.positions[ - 0 - ] # ingr.transformPoints(jtrans, rotMat, ingr.positions[0]) - centT2 = self.positions2[ - 0 - ] # ingr.transformPoints(jtrans, rotMat, ingr.positions2[0]) - for radc, p1, p2 in zip(self.radii[0], centT1, centT2): - length, mat = autopack.helper.getTubePropertiesMatrix(p1, p2) - pMat = pandaMatrice(mat) - # d = numpy.array(p1) - numpy.array(p2) - # s = numpy.sum(d*d) - Point3( - self.principal_vector[0], - self.principal_vector[1], - self.principal_vector[2], - ) - shape = BulletCylinderShape( - radc, length, 1 - ) # math.sqrt(s), 1)# { XUp = 0, YUp = 1, ZUp = 2 } or LVector3f const half_extents - inodenp.node().addShape(shape, TransformState.makeMat(pMat)) # - return inodenp - def checkCylCollisions( self, centers1, diff --git a/cellpack/autopack/ingredient/single_sphere.py b/cellpack/autopack/ingredient/single_sphere.py index 55bd1f98a..bcc35999c 100644 --- a/cellpack/autopack/ingredient/single_sphere.py +++ b/cellpack/autopack/ingredient/single_sphere.py @@ -1,9 +1,5 @@ import numpy from math import pi -from panda3d.bullet import BulletRigidBodyNode, BulletSphereShape -from panda3d.core import Point3, TransformState, Vec3 -from panda3d.ode import OdeBody, OdeMass, OdeSphereGeom - import cellpack.autopack as autopack from .Ingredient import Ingredient @@ -262,29 +258,6 @@ def get_new_distance_values( newDistPoints[pt] = d return insidePoints, newDistPoints - def add_rb_node(self, worldNP): - shape = BulletSphereShape(self.encapsulating_radius) - inodenp = worldNP.attachNewNode(BulletRigidBodyNode(self.name)) - inodenp.node().setMass(1.0) - # inodenp.node().addShape(shape) - inodenp.node().addShape( - shape, TransformState.makePos(Point3(0, 0, 0)) - ) # rotation ? - # spherenp.setPos(-2, 0, 4) - return inodenp - - def add_rb_node_ode(self, world, jtrans, pMat): - body = OdeBody(world) - M = OdeMass() - M.setSphereTotal(1.0, self.encapsulating_radius) - body.setMass(M) - body.setPosition(Vec3(jtrans[0], jtrans[1], jtrans[2])) - body.setRotation(pMat) - # the geometry for the collision ? - geom = OdeSphereGeom(self.ode_space, self.encapsulating_radius) - geom.setBody(body) - return geom - def initialize_mesh(self, mesh_store): if self.mesh is None: self.mesh = mesh_store.create_sphere( diff --git a/cellpack/autopack/ingredient/utils.py b/cellpack/autopack/ingredient/utils.py index 71d10242d..72e49344f 100644 --- a/cellpack/autopack/ingredient/utils.py +++ b/cellpack/autopack/ingredient/utils.py @@ -1,6 +1,4 @@ import numpy -import panda3d -from panda3d.core import Mat4 from math import sqrt, pi, sin, cos, asin from cellpack.autopack.transformation import angle_between_vectors @@ -202,34 +200,6 @@ def bullet_checkCollision_mp(world, node1, node2): # node2 = histoVol.callFunction(self.env.addRB,(self, jtrans, rotMatj,),{"rtype":self.type},) return world.contactTestPair(node1, node2).getNumContacts() > 0 - -# TODO : move somewhere in a more apropriate place ? -def pandaMatrice(mat): - if panda3d is None: - return - mat = mat.transpose().reshape((16,)) - # print mat,len(mat),mat.shape - pMat = Mat4( - mat[0], - mat[1], - mat[2], - mat[3], - mat[4], - mat[5], - mat[6], - mat[7], - mat[8], - mat[9], - mat[10], - mat[11], - mat[12], - mat[13], - mat[14], - mat[15], - ) - return pMat - - def get_reflected_point(self, new_position, boundingBox=None): # returns the reflection of a point across a bounding box if boundingBox is None: diff --git a/cellpack/autopack/loaders/config_loader.py b/cellpack/autopack/loaders/config_loader.py index 06a676b07..432442065 100644 --- a/cellpack/autopack/loaders/config_loader.py +++ b/cellpack/autopack/loaders/config_loader.py @@ -12,9 +12,6 @@ class Place_Methods(MetaEnum): JITTER = "jitter" SPHERES_SST = "spheresSST" - PANDA_BULLET = "pandaBullet" - PANDA_BULLET_RELAX = "pandaBulletRelax" - class Inner_Grid_Methods(MetaEnum): # Working inner grid methods diff --git a/cellpack/tests/recipes/v2/test_recipe_loader.json b/cellpack/tests/recipes/v2/test_recipe_loader.json index 6b8f9f4b6..a5d59fc04 100644 --- a/cellpack/tests/recipes/v2/test_recipe_loader.json +++ b/cellpack/tests/recipes/v2/test_recipe_loader.json @@ -65,7 +65,7 @@ 1 ], "rejection_threshold": 50, - "place_method": "panda_bullet", + "place_method": "jitter", "cutoff_surface": 42, "rotation_axis": [ 0, diff --git a/cellpack/tests/test_config.py b/cellpack/tests/test_config.py index 744d161fd..7664c6129 100644 --- a/cellpack/tests/test_config.py +++ b/cellpack/tests/test_config.py @@ -28,7 +28,7 @@ def test_wrong_place_method(): except TypeError as error: assert ( format(error) - == "place_method must be one of ['jitter', 'spheresSST', 'pandaBullet', 'pandaBulletRelax'], not error" + == "place_method must be one of ['jitter', 'spheresSST'], not error" ) diff --git a/docs/RECIPE_SCHEMA.md b/docs/RECIPE_SCHEMA.md index ac0eb0e7a..b0e6ca6ae 100644 --- a/docs/RECIPE_SCHEMA.md +++ b/docs/RECIPE_SCHEMA.md @@ -94,7 +94,7 @@ Display packing in realtime (slow) ### place_method -_Optional `enum`_. One of `"jitter"`, `"spheresSST"`, `"pandaBullet"`.. Default: `"jitter"`. +_Optional `enum`_. One of `"jitter"`, `"spheresSST"`.. Default: `"jitter"`. Will be use if place_method isn't in an ingredient setup @@ -102,8 +102,6 @@ Will be use if place_method isn't in an ingredient setup `"spheresSST"` gets the sphereTrees of the potential colliding neighbors, and does an efficient sphereTree-sphereTree collision detection of the sphereTree for the object being packed against the sphereTrees of each neighbor- returns false if a collision is detected -`"pandaBullet"` Python wrapper for Bullet Physics Engine (popular in ~2010 and used by C4D, Maya, Blender, etc) that provides a variety of object-object collision detection, including collision min/max overlap distance, etc. Allows relaxation in its own loop, springs, rejection, meshes, primitives, etc. - ### use_gradient _Optional `boolean`_. Default: `false`. @@ -321,15 +319,13 @@ The amount this ingredient can move in x, y and z. If z is set to 0, will be a 2 _Optional `number`_. Default: `5.0`. ### place_method -_Optional enum. One of `"jitter"`, `"spheresSST"`, `"pandaBullet"`_. Default: `"jitter"`. +_Optional enum. One of `"jitter"`, `"spheresSST"`_. Default: `"jitter"`. `"jitter"` uses a simple algorithm developed by GJ, M-A-A, MS, and LA to test if a single sphere, sphere-tree, or other primative (box and cylinder) are colliding with masked/unallowed points on the grid... I can't recall all of the allowed types, but check the input parameters that it accepts. I believe there is also an option to perform simple collisions directly between primatives, e.g. sphere-sphere, sphere-box, sphere-cylinder, cylinder-box, and spheretree-others `"spheresSST"` gets the sphereTrees of the potential colliding neighbors, and does an efficient sphereTree-sphereTree collision detection of the sphereTree for the object being packed against the sphereTrees of each neighbor- returns false if a collision is detected -`"pandaBullet"` Python wrapper for Bullet Physics Engine (popular in ~2010 and used by C4D, Maya, Blender, etc) that provides a variety of object-object collision detection, including collision min/max overlap distance, etc. Allows relaxation in its own loop, springs, rejection, meshes, primitives, etc. - ### rejection_threshold _Optional `number`_. Default: `30`. diff --git a/examples/recipes/v2/example.json b/examples/recipes/v2/example.json index 5b600f218..aa476cc60 100644 --- a/examples/recipes/v2/example.json +++ b/examples/recipes/v2/example.json @@ -51,7 +51,7 @@ 1 ], "rejection_threshold": 50, - "place_method": "panda_bullet", + "place_method": "spheresSST", "cutoff_surface": 42, "rotation_axis": [0, 0, 1], "available_regions": { diff --git a/setup.py b/setup.py index ec4a11fb5..66fb60c53 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ "scikit-learn>=1.1.3", "seaborn>=0.12.1", "aicsimageio>=4.10.0", + "pandas>=1.2.4", ] dev_requirements = [ @@ -51,7 +52,6 @@ "firebase_admin>=6.0.1", "matplotlib>=3.3.4", "numpy>=1.19.2", - "panda3d==1.10.10", "pmw==2.0.1", "scipy>=1.6.2", "simulariumio>=1.6.3", From 0b7a859ba15147cc95394a9b45b4db4f734207dc Mon Sep 17 00:00:00 2001 From: meganrm Date: Mon, 29 Jan 2024 12:56:02 -0800 Subject: [PATCH 2/2] formatted --- cellpack/autopack/Compartment.py | 2 +- cellpack/autopack/Environment.py | 5 ++--- cellpack/autopack/IOutils.py | 1 + cellpack/autopack/ingredient/Ingredient.py | 2 +- cellpack/autopack/ingredient/utils.py | 1 + cellpack/autopack/loaders/config_loader.py | 1 + 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cellpack/autopack/Compartment.py b/cellpack/autopack/Compartment.py index 5a1147634..f3950f264 100644 --- a/cellpack/autopack/Compartment.py +++ b/cellpack/autopack/Compartment.py @@ -283,7 +283,7 @@ def setGeomFaces(self, tris, face): def create_rbnode(self): # Sphere return None - + def get_rb_model(self): if self.rbnode is None: self.rbnode = self.create_rbnode() diff --git a/cellpack/autopack/Environment.py b/cellpack/autopack/Environment.py index 889d86fed..b43a2f3f4 100644 --- a/cellpack/autopack/Environment.py +++ b/cellpack/autopack/Environment.py @@ -1953,7 +1953,6 @@ def pack_grid( PlacedMols = 0 vThreshStart = 0.0 # Added back by Graham on July 5, 2012 from Sept 25, 2011 thesis version - # ============================================================================== # #the big loop # ============================================================================== @@ -2660,7 +2659,7 @@ def addMeshRBOrganelle(self, o): def addRB(self, ingr, trans, rotMat, rtype="single_sphere", static=False): return None - + def moveRBnode(self, node, trans, rotMat): return None @@ -2669,7 +2668,7 @@ def getRotTransRB(self, node): def runBullet(self, ingr, simulationTimes, runTimeDisplay): return None - + def exportToBD_BOX(self, res_filename=None, output=None, bd_type="flex"): # , call the BD_BOX exporter, plugin ? better if result store somewhere. # only sphere + boudary ? diff --git a/cellpack/autopack/IOutils.py b/cellpack/autopack/IOutils.py index fe51fa5c0..97f9f008e 100644 --- a/cellpack/autopack/IOutils.py +++ b/cellpack/autopack/IOutils.py @@ -1250,6 +1250,7 @@ def setupFromJsonDic( # restore env.molecules if any resuylt was loaded env.loopThroughIngr(env.restore_molecules_array) + def load_MixedasJson(env, resultfilename=None, transpose=True): # from upy.hostHelper import Helper as helper if resultfilename is None: diff --git a/cellpack/autopack/ingredient/Ingredient.py b/cellpack/autopack/ingredient/Ingredient.py index fa817dd8a..1194ea5e2 100644 --- a/cellpack/autopack/ingredient/Ingredient.py +++ b/cellpack/autopack/ingredient/Ingredient.py @@ -1580,7 +1580,7 @@ def attempt_to_pack_at_grid_location( grid_point_distances, dpad, ) - + else: self.log.error("Can't pack using this method %s", self.place_method) self.reject() diff --git a/cellpack/autopack/ingredient/utils.py b/cellpack/autopack/ingredient/utils.py index 72e49344f..0ef42117b 100644 --- a/cellpack/autopack/ingredient/utils.py +++ b/cellpack/autopack/ingredient/utils.py @@ -200,6 +200,7 @@ def bullet_checkCollision_mp(world, node1, node2): # node2 = histoVol.callFunction(self.env.addRB,(self, jtrans, rotMatj,),{"rtype":self.type},) return world.contactTestPair(node1, node2).getNumContacts() > 0 + def get_reflected_point(self, new_position, boundingBox=None): # returns the reflection of a point across a bounding box if boundingBox is None: diff --git a/cellpack/autopack/loaders/config_loader.py b/cellpack/autopack/loaders/config_loader.py index 432442065..4871c9f68 100644 --- a/cellpack/autopack/loaders/config_loader.py +++ b/cellpack/autopack/loaders/config_loader.py @@ -13,6 +13,7 @@ class Place_Methods(MetaEnum): JITTER = "jitter" SPHERES_SST = "spheresSST" + class Inner_Grid_Methods(MetaEnum): # Working inner grid methods RAYTRACE = "raytrace"