Present of year 2023

I wish everyone a Merry Christmas and a Happy New Year!

As I present, let me share the discovery of this year.

Ferdium is a program that combines all messengers in a single window! I tried to distinguish between work and life using different messengers for years. For work, I used Unfortunately, they decided to close all freemium accounts and raise the prices this year. So, I switched to other messengers and eventually mixed them up. Luckily, I found Ferdium! Just see my print screen – all messengers in one app:

Go to to get it.

By the way, Opera provides a similar functionality, but it does not have so many app in it. For example, it does not have Element.

Type hinting in python

[a note for myself]

var: str='text'
from typing import Optional
def function(variable: str|float, number: int|float, variable: bool=False, a_kwarg: Optional[int]=None):
from typing import Tuple
def function() -> Tuble[str,str]:
    return 'Hello', 'World!'

Zotero + chatGPT via pdfGEAR

Some time ago (in 2023), I linked Zotero with chatGPT by creating an environment with paper-qa and pyzotero like this:
conda create -n Zotero
conda activate Zotero
conda install pip
pip install paper-qa
pip install pyzotero
pip install bs4

That worked but felt way too complicated … like I am not going to use it on a daily basis. It also reminded me the very first experience with the Meta AI in late 2022 (which everyone already forgot).

Here is a much simpler recipe:

  1. Install Zotero add-on from to enable opening with external pdf viewers.
  2. Install pdfGEAR as your default pdf viewer (external to Zotero).

See how it works on my YouTube channel:

Fonts for grant proposals

The reference font for the body text of European proposals is Times New Roman (Windows platforms), Times/Times New Roman (Apple platforms) or Nimbus Roman No. 9 L (Linux distributions). The Roman family is from a pre-digital age and has well-recognizable features.

Is it the best font in terms of readability? On the one hand, there is a tendency to move from Times-type fonts to plainer fonts, like Calibri. On the other hand, many studies (with controversial results) account for aspects like Dyslexia, typeface anatomy, and Display vs. Print. The effect of font choice on readability and compression on big numbers seems small or insignificant. However, my point is that a proposal must be clear to a few reviewers, who might have difficulties understanding the proposal due to age, Dyslexia, and colour vision deficiency. These few people will have some feelings about how the text is formatted. For that reason and also because of my artistic education in caligraphy, I have been looking for and playing with font combinations for a long time. Here is what I have tried and liked.

1. STIX two and Source Sans form a pair of Serif and Sans fonts. STIX two resulted from a collaborative effort from the most prominent academic publishing companies. Its predecessor (STIX one) has exactly the same metrics as Times New Roman. STIX two is somewhat bigger, which is not prohibited by the EU funding agencies. The main benefit of using STIX fonts is that these are mathematical fonts and, thus, can be natively used in MS Equation Editor (instead of Cambria) and LaTeX (as XITS or STIX2).

2. An excellent substitution for Times New Roman is Zilla Slab – a unique font by the Mozilla foundation – which has the same metrics as Times New Roman, is a Sans font, yet looks like a monospace one, does have features of a Dyslexia-friendly typeface, and looks great in print and on screen. It is freely available from Google fonts. It can be used with Times New Roman (or similar) as a pair of Serif and Sans fonts.

3. Libertinus Serif + Gill Sans is my favourite Serif and Sans pair. You can see Linux Libertine in the Wikipedia logo. Gill Sans Nova is commonly fond in the University of Tartu (Estonia) press. Although Libertinus Serif has an original Sans counterpart, its combination with Gill Sans looks most natural. I love Libertinus because of its amazingly looking ligatures, and it is also compatible with MS Equation Editor and LaTeX.

PS One can play with fonts in the EU projects to make their proposal more appealing. Like Estonian grants, I prefer calls, where applicants fill out online forms without changing the text appearance. Of course, the text looks ugly due to nasty line breaks, horrible chemical formulas and mathematical equations, and poor typography. Still, the competition is more fair because everyone is in the same conditions. 

PAW Setups & PseudoPotentials

GPAW has a large set of PAW setups (updated in 2016) for elements from H to Rn, excluding lanthanides, actinides, and radioactive elements. One can generate new setups with a PAW generating build-in tool and their own risk. One can use optimized norm-conserving Vanderbilt SG15 pseudopotentials (updated in 2017) or norm-conserving Hartwigsen-Goedecker-Hutter HGH pseudopotentials (see also GPAW intro) or even JTH pseudopotentials from ABINIT. There are even more setups, including f-elements, listed on the QE webpage. The great thing about these setups is that they use a similar format – either xml or upfApparently, GPAW can read both formats, although there is no relevant documentation. So, there are many ways to run calculations with elements that are missing in the GPAW default setups set. QuantumATK webpage provides an overview of pseudopotentials and even suggests mixing them. I hope that in the future, these and new PAWs will be gathered together like basis sets at the basis sets exchange portal.

