コード例 #1
0
def import_thermo(thermo_path, kinetic_model, models):
    local_context = {
        "ThermoData": ThermoData,
        "Wilhoit": Wilhoit,
        "NASAPolynomial": NASAPolynomial,
        "NASA": NASA,
    }
    library = ThermoLibrary(label=kinetic_model.model_name)
    # NOTE: In order for this feature to run we have to be on "rmg-py/importer" branch, may require reinstall # noqa: E501
    library.SKIP_DUPLICATES = True
    library.load(thermo_path, local_context=local_context)
    for species_name, entry in library.entries.items():
        logger.info(f"Importing Thermo entry for {species_name}")
        try:
            species = get_or_create_species(kinetic_model, species_name,
                                            [entry.item], models)
            thermo_data = entry.data
            poly1, poly2 = thermo_data.polynomials
            thermo, _ = models.Thermo.objects.get_or_create(
                species=species,
                coeffs_poly1=poly1.coeffs.tolist(),
                coeffs_poly2=poly2.coeffs.tolist(),
                temp_min_1=poly1.Tmin.value_si,
                temp_max_1=poly1.Tmax.value_si,
                temp_min_2=poly2.Tmin.value_si,
                temp_max_2=poly2.Tmax.value_si,
            )
            thermo_comment = models.ThermoComment.objects.create(
                kinetic_model=kinetic_model, thermo=thermo)
            thermo_comment.comment = entry.long_desc or entry.short_desc or thermo_comment.comment
            thermo.save()
            thermo_comment.save()
        except Exception:
            logger.exception("Failed to import entry")