예제 #1
0
 def checkConfiguration(self):
     """Verify that the dopant and base are elements.
     
     More detailed checking is done in the control method.
     """
     from diffpy.pdfgui.control.controlerrors import ControlValueError
     from diffpy.pdffit2 import is_element
     base = self.textCtrlBaseElement.GetValue()
     dopant = self.textCtrlDopant.GetValue()
     # Make sure that the base and dopant are actual elements
     base = base.title()
     dopant = dopant.title()
     if not is_element(base):
         raise ControlValueError("'%s' is not an element!"%base)
     if not is_element(dopant):
         raise ControlValueError("'%s' is not an element!"%dopant)
     return
    def checkConfiguration(self):
        """Verify that the dopant and base are elements.

        More detailed checking is done in the control method.
        """
        from diffpy.pdfgui.control.controlerrors import ControlValueError
        from diffpy.pdffit2 import is_element
        base = self.textCtrlBaseElement.GetValue()
        dopant = self.textCtrlDopant.GetValue()
        # Make sure that the base and dopant are actual elements
        base = base.title()
        dopant = dopant.title()
        if not is_element(base):
            raise ControlValueError("'%s' is not an element!" % base)
        if not is_element(dopant):
            raise ControlValueError("'%s' is not an element!" % dopant)
        return
예제 #3
0
    def applyCellChange(self, i, j, value):
        """Update an atom according to a change in a cell.

        i       --  cell position
        j       --  cell position
        value   --  new value
        """
        if not self.mainFrame or self.structure is None: return

        # The element name
        if j == 0:
            value = value.title()
            if not is_element(value): return
            self.structure[i].element = value  # element
            return value

        # Other entries
        # ignore the change if the value is not valid
        try:
            value = float(value)
            if value == "": value = 0.0
            if j == 1:
                self.structure[i].xyz[0]    = value # x
            elif j == 2:
                self.structure[i].xyz[1]    = value # y
            elif j == 3:
                self.structure[i].xyz[2]    = value # z
            elif j == 4:
                self.structure[i].U[0,0]    = value # U(1,1)
            elif j == 5:
                self.structure[i].U[1,1]    = value # U(2,2)
            elif j == 6:
                self.structure[i].U[2,2]    = value # U(3,3)
            elif j == 7:
                self.structure[i].U[0,1] = self.structure[i].U[1,0] = value # U(1,2)
            elif j == 8:
                self.structure[i].U[0,2] = self.structure[i].U[2,0] = value # U(1,3)
            elif j == 9:
                self.structure[i].U[1,2] = self.structure[i].U[2,1] = value # U(2,3)
            elif j == 10:
                self.structure[i].occupancy = value # occupancy

            self.mainFrame.needsSave()
            return value

        except ValueError:
            return
예제 #4
0
    def applyCellChange(self, i, j, value):
        """Update an atom according to a change in a cell.

        i       --  cell position
        j       --  cell position
        value   --  new value
        """
        if not self.mainFrame or self.structure is None: return

        # The element name
        if j == 0:
            value = value.title()
            if not is_element(value): return
            self.structure[i].element = value  # element
            return value

        # Other entries
        # ignore the change if the value is not valid
        try:
            value = float(value)
            if value == "": value = 0.0
            if j == 1:
                self.structure[i].xyz[0]    = value # x
            elif j == 2:
                self.structure[i].xyz[1]    = value # y
            elif j == 3:
                self.structure[i].xyz[2]    = value # z
            elif j == 4:
                self.structure[i].U[0,0]    = value # U(1,1)
            elif j == 5:
                self.structure[i].U[1,1]    = value # U(2,2)
            elif j == 6:
                self.structure[i].U[2,2]    = value # U(3,3)
            elif j == 7:
                self.structure[i].U[0,1] = self.structure[i].U[1,0] = value # U(1,2)
            elif j == 8:
                self.structure[i].U[0,2] = self.structure[i].U[2,0] = value # U(1,3)
            elif j == 9:
                self.structure[i].U[1,2] = self.structure[i].U[2,1] = value # U(2,3)
            elif j == 10:
                self.structure[i].occupancy = value # occupancy

            self.mainFrame.needsSave()
            return value

        except ValueError:
            return
