ASEconvert
Light-weight module to install the atomistic simulation environment (ASE) and provide routines for cross-converting between ASE datastructures and the respective ones of the JuliaMolSim ecosystem. E.g. it allows to convert between the ASE Atoms and exposing them using an AtomsBase compatible interface or it allows to employ calculators from ASE as AtomsCalculators.
Automatic ASE installation
Using the mechanism provided by PythonCall and CondaPkg ASEconvert will automatically take care of installing ASE and exporting a useful subset of its modules under the ase
variable. For example one may easily create bulk systems
using ASEconvert
ase.build.bulk("Mg")
Python: Atoms(symbols='Mg2', pbc=True, cell=[[3.21, 0.0, 0.0], [-1.605, 2.7799415461480477, 0.0], [0.0, 0.0, 5.21304]])
or surfaces
using ASEconvert
ase.build.surface(ase.build.bulk("Mg"), (1, 1, 0), 4, 0, periodic=true)
Python: Atoms(symbols='Mg8', pbc=True, cell=[5.559883092296095, 5.21304, 4.8149999999999995])
Conversion from ASE to AtomsBase
using ASEconvert
# Construct bulk magnesium using ASE and convert to atomsbase
mg_ase = ase.build.bulk("Mg")
mg_atb = pyconvert(AbstractSystem, mg_ase)
FlexibleSystem(Mg₂, periodic = TTT):
bounding_box : [ 3.21 0 0;
-1.605 2.77994 0;
0 0 5.21304]u"Å"
Atom(Mg, [ 0, 0, 0]u"Å")
Atom(Mg, [-8.86328e-17, 1.85329, 2.60652]u"Å")
Mg
Mg
using DFTK
# Attach pseudopotentials, construct LDA DFT model and solve for DFT ground state
system = attach_psp(mg_atb; Mg="hgh/lda/mg-q2")
model = model_LDA(system; temperature=1e-3, smearing=Smearing.MarzariVanderbilt())
basis = PlaneWaveBasis(model; Ecut=20, kgrid=(4, 4, 4))
scfres = self_consistent_field(basis)
scfres.energies
Conversion from AtomsBase to ASE
using ASEconvert
using AtomsIO
# Read an extxyz file using AtomsIO.jl.
system = load_system("Mn3Si.extxyz")
Atoms(Mn₃Si, periodic = TTT):
bounding_box : [ 3.99987 0 0;
1.99993 3.46399 0;
1.99993 1.15466 3.26588]u"Å"
spacegroup : P 1
occupancy : _JSON {"0": {"Mn": 1}, "1": {"Mn": 1}, "2": {"Mn": 1}, "3": {"Si": 1}}
unit_cell : conventional
AtomView(Mn, [ 1.99993, 1.15466, 0.81647]u"Å")
AtomView(Mn, [ 5.9998, 3.46399, 2.44941]u"Å")
AtomView(Mn, [ 3.99987, 2.30933, 1.63294]u"Å")
AtomView(Si, [ 0, 0, 0]u"Å")
Mn
Mn
Mn
Si
This example uses AtomsIO to read the extended XYZ file file Mn3Si.extxyz
. The data is returned as a subtype of AtomsBase.AbstractSystem
(in this case an ExtXYZ.Atoms
from ExtXYZ). We can thus directly convert this system to an ase.Atoms
using convert_ase
and write it again as an ASE json file
ase.io.write("out.json", convert_ase(system));
Python: None
Employing ASE calculators in Julia
using PythonCall
using ASEconvert
ase_emt = pyimport("ase.calculators.emt")
calculator = ASEcalculator(ase_emt.EMT())
ASEcalculator(<py ase.calculators.emt.EMT object at 0x7f7b93c4c2f0>)
The above codeblock employs PythonCall to setup an EMT calculator in ASE. Using the ASEcalculator
wrapper this calculator is wrapped and now exposes a standard AtomsCalculators-compatible interface. For example one can use it to compute energy and forces of a copper supercell.
First we make the supercell:
using AtomsBuilder
system = bulk(:Cu) * (4, 3, 2) # Make copper supercell
FlexibleSystem(Cu₂₄, periodic = TTT):
bounding_box : [ 0 7.22 7.22;
5.415 0 5.415;
3.61 3.61 0]u"Å"
Cu
Cu
Cu
Cu Cu
CuCu
Cu Cu
Cu Cu
Cu
Cu
Cu Cu
Cu Cu
CuCu
Cu Cu
Cu
Cu
Cu
Next we use the energy_forces
function from AtomsCalculators
:
using AtomsCalculators
AtomsCalculators.energy_forces(system, calculator)
(energy = -0.13635627260589267 eV, forces = StaticArraysCore.SVector{3, Unitful.Quantity{Float64, 𝐋 𝐌 𝐓^-2, Unitful.FreeUnits{(Å^-1, eV), 𝐋 𝐌 𝐓^-2, nothing}}}[[-6.8187062814389476e-15 eV Å^-1, 1.0179357357031904e-14 eV Å^-1, 1.05686776812103e-14 eV Å^-1], [2.0256562117108466e-15 eV Å^-1, -4.630718958243893e-15 eV Å^-1, -1.8972955836827935e-15 eV Å^-1], [7.111350447242914e-15 eV Å^-1, 7.757683384568281e-15 eV Å^-1, -3.8749502111662176e-15 eV Å^-1], [-5.127842594987442e-15 eV Å^-1, -9.372710940702689e-15 eV Å^-1, -7.153999614928352e-15 eV Å^-1], [1.6375789613221059e-15 eV Å^-1, 7.388187284185221e-15 eV Å^-1, 3.0513785942432037e-15 eV Å^-1], [2.42861286636753e-17 eV Å^-1, 2.0122792321330962e-16 eV Å^-1, -2.473715676742927e-15 eV Å^-1], [7.129713486264677e-15 eV Å^-1, 3.2248509418408844e-15 eV Å^-1, -9.386588728510503e-15 eV Å^-1], [-4.12864121812496e-16 eV Å^-1, -6.943356073473364e-15 eV Å^-1, 1.1258847061715359e-14 eV Å^-1], [9.558326352632207e-16 eV Å^-1, 4.5727310826748635e-15 eV Å^-1, 7.840950111415168e-16 eV Å^-1], [7.173081573164097e-15 eV Å^-1, 2.7998436902265667e-15 eV Å^-1, -8.815864704914134e-15 eV Å^-1] … [-4.401769234853726e-15 eV Å^-1, -6.017982742993408e-15 eV Å^-1, -3.730968031720174e-15 eV Å^-1], [5.127842594987442e-15 eV Å^-1, 1.3454515279676116e-14 eV Å^-1, -7.28583859910259e-15 eV Å^-1], [-5.5103006288040974e-15 eV Å^-1, 1.960968411408154e-15 eV Å^-1, -7.532379661141233e-17 eV Å^-1], [-4.51354529076018e-15 eV Å^-1, -6.303483032920232e-15 eV Å^-1, -2.987193825632062e-15 eV Å^-1], [5.339707769710608e-15 eV Å^-1, -4.0121183560676646e-15 eV Å^-1, -4.6150832594331706e-15 eV Å^-1], [-2.0678827099556048e-17 eV Å^-1, 6.1451096299425104e-15 eV Å^-1, 8.172043220277376e-15 eV Å^-1], [-4.465611908033296e-15 eV Å^-1, 2.033095913844818e-15 eV Å^-1, -6.316561856900549e-16 eV Å^-1], [-5.530298441414061e-15 eV Å^-1, -4.772657963281191e-16 eV Å^-1, -3.677613769070831e-15 eV Å^-1], [-4.8327227636368875e-15 eV Å^-1, -5.006195111234568e-15 eV Å^-1, 7.039507865513883e-15 eV Å^-1], [-3.8614944575243726e-15 eV Å^-1, 4.763550665032312e-15 eV Å^-1, -7.17134684968812e-15 eV Å^-1]])