@@ -86,8 +86,10 @@ def fromStructure(cls, stru, sftb, q=0):
8686 The structure object that stores the atom species and their
8787 occupancies. Can be any type with a registered conversion
8888 to the StructureAdapter class.
89- sftb : ScatteringFactorTable
89+ sftb : ScatteringFactorTable or str
9090 The ScatteringFactorTable object for looking up the values.
91+ When string use `ScatteringFactorTable.createByType` to create
92+ a new lookup table of the specified type.
9193 q : float or NumPy array (optional)
9294 The Q value in inverse Angstroms for which to lookup
9395 the scattering factor values.
@@ -127,8 +129,10 @@ def fromComposition(cls, composition, sftb, q=0):
127129 composition : dictionary or a list of (symbol, amount) pairs.
128130 The chemical composition for evaluating the average. Atom
129131 symbols may repeat when it is a list of (symbol, amount) pairs.
130- sftb : ScatteringFactorTable
132+ sftb : ScatteringFactorTable or str
131133 The ScatteringFactorTable object for looking up the values.
134+ When string use `ScatteringFactorTable.createByType` to create
135+ a new lookup table of the specified type.
132136 q : float or NumPy array (optional)
133137 The Q value in inverse Angstroms for which to lookup
134138 the scattering factor values.
@@ -138,6 +142,7 @@ def fromComposition(cls, composition, sftb, q=0):
138142 SFAverage
139143 The calculated scattering factor averages.
140144 """
145+ from diffpy .srreal .scatteringfactortable import ScatteringFactorTable
141146 sfa = cls ()
142147 sfa .composition = {}
143148 if isinstance (composition , dict ):
@@ -149,8 +154,11 @@ def fromComposition(cls, composition, sftb, q=0):
149154 sfa .composition [smbl ] += cnt
150155 sfa .f1sum = 0.0 * q
151156 sfa .f2sum = 0.0 * q
157+ # resolve the lookup table object `tb`
158+ tb = (sftb if not isinstance (sftb , basestring )
159+ else ScatteringFactorTable .createByType (sftb ))
152160 for smbl , cnt in sfa .composition .items ():
153- sfq = sftb .lookup (smbl , q )
161+ sfq = tb .lookup (smbl , q )
154162 sfa .f1sum += cnt * sfq
155163 sfa .f2sum += cnt * sfq ** 2
156164 sfa .count += cnt
0 commit comments