本文整理汇总了Python中diffpy.pdffit2.PdfFit.getR方法的典型用法代码示例。如果您正苦于以下问题:Python PdfFit.getR方法的具体用法?Python PdfFit.getR怎么用?Python PdfFit.getR使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.pdffit2.PdfFit
的用法示例。
在下文中一共展示了PdfFit.getR方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import getR [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: TestSphereEnvelope
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import getR [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()
#.........这里部分代码省略.........
示例3: TestStepCutEnvelope
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import getR [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
示例4: TestPdfFit
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import getR [as 别名]
class TestPdfFit(unittest.TestCase):
places = 6
def setUp(self):
self.P = PdfFit()
return
def tearDown(self):
del self.P
return
# def test_intro(self):
# """check PdfFit.intro()
# """
# return
def test_add_structure(self):
"""check PdfFit.add_structure()
"""
# skip test when diffpy.Structure is not installed
try:
from diffpy.Structure import Structure
except ImportError:
return
ni = Structure(filename=datafile('Ni.stru'))
self.P.add_structure(ni)
self.assertEqual(4, self.P.num_atoms())
return
# def test_read_struct(self):
# """check PdfFit.read_struct()
# """
# return
#
# def test_read_struct_string(self):
# """check PdfFit.read_struct_string()
# """
# return
#
# def test_read_data(self):
# """check PdfFit.read_data()
# """
# return
#
# def test_read_data_string(self):
# """check PdfFit.read_data_string()
# """
# return
#
# def test_read_data_lists(self):
# """check PdfFit.read_data_lists()
# """
# return
#
# def test_pdfrange(self):
# """check PdfFit.pdfrange()
# """
# return
#
# def test_reset(self):
# """check PdfFit.reset()
# """
# return
def test_alloc(self):
"""check PdfFit.alloc()
"""
# alloc and read_struct can be called in any order.
self.P.alloc('X', 25, 0.0, 0.01, 10, 1000)
# without a structure calculated PDF is all zero
self.P.calc()
Gzero = self.P.getpdf_fit()
self.assertEqual(1000*[0.0], Gzero)
self.P.read_struct(datafile('Ni.stru'))
self.P.calc()
# check r-values
r = self.P.getR()
self.assertEqual(1000, len(r))
for i in range(1000):
self.assertAlmostEqual(0.01*(i + 1), r[i], self.places)
Gfit_alloc_read = self.P.getpdf_fit()
# now try the other order
self.P.reset()
self.P.read_struct(datafile('Ni.stru'))
self.P.alloc('X', 25, 0.0, 0.01, 10, 1000)
self.P.calc()
Gfit_read_alloc = self.P.getpdf_fit()
# and they should be the same
self.assertEqual(Gfit_read_alloc, Gfit_alloc_read)
return
# def test_calc(self):
# """check PdfFit.calc()
# """
# return
#
# def test_refine(self):
# """check PdfFit.refine()
# """
#.........这里部分代码省略.........
示例5: PdfFit
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import getR [as 别名]
# create new PDF calculator object
P = PdfFit()
# load structure file in PDFFIT or DISCUS format
P.read_struct("Ni.stru")
radiation_type = 'X' # x-rays
qmax = 30.0 # Q-cutoff used in PDF calculation in 1/A
qdamp = 0.01 # instrument Q-resolution factor, responsible for PDF decay
rmin = 0.01 # minimum r-value
rmax = 30.0 # maximum r-value
npts = 3000 # number of points in the r-grid
# allocate and configure PDF calculation
P.alloc(radiation_type, qmax, qdamp, rmin, rmax, npts)
P.calc()
# obtain list of r-points and corresponding G values
r = P.getR()
G = P.getpdf_fit()
# pylab is matplotlib interface with MATLAB-like plotting commands
import pylab
pylab.plot(r, G)
pylab.xlabel('r ($\AA$)')
pylab.ylabel('G ($\AA^{-2}$)')
pylab.title('x-ray PDF of nickel simulated at Qmax = %g' % qmax)
# display plot window, this must be the last command in the script
pylab.show()
示例6:
# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import getR [as 别名]
pf.pdfrange(1, 1.5, 19.99)
pf.refine()
# Save results ---------------------------------------------------------------
pf.save_pdf(1, "Ni_refinement.fgr")
pf.save_struct(1, "Ni_refinement.rstr")
pf.save_res("Ni_refinement.res")
# Plot results ---------------------------------------------------------------
# pylab is matplotlib interface with MATLAB-like plotting commands
import pylab
# obtain data from PdfFit calculator object
r = pf.getR()
Gobs = pf.getpdf_obs()
Gfit = pf.getpdf_fit()
# calculate difference curve, with pylab arrays it can be done
# without for loop
Gdiff = pylab.array(Gobs) - pylab.array(Gfit)
Gdiff_baseline = -10
pylab.plot(r, Gobs, 'ko')
pylab.plot(r, Gfit, 'b-')
pylab.plot(r, Gdiff + Gdiff_baseline, 'r-')
pylab.xlabel('r ($\AA$)')
pylab.ylabel('G ($\AA^{-2}$)')
pylab.title('Fit of nickel to x-ray experimental PDF')