當前位置: 首頁>>代碼示例>>Python>>正文


Python PDFCalculator.getPairMask方法代碼示例

本文整理匯總了Python中diffpy.srreal.pdfcalculator.PDFCalculator.getPairMask方法的典型用法代碼示例。如果您正苦於以下問題:Python PDFCalculator.getPairMask方法的具體用法?Python PDFCalculator.getPairMask怎麽用?Python PDFCalculator.getPairMask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在diffpy.srreal.pdfcalculator.PDFCalculator的用法示例。


在下文中一共展示了PDFCalculator.getPairMask方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestPDFCalculator

# 需要導入模塊: from diffpy.srreal.pdfcalculator import PDFCalculator [as 別名]
# 或者: from diffpy.srreal.pdfcalculator.PDFCalculator import getPairMask [as 別名]

#.........這裏部分代碼省略.........
        # O-O
        pdfc.maskAllPairs(False)
        for i, smbli in enumerate(atomtypes):
            for j, smblj in enumerate(atomtypes):
                if smbli == smblj == "O":
                    pdfc.setPairMask(i, j, True)
        r3, g3 = pdfc(rutile)
        rdf3 = pdfc.rdf
        pdfc.invertMask()
        r3i, g3i = pdfc(rutile)
        rdf3i = pdfc.rdf
        self.failUnless(numpy.allclose(g0, g3 + g3i))
        self.failUnless(numpy.allclose(rdf0, rdf3 + rdf3i))
        # check the sum of all partials
        self.failUnless(numpy.allclose(g0, g1 + g2 + g3))
        self.failUnless(numpy.allclose(rdf0, rdf1 + rdf2 + rdf3))
        return

    def test_full_mask(self):
        '''Test PDFCalculator for a fully masked structure.
        '''
        pdfc = self.pdfcalc
        pdfc.rstep = 0.1
        rutile = self.tio2rutile
        pdfc.maskAllPairs(True)
        r0, g0 = pdfc(rutile)
        pdfc.maskAllPairs(False)
        r1, g1 = pdfc(rutile)
        self.assertEqual(0.0, numpy.dot(g1, g1))
        indices = range(len(rutile))
        pdfc.setPairMask(indices, indices, True)
        r2, g2 = pdfc(rutile)
        self.failUnless(numpy.array_equal(g0, g2))
        return

    def test_zero_mask(self):
        '''Test PDFCalculator with a totally masked out structure.
        '''
        pdfc = self.pdfcalc
        pdfc.rstep = 0.1
        rutile = self.tio2rutile
        indices = range(len(rutile))
        for i in indices:
            for j in indices:
                pdfc.setPairMask(i, j, False)
        r, g = pdfc(rutile)
        self.assertEqual(0.0, numpy.dot(g, g))
        rdf = pdfc.rdf
        self.assertEqual(0.0, numpy.dot(rdf, rdf))
        return

    def test_pickling(self):
        '''check pickling and unpickling of PDFCalculator.
        '''
        pdfc = self.pdfcalc
        pdfc.setScatteringFactorTableByType('N')
        pdfc.scatteringfactortable.setCustomAs('Na', 'Na', 7)
        pdfc.addEnvelopeByType('sphericalshape')
        pdfc.delta1 = 0.2
        pdfc.delta2 = 0.3
        pdfc.maxextension = 10.1
        pdfc.peakprecision = 5e-06
        pdfc.qbroad = 0.01
        pdfc.qdamp = 0.05
        pdfc.qmax = 10
        pdfc.qmin = 0.5
        pdfc.rmax = 10.0
        pdfc.rmin = 0.02
        pdfc.rstep = 0.02
        pdfc.scale = 1.1
        pdfc.slope = 0.1
        pdfc.spdiameter = 13.3
        pdfc.foobar = 'asdf'
        spkl = cPickle.dumps(pdfc)
        pdfc1 = cPickle.loads(spkl)
        sft = pdfc.scatteringfactortable
        sft1 = pdfc1.scatteringfactortable
        self.assertEqual(sft.type(), sft1.type())
        self.assertEqual(7.0, sft1.lookup('Na'))
        for a in pdfc._namesOfDoubleAttributes():
            self.assertEqual(getattr(pdfc, a), getattr(pdfc1, a))
        self.assertEqual(13.3,
                pdfc1.getEnvelopeByType('sphericalshape').spdiameter)
        self.assertEqual(pdfc._namesOfDoubleAttributes(),
                pdfc1._namesOfDoubleAttributes())
        self.assertEqual(pdfc.usedenvelopetypes, pdfc1.usedenvelopetypes)
        self.assertEqual('asdf', pdfc1.foobar)
        return

    def test_mask_pickling(self):
        '''Check if mask gets properly pickled and restored.
        '''
        self.pdfcalc.maskAllPairs(False)
        self.pdfcalc.setPairMask(0, 1, True)
        self.failUnless(False is self.pdfcalc.getPairMask(0, 0))
        self.failUnless(True is self.pdfcalc.getPairMask(0, 1))
        pdfcalc1 = cPickle.loads(cPickle.dumps(self.pdfcalc))
        self.failUnless(False is pdfcalc1.getPairMask(0, 0))
        self.failUnless(True is pdfcalc1.getPairMask(0, 1))
        return
開發者ID:XiaohaoYang,項目名稱:diffpy.srreal,代碼行數:104,代碼來源:testpdfcalculator.py


注:本文中的diffpy.srreal.pdfcalculator.PDFCalculator.getPairMask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。