• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimalistic atomic Density Functional Theory (DFT) code

Tiny DFT

Tiny DFT is a minimalistic atomic Density Functional Theory (DFT) code, mainly for educational purposes. It only supports spherically symmetric atoms and local exchange-correlation functionals (at the moment only Dirac exchange).

The code is designed with the following criteria in mind:

  • It depends only on established scientific Python libraries: numpy, scipy, matplotlib and (the lesser known) autograd. The latter is a library for algorithmic differentiation, used to computed the analytic exchange(-correlation) potential and the grid transformation.

  • The numerical integration and differentiation algorithms should be precise enough to at least 6 significant digits for the total energy, but in many cases the numerical precision is better. Some integrals over Gaussian basis functions are computed analytically. The pseudo-spectral method with Legendre polynomials is used for the Poisson solver.

  • The total number of lines should be minimal and the source-code should be easy to understand, provided some background in DFT and spectral methods. As in most atomic DFT codes, the occupation numbers of the orbitals are all given the same value within one pair of angular and principal quantum number, to obtain a spherically symmetric density. The code only keeps track of the total number of electrons for each pair of quantum numbers.

Installation

  1. Download the Tiny DFT repository. This can be done with your browser, after which you unpack the archive: https://github.com/theochem/tinydft/archive/master.zip. Or you can use git:

    bash git clone https://github.com/theochem/tinydft.git cd tinydft

  2. Install the tinydft package from source in development mode (for easy hacking):

    bash pip install -e .

Usage

To run a series of atomic DFT calculation, up to argon, run the mendelejev demo

bash tinydft-demo-mendelejev

This generates some screen output with SCF convergence, energy contributions and the figures rho_z0*.png with the radial electron densities on a semi-log plot. To modify the settings for these calculation, you can directly edit the source code.

When you make serious modifications to Tiny DFT, you can run the unit tests to make sure the original features still work.

For this, you first need to install pytest:

bash python3 -m pip install pytest pytest-cov pytest-regressions pandas --upgrade pytest

Programming assignments

