Example #1
0
    def validate(self):
        """
        validate the parameters, subclass and container to meet the refinement requirement
        """ 
        rvalue = RietveldClass.validate(self)

        if self.__class__.__name__ == "FormFactor":
            print "base class FormFactor is not allowed"
            rvalue = False

        return rvalue
Example #2
0
    def validate(self):
        """
        validate the parameters, subclass and container to meet the refinement requirement
        """ 
        rvalue = RietveldClass.validate(self)

        name = self.__class__.__name__
        if name == "Background":
            print "base class of Background is not allowed"
            rvalue = False

        return rvalue
Example #3
0
    def validate(self):
        """
        validate the parameters, subclass and container to meet the refinement requirement
        """
        rvalue = RietveldClass.validate(self)

        # type check
        name = self.__class__.__name__
        if name == "AtomicDisplacementFactor":
            print "base class AtomicDisplacementFactor is not allowed"
            rvalue = False

        return rvalue
Example #4
0
    def validate(self):
        """
        validate the parameters, subclass and container to meet the refinement requirement
        """
        rvalue = RietveldClass.validate(self)

        # type check
        name = self.__class__.__name__
        if name == "AtomicDisplacementFactor":
            print "base class AtomicDisplacementFactor is not allowed"
            rvalue = False

        return rvalue
Example #5
0
    def validate(self):
        """
        validate of class Phase
        """
        rvalue = RietveldClass.validate(self)

        errmsg = ""

        # FullProf parameter synchronization
        # atom
        nat = len(self.get("Atom"))
        self.set("Nat", nat)
        # dis
        dis = len(self.get("DistanceRestraint"))
        self.set("Dis", dis)
        # momma
        ang = len(self.get("AngleRestraint"))
        mom = len(self.get("MomentRestraint"))
        if ang != 0 and mom != 0:
            raise NotImplementedError, "Angular Restraint and Moment Restraint cannot be used simultaneously"
        self.set("MomMA", ang + mom)
        # nvk
        nvk = len(self.get("PropagationVector"))
        self.set("Nvk", nvk)

        # Situation validation
        # 1. Jbt and Atom Number
        jbt = self.get("Jbt")
        if abs(jbt) != 2 and nat == 0:
            # not Le-Bail (profile match)
            rvalue = False
            errmsg += "No Atom is defined while Jbt = %-5s (Not Le-Bail)" % (
                jbt)

        # error message output
        if errmsg != "":
            prtmsg = "Phase Invalid Setup: %-60s" % (errmsg)
            print prtmsg

        if rvalue is not True:
            print "Invalidity Deteced In %-10s" % (self.__class__.__name__)

        return rvalue
Example #6
0
    def validate(self):
        """
        validate of class Phase
        """
        rvalue = RietveldClass.validate(self)

        errmsg = ""

        # FullProf parameter synchronization
        # atom
        nat = len(self.get("Atom"))
        self.set("Nat", nat)
        # dis
        dis = len(self.get("DistanceRestraint"))
        self.set("Dis", dis)
        # momma
        ang = len(self.get("AngleRestraint"))
        mom = len(self.get("MomentRestraint"))
        if ang != 0 and mom != 0:
            raise NotImplementedError, "Angular Restraint and Moment Restraint cannot be used simultaneously"
        self.set("MomMA", ang+mom)
        # nvk
        nvk = len(self.get("PropagationVector"))
        self.set("Nvk", nvk)

        # Situation validation
        # 1. Jbt and Atom Number
        jbt = self.get("Jbt")
        if abs(jbt) != 2 and nat == 0:
            # not Le-Bail (profile match)
            rvalue = False
            errmsg += "No Atom is defined while Jbt = %-5s (Not Le-Bail)"% (jbt)

        # error message output
        if errmsg != "":
            prtmsg = "Phase Invalid Setup: %-60s"% (errmsg)
            print prtmsg

        if rvalue is not True:
            print "Invalidity Deteced In %-10s"% (self.__class__.__name__)

        return rvalue
