Skip to content

Commit 89b6a13

Browse files
committed
Merge branch 'update-hdf5-data-import'
2 parents dadc0ce + a8a4a9f commit 89b6a13

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/datautils.jl

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,50 @@ function save_h5fdata(rdata, filename )
8383
HDF5.close(fid)
8484
end
8585

86-
_hdf52Atoms( ag::HDF5.Group ) = JuLIP.Atoms(;
87-
X=[SVector{3}(d) for d in eachslice(read(ag["positions"]); dims=1)],
86+
function _hdf52Atoms( ag::HDF5.Group )
87+
local positions, cell
88+
try
89+
if Bool(read_attribute(ag["positions"],"column_major")) == true
90+
positions = read(ag["positions"])
91+
else
92+
positions = permutedims(read(ag["positions"]), [2, 1])
93+
end
94+
catch
95+
@warn "The attribute 'column_major' is missing for the data 'positions'. Proceed assuming array was stored in column-major format. If you are saving your array from Python, make sure to set the column_major attribute to 0 (False)."
96+
positions = read(ag["positions"])
97+
end
98+
99+
try
100+
if Bool(read_attribute(ag["cell"],"column_major")) == true
101+
cell = read(ag["cell"])
102+
else
103+
cell = permutedims(read(ag["cell"]), [2, 1])
104+
end
105+
catch
106+
@warn "The attribute 'column_major' is missing for the data 'cell'. Proceed assuming array was stored in column-major format. If you are saving your array from Python, make sure to set the column_major attribute to 0 (False)."
107+
cell = read(ag["cell"])
108+
end
109+
return JuLIP.Atoms(;
110+
X=[SVector{3}(d) for d in eachslice(positions; dims=1)],
88111
Z=read(ag["atypes"]),
89-
cell= read(ag["cell"]),
90-
pbc=read(ag["pbc"])
112+
cell= cell,
113+
pbc=Bool.(read(ag["pbc"]))
91114
)
92-
115+
end
93116

94117
function _hdf52ft( ftg::HDF5.Group )
95-
spft = sparse( read(ftg["ft_I"]),read(ftg["ft_J"]), [SMatrix{3,3}(d) for d in eachslice(read(ftg["ft_val"]); dims=1)] )
118+
local ft_val
119+
try
120+
if Bool(read_attribute(ftg["ft_val"],"column_major")) == true
121+
ft_val = read(ftg["ft_val"])
122+
else
123+
ft_val = permutedims(read(ftg["ft_val"]), [3, 2, 1])
124+
end
125+
catch
126+
@warn "The attribute 'column_major' is missing for the data 'ft_val'. Proceed assuming array was stored in column-major format. If you are saving your array from Python, make sure to set the column_major attribute to 0 (False)."
127+
ft_val = read(ftg["ft_val"])
128+
end
129+
spft = sparse( read(ftg["ft_I"]),read(ftg["ft_J"]), [SMatrix{3,3}(d) for d in eachslice(ft_val; dims=1)] )
96130
ft_mask = read(ftg["ft_mask"])
97131
return (friction_tensor = spft, mask = ft_mask)
98132
end

0 commit comments

Comments
 (0)