Skip to content

Commit

Permalink
Replace SciPy qhull dependence by DirectQhull.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Dec 1, 2022
1 parent 7be63e0 commit f3b1dd6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ jobs:
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
env:
PYTHON: "" # the python version picked by PyCall.jl sometimes isn't Conda.jl's version, but the system's: this ensures that it is Conda.jl's
- uses: julia-actions/julia-runtest@v1
env:
PYTHON: ""
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand All @@ -54,8 +50,6 @@ jobs:
with:
version: '1'
- uses: julia-actions/julia-buildpkg@v1
env:
PYTHON: ""
- run: |
julia --project=docs -e '
using Pkg
Expand All @@ -67,10 +61,7 @@ jobs:
using Documenter: doctest
using Brillouin
doctest(Brillouin)'
env:
PYTHON: ""
- run: julia --project=docs docs/make.jl
env:
PYTHON: ""
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name = "Brillouin"
uuid = "23470ee3-d0df-4052-8b1a-8cbd6363e7f0"
authors = ["Thomas Christensen <tchr@mit.edu> and contributors"]
version = "0.5.10"
version = "0.5.11"

[deps]
Bravais = "ada6cbde-b013-4edf-aa94-f6abe8bd6e6b"
DirectQhull = "c3f9d41a-afcb-471e-bc58-0b8d83bd86f4"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Bravais = "0.1.8"
DirectQhull = "0.2"
DocStringExtensions = "0.8, 0.9"
PyCall = "1.92"
Reexport = "1.0, 1.1, 1.2"
Requires = "1.1"
StaticArrays = "1.2"
Expand Down
36 changes: 11 additions & 25 deletions src/WignerSeitz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using LinearAlgebra:
norm,
dot,
×
using PyCall
import DirectQhull
using DocStringExtensions

import Base: getindex, size, IndexStyle, show, summary
Expand All @@ -32,20 +32,6 @@ import Base: getindex, size, IndexStyle, show, summary

export Cell, wignerseitz, faces, vertices, reduce_to_wignerseitz

# ---------------------------------------------------------------------------------------- #

const PySpatial = PyNULL()
function __init__()
# bringing in SciPy's Spatial module (for `Voronoi` and `ConvexHull`)
if PyCall.conda
copy!(PySpatial, pyimport_conda("scipy.spatial", "scipy"))
else
copy!(PySpatial, pyimport_e("scipy.spatial"))
end
ispynull(PySpatial) && @warn("scipy python package not found. " *
"WignerSeitz.wignerseitz is nonfunctional.")
end

# ---------------------------------------------------------------------------------------- #
# STRUCTURES

Expand Down Expand Up @@ -130,15 +116,15 @@ function wignerseitz(basis::AVec{<:SVector{D,<:Real}};
iszero(I) && (idx_cntr = idx)
end

ispynull(PySpatial) && error("You need to install scipy for wignerseitz to work.")
vor = PySpatial.Voronoi(lattice) # voronoi tesselation of lattice
vor = DirectQhull.Voronoi(reduce(hcat, lattice)) # voronoi tesselation of lattice

# grab all the vertices of the central voronoi region enclosing origo
verts_cntr = # NB: offsets by 1 due to Julia 1-based vs. Python 0-based indexing
[vor.vertices[idx+1,:] for idx in vor.regions[vor.point_region[idx_cntr]+1]]

# [NB: offsets by 1 due to Julia 1-based vs. C++ 0-based indexing;
# see https://github.com/JuhaHeiskala/DirectQhull.jl/issues/7]
verts_cntr = vor.vertices[:, vor.regions[vor.point_region[idx_cntr]+1] .+ 1]

# get convex hull of central vertices
hull = PySpatial.ConvexHull(verts_cntr)
hull = DirectQhull.ConvexHull(verts_cntr)
c = convert_to_cell(hull, basis)
c = reorient_normals!(c)

Expand All @@ -165,11 +151,11 @@ end
# UTILITIES & SUBFUNCTIONS

function convert_to_cell(hull, basis::AVec{<:SVector{D,<:Real}}) where D
vs′ = hull.points # vertices
fs′ = hull.simplices .+ 1 # faces
vs′ = hull.points # vertices
fs′ = hull.simplices # faces [NB: 1-based, cf. https://github.com/JuhaHeiskala/DirectQhull.jl/issues/7#issuecomment-1334411873]

vs = SVector{D, Float64}.(eachrow(vs′))
fs = Vector{Int}.(eachrow(fs′))
vs = SVector{D, Float64}.(eachcol(vs′))
fs = Vector{Int}.(eachcol(fs′))
return Cell(vs, fs, SVector{D, SVector{D, Float64}}(basis), Ref(CARTESIAN))
end

Expand Down

0 comments on commit f3b1dd6

Please sign in to comment.