Esempio n. 1
0
    def alloc(self, stype, qmax, qdamp, rmin, rmax, rlen):
        """Allocate space for a PDF calculation.

        The structure from which to calculate the PDF must first be imported with
        the read_struct() or read_struct_string() method.
        stype   -- 'X' (xray) or 'N' (neutron)
        qmax    -- maximum q value
        qdamp   -- instrumental q-resolution factor
        rmin    -- minimum r-value of calculation
        rmax    -- maximum r-value of calculation
        rlen    -- number of data points in calculation
        """
        # convert last fit to calculation
        last = self._fits[-1]
        newcalc = Calculation(last.name)
        newcalc.strucs = last.strucs
        newcalc.stype = stype
        newcalc.qmax = qmax
        newcalc.qdamp = qdamp
        newcalc.rmin = rmin
        newcalc.rmax = rmax
        newcalc.rlen = rlen
        newcalc.rstep = (rmax - rmin) / (rlen - 1)
        self._fits[-1] = newcalc
        return
Esempio n. 2
0
    def load(self, z, subpath):
        """load data from a zipped project file

        z -- zipped project file
        subpath -- path to its own storage within project file

        returns a tree of internal hierachy
        """
        # subpath = projName/myName/
        from diffpy.pdfgui.utils import unquote_plain
        subs = subpath.split('/')
        rootDict = z.fileTree[subs[0]][subs[1]]
        if rootDict.has_key('structure'):
            for strucName in rootDict['structure'].keys():
                struc = FitStructure(unquote_plain(strucName))
                struc.load(z, subpath + 'structure/' + strucName + '/')
                self.add(struc)

        if rootDict.has_key('dataset'):
            for datasetName in rootDict['dataset'].keys():
                dataset = FitDataSet(unquote_plain(datasetName))
                dataset.load(z, subpath + 'dataset/' + datasetName + '/')
                self.add(dataset)

        if rootDict.has_key('calculation'):
            for calcName in rootDict['calculation'].keys():
                calc = Calculation(unquote_plain(calcName))
                calc.load(z, subpath + 'calculation/' + calcName + '/')
                self.add(calc)

        self.__forward_spdiameter()

        return self.organization()
Esempio n. 3
0
    def load(self, z, subpath):
        """load data from a zipped project file

        z -- zipped project file
        subpath -- path to its own storage within project file

        returns a tree of internal hierachy
        """
        # subpath = projName/myName/
        from diffpy.pdfgui.utils import unquote_plain
        subs = subpath.split('/')
        rootDict = z.fileTree[subs[0]][subs[1]]
        if rootDict.has_key('structure'):
            for strucName in rootDict['structure'].keys():
                struc = FitStructure(unquote_plain(strucName))
                struc.load(z, subpath + 'structure/' + strucName + '/')
                self.add(struc)

        if rootDict.has_key('dataset'):
            for datasetName in rootDict['dataset'].keys():
                dataset = FitDataSet(unquote_plain(datasetName))
                dataset.load(z, subpath + 'dataset/' + datasetName + '/')
                self.add(dataset)

        if rootDict.has_key('calculation'):
            for calcName in rootDict['calculation'].keys():
                calc = Calculation(unquote_plain(calcName))
                calc.load(z, subpath + 'calculation/' + calcName + '/')
                self.add(calc)

        self.__forward_spdiameter()

        return self.organization()
Esempio n. 4
0
    def alloc(self, stype, qmax, qdamp, rmin, rmax, rlen):
        """Allocate space for a PDF calculation.

        The structure from which to calculate the PDF must first be imported with
        the read_struct() or read_struct_string() method.
        stype   -- 'X' (xray) or 'N' (neutron)
        qmax    -- maximum q value
        qdamp   -- instrumental q-resolution factor
        rmin    -- minimum r-value of calculation
        rmax    -- maximum r-value of calculation
        rlen    -- number of data points in calculation
        """
        # convert last fit to calculation
        lastidx = len(self._fits) - 1
        last = self._fits[-1]
        newcalc = Calculation(last.name)
        newcalc.strucs = last.strucs
        newcalc.stype = stype
        newcalc.qmax = qmax
        newcalc.qdamp = qdamp
        newcalc.rmin = rmin
        newcalc.rmax = rmax
        newcalc.rlen = rlen
        newcalc.rstep = (rmax - rmin)/(rlen - 1)
        self._fits[-1] = newcalc
        return
Esempio n. 5
0
class TestCalculation(unittest.TestCase):

    def setUp(self):
        self.calc = Calculation('calc')
        return

    def tearDown(self):
        return

#   def test___init__(self):
#       """check Calculation.__init__()
#       """
#       return
#
#   def test__getStrId(self):
#       """check Calculation._getStrId()
#       """
#       return

    def test_setRGrid(self):
        """check Calculation.setRGrid()
        """
        # helper function
        def rgriddata(calc):
            rv = (calc.rmin, calc.rstep, calc.rmax, calc.rlen)
            return rv
        # original data:
        rgd0 = rgriddata(self.calc)
        # test input argument checks
        self.assertRaises(ControlValueError,
                self.calc.setRGrid, rmin=-1)
        self.assertRaises(ControlValueError,
                self.calc.setRGrid, rmin=0)
        self.assertRaises(ControlValueError,
                self.calc.setRGrid, rmin=500)
        self.assertRaises(ControlValueError,
                self.calc.setRGrid, rstep=0)
        self.assertRaises(ControlValueError,
                self.calc.setRGrid, rmax=1e-10)
        # data should be the same
        self.assertEqual(rgd0, rgriddata(self.calc))
        # check round-offs for very close values
        self.calc.setRGrid(1, 0.2, 10.0 - 1e-14)
        self.assertEqual(1, self.calc.rmin)
        self.assertEqual(10, self.calc.rmax)
        self.assertEqual(0.2, self.calc.rstep)
        self.assertEqual(46, self.calc.rlen)
        # range should cover the argument range.
        self.calc.setRGrid(1, 0.7, 10)
        self.assertEqual(1, self.calc.rmin)
        self.assertTrue(10 < self.calc.rmax)
        self.assertEqual(0.7, self.calc.rstep)
        return
Esempio n. 6
0
    def newCalculation(self, targetID, name, position=None):
        """insert a new instance of Calculation to a Fitting

        targetID  --  reference to Fitting
        name      --  unique name for this Calculation
        position  --  where Calculation is inserted, default is last place

        return: Calculation reference
        """
        calculation = Calculation(name)
        targetID.add(calculation, position)

        return calculation
Esempio n. 7
0
 def setUp(self):
     self.calc = Calculation('calc')
     return