Installing GPAW with conda

[Updated on 14.09.2022]

In short, in a clean environment, everything should work with just five lines:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Initialize conda. If it is in the .bashch, source it. If not, source “PATHTOCONDA/miniconda3/etc/profile.d/conda.sh”.

conda create --name gpaw python=3
conda activate gpaw
conda install -c conda-forge gpaw=22.8=*openmpi*

For details, see the description below.

1. Install conda – software and environment management system.

Here is the official instruction: docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html

On August 2022, run these:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

If you wish to autostart conda, allow it to write to your .bashrc.

P.S. Here are good intros to conda:

2. Create a conda virtual environment:

conda create --name gpaw python=3.10

If needed, remove the environment as:

conda remove --name gpaw --all

You can check the available environments as:

conda env list

3. Activate the virtual environment.

conda activate gpaw

4. Install gpaw:

Ensure that no interfering modules and environments are loaded.

Purge modules by executing:

module purge

To check whether some code (like mpirun) has an alternative path, try:

which codename

or

codename --version

There should be no mpirun, ase, libxc, numpy, scipy, etc. Otherwise, the installation with conda will most probably fail due to conflicting paths.

4.1. It is safer to install using gpaw*.yml file from vliv/conda directory on FEND:

conda env create -f gpaw.yml

Note that there are many yml files with different versions of GPAW.

4.2. Pure installation is simple, but might not work:

conda install -c conda-forge gpaw=*=*openmpi*

Recently, there were problems with openmpi. Try downgrading it to version 4.1.2:

conda install -c conda-forge openmpi=4.1.2

You might with to install ucx but be aware that there are many problems with it; e. g. depending on mlx version:

conda install -c conda-forge ucx

If you get an error about GLIBCXX, try upgrading gcc:

conda install -c conda-forge gcc=12.1.0

4.3. To make a quick check of the installation, run “gpaw -P 2 test” or “gpaw info”.

The installation might fail. In case you succeed, save the yml file as:

conda env export | grep -v "^prefix: " > gpaw.yml

Now you can use it to install gpaw as:

conda env create -f gpaw.yml

To properly test the installation install pytest and follow wiki.fysik.dtu.dk/gpaw/devel/testing.html. That might take hours.

conda install -c conda-forge pytest pytest-xdist 

5. If needed, install extra packages within your specific conda environment (gpaw).

To apply D4 dispersion correction:

conda install -c conda-forge dftd4 dftd4-python

To analyze trajectories:

conda install -c conda-forge mdanalysis

To analyze electronic density (some might not work):

pip install git+https://github.com/funkymunkycool/Cube-Toolz.git
pip install git+https://github.com/theochem/grid.git
pip install git+https://github.com/theochem/denspart.git
pip install pybader
pip install cpmd-cube-tools
conda install -c conda-forge chargemol

To use catlearn:

pip install catlearn

To work with crystal symmetries:

conda install -c conda-forge spglib

Extra for visualization (matplotlib comes with ASE):

conda install -c conda-forge pandas seaborn bokeh

To use notebooks (you might need to install firefox as well):

conda install -c conda-forge jupyterlab nodejs jupyter_contrib_nbextensions 

6. Run calculations by adding these lines to the submission script:

Note1: Check the path and change the USERNAME

Note2: Turn off ucx.

Note3: You may play with the number of openmp threads.

module purge
source "/groups/kemi/USERNAME/miniconda3/etc/profile.d/conda.sh"
conda activate gpaw
export OMP_NUM_THREADS=1
export OMPI_MCA_pml="^ucx"
export OMPI_MCA_osc="^ucx"
mpirun gpaw python script.py

Note4: Check an example in vliv/conda/sub directory.

7. Speeding-up calculations.

Add the “parallel” keyword to GPAW calculator:

parallel = {'augment_grids':True,'sl_auto':True},

For more options see wiki.fysik.dtu.dk/gpaw/documentation/parallel_runs/parallel_runs.html#manual-parallel. For LCAO mode, try ELPA. See wiki.fysik.dtu.dk/gpaw/documentation/lcao/lcao.html#notes-on-performance.

parallel = {'augment_grids':True,'sl_auto':True,'use_elpa':True},

For calculations with vdW-functionals, use libvdwxc:

xc = {'name':'BEEF-vdW', 'backend':'libvdwxc'},

8. If needed, add fixes.

