the atomic simulation environment: overview and...

29

Upload: others

Post on 27-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

The Atomic Simulation Environment:Overview and developments

Ask Hjorth [email protected]

Nano-bio Spectroscopy Groupand ETSF Scienti�c Development CentreUniversidad del País Vasco UPV/EHU

FHI-aims developers' and users' meeting 2018

Page 2: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

The Atomic Simulation Environment

ASE is a free (LGPLv2.1+) toolkit to set up and control atomisticcalculations in a fully scripted environment using Python.

Main features

I The Atoms object: A collection of atoms

I Calculators: Capable of calculating energies and forces ofatoms, often using an external code as backend

I Algorithms working with atoms/calculators: Structureoptimization, molecular dynamics, basin hopping, minimahopping, nudged elastic band, . . .

I Many utilities: Build crystals, surfaces, . . .

I Read/write structures in many formats

I Also: GUI, command-line utilities

Page 3: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Example: Structure optimization with GPAW

from ase import Atoms

from ase.optimize import BFGS

from gpaw import GPAW

system = Atoms('H2O', positions =[[-1, 0, 0],

[1, 0, 0],

[0, 0, 1]])

system.center(vacuum =3.0)

system.calc = GPAW(mode='lcao', basis='dzp')

opt = BFGS(system ,

trajectory='opt.traj',

logfile='opt.log')

opt.run(fmax =0.05)

Page 4: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Example: Structure optimization with Espresso

from ase import Atoms

from ase.optimize import BFGS

from ase.calculators.espresso import Espresso

system = Atoms('H2O', positions =[[-1, 0, 0],

[1, 0, 0],

[0, 0, 1]])

system.center(vacuum =3.0)

system.calc = Espresso(

ecutwfc =40., pseudo_dir='.', tprnfor=True ,

pseudopotentials ={'H': 'H_ONCV_PBE -1.0. upf',

'O': 'O_ONCV_PBE -1.0. upf'})

opt = BFGS(system , trajectory='opt.traj',

logfile='opt.log')

opt.run(fmax =0.05)

Page 5: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Example: Structure optimization with FHI-aims

from ase import Atoms

from ase.optimize import BFGS

from ase.calculators.aims import Aims

system = Atoms('H2O', positions =[[-1, 0, 0],

[1, 0, 0],

[0, 0, 1]])

species_dir = '/home/aimsuser/src/fhi -aims .171221 _1/species_defaults/light'

system.calc = Aims(xc='LDA',

command='aims',

species_dir=species_dir ,

compute_forces=True)

opt = BFGS(system ,

trajectory='opt.traj',

logfile='opt.log')

opt.run(fmax =0.05)

Page 6: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Codes with ASE calculators

ASAP Abinit AtomisticaCP2K Castep DFTB+Dacapo ELK ExcitingFHI-aims Fleur GPAWGaussian Gromacs HotbitJDFTx LAMMPS MOPACNWChem Octopus OpenKIMOpenMX OpenMX QUIPQuantum Espresso Siesta TurbomoleVASP deMon matscipy

Page 7: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Communication withexternal codes

Atoms

Calculator

External code

generate

input

script

retrieve and

convert data

"get

potential

energy"

solve Schrödinger

equation

return the

potential

energy

1) One process per calculation

I ASE creates input�le, runs codein subprocess (see �gure)

2) Persistent subprocess

I External process remains aliveover multiple calculations

I IO uses sockets, pipes or �les

3) Within same process

I Direct access to functions, data

I Requires Python bindings

Page 8: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Atoms

Calculator

Dynamics

Optimizer

GPAW DacapoAbinit ...

Interface

Implementations

Vibrations

BFGS MDMin

MolecularDynamics

Langevin Verlet

NEB

Constraints

Page 9: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Build and view structures

from ase import Atoms

from ase.visualize import view

a = 2.04

gold = Atoms('Au', pbc=True ,

cell =[[0, a, a],

[a, 0, a],

[a, a, 0]])

print(gold)

view(gold.repeat ((2, 2, 2)))

from ase.build import molecule

view(molecule('C6H6'))

Page 10: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Command-line tools

I Type ase help

I Di�erent subcommands: build, gui, nomad-upload, . . .

Page 11: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Try the ASE GUI

I Run ase gui

(previously: ase-gui)

I Build nanoparticle orsomething else

I Select, move atoms(Ctrl+M)

