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

Generalise system properties type check #49

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/atoms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Atoms(system::AbstractSystem{D})
atoms_base_keys = (:charge, :covalent_radius, :vdw_radius,
:magnetic_moment, :pseudopotential)
v = system[1, k]
if k in atoms_base_keys || v isa ExtxyzType
if k in atoms_base_keys || v isa ExtxyzType || v isa AbstractVector{<: ExtxyzType}
# These are either Unitful quantities, which are uniformly supported
# across all of AtomsBase or the value has a type that Extxyz can write
# losslessly, so we can just write them no matter the value
Expand All @@ -79,7 +79,7 @@ function Atoms(system::AbstractSystem{D})
system_data = Dict{Symbol,Any}()
for (k, v) in pairs(system)
atoms_base_keys = (:charge, :multiplicity, :boundary_conditions, :bounding_box)
if k in atoms_base_keys || v isa ExtxyzType
if k in atoms_base_keys || v isa ExtxyzType || v isa AbstractArray{<: ExtxyzType}
# These are either Unitful quantities, which are uniformly supported
# across all of AtomsBase or the value has a type that Extxyz can write
# losslessly, so we can just write them no matter the value
Expand Down Expand Up @@ -136,7 +136,7 @@ function Atoms(dict::Dict{String, Any})
elseif key in ("charge", ) # Add charge unit
atom_data[Symbol(key)] = arrays[key] * u"e_au"
elseif typeof(arrays[key]) <: AbstractMatrix
atom_data[Symbol(key)] = [ collect(col) for col in eachcol(arrays[key]) ]
atom_data[Symbol(key)] = [ collect(col) for col in eachcol(arrays[key]) ]
else
atom_data[Symbol(key)] = arrays[key]
end
Expand Down Expand Up @@ -225,7 +225,12 @@ function write_dict(atoms::Atoms)
elseif v isa ExtxyzType
info[string(k)] = v
elseif v isa AbstractArray{<:ExtxyzType}
info[string(k)] = convert(Array, v)
if size(v, 1) != 3
@warn("Writing Array data with a first leading dimension " *
"different from 3 not supported.") # Else leads to segfaults
else
info[string(k)] = convert(Array, v)
end
else
@warn "Writing quantities of type $(typeof(v)) is not supported in write_dict."
end
Expand Down
Loading