Package diffpy :: Package pdffit2 :: Package tests :: Module TestPhaseFractions
[hide private]
[frames] | no frames]

Source Code for Module diffpy.pdffit2.tests.TestPhaseFractions

  1  #!/usr/bin/env python 
  2   
  3  """Unit tests for phase fraction calculations. 
  4  """ 
  5   
  6   
  7  import unittest 
  8   
  9  from diffpy.pdffit2 import PdfFit 
 10  from pdffit2testutils import datafile 
 11   
 12  ############################################################################## 
13 -class TestPhaseFractions(unittest.TestCase):
14 15 places = 4 16
17 - def setUp(self):
18 self.P = PdfFit() 19 self.P.read_struct(datafile('Ni.stru')) 20 self.P.read_struct(datafile('PbScW25TiO3.stru')) 21 self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200) 22 self.P.alloc('N', 0.0, 0.05, 0.1, 10, 200) 23 return
24
25 - def tearDown(self):
26 del self.P 27 return
28
29 - def test_xray_fractions(self):
30 """test_xray_fractions -- check phase fractions in x-ray dataset. 31 """ 32 self.P.setdata(1) 33 ph = self.P.phase_fractions() 34 bb1 = 28**2 35 bb2 = ((8*82 + 24*8 + 4*21 + 2*74 + 2*22) / 40.0)**2 36 self.assertAlmostEqual(1.0, sum(ph['atom']), self.places) 37 self.assertAlmostEqual(1.0, sum(ph['cell']), self.places) 38 self.assertAlmostEqual(1.0, sum(ph['mass']), self.places) 39 self.assertAlmostEqual(bb2/bb1, 40 ph['atom'][0]/ph['atom'][1], self.places) 41 self.assertAlmostEqual(bb2/bb1 * 40.0/4.0, 42 ph['cell'][0]/ph['cell'][1], self.places) 43 mavg1 = 58.69 44 mavg2 = (8*207.19 + 24*15.994 + 4*44.956 + 2*183.85 + 2*47.90)/40.0 45 self.assertAlmostEqual(bb2/bb1 * mavg1/mavg2, 46 ph['mass'][0]/ph['mass'][1], self.places) 47 self.assertEqual(0.0, sum(ph['stdatom'])) 48 self.assertEqual(0.0, sum(ph['stdcell'])) 49 self.assertEqual(0.0, sum(ph['stdmass'])) 50 self.P.setphase(1) 51 self.P.setvar('pscale', 2.0) 52 ph2 = self.P.phase_fractions() 53 self.assertAlmostEqual(1.0, sum(ph2['atom']), self.places) 54 self.assertAlmostEqual(1.0, sum(ph2['cell']), self.places) 55 self.assertAlmostEqual(1.0, sum(ph2['mass']), self.places) 56 self.assertAlmostEqual(2.0, ph2['atom'][0]/ph2['atom'][1] / 57 (ph['atom'][0]/ph['atom'][1]), self.places) 58 self.assertAlmostEqual(2.0, ph2['cell'][0]/ph2['cell'][1] / 59 (ph['cell'][0]/ph['cell'][1]), self.places) 60 self.assertAlmostEqual(2.0, ph2['mass'][0]/ph2['mass'][1] / 61 (ph['mass'][0]/ph['mass'][1]), self.places) 62 return
63
64 - def test_neutron_fractions(self):
65 """test_neutron_fractions -- check phase fractions in neutron dataset. 66 """ 67 self.P.setdata(2) 68 ph = self.P.phase_fractions() 69 bb1 = 10.31**2 70 bPb = 9.4012 71 bO = 5.8054 72 bSc = 12.11 73 bW = 4.75518 74 bTi = -3.37013 75 bb2 = ((8*bPb + 24*bO + 4*bSc + 2*bW + 2*bTi) / 40.0)**2 76 self.assertAlmostEqual(1.0, sum(ph['atom']), self.places) 77 self.assertAlmostEqual(1.0, sum(ph['cell']), self.places) 78 self.assertAlmostEqual(1.0, sum(ph['mass']), self.places) 79 self.assertAlmostEqual(bb2/bb1, 80 ph['atom'][0]/ph['atom'][1], self.places) 81 self.assertAlmostEqual(bb2/bb1 * 40.0/4.0, 82 ph['cell'][0]/ph['cell'][1], self.places) 83 mavg1 = 58.69 84 mavg2 = (8*207.19 + 24*15.994 + 4*44.956 + 2*183.85 + 2*47.90)/40.0 85 self.assertAlmostEqual(bb2/bb1 * mavg1/mavg2, 86 ph['mass'][0]/ph['mass'][1], self.places) 87 self.assertEqual(0.0, sum(ph['stdatom'])) 88 self.assertEqual(0.0, sum(ph['stdcell'])) 89 self.assertEqual(0.0, sum(ph['stdmass'])) 90 self.P.setphase(1) 91 self.P.setvar('pscale', 2.0) 92 ph2 = self.P.phase_fractions() 93 self.assertAlmostEqual(1.0, sum(ph2['atom']), self.places) 94 self.assertAlmostEqual(1.0, sum(ph2['cell']), self.places) 95 self.assertAlmostEqual(1.0, sum(ph2['mass']), self.places) 96 self.assertAlmostEqual(2.0, ph2['atom'][0]/ph2['atom'][1] / 97 (ph['atom'][0]/ph['atom'][1]), self.places) 98 self.assertAlmostEqual(2.0, ph2['cell'][0]/ph2['cell'][1] / 99 (ph['cell'][0]/ph['cell'][1]), self.places) 100 self.assertAlmostEqual(2.0, ph2['mass'][0]/ph2['mass'][1] / 101 (ph['mass'][0]/ph['mass'][1]), self.places) 102 return
103 104 # End of class TestSphereEnvelope 105 106 if __name__ == '__main__': 107 unittest.main() 108 109 # End of file 110