To do Bayesian error estimation (BEE) see doublelayer.eu/vilab/2022/03/30/bayesian-error-estimation-for-rpbe/.

To use MLMin/NEB apply corrections from github.com/SUNCAT-Center/CatLearn/pulls

9. Something worth trying:

Atomic Simulation Recipes:

asr.readthedocs.io/en/latest/

gpaw-tools:

github.com/lrgresearch/gpaw-tools/

www.sciencedirect.com/science/article/pii/S0927025622000155

ase-notebook (won’t install at FEND because of glibc 2.17):

github.com/chrisjsewell/ase-notebook

ase-notebook.readthedocs.io/en/latest/

gpaw benchmarking:

github.com/OleHolmNielsen/GPAW-benchmark-2021

github.com/mlouhivu/gpaw-benchmarks

members.cecam.org/storage/presentation/Ask_Hjorth_Larsen-1622631504.pdf

Bayesian Error Estimation for RPBE

Here is a trick for making the Bayesian Error Estimation (BEE) with the RPBE functional. Just edit the lines in ASE and GPAW codes by adding RPBE as an exception.

To find the needed files, run

find ./ -name "bee.py"

In ase/dft/bee.py change one line:

class BEEFEnsemble:



            if self.xc in ['BEEF-vdW', 'BEEF', 'PBE', 'RPBE']: # add RPBE
                self.beef_type = 'beefvdw'

In gpaw/xc/bee.py add two lines:

class BEEFEnsemble:
    """BEEF ensemble error estimation."""
    def __init__(self, calc):



        # determine functional and read parameters
        self.xc = self.calc.get_xc_functional()
        if self.xc == 'BEEF-vdW':
            self.bee_type = 1
        elif self.xc == 'RPBE': # catch the RPBE exchange functional
            self.bee_type = 1   # assign BEEF coefficients the RBPE

Below we use BEEF-vdW, RPBE, and PBE dimensionless density (n) with gradient (s) and apply BEEF coefficients (E₀, ΔEᵢ) to evaluate the BEE as the standard deviation for the ensemble total energies with the variable enhancement factor (F(s,θᵢ)).


from ase import Atoms
from ase.dft.bee import BEEFEnsemble
from ase.parallel import parprint
from gpaw import GPAW
import time

for xc in ['BEEF-vdW','RPBE','PBE']:
    start_time = time.time()

    h2 = Atoms('H2',[[0.,0.,0.],[0.,0.,0.741]]) #exp. bond length
    h2.center(vacuum=3)
    cell = h2.get_cell()

    calc = GPAW(xc=xc,txt='H2_{0}.txt'.format(xc))
    h2.calc = calc
    e_h2 = h2.get_potential_energy()
    ens = BEEFEnsemble(calc)
    de_h2 = ens.get_ensemble_energies()
    del h2, calc, ens

    h = Atoms('H')
    h.set_cell(cell)
    h.center()
    calc = GPAW(xc=xc,txt='H_{0}.txt'.format(xc), hund=True)
    h.calc = calc
    e_h = h.get_potential_energy()
    ens = BEEFEnsemble(calc)
    de_h = ens.get_ensemble_energies()
    del h, calc, ens

    E_bind = 2*e_h - e_h2
    dE_bind = 2*de_h[:] - de_h2[:]
    dE_bind = dE_bind.std()
    
    parpting('{0} functional'.format(xc))
    parprint('Time: {0} s'.format(round(time.time()-start_time,0)))
    parprint('E_bind: {0} eV'.format(round(E_bind,4)))
    parprint('Error bar {0} eV'.format(round(dE_bind,4)))

TS09 and D4 corrections with ASE

TS09 and D4 are atomic-charge dependent dispersion corrections (see TS09 PRL paper and D4 homepage for the refs). The D4 code is available at github. According to GPAW documentation, TS09 and D4 show for the S26 test set smaller mean deviation than vdW-DF. Herewith, D4 correction does not depend on the actual calculation as it is added to the calculated energy.

Here is how D4 correction can be added with ASE (see Readme):

from ase.build import molecule 
from ase.calculators.mixing import SumCalculator 
from ase.optimize import BFGS
from dftd4.ase import DFTD4 
from gpaw import GPAW 

atoms = molecule('H2O') 
atoms.center(vacuum=4)

gpaw = GPAW(txt='H2O.txt',xc='PBE') 
atoms.calc = SumCalculator([DFTD4(method='PBE'), gpaw])

