Package diffpy :: Package srrietveld :: Module objectinfo
[frames] | no frames]

Source Code for Module diffpy.srrietveld.objectinfo

  1  ############################################################################## 
  2  # 
  3  # diffpy.srrietveld by DANSE Diffraction group 
  4  #                   Simon J. L. Billinge 
  5  #                   (c) 2009 Trustees of the Columbia University 
  6  #                   in the City of New York.  All rights reserved. 
  7  # 
  8  # File coded by:    Jiwu Liu, Yingrui Shang 
  9  # 
 10  # See AUTHORS.txt for a list of people who contributed. 
 11  # See LICENSE.txt for license information. 
 12  # 
 13  ############################################################################## 
 14   
 15  """This module contains the definition of the ObjectInfo class. """ 
 16   
 17  __id__ = "$Id: objectinfo.py 6718 2011-08-23 21:33:20Z yshang $" 
 18   
19 -class ObjectInfo:
20 """ 21 ObjectInfo uses the info in the engine definition to define what is allowed 22 to be set in an object, namely the legal content of an object. 23 """
24 - def __init__(self, cls=None):
25 '''Initialization. 26 27 @type cls: an engine class 28 @param cls: the class of the engine fit object 29 @return: no value 30 ''' 31 self.cls = cls 32 return
33
34 - def listParams(self):
35 """ 36 List all the parameters that can be refined by the engine. 37 38 @return: a list of refinable parameter names 39 """ 40 params = [] 41 if self.cls is None: 42 return params 43 for name, info in self.cls.ParamDict.items(): 44 if info.__class__.__name__ == 'RefineInfo': 45 params.append(name) 46 for name, info in self.cls.ParamListDict.items(): 47 if info.__class__.__name__ == 'RefineInfo': 48 params.append(name) 49 50 return params
51
52 - def getDescription(self, paramname):
53 """ 54 Get the description of a parameter. 55 56 @type paramname: string 57 @param paramname: parameter name 58 @return: a string to describe the parameter 59 """ 60 if paramname in self.cls.ParamDict: 61 return self.cls.ParamDict[paramname].description 62 if paramname in self.cls.ParamListDict: 63 return self.cls.ParamListDict[paramname].description 64 65 return ''
66
67 - def get(self,paramname):
68 """ 69 Get the full info of a parameter. 70 71 @type paramname: string 72 @param paramname: parameter name 73 @return: an Info object defined in the engine. 74 """ 75 if paramname in self.cls.ParamDict: 76 return self.cls.ParamDict[paramname] 77 if paramname in self.cls.ParamListDict: 78 return self.cls.ParamListDict[paramname] 79 80 return None
81
82 -def setObjectInfo(refinementObj):
83 """ 84 Set the object info for the engine. 85 86 @type refinementObj: Refinement object 87 @param refinementObj: the ObjectInfo will be generated and set to the 88 refinementObj 89 @return: no return value 90 """ 91 try: 92 engineclassname = refinementObj.getAttr('rietveldcls') 93 modulename, classname = engineclassname.rsplit('.', 1) 94 module = __import__(modulename, globals(), locals(), [classname], -1) 95 engineclass = getattr(module, classname) 96 refinementObj.info = ObjectInfo(engineclass) 97 except (ImportError, AttributeError, ValueError): 98 refinementObj.info = ObjectInfo() 99 100 for myobjchild in refinementObj.objects: 101 setObjectInfo(myobjchild) 102 103 return
104