cndaqiang Web Linux DFT

GPAW快速上手

2020-09-03
cndaqiang
DFT
 
RSS

参考

GPAW

ASE

执行脚本

串行

gpaw python test.py 
#或(下面这个运行结果和上面的在输出屏幕的精度可能不同,是一致的)
./test.py 

并行

mpiexec -n 8  gpaw python test.py
#或
gpaw -P 8 python test.py
#或(下面这个运行结果和上面的在输出屏幕的精度可能不同,是一致的)
mpiexec -n 8 python test.py 

计算示例

示例1

test.py

#!/usr/bin/env python
from ase import Atoms
from gpaw import GPAW

d = 0.74
a = 6.0

atoms = Atoms('H2',
              positions=[(0, 0, 0),
                         (0, 0, d)],
              cell=(a, a, a))
atoms.center()

calc = GPAW(nbands=2, txt='h2.txt') #计算程序和参数, GPAW/NWCHem等
atoms.calc = calc
print(atoms.get_forces())#执行计算 atoms.get_forces(), 如果计算过了不再重复计算
atoms.get_total_energy() #计算总能量, 上一行已经计算过了,不重复计算

示例2

#!/usr/bin/env python

from ase import Atoms
from gpaw import GPAW
from gpaw import mpi
from gpaw import PW

rank = mpi.world.rank

#------------------ STRUCTURE
a=15
RM=Atoms('C3O1H6',
        positions=[
            [ 8.682901,    8.148500,    6.967300 ],
            [ 7.500000,    7.500000,    7.500000 ],
            [ 6.142400,    7.654800,    6.874200 ],
            [ 8.451600,    6.780600,    6.762900 ],
            [ 8.605600,    8.769301,    6.079600 ],
            [ 9.518500,    8.385800,    7.619100 ],
            [ 7.497300,    7.256200,    8.558300 ],
            [ 5.572400,    6.733100,    6.970900 ],
            [ 5.584000,    8.451500,    7.361100 ],
            [ 6.233600,    7.887900,    5.815400 ]
        ],
        cell=(a, a, a)
        )
atoms=RM

#------------------ PARAMETER
calc = GPAW(#nbands=2,       #nbands
            xc='PBE',       #XC
            basis={},       #基组
            charge=0.0,     #总电荷
            #mode=PW(350),
            #gpts=(24, 24, 24), #grid points in each direction
            h=0.2,          #Grid spacing, gpts和h二选一
            #kpts={'size': (1, 1, 1)}, #仅在周期性条件下使用 1x1x1 Monkhorst-pack,有其他形式
            #occupations={'name': 'fermi-dirac',
            #             'width': 0.05
            #            },
            parallel={},    #k点并行, nbnd并行等并行操作
            convergence={   #收敛精度
                'energy': 0.0005,  # eV / electron
                'density': 1.0e-4,
                'eigenstates': 4.0e-8,  # eV^2 / electron
                'bands': 'occupied',  #'all','occupied',100,-10,'CBM+5.0'} 等,一般占据态收敛就可以
                'forces': float('inf') # eV / Ang Max
                        },
                            # add new
            txt='result'   #result
            ) #计算程序和参数, GPAW/NWCHem等
atoms.calc = calc
energy=atoms.get_total_energy() #执行计算get_total_energy,
force=atoms.get_forces()#执行计算 atoms.get_forces(), 上面计算过了不再重复计算
if rank == 0:
    print(energy)
    #print(atoms.get_forces()) #这样也可以

Lr-TDDFT计算吸收光谱

mpiexec -n 8  gpaw python Lr-TDDFT.py

Lr-TDDFT.py内容

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 
@author: cndaqiang 2020-
吸收光谱计算
"""

from gpaw import GPAW
from ase import Atoms
from ase.io import read, write
from gpaw.lrtddft import LrTDDFT,photoabsorption_spectrum
from gpaw import mpi
import sys
import os
rank = mpi.world.rank

POSCAR="center.frac.car.roat.8883.vasp"
atoms = read(POSCAR,format="vasp")
#atoms=Atoms('Na2', positions=((0.0, 0.0, 0.0), (3.12, 0.0, 0.0)))


calc = GPAW(xc='PBE',
            txt='result')
#计算结果输出到result,屏幕上没有输出
atoms.calc = calc

#执行计算,平面有输出
energy=atoms.get_potential_energy()
#执行完计算后,计算的结果保存到calc中

lr = LrTDDFT(calc, xc='PBE')
lr.write('Omega_result.gz')

lr = LrTDDFT(filename='Omega_result.gz')
lr.diagonalize()
lr.write('excitations_result.gz')
#
lr = LrTDDFT(filename='excitations_result.gz')
photoabsorption_spectrum(lr, 'result_spectrum.dat', e_min=0.0, e_max=10)
if rank == 0:
    print("Save to result_spectrum.dat")

LrTDDFT(calc, istart=0, jend=10)

atoms.write("result.vasp",format="vasp")

画图

spectrum.gpaw.py result_spectrum.dat

报错

会提示的,看信息

参数不合理

bands太少

rank=2 L32:     self.initialize(atoms)
rank=2 L33:   File "/Users/cndaqiang/anaconda3/envs/python37/lib/python3.7/site-packages/gpaw/calculator.py", line 732, in initialize
rank=2 L34:     % (nvalence, nbands))
rank=2 L35: ValueError: Too few bands!  Electrons: 24.000000, bands: 2
GPAW CLEANUP (node 2): <class 'ValueError'> occurred.  Calling MPI_Abort!
--------------------------------------------------------------------------

cpu数不合适

调大调小或调网格

rank=13 L50:     raise BadGridError(msg)
rank=13 L51: gpaw.grid_descriptor.BadGridError: Grid 19x19x19 too small for 19x1x1 cores!
GPAW CLEANUP (node 13): <class 'gpaw.grid_descriptor.BadGridError'> occurred.  Calling MPI_Abort!
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 18 in communicator MPI_COMM_WORLD
rank=12 L51: gpaw.grid_descriptor.BadGridError: Grid 19x19x19 too small for 23x1x1 cores!
GPAW CLEANUP (node 12): <class 'gpaw.grid_descriptor.BadGridError'> occurred.  Calling MPI_Abort!

本文首发于我的博客@cndaqiang.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!


上一篇 GPAW安装

下一篇 ASE快速上手

目录

访客数据