Upload
a-fernando-cg
View
217
Download
0
Embed Size (px)
Citation preview
8/19/2019 Atomic Simulation Enviornment
1/21
Atomic Simulation Environment - a Python library
Modern Tools for Spectroscopy on Advanced MaterialsLouvain-la-Neuve, September 15-17, 2014
Jens Jørgen Mortensen
Department of Physics
Technical University of Denmark
Overview of ASE
The Python language
The Atoms object
Building stuff (molecules, surfaces, ...)Doing stuff with atoms (MD, optimization, ...)
Databases
Installing ASE
Development of ASE
8/19/2019 Atomic Simulation Enviornment
2/21
What is ASE?
ASE is a Python library for working with atoms:
A S E p a c k a g e
A t o m s
p o s i t i o n s ,
a t o m i c n u m b e r s ,
. . .
C o n s t r a i n t s
F i x e d a t o m s ,
b o n d s , . . .
C a l c u l a t o r
A b i n i t , . . . , V A S P
F i l e I O
x y z , c i f , . . .
M o l e c u l a r D y n a m i c s
O p t i m i z a t i o n
V i s u a l i z e
R e a c t i o n p a t h s
N E B , D i m e r
V i b r a t i o n s
I n f r a r e d ,
P h o n o n s
A n a l y s i s
D O S , S T M i m a g e s
http://wiki.fysik.dtu.dk/ase
http://wiki.fysik.dtu.dk/asehttp://wiki.fysik.dtu.dk/ase
8/19/2019 Atomic Simulation Enviornment
3/21
A recipe for your atoms
from ase import Atoms
from ase.optimize import BFGS
from ase.calculators.nwchem import NWChem
from ase.io import write
h2 = Atoms(’H2’,
positions=[(0, 0, 0),
(0, 0, 0.7)])
h2.calc = NWChem(xc=’PBE’)
opt = BFGS(h2)
opt.run(fmax=0.02)write(’H2.xyz’, h2)
Units: eV and Å.
8/19/2019 Atomic Simulation Enviornment
4/21
An interactive recipe for your atoms
>>> from ase import Atoms
>>> from ase.optimize import BFGS
>>> from ase.calculators.nwchem import NWChem
>>> from ase.io import write
>>> h2 = Atoms(’H2’,
positions=[(0, 0, 0),
(0, 0, 0.7)])
>>> h2.calc = NWChem(xc=’PBE’)
>>> opt = BFGS(h2)
>>> opt.run(fmax=0.02)
BFGS: 0 19:10:49 -31.435229 2.2691
BFGS: 1 19:10:50 -31.490773 0.3740BFGS: 2 19:10:50 -31.492791 0.0630
BFGS: 3 19:10:51 -31.492848 0.0023
>>> write(’H2.xyz’, h2)
>>> h2.get_potential_energy()
-31.492847800329216
8/19/2019 Atomic Simulation Enviornment
5/21
What is Python?
http://www.python.org
Interpreted language
Dynamically typed
Easy to read and write, and very expressive
Great for scripting a calculation
Great for small and large programsOptimized for programmer productivity
Can be extended in C/C++/Fortran
General purpose language
Numpy: Base N-dimensional array packageScipy: Fundamental library for scientific computing
Matplotlib: Comprehensive 2D Plotting
Sympy: Symbolic mathematics.
http://www.python.org/http://www.python.org/
8/19/2019 Atomic Simulation Enviornment
6/21
8/19/2019 Atomic Simulation Enviornment
7/21
The Atoms objectA t o m s
. . .
C o n s t r a i n t s C a l c u l a t o r
What’s inside?
Positions, atomic numbers, velocities, masses, initial magneticmoments, charges, tags
Unit cell
Boundary conditions
(Calculator)
(Constraints)
M h d d ib f h A bj
8/19/2019 Atomic Simulation Enviornment
8/21
Methods and attributes of the Atoms object
List methods:
a.pop() # remove last atom
a.append(’Xe’) # append xenon atom
a.extend(Atoms(’H2’)) # append 2 hydrogens
a[1] # second atom
del a[-3:] # delete three last atoms
Other methods: repeat(), translate(), center(),rotate(), get_distance(), get_angle(), get_momentsof_inertia(), ...Special attributes: positions, numbers, cell, pbc (Numpy n-darrays)
x1, x2 = a.positions[-2:, 0] # x-coords of
# last two atoms
a.positions[-2:, 0] += 0.1 # translate atoms
a.positions[:, 2].max() # maximum z-coord
B ildi h A bj
8/19/2019 Atomic Simulation Enviornment
9/21
Building the Atoms object
A t o m s
p o s i t i o n s ,
a t o m i c n u m b e r s ,
. . .
F i l e I O
x y z , c i f , . . .
D a t a b a s e
b u l k ( )
m o l e c u l e ( )
n a n o r i b b o n ( )
s u r f a c e ( )
B ildi th At bj t
8/19/2019 Atomic Simulation Enviornment
10/21
Building the Atoms object ...
from ase import Atoms
h2 = Atoms(’H2’, [(0, 0, 0), (0, 0, 0.74)])
from ase.structure import molecule
water = molecule(’H2O’)
from ase.lattice import bulk
si2 = bulk(’Si’)
from ase.lattice.spacegroup import crystal
rutile = crystal([’Ti’, ’O’],
basis=[(0, 0, 0), (u, u, 0)],
spacegroup=136,
cellpar=[a, a, c,
90, 90, 90])from ase.lattice.surface import fcc110
slab = fcc110(’Pt’, (2, 1, 7), a=4.0,
vacuum=6.0)
from ase.lattice.surface import add_adsorbate
add_adsorbate(slab, ’H’, site=’hollow’)
B ildi th At bj t ti d
8/19/2019 Atomic Simulation Enviornment
11/21
Building the Atoms object, continued ...
from ase.lattice.surface import surface
nasty_cut = surface(rutile, (1, 1, 0),
layers=5)from ase.io import read
q = read(’quarts.cif’)
import ase.db
con = ase.db.con(’mystuff.db’)
atoms = con.get_atoms(foo=’bar’, H=0)
# same as this:
atoms = read(’mystuff.db@foo=bar,H=0’)
ASE’ l l t
8/19/2019 Atomic Simulation Enviornment
12/21
ASE’s calculatorsA t o m s
C a l c u l a t o r
. . .
DFT, ab initio :
Abinit, Castep, ELK, Exciting, FHI-Aims, Fleur, Gaussian,
GPAW, Jacapo, JDFTx, NWChem, QuantumEspresso,
SIESTA, Turbomole, VASP
(Semi-)empirical potentials:
ASAP, DFTB+, EAM, EMT, Gromacs, Hotbit, LAMMPS,
Lennard-Jones, MOPAC, Morse
Optimization MD and minimum energy paths
8/19/2019 Atomic Simulation Enviornment
13/21
Optimization, MD and minimum energy pathsA t o m s
p o s i t i o n s ,
a t o m i c n u m b e r s ,
. . .
M o l e c u l a r D y n a m i c s
V e r l e t , L a n g e v i n ,
N P T , . . .
O p t i m i z a t i o n
B F G S , F I R E ,
M i n i m a h o p p i n g ,
B a s i n h o p p i n g , . . .
R e a c t i o n p a t h s
N E B , D i m e r
ASE database
8/19/2019 Atomic Simulation Enviornment
14/21
ASE-database
In each row we have:
Taxonomy:Atoms object (positions, atomic numbers, ...)ID, user-name, creation and modified timeConstraintsCalculator name and parameters
Energy, Forces, Stress tensor, dipole moment,magnetic moments
Folksonomy:
Key-value pairs
KeywordsAdditional stuff:
extra data (band structure, ...)
Back-ends: JSON, SQLite3 and PostgreSQL.
Dye sensitized solar cells1
8/19/2019 Atomic Simulation Enviornment
15/21
Dye sensitized solar cells
3 . 0 3 . 5 4 . 0 4 . 5 5 . 0
E
g a p
( e V )
7
6
5
4
3
2
E
n
e
r
g
y
(
e
V
)
1Kristian B. Ørnsø, Christian S. Pedersen, Juan M. Garca-Lastra and Kristian S.
Thygesen Optimizing porphyrins for dye sensitized solar cells using large-scale ab initio calculations Phys. Chem. Chem. Phys., 2014, 16, 16246-16254
A figure from Ørnsø et al (almost)
8/19/2019 Atomic Simulation Enviornment
16/21
A figure from Ørnsø et al. (almost)
import matplotlib.pyplot as plt
import ase.db
con = ase.db.connect(’dssc.db’)for M in [’Zn’, ’TiO’, ’H2’]:
gap = []
homo = []
lumo = []
for dct in con.select(metal=M,
anchor=’EthynPhA’):
gap.append(dct.E_gap)
homo.append(dct.E_HOMO)
lumo.append(dct.E_LUMO)plt.plot(gap, homo, ’o’)
plt.plot(gap, lumo, ’*’)
plt.ylabel(r’Energy (eV)’)
plt.xlabel(r’$E_{\mathrm{gap}}$ (eV)’)
plt.savefig(’homolumo.svg’)
Three types of calculators
8/19/2019 Atomic Simulation Enviornment
17/21
Three types of calculators
1) a) ASE writes input fileb) ASE starts Fortran/C/C++ code (maybe in parallel)c) ASE waits for Fortran/C/C++ code to finishd) ASE reads output file
2) Same as above, except that the Fortran code doesn’t stop -it waits for a new input file with new coordinates(QuantumEspresso, Dacapo).
3) Python solution (EMT, EAM, ...). For parallel calculations,
the Python interpreter runs on all processes (GPAW, ASAP)
Installing ASE
8/19/2019 Atomic Simulation Enviornment
18/21
Installing ASE
Requirements: Python and NumPy (ase-gui: PyGTK andMatplotlib)
$ SVN=https://svn.fysik.dtu.dk/projects
$ svn co $SVN/ase/trunk ase
$ cd ase
$ python setup.py install --user
$ python setup.py test # takes 1 min.
Where is what?ase/:
Source code.
tools/:Command-line tools
ase/doc/:
Documentation (source for web-page)
Questions
8/19/2019 Atomic Simulation Enviornment
19/21
Questions
How to get started?
http://wiki.fysik.dtu.dk/ase
http://docs.scipy.org/doc/numpy
http://www.python.org
How to get help?
Write to the ase-users mailing list.
How is ASE developed?
Mostly by volunteers. Coordination and discussions on the
ase-developers mailing list.
How to contribute?Please send us bug-reports, patches, code and ideas.
License?
LGPLv2.1+
Thanks
http://wiki.fysik.dtu.dk/asehttp://docs.scipy.org/doc/numpyhttp://www.python.org/http://www.python.org/http://docs.scipy.org/doc/numpyhttp://wiki.fysik.dtu.dk/ase
8/19/2019 Atomic Simulation Enviornment
20/21
Thanks
Andrew Peterson, Anthony Goodrow, Ask Hjorth Larsen, CarstenRostgaard, Christian Glinsvad, David Landis, Elvar Örn Jónsson, EricHermes, Felix Hanke, Gaël Donval, George Tritsaris, Glen Jenness,Heine Anton Hansen, Ivano Eligio Castelli, Jakob Blomquist, JakobSchiøtz, Janne Blomqvist, Janosch Michael Rauba, Jens Jørgen
Mortensen, Jesper Friis, Jesper Kleis, Jess Wellendorff Pedersen,Jingzhe Chen, John Kitchin, Jon Bergmann Maronsson, Jonas Bjork,Jussi Enkovaara, Karsten Wedel Jacobsen, Kristen Kaasbjerg, KristianBaruel Ørnsø, Lars Grabow, Lars Pastewka, Lasse Vilhelmsen, MarcinDulak, Marco Vanin, Markus Kaukonen, Mattias Slabanja, Michael
Walter, Mikkel Strange, Poul Georg Moses, Rolf Würdemann, SteenLysgaard, Stephan Schenk, Tao Jiang, Thomas Olsen, TristanMaxson, Troels Kofoed Jacobsen, ...
Extra material
8/19/2019 Atomic Simulation Enviornment
21/21
Extra material
How to use sys.argv, other ASE functions, for-loops and string
interpolation:import sys
from ase.lattice.surface import fcc111
from gpaw import GPAW, PW
a = float(sys.argv[1])k = int(sys.argv[2])
for n in range(1, 5):
slab = fcc111(’Cu’, size=(1, 1, n),
a=a, vacuum=5.0)
slab.calc = GPAW(mode=PW(ecut=400),kpts=(k, k, 1),
txt=’Cu%d .txt’ % n)
slab.get_potential_energy()