energy_implementation_units=GM_implementation_units='J / mol'energy_display_units=GM_display_units='J / mol'energy_display_name=GM_display_name='Gibbs Energy'G_implementation_units='J'G_display_units='J'G_display_name='Gibbs Energy'enthalpy_implementation_units=HM_implementation_units=GM_implementation_unitsenthalpy_display_units=HM_display_units=GM_display_unitsenthalpy_display_name=HM_display_name='Enthalpy'H_implementation_units='J'H_display_units='J'H_display_name='Enthalpy'entropy_implementation_units=SM_implementation_units='J / mol / K'entropy_display_units=SM_display_units='J / mol / K'entropy_display_name=SM_display_name='Entropy'def_conversions_per_formula_unit(compset):components=compset.phase_record.nonvacant_elementsnum_components=len(components)moles_per_fu=np.zeros((num_components,1))forcomp_idxinrange(num_components):compset.phase_record.formulamole_obj(moles_per_fu[comp_idx,:],compset.dof,comp_idx)# now we have 'moles per formula unit'# need to convert by adding molecular weight of each elementgrams_per_mol=np.array(compset.phase_record.molar_masses,dtype='float')grams_per_fu=np.dot(grams_per_mol,moles_per_fu)returnmoles_per_fu.sum(),grams_per_fu
[docs]defunit_conversion_context(compsets,prop):context=pint.Context()# these will be something/mol by convention# XXX: This is a very rough checkifnot('/ mol'instr(prop.implementation_units)):returncontextimplementation_units=(ureg.Unit(prop.implementation_units)*ureg.Unit('mol'))molar_weight=0.0# g/mol-atomforcompsetincompsets:ifcompset.NP>0:moles_per_fu,grams_per_fu=_conversions_per_formula_unit(compset)grams_per_mol_atoms=(compset.NP/moles_per_fu)*grams_per_fumolar_weight+=grams_per_mol_atomsmolar_weight=Q_(molar_weight,'g/mol')per_moles=ureg.get_dimensionality(ureg.Unit('{} / mol'.format(implementation_units)))per_mass=ureg.get_dimensionality(ureg.Unit('{} / g'.format(implementation_units)))context.add_transformation(per_moles,per_mass,lambdaureg,x:(x/molar_weight).to_reduced_units())context.add_transformation(per_mass,per_moles,lambdaureg,x:(x*molar_weight).to_reduced_units())returncontext