P.S. Interesting and

DFT geometry optimizers

These are undeservedly less attention to optimizers than density functionals (concerning Jacob’s ladder). It is not even covered in the recent review: Best-Practice DFT Protocols for Basic Molecular Computational Chemistry. At the same time, in my current projects, the most resource-demanding was geometry optimization – the time spent on optimizing structures was much longer than a single-point calculation. Papers that introduce new (AI-based) optimizers promise significant speed-up. However, there are always some problems:

  1. The tested systems are different from my electrochemical interfaces.
  2. The code is not available or difficult to install.
  3. The code is outdated and contains bugs.
  4. Optimizers perform worse than the common ones, like QuasiNewton in ASE.

ASE wiki lists all internal and some external optimizers and provides their comparison. I have checked the most promising on a high-entropy alloy slab.

Observation 1. QuasiNewton outperforms all other optimizers. Point. I have run a standard GPAW/DFT/PBE/PW optimization with various optimizers:

Observation 2. Pre-optimizing the slab with a cheaper method does not reduce the number of optimization steps. I have preoptimized the geometry with TBLITE/DFTB/GFN1-xTB to continue with GPAW/DFT/PBE/PW. Preoptimization takes just some minutes and the obtained geometry looks similar to the DFT one but that does not reduce the number of DFT optimization steps.

OptimizerN steps*Time$N steps*#Total time#

Note * – the printed number of steps might different from the actuall number of calculations because each calculator has a different way of reporting that number.

Note $ – the time between the end of the first and last steps.

Note # – started from the TBLITE/DFTB/GFN1-xTB preoptimized geometry.

N.B! I have done my test only once in two runs: starting with and preoptized geometry. Runs were on similar nodes and all optimizations were done on the same node.

Conclusion. Do not believe in claims in articles advertizing new optimizers – Run your tests before using them.

A practical finding. The usual problem with calculations that require many optimization steps is that they need to fit into HPC time limits. On the restart, ASE usually rewrites the trajectory. Some optimizers (GPMin and AI-based) could benefit from reading the full trajectory. So, I started writing two trajectories and a restart file like this.

# Restarting
if os.path.exists(f'{name}_last.gpw') == True and os.stat(f'{name}_last.gpw').st_size > 0:
    atoms,calc = restart(f'{name}_last.gpw', txt=None)
    parprint(f'Restart from the gpw geometry.')
elif os.path.exists(f'{name}_full.traj') == True and os.stat(f'{name}_full.traj').st_size > 0:
    atoms = read(f'{name}_full.traj',-1)
    parprint(f'Restart with the traj geometry.')
    atoms = read(f'{name}')
    parprint(f'Start with the initial xyz geometry.')

# Optimizing
opt = QuasiNewton(atoms, trajectory=f'{name}.traj', logfile=f'{name}.log')
traj= Trajectory(f'{name}_full.traj', 'a', atoms)
opt.attach(traj.write, interval=1)
def writegpw():
opt.attach(writegpw, interval=1), steps=42)

Here are some details on the tests.

My for DFT calculations on 24 cores:

# Load modules
from ase import Atom, Atoms
from import add_adsorbate, fcc100, fcc110, fcc111, fcc211, molecule
from ase.calculators.mixing import SumCalculator
from ase.constraints import FixAtoms, FixedPlane, FixInternals
from import vdw_radii
from ase.db import connect
from import write, read
from ase.optimize import BFGS, GPMin, LBFGS, FIRE, QuasiNewton
from ase.parallel import parprint
from ase.units import Bohr
from bondmin import BondMin
from catlearn.optimize.mlmin import MLMin
from dftd4.ase import DFTD4
from gpaw import GPAW, PW, FermiDirac, PoissonSolver, Mixer, restart
from gpaw.dipole_correction import DipoleCorrection
from gpaw.external import ConstantElectricField
from gpaw.utilities import h2gpts
import numpy as np
import os

atoms = read('')
atoms.set_constraint([FixAtoms(indices=[atom.index for atom in atoms if atom.tag in [1,2]])])

