Beispiel #1
0
def test_functional():
  from pylada.dftcrystal import Functional, Shell
  from pylada.dftcrystal.input import print_input
  
  a = Functional()
  assert repr(a) == repr(loads(dumps(a)))
  a.basis['H'] = [ Shell( 's', 1.0, 
                          a0=[18.731137, 0.0334946],
                          a1=[2.8253937, 0.23472695],
                          a2=[0.6401217, 0.81375733] ),
                   Shell('s', 0.0, a0=[0.1612778, 1.0]), 
                   Shell('p', 0.0, a0=[1.1, 1.0]) ]
  a.shrink = [8, 8, 9], None
  a.tolinteg = 8, 8, 8, 8, 14
  a.dft.b3lyp = True
  a.dft.exchange = 'lda'
  a.dft.xxlgrid = True
  a.optgeom.maxcycle = 50
  a.optgeom.fulloptg = True
  assert repr(Functional()) != repr(loads(dumps(a)))
  assert repr(a) == repr(loads(dumps(a)))
  b = loads(dumps(a))
  assert print_input(a.output_map(crystal=a)) == print_input(b.output_map(crystal=b))
Beispiel #2
0
def test_grids():
  from numpy import array, all, abs
  from collections import namedtuple
  from pylada.dftcrystal.hamiltonian import Dft
  from pylada.dftcrystal.input import print_input
  Crystal = namedtuple('Crystal', ['dft'])
  a = Dft()
  assert a.radial.intervals is None
  assert a.radial.nbpoints is None
  assert a.angular.intervals is None
  assert a.angular.levels is None
  assert a.output_map(crystal=Crystal(a)) is None
  assert not a.lgrid
  assert not a.xlgrid
  assert not a.xxlgrid

  a.lgrid = True
  assert all(abs(array(a.angular.intervals) - [0.1667, 0.5, 0.9, 3.05, 9999.0]) < 1e-8)
  assert all(abs(array(a.angular.levels) - [2, 6, 8, 13, 8]) < 1e-8)
  assert all(abs(array(a.radial.intervals) - [4]) < 1e-8)
  assert all(abs(array(a.radial.nbpoints) - [75]) < 1e-8)
  assert print_input(a.output_map(crystal=Crystal(a))) == 'DFT\nLGRID\nEND DFT\n'
Beispiel #3
0
def test():
  from collections import namedtuple
  from pylada.dftcrystal.optgeom import OptGeom
  from pylada.dftcrystal.input import print_input
  Crystal = namedtuple('Crystal', ['optgeom'])

  a = OptGeom()
  assert a.maxcycle is None
  assert a.fulloptg is False
  assert a.cellonly is False
  assert a.itatocell is False
  assert a.intredun is False
  a.maxcycle = 10
  assert a.maxcycle == 10
  assert a.fulloptg is False
  assert a.cellonly is False
  assert a.itatocell is False
  assert a.intredun is False
  a.maxcycle = None
  assert a.maxcycle is None
  assert a.fulloptg is False
  assert a.cellonly is False
  assert a.itatocell is False
  assert a.intredun is False
  a.cellonly = True
  assert a.maxcycle is None
  assert a.fulloptg is False
  assert a.cellonly is True
  assert a.itatocell is False
  assert a.intredun is False
  a.maxcycle = 10
  assert a.maxcycle == 10
  assert a.fulloptg is False
  assert a.cellonly is True
  assert a.itatocell is False
  assert a.intredun is False

  assert a.enabled is False
  assert a.output_map(crystal=Crystal(a)) is None
  a.enabled = True
  assert a.enabled is True
  string = print_input(a.output_map(crystal=Crystal(a)))
  assert len(string.split('\n')) == 6
  string = string.split('\n')
  assert string[0] == 'OPTGEOM'
  assert string[-1] == ''
  assert string[-2] == 'END OPTGEOM'
  string = print_input(a.output_map(crystal=Crystal(a))).split()
  assert 'MAXCYCLE' in string
  assert string[string.index('MAXCYCLE')+1] == str(10)
  assert 'CELLONLY' in string

  a.cvolopt = True
  string = print_input(a.output_map(crystal=Crystal(a))).split('\n')
  assert len(string) == 7
  assert string[0] == 'OPTGEOM'
  assert string[-1] == ''
  assert string[-2] == 'END OPTGEOM'
  string = print_input(a.output_map(crystal=Crystal(a))).split()
  assert 'MAXCYCLE' in string
  assert string[string.index('MAXCYCLE')+1] == str(10)
  assert 'CELLONLY' in string
  assert 'CVOLOPT' in string

  a.itatocell = True
  string = print_input(a.output_map(crystal=Crystal(a))).split('\n')
  assert len(string) == 6
  assert string[0] == 'OPTGEOM'
  assert string[-1] == ''
  assert string[-2] == 'END OPTGEOM'
  string = print_input(a.output_map(crystal=Crystal(a))).split()
  assert 'MAXCYCLE' in string
  assert string[string.index('MAXCYCLE')+1] == str(10)
  assert 'ITATOCELL' in string

  a.itatocell = False
  assert a.output_map(crystal=Crystal(a)) is not None
  string = print_input(a.output_map(crystal=Crystal(a))).split('\n')
  assert len(string) == 5
  assert string[0] == 'OPTGEOM'
  assert string[1] == 'MAXCYCLE'
  assert string[2] == '10'
  assert string[-2] == 'END OPTGEOM'
  assert string[-1] == ''

  a.enabled = False
  assert a.output_map(crystal=Crystal(a)) is None
