本文整理汇总了Python中diffpy.srreal.pdfcalculator.PDFCalculator.rstep方法的典型用法代码示例。如果您正苦于以下问题:Python PDFCalculator.rstep方法的具体用法?Python PDFCalculator.rstep怎么用?Python PDFCalculator.rstep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffpy.srreal.pdfcalculator.PDFCalculator
的用法示例。
在下文中一共展示了PDFCalculator.rstep方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGenerator
# 需要导入模块: from diffpy.srreal.pdfcalculator import PDFCalculator [as 别名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import rstep [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
示例2: gr_lib_build
# 需要导入模块: from diffpy.srreal.pdfcalculator import PDFCalculator [as 别名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import rstep [as 别名]
def gr_lib_build(self, cif_lib_path):
''' method to calculate G(r) based on path of cif library located at.
Paramters of G(r) calculation are set via glbl.<attribute>, one can tune it based on purpose of building library.
After entire method, text file contains all G(r), space_group_symbol and material name will be saved respectively
Parameters
----------
cif_lib_path : str
path to lib of cif files
'''
el_list = [] # data column
space_group_symbol_list = [] # reference for search have been done in the past
# set up calculation environment
#dbc = DebyePDFCalculator()
pdf = PDFCalculator()
pdf.rstep = glbl.rstep
cfg = {'qmin': glbl.q_min, 'qmax':glbl.q_max, 'rmin':glbl.r_min, 'rmax': glbl.r_max}
Bisoequiv = glbl.Bisoequiv #FIXME: current value = 0.5, need to figure out the most suitable value
print('====Parameter used in this PDF calculator is: {}===='.format(cfg))
print('====Bisoequiv used in this PDF calculator is: {}===='.format(Bisoequiv))
# step 1: list cif dir
output_dir = os.path.join(self.data_dir, 'lib_data')
self._makedirs(output_dir)
self.output_dir = output_dir
cif_f_list = [ f for f in os.listdir(self.cif_dir)]
# hidden step as numpy can't take an empty array and stack
struc = loadStructure(os.path.join(self.cif_dir, cif_f_list[0]))
struc.Bisoequiv = Bisoequiv
(r,g) = pdf(nosymmetry(struc), **cfg)
r_grid = np.array(r) # data x-axis
gr_list = np.empty_like(np.array(g)) # data y-axis
for cif in cif_f_list:
# part 2: calculate PDF with diffpy
struc = loadStructure(os.path.join(self.cif_dir, cif))
struc.Bisoequiv = Bisoequiv
#(r,g) = pdf(nosymmetry(struc), **cfg)
(r,g) = pdf(struc, **cfg)
print('Finished calculation of G(r) on {}'.format(cif))
sep = cif.index('_')
space_group_symbol = cif[:sep]
m_name = cif[sep+1:]
# part 3: save data
#if not gr_list.any():
#gr_list = np.append(gr_list, g)
gr_list = np.vstack((gr_list,g))
space_group_symbol_list.append(space_group_symbol)
el_list.append(m_name)
#print('size of gr_list = {}'.format(np.shape(gr_list)))
#space_group_symbol_list = np.concatenate([space_group_symbol_list, space_group_symbol], axis=0)
#el_list = np.concatenate([el_list, m_name], axis=0)
time_info = time.strftime('%Y-%m-%d')
gr_list_name = '{}_{}_Gr'.format(self.crystal_system, time_info)
gr_list_w_name = os.path.join(output_dir, gr_list_name)
print('Saving {}'.format(gr_list_w_name))
np.save(gr_list_w_name, gr_list)
r_grid_name = '{}_{}_rgrid'.format(self.crystal_system, time_info)
r_grid_w_name = os.path.join(output_dir, r_grid_name)
np.save(r_grid_w_name, r)
space_group_symbol_list_name = '{}_{}_SpaceGroupSymbol'.format(self.crystal_system, time_info)
space_group_symbol_list_w_name= os.path.join(output_dir, space_group_symbol_list_name)
np.save(space_group_symbol_list_w_name, space_group_symbol_list) #fmt="%s")
el_list_name = '{}_{}_Element'.format(self.crystal_system, time_info)
el_list_w_name = os.path.join(output_dir, el_list_name)
np.save(el_list_w_name, el_list) #fmt="%s")
print('''====SUMMARY====:
for {} cystsal sytem,
Number of cif pulled out and G(r) calculated is {}'''.format(self.crystal_system, np.shape(gr_list)))
return gr_list