#atoms.get_potential_energy()

opt = BFGS(atoms)
opt.run(fmax=0.05)

Let me stress that before choosing TS09 or D4 one should consider all pro and contra. TS09 method used Hirshfeld charges while D4 uses the electronegativity equilibration method to obtain charges. The former naturally accounts for the interfacial charge transfer while the latter does not. TS09 requires vdW radii and is implemented for a limited set on functionals (see ASE code), like PBE, RPBE, and BLYP. D4 supports much more functionals (see parameters). Regarding the vdW radii values for TS09 bare in mind that there are four sources – one in GPAW, two in ASE and one more in ASE.

Here is how TS09 correction can be added with ASE and GPAW:

from ase.build import molecule
from ase.calculators.vdwcorrection import vdWTkatchenko09prl
from ase.data.vdw_alvarez import vdw_radii
from ase.optimize import BFGS
from gpaw.analyse.hirshfeld import HirshfeldPartitioning
from gpaw.analyse.vdwradii import vdWradii
from gpaw import GPAW

atoms = molecule('H2O')
atoms.center(vacuum=4)

gpaw = GPAW(txt='H2O.txt',xc='PBE')
atoms.calc = vdWTkatchenko09prl(HirshfeldPartitioning(gpaw), vdWradii(atoms.get_chemical_symbols(), 'PBE'))

#atoms.get_potential_energy()
opt = BFGS(atoms)
opt.run(fmax=0.05)

P.S. Note that the TS09 and D4 energies are no outputted to the H2O.txt.

Synchronizing calendars

This post describes ways of pushing MS outlook and Google calendars to Nextcloud.

My main working calendar is the Nextcloud app because I can easily sync it is my Sailfish phone. I also use Google calendar (for sharing family events) and MS outlook calendar (for work). Today I decided to merge all these calendars into a single one that I can sync on all my devices. Here is how.

MS to Nextcloud

Use outlookcaldavsynchronizer as recommended in the Nextcloud blog.

Google to Nextcould

  • Get the iCal link from Google Calendar as follows:
  • In the left calendar list menu of Google Calendar, go to the ⋮ menu of the calendar to be shared
  • Click on “Settings and sharing”
  • On the Calendar settings page, scroll down to “Secret address in iCal format”
  • In Nextcloud Calendar’s left menu, click on “+New Calendar” > “New subscription from link (read-only)”
  • Insert the “Secret address in iCal format”
  • Your new calendar subscription will appear in the list; you can change its name or color in the menu of your calendar

Bader and Hirshfeld charges with python

Bader analysis is a fast and simple way of getting atomic charges. It is especially useful for periodic calculations. The analysis can be done on the fly using pybader tool from pypi.org/project/pybader. I recommend using it within conda environments.

The installation is straightforward:

pip install pybader

The usage is less obvious. Here is a function for obtaining xmol-type xyz that can obtained with GPAW and visualized with ASE:


def xyzb(atoms, filename, nCPU):
  from pybader.io import gpaw
  from pybader.interface import Bader
  import os
  bader = Bader(*gpaw.read_obj(atoms.calc)) # read ASE object 'atoms'
  bader(threads=nCPU)                       # specify the number of CPUs
  f = open('{0}.xyz'.format(filename), 'w') # set xmol format
  b = bader.atoms_charge                    # get number of electrons per atom
  n = atoms.get_atomic_numbers()            # get atomic numbers
  a = atoms.get_chemical_symbols()          # get chemical symbols
  p = atoms.get_positions()                 # get positions of the atoms
  f.write('{0}\n'.format(len(a)))
  f.write('Properties=species:S:1:pos:R:3:charge:R:1\n') # ensure compatibility with ASE
  for i in range(len(a)):                   # print symbol, positions, and charge
    s = '{0}'.format(a[i])
    x = '{0:.6f}'.format(round(p[i][0],6))
    y = '{0:.6f}'.format(round(p[i][1],6))
    z = '{0:.6f}'.format(round(p[i][2],6))
    c = '{0:.3f}'.format(round(float(n[i]) - float(b[i]),3))
    f.write('{0:<4}{1:>16}{2:>16}{3:>16}{4:>10}\n'.format(s,x,y,z,c))
  f.close()
  del bader
  os.remove('bader.p')

Similarly one can obtain xmol-type xyz file with Hirshfeld charges:


