Calculating molecular properties

Table of Contents

Molecular systems constitute the simplest and most basic of the settings that can be analyzed using ATK and NanoLanguage. For such system, you will be able to

Read on through the subsequent section, for a quick introduction to some of the many tools NanoLanguage offers for analyzing molecular systems.

Defining a molecule

Setting up the geometry of molecular structures using NanoLanguage is simple. All you have to do is

  • define a list of atomic constituents and their respective positions

  • store the above information in the NanoLanguage class MoleculeConfiguration

The MoleculeConfiguration object is then ready to be passed on for investigation and calculation of its physical properties. Here is a short script example for setting up and storing a water molecule

# Import the KohnSham module from ATK
from ATK.KohnSham import *

# Set up elements and positions
elm = [ Oxygen, Hydrogen, Hydrogen ]
pos = [ ( 0.000, 0.000, 0.0)*Angstrom,
        ( 0.757, 0.586, 0.0)*Angstrom,
        (-0.757, 0.586, 0.0)*Angstrom ]

# Add them to a configuration
h2o = MoleculeConfiguration(elm,pos)

# Open a VNL file and add the molecule to it
vnl_file = VNLFile('h2o.vnl')
vnl_file.addToSample(h2o, 'h2o')

water-viz.py

  1. Define atomic constituents and their positions

  2. Store the molecule as a MoleculeConfiguration object,

  3. Save the molecular configuration to a VNLFile. In this way, the configuration can be loaded and used from other scripts, and may also used for generating 3D renderings in VNL.

Run the script by issuing the command

atk water-viz.py

from the command line.

Calculating molecular properties

Once you have the geometry of your structure defined, you are ready to take advantage of the rich set of NanoLanguage functions and classes that are available for calculating the physical properties of your system. This requires to simple steps

  • define the method that should be used for running the DFT analysis of your structure

  • apply the method to your molecular configuration

  • choose the NanoLanguage function that should be used for determining the particular physical property that you wish to determine

For example, here is a script that loads the water molecule defined above and determine its total energy

# Import the KohnSham module from ATK
from ATK.KohnSham import *
   
# Load molecule from VNLFile
h2o = VNLFile("h2o.vnl").readAtomicConfigurations()["h2o"]

# Perform a selc-consistent calculation
method = KohnShamMethod()
scf = method.apply(h2o)

print 'Total energy = ', calculateTotalEnergy(scf)

water02-etot.py

  1. Restore the water molecule configuration from a VNLFile.

  2. Choose the KohnShamMethod DFT method with default parameters. If you wish to tweak the input parameters that influence the finer details of the DFT method, this can of course also be done. A full list of available options for the KohnShamMethod is given here.

  3. Calculate the total energy using the NanoLanguage function calculateTotalEnergy().

Run the script by issuing the command

atk water02-etot.py

from the command line.

Studying energy spectra

Once you have your system defined, only a few lines of additional NanoLanguage scripting is necessary for extracting complicated physical properties. Again the steps are simple

  • Either define or load your system from a preexisting VNLFile.

  • Setup and perform the DFT method(s).

  • Use NanoLanguage functions for extracting the desired physical properties.

Here is a simple script for calculating and printing the energy spectrum of a water molecule

# Import the KohnSham module from ATK
from ATK.KohnSham import *

# Load molecule from VNLFile
h2o = VNLFile("h2o.vnl").readAtomicConfigurations()["h2o"]

# Set up Kohn-Sham for two exchange correlation functionals
gga_calculation = KohnShamMethod(exchange_correlation_type=GGA.PBE).apply(h2o)
lda_calculation = KohnShamMethod(exchange_correlation_type=LDA.PZ).apply(h2o)

# Perform the actual calculations
gga_spectrum = calculateMolecularEnergySpectrum(gga_calculation).energies()
lda_spectrum = calculateMolecularEnergySpectrum(lda_calculation).energies()

# eV = electronVolt

print '   Energy eigenvalues for water (in eV)\n'
print '-----------------------------------------'
print '  LDA\t\t  GGA\t\t  diff\t'
print '-----------------------------------------'

for (E1,E2) in zip(lda_spectrum,gga_spectrum):
    e1 = E1.inUnitsOf(eV)
    e2 = E2.inUnitsOf(eV)
    print '%7.3f\t\t%7.3f\t\t%7.3f' % (e1,e2,(e1-e2))

water02-egv.py

  1. Load the molecule from a VNLFile.

  2. Perform two DFT calculations, using different exchange correlation functionals.

  3. Use the NanoLanguage function calculateMolecularEnergySpectrum() for calculating the spectra of the respective exchange correlation functionals.

  4. Use a Python for-loop for printing out the spectra.

Run the script by issuing the command

atk water02-egv.py

from the command line.

Flexible data storage and data visualization

The results that you calculate with your NanoLanguage scripts can be stored using the flexible VNLFile storage format. Import these files into VNL and have access to advanced 3D rendering of complicated physical objects.

Here are the simple scripting lines needed for storing and later rendering the HOMO-LUMO orbitals of the water molecule.

# Import the KohnSham module from ATK
from ATK.KohnSham import *

# Load molecule from VNLFile
h2o = VNLFile('h2o.vnl').readAtomicConfigurations()['h2o']

method = KohnShamMethod()
scf    = method.apply(h2o)

# calculate HOMO and LUMO eigenstates
egvs = calculateEigenstates(
    self_consistent_calculation=scf,
    quantum_numbers=( [3,4] )
    )

results = VNLFile('results.vnl')
results.addToSample(h2o, 'h2o')
results.addToSample(egvs[0], 'h2o','0')
results.addToSample(egvs[1], 'h2o','1')

water02-orb.py

  1. Load the water molecule from a VNLFile.

  2. Set-up the DFT method.

  3. Use the NanoLanguage function calculateEigenstates() for calculating the molecular orbitals. In this case, only a subset is determined, since we only want to study the HOMO-LUMO states.

  4. Store the HOMO-LUMO states in a VNLFile.

Run the script by issuing the command

atk water02-orb.py

from the command line.

A 3D rendering of the two states is shown below in Figure 3 and Figure 4.

The HOMO state of the water molecule rendered using VNL.

Figure 3: The HOMO state of the water molecule rendered using VNL.


The LUMO state of the water molecule rendered using VNL.

Figure 4: The LUMO state of the water molecule rendered using VNL.