In order of increasing difficulty:

  1. Change tinydft/demo_mendelejev.py to also make plots of the radial probability density, the occupied orbitals, the potentials (external, Kohn-Sham) with horizontal lines for the (higher but still negative) energy levels. Does this code reproduce the Rydberg spectral series well? (See https://en.wikipedia.org/wiki/Hydrogen_spectral_series#Rydberg_formula)

  2. Add a second unit test for the Poisson solver in tests/test_tinydft.py. The current unit test checks if the Poisson solver can correctly compute the electrostatic potential of a spherical exponential density distribution (Slater-type). Add a similar test for a Gaussian density distribution. Use the erf function from scipy.special to compute the analytic result.

  3. At the moment, the DFT calculations assume spin-unpolarized densities, which mainly affects the exchange-correlation energy. Change the code to work with spin-polarized densities. For this, also the occupation numbers for each angular momentum and principal quantum number should be split into a spin-up and spin-down occupation number.

  4. Change the external potential to take into account the finite extent of the nucleus. You can use a Gaussian density distribution. Write a python script that combines isotope abundancies from NUBASE2016 and nucleotide radii from ADNDT to build a table of abundance-averaged nuclear radii.

  5. Add a correlation energy density to the function excfunction and check if it improve the results in assignment (2). The following correlation functional has a good compromise between simplicity and accuracy:

  6. The provided implementation has a rigid algorithm to assign occupation numbers using the Klechkowski rule. Replace this by an algorithm that just looks for all the relevant lowest-energy orbitals at every SCF iteration.

  7. Implement an SCF convergence test, which checks if the new Fock operator, in the basis of occupied orbitals from a previous iteration, is diagonal with orbital energies from the previous iteration on the diagonal

  8. Implement the zeroth-order regular approximation to the Dirac equation (ZORA). ZORA needs a pro-atomic Kohn-Sham potential as input, which remains fixed during the SCF cycle. Add an outer loop where the first iteration is without ZORA and subsequent iterations use the Kohn-Sham potential from the previous SCF loop as pro-density for ZORA. (To avoid that the density diverges at the nucleus, assignment 4 should be implemented first.)

    In ZORA, the following operator should be added to the Hamiltonian:

    t_{ab} = \int (\nabla \chi_a) (\nabla \chi_b) \frac{v_{KS}(\mathbf{r})}{4/\alpha^2 - 2v_{KS}(\mathbf{r})} \mathrm{d}\mathbf{r}

    where the first factors are the gradients of the basis functions (similar to the kinetic energy operator). The Kohn-Sham potential from the previous outer iteration can be used. The parameter alpha is the dimensionless inverse fine-structure constant, see https://physics.nist.gov/cgi-bin/cuu/Value?alphinv and https://docs.scipy.org/doc/scipy/reference/constants.html (inverse fine-structure constant). Before ZORA can be implemented, the formula needs to be worked out in spherical coordinates, separating it in a radial and an angular contribution.

  9. Extend the program to perform unrestricted Spin-polarized KS-DFT calculations. (Assignment 6 should done prior to this one.) In addition to the Aufbau rule, you now also have to implement the Hund rule. You also need to keep track of spin-up and spin-down orbitals. The original code uses the angular momentum quantum number, angqn as keys in the eps_orbs_u dictionary. Instead, you can now use (angqn, spinqn) keys.

  10. Extend the program to support (fractional) Hartree-Fock exchange.

  11. Extend the program to support (meta) generalized gradient functionals.

Dictionary of variable names

The variable names are not always the shortest possible, e.g. atnum instead of z, to make them more self-explaining and to comply with good practices.

  • alphas: Gaussian exponents in basis functions
  • atcharge: Atomic charge
  • atnum: Atomic number
  • angqn: Angular momentum (or azimuthal) quantum number
  • coeffs: Expansion coefficients of a function in Gaussian primitives or Legendre polynomials.
  • econf: Electronic configuration
  • energy_hartree: Hartree energy, i.e. classical electron-electron repulsion.
  • eps: Orbital energies
  • eps_orbs_u: A list of tuples of (orbital energy, orbital coefficients). One tuple for each angular momentum quantum number. The orbital coefficients represent the radial solutions U = R/r.
  • energy_xc: Exchange-correlation energy
  • exc: Exchange-correlation energy density
  • evals: Eigenvalues
  • evecs: Eigenvectors
  • ext: Integrals for interaction with the external field (proton)
  • fnvals: Function values on grid points
  • fock: Fock operator
  • iscf: Current SCF iteration
  • jxc: Hartree-Exchange-Correlation operator
  • kin_rad: Radial kinetic energy integrals
  • kin_ang: Angular kinetic energy integrals
  • maxangqn: Maximum angular quantum number of the occupied orbitals
  • nbasis: Number of basis functions
  • nelec: Number of electrons
  • nscf: Number of SCF iterations
  • occups: Occupation numbers
  • olp: Overlap integrals
  • orb_u: Orbital divided by r: U = R/r
  • orb_r: Orbital: R = U*r
  • priqn: Primary quantum numbers
  • rho: Electron density on grid points
  • vhartree: Hartree potential, i.e. minus classical electrostatic potential due to the electrons.
  • vol: Volume element in spherical coordinates
  • vxc: Exchange-correlation potential

More Repositories

1

iodata

Python library for reading, writing, and converting computational chemistry file formats and generating input files.
Python
131
star
2

procrustes

Python library for finding the optimal transformation(s) that makes two matrices as close as possible to each other.
Python
109
star
3

horton

HORTON: Helpful Open-source Research TOol for N-fermion systems
Python
94
star
4

chemtools

A collection of interpretive chemical tools for analyzing outputs of the quantum chemistry calculations.
Python
48
star
5

grid

Python library for numerical integration, interpolation, and differentiation on (molecular) grids.
Python
43
star
6

B3DB

A large benchmark dataset, Blood-Brain Barrier Database (B3DB), complied from 50 published resources.
Jupyter Notebook
42
star
7

gbasis

Python library for analytical evaluation and integration of Gaussian-type basis functions and related quantities.
Jupyter Notebook
38
star
8

ModelHamiltonian

Generate 1- and 2-electron integrals so that molecular quantum chemistry software can be used for model Hamiltonians.
Python
26
star
9

Selector

Python library of algorithms for selecting diverse subsets of data for machine-learning.
Jupyter Notebook
22
star
10

denspart

Atoms-in-molecules density partitioning schemes based on stockholder recipe
Python
19
star
11

fanpy

Projectively-optimized geminal and "fancyCI" wavefunctions
Python
17
star
12

AtomDB

An Extended Periodic Table of Neutral and Charged Atomic Species
Jupyter Notebook
16
star
13

PyCI

A flexible ab-initio quantum chemistry library for (parameterized) configuration interaction calculations.
C++
14
star
14

gopt

Python library for optimizing molecular structures and determining chemical reaction pathways.
Python
11
star
15

B3clf

Predictors for Blood-Brain Barrier Permeability with resampling strategies based on B3DB database.
Python
8
star
16

cgbasis

C++ library for Gaussian basis function evaluation & integrals
C++
8
star
17

.github

Guidelines for various activities and initiative with QC-Devs
7
star
18

BFit

Fit a convex sum of positive basis functions to any probability distribution
Python
6
star
19

derivcheck

Derivcheck provides a robust and very sensitive checker of analytic partial derivates
Python
6
star
20

cuGBasis

High performance CUDA/Python library for computing quantum chemistry density-based descriptors for larger systems using GPUs.
Cuda
5
star
21

roberto

Collection of configurable development workflows
Python
5
star
22

matrix-permanent

Evaluates the permanent of a (possibly rectangular) matrix
C++
4
star
23

meanfield

HORTON module for SCF and HF/DFT methods
Python
4
star
24

cgrid

C++ version of horton (2.x) grid functionality
C++
4
star
25

horton3

HORTON 3 is conceived a set of workflows that bring together independent modules (e.g., IOData, Grid, and GBasis), providing a flexible architecture with a rich set of utilities and customizable features for quantum chemistry, thereby extending the functionality that was previously available in HORTON 2.x
Jupyter Notebook
4
star
26

periodic

Constants related to atomic elements
Python
2
star
27

cardboardlint

Cheap lint solution for PRs
Python
2
star
28

resummation

Python
2
star
29

NICE.jl

Julia
2
star
30

AtomDBdata

Data for AtomDB
2
star
31

cellcutoff

Library for periodic boundary conditions and real-space cutoff calculations
C++
1
star
32

romin

Robust Minimizer๏ฟผ using DIIS
Python
1
star