def xyzh(atoms, filename):
  from gpaw.analyse.hirshfeld import HirshfeldPartitioning
  f = open('{0}.xyz'.format(filename), 'w') # set xmol format
  a = atoms.get_chemical_symbols()          # get chemical symbols
  p = atoms.get_positions()                 # get positions of the atoms
  h = HirshfeldPartitioning(atoms.calc).get_charges()
  f.write('{0}\n'.format(len(a)))
  f.write('Properties=species:S:1:pos:R:3:charge:R:1\n') # ensure compatibility with ASE
  for i in range(len(a)):                   # print symbol, positions, and charge
    s = '{0}'.format(a[i])
    x = '{0:.6f}'.format(round(p[i][0],6))
    y = '{0:.6f}'.format(round(p[i][1],6))
    z = '{0:.6f}'.format(round(p[i][2],6))
    c = '{0:.3f}'.format(round(h[i],3))
    f.write('{0:<4}{1:>16}{2:>16}{3:>16}{4:>10}\n'.format(s,x,y,z,c))
  f.close()

In the LCAO mode of GPAW one can also get the Mulliken charges. Test before using:


def xyzm(atoms, filename):
  from gpaw.lcao.tools import get_mulliken
  f = open('{0}.xyz'.format(filename), 'w') # set xmol format
  a = atoms.get_chemical_symbols()          # get chemical symbols
  p = atoms.get_positions()                 # get positions of the atoms
  m = get_mulliken(atoms.calc, range(len(a)))
  f.write('{0}\n'.format(len(a)))
  f.write('Properties=species:S:1:pos:R:3:charge:R:1\n') # ensure compatibility with ASE
  for i in range(len(a)):                   # print symbol, positions, and charge
    s = '{0}'.format(a[i])
    x = '{0:.6f}'.format(round(p[i][0],6))
    y = '{0:.6f}'.format(round(p[i][1],6))
    z = '{0:.6f}'.format(round(p[i][2],6))
    c = '{0:.3f}'.format(round(m[i],3))
    f.write('{0:<4}{1:>16}{2:>16}{3:>16}{4:>10}\n'.format(s,x,y,z,c))
  f.close()

“Resurrections”

I have not been writing to the blog for approximately 2.5 years. That period overlaps with the birth of my second child, pandemic, and absence of research funding – all the reasons for prioritizing family and grant writing above the blog writing. At the moment, there are no barriers to blogging, as I have the MSCA fellowship, some vaccine protection, and my adapted to a nursery.

I am now returning to that blog for several reasons. First, it is the right place for summarising research activity. Foremost for myself and close colleagues. Second, I feel the need to communicate science-related thoughts and emotions, especially in changing the working environment (from Tartu Univ. to Copenhagen Univ.). So, I am back!

ILMAT5 presentation

LINK to the PRESENTATION

Abstract

In this work [0], we have applied the DFT-based delta Kohn–Sham (ΔKS) method to ion pairs in a vacuum to obtain X-ray pho­toelectron spectra of corresponding ionic liquids (IL). On the example of forty ion pairs, we demonstrate how the core level binding energy (BE) values can be calcu­lated and used to plot theo­retical spectra at a low computational cost. Furthermore, we compare the ΔKS results, 1s Kohn–Sham orbital energies, and atomic charges against the experi­mental X-ray photoelec­tron data. Recently, in connection to the electro­chemical application in the super­capacitors, we have measured spectra for EMImBF4 and EMImB(CN)4 ionic liquids at the carbon–IL interface [1–3]. Other experimental spectra were obtained from the literature [4,5]. Both the ΔKS BE values and the 1s Kohn–Sham orbital energies show a correlation, yet with a different order of the BEs assigned to spe­cific atoms. We find that neither DDEC6 nor Bader charges cor­relate with the experi­mental data. Thus, the DFT calculations of 1s Kohn–Sham orbital energies provide the fastest way of pre­dicting the XPS spectra. However, more detailed experimental studies are required to resolve the right order of the BE values and its rela­tion to the atomistic structure of the ILs. The ΔKS calculations provide the most precise estimations of the BEs. Herewith, they also demand more resources and cause computa­tional difficulties discussed in the presenta­tion. Besides the prediction power, a robust computational method can help in intepre­tating experimental data when the appropriate reference values are either not available nor directly applicable. Thus, the ΔKS method can find its application in various fields of physics and chemistry where the XPS is used for re­solving electronic and geometric structures of pure ILs, their mixtures, and at interfaces.

