ORNL-MDF / mist

Mist is a Python tool for storing, sharing, and using information about materials in models and simulations.
BSD 3-Clause "New" or "Revised" License
2 stars 2 forks source link

Initialization of unlisted properties #11

Open stvdwtt opened 4 months ago

stvdwtt commented 4 months ago

When one of the thermophysical properties isn't listed in the JSON file, you end up not initializing the properties correctly.

mistlib/core.py, Line 80-92:

        if (file == None):
            # Set all values to None
            self.name = None
            self.notes = None
            self.composition = None
            self.single_phase_properties = None

            for p in self.thermophysical_property_names:
                self.properties[p] = None

        else:
            # Call the load from file method
            self.load_json(file)

If you try to run mat.write_markdown("export.md") after loading the JSON in the ramen example problem, then you get the following error.

Traceback:

Traceback (most recent call last): 
File "AlCu_eutectic_spacing_pdf.py", line 17, in <module> 
   mat.write_pdf(file)
File "c:\users\ygk\dev\mist\mistlib\core.py", line 273, in write_pdf 
   self.write_markdown(temp_md_file)
File "c:\users\ygk\dev\mist\mistlib\core.py", line 224, in write_markdown
   next_ref = self.properties[p].reference                                                             
KeyError: 'density'

Further errors in that code block would be thrown at print_name_str = self.properties[p].print_name and anywhere else that tries to access properties[p] for a value of p that was not initialized.