Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 3 additions & 8 deletions docs/src/fitting-eft.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,9 @@ R = randf(fm,Σ)
## [Friction Model with a Pairwise Coupling](@id fitting-pairwise-coupling)
Instead of using a row-wise coupling, we can also use a pairwise coupling to construct a friction model. The following code produces a friction model with a pairwise coupling:
```julia
property = EuclideanMatrix()
property = EuclideanMatrix(Float64)
species_friction = [:H]
species_env = [:Cu]
m_equ = RWCMatrixModel(property, species_friction, species_env;
species_substrat = [:Cu],
rcut = 5.0,
maxorder = 2,
maxdeg = 5,
);
species_env = [:Cu,:H]

m_equ = PWCMatrixModel(property, species_friction, species_env;
z2sym = NoZ2Sym(),
Expand All @@ -152,4 +146,5 @@ m_equ0 = OnsiteOnlyMatrixModel(property, species_friction, species_env;
);

fm= FrictionModel((mequ_off = m_equ, mequ_on=m_equ0));

```
37 changes: 28 additions & 9 deletions examples/fit-ACEFrictionModel-new-pw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using ACEfriction.FrictionFit

using ACEfriction.MatrixModels

fname = "./test/test-data-large"
fname = "./test/test-data-100"
filename = string(fname,".h5")

rdata = ACEfriction.DataUtils.load_h5fdata(filename);
Expand All @@ -25,17 +25,35 @@ shuffle!(rng, rdata)
n_train = Int(ceil(.8 * length(rdata)))
n_test = length(rdata) - n_train

fdata = Dict("train" => FrictionData.(rdata[1:n_train]),
"test"=> FrictionData.(rdata[n_train+1:end]));
fdata = Dict("train" => rdata[1:n_train],
"test"=> rdata[n_train+1:end]);

using ACEfriction.AtomCutoffs: SphericalCutoff
using ACEfriction.MatrixModels: NoZ2Sym, SpeciesUnCoupled
species_friction = [:H]
species_env = [:Cu,:H]
species_substrat = [:Cu]
rcut = 5.0
z2sym= NoZ2Sym()
speciescoupling = SpeciesUnCoupled()
# property = EuclideanMatrix(Float64)
# species_friction = [:H]
# species_env = [:Cu,:H]

# m_equ = PWCMatrixModel(property, species_friction, species_env;
# z2sym = NoZ2Sym(),
# speciescoupling = SpeciesUnCoupled(),
# species_substrat = [:Cu],
# n_rep = 1,
# maxorder=2,
# maxdeg=5,
# rcut= 5.0,
# );

# m_equ0 = OnsiteOnlyMatrixModel(property, species_friction, species_env;
# species_substrat=[:Cu],
# id=:equ0,
# n_rep = 1,
# rcut = rcut,
# maxorder=2,
# maxdeg=5
# );

# fm= FrictionModel((mequ_off = m_equ, mequ_on=m_equ0));

m_equ = PWCMatrixModel(ACE.EuclideanMatrix(Float64),species_friction, species_env;
z2sym = NoZ2Sym(),
Expand Down Expand Up @@ -88,6 +106,7 @@ end

loss_traj = Dict("train"=>Float64[], "test" => Float64[])

# Note: the following code only works when run in REPL (scoping of the variable 'epoch' fails if run in a global scope.)
epoch = 0
batchsize = 10
nepochs = 10
Expand Down
3 changes: 3 additions & 0 deletions src/datautils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ function save_h5fdata(rdata::Vector{FrictionData}, filename::String )
for (k,x) in enumerate(d.atoms.X)
dset_pos[k,:] = x
end
write_attribute(dset_pos, "column_major", true)
write(ag, "atypes", Int.(d.atoms.Z))
write(ag, "cell", Matrix(d.atoms.cell))
write_attribute(ag["cell"], "column_major", true)
write(ag, "pbc", Array(d.atoms.pbc))
# write friction data
fg = create_group(g, "friction_tensor")
Expand All @@ -77,6 +79,7 @@ function save_h5fdata(rdata::Vector{FrictionData}, filename::String )
for (k,v) in enumerate(V)
dset_ft[k,:,:] = v
end
write_attribute(dset_ft, "column_major", true)
write(fg, "ft_mask", d.friction_indices)
end
catch
Expand Down
Binary file modified test/test-data-100.h5
Binary file not shown.