Example #7
0
    def validate(self, mode="Refine"):
        """
        validate the parameters, subclass and container to meet the refinement requirement

        Arguments
        - mode  :  string, validate mode, (Refine, Calculate)

        Return  :  Boolean 
        """
        rvalue = RietveldClass.validate(self)
        errmsg = ""

        # I. Synchronization of FulProf Parameter & Check Data File Existence
        for pattern in self.get("Pattern"):

            # 2.1 data file existence
            if mode == "Refine":
                exist = checkFileExistence(pattern.get("Datafile"))
                if not exist:
                    rvalue = False
                    errmsg += "Data File %-10s Cannot Be Found\n" % (
                        pattern.get("Datafile"))

        # 2. Nre
        nre = 0
        for variable in self.get("Refine").get("Variable"):
            if variable.get("usemin") is True:
                nre += 1
        # End -- for variable in ...
        self.set("Nre", nre)

        # Check Validity
        # 1. parameter
        if self.get("NCY") < 1:
            rvalue = False

        # 2. .hkl file
        #   the reason why not put the checking .hkl file in Contribution is that
        #   there is a sequence number related between pattern sequence
        #   within contribution, it is hard to get this number
        for pattern in self.get("Pattern"):
            # scan all Phases
            pindex = 1
            fnamer = pattern.get("Datafile").split(".")[0]
            usehkl = False
            for phase in self.get("Phase"):
                # get contribution
                contribution = self.getContribution(pattern, phase)

                if contribution is not None and contribution.get("Irf") == 2:
                    # using reflection
                    usehkl = True
                    # check single phase/contribution hkl file
                    hklfname = fnamer + str(pindex) + ".hkl"
                    try:
                        hklfile = open(hklfname, "r")
                        hklfile.close()
                    except IOError, err:
                        # if no such file exits, update Irf to 0
                        contribution.set("Irf", 0)
                        # error message output
                        errmsg += "Fit.validate():  Reflection File %-10s Cannot Be Found: " % (
                            hklfname)
                        errmsg += "Chaning Contribution.Irf to 0 ... Related to Phase[%-5s]" % (
                            pindex)
                        print errmsg
                # End -- if contribution is not None and Irf == 2:

                pindex += 1
            # End -- for phase in self.get("Phase"):

            if usehkl is True:
                # check overall hkl file
                hklfname = fnamer + ".hkl"
                try:
                    hklfile = open(hklfname, "r")
                    hklfile.close()
                except IOError, err:
                    # if no such file exists, update all Irf to 0
                    for contribution in self.get("Contribution"):
                        contribution.set("Irf", 0)
Example #8
0
    def validate(self):
        """
        validate the parameters, subclass and container to meet the refinement requirement of 
        class Pattern

        Return  --  bool
        """
        from diffpy.pyfullprof.utilfunction import checkFileExistence
        rvalue = RietveldClass.validate(self)

        errmsg = ""

        # type check: virtual base class
        name = self.__class__.__name__
        if name == "Pattern":
            errmsg += "%-30s: %-40s"%("Pattern.validate()", "virtual base Pattern")
            print errmsg
            rvalue = False

        # FullProf Parameter Synchronization
        # 1. Excluded Region
        nex = len(self.get("ExcludedRegion"))
        self.set("Nex", nex)

        # 2. Scttering Factor
        nsc = len(self.get("ScatterFactor"))
        self.set("Nsc", nsc)

        # 3. background
        background = self.get("Background")

        if isinstance(background, BackgroundUserDefinedLinear):
            #NOTE: avoid using self.set('Nba', 2)
            self.Nba = 2
        elif isinstance(background, BackgroundUserDefinedCubic):
            #NOTE: avoid using self.set('Nba', -5)
            self.Nba = -5
        elif isinstance(background, BackgroundFourierwindow):
            #NOTE: avoid using self.set('Nba', -2)
            self.Nba = -2

        elif isinstance(background, BackgroundPolynomial):
            if background.get("Order") == 6:
                #NOTE: avoid using self.set('Nba', 0)
                self.Nba = 0
            elif background.get("Order") == 12:
                #NOTE: avoid using self.set('Nba', -4)
                self.Nba = -4
            else:
                errmsg = "Polynomial Order = %-4s Is Not Supported"% (background.get("Order"))
                raise NotImplementedError(errmsg)
        else:
            pass       

        if self.get("Nba") <= -5 or self.get("Nba") >= 2:
            self.set('NbaPoint', self.get("Background").size())

        if background.ParamDict.has_key("Bkpos"):
            self.set('Bkpos', self.get("Background").get("Bkpos"))

        # 4. output 
        self.set("Ipr", 3)
        if self.get("Prf") == 0:
            self.set("Prf", 3)

        # 5. peak profile Npr
        for contribution in self._contributionlist:
            npr = contribution.get("Npr")
            self.set("Npr", npr)

        # WZ: this section (item 6) is removed as all wdt from fit should be trustful
        # 6. Peak range
        # for contribution in self._contributionlist:
        #     wdt = contribution.get("Profile").get("PeakRange")
        #     if wdt > 0.0:
        #         self.set("Wdt", wdt)
        wdt = self.get("Wdt")
        if wdt <= 0.0:
            errmsg = String.Format("Pattern has Wdt (peak range) = %f <= 0") % (wdt)
            raise RietError(errmsg)

        # Check Valid
        # 1. resolution file
        if self.get("Res") != 0:
            exist = checkFileExistence(self.get("Resofile"))
            if not exist:
                rvalue = False
                errmsg += "Resolution File %-10s Cannot Be Found\n"% (self.get("Resofile"))

        # 2. data file.... ->  moved to Fit.validate()
        
        if rvalue is not True:
            print "Invalidity Detected In %-10s: %-60s"% (self.__class__.__name__, errmsg)

        return rvalue
