Esempio n. 1
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)