I Save to your favouriteformat

Page 12: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

DatabaseI Store atoms objects alongside auxiliary informationI Backends: JSON, SQLite, PostgreSQLI Good for everyday calculation work�ow

import numpy as np

from ase.build import bulk

from ase.db import connect

from ase.calculators.emt import EMT

with connect('database.db') as con:

for sym in ['Al', 'Cu', 'Pd', 'Ag', 'Au', 'Pd']:

atoms = bulk(sym)

atoms.calc = EMT()

cell0 = atoms.cell.copy()

for scale in np.linspace (0.95 , 1.05, 11):

atoms.cell = cell0 * scale

atoms.get_potential_energy ()

# Add user -defined columns:

con.write(atoms , sym=sym , scale=scale)

Page 13: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Database

Retrieve and print data from database

from ase.db import connect

con = connect('database.db')

for row in con.select(sym='Au'):

atoms = row.toatoms ()

print('{}: {:8.3f} {:8.3f} {:8.3f}'

.format(row.id, row.scale ,

atoms.get_volume (), row.energy ))

I Also available: ase db command line tool

I Display and manipulate databases

Page 14: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

More on ASE

I Started as an object-oriented Python interface to the oldultrasoft pseudopotential planewave code Dacapo

I S.R. Bahn, K.W. Jacobsen, �An object-oriented scriptinginterface to a legacy electronic structure code�. Computing inScience & Engineering, 4(3):56�66, 2002.

I New reference paper: A.H. Larsen, J.J. Mortensen et al., 2017J. Phys. Condens. Matter 29 273002, 2017. �The AtomicSimulation Environment � A Python library for working withatoms�. (Also available as Psi-k Highlight of the Month,January 2017)

Page 15: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Development

I https://gitlab.com/ase/ase

I BDFL: Jens Jørgen Mortensen, DTU Physics

I Very large number of contributors (∼ 150 committers)

I Many modules are maintained by di�erent contributors

I �Scratch your own itch�

Page 16: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Communication schemes(again)

Atoms

Calculator

External code

generate

input

script

retrieve and

convert data

"get

potential

energy"

solve Schrödinger

equation

return the

potential

energy

Persistent calculators

I Standard �File I/O� calculatorprocesses will end after eachcalculation

I Ine�cient because: No reuse ofdensity/wavefunctions, nowavefunction extrapolation

I With some codes the processcan persist over multiplecalculations, providing somemechanism to communicatenew positions/forces

I Typical mechanisms are socketsor pipes

Page 17: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Support for i-PI socket protocol in ASE

About i-PI

I Molecular dynamics with many codes over socket interface

I http://ipi-code.org/

I Ceriotti, More, Manolopoulos, Comp. Phys. Comm. 185,1019�1026 (2014)

I Implements MD algorithms, �drivers�, server

I Interfaces to several codes using sockets

I Client codes: Quantum Espresso, FHI-aims, Siesta, DFTB+,Ya�, cp2k, Lammps, ASE, GPAW

I ASE now implements a server that can use the i-PI protocol

Page 18: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Sockets in ASE using the i-PI protocol

I ASE implements both server and client for the i-PI protocol

I The server can be used as a Calculator,ase.calculators.socketio.SocketIOCalculator

I The SocketIOCalculator wraps another (ordinary) calculatorwhich is responsible for launching the client

Page 19: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Socket protocol

I Start server, listen for connection on socket

I When calculation is triggered, use wrapped calculator tolaunch subprocess

I Or: Start server on one computer, start client on di�erentcomputer

I Client process connects to socket

I Server passes positions and cell to client; client passes energy,forces, and stress to server

I Other quantities (atomic species, input parameters in general)are communicated by other means and requires restart

Page 20: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Run FHI-aims with ASE using i-PI socket protocol:

from ase.build import molecule

from ase.optimize import BFGS

from ase.calculators.aims import Aims

from ase.calculators.socketio import SocketIOCalculator

port = 31415

atoms = molecule('H2O', vacuum =3.0)

atoms.rattle(stdev =0.1)

aims = Aims(command='ipi.aims .171221 _1.mpi.x',

use_pimd_wrapper =('localhost ', port),

compute_forces=True ,

xc='LDA',

species_dir='/home/aimsuser/species_dir ')

opt = BFGS(atoms , trajectory='opt.aims.traj')

with SocketIOCalculator(aims , port=port) as calc:

