本文整理汇总了Python中diffpy.srreal.pdfcalculator.PDFCalculator.eval方法的典型用法代码示例。如果您正苦于以下问题:Python PDFCalculator.eval方法的具体用法?Python PDFCalculator.eval怎么用?Python PDFCalculator.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.srreal.pdfcalculator.PDFCalculator
的用法示例。
在下文中一共展示了PDFCalculator.eval方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _makePDFCalculator
# 需要导入模块: from diffpy.srreal.pdfcalculator import PDFCalculator [as 别名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import eval [as 别名]
def _makePDFCalculator(crst, cfgdict):
'''Return a PDFCalculator object evaluated for a pyobjcryst.Crystal crst.
'''
inpdfcalc = lambda kv: kv[0] not in ('biso', 'type')
pdfcargs = dict(filter(inpdfcalc, cfgdict.items()))
pdfc = PDFCalculator(**pdfcargs)
if 'biso' in cfgdict:
setbiso = lambda sc: sc.mpScattPow.SetBiso(cfgdict['biso'])
map(setbiso, crst.GetScatteringComponentList())
if 'type' in cfgdict:
pdfc.scatteringfactortable = cfgdict['type']
pdfc.eval(crst)
# avoid metadata override by PDFFitStructure
for k, v in pdfcargs.items():
setattr(pdfc, k, v)
return pdfc
示例2: testGenerator
# 需要导入模块: from diffpy.srreal.pdfcalculator import PDFCalculator [as 别名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import eval [as 别名]
def testGenerator(self):
qmax = 27.0
gen = PDFGenerator()
gen.setScatteringType('N')
self.assertEqual('N', gen.getScatteringType())
gen.setQmax(qmax)
self.assertAlmostEqual(qmax, gen.getQmax())
from diffpy.Structure import PDFFitStructure
stru = PDFFitStructure()
ciffile = datafile("ni.cif")
stru.read(ciffile)
for i in range(4):
stru[i].Bisoequiv = 1
gen.setStructure(stru)
calc = gen._calc
# Test parameters
for par in gen.iterPars(recurse = False):
pname = par.name
defval = calc._getDoubleAttr(pname)
self.assertEquals(defval, par.getValue())
# Test setting values
par.setValue(1.0)
self.assertEquals(1.0, par.getValue())
par.setValue(defval)
self.assertEquals(defval, par.getValue())
r = numpy.arange(0, 10, 0.1)
y = gen(r)
# Now create a reference PDF. Since the calculator is testing its
# output, we just have to make sure we can calculate from the
# PDFGenerator interface.
from diffpy.srreal.pdfcalculator import PDFCalculator
calc = PDFCalculator()
calc.rstep = r[1] - r[0]
calc.rmin = r[0]
calc.rmax = r[-1] + 0.5 * calc.rstep
calc.qmax = qmax
calc.setScatteringFactorTableByType('N')
calc.eval(stru)
yref = calc.pdf
diff = y - yref
res = numpy.dot(diff, diff)
self.assertAlmostEquals(0, res)
return
示例3: _makePDFCalculator
# 需要导入模块: from diffpy.srreal.pdfcalculator import PDFCalculator [as 别名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import eval [as 别名]
def _makePDFCalculator(crst, cfgdict):
'''Return a PDFCalculator object evaluated for a pyobjcryst.Crystal crst.
'''
pdfcargs = {k : v for k, v in cfgdict.items()
if k not in ('biso', 'type')}
pdfc = PDFCalculator(**pdfcargs)
if 'biso' in cfgdict:
reg = crst.GetScatteringPowerRegistry()
for i in range(reg.GetNb()):
sp = reg.GetObj(i)
sp.SetBiso(cfgdict['biso'])
if 'type' in cfgdict:
pdfc.scatteringfactortable = cfgdict['type']
pdfc.eval(crst)
# avoid metadata override by PDFFitStructure
for k, v in pdfcargs.items():
setattr(pdfc, k, v)
return pdfc
示例4: TestPDFCalculator
# 需要导入模块: from diffpy.srreal.pdfcalculator import PDFCalculator [as 别名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import eval [as 别名]
class TestPDFCalculator(unittest.TestCase):
nickel = None
tio2rutile = None
def setUp(self):
self.pdfcalc = PDFCalculator()
if not self.nickel:
type(self).nickel = loadDiffPyStructure('Ni.stru')
if not self.tio2rutile:
type(self).tio2rutile = (
loadDiffPyStructure('TiO2_rutile-fit.stru'))
return
def tearDown(self):
return
def test___init__(self):
"""check PDFCalculator.__init__()
"""
pdfc = PDFCalculator(qmin=13, rmin=4, rmax=99)
self.assertEqual(13, pdfc.qmin)
self.assertEqual(4, pdfc.rmin)
self.assertEqual(99, pdfc.rmax)
self.assertEqual(99, pdfc._getDoubleAttr('rmax'))
return
def test___call__(self):
"""Check PDFCalculator.__call__()
"""
from diffpy.Structure import Structure
r0, g0 = self.pdfcalc(self.tio2rutile, rmin=2)
self.assertEqual(2.0, r0[0])
r1, g1 = self.pdfcalc(self.tio2rutile, scale=7)
self.assertAlmostEqual(7.0, g1[0] / g0[0])
# check application of spdiameter
rutile2 = Structure(self.tio2rutile)
# work around Structure bug of shared pdffit dictionary
rutile2.pdffit = dict(self.tio2rutile.pdffit)
rutile2.pdffit['spdiameter'] = 5.0
r3, g3 = self.pdfcalc(rutile2)
self.assertEqual(0.0, sum(g3[r3 >= 5] ** 2))
r4, g4 = self.pdfcalc(rutile2, scale=1, spdiameter=0)
self.failUnless(numpy.all(r4 == r0))
self.failUnless(numpy.all(g4 == g0))
return
def test__getDoubleAttr(self):
"""check PDFCalculator._getDoubleAttr()
"""
gdba = self.pdfcalc._getDoubleAttr
self.assertEqual(1.0, gdba('scale'))
self.assertEqual(0.0, gdba('qdamp'))
self.assertRaises(Exception, gdba, 'notanattribute')
return
def test__hasDoubleAttr(self):
"""check PDFCalculator._hasDoubleAttr()
"""
self.failUnless(self.pdfcalc._hasDoubleAttr('scale'))
self.failIf(self.pdfcalc._hasDoubleAttr('notanattribute'))
return
def test__namesOfDoubleAttributes(self):
"""check PDFCalculator._namesOfDoubleAttributes()
"""
self.failUnless(type(self.pdfcalc._namesOfDoubleAttributes()) is set)
self.failUnless('qmax' in self.pdfcalc._namesOfDoubleAttributes())
return
def test__setDoubleAttr(self):
"""check PDFCalculator._setDoubleAttr()
"""
gdba = self.pdfcalc._getDoubleAttr
sdba = self.pdfcalc._setDoubleAttr
self.assertEqual(0.0, gdba('rmin'))
sdba('rmin', 3.0)
self.assertEqual(3.0, gdba('rmin'))
return
def test_eval_nickel(self):
"""check PDFCalculator.eval() on simple Nickel data
"""
fnipf2 = datafile('Ni-fit.fgr')
gpf2 = numpy.loadtxt(fnipf2, usecols=(1,))
self.pdfcalc._setDoubleAttr('rmax', 10.0001)
self.pdfcalc.eval(self.nickel)
gcalc = self.pdfcalc.pdf
self.failUnless(_maxNormDiff(gpf2, gcalc) < 0.0091)
return
def test_eval_rutile(self):
"""check PDFCalculator.eval() on anisotropic rutile data
"""
frutile = datafile('TiO2_rutile-fit.fgr')
gpf2 = numpy.loadtxt(frutile, usecols=(1,))
# configure calculator according to testdata/TiO2_ruitile-fit.fgr
self.pdfcalc.qmax = 26
self.pdfcalc.qdamp = 0.0665649
dscale = 0.655857
#.........这里部分代码省略.........