-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typo in GGA derivatives Higher-level julia interface and test Ignore vim temporaries Make testdata local patch version 0.1.2
- Loading branch information
Showing
9 changed files
with
200 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,8 @@ | |
deps/usr | ||
deps/deps.jl | ||
deps/build.log | ||
|
||
# vim temporaries | ||
*~ | ||
.*.swp | ||
.*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Libxc" | ||
uuid = "66e17ffc-8502-11e9-23b5-c9248d0eb96d" | ||
authors = ["Jason Eu <[email protected]>"] | ||
version = "0.1.0" | ||
version = "0.1.2" | ||
|
||
[compat] | ||
julia = "1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Return the list of available libxc functionals as strings""" | ||
function available_functionals() | ||
n_xc = ccall((:xc_number_of_functionals, libxc), Cint, ()) | ||
max_string_length = ccall((:xc_maximum_name_length, libxc), Cint, ()) | ||
|
||
funcnames = Vector{String}(undef, n_xc) | ||
for i in 1:n_xc | ||
funcnames[i] = "\0"^(max_string_length + 2) | ||
end | ||
ccall((:xc_available_functional_names, libxc), Cvoid, (Ptr{Ptr{UInt8}}, ), funcnames) | ||
[string(split(funcnames[i], "\0")[1]) for i in 1:n_xc] | ||
end | ||
|
||
@enum FunctionalKind begin | ||
functional_exchange = 0 | ||
functional_correlation = 1 | ||
functional_exchange_correlation = 2 | ||
functional_kinetic = 3 | ||
end | ||
|
||
@enum FunctionalFamily begin | ||
family_unknown = -1 | ||
family_lda = 1 | ||
family_gga = 2 | ||
family_mggai = 4 | ||
family_lca = 8 | ||
family_oep = 16 | ||
family_hyb_gga = 32 | ||
family_hyb_mgga = 64 | ||
end | ||
|
||
mutable struct Functional | ||
number::Int | ||
name::String | ||
kind::FunctionalKind | ||
family::FunctionalFamily | ||
n_spin::Int | ||
|
||
# Pointer holding the LibXC representation of this functional | ||
pointer::Ptr{XCFuncType} | ||
end | ||
|
||
|
||
""" | ||
Functional(identifier; n_spin::Integer = 1) | ||
Construct a Functional from a libxc `identifier` and the number | ||
of spins `n_spin` to consider. ` | ||
""" | ||
function Functional(identifier; n_spin::Integer = 1) | ||
if n_spin != 1 && n_spin != 2 | ||
error("n_spin needs to be 1 or 2") | ||
end | ||
|
||
number = ccall((:xc_functional_get_number, libxc), Cint, (Cstring, ), | ||
string(identifier)) | ||
if number == -1 | ||
error("Functional $identifier is not known.") | ||
end | ||
|
||
function pointer_cleanup(ptr::Ptr{XCFuncType}) | ||
if ptr != C_NULL | ||
xc_func_end(ptr) | ||
xc_func_free(ptr) | ||
end | ||
end | ||
|
||
pointer = xc_func_alloc() | ||
ret = xc_func_init(pointer, number, n_spin) | ||
if ret != 0 | ||
error("Something went wrong initialising the functional") | ||
end | ||
|
||
try | ||
funcinfo = xc_func_get_info(pointer) | ||
kind = xc_func_info_get_kind(funcinfo) | ||
family = xc_func_info_get_family(funcinfo) | ||
flags = xc_func_info_get_flags(funcinfo) | ||
# TODO Extract references .... | ||
|
||
# Make functional and attach finalizer for cleaning up the pointer | ||
func = Functional(number, string(identifier), FunctionalKind(kind), | ||
FunctionalFamily(family), n_spin, pointer) | ||
finalizer(cls -> pointer_cleanup(cls.pointer), func) | ||
return func | ||
catch | ||
pointer_cleanup(pointer) | ||
rethrow() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function evaluate_lda!(func::Functional, ρ::Array{Float64}; kwargs...) | ||
@assert func.family == family_lda | ||
n_p = Int(length(ρ) / func.n_spin) | ||
|
||
sizes = Dict(:E => n_p, :Vρ => 2n_p, :V2ρ2 => 3n_p, :V3ρ3 => 4n_p) | ||
if func.n_spin == 1 | ||
for key in keys(sizes) | ||
sizes[key] = n_p | ||
end | ||
end | ||
|
||
dargs = Dict(kwargs) | ||
for key in keys(dargs) | ||
if !haskey(sizes, key) | ||
throw(ArgumentError("Unknown keyword argument: $(string(key))")) | ||
end | ||
if length(dargs[key]) != sizes[key] | ||
throw(DimensionMismatch("Length of keyword argument $(string(key)) == " * | ||
"$(length(dargs[key])) does not agree with expected " * | ||
"value $(sizes[key])")) | ||
end | ||
end | ||
|
||
ccall((:xc_lda, libxc), Cvoid, (Ptr{XCFuncType}, Cint, Ptr{Float64}, Ptr{Float64}, | ||
Ptr{Float64}, Ptr{Float64}, Ptr{Float64}), | ||
func.pointer, n_p, ρ, get(dargs, :E, C_NULL), | ||
get(dargs, :Vρ, C_NULL), get(dargs, :V2ρ2, C_NULL), get(dargs, :V3ρ3, C_NULL) | ||
) | ||
end | ||
|
||
|
||
function evaluate_gga!(func::Functional, ρ::Array{Float64}, σ::Array{Float64}; kwargs...) | ||
@assert func.family == family_gga | ||
n_p = Int(length(ρ) / func.n_spin) | ||
|
||
n_σ = 3n_p | ||
sizes = Dict(:E => n_p, :Vρ => 2n_p, :Vσ => 3n_p, | ||
:V2ρ2 => 3n_p, :V2ρσ => 6n_p, :V2σ2 => 6n_p, | ||
:V3ρ3 => 4n_p, :V3ρ2σ => 9n_p, :V3ρσ2 => 12n_p, :V3σ3 => 10n_p) | ||
if func.n_spin == 1 | ||
n_σ = n_p | ||
for key in keys(sizes) | ||
sizes[key] = n_p | ||
end | ||
end | ||
|
||
dargs = Dict(kwargs) | ||
for key in keys(dargs) | ||
if !haskey(sizes, key) | ||
throw(ArgumentError("Unknown keyword argument: $(string(key))")) | ||
end | ||
if length(dargs[key]) != sizes[key] | ||
throw(DimensionMismatch("Length of keyword argument $(string(key)) == " * | ||
"$(length(dargs[key])) does not agree with expected " * | ||
"value $(sizes[key])")) | ||
end | ||
end | ||
|
||
ccall((:xc_gga, libxc), Cvoid, (Ptr{XCFuncType}, Cint, Ptr{Float64}, Ptr{Float64}, | ||
Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, | ||
Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, | ||
Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, | ||
Ptr{Float64}), | ||
func.pointer, n_p, ρ, σ, | ||
get(dargs, :E, C_NULL), get(dargs, :Vρ, C_NULL), get(dargs, :Vσ, C_NULL), | ||
get(dargs, :V2ρ2, C_NULL), get(dargs, :V2ρσ, C_NULL), get(dargs, :V2σ2, C_NULL), | ||
get(dargs, :V3ρ3, C_NULL), get(dargs, :V3ρ2σ, C_NULL), get(dargs, :V3ρσ2, C_NULL), | ||
get(dargs, :V3σ3, C_NULL) | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0dfa8f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
0dfa8f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/2072
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:
0dfa8f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New patched version with your changes is available JuliaRegistries/General#2072 (comment) @mfherbst