atoms.calc = calc

opt.run(fmax =0.05)

Page 21: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

H3CN

H2CH

2OCH

2C2

H5CH

3NO2

CH2S

CH2

C3H6

_D3h

C3H4

_D2d

C3H4

_C3v

CH3C

H2SH

CH3C

H2Cl

CH3C

OCH3

H2CC

HCN

HCOO

CH3

CH3C

H2OH

C4H4

OC2

H6SO

C3H7

CH3C

ONH2

bicy

clobu

tane

cyclo

buta

neC6

H62-

buty

neiso

bute

neC2

H6CH

OHtra

ns-b

utan

eC3

H9C

0

25

50

75

100

125

150

175

200

Tim

e to

opt

imise

[s]

normalpersistent/sockets

I Relaxation time for randomly perturbed molecules with Aims,no wavefunction extrapolation (some axis labels omitted)

Page 22: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

H3CN

H2CH

2OCH

2C2

H5CH

3NO2

CH2S

CH2

C3H6

_D3h

C3H4

_D2d

C3H4

_C3v

CH3C

H2SH

CH3C

H2Cl

CH3C

OCH3

H2CC

HCN

HCOO

CH3

CH3C

H2OH

C4H4

OC2

H6SO

C3H7

CH3C

ONH2

bicy

clobu

tane

cyclo

buta

neC6

H62-

buty

neiso

bute

neC2

H6CH

OHtra

ns-b

utan

eC3

H9C

0.0

2.5

5.0

7.5

10.0

12.5

15.0

17.5

20.0

Itera

tions

in fi

nal S

CF lo

opnormalpersistent/sockets

I Number of SCF steps for �nal step

I About 40% fewer iterations on average

Page 23: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Support in ASE for codes implementing i-PI clients

Program name Supported by ASE calculator

Quantum Espresso YesFHI-aims YesSiesta YesDFTB+ Yes, presumably (untested)Ya� No; there is no ASE calculator for Ya�cp2k No; ASE uses cp2k shell insteadLammps No; ASE uses lammpsrun/lammpslib insteadASE Yes - ASE provides a client as wellGPAW Yes, using the ASE client

Page 24: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Planned/on-going developments for molecular dynamics

I ASE supports molecular dynamics with several thermostats(Langevin, Berendsen NPT/NVT, . . .

I High-level tools for initialization/calibration of MD runs

I High-level tools for process management, error handling, . . .

Page 25: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Thermalization in molecular dynamics

I How do we start an MD run at a given temperature?

I Maxwell�Boltzmann distribution ignores potential energycontribution in solids

0 200 400 600 800 1000 1200 1400Time [fs]

0

20

40

60

80

100

Tem

pera

ture

[K]

Maxwell-Boltzmann 100K

Langevin thermostat at100 K running on FCCstructure of random alloy

Page 26: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Equilibrium positions, double temperature

0 200 400 600 800 1000 1200 1400Time [fs]

0

25

50

75

100

125

150

175

200

Tem

pera

ture

[K]

Maxwell-Boltzmann 100KMaxwell-Boltzmann 200K

I Almost good, but unphysical starting point

Page 27: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

MD initialization from phonon modes

I Initialize displacements and velocities according to phononmodes εai

Ra =

√kBT

ma

∑i

εaiωiAi sin(Pi)

va =

√kBT

ma

∑i

εaiAi cos(Pi)

I Ai are random normally distributed numbers

I Pi are uniformly random phases 0 . . . 2π

http://ollehellman.github.io/program/extract_

forceconstants.html

More on phonons: See poster by Florian Knoop

Page 28: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

MD initialization from phonon modes

0 200 400 600 800 1000 1200 1400Time [fs]

0

25

50

75

100

125

150

175

200

Tem

pera

ture

[K]

Maxwell-Boltzmann 100KMaxwell-Boltzmann 200KPhononically correct

I Starts at physically meaningful con�guration

Page 29: The Atomic Simulation Environment: Overview and developmentsdcaskhl/files/askhl-aims-muenchen-2018.pdf · Introduction and overview Communication and sockets MD and high-throughput

Introduction and overview Communication and sockets MD and high-throughput Conclusions

Concluding remarks

I Web page: https://wiki.fysik.dtu.dk/ase/

I Gitlab: https://gitlab.com/ase/ase

I Mailing lists, IRC:https://wiki.fysik.dtu.dk/ase/contact.html