#NEWLINE# @ ValidateLarchPlugin #NEWLINE# def material_mu( name , energy , density = None , kind = 'total' , _larch = None ) : #NEWLINE# #INDENT# "\n    material_mu(name, energy, density=None, kind='total')\n\n    return X-ray attenuation length (in 1/cm) for a material by name or formula\n\n    arguments\n    ---------\n     name:     chemical formul or name of material from materials list.\n     energy:   energy or array of energies in eV\n     density:  material density (gr/cm^3).  If None, and material is a\n               known material, that density will be used.\n     kind:     'photo' or 'total' (default) for whether to\n               return photo-absorption or total cross-section.\n    returns\n    -------\n     mu, absorption length in 1/cm\n\n    notes\n    -----\n      1.  material names are not case sensitive,\n          chemical compounds are case sensitive.\n      2.  mu_elam() is used for mu calculation.\n\n    example\n    -------\n      >>> print material_mu('H2O', 10000.0)\n      5.32986401658495\n    " #NEWLINE# _materials = get_materials ( mass_tot ) #NEWLINE# formula = None #NEWLINE# mater = _materials . get ( name . lower ( ) , None ) #NEWLINE# if ( mater is not None ) : #NEWLINE# #INDENT# ( formula , density ) = mater #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for ( key , val ) in _materials . items ( ) : #NEWLINE# #INDENT# if ( name . lower ( ) == val [ 0 ] . lower ( ) ) : #NEWLINE# #INDENT# ( formula , density ) = val #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( formula is None ) : #NEWLINE# #INDENT# formula = name #NEWLINE# #UNINDENT# if ( density is None ) : #NEWLINE# #INDENT# raise Warning ( 'material_mu(): must give density for unknown materials' ) #NEWLINE# #UNINDENT# ( mass_tot , mu ) = ( 0.0 , 0.0 ) #NEWLINE# for ( elem , frac ) in chemparse ( formula ) . items ( ) : #NEWLINE# #INDENT# mass = ( frac * atomic_mass ( elem , _larch = _larch ) ) #NEWLINE# mu += ( mass * mu_elam ( elem , energy , kind = kind , _larch = _larch ) ) #NEWLINE# mass_tot += mass #NEWLINE# #UNINDENT# return ( ( density * mu ) / mass_tot )