Skip to content

Commit

Permalink
Small changes in Si example.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuellujan committed Jun 17, 2024
1 parent 5e3e0ec commit 5d8b807
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions examples/DPP-ACE-Si/fit-dpp-ace-si.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# # Subsample Si dataset and fit with ACE

# ## Load packages, define paths, and create experiment folder.

# Load packages
using LinearAlgebra, Random, InvertedIndices
using Statistics, StatsBase, Distributions, Determinantal
using Unitful, UnitfulAtomic
using AtomsBase, InteratomicPotentials, PotentialLearning
using CSV, JLD, DataFrames

# Define atomic type information
elname, elspec = "Si", [:Si]

# Define paths.
path = joinpath(dirname(pathof(PotentialLearning)), "../examples/DPP-ACE-Si")
inpath = "$path/../data/Si-3Body-LAMMPS/"
outpath = "$path/output/$elname/"

# Load utility functions.
include("$path/subsampling_utils.jl")

# Load dataset
elname = "Si"
elspec = [:Si]
inpath = "$path/../data/Si-3Body-LAMMPS/"
outpath = "$path/output/$elname/"
# ## Load atomistic datasets

# Read all data
# Load all atomistic datasets: atomistic configurations (atom positions, geometry, etc.) + DFT data (energies, forces, etc.)
file_arr = readext(inpath, "xyz")
nfile = length(file_arr)
confs_arr = [load_data(inpath*file, ExtXYZ(u"eV", u"")) for file in file_arr]
Expand All @@ -29,7 +37,9 @@ for k = 1:nfile
n += length(confs_arr[k])
end

# Define ACE basis
# ## Subsampling by DPP

# Create ACE basis
nbody = 4
deg = 5
ace = ACE(species = elspec, # species
Expand All @@ -40,17 +50,18 @@ ace = ACE(species = elspec, # species
r0 = 1.0, # minimum distance between atoms
rcutoff = 10.0)

# Update dataset by adding energy and force descriptors
# Compute ACE descriptors for energies and forces.
println("Computing local descriptors")
e_descr = compute_local_descriptors(confs, ace)
f_descr = compute_force_descriptors(confs, ace)
e_descr = compute_local_descriptors(confs, ace; pbar=false)
f_descr = compute_force_descriptors(confs, ace; pbar=false)
JLD.save(outpath*"$(elname)_energy_descriptors.jld", "e_descr", e_descr)
JLD.save(outpath*"$(elname)_force_descriptors.jld", "f_descr", f_descr)

# Update training dataset by adding energy and force descriptors.
ds = DataSet(confs .+ e_descr .+ f_descr)
ndata = length(ds)

# Compute cross validation error from training
# ## Compute cross validation error from training dataset
batch_size = [80, 40]
sel_ind = Dict{Int64, Vector}()
cond_num = Dict{Int64, Vector}()
Expand Down

0 comments on commit 5d8b807

Please sign in to comment.