Пример #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)
Пример #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)
Пример #3
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
Пример #4
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)
Пример #5
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