Skip to content

Commit

Permalink
Merge pull request #84 from Chemellia/fix_exports
Browse files Browse the repository at this point in the history
Need to import from submodules before doing top-level convenience export, also other minor fixes
  • Loading branch information
rkurchin authored Jun 17, 2021
2 parents 618c0bb + 7442968 commit c5bde65
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
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
5 changes: 5 additions & 0 deletions test/featurizations/GraphNodeFeaturization_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ 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]),
)
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

2 comments on commit c5bde65

@rkurchin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/39137

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 the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" c5bde65a2dbb8f2bb992299b258bdac714785f83
git push origin v0.3.1

Please sign in to comment.