From 3593096735e5fffab9a3a17325871cd024ed3050 Mon Sep 17 00:00:00 2001 From: Shane Parker Date: Sat, 13 Jan 2024 21:35:43 -0500 Subject: [PATCH] some optimizations --- .github/workflows/blender-plugin.yml | 2 +- molecular_blender/isosurfaces.py | 11 ++++------- molecular_blender/marching_cube_cy.pyx | 4 ++-- molecular_blender/orbitals_cy.pyx | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/blender-plugin.yml b/.github/workflows/blender-plugin.yml index 3c26b84..5959069 100644 --- a/.github/workflows/blender-plugin.yml +++ b/.github/workflows/blender-plugin.yml @@ -41,7 +41,7 @@ jobs: run: | mkdir -p ${HOME}/.config/blender/${BLENDER_MAJOR_VERSION}/scripts/addons python setup.py build - python setup.py install --mode copy + python setup.py install - name: Test Blender run: | bash run_test.sh -b blender-${BLENDER_VERSION}-linux-x64/blender diff --git a/molecular_blender/isosurfaces.py b/molecular_blender/isosurfaces.py index 838a882..4b9925b 100644 --- a/molecular_blender/isosurfaces.py +++ b/molecular_blender/isosurfaces.py @@ -21,8 +21,8 @@ def transform_triangles(triangles, origin, axes): if not triangles: return triangles coords = np.array(triangles, dtype=DTYPE) - out = np.dot(coords, axes) - return [out[i, :] + origin for i in range(coords.shape[0])] + out = np.dot(coords, axes) + origin + return [ out[i,:] for i in range(out.shape[0]) ] def cube_isosurface(data, origin, axes, isovalues, name="cube", wm=None): @@ -113,16 +113,13 @@ def isosurface_simple(p0, p1, nvoxels, isovalues, box_func, axes, name, wm=None) yvals, ystep = np.linspace(p0[1], p1[1], num=nvoxels[1]+1, retstep=True, endpoint=True, dtype=DTYPE) zvals, zstep = np.linspace(p0[2], p1[2], num=nvoxels[2]+1, retstep=True, endpoint=True, dtype=DTYPE) - scaled_axes = np.array(axes, dtype=DTYPE) - scaled_axes[:,0] *= xstep - scaled_axes[:,1] *= ystep - scaled_axes[:,2] *= zstep + scaled_axes = np.array(axes, dtype=DTYPE) * np.array([xstep, ystep, zstep], dtype=DTYPE) box_values = box_func(xvals, yvals, zvals) tri_list = marching_cube_box(box_values, isovalues) + origin = np.array(p0, dtype=DTYPE) * bohr2ang for iiso in range(len(isovalues)): - origin = np.array(p0, dtype=DTYPE) * bohr2ang triangle_sets[iiso]["triangles"] = transform_triangles( tri_list[iiso], origin, scaled_axes) diff --git a/molecular_blender/marching_cube_cy.pyx b/molecular_blender/marching_cube_cy.pyx index 2adcea8..31408a3 100644 --- a/molecular_blender/marching_cube_cy.pyx +++ b/molecular_blender/marching_cube_cy.pyx @@ -331,7 +331,7 @@ ctypedef vector[triangle_vec] iso_triangles @cython.nonecheck(CYDEBUG) cdef void polygonise(triangle_vec* tri_list, const DTYPE_t* cornervalues, const DTYPE_t* cornerpos, - float isolevel) nogil: + float isolevel) noexcept nogil: global edgetable, tritable cdef point[12] vertlist @@ -379,7 +379,7 @@ cdef void polygonise(triangle_vec* tri_list, const DTYPE_t* cornervalues, @cython.wraparound(CYDEBUG) @cython.initializedcheck(CYDEBUG) @cython.nonecheck(CYDEBUG) -cdef void vertex_interp(point* vert_out, float isolevel, const DTYPE_t* p1, const DTYPE_t* p2, const float v1, const float v2) nogil: +cdef void vertex_interp(point* vert_out, float isolevel, const DTYPE_t* p1, const DTYPE_t* p2, const float v1, const float v2) noexcept nogil: cdef float zero = 1e-8 if (fabs(isolevel-v1) < zero): vert_out.x = p1[0] diff --git a/molecular_blender/orbitals_cy.pyx b/molecular_blender/orbitals_cy.pyx index 1829d30..faf40d9 100644 --- a/molecular_blender/orbitals_cy.pyx +++ b/molecular_blender/orbitals_cy.pyx @@ -430,7 +430,7 @@ cdef void add_box_values(CShell* shell, int nz, DTYPE_t* zz, DTYPE_t* coeff, DTYPE_t* target, - float logmxcoeff) nogil: + float logmxcoeff) noexcept nogil: cdef float X = shell.X cdef float Y = shell.Y cdef float Z = shell.Z