@@ -1551,16 +1551,31 @@ def getMass(generalData):
15511551 mass += generalData ['NoAtoms' ][elem ]* generalData ['AtomMass' ][i ]
15521552 return max (mass ,1.0 )
15531553
1554- def getDensity (generalData ):
1555- '''calculate crystal structure density
1554+ def getDensity (generalData ,hist = None ,data = None ):
1555+ '''Calculate crystal structure density. Uses cell values only,
1556+ unless hist & data are supplied. In that case it uses
1557+ the Dij terms as well.
15561558
15571559 :param dict generalData: The General dictionary in Phase
1558-
1559- :returns: float density: crystal density in gm/cm^3
1560-
1560+ :param str hist: optional name of a histogram. When not None,
1561+ the volume adjusted bt the Dij (hydrostatic strain terms) is
1562+ used to compute the density.
1563+ :parm dict data: reference to entire phase data array. Required
1564+ if hist is specified. Ignored otherwise.
1565+ :returns: crystal density in gm/cm^3 (float) and Matthews Coeff.
1566+ (Vm or Volume/mass, float)
15611567 '''
15621568 mass = getMass (generalData )
15631569 Volume = generalData ['Cell' ][7 ]
1570+ if hist is not None : # recompute the density using Dij terms
1571+ if data is None :
1572+ print ('called getDensity with hist and without data' )
1573+ raise Exception ('Called getDensity with hist and without data' )
1574+ A = G2lat .cell2A (data ['General' ]['Cell' ][1 :7 ])
1575+ DijVals = data ['Histograms' ][hist ]['HStrain' ][0 ][:]
1576+ # apply the Dij values to the reciprocal cell
1577+ newA = G2lat .AplusDij (A ,DijVals ,data ['General' ]['SGData' ])
1578+ Volume = G2lat .calc_V (newA )
15641579 density = mass / (0.6022137 * Volume )
15651580 return density ,Volume / mass
15661581
0 commit comments