# Set calculator
kwargs = dict(poissonsolver={'dipolelayer':'xy'},
              gpts=h2gpts(0.18, atoms.get_cell(), idiv=4),
calc = GPAW(**kwargs)

#atoms.calc = SumCalculator([DFTD4(method='RPBE'), calc])
#atoms.calc = calc

# Optimization paramters
maxf = 0.05

# Run optimization

# 2.A. Optimize structure using MLMin (CatLearn).
initial_mlmin = atoms.copy()
mlmin_opt = MLMin(initial_mlmin, trajectory='results_mlmin.traj'), kernel='SQE', full_output=True)

# 2.B Optimize using GPMin.
initial_gpmin = atoms.copy()
gpmin_opt = GPMin(initial_gpmin, trajectory='results_gpmin.traj', logfile='results_gpmin.log', update_hyperparams=True)

# 2.C Optimize using LBFGS.
initial_lbfgs = atoms.copy()
lbfgs_opt = LBFGS(initial_lbfgs, trajectory='results_lbfgs.traj', logfile='results_lbfgs.log')

# 2.D Optimize using FIRE.
initial_fire = atoms.copy()
fire_opt = FIRE(initial_fire, trajectory='results_fire.traj', logfile='results_fire.log')

# 2.E Optimize using QuasiNewton.
initial_qn = atoms.copy()
qn_opt = QuasiNewton(initial_qn, trajectory='results_qn.traj', logfile='results_qn.log')

# 2.F Optimize using BFGS.
initial_bfgs = atoms.copy()
bfgs_opt = LBFGS(initial_bfgs, trajectory='results_bfgs.traj', logfile='results_bfgs.log')

# 2.G. Optimize structure using BondMin.
initial_bondmin = atoms.copy()
bondmin_opt = BondMin(initial_bondmin, trajectory='results_bondmin.traj',logfile='results_bondmin.log')

# Summary of the results

