Introduction to atomman: pymatgen conversions

Lucas M. Hale, lucas.hale@nist.gov, Materials Science and Engineering Division, NIST.

Disclaimers

1. Introduction

The pymatgen Python package is an alternative Python representation of atomic configurations that is used by the Materials Project. Atomman provides direct conversions between atomman.System objects and pymatgen.Structure objects to allow users to easily access the features of the different packages.

NOTE: Requires that pymatgen be installed.

Library Imports

[1]:
# Standard Python libraries
import datetime

# http://www.numpy.org/
import numpy as np

import atomman as am
import atomman.unitconvert as uc

# Show atomman version
print('atomman version =', am.__version__)

# Show date of Notebook execution
print('Notebook executed on', datetime.date.today())
atomman version = 1.4.10
Notebook executed on 2023-07-28

Generate test system information (CsCl)

[2]:
# Generate box
alat = uc.set_in_units(3.2, 'angstrom')
box = am.Box(a=alat, b=alat, c=alat)

# Generate atoms with atype, pos, charge, and stress properties
atype = [1, 2]
pos = [[0,0,0], [0.5, 0.5, 0.5]]
charge = uc.set_in_units([1, -1], 'e')
stress = uc.set_in_units(np.zeros((2, 3, 3)), 'MPa')
atoms = am.Atoms(pos=pos, atype=atype, charge=charge, stress=stress)

# Build system from box and atoms, and scale atoms
system = am.System(atoms=atoms, box=box, scale=True, symbols=['Cs', 'Cl'])

# Print system information
print(system)
system.atoms_df()
avect =  [ 3.200,  0.000,  0.000]
bvect =  [ 0.000,  3.200,  0.000]
cvect =  [ 0.000,  0.000,  3.200]
origin = [ 0.000,  0.000,  0.000]
natoms = 2
natypes = 2
symbols = ('Cs', 'Cl')
pbc = [ True  True  True]
per-atom properties = ['atype', 'pos', 'charge', 'stress']
     id   atype  pos[0]  pos[1]  pos[2]
      0       1   0.000   0.000   0.000
      1       2   1.600   1.600   1.600
[2]:
atype pos[0] pos[1] pos[2] charge stress[0][0] stress[0][1] stress[0][2] stress[1][0] stress[1][1] stress[1][2] stress[2][0] stress[2][1] stress[2][2]
0 1 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 2 1.6 1.6 1.6 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

2. System.dump(‘pymatgen_Structure’)

Caution: pymatgen.Structure objects always assume all three box directions to be periodic.

Parameters

  • symbols (list) List of the element symbols that correspond to the atom types. If not given, will use system.symbols if set, otherwise no element content will be included.

Returns

  • structure (pymatgen.Structure) A pymatgen representation of a structure.

[3]:
structure = system.dump('pymatgen_Structure')

print(structure)
Full Formula (Cs1 Cl1)
Reduced Formula: CsCl
abc   :   3.200000   3.200000   3.200000
angles:  90.000000  90.000000  90.000000
pbc   :       True       True       True
Sites (2)
  #  SP      a    b    c    charge  stress
---  ----  ---  ---  ---  --------  ------------
  0  Cs    0    0    0           1  [[0. 0. 0.]
                                     [0. 0. 0.]
                                     [0. 0. 0.]]
  1  Cl    0.5  0.5  0.5        -1  [[0. 0. 0.]
                                     [0. 0. 0.]
                                     [0. 0. 0.]]

3. atomman.load(‘pymatgen_Structure’)

Caution: pymatgen.Structure objects always assume all three box directions to be periodic.

Parameters

  • structure (pymatgen.Structure) A pymatgen representation of a structure.

  • symbols (tuple, optional) Allows the list of element symbols to be assigned during loading. Useful if the symbols for the model differ from the standard element tags.

Returns

  • system (atomman.System) A atomman representation of a system.

[4]:
system = am.load('pymatgen_Structure', structure)

print(system)
system.atoms_df()
avect =  [ 3.200,  0.000,  0.000]
bvect =  [ 0.000,  3.200,  0.000]
cvect =  [ 0.000,  0.000,  3.200]
origin = [ 0.000,  0.000,  0.000]
natoms = 2
natypes = 2
symbols = ('Cl', 'Cs')
pbc = [ True  True  True]
per-atom properties = ['atype', 'pos', 'charge', 'stress']
     id   atype  pos[0]  pos[1]  pos[2]
      0       2   0.000   0.000   0.000
      1       1   1.600   1.600   1.600
[4]:
atype pos[0] pos[1] pos[2] charge stress[0][0] stress[0][1] stress[0][2] stress[1][0] stress[1][1] stress[1][2] stress[2][0] stress[2][1] stress[2][2]
0 2 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 1 1.6 1.6 1.6 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0