Exemplo n.º 1
0
def test():
    from tempfile import mkdtemp
    from shutil import rmtree
    from os.path import join
    from numpy import mean, abs, sum
    from pylada.dftcrystal import Crystal, Functional, Shell
    from pylada.dftcrystal.properties.emass import effective_mass
    from pylada import default_comm

    functional = Functional()
    functional.basis["Si"] = [
        Shell(
            "s",
            a0=[16120.0, 0.001959],
            a1=[2426.0, 0.01493],
            a2=[553.9, 0.07285],
            a3=[156.3, 0.2461],
            a4=[50.07, 0.4859],
            a5=[17.02, 0.325],
        ),
        Shell(
            "sp",
            a0=[292.7, -0.002781, 0.004438],
            a1=[69.87, -0.03571, 0.03267],
            a2=[22.34, -0.115, 0.1347],
            a3=[8.15, 0.09356, 0.3287],
            a4=[3.135, 0.603, 0.4496],
        ),
        Shell("sp", 4.0, a0=[1.22, 1.0, 1.0]),
        Shell("sp", 0.0, a0=[0.55, 1.0, 1.0]),
        Shell("sp", 0.0, a0=[0.27, 1.0, 1.0]),
    ]

    functional.dft.pbe0 = True
    functional.fmixing = 30
    functional.shrink = 8, 16
    functional.levshift = 5, True
    functional.maxcycle = 600
    functional.dft.spin = False
    functional.toldee = 12

    crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, "Si")
    directory = "/tmp/test/"  # mkdtemp()
    firstdir, seconddir = join(directory, "0"), join(directory, "1")
    try:
        emass = effective_mass(
            functional, crystal, range=0.05, polarpoints=20, nbpoints=10, outdir=directory, comm=default_comm
        )
        assert emass.success
        print emass.bandstructure.kpoints.shape, emass.bandstructure.eigenvalues.shape
        print emass.success
        print emass.tensors([0, 1, 2])[2][11:15]
    #  print emass.kpoints
    #  kpoints = emass.bandstructure.kpoints
    #  ball = abs(sum(kpoints*kpoints, axis=1)-1e0) < 1e-8
    #  print kpoints[ball]
    #  print mean(kpoints[ball], axis=0)
    finally:
        if directory != "/tmp/test/":
            rmtree(directory)
Exemplo n.º 2
0
def test():
  from tempfile import mkdtemp
  from shutil import rmtree
  from os.path import join, exists
  from os import mkdir
  from pylada.dftcrystal import Crystal, Functional, Shell
  from pylada.dftcrystal.properties import Properties
  from pylada import default_comm

  functional = Functional()
  functional.basis['Si'] = [
      Shell('s', a0=[16120.0, 0.001959],
                 a1=[2426.0, 0.01493], 
                 a2=[553.9, 0.07285],
                 a3=[156.3, 0.2461], 
                 a4=[50.07, 0.4859],
                 a5=[17.02, 0.325]),
      Shell('sp', a0=[292.7, -0.002781, 0.004438],
                  a1=[69.87, -0.03571, 0.03267],
                  a2=[22.34, -0.115, 0.1347],
                  a3=[8.15, 0.09356, 0.3287],
                  a4=[3.135, 0.603, 0.4496]), 
      Shell('sp', 4.0, a0=[1.22, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.55, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.27, 1.0, 1.0]) ]

  functional.dft.pbe0 = True
  functional.fmixing = 30
  functional.shrink = 8, 16
  functional.levshift = 5, True
  functional.maxcycle = 600
  functional.dft.spin = True

  crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si')
  directory =  mkdtemp() 
  if directory == '/tmp/test/':
    rmtree(directory)
    mkdir(directory)
  firstdir, seconddir = join(directory, '0'), join(directory, '1')
  try: 
     si = functional(crystal, outdir=firstdir, comm=default_comm)
     assert exists(join(firstdir, 'crystal.f9'))
     assert not exists(join(directory, 'crystal.f98'))
     properties = Properties(si)
     properties.rdfmwf = True
     result = properties(outdir=directory, workdir=join(directory, 'try0'))
     assert result.success
     assert exists(join(directory, 'crystal.f9'))
     assert not exists(join(directory, 'crystal.f98'))
     properties = Properties(directory)
     properties.fmwf = True
     result = properties(outdir=directory, workdir=join(directory, 'try1'))
     assert not exists(join(directory, 'crystal.f98'))
     result = properties(outdir=directory, workdir=join(directory, 'try1'), overwrite=True)
     assert result.success
     assert exists(join(directory, 'crystal.f98'))

  finally: 
    if directory != '/tmp/test/': rmtree(directory)