fire_results = read('results_fire.traj', ':')
parprint('Number of function evaluations using FIRE:',

lbfgs_results = read('results_lbfgs.traj', ':')
parprint('Number of function evaluations using LBFGS:',

gpmin_results = read('results_gpmin.traj', ':')
parprint('Number of function evaluations using GPMin:',

bfgs_results = read('results_bfgs.traj', ':')
parprint('Number of function evaluations using BFGS:',

qn_results = read('results_qn.traj', ':')
parprint('Number of function evaluations using QN:',

catlearn_results = read('results_mlmin.traj', ':')
parprint('Number of function evaluations using MLMin:',

bondmin_results = read('results_bondmin.traj', ':')
parprint('Number of function evaluations using BondMin:',

Initial file:

Lattice="8.529357696932532 0.0 0.0 4.264678848466266 7.386640443507905 0.0 0.0 0.0 29.190908217261956" Properties=species:S:1:pos:R:3:tags:I:1 pbc="T T F"
Ir       0.00000000       1.62473838      10.00000000        5
Ru       2.81412943       1.62473838      10.00000000        5
Pt       5.62825885       1.62473838      10.00000000        5
Pd       1.40706471       4.06184595      10.00000000        5
Ag       4.22119414       4.06184595      10.00000000        5
Ag       7.03532356       4.06184595      10.00000000        5
Ag       2.81412943       6.49895353      10.00000000        5
Ru       5.62825885       6.49895353      10.00000000        5
Pt       8.44238828       6.49895353      10.00000000        5
Pt       0.00000000       0.00000000      12.29772705        4
Ag       2.81412943       0.00000000      12.29772705        4
Ru       5.62825885       0.00000000      12.29772705        4
Ru       1.40706471       2.43710757      12.29772705        4
Ir       4.22119414       2.43710757      12.29772705        4
Ag       7.03532356       2.43710757      12.29772705        4
Ag       2.81412943       4.87421514      12.29772705        4
Ir       5.62825885       4.87421514      12.29772705        4
Pd       8.44238828       4.87421514      12.29772705        4
Pd       1.40706471       0.81236919      14.59545411        3
Ir       4.22119414       0.81236919      14.59545411        3
Pt       7.03532356       0.81236919      14.59545411        3
Ag       2.81412943       3.24947676      14.59545411        3
Ir       5.62825885       3.24947676      14.59545411        3
Ir       8.44238828       3.24947676      14.59545411        3
Pd       4.22119414       5.68658433      14.59545411        3
Pt       7.03532356       5.68658433      14.59545411        3
Ag       9.84945299       5.68658433      14.59545411        3
Pd       0.00000000       1.62473838      16.89318116        2
Pd       2.81412943       1.62473838      16.89318116        2
Ag       5.62825885       1.62473838      16.89318116        2
Pt       1.40706471       4.06184595      16.89318116        2
Ag       4.22119414       4.06184595      16.89318116        2
Ag       7.03532356       4.06184595      16.89318116        2
Ru       2.81412943       6.49895353      16.89318116        2
Ru       5.62825885       6.49895353      16.89318116        2
Ru       8.44238828       6.49895353      16.89318116        2
Ir       0.00000000       0.00000000      19.19090822        1
Ag       2.81412943       0.00000000      19.19090822        1
Pt       5.62825885       0.00000000      19.19090822        1
Pd       1.40706471       2.43710757      19.19090822        1
Ag       4.22119414       2.43710757      19.19090822        1
Pd       7.03532356       2.43710757      19.19090822        1
Ag       2.81412943       4.87421514      19.19090822        1
Ru       5.62825885       4.87421514      19.19090822        1
Ir       8.44238828       4.87421514      19.19090822        1

My for DFTB calcualation with just one core. It takes some minutes but eventually crashes 🙁

# Load modules
from ase import Atom, Atoms
from import add_adsorbate, fcc100, fcc110, fcc111, fcc211, molecule
from ase.calculators.mixing import SumCalculator
from ase.constraints import FixAtoms, FixedPlane, FixInternals
from import vdw_radii
from ase.db import connect
from import write, read
from ase.optimize import BFGS, GPMin, LBFGS, FIRE, QuasiNewton
from ase.parallel import parprint
from ase.units import Bohr
from tblite.ase import TBLite
import numpy as np
import os


atoms = read('')
atoms.set_constraint([FixAtoms(indices=[atom.index for atom in atoms if atom.tag in [1,2]])])

# Set calculator
calc = TBLite(method="GFN1-xTB",accuracy=1000,electronic_temperature=300,max_iterations=300)
qn_opt = QuasiNewton(atoms, trajectory='results_qn.traj', logfile='results_qn.log', maxstep=0.1)

To compare structures I have used MDanalysis, which unfortunately does not work with ASE traj, so I prepared xyz-files with “ase convert -n -1 file.traj”

import MDAnalysis as mda
from MDAnalysis.analysis.rms import rmsd
import sys

def coord(file_name):
    file  = mda.Universe(f"{file_name}.xyz")
    atoms = file.select_atoms("index 1:9")
    return  atoms.positions.copy()


An instruction on installation of GPAW. TBLITE can be installed as “conda install -c conda-forge tblite”.

GPAW installation with pip

Between installation with conda and compilation of libraries, an intermediate path – installation of GPAW with pip – is a compromise for those who wish to text specific GPAW branches or packages.

For example, I wish to text self-interaction error correction (SIC) and evaluate Bader charges with pybader. Neither SIC nor pybader is compatible with the recent GPAW. Here is not to get a workable version.

# numba in pybader is not compatible with python 3.11, so create a conda environment with python 3.10
conda create -n gpaw-pip python=3.10 
conda activate gpaw-pip

conda install -c conda-forge libxc libvdwxc
conda install -c conda-forge ase
# ensure that you install the right openmpi (not external)
conda install -c conda-forge openmpi ucx
conda install -c conda-forge compilers
conda install -c conda-forge openblas scalapack
conda install -c conda-forge pytest
pip install pybader

# Get a developer version of GPAW with SIC
git clone -b dm_sic_mom_update
cd gpaw

# In the rewrite
fftw = True
scalapack = True
if scalapack:
    libraries += ['scalapack']

unset CC
python -m pip install -e .
gpaw info

Some pictures on preparing my MSCA proposal

While preparing the final report on the past MSCA project, I found some memorable pictures. Here me, my wife and nephew are building a LEGO illustration for the project proposal. Yes, we had some fun while I was thinking about the concept.

The results looks pretty.

Still, as the concept illustration, I draw this figure. Today, I have reused it for the report illustration.

k-points with kplib and gpaw

Choosing optimal k-points is a tricky task. In GPAW, one can set them manually, using size or density and following a rule of thumb:

calc = GPAW(kpts={'size': (4, 4, 4), 'gamma': True})
# or
calc = GPAW(kpts={'density': 2.5, 'gamma': True})

A rule of thumb for choosing the initial k-point sampling is, that the product, ka, between the number of k-points, k, in any direction, and the length of the basis vector in this direction, a, should be:

  • ka ~ 30 Å, for d band metals
  • ka ~ 25 Å, for simple metals
  • ka ~ 20 Å, for semiconductors
  • ka ~ 15 Å, for insulators

Remember that convergence in this parameter should always be checked.

The corresponding densities (ka/2π) are:

  • ka/2π ~ 4.8 Å, for d band metals
  • ka/2π ~ 4.0 Å, for simple metals
  • ka/2π ~ 3.2 Å, for semiconductors
  • ka/2π ~ 2.4 Å, for insulators

With the recent update, I can start using kplib (see paper) to choose the optimal generalized k-point grids. The main variable in kplib is min_distance, which is analogous to the density×2π. Read more about the min_distance at

Here is an example of my conda environment

conda create -n gpaw23 python=3.9
conda activate gpaw23
conda install -c conda-forge cxx-compiler
pip install kplib # from
conda install -c conda-forge gpaw

Here is a working example:

from ase import Atoms
from ase.parallel import parprint
from gpaw import GPAW, PW
from kpLib import get_kpoints
from import AseAtomsAdaptor

atoms = Atoms(cell=[[1.608145, -2.785389, 0.0], [1.608145, 2.785389, 0.0], [0.0, 0.0, 5.239962]],
              symbols=['Ga', 'Ga', 'N', 'N'],
              positions=[[ 1.608145  , -0.92846486,  2.61536983],
                         [ 1.608145  ,  0.92846486,  5.23535083],
                         [ 1.608145  , -0.92846486,  4.58957792],
                         [ 1.608145  ,  0.92846486,  1.96959692]],
structure = AseAtomsAdaptor.get_structure(atoms)
kpts_data = get_kpoints(structure, minDistance=30, include_gamma=False)
parprint("Found lattice with kplib: ")
parprint(f"Nominal kpts: {kpts_data['num_total_kpts']}")
parprint(f"Distinct kpts: {kpts_data['num_distinct_kpts']}")

atoms.calc = GPAW(xc='PBE',
                  symmetry={'point_group': True,
                            'time_reversal': True,
                            'symmorphic': False,
                            'tolerance': 1e-4},
energy = atoms.get_total_energy()

parprint(f"Total energy: {energy}")
parprint(f"kpts passed to GPAW: {len(atoms.calc.get_bz_k_points())}")
parprint(f"kpts in GPAW IBZ: {len(atoms.calc.get_ibz_k_points())}")

Memory issues in GPAW

Try to use default parameters for the calculator. Simple and often useful.

Below you find a list of suggestions that should be considered when encountering a memory problem – when a calculation does not fit an allocated memory limit.

Note1: You can use –dry-run to make memory estimation and check for parallelization over kpts, domain, and bands as well as use of symmetry.

gpaw python --dry-run=N

Mind that the memory estimation with –dry-run is underestimated.

Note2: You can use def monkey_patch_timer() to write information about memory usage into mem.* files. Call the function before the actual work is started.

from gpaw.utilities.memory import monkey_patch_timer



  1. Try increasing the total memory or memory per tasks in the submission script, if you are sure that everything else (see below) is correct.
  2. Try increasing number of tasks (CPUs×threading) and nodes, if only you are sure that everything else (see below) is correct. Note that your calculation accesses all the nodes’ memory independent on the number of allocated tasks, but not not all memory is actually available because some is used by the OS and other running jobs. Also, increasing the number of tasks decreases parallelization efficiency and might decrease the queue priority (depending on the queuing system).


  1. Check the model geometry. Perhaps, you can make a more compact model. For example, with orthorhombic=False option.
  2. In slab calculations, use just enough vacuum. Mind that PW mode is egg-box effect free, so, with the dipole-layer correction, you can reduce the vacuum layer significantly. Just check for the energy convergence.
  3. Ensure that symmetry is used. Sometimes, the calculator uses less symmetry than there is. In that case, recheck the geometry. Remember that you can preserve symmetry during optimization.


In general, parallelization over domains requires less memory than parallelization over bands and k-points, but the default order of parallelization is k-points, then domains, then bands. Remember the formula kpts×domain×bands = N, where N is the number of tasks (CPUs).

  1. In most cases, the default parallelization with symmetry is most efficient in terms of memory usage.
  2. Reprioritizing parallelization over domain can reduce memory consumption, but also slow down the calculation as parallelization over k-points is usually more time-efficient.
  3. Parallelization over any type can be suppressed by setting, for example, for domains like parallel = {'domain':1}. In the LCAO mode, you should check whether parallelizing over bands, like parallel = {'bands':2}, helps with the memory issue.


  1. Consider using a different mode. “With LCAO, you have fewer degrees of freedom, so memory usage is low. PW mode uses more memory and FD a lot more.”
  2. Change calculation parameters, like h, cutoff, setups (like setups={'Pt': '10'}), basis (like basis={'H': 'sz', 'C': 'dz'}), etc. Check for convergence of properties, like in this tutorial:
  3. It is possible to reduce the memory by changing the mixer options.