Beispiel #4
0
def test():
  from collections import namedtuple
  from pylada.dftcrystal.hamiltonian import Dft
  from pylada.dftcrystal.input import print_input
  from pylada.dftcrystal.parse import parse
  Crystal = namedtuple('Crystal', ['dft'])
  
  a = Dft()
  crystal = Crystal(a)
  assert a.exchange is None
  assert a.correlat is None
  assert a.hybrid is None
  assert a.nonlocal.correlation is None
  assert a.nonlocal.exchange is None
  assert a.spin is None
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.pbe0
  assert not a.soggaxc
  assert a.output_map(crystal=crystal) is None

  try: a.exchange = 'none'
  except: pass
  else: raise Exception()
  try: a.correlat = 'none'
  except: pass
  else: raise Exception()
  try: a.hybrid = 'none'
  except: pass
  else: raise Exception()
  a.spin = 'none'
  assert a.spin == False

  a.exchange = 'lda'
  crystal = Crystal(a)
  assert a.exchange == 'lda'
  assert a.correlat is None
  assert a.hybrid is None
  assert a.nonlocal.correlation is None
  assert a.nonlocal.exchange is None
  assert a.spin is False
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.pbe0
  assert not a.soggaxc
  assert len(a.output_map(crystal=crystal)) == 1
  assert 'DFT' in a.output_map(crystal=crystal)
  assert len(a.output_map(crystal=crystal)['DFT']) == 1
  assert 'EXCHANGE' in a.output_map(crystal=crystal)['DFT']
  assert a.output_map(crystal=crystal)['DFT']['EXCHANGE'] == 'LDA'

  b = parse("DFT\nEXCHANGE\nPBE\nEND DFT\n", needstarters=False)
  a = Dft()
  a.read_input(b['DFT'])
  assert a.exchange == 'pbe'
  assert a.correlat is None
  assert a.hybrid is None
  assert a.nonlocal.correlation is None
  assert a.nonlocal.exchange is None
  assert a.spin is None
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.pbe0
  assert not a.soggaxc

  a.b3lyp = True
  crystal = Crystal(a)
  assert a.exchange == 'becke'
  assert a.correlat == 'lyp'
  assert abs(a.hybrid - 20) < 1e-8
  assert abs(a.nonlocal.exchange - 0.9) < 1e-8
  assert abs(a.nonlocal.correlation - 0.81) < 1e-8
  assert a.spin is None
  assert a.b3lyp
  assert not a.b3pw
  assert not a.pbe0
  assert not a.soggaxc
  assert len(a.output_map(crystal=crystal)) == 1
  assert 'DFT' in a.output_map(crystal=crystal)
  assert len(a.output_map(crystal=crystal)['DFT']) == 1
  assert 'B3LYP' in a.output_map(crystal=crystal)['DFT']
  assert a.output_map(crystal=crystal)['DFT']['B3LYP'] is None

  b = parse("DFT\nB3LYP\nEND DFT\n", needstarters=False)
  a = Dft()
  a.read_input(b['DFT'])
  assert a.b3lyp
  b = parse("DFT\nPBE0\nEND DFT\n", needstarters=False)
  a = Dft()
  a.read_input(b['DFT'])
  crystal = Crystal(a)
  assert a.pbe0
  assert a.exchange == 'pbe'
  assert a.correlat == 'pbe'
  assert a.hybrid is None
  assert a.nonlocal.exchange is None
  assert a.nonlocal.correlation is None
  assert a.spin is None
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.soggaxc
  assert len(a.output_map(crystal=crystal)) == 1
  assert 'DFT' in a.output_map(crystal=crystal)
  assert len(a.output_map(crystal=crystal)['DFT']) == 1
  assert 'PBE0' in a.output_map(crystal=crystal)['DFT']
  assert a.output_map(crystal=crystal)['DFT']['PBE0'] is None

  a.b3pw = True
  a.exchange = 'lda'
  assert a.exchange == 'lda'
  assert a.correlat == 'pwgga'
  assert abs(a.hybrid - 20) < 1e-8
  assert abs(a.nonlocal.exchange - 0.9) < 1e-8
  assert abs(a.nonlocal.correlation - 0.81) < 1e-8
  assert a.spin is None
  assert not a.pbe0
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.soggaxc
  string = "DFT\nCORRELAT\nPWGGA\nEXCHANGE\nLDA\n"\
           "HYBRID\n" + str(float(20)) + "\n"     \
           "NONLOCAL\n" + str(float(0.9)) + " "   \
           + str(float(0.81)) + "\n" + "END DFT\n"
  assert print_input(a.output_map(crystal=Crystal(a))) == string
  assert print_input(a.output_map(crystal=Crystal(a))) == string

  b = parse(string, needstarters=False)
  a = Dft()
  a.read_input(b['DFT'])
  assert a.exchange == 'lda'
  assert a.correlat == 'pwgga'
  assert abs(a.hybrid - 20) < 1e-8
  assert abs(a.nonlocal.exchange - 0.9) < 1e-8
  assert abs(a.nonlocal.correlation - 0.81) < 1e-8
  assert a.spin is None
  assert not a.pbe0
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.soggaxc
  assert print_input(a.output_map(crystal=Crystal(a))) == string

  string = "DFT\nCORRELAT\nPWGGA\nEXCHANGE\nLDA\n"\
           "HYBRID\n" + str(float(20)) + "\n"     \
           "NONLOCAL\n" + str(float(0.9)) + " "   \
           + str(float(0.81)) + "\nHELLO\nWORLD\n1\n" + "END DFT\n"
  b = parse(string, needstarters=False)
  a = Dft()
  a.read_input(b['DFT'])
  assert a.exchange == 'lda'
  assert a.correlat == 'pwgga'
  assert abs(a.hybrid - 20) < 1e-8
  assert abs(a.nonlocal.exchange - 0.9) < 1e-8
  assert abs(a.nonlocal.correlation - 0.81) < 1e-8
  assert a.spin is None
  assert not a.pbe0
  assert not a.b3lyp
  assert not a.b3pw
  assert not a.soggaxc
  assert 'hello' in a._input
  assert type(a._input['hello']) is bool and a._input['hello'] == True
  assert 'world' in a._input
  assert type(a._input['world']) is int and a._input['world'] == 1
  string = print_input(a.output_map(crystal=Crystal(a))).split('\n')
  assert 'HELLO' in string
  assert 'WORLD' in string 
  assert string[string.index('WORLD')+1] == '1'
  a.hello = False
  a.world = 2
  string = print_input(a.output_map(crystal=Crystal(a))).split('\n')
  assert 'HELLO' not in string
  assert 'WORLD' in string 
  assert string[string.index('WORLD')+1] == '2'