예제 #5
0
def makeDopingSeries(control, fit, base, dopant, paths, doping):
    """Make a temperature series.
    
    control         --  pdguicontrol instance
    fit             --  The template fit
    base            --  Name of the base element
    dopant          --  Name of the dopant element
    paths           --  list of path names of new datasets
    doping          --  list of doping values corresponding to the datasets
    
    returns a list of the new fit organization objects
    """
    from diffpy.pdffit2 import is_element

    # Make sure that base and dopant are elements
    base = base.title()
    dopant = dopant.title()
    if not is_element(base):
        raise ControlValueError("'%s' is not an element!"%base)
    if not is_element(dopant):
        raise ControlValueError("'%s' is not an element!"%dopant)

    # Make sure that base and dopant are in the structure file(s)
    hasBase = False
    hasDopant = False
    for S in fit.strucs:
        for atom in S:
            if atom.element == base:
                hasBase = True
            if atom.element == dopant:
                hasDopant = True
        if hasBase and hasDopant: break

    if not hasBase:
        message = "The template structure does not contain the base atom."
        raise ControlValueError(message)

    if not hasDopant:
        message = "The template structure does not contain the dopant atom."
        raise ControlValueError(message)

    # Make sure we're only replacing a single dataset
    if len(fit.datasets) != 1:
        message = "Can't apply macro to fits with multiple datasets."
        raise ControlValueError(message)


    fits = []
    # holds all of the other information about the dataset
    fitbasename = fit.name
    fitnewname = fit.name
    fitlastname = fit.name
    dataset = fit.datasets[0]
    for i in range(len(paths)):
        filename = paths[i]
        fitlastname = fitnewname

        fitcopy = control.copy(fit)

        # Get rid of the old dataset
        temp = fitcopy.datasets[0]
        fitcopy.remove(temp)

        # Configure the new dataset
        dsname = os.path.basename(filename)
        newdataset = FitDataSet(dsname)
        newdataset.readObs(filename)

        newdataset.qdamp = dataset.qdamp
        newdataset.qbroad = dataset.qbroad
        newdataset.dscale = dataset.dscale
        newdataset.fitrmin = dataset.fitrmin
        newdataset.fitrmax = dataset.fitrmax
        rstep = dataset.fitrstep
        st = dataset.getFitSamplingType()
        newdataset.setFitSamplingType(st, rstep)
        temperature = dataset.metadata.get("temperature")
        if temperature is None: temperature = 300.0
        newdataset.metadata["temperature"] = temperature
        newdataset.constraints = copy.deepcopy(dataset.constraints)

        # Set the chosen temperature
        newdataset.metadata["doping"] = doping[i]

        # Add the dataset to the fitcopy
        fitcopy.add(newdataset, None)

        # Update the doping information in the structures
        for S in fitcopy.strucs:
            for A in S:
                if A.element == dopant:
                    A.occupancy = doping[i]
                if A.element == base:
                    A.occupancy = 1-doping[i]


        # Set the parameters to the previous fit's name, if one exists.
        if fitlastname:
            parval = "=%s" % fitlastname
            for par in fitcopy.parameters.values():
                par.setInitial(parval)

        # Now paste the copy into the control.
        fitnewname = "%s-%1.4f" % (fitbasename, doping[i])
        o = control.paste(fitcopy, new_name = fitnewname)
        fits.append(o)

    return [f.organization() for f in fits]
예제 #6
0
def makeDopingSeries(control, fit, base, dopant, paths, doping):
    """Make a temperature series.

    control         --  pdguicontrol instance
    fit             --  The template fit
    base            --  Name of the base element
    dopant          --  Name of the dopant element
    paths           --  list of path names of new datasets
    doping          --  list of doping values corresponding to the datasets

    returns a list of the new fit organization objects
    """
    from diffpy.pdffit2 import is_element

    # Make sure that base and dopant are elements
    base = base.title()
    dopant = dopant.title()
    if not is_element(base):
        raise ControlValueError("'%s' is not an element!" % base)
    if not is_element(dopant):
        raise ControlValueError("'%s' is not an element!" % dopant)

    # Make sure that base and dopant are in the structure file(s)
    hasBase = False
    hasDopant = False
    for S in fit.strucs:
        for atom in S:
            if atom.element == base:
                hasBase = True
            if atom.element == dopant:
                hasDopant = True
        if hasBase and hasDopant: break

    if not hasBase:
        message = "The template structure does not contain the base atom."
        raise ControlValueError(message)

    if not hasDopant:
        message = "The template structure does not contain the dopant atom."
        raise ControlValueError(message)

    # Make sure we're only replacing a single dataset
    if len(fit.datasets) != 1:
        message = "Can't apply macro to fits with multiple datasets."
        raise ControlValueError(message)

    fits = []
    # holds all of the other information about the dataset
    fitbasename = fit.name
    fitnewname = fit.name
    fitlastname = fit.name
    dataset = fit.datasets[0]
    for i in range(len(paths)):
        filename = paths[i]
        fitlastname = fitnewname

        fitcopy = control.copy(fit)

        # Get rid of the old dataset
        temp = fitcopy.datasets[0]
        fitcopy.remove(temp)

        # Configure the new dataset
        dsname = os.path.basename(filename)
        newdataset = FitDataSet(dsname)
        newdataset.readObs(filename)

        newdataset.qdamp = dataset.qdamp
        newdataset.qbroad = dataset.qbroad
        newdataset.dscale = dataset.dscale
        newdataset.fitrmin = dataset.fitrmin
        newdataset.fitrmax = dataset.fitrmax
        rstep = dataset.fitrstep
        st = dataset.getFitSamplingType()
        newdataset.setFitSamplingType(st, rstep)
        temperature = dataset.metadata.get("temperature")
        if temperature is None: temperature = 300.0
        newdataset.metadata["temperature"] = temperature
        newdataset.constraints = copy.deepcopy(dataset.constraints)

        # Set the chosen temperature
        newdataset.metadata["doping"] = doping[i]

        # Add the dataset to the fitcopy
        fitcopy.add(newdataset, None)

        # Update the doping information in the structures
        for S in fitcopy.strucs:
            for A in S:
                if A.element == dopant:
                    A.occupancy = doping[i]
                if A.element == base:
                    A.occupancy = 1 - doping[i]

        # Set the parameters to the previous fit's name, if one exists.
        if fitlastname:
            parval = "=%s" % fitlastname
            for par in fitcopy.parameters.values():
                par.setInitial(parval)

        # Now paste the copy into the control.
        fitnewname = "%s-%1.4f" % (fitbasename, doping[i])
        o = control.paste(fitcopy, new_name=fitnewname)
        fits.append(o)

    return [f.organization() for f in fits]