-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from ACEsuit/co/load
Load potential
- Loading branch information
Showing
5 changed files
with
50 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,25 @@ | ||
using Test | ||
using ACEpotentials | ||
using LazyArtifacts | ||
|
||
using Test, ACEpotentials, AtomsBuilder | ||
using AtomsCalculators: potential_energy | ||
using Polynomials4ML.Testing: print_tf | ||
|
||
model = acemodel(elements = [:Si], | ||
Eref = [:Si => -158.54496821], | ||
rcut = 5.5, | ||
order = 3, | ||
totaldegree = 12) | ||
data = read_extxyz(artifact"Si_tiny_dataset" * "/Si_tiny.xyz") | ||
data_keys = [:energy_key => "dft_energy", | ||
:force_key => "dft_force", | ||
:virial_key => "dft_virial"] | ||
weights = Dict("default" => Dict("E"=>30.0, "F"=>1.0, "V"=>1.0), | ||
"liq" => Dict("E"=>10.0, "F"=>0.66, "V"=>0.25)) | ||
model_spec = Dict("model_name" => "ACE1", | ||
"elements" => ["Ti", "Al"], | ||
"rcut" => 5.5, | ||
"order" => 3, | ||
"totaldegree" => 8) | ||
model = ACEpotentials.make_model(model_spec) | ||
set_parameters!(model, randn(length_basis(model))) | ||
|
||
|
||
acefit!(model, data; | ||
data_keys..., | ||
weights = weights, | ||
solver = ACEfit.LSQR( | ||
damp = 2e-2, | ||
conlim = 1e12, | ||
atol = 1e-7, | ||
maxiter = 100000, | ||
verbose = false | ||
) | ||
) | ||
fname = tempname() * ".json" | ||
pot = ACEpotential(model.potential.components) | ||
@test_throws AssertionError save_potential(fname, model; meta="meta test") | ||
save_potential(fname, model; meta=Dict("test"=>"meta test") ) | ||
npot = load_potential(fname; new_format=true) | ||
@test ace_energy(pot, data[1]) ≈ ace_energy(npot, data[1]) | ||
ACEpotentials.save_model(model, fname; model_spec = model_spec) | ||
|
||
model1, meta = ACEpotentials.load_model(fname) | ||
|
||
for ntest = 1:10 | ||
sys = rattle!(bulk(:Al, cubic=true) * 2, 0.1) | ||
sys = randz!(sys, [:Ti => 0.5, :Al => 0.5]) | ||
print_tf( @test potential_energy(sys, model) ≈ potential_energy(sys, model1) ) | ||
end | ||
|
||
rm(fname) |