Example #9
0
    def validate(self, mode="Refine"):
        """
        validate the parameters, subclass and container to meet the refinement requirement

        Arguments
        - mode  :  string, validate mode, (Refine, Calculate)

        Return  :  Boolean 
        """
        rvalue = RietveldClass.validate(self)
        errmsg = ""

        # I. Synchronization of FulProf Parameter & Check Data File Existence
        for pattern in self.get("Pattern"):

            # 2.1 data file existence
            if mode == "Refine":
                exist = checkFileExistence(pattern.get("Datafile"))
                if not exist:
                    rvalue = False
                    errmsg += "Data File %-10s Cannot Be Found\n"% (pattern.get("Datafile"))

        # 2. Nre
        nre = 0
        for variable in self.get("Refine").get("Variable"):
            if variable.get("usemin") is True:
                nre += 1
        # End -- for variable in ... 
        self.set("Nre", nre)

        # Check Validity
        # 1. parameter
        if self.get("NCY") < 1:
            rvalue = False

        # 2. .hkl file 
        #   the reason why not put the checking .hkl file in Contribution is that
        #   there is a sequence number related between pattern sequence
        #   within contribution, it is hard to get this number
        for pattern in self.get("Pattern"):
            # scan all Phases
            pindex = 1
            fnamer = pattern.get("Datafile").split(".")[0]
            usehkl = False
            for phase in self.get("Phase"):
                # get contribution
                contribution = self.getContribution(pattern, phase)
                
                if contribution is not None and contribution.get("Irf") == 2:
                    # using reflection
                    usehkl = True
                    # check single phase/contribution hkl file
                    hklfname = fnamer+str(pindex)+".hkl"
                    try:
                        hklfile = open(hklfname, "r")
                        hklfile.close()
                    except IOError, err:
                        # if no such file exits, update Irf to 0
                        contribution.set("Irf", 0)
                        # error message output
                        errmsg += "Fit.validate():  Reflection File %-10s Cannot Be Found: "% (hklfname)
                        errmsg += "Chaning Contribution.Irf to 0 ... Related to Phase[%-5s]"% (pindex)
                        print errmsg
                # End -- if contribution is not None and Irf == 2:

                pindex += 1
            # End -- for phase in self.get("Phase"):

            if usehkl is True:
                # check overall hkl file
                hklfname = fnamer+".hkl"
                try:
                    hklfile = open(hklfname, "r")
                    hklfile.close()
                except IOError, err:
                    # if no such file exists, update all Irf to 0
                    for contribution in self.get("Contribution"):
                        contribution.set("Irf", 0)