In this work, we have applied the DFT-based delta Kohn–Sham (ΔKS) method to ion pairs in a vacuum to obtain X-ray pho­toelectron spectra of corresponding ionic liquids (IL). On the example of forty ion pairs, we demonstrate how the core level binding energy (BE) values can be calcu­lated and used to plot theo­retical spectra at a low computational cost. Furthermore, we compare the ΔKS results, 1s Kohn–Sham orbital energies, and atomic charges against the experi­mental X-ray photoelec­tron data. Recently, in connection to the electro­chemical application in the super­capacitors, we have measured spectra for EMImBF4 and EMImB(CN)4 ionic liquids at the carbon–IL interface [1–3]. Other experimental spectra were obtained from the literature [4,5]. Both the ΔKS BE values and the 1s Kohn–Sham orbital energies show a correlation, yet with a different order of the BEs assigned to spe­cific atoms. We find that neither DDEC6 nor Bader charges cor­relate with the experi­mental data. Thus, the DFT calculations of 1s Kohn–Sham orbital energies provide the fastest way of pre­dicting the XPS spectra. However, more detailed experimental studies are required to resolve the right order of the BE values and its rela­tion to the atomistic structure of the ILs. The ΔKS calculations provide the most precise estimations of the BEs. Herewith, they also demand more resources and cause computa­tional difficulties discussed in the presenta­tion. Besides the prediction power, a robust computational method can help in intepre­tating experimental data when the appropriate reference values are either not available nor directly applicable. Thus, the ΔKS method can find its application in various fields of physics and chemistry where the XPS is used for re­solving electronic and geometric structures of pure ILs, their mixtures, and at interfaces.

[0] M. Lembinen, E. Nõmmiste, H. Ers, B. Docampo‐Álvarez, J. Kruusma, E. Lust, V.B. Ivaništšev, Calculation of core‐level electron spectra of ionic liquids, Int. J. Quantum Chem. 120 (2020). https://doi.org/10.1002/qua.26247.

[1] J. Kruusma, A. Tõnisoo, R. Pärna, E. Nõmmiste, I. Tallo, T. Romann, E. Lust, Electrochimica Acta 206 (2016) 419–426.

[2] J. Kruusma, A. Tõnisoo, R. Pärna, E. Nõmmiste, I. Kuusik, M. Vahtrus, I. Tallo, T. Romann, E. Lust, J. Electrochem. Soc. 164 (2017) A3393–A3402.

[3] A. Tõnisoo, J. Kruusma, R. Pärna, A. Kikas, M. Hirsimäki, E. Nõmmiste, E. Lust, J. Electrochem. Soc. 160 (2013) A1084–A1093.

[4] A. Foelske-Schmitz, D. Weingarth, R. Kötz, Surf. Sci. 605 (2011) 1979–1985.

[5] I.J. Villar-Garcia, E.F. Smith, A.W. Taylor, F. Qiu, K.R.J. Lovelock, R.G. Jones, P. Licence, Phys. Chem. Chem. Phys. 13 (2011) 2797–2808.

Oriental fonts in Ubuntu

!/bin/bash

for i in fonts-kacst fonts-kacst-one fonts-khmeros-core fonts-lklug-sinhala fonts-guru fonts-nanum fonts-noto-cjk fonts-takao-pgothic fonts-tibetan-machine fonts-guru-extra fonts-lao fonts-sil-padauk fonts-sil-abyssinica fonts-tlwg-* fonts-lohit-* fonts-beng fonts-beng-extra fonts-gargi fonts-gubbi fonts-gujr fonts-gujr-extra fonts-kalapi fonts-lohit-gujr fonts-samyak-* fonts-noto-unhinted fonts-noto-hinted fonts-navilu fonts-nakula fonts-orya-extra fonts-pagul fonts-sahadeva fonts-sarai fonts-smc fonts-telu-extra fonts-wqy-microhei; do
sudo apt purge -y $i
echo
done

echo “==== Fixing font cache”
sudo fc-cache -f -v && sudo dpkg-reconfigure fontconfig

echo “==== Packages remained (each containing multiple fonts)”
dpkg -l fonts*|grep ^ii|awk ‘{print $2}’

echo
read -p “Press any key to close.”