Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to import from submodules before doing top-level convenience export, also other minor fixes #84

Merged
merged 8 commits into from
Jun 17, 2021
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ChemistryFeaturization"
uuid = "6c925690-434a-421d-aea7-51398c5b007a"
authors = ["Rachel Kurchin <[email protected]>", "Sean Sun"]
version = "0.3.0"
version = "0.3.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
11 changes: 7 additions & 4 deletions src/ChemistryFeaturization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module ChemistryFeaturization

using SimpleWeightedGraphs

encodable_elements(a::Any) = throw(MethodError(encodable_elements, a))
decode(a::Any, encoded_features) = throw(MethodError(decode, a))

include("utils/Utils.jl")
export Utils

Expand All @@ -11,20 +14,20 @@ export AbstractType
include("codecs/codecs.jl")
export Codec

encodable_elements(a::Any) = throw(MethodError(encodable_elements, a))
decode(a::Any, encoded_features) = throw(MethodError(decode, a))

include("features/features.jl")
export FeatureDescriptor
using .FeatureDescriptor: ElementFeatureDescriptor
export ElementFeatureDescriptor

include("atoms/atoms.jl")
export Atoms
using .Atoms: AtomGraph
export AtomGraph

include("featurizations/featurizations.jl")
export Featurization
export GraphNodeFeaturization
using .Featurization: GraphNodeFeaturization, featurize!
export GraphNodeFeaturization, featurize!

export encodable_elements, decode

Expand Down
10 changes: 6 additions & 4 deletions src/atoms/atomgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ function AtomGraph(
num_atoms = size(graph)[1]
@assert length(elements) == num_atoms "Element list length doesn't match graph size!"

# check that features is the right dimensions (# features x # nodes)
expected_feature_length = sum(f.num_bins for f in featurization)
@assert size(features) == (expected_feature_length, num_atoms) "Feature matrix is of wrong dimension! It should be of size (# features, # nodes)"
# TO CONSIDER: add `validate_features` function or something like that for when this constructor is used
# that we can then dispatch on different featurization types. Alternatively, remove this constructor?

# check that features is the right dimensions (# features x # nodes) -> commented out because doesn't work with generic fzn
# expected_feature_length = sum(f.num_bins for f in featurization)
# @assert size(features) == (expected_feature_length, num_atoms) "Feature matrix is of wrong dimension! It should be of size (# features, # nodes)"

# if all these are good, calculate laplacian and build the thing
laplacian = normalized_laplacian(graph)
AtomGraph(graph, elements, laplacian, features, featurization, id)
end


# one without features or featurization initialized yet
function AtomGraph(
graph::SimpleWeightedGraph{A,B},
Expand Down
2 changes: 1 addition & 1 deletion src/featurizations/graphnodefeaturization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
function GraphNodeFeaturization(
feature_names::Vector{String},
lookup_table::Union{DataFrame,Nothing} = nothing;
nbins::Union{Vector{Integer},Integer,Nothing} = nothing,
nbins::Union{Vector{<:Integer},Integer,Nothing} = nothing,
logspaced::Union{Vector{Bool},Bool,Nothing} = nothing,
categorical::Union{Vector{Bool},Bool,Nothing} = nothing,
)
Expand Down
6 changes: 6 additions & 0 deletions test/featurizations/GraphNodeFeaturization_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ using ChemistryFeaturization.Featurization
featurize!(F2, fzn3)
decoded_matrix = decode(fzn3, F2.encoded_features)
decoded_ag = decode(F2)
enc1 = F2.encoded_features
@test all(
map(d -> d[1]["Block"] == d[2]["Block"] == "p", [decoded_matrix, decoded_ag]),
)

rkurchin marked this conversation as resolved.
Show resolved Hide resolved
thazhemadam marked this conversation as resolved.
Show resolved Hide resolved
fzn4 = GraphNodeFeaturization(fnames, nbins = [2, 4, 2])
F2 = AtomGraph(Float32.([0 1; 1 0]), ["F", "F"])
featurize!(F2, fzn4)
@test all(F2.encoded_features .== enc1)
end

# encodable_elements
Expand Down
6 changes: 0 additions & 6 deletions test/utils/ElementFeatureUtils_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ using ChemistryFeaturization.Utils.ElementFeatureUtils
@test fea_minmax("Group") == [1, 18]
@test fea_minmax("MeaningOfLife", df) == [-1, 42]

# default_log
@test default_log("Block") == false # not numbers
@test default_log("MeaningOfLife", df) == false # values span 0
@test default_log("Valence") == false # extremal value 0
@test default_log("Atomic mass") == true
@test default_log("Atomic mass", threshold = 3) == false
# default_log
@test default_log("Block") == false # not numbers
@test default_log("MeaningOfLife", df) == false # values span 0
Expand Down