当前位置: 首页>>代码示例>>Python>>正文


Python PdfFit.save_struct_string方法代码示例

本文整理汇总了Python中diffpy.pdffit2.PdfFit.save_struct_string方法的典型用法代码示例。如果您正苦于以下问题:Python PdfFit.save_struct_string方法的具体用法?Python PdfFit.save_struct_string怎么用?Python PdfFit.save_struct_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在diffpy.pdffit2.PdfFit的用法示例。


在下文中一共展示了PdfFit.save_struct_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSphereEnvelope

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import save_struct_string [as 别名]

#.........这里部分代码省略.........

    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()
        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', dcheck2)
        self.P.calc()
        G2 = numpy.array(self.P.getpdf_fit())
        r = numpy.array(self.P.getR())
        Gnoise = G1 + G2
        Gnoise[::2] += 0.01
        Gnoise[1::2] -= 0.01
        self.P.reset()
        self.P.read_struct(datafile('Ni.stru'))
        self.P.read_struct(datafile('PbScW25TiO3.stru'))
        self.P.read_data_lists('X', 0.0, 0.05, list(r), list(Gnoise))
        self.P.setphase(1)
        self.P.constrain('spdiameter', '@11')
        self.P.setphase(2)
        self.P.constrain('spdiameter', '@12')
        self.P.setpar(11, dstart1)
        self.P.setpar(12, dstart2)
        self.P.refine()
        dfinal2 = self.P.getvar('spdiameter')
        self.P.setphase(1)
        dfinal1 = self.P.getvar('spdiameter')
        self.assertAlmostEqual(dcheck1, dfinal1, 3)
        self.assertAlmostEqual(dcheck2, dfinal2, 3)
        return


    def test_spdiameter_io(self):
        """Check reading and writing of spdiameter from structure file.
        """
        import re
        self.P.read_struct(datafile('Ni.stru'))
        self.assertEqual(0.0, self.P.getvar('spdiameter'))
        # engine should not write shape factor when not defined
        spdnone = self.P.save_struct_string(1)
        self.failUnless(not re.search('(?m)^shape +sphere,', spdnone))
        self.P.setvar('spdiameter', 7)
        spd7 = self.P.save_struct_string(1)
        # spd7 should contain shape factor data
        self.failUnless(re.search('(?m)^shape +sphere,', spd7))
        self.P.reset()
        self.P.read_struct_string(spd7)
        self.assertEqual(7.0, self.P.getvar('spdiameter'))
        # try to read without comma
        spd14 = re.sub('(?m)^shape +sphere.*$', 'shape sphere 14.00', spd7)
        self.P.read_struct_string(spd14)
        self.assertEqual(14.0, self.P.getvar('spdiameter'))
        # try to read invalid shape data
        sinvalid = re.sub('(?m)^shape .*', 'shape invalid, 1', spd7)
        self.assertRaises(pdffit2.structureError,
                self.P.read_struct_string, sinvalid)
        return
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:104,代码来源:TestShapeFactors.py

示例2: TestStepCutEnvelope

# 需要导入模块: from diffpy.pdffit2 import PdfFit [as 别名]
# 或者: from diffpy.pdffit2.PdfFit import save_struct_string [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
开发者ID:cfarrow,项目名称:diffpy.pdffit2,代码行数:94,代码来源:TestShapeFactors.py


注:本文中的diffpy.pdffit2.PdfFit.save_struct_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。