Skip to content

Commit 6e1b5d8

Browse files
committed
add Molly example
1 parent da33cfe commit 6e1b5d8

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

examples/Tutorial/ACE+AtomsBase.jl

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
using Pkg
1313
## Uncomment the next line if installing Julia for the first time
1414
## Pkg.Registry.add("General")
15-
Pkg.activate(".")
15+
## Pkg.Registry.add
1616
Pkg.add(["ExtXYZ", "Unitful", "Distributed", "AtomsCalculators",
17-
"ACEpotentials", "Molly", "AtomsCalculatorsUtilities",
18-
"AtomsBuilder"
17+
"Molly", "AtomsCalculatorsUtilities", "AtomsBuilder",
1918
])
2019

2120
## ACEpotentials installation:
2221
## If ACEpotentials has not been installed yet, uncomment the following lines
23-
## using Pkg; Pkg.activate(".")
2422
## Add the ACE registry, which stores the ACEpotential package information
25-
## Pkg.Registry.add(RegistrySpec(url="https://github.com/ACEsuit/ACEregistry"))
26-
## Pkg.add("ACEpotentials")
23+
Pkg.Registry.add(RegistrySpec(url="https://github.com/ACEsuit/ACEregistry"))
24+
Pkg.add(["GeomOpt", "ACEpotentials",])
2725

2826
# We can check the status of the installed packages.
2927

@@ -59,8 +57,11 @@ acefit!(train, model; solver=solver); GC.gc()
5957
## quickly check test errors => 0.5 meV/atom and 0.014 eV/A are ok
6058
ACEpotentials.compute_errors(test, model)
6159

62-
# ## A Simple Geometry Optimization Task
60+
# ## Geometry Optimization with GeomOpt
6361
#
62+
# ( Note: we should use GeometryOptimization.jl, but this is not yet updated to
63+
# AtomsBase.jl version 0.4. )
64+
#
6465
# First import some stuff + a little hack to make GeomOpt play nice with
6566
# the latest AtomsBase. This is a shortcoming of DecoratedParticles.jl
6667
# and requires some updates to fully implement the AtomsBase interface.
@@ -79,7 +80,7 @@ end
7980
# equilibrium bond distance as the default in AtomsBuilder, so we optimize
8081
# the unit cell.
8182

82-
ucell = bulk(:Cu, cubic=true)
83+
ucell = bulk(sym, cubic=true)
8384
ucell, _ = GeomOpt.minimise(ucell, model; variablecell=true)
8485

8586
# We keep the energy of the equilibrated unit cell to later compute the
@@ -104,3 +105,27 @@ vacancy_equil, result = GeomOpt.minimise(sys, model; variablecell = false)
104105
E_def = potential_energy(vacancy_equil, model) - length(sys) * Eperat
105106
@show E_def
106107

108+
# ## Molecular Dynamics with Molly
109+
#
110+
# First import some stuff + a little hack to make GeomOpt play nice with
111+
# the latest AtomsBase. This is a shortcoming of DecoratedParticles.jl
112+
# and requires some updates to fully implement the AtomsBase interface.
113+
114+
import Molly
115+
sys = rattle!(bulk(sym, cubic=true) * (2,2,2), 0.03)
116+
sys_md = Molly.System(sys; force_units=u"eV/Å", energy_units=u"eV")
117+
temp = 298.0u"K"
118+
sys_md = Molly.System(
119+
sys_md;
120+
general_inters = (model,),
121+
velocities = Molly.random_velocities(sys_md, temp),
122+
loggers=(temp=Molly.TemperatureLogger(100),) )
123+
# energy = Molly.PotentialEnergyLogger(100),), )
124+
# can't add an energy logger because Molly internal energies are per mol
125+
simulator = Molly.VelocityVerlet(
126+
dt = 1.0u"fs",
127+
coupling = Molly.AndersenThermostat(temp, 1.0u"ps"), )
128+
traj = Molly.simulate!(sys_md, simulator, 1000)
129+
130+
## the temperature seems to fluctuate a bit too much, but at least it looks stable?
131+
@show sys_md.loggers.temp.history

0 commit comments

Comments
 (0)