Exemplo n.º 3
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))
Exemplo n.º 4
0
def test():
    from tempfile import mkdtemp
    from shutil import rmtree
    from pylada.dftcrystal import Crystal, Functional, Shell
    from pylada import default_comm

    functional = Functional()
    functional.basis["Si"] = [
        Shell(
            "s",
            a0=[16120.0, 0.001959],
            a1=[2426.0, 0.01493],
            a2=[553.9, 0.07285],
            a3=[156.3, 0.2461],
            a4=[50.07, 0.4859],
            a5=[17.02, 0.325],
        ),
        Shell(
            "sp",
            a0=[292.7, -0.002781, 0.004438],
            a1=[69.87, -0.03571, 0.03267],
            a2=[22.34, -0.115, 0.1347],
            a3=[8.15, 0.09356, 0.3287],
            a4=[3.135, 0.603, 0.4496],
        ),
        Shell("sp", 4.0, a0=[1.22, 1.0, 1.0]),
        Shell("sp", 0.0, a0=[0.55, 1.0, 1.0]),
        Shell("sp", 0.0, a0=[0.27, 1.0, 1.0]),
    ]

    functional.dft.pbe0 = True
    functional.fmixing = 30
    functional.shrink = 8, 16
    functional.levshift = 5, True
    functional.maxcycle = 600

    crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, "Si")
    directory = mkdtemp()
    try:
        results = functional(crystal, outdir=directory, comm=default_comm)
        assert results.success
    finally:
        if directory != "/tmp/test/":
            rmtree(directory)
        pass
