JDFTx  1.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ASE Interface

JDFTx contains a python interface class to the Atomic Simulation Environment (https://wiki.fysik.dtu.dk/ase/), developed by CAMd in DTU. This provides a quick but powerful interface to many features, including phonons and ab-initio molecular dynamics.

The current implementation of the interface is as a force calculator. Potential energies and forces are implemented, but stresses are still under development.

Installation

The interface is available with JDFTx source code, under the scripts directory (/jdftx/scripts/ase).

Installing the JDFTx calculator can be done in three steps:

  1. Download and compile JDFTx

    See here for more details on compiling JDFTx.

  2. Install Atomic Simulation Environment (ASE):

    ASE is not distributed with JDFTx, and requires separate installation. See here about installing ASE.

  3. Add JDFTx interface to PythonPath:

    To be able to use the JDFTx interface, python needs to know where the interface file is located. This is done by adding the jdftx/scripts/ase to your PythonPath variable.

    In unix based systems, the easiest way to do this is by adding the line

    export PYTHONPATH=/path-to-jdftx/scripts/ase:$PYTHONPATH
    

    to your ~/.bashrc or ~/.profile files. Once this is done, you can import the JDFTx calculator simply by

    from JDFTx import JDFTx
    

Use

JDFTx interface needs to know where your executable and pseudopotentials are located. This can be done at runtime by specifying paths to the class constructor, or by setting environment variables in your system.

A JDFTx calculator object uses variables executable and pseudoDir to find the executable and the pseudopotential directory. By default, they are set to the envionment variables $JDFTx and $JDFTx_pseudo. These can be set in the constructor or changed later.

The easiest way to use the interface is to set these environment variables. On Ubuntu, this can be accomplished by to accomplish this is to have the lines

export JDFTx=/path/to/jdftx
export JDFTx_pseudo=/path/to/pseudopotential/directory

in your ~/.bashrc or ~/.profile files.

On clusters with resource management programs (e.g. slurm, torque...), you can override the executable with a command that submits a job to the queue. For example, on slurm, the following would work:

calculator = JDFTx(executable='srun /path/to/jdftx')

Take note that when you do that, the command that submits the job (in this case, srun) should not release the shell until the job is completed. For example, in slurm, srun would work, but not sbatch.

Example

Below is a sample python script that uses jdftx through the ASE interfae to calculate the bond length of CO molecule using the BFGS minimization algorithm. Keep in mind that in order for the script to run, you need to modify the paths for the executable and the pseudopotentials.

from ase import Atoms
from JDFTx import *

d = 1.25
CO = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)], cell=[(10,0,0),(0,10,0),(0,0,15)], pbc = [False, False, False])

# set up JDFTx calculator
jdftx_calculator = JDFTx(executable='/path/to/executable', pseudoDir='/path/to/pseudopotentials', commands={"elec-cutoff": 30})
CO.set_calculator(jdftx_calculator)

# print the initial total energy
print CO.get_potential_energy()

# perform structure optimization
from ase.optimize import BFGS
dyn = BFGS(CO)
dyn.run(fmax=0.05)

Output from this script is:

-583.728565039
BFGS:   0  12:37:44     -583.728565       8.6537
BFGS:   1  12:38:44     -584.230224       3.4122
BFGS:   2  12:39:45     -584.274439       2.0316
BFGS:   3  12:40:48     -584.291420       0.2329
BFGS:   4  12:41:50     -584.291665       0.0144

(warning: the exact energies depend on the pseudopotentials you use.)

More examples on how to use ASE can be found here