本文整理汇总了Python中diffpy.pdffit2.PdfFit.setvar方法的典型用法代码示例。如果您正苦于以下问题:Python PdfFit.setvar方法的具体用法?Python PdfFit.setvar怎么用?Python PdfFit.setvar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.pdffit2.PdfFit
的用法示例。
在下文中一共展示了PdfFit.setvar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import setvar [as 别名]
def calculate(self):
"""do the real calculation
"""
# clean up old results
self.rcalc = []
self.Gcalc = []
# do the job
if len(self.owner.strucs) == 0:
raise ControlConfigError("No structure is given for calculation")
# make sure parameters are initialized
self.owner.updateParameters()
from diffpy.pdffit2 import PdfFit
server = PdfFit()
# structure needs to be read before dataset allocation
for struc in self.owner.strucs:
server.read_struct_string(struc.writeStr('pdffit'))
for key,var in struc.constraints.items():
server.constrain(key.encode('ascii'), var.formula.encode('ascii'))
# set up dataset
server.alloc(self.stype, self.qmax, self.qdamp,
self.rmin, self.rmax, self.rlen)
server.setvar('qbroad', self.qbroad)
server.setvar('dscale', self.dscale)
# phase related variables
# pair selection applies to current dataset,
# therefore it has to be done after alloc
nstrucs = len(self.owner.strucs)
for phaseidx0, struc in enumerate(self.owner.strucs):
phaseidx1 = phaseidx0 + 1
server.setphase(phaseidx1)
server.setvar('pscale', struc.getvar('pscale'))
server.setvar('spdiameter', struc.getvar('spdiameter'))
struc.applyPairSelection(server, phaseidx1)
# set up parameters
for index, par in self.owner.parameters.items():
server.setpar(index, par.initialValue()) # info[0] = init value
# fix if fixed. Note: all parameters are free after server.reset().
if par.fixed:
server.fixpar(index)
# all ready here
server.calc()
# get results
self.rcalc = server.getR()
self.Gcalc = server.getpdf_fit()
示例2: TestPhaseFractions
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import setvar [as 别名]
class TestPhaseFractions(unittest.TestCase):
places = 4
def setUp(self):
self.P = PdfFit()
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.alloc('N', 0.0, 0.05, 0.1, 10, 200)
return
def tearDown(self):
del self.P
return
def test_xray_fractions(self):
"""test_xray_fractions -- check phase fractions in x-ray dataset.
"""
self.P.setdata(1)
ph = self.P.phase_fractions()
bb1 = 28**2
bb2 = ((8*82 + 24*8 + 4*21 + 2*74 + 2*22) / 40.0)**2
self.assertAlmostEqual(1.0, sum(ph['atom']), self.places)
self.assertAlmostEqual(1.0, sum(ph['cell']), self.places)
self.assertAlmostEqual(1.0, sum(ph['mass']), self.places)
self.assertAlmostEqual(bb2/bb1,
ph['atom'][0]/ph['atom'][1], self.places)
self.assertAlmostEqual(bb2/bb1 * 40.0/4.0,
ph['cell'][0]/ph['cell'][1], self.places)
mavg1 = 58.69
mavg2 = (8*207.19 + 24*15.994 + 4*44.956 + 2*183.85 + 2*47.90)/40.0
self.assertAlmostEqual(bb2/bb1 * mavg1/mavg2,
ph['mass'][0]/ph['mass'][1], self.places)
self.assertEqual(0.0, sum(ph['stdatom']))
self.assertEqual(0.0, sum(ph['stdcell']))
self.assertEqual(0.0, sum(ph['stdmass']))
self.P.setphase(1)
self.P.setvar('pscale', 2.0)
ph2 = self.P.phase_fractions()
self.assertAlmostEqual(1.0, sum(ph2['atom']), self.places)
self.assertAlmostEqual(1.0, sum(ph2['cell']), self.places)
self.assertAlmostEqual(1.0, sum(ph2['mass']), self.places)
self.assertAlmostEqual(2.0, ph2['atom'][0]/ph2['atom'][1] /
(ph['atom'][0]/ph['atom'][1]), self.places)
self.assertAlmostEqual(2.0, ph2['cell'][0]/ph2['cell'][1] /
(ph['cell'][0]/ph['cell'][1]), self.places)
self.assertAlmostEqual(2.0, ph2['mass'][0]/ph2['mass'][1] /
(ph['mass'][0]/ph['mass'][1]), self.places)
return
def test_neutron_fractions(self):
"""test_neutron_fractions -- check phase fractions in neutron dataset.
"""
self.P.setdata(2)
ph = self.P.phase_fractions()
bb1 = 10.31**2
bPb = 9.4012
bO = 5.8054
bSc = 12.11
bW = 4.75518
bTi = -3.37013
bb2 = ((8*bPb + 24*bO + 4*bSc + 2*bW + 2*bTi) / 40.0)**2
self.assertAlmostEqual(1.0, sum(ph['atom']), self.places)
self.assertAlmostEqual(1.0, sum(ph['cell']), self.places)
self.assertAlmostEqual(1.0, sum(ph['mass']), self.places)
self.assertAlmostEqual(bb2/bb1,
ph['atom'][0]/ph['atom'][1], self.places)
self.assertAlmostEqual(bb2/bb1 * 40.0/4.0,
ph['cell'][0]/ph['cell'][1], self.places)
mavg1 = 58.69
mavg2 = (8*207.19 + 24*15.994 + 4*44.956 + 2*183.85 + 2*47.90)/40.0
self.assertAlmostEqual(bb2/bb1 * mavg1/mavg2,
ph['mass'][0]/ph['mass'][1], self.places)
self.assertEqual(0.0, sum(ph['stdatom']))
self.assertEqual(0.0, sum(ph['stdcell']))
self.assertEqual(0.0, sum(ph['stdmass']))
self.P.setphase(1)
self.P.setvar('pscale', 2.0)
ph2 = self.P.phase_fractions()
self.assertAlmostEqual(1.0, sum(ph2['atom']), self.places)
self.assertAlmostEqual(1.0, sum(ph2['cell']), self.places)
self.assertAlmostEqual(1.0, sum(ph2['mass']), self.places)
self.assertAlmostEqual(2.0, ph2['atom'][0]/ph2['atom'][1] /
(ph['atom'][0]/ph['atom'][1]), self.places)
self.assertAlmostEqual(2.0, ph2['cell'][0]/ph2['cell'][1] /
(ph['cell'][0]/ph['cell'][1]), self.places)
self.assertAlmostEqual(2.0, ph2['mass'][0]/ph2['mass'][1] /
(ph['mass'][0]/ph['mass'][1]), self.places)
return
示例3: TestSphereEnvelope
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import setvar [as 别名]
class TestSphereEnvelope(unittest.TestCase):
places = 6
def setUp(self):
self.P = PdfFit()
return
def tearDown(self):
self.P = None
return
def test_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()
d = 8.0
r = numpy.array(self.P.getR())
G0 = numpy.array(self.P.getpdf_fit())
self.P.setvar('spdiameter', d)
self.P.calc()
G1 = numpy.array(self.P.getpdf_fit())
dG = (G0*spherefactor(r, d) - G1)
msd = numpy.dot(dG, dG)/len(r)
self.assertAlmostEqual(0.0, numpy.sqrt(msd), self.places)
return
def test_refinement(self):
"""check refinement of sphere envelope factor
"""
dcheck = 8.0
dstart = 12.0
self.P.read_struct(datafile('Ni.stru'))
self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200)
self.P.setvar('spdiameter', dcheck)
self.P.calc()
r = numpy.array(self.P.getR())
Gd8 = numpy.array(self.P.getpdf_fit())
Gd8noise = Gd8
Gd8noise[::2] += 0.01
Gd8noise[1::2] -= 0.01
self.P.reset()
self.P.read_struct(datafile('Ni.stru'))
self.P.read_data_lists('X', 0.0, 0.05, list(r), list(Gd8noise))
self.P.constrain('spdiameter', '@8')
self.P.setpar(8, dstart)
self.P.refine()
dfinal = self.P.getvar('spdiameter')
self.assertAlmostEqual(dcheck, dfinal, 3)
return
def test_twophase_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('spdiameter', 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('spdiameter', 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('spdiameter', d1)
self.P.setphase(2)
self.P.setvar('spdiameter', 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)
return
def test_twophase_refinement(self):
"""check PDF refinement of 2 phases that have different spdiameter.
"""
dcheck1 = 8.0
dstart1 = 8.2
dcheck2 = 6.0
dstart2 = 5.5
self.P.read_struct(datafile('Ni.stru'))
self.P.alloc('X', 0.0, 0.05, 0.1, 10, 200)
self.P.setvar('spdiameter', dcheck1)
self.P.calc()
#.........这里部分代码省略.........
示例4: TestStepCutEnvelope
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import setvar [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
示例5: TestPdfFit
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import setvar [as 别名]
#.........这里部分代码省略.........
self.assertEqual([], self.P.getcrw())
self.P.read_struct(datafile('Ni.stru'))
self.P.pdfrange(1, 2, 19)
self.P.refine()
crw19 = numpy.array(self.P.getcrw())
self.failUnless(numpy.all(crw19 >= 0.0))
# check that crw19 is non decreasing
self.failUnless(numpy.all(numpy.diff(crw19) >= 0.0))
# check that crw19 and getrw give the same value
rw19 = crw19[-1]
self.assertAlmostEqual(self.P.getrw(), rw19, self.places)
# renormalize cumulative Rw and compare with Rw at r=15
Gobs19 = numpy.array(self.P.getpdf_obs())
Gnorm19 = numpy.sqrt(numpy.sum(Gobs19**2))
r = numpy.array(self.P.getR())
idx = numpy.nonzero(r <= 15)[0]
Gnorm15 = numpy.sqrt(numpy.sum(Gobs19[idx]**2))
i15 = idx[-1]
rw15 = crw19[i15] * Gnorm19 / Gnorm15
self.P.pdfrange(1, 2, r[i15] + 1e-5)
self.P.refine()
self.assertAlmostEqual(self.P.getrw(), rw15, self.places)
return
def test_getcrw_two_datasets(self):
"""check that getcrw() and getrw() are consistent for two datasets.
"""
self.P.read_data(datafile('Ni.dat'), 'X', 25.0, 0.0)
self.P.pdfrange(1, 2, 8)
self.P.read_data(datafile('300K.gr'), 'N', 32.0, 0.0)
self.P.pdfrange(2, 1, 11)
self.P.read_struct(datafile('Ni.stru'))
# mess lattice parameters to have comparable Rw contributions
self.P.setvar('lat(1)', 3)
self.P.setvar('lat(2)', 3)
self.P.setvar('lat(3)', 3)
self.P.refine()
rwtot = self.P.getrw()
self.failUnless(rwtot > 0.0)
self.P.setdata(1)
rw1 = self.P.getcrw()[-1]
self.P.setdata(2)
rw2 = self.P.getcrw()[-1]
self.assertAlmostEqual(rwtot**2, rw1**2 + rw2**2, self.places)
return
# def test_getpar(self):
# """check PdfFit.getpar()
# """
# return
#
# def test_fixpar(self):
# """check PdfFit.fixpar()
# """
# return
#
# def test_freepar(self):
# """check PdfFit.freepar()
# """
# return
#
# def test_setphase(self):
# """check PdfFit.setphase()
# """
# return
#