本文整理汇总了Python中diffpy.pdffit2.PdfFit.read_struct方法的典型用法代码示例。如果您正苦于以下问题:Python PdfFit.read_struct方法的具体用法?Python PdfFit.read_struct怎么用?Python PdfFit.read_struct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.pdffit2.PdfFit
的用法示例。
在下文中一共展示了PdfFit.read_struct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: selectNoneExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class selectNoneExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.iset = 1
self.i = 1
def tearDown(self):
del self.P
def test_unassignedError1(self):
"""raise pdffit2.unassignedError when set does not exist"""
self.assertRaises(pdffit2.unassignedError, self.P.selectNone,
self.iset, 'i')
def test_unassignedError2(self):
"""raise pdffit2.unassignedError when set does not exist"""
self.P.read_struct(datafile("Ni.stru"))
# fail when there is no dataset
self.assertRaises(pdffit2.unassignedError, self.P.selectNone,
self.iset, 'i')
# pass with dataset
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.P.selectNone(self.iset, 'i')
self.P.selectNone(self.iset, 'j')
# fail for phase 2
self.assertRaises(pdffit2.unassignedError, self.P.selectNone, 2, 'i')
self.assertRaises(pdffit2.unassignedError, self.P.selectNone, 2, 'j')
示例2: selectAtomIndexExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class selectAtomIndexExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.iset = 1
self.i = 1
def tearDown(self):
del self.P
def test_unassignedError1(self):
"""raise pdffit2.unassignedError when set does not exist"""
self.assertRaises(pdffit2.unassignedError, self.P.selectAtomIndex,
self.iset, 'i', self.i, True)
def test_unassignedError2(self):
"""raise pdffit2.unassignedError when set does not exist"""
self.P.read_struct(datafile("Ni.stru"))
# pass for phase 1
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.P.selectAtomIndex(self.iset, 'i', 1, True)
self.P.selectAtomIndex(self.iset, 'i', 2, False)
# fail for phase 2
self.assertRaises(pdffit2.unassignedError, self.P.selectAtomIndex,
2, 'i', 1, True)
def test_ValueError(self):
"""raise ValueError when selected atom does not exist"""
self.P.read_struct(datafile("Ni.stru"))
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.assertRaises(ValueError, self.P.selectAtomIndex,
self.iset, 'i', 6, True)
示例3: selectAtomTypeExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class selectAtomTypeExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.iset = 1
self.i = 1
def tearDown(self):
del self.P
def test_unassignedError1(self):
"""raise pdffit2.unassignedError when set does not exist"""
self.assertRaises(pdffit2.unassignedError, self.P.selectAtomType,
self.iset, 'i', 'Ni', True)
def test_unassignedError2(self):
"""raise pdffit2.unassignedError when set does not exist"""
self.P.read_struct(datafile("Ni.stru"))
# selectAtomType should pass with one phase defined
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.P.selectAtomType(self.iset, 'i', 'Ni', True)
self.P.selectAtomType(self.iset, 'j', 'Ni', False)
# but fail for phase 2 which is not present
self.assertRaises(pdffit2.unassignedError, self.P.selectAtomType,
2, 'i', 'Ca', True)
def test_ijcharValueError(self):
"""raise ValueError when ijchar is neither 'i' nor 'j'"""
self.P.read_struct(datafile("Ni.stru"))
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.P.selectAtomType(self.iset, 'i', 'Ni', True)
self.P.selectAtomType(self.iset, 'j', 'Ni', True)
self.assertRaises(ValueError, self.P.selectAtomType,
self.iset, 'k', 'Ni', True)
示例4: calcExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class calcExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.P.read_struct(datafile("Ni.stru"))
def tearDown(self):
del self.P
def test_unassignedError(self):
"""raise pdffit2.unassignedError when no space has been allocated"""
self.assertRaises(pdffit2.unassignedError, self.P.calc)
示例5: setdataExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class setdataExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
def tearDown(self):
del self.P
def test_unassignedError(self):
"""raise pdffit2.unassignedError when data set does not exist"""
self.P.read_struct(datafile("Ni.stru"))
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.assertRaises(pdffit2.unassignedError, self.P.setdata, 2)
示例6: pdeselExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class pdeselExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.ip = 1
def tearDown(self):
del self.P
def test_unassignedError1(self):
"""raise pdffit2.unassignedError when phase does not exist"""
self.assertRaises(pdffit2.unassignedError, self.P.pdesel, self.ip)
def test_unassignedError2(self):
"""raise pdffit2.unassignedError when phase does not exist"""
self.P.read_struct(datafile("Ni.stru"))
self.assertRaises(pdffit2.unassignedError, self.P.pdesel, self.ip)
示例7: getparExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class getparExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
def tearDown(self):
del self.P
def test_unassignedError1(self):
"""raise pdffit2.unassignedError when parameter does not exist"""
self.assertRaises(pdffit2.unassignedError, self.P.getpar, 1)
def test_unassignedError2(self):
"""raise pdffit2.unassignedError when parameter does not exist"""
self.P.read_struct(datafile("Ni.stru"))
self.P.constrain(self.P.lat(1), 2)
self.assertRaises(pdffit2.unassignedError, self.P.getpar, 1)
示例8: getvarExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class getvarExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
def tearDown(self):
del self.P
def test_unassignedError(self):
"""raise pdffit2.unassignedError when variable is undefined"""
self.assertRaises(pdffit2.unassignedError, self.P.getvar,
self.P.pscale())
def test_ValueError(self):
"""raise ValueError when a variable index does not exist"""
self.P.read_struct(datafile("Ni.stru"))
self.assertRaises(ValueError, self.P.getvar, self.P.lat(7))
示例9: save_structExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class save_structExceptions(unittest.TestCase):
#Same code as show_struct
def setUp(self):
self.P = PdfFit()
self.strufile = "temp.stru"
def tearDown(self):
del self.P
def test_IOError(self):
"""raise IOError when structure cannot be saved"""
self.P.read_struct(datafile("Ni.stru"))
self.assertRaises(IOError, self.P.save_struct, 1,
"nodir183160/"+self.strufile)
def test_unassignedError(self):
"""raise pdffit2.unassignedError when structure is undefined"""
self.assertRaises(pdffit2.unassignedError, self.P.save_struct, 1,
self.strufile)
示例10: save_pdfExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class save_pdfExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.strufile = "temp.pdf"
def tearDown(self):
del self.P
def test_IOError(self):
"""raise IOError when structure cannot be saved"""
self.P.read_struct(datafile("Ni.stru"))
self.P.alloc('X', 30.0, 0.05, 2, 10, 100)
self.P.calc()
self.assertRaises(IOError, self.P.save_pdf, 1,
"nodir183160/"+self.strufile)
def test_unassignedError(self):
"""raise pdffit2.unassignedError when structure is undefined"""
self.assertRaises(pdffit2.unassignedError, self.P.save_pdf, 1,
self.strufile)
示例11: blenExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class blenExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.a1 = 1
self.a2 = 2
def tearDown(self):
del self.P
def test_unassignedError(self):
"""raise pdffit2.unassignedError when no data exists"""
self.assertRaises(pdffit2.unassignedError, self.P.blen, self.a1,
self.a2)
def test_ValueError1(self):
"""raise ValueError when selected atom(s) does not exist"""
self.P.read_struct(datafile('Ni.stru'))
self.assertRaises(ValueError, self.P.blen, 0, self.a2)
def test_ValueError2(self):
"""raise ValueError when selected atom(s) does not exist"""
self.P.read_struct(datafile('Ni.stru'))
self.assertRaises(ValueError, self.P.blen, self.a1, 6)
def test_ValueError3(self):
"""raise ValueError when selected atom(s) does not exist"""
self.P.read_struct(datafile('Ni.stru'))
self.assertRaises(ValueError, self.P.blen, 0, 6)
示例12: bangExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class bangExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.a1 = 1
self.a2 = 2
self.a3 = 3
def tearDown(self):
del self.P
def test_unassignedError(self):
"""raise pdffit2.unassignedError when phase does not exist"""
self.assertRaises(pdffit2.unassignedError, self.P.bang, self.a1,
self.a2, self.a3)
def test_ValueError1(self):
"""raise ValueError when selected atom(s) does not exist"""
self.P.read_struct(datafile('Ni.stru'))
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.assertRaises(ValueError, self.P.bang, 0,
self.a2, self.a3)
def test_ValueError2(self):
"""raise ValueError when selected atom(s) does not exist"""
self.P.read_struct(datafile('Ni.stru'))
self.assertRaises(ValueError, self.P.bang, self.a1,
-1, self.a3)
def test_ValueError3(self):
"""raise ValueError when selected atom(s) does not exist"""
self.P.read_struct(datafile('Ni.stru'))
self.assertRaises(ValueError, self.P.bang, self.a1,
self.a2, 6)
示例13: save_resExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class save_resExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.resfile = "temp.res"
def tearDown(self):
del self.P
def test_IOError(self):
"""raise IOError when residual file cannot be saved"""
self.P.read_struct(datafile("Ni.stru"))
self.P.read_data(datafile("Ni.dat"), 'X', 30.0, 0.0)
self.P.constrain(self.P.lat(1), 1)
self.P.setpar(1, 3.0)
self.P.pdfrange(1,2.0,10.0)
self.P.refine_step()
self.assertRaises(IOError, self.P.save_res,
"nodir183160/"+self.resfile)
def test_unassignedError(self):
"""raise pdffit2.unassignedError when structure is undefined"""
self.assertRaises(pdffit2.unassignedError, self.P.save_res,
self.resfile)
示例14: constrainExceptions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class constrainExceptions(unittest.TestCase):
def setUp(self):
self.P = PdfFit()
self.par = 1
return
def tearDown(self):
self.P = None
return
def test_constraintError(self):
"""raise constraintError when constraint is bad"""
self.P.read_struct(datafile("Ni.stru"))
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.P.constrain('x(1)', '[email protected]')
self.P.setpar(1, 0.01)
self.assertRaises(pdffit2.constraintError, self.P.calc)
self.assertRaises(pdffit2.constraintError, self.P.refine)
return
def test_unassignedError(self):
"""raise pdffit2.unassignedError when variable is undefined"""
self.assertRaises(pdffit2.unassignedError, self.P.constrain, self.P.x(1),
self.par)
return
def test_ValueError(self):
"""raise ValueError when a variable index does not exist"""
self.P.read_struct(datafile("Ni.stru"))
self.assertRaises(ValueError, self.P.constrain, self.P.x(6),
self.par)
return
def test_constrainNonRefVar(self):
"raise constraintError when attempting to constrain non-refinables"
self.P.read_struct(datafile("Ni.stru"))
self.P.read_data(datafile("Ni.dat"), 'X', 25.0, 0.0)
self.assertRaises(pdffit2.constraintError,
self.P.constrain, 'rcut', '@7')
self.assertRaises(pdffit2.constraintError,
self.P.constrain, 'rcut', 13)
self.assertRaises(pdffit2.constraintError,
self.P.constrain, 'stepcut', '@17')
return
示例15: TestStepCutEnvelope
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import read_struct [as 别名]
class TestStepCutEnvelope(unittest.TestCase):
places = 6
def setUp(self):
self.P = PdfFit()
return
def tearDown(self):
self.P = None
return
def test_stepcut_calculation(self):
"""check calculation of sphere envelope factor
"""
self.P.read_struct(datafile('Ni.stru'))
self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200)
self.P.calc()
stepcut = 8.0
r = numpy.array(self.P.getR())
G0 = numpy.array(self.P.getpdf_fit())
G0[r > stepcut] = 0.0
self.P.setvar('stepcut', stepcut)
self.P.calc()
G1 = numpy.array(self.P.getpdf_fit())
dG = (G0 - G1)
msd = numpy.dot(dG, dG)/len(r)
self.assertAlmostEqual(0.0, numpy.sqrt(msd), self.places)
return
def test_twophase_stepcut_calculation(self):
"""check PDF calculation for 2 phases with different spdiameters
"""
d1 = 6
d2 = 9
self.P.read_struct(datafile('Ni.stru'))
self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200)
self.P.setvar('stepcut', d1)
self.P.calc()
G1 = numpy.array(self.P.getpdf_fit())
self.P.reset()
self.P.read_struct(datafile('PbScW25TiO3.stru'))
self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200)
self.P.setvar('stepcut', d2)
self.P.calc()
G2 = numpy.array(self.P.getpdf_fit())
self.P.reset()
self.P.read_struct(datafile('Ni.stru'))
self.P.read_struct(datafile('PbScW25TiO3.stru'))
self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200)
self.P.setphase(1)
self.P.setvar('stepcut', d1)
self.P.setphase(2)
self.P.setvar('stepcut', d2)
self.P.calc()
Gtot = numpy.array(self.P.getpdf_fit())
dG = (G1 + G2 - Gtot)
r = numpy.array(self.P.getR())
msd = numpy.dot(dG, dG)/len(r)
self.assertAlmostEqual(0.0, numpy.sqrt(msd), self.places)
# G after step should be zero
self.failUnless(numpy.all(0 == Gtot[r > max(d1, d2)]))
return
def test_stepcut_io(self):
"""Check reading and writing of stepcut from structure file.
"""
import re
self.P.read_struct(datafile('Ni.stru'))
self.assertEqual(0.0, self.P.getvar('stepcut'))
# engine should not write shape factor when not defined
sscnone = self.P.save_struct_string(1)
self.failUnless(not re.search('(?m)^shape +stepcut,', sscnone))
self.P.setvar('stepcut', 7)
ssc7 = self.P.save_struct_string(1)
# ssc7 should contain shape factor data
self.failUnless(re.search('(?m)^shape +stepcut,', ssc7))
self.P.reset()
self.P.read_struct_string(ssc7)
self.assertEqual(7.0, self.P.getvar('stepcut'))
# try to read without comma
ssc14 = re.sub('(?m)^shape +stepcut.*$', 'shape stepcut 14.00', ssc7)
self.P.read_struct_string(ssc14)
self.assertEqual(14.0, self.P.getvar('stepcut'))
# try to read invalid shape data
sinvalid = re.sub('(?m)^shape .*', 'shape invalid, 1', ssc7)
self.assertRaises(pdffit2.structureError,
self.P.read_struct_string, sinvalid)
return