Esempio n. 1
0
def test_input():
  from numpy import array, all, abs
  from pylada.error import ValueError
  from pylada.gulp import Functional

  functional = Functional()
  functional.morse['Ti', 'O']  = [1.0279493, 3.640737, 1.88265, 0, 25]
  functional.morse['Ti', 'Ti'] = [0.00567139, 1.5543, 4.18784, 0, 25]
  functional.morse['O', 'O']   = [0.00567139, 1.5543, 4.18784, 0, 25] 

  # should fail since no interaction enabled yet.
  try: functional.input_string()
  except ValueError: pass
  else: raise Exception()

  functional.morse.enabled = True
  string = functional.input_string().splitlines()
  assert string[:2] == [''] * 2
  assert string[2] == 'morse'
  assert string[3].split()[:4] == ['O', 'core'] * 2
  assert all(abs(array( string[3].split()[4:], dtype='float64')
                        - functional.morse['O', 'O'] ) < 1e-3) 
  assert string[4].split()[:4] == ['Ti', 'core'] * 2
  assert all(abs(array( string[4].split()[4:], dtype='float64')
                        - functional.morse['Ti', 'Ti'] ) < 1e-3) 
  assert string[5].split()[:4] == ['O', 'core', 'Ti', 'core']
  assert all(abs(array( string[5].split()[4:], dtype='float64')
                        - functional.morse['Ti', 'O'] ) < 1e-3) 
Esempio n. 2
0
def test():
  """ Tests file setup. """
  from tempfile import mkdtemp
  from os.path import exists
  from shutil import rmtree
  from quantities import eV
  from pylada.gulp import Functional
  from pylada.crystal import Structure
  from pylada.tools import create_directory

  functional = Functional()
  functional.qeq = True
  functional.morse.enabled     = True
  functional.morse['Ti', 'O']  = [1.0279493, 3.640737, 1.88265, 0, 25]
  functional.morse['Ti', 'Ti'] = [0.00567139, 1.5543, 4.18784, 0, 25]
  functional.morse['O', 'O']   = [0.00567139, 1.5543, 4.18784, 0, 25] 

  structure = Structure( 4.6391, 0, 0,
                         0, 4.6391, 0,
                         0, 0, 2.97938,
                         scale=1, symmgroup=136 )                              \
                .add_atom(0, 0, 0, 'Ti', asymmetric=True)                      \
                .add_atom(2.31955, 2.31955, 1.48969, 'Ti', asymmetric=False)   \
                .add_atom(1.42027, 1.42027, 0, 'O', asymmetric=True)           \
                .add_atom(-1.42027, -1.42027, 0, 'O', asymmetric=False)        \
                .add_atom(-0.899275, 0.899275, 1.48969, 'O', asymmetric=False) \
                .add_atom(0.899275, -0.899275, 1.48969, 'O', asymmetric=False)

  directory = mkdtemp()
  if directory == '/tmp/test/':
    if exists(directory): rmtree(directory)
    create_directory(directory)
  try:
    result = functional(structure, directory)
    assert result._finished
    assert result.success
    assert not result.optimize
    assert not result.conp
    assert abs(result.energy + 9.84502039*eV) < 1e-5
  finally:
    if directory != '/tmp/test/': rmtree(directory)
Esempio n. 3
0
def test_repr():
  """ Test representability. """
  from numpy import all, array, abs
  from pylada.gulp import Functional
  
  functional = Functional()
  b = {}; exec(repr(functional)) in b; b = b['functional']
  assert not b.morse.enabled
  assert not b.opti
  assert not b.conv
  assert not b.conp
  assert not b.isotropic
  assert not b.cellonly
  assert not b.buckingham.enabled
  assert len(b.morse) == 0
  assert len(b.buckingham) == 0

  functional.morse['Ti', 'O']  = [1.0279493, 3.640737, 1.88265, 0, 25]
  functional.morse['Ti', 'Ti'] = [0.00567139, 1.5543, 4.18784, 0, 25]
  functional.morse['O', 'O']   = [0.00567139, 1.5543, 4.18784, 0, 25] 
  b = {}; exec(repr(functional)) in b; b = b['functional']
  assert not b.morse.enabled
  assert not b.opti
  assert not b.conv
  assert not b.conp
  assert not b.isotropic
  assert not b.cellonly
  assert len(b.morse) == 3
  assert not b.buckingham.enabled
  assert len(b.buckingham) == 0
  assert all(abs(array( functional.morse['Ti', 'O'])  
                        - [1.0279493, 3.640737, 1.88265, 0, 25] ) < 1e-4)
  assert all(abs(array( functional.morse['Ti', 'Ti']) 
                        - [0.00567139, 1.5543, 4.18784, 0, 25] ) < 1e-4)
  assert all(abs(array( functional.morse['O', 'O'])
                        - [0.00567139, 1.5543, 4.18784, 0, 25] ) < 1e-4)

  functional.morse.enabled = True
  functional.opti          = True
  functional.cellonly      = True
  b = {}; exec(repr(functional)) in b; b = b['functional']
  assert b.morse.enabled
  assert b.opti
  assert not b.conv
  assert not b.conp
  assert not b.isotropic
  assert not b.buckingham.enabled
  assert len(b.buckingham) == 0
  assert b.cellonly
  assert len(b.morse) == 3
  assert all(abs(array( functional.morse['Ti', 'O'])  
                        - [1.0279493, 3.640737, 1.88265, 0, 25] ) < 1e-4)
  assert all(abs(array( functional.morse['Ti', 'Ti']) 
                        - [0.00567139, 1.5543, 4.18784, 0, 25] ) < 1e-4)
  assert all(abs(array( functional.morse['O', 'O'])
                        - [0.00567139, 1.5543, 4.18784, 0, 25] ) < 1e-4)
