Пример #1
0
def test_doubleatomsymm():
  """ Bugs when calling atomsymm twice. """
  from tempfile import mkdtemp
  from shutil import rmtree
  from os.path import exists
  from pylada.dftcrystal import Crystal
  from pylada.misc import Changedir


  c = Crystal(136, 4.63909875, 2.97938395, 
              ifhr=0, 
              shift=0)                                  \
             .add_atom(0, 0, 0, 'Ti')                   \
             .add_atom(0.306153, 0.306153, 0, 'O')      \
             .append('ATOMSYMM')
  
  directory = '/tmp/test' #mkdtemp()
  if directory == '/tmp/test':
    if exists(directory): rmtree(directory)
    with Changedir(directory) as cwd: pass
  try: 
      c.append('ATOMSYMM')
      c.eval()
  finally:
    if directory != '/tmp/test': rmtree(directory)
Пример #2
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
Пример #3
0
def test():
  from tempfile import mkdtemp
  from numpy import array, all, abs
  from shutil import rmtree
  from os.path import exists
  from os import mkdir
  from pylada.dftcrystal import Crystal, relax, Shell, DisplaceAtoms
  from pylada import default_comm

  functional = relax.Relax()
  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.optgeom.fulloptg = True
  functional.shrink = 8, 16
  functional.levshift = 5, True
  functional.maxcycle = 600
  functional.guessp = True
  functional.optgeom.keepsymm = True

  crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si')
  crystal.append('fraction')
  crystal.append('keepsymm')
  crystal.append(DisplaceAtoms().add_atom(0.01, 0, 0, 1))
  directory = mkdtemp()
  if directory == '/tmp/test/' and exists(directory):
    rmtree(directory)
    mkdir(directory)
  try: 
     results = functional(crystal, outdir=directory, comm=default_comm)
     assert results.success
     # check that final crystals are same as final structures.
     for crystal, structure in zip(results.details.crystal.itervalues(),
                                   results.details.structure.itervalues()):
       estruc = crystal.eval()
       assert all(abs(estruc.cell - structure.cell) < 1e-8)
       assert all(abs( array([a.pos for a in estruc])
                       - array([a.pos for a in structure]) ) < 1e-8)
       assert all( array([a.type for a in estruc])
                   == array([a.type for a in structure]) )
     instruc = results.details.input_crystal.values()[1:] + [results.crystal]
     outstruc = results.details.structure.values()
     for a, b in zip(instruc, outstruc):
       a = a.eval()
       assert all(abs(a.cell - b.cell) < 1e-8)
       assert all(abs( array([v.pos for v in a])
                       - array([v.pos for v in b]) ) < 1e-8)
       assert all( array([v.type for v in a])
                   == array([v.type for v in b]) )
  finally: 
    if directory != '/tmp/test/': rmtree(directory)
    pass