コード例 #1
0
ファイル: external.py プロジェクト: georgeyumnam/pylada
def test():
  from numpy import all, abs, dot, identity
  from pylada.dftcrystal import Crystal, External
  from pylada.crystal import which_site

  orig = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si')
  b = External(copy=orig.eval())
  assert all(abs(orig.eval().cell - b.initial.cell) < 1e-8)
  assert len(b.initial) == 2
  assert repr(b) == repr( eval(repr(b), {'External': External}) )
  assert len(b.print_input().splitlines()) == 2
  assert b.print_input().splitlines()[0] == 'EXTERNAL'
  assert b.print_input().splitlines()[1] == 'END EXTERNAL'

  # check that symmetries as extracted are ok.
  for atom in b.initial:
    for op in orig.symmetry_operators:
      assert all(abs(identity(3, dtype='float64') - dot(op[:3].T, op[:3])) < 1e-8)
      assert which_site(dot(op[:3], atom.pos) + op[3], b.initial) != -1

  # Check that running structure through crystal works
  c = b.eval()
  assert all(abs(c.cell - b.cell) < 1e-8)
  assert len(c) == 2
  assert all(abs(abs(c[0].pos) - [0.67875]*3) < 1e-8)
  assert all(abs(abs(c[1].pos) - [0.67875]*3) < 1e-8)
  assert all(abs(c[0].pos + c[1].pos) < 1e-8)
コード例 #2
0
ファイル: crystal_regression.py プロジェクト: mdavezac/LaDa
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)
コード例 #3
0
ファイル: runrelax.py プロジェクト: mdavezac/LaDa
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