Esempio n. 4
0
def test_filesetup():
  """ Tests file setup. """
  from tempfile import mkdtemp
  from os.path import exists, join, samefile, lexists
  from shutil import rmtree
  from pylada.gulp import Functional
  from pylada.crystal import Structure
  from pylada.tools import create_directory, get_section_from_file

  functional = Functional()
  functional.morse.enabled     = True
  functional.morse['Ti', 'O']  = [1.0279493, 3.640737, 1.88265, 0, 25]
  functional.morse['Ti', 'Ti'] = [0.00567139, 1.5543, 4.18784, 0, 25]
  functional.morse['O', 'O']   = [0.00567139, 1.5543, 4.18784, 0, 25] 

  structure = Structure( 4.6391, 0, 0,
                         0, 4.6391, 0,
                         0, 0, 2.97938,
                         scale=1, symmgroup=136 )                              \
                .add_atom(0, 0, 0, 'Ti', asymmetric=True)                      \
                .add_atom(2.31955, 2.31955, 1.48969, 'Ti', asymmetric=False)   \
                .add_atom(1.42027, 1.42027, 0, 'O', asymmetric=True)           \
                .add_atom(-1.42027, -1.42027, 0, 'O', asymmetric=False)        \
                .add_atom(-0.899275, 0.899275, 1.48969, 'O', asymmetric=False) \
                .add_atom(0.899275, -0.899275, 1.48969, 'O', asymmetric=False)

  directory = mkdtemp()
  if directory == '/tmp/test/':
    if exists(directory): rmtree(directory)
    create_directory(directory)
  try:
    iterator = functional.iter(structure, outdir=directory)
    assert exists(directory)
    assert not exists(join(directory, 'gulp.out'))
    assert not exists(join(directory, 'gulp.in'))
    assert not exists(join(directory, 'gulp.err'))
    
    program = iterator.next()
    assert exists(join(directory, 'gulp.out'))
    assert exists(join(directory, 'gulp.in'))
    assert not exists(join(directory, 'gulp.err'))
    with open(join(directory, 'gulp.out'), 'r') as file:
      get_section_from_file(file, 'input file')
      get_section_from_file(file, 'functional')

    rmtree(directory)
    create_directory(directory)

    workdir = join(directory, 'wtf')
    iterator = functional.iter( structure, outdir=directory,
                                workdir=workdir )
    assert exists(directory)
    assert not exists(join(directory, 'gulp.out'))
    assert not exists(join(directory, 'gulp.in'))
    assert not exists(join(directory, 'gulp.err'))

    program = iterator.next()
    assert exists(join(directory, 'gulp.out'))
    assert exists(join(directory, 'gulp.in'))
    assert not exists(join(directory, 'gulp.err'))
    with open(join(directory, 'gulp.out'), 'r') as file:
      get_section_from_file(file, 'input file')
      get_section_from_file(file, 'functional')
    assert samefile(workdir, join(directory, 'workdir'))
    assert exists(join(workdir, 'gulp.out'))
    assert samefile(join(workdir, 'gulp.out'), join(directory, 'gulp.out'))
    assert exists(join(workdir, 'gulp.in'))
    assert not samefile(join(workdir, 'gulp.in'), join(directory, 'gulp.in'))
    assert lexists(join(workdir, 'gulp.err'))
    assert exists(join(directory, '.pylada_is_running'))

    program.onfinish()
    assert not exists(join(directory, '.pylada_is_running'))
    assert exists(workdir)
    assert exists(join(directory, 'workdir'))
    assert samefile(join(workdir, 'gulp.out'), join(directory, 'gulp.out'))

  finally:
    if directory != '/tmp/test/': rmtree(directory)