Exemplo n.º 5
0
def test_chemod():
  from pickle import loads, dumps
  from numpy import all, array, abs
  from pylada.dftcrystal import Crystal, Functional, Shell
  functional = Functional()
  functional.basis['Si'] = [
      Shell('s', a0=[16120.0, 0.001959],
                 a1=[2426.0, 0.01493], 
                 a2=[553.9, 0.07285],
                 a3=[156.3, 0.2461], 
                 a4=[50.07, 0.4859],
                 a5=[17.02, 0.325]),
      Shell('sp', a0=[292.7, -0.002781, 0.004438],
                  a1=[69.87, -0.03571, 0.03267],
                  a2=[22.34, -0.115, 0.1347],
                  a3=[8.15, 0.09356, 0.3287],
                  a4=[3.135, 0.603, 0.4496]), 
      Shell('sp', 4.0, a0=[1.22, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.55, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.27, 1.0, 1.0]) ]
  crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si')

  kwargs = {'crystal': functional, 'structure': crystal}
  a = functional.basis._input['chemod']
  assert len(functional.basis.chemod) == 0
  assert a.output_map(**kwargs) is None
  assert functional.basis.chemod.breaksym == True
  assert loads(dumps(a)).breaksym is True
  assert len(loads(dumps(a))) == 0
 
  functional.basis.chemod.keepsym = True
  functional.basis.chemod[1] = [2.0, 8.0, 4.0, 0.0, 0.0]
  assert 'chemod' in a.output_map(**kwargs)
  assert all( abs( array(a.output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [2.0,  1.0, 2.0, 8.0, 4, 0, 0, 2, 2, 8, 4, 0, 0] ) < 1e-8 )
  assert a.modisymm(crystal) is None
  assert loads(dumps(a)).breaksym is False
  assert all( abs( array(loads(dumps(a)).output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [2.0,  1.0, 2.0, 8.0, 4, 0, 0, 2, 2, 8, 4, 0, 0] ) < 1e-8 )
  functional.basis.chemod[2] = [2.0, 8.0, 4.0, 0.0, 0.0]
  assert 'chemod' in a.output_map(**kwargs)
  assert all( abs( array(a.output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [2.0,  1.0, 2.0, 8.0, 4, 0, 0, 2, 2, 8, 4, 0, 0] ) < 1e-8 )
  assert loads(dumps(a)).breaksym is False
  assert all( abs( array(loads(dumps(a)).output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [2.0,  1.0, 2.0, 8.0, 4, 0, 0, 2, 2, 8, 4, 0, 0] ) < 1e-8 )
  assert a.modisymm(crystal) is None
  del functional.basis.chemod[1]
  assert 'chemod' in a.output_map(**kwargs)
  assert all( abs( array(a.output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [2.0,  1.0, 2.0, 8.0, 4, 0, 0, 2, 2, 8, 4, 0, 0] ) < 1e-8 )
  assert loads(dumps(a)).breaksym is False
  assert all( abs( array(loads(dumps(a)).output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [2.0,  1.0, 2.0, 8.0, 4, 0, 0, 2, 2, 8, 4, 0, 0] ) < 1e-8 )
  assert a.modisymm(crystal) is None

  functional.basis.chemod.breaksym = True
  assert 'chemod' in a.output_map(**kwargs)
  assert all( abs( array(a.output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [1.0,  2.0, 2.0, 8.0, 4, 0, 0] ) < 1e-8 )
  assert loads(dumps(a)).breaksym is True
  assert all( abs( array(loads(dumps(a)).output_map(**kwargs)['chemod'].split(), dtype='float64')
                   - [1.0,  2.0, 2.0, 8.0, 4, 0, 0] ) < 1e-8 )
  assert a.modisymm(crystal) is not None
  assert [2] in a.modisymm(crystal).groups 
  assert [1] in a.modisymm(crystal).groups 
  assert len(a.modisymm(crystal).groups) == 2
Exemplo n.º 6
0
def test():
  from tempfile import mkdtemp
  from shutil import rmtree
  from os.path import join
  from numpy import all, array
  from quantities import hartree
  from pylada.dftcrystal import Crystal, Functional, Shell
  from pylada.dftcrystal.properties import Properties
  from pylada import default_comm

  functional = Functional()
  functional.basis['Si'] = [
      Shell('s', a0=[16120.0, 0.001959],
                 a1=[2426.0, 0.01493], 
                 a2=[553.9, 0.07285],
                 a3=[156.3, 0.2461], 
                 a4=[50.07, 0.4859],
                 a5=[17.02, 0.325]),
      Shell('sp', a0=[292.7, -0.002781, 0.004438],
                  a1=[69.87, -0.03571, 0.03267],
                  a2=[22.34, -0.115, 0.1347],
                  a3=[8.15, 0.09356, 0.3287],
                  a4=[3.135, 0.603, 0.4496]), 
      Shell('sp', 4.0, a0=[1.22, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.55, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.27, 1.0, 1.0]) ]

  functional.dft.pbe0 = True
  functional.fmixing = 30
  functional.shrink = 8, 16
  functional.levshift = 5, True
  functional.maxcycle = 600
  functional.dft.spin = True

  crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si')
  directory =  mkdtemp() 
  firstdir, seconddir = join(directory, '0'), join(directory, '1')
  try: 
     si = functional(crystal, outdir=firstdir, comm=default_comm)
     properties = Properties(si)
     properties.band = [0, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0]
     result0 = properties(outdir=firstdir)
     assert result0.success 
     assert all(abs(result0.bandstructure.eigenvalues[0] - result0.bandstructure.eigenvalues[1]) < 1e-6)
     test = [ [-64.55637917, -64.55637522,  -3.64877203,  -3.64854929,
                -1.98183315,  -1.98183315,  -1.98183315,  -1.98097196,
                -1.98097196,  -1.98097196,   1.00052165,   1.49996607,
                 1.49996607,   1.49996607,   1.63212276,   1.63212276,
                 1.63212276,   1.66407077],
               [-64.55637917, -64.55637522,  -3.64877203,  -3.64854929,
                 -1.98183315,  -1.98183315,  -1.98183315,  -1.98097196,
                 -1.98097196,  -1.98097196,   1.00052165,   1.49996607,
                  1.49996607,   1.49996607,   1.63212276,   1.63212276,
                  1.63212276,   1.66407077] ] * hartree
     assert all(abs(result0.bandstructure.eigenvalues[0,0] - test[0]) < 1e-8)
     assert all(abs(result0.bandstructure.eigenvalues[0,-1] - test[1]) < 1e-8)
     test = array([[  6.66666667e-02,   0, 0],
                   [  1.33333333e-01,   0, 0],
                   [  2.00000000e-01,   0, 0],
                   [  2.66666667e-01,   0, 0],
                   [  3.33333333e-01,   0, 0],
                   [  4.00000000e-01,   0, 0],
                   [  4.66666667e-01,   0, 0],
                   [  5.33333333e-01,   0, 0],
                   [  6.00000000e-01,   0, 0],
                   [  6.66666667e-01,   0, 0],
                   [  7.33333333e-01,   0, 0],
                   [  8.00000000e-01,   0, 0],
                   [  8.66666667e-01,   0, 0],
                   [  9.33333333e-01,   0, 0],
                   [  1.00000000e+00,   0, 0],
                   [  1.06666667e+00,   0, 0],
                   [  9.58333333e-01,   4.16666667e-02,   0],
                   [  9.16666667e-01,   8.33333333e-02,   0],
                   [  8.75000000e-01,   1.25000000e-01,   0],
                   [  8.33333333e-01,   1.66666667e-01,   0],
                   [  7.91666667e-01,   2.08333333e-01,   0],
                   [  7.50000000e-01,   2.50000000e-01,   0],
                   [  7.08333333e-01,   2.91666667e-01,   0],
                   [  6.66666667e-01,   3.33333333e-01,   0],
                   [  6.25000000e-01,   3.75000000e-01,   0],
                   [  5.83333333e-01,   4.16666667e-01,   0],
                   [  5.41666667e-01,   4.58333333e-01,   0],
                   [  5.00000000e-01,   5.00000000e-01,   0],
                   [  4.58333333e-01,   5.41666667e-01,   0],
                   [  4.16666667e-01,   5.83333333e-01,   0],
                   [  3.75000000e-01,   6.25000000e-01,   0],
                   [  3.33333333e-01,   6.66666667e-01,   0],
                   [  2.91666667e-01,   7.08333333e-01,   0],
                   [  2.50000000e-01,   7.50000000e-01,   0],
                   [  2.08333333e-01,   7.91666667e-01,   0],
                   [  1.66666667e-01,   8.33333333e-01,   0],
                   [  1.25000000e-01,   8.75000000e-01,   0],
                   [  8.33333333e-02,   9.16666667e-01,   0],
                   [  4.16666667e-02,   9.58333333e-01,   0],
                   [ -1.11022302e-16,   1.00000000e+00,   0]])
     assert all(abs(result0.bandstructure.kpoints - test) < 1e-8)
     
     functional.dft.spin = False
     si = functional(crystal, outdir=seconddir, comm=default_comm)
     properties = Properties(si)
     properties.band = [0, 0, 0], [1, 0, 0], [1, 0, 0], [0, 1, 0]
     result1 = properties(outdir=seconddir)
     assert result1.success 
     assert all(abs(result1.bandstructure.eigenvalues - result0.bandstructure.eigenvalues[0]) < 1e-6)
     assert all(abs(result1.bandstructure.kpoints - result0.bandstructure.kpoints) < 1e-6)
  finally: 
    if directory != '/tmp/test/': rmtree(directory)
Exemplo n.º 7
0
def test_breaksym():
  from pylada.dftcrystal import Crystal, Functional, Shell, DisplaceAtoms, read

  functional = Functional()
  functional.basis['Si'] = [
      Shell('s', a0=[16120.0, 0.001959],
                 a1=[2426.0, 0.01493], 
                 a2=[553.9, 0.07285],
                 a3=[156.3, 0.2461], 
                 a4=[50.07, 0.4859],
                 a5=[17.02, 0.325]),
      Shell('sp', a0=[292.7, -0.002781, 0.004438],
                  a1=[69.87, -0.03571, 0.03267],
                  a2=[22.34, -0.115, 0.1347],
                  a3=[8.15, 0.09356, 0.3287],
                  a4=[3.135, 0.603, 0.4496]), 
      Shell('sp', 4.0, a0=[1.22, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.55, 1.0, 1.0]),
      Shell('sp', 0.0, a0=[0.27, 1.0, 1.0]) ]

  functional.dft.pbe0 = True
  functional.fmixing = 30
  functional.shrink = 8, 16
  functional.levshift = 5, True
  functional.maxcycle = 600
  functional.optgeom.keepsymm = True
  functional.optgeom.enabled = True

  crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si')
  crystal.append('breaksym')
  crystal.append(DisplaceAtoms().add_atom(0.01, 0, 0, 1))
  string = functional.print_input(structure=crystal)
  assert string.splitlines()[10] == 'KEEPSYMM'
  cry, func = read(string)
  assert cry.is_breaksym
  assert func.optgeom.enabled 
  assert func.optgeom.keepsymm 

  functional.optgeom.keepsymm = False
  string = functional.print_input(structure=crystal)
  assert string.splitlines()[10] == 'OPTGEOM'
  cry, func = read(string)
  assert cry.is_breaksym
  assert func.optgeom.enabled 
  assert func.optgeom.breaksym 

  crystal[0] = 'keepsymm'
  string = functional.print_input(structure=crystal)
  assert string.splitlines()[11] == 'BREAKSYM'
  cry, func = read(string)
  assert not cry.is_breaksym
  assert func.optgeom.enabled 
  assert func.optgeom.breaksym 

  functional.optgeom.keepsymm = True
  string = functional.print_input(structure=crystal)
  assert string.splitlines()[11] == 'OPTGEOM'
  cry, func = read(string)
  assert not cry.is_breaksym
  assert func.optgeom.enabled 
  assert func.optgeom.keepsymm 

  string = crystal.print_input()
  crystal.append('keepsymm')
  crystal.append('keepsymm')
  assert crystal.print_input() == string
  crystal.append('breaksym')
  assert crystal.print_input() != string
  assert len(crystal.print_input().splitlines()) == len(string.splitlines()) + 1
Exemplo n.º 8
0
def test_broyden():
  from pickles import loads, dumps
  from pylada.dftcrystal import Functional
  from pylada.dftcrystal.electronic import Broyden
  from pylada.error import ValueError, TypeError

  a = Functional()
  b = a.scf._input['broyden']
  assert a.broyden.w0 is None
  assert a.broyden.imix is None
  assert a.broyden.istart is None
  assert b.output_map() is None
  assert eval(repr(b), {'Broyden': Broyden}).w0 is None
  assert eval(repr(b), {'Broyden': Broyden}).imix is None
  assert eval(repr(b), {'Broyden': Broyden}).istart is None
  
  a.broyden.w0 = 1e-4
  assert abs(a.broyden.w0 - 1e-4) < 1e-8
  assert a.broyden.imix is None
  assert a.broyden.istart is None
  assert b.output_map() is None
  assert abs(eval(repr(b), {'Broyden': Broyden}).w0 - 1e-4) < 1e-8
  assert eval(repr(b), {'Broyden': Broyden}).imix is None
  assert eval(repr(b), {'Broyden': Broyden}).istart is None

  a.broyden.w0 = None
  a.broyden.imix = 50
  a.broyden.istart = 3
  assert a.broyden.w0 is None
  assert a.broyden.imix == 50
  assert a.broyden.istart == 3
  assert eval(repr(b), {'Broyden': Broyden}).w0 is None
  assert eval(repr(b), {'Broyden': Broyden}).imix == 50
  assert eval(repr(b), {'Broyden': Broyden}).istart == 3
  assert b.output_map() is None

  a.broyden.w0 = 1e-4
  a.broyden.imix = 50
  a.broyden.istart = 3
  assert abs(a.broyden.w0 - 1e-4) < 1e-8
  assert a.broyden.imix == 50
  assert a.broyden.istart == 3
  assert abs(eval(repr(b), {'Broyden': Broyden}).w0 - 1e-4) < 1e-8
  assert eval(repr(b), {'Broyden': Broyden}).imix == 50
  assert eval(repr(b), {'Broyden': Broyden}).istart == 3
  assert b.output_map() is not None
  assert 'broyden' in b.output_map() 
  assert len(b.output_map()['broyden'].split()) == 3
  assert abs(float(b.output_map()['broyden'].split()[0])-1e-4) < 1e-8
  assert int(b.output_map()['broyden'].split()[1]) == 50
  assert int(b.output_map()['broyden'].split()[2]) == 3

  a.broyden[0] = '1e-2'
  assert abs(a.broyden.w0 - 1e-2) < 1e-8
  assert abs(a.broyden[0] - 1e-2) < 1e-8
  a.broyden[1] = 25
  assert a.broyden.imix == 25
  assert a.broyden[1] == 25
  a.broyden[2] = 5
  assert a.broyden.istart == 5
  assert a.broyden[2] == 5

  assert abs(loads(dumps(b))[0] - 1e-2) < 1e-8
  assert loads(dumps(b))[1] == 25
  assert loads(dumps(b))[2] == 5

  a.broyden = None
  assert a.broyden.w0 is None
  assert a.broyden.imix is None
  assert a.broyden.istart is None
  a.broyden = ' 1e-2', 25, 5
  assert abs(a.broyden[0] - 1e-2) < 1e-8
  assert a.broyden[1] == 25
  assert a.broyden[2] == 5

  try: a.broyden = 0
  except TypeError: pass
  else: raise Exception()
  try: a.broyden = 0, 1
  except TypeError: pass
  else: raise Exception()
  try: a.broyden[1] = 0
  except ValueError: pass
  else: raise Exception()
  try: a.broyden[2] = 1
  except ValueError: pass
  else: raise Exception()