Skip to content

Commit f1917d0

Browse files
authored
Add some ad-hoc codes to read old models
1 parent 0bf9c5f commit f1917d0

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

src/dictionary.jl

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ write_dict(V::TBModel) =
125125
"coeffs" => V.coeffs,
126126
"mean" => V.mean )
127127

128+
129+
function deal_mean(mean)
130+
if typeof(mean)<:Matrix
131+
return mean
132+
else
133+
Mean = [ mean[j][i] for i = 1:length(mean[1]), j = 1:length(mean) ]
134+
end
135+
end
136+
128137
function read_dict(::Val{:ACEhamiltonians_TBModel}, D::Dict)
129138

130139
basis = read_dict(D["basis"])
@@ -134,12 +143,15 @@ function read_dict(::Val{:ACEhamiltonians_TBModel}, D::Dict)
134143
return TBModel(basis, coeffs, mean)
135144

136145
end
137-
function deal_mean(mean)
138-
if typeof(mean)<:Matrix
139-
return mean
140-
else
141-
Mean = [ mean[j][i] for i = 1:length(mean[1]), j = 1:length(mean) ]
142-
end
146+
147+
function read_dict(::Val{:ACE2tb_TBModel}, D::Dict)
148+
149+
basis = read_dict(D["basis"])
150+
coeffs = D["coeffs"]
151+
mean = deal_mean(D["mean"])
152+
153+
return TBModel(basis, coeffs, mean)
154+
143155
end
144156

145157
write_dict(env::CylindricalBondEnvelope) =
@@ -187,6 +199,22 @@ function read_dict(::Val{:ACEhamiltonians_OnModelWhole}, D::Dict)
187199

188200
end
189201

202+
function read_dict(::Val{:ACE2tb_OnModelWhole}, D::Dict)
203+
204+
data = read_dict(D["data"])
205+
paramset = read_dict(D["params"])
206+
type = D["Type"]
207+
ModelSS = read_dict.(D["ModelSS"])
208+
ModelSP = read_dict.(D["ModelSP"])
209+
ModelSD = read_dict.(D["ModelSD"])
210+
ModelPP = read_dict.(D["ModelPP"])
211+
ModelPD = read_dict.(D["ModelPD"])
212+
ModelDD = read_dict.(D["ModelDD"])
213+
214+
return OnModelWhole(data,paramset,type,ModelSS,ModelSP,ModelSD,ModelPP,ModelPD,ModelDD)
215+
216+
end
217+
190218
write_dict(ModelW::OffModelWhole) =
191219
Dict( "__id__" => "ACEhamiltonians_OffModelWhole",
192220
"data" => write_dict(ModelW.data),
@@ -221,6 +249,25 @@ function read_dict(::Val{:ACEhamiltonians_OffModelWhole}, D::Dict)
221249

222250
end
223251

252+
function read_dict(::Val{:ACE2tb_OffModelWhole}, D::Dict)
253+
254+
data = read_dict(D["data"])
255+
paramset = read_dict(D["params"])
256+
type = D["Type"]
257+
ModelSS = read_dict.(D["ModelSS"])
258+
ModelSP = read_dict.(D["ModelSP"])
259+
ModelSD = read_dict.(D["ModelSD"])
260+
ModelPS = read_dict.(D["ModelPS"])
261+
ModelPP = read_dict.(D["ModelPP"])
262+
ModelPD = read_dict.(D["ModelPD"])
263+
ModelDS = read_dict.(D["ModelDS"])
264+
ModelDP = read_dict.(D["ModelDP"])
265+
ModelDD = read_dict.(D["ModelDD"])
266+
267+
return OffModelWhole(data,paramset,type,ModelSS,ModelSP,ModelSD,ModelPS,ModelPP,ModelPD,ModelDS,ModelDP,ModelDD)
268+
269+
end
270+
224271
## Model recover
225272
# Recover model/atoms from json file - TODO: there must be a more elegant way for model reconstruction - will consider label the model (by apping orbital symbol to number)!!
226273

0 commit comments

Comments
 (0)