def testGenerator(self): qmax = 27.0 gen = self.gen 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
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
def read(self, filename, format='auto'): """Load structure from a file, raise ControlFileError for invalid or unknown structure format. filename -- file to be loaded format -- structure format such as 'pdffit', 'pdb', 'xyz'. When 'auto' all available formats are tried in a row. Return instance of StructureParser used to load the data. See Structure.read() for more info. """ from diffpy.Structure import StructureFormatError try: p = PDFFitStructure.read(self, filename, format) except StructureFormatError, err: import os.path emsg = "Unable to read file '%s'\n%s." % ( os.path.basename(filename), err) raise ControlFileError(emsg)