Input and Output
Input and output to different forms is an active area of development for pMuTT.
Excel
Reads an excel file and returns it as a list of dictionaries to initialize objects |
Special Rules
Special rules can be defined in the read_excel()
function to process inputs differently. Currently supported special rules are
listed below.
Parses element header and assigns to output_structure['elements'] |
|
Parses stoichiometric formula unit and assigns to output_structure |
|
Reads the atoms object ans assigns to output_structure |
|
Imports module and assigns the class to output_structure |
|
Imports module and assigns the class to output_structure |
|
Imports module and assigns the class to output_structure |
|
Imports module and assigns the class to output_structure |
|
Imports module and assigns the class to output_structure |
|
Imports module and assigns the class to output_structure |
|
Parses element header and assigns to output_structure['vib_wavenumber'] |
|
Parses element header and assigns to output_structure ['rot_temperatures'] |
|
Parses a_low parameter for |
|
Parses a_high parameter for |
|
Generic function to read a list from a spreadsheet |
|
Generic function to read a dictionary from a spreadsheet |
Thermdat
This is the output format used for Chemkin. A list of NASA objects can be written to a thermdat file.
Directly read thermdat file that is in the Chemkin format |
|
Writes thermdats in the Chemkin format |
JSON
JavaScript Object Notation (JSON) is a format that is easily read and
written by both humans and machines. All pmutt objects with the methods
to_dict and from_dict are JSON compatible.
Encodes pmutt objects to JSON format. |
|
Object hook to convert json to pmutt objects. |
Examples
Saving pmutt objects can be done by using
pmuttEncoder().
import json
from pmutt.io.json import pmuttEncoder
with open(json_path, 'w') as f_ptr:
json.dump(pmutt_obj, f_ptr, cls=pmuttEncoder, indent=True)
Loading pmutt objects can be done by using the object hook:
json_to_pmutt().
import json
from pmutt.io.json import json_to_pmutt
with open(json_path, 'r') as f_ptr:
pmutt_obj = json.load(f_ptr, object_hook=json_to_pmutt)
Sample JSON File
JSON writes in a human-readable syntax. An example showing a H2
Shomate object in JSON format is shown below.
{
"class": "<class 'pmutt.empirical.shomate.Shomate'>",
"type": "shomate",
"name": "H2",
"phase": "G",
"elements": {
"H": 2
},
"notes": null,
"smiles": null,
"model": null,
"misc_models": [
{
"class": "<class 'pmutt.empirical.GasPressureAdj'>"
}
],
"a": [
33.066178,
-11.363417,
11.432816,
-2.772874,
-0.158558,
-9.980797,
172.707974,
0.0
],
"T_low": 298.0,
"T_high": 1000.0,
"units": "J/mol/K"
}
Creating New pmutt Classes
Encoding
To ensure your new class can be encoded using the pmuttEncoder, the
to_dict() method should be implemented. One of the entries of the
dictionary should be 'class': str(self.__class__) so that it can be decoded
later. The other elements should be the attributes that can be used to
reinitialize the object and must be JSON-supported objects. A simple example
using FreeTrans is shown below.
def to_dict(self):
return {'class': str(self.__class__),
'n_degrees': self.n_degrees,
'molecular_weight': self.molecular_weight}
If the attributes are not supported by JSON (such as other pmutt objects), use
their to_dict() methods to convert to JSON-supported objects. An example
using StatMech is shown below.
def to_dict(self):
return {'class': str(self.__class__),
'trans_model': self.trans_model.to_dict(),
'vib_model': self.vib_model.to_dict(),
'rot_model': self.rot_model.to_dict(),
'elec_model': self.elec_model.to_dict(),
'nucl_model': self.nucl_model.to_dict()}
Decoding
To ensure your object can be decoded using the json_to_pmutt object hook,
add an entry to the dictionary in the pmutt.io.json.type_to_class method.
The key should be the type of your object in string format (i.e. the result of
str(self.__class__)). Your class should also have the from_dict() class
method to reinitialize your object. A simple example using
FreeTrans is shown below.
from pmutt.io.json import remove_class
@classmethod
def from_dict(cls, json_obj):
json_obj = remove_class(json_obj)
return cls(**json_obj)
Similarly to encoding, sometimes your object contains pmutt objects. You can
use the json_to_pmutt object hook to remake these objects. An example using
StatMech is shown below.
from pmutt.io import json as json_pmutt
@classmethod
def from_dict(cls, json_obj):
json_obj = remove_class(json_obj)
trans_model = json_pmutt.json_to_pmutt(json_obj['trans_model'])
vib_model = json_pmutt.json_to_pmutt(json_obj['vib_model'])
rot_model = json_pmutt.json_to_pmutt(json_obj['rot_model'])
elec_model = json_pmutt.json_to_pmutt(json_obj['elec_model'])
nucl_model = json_pmutt.json_to_pmutt(json_obj['nucl_model'])
return cls(trans_model=trans_model,
vib_model=vib_model,
rot_model=rot_model,
elec_model=elec_model,
nucl_model=nucl_model)
YAML
YAML Ain’t Markup Language (YAML) is a human friendly data serialization standard for all programming languages. All pmutt objects are natively supported by YAML.
Examples
Saving pmutt objects can be done by using
pmuttEncoder().
import yaml
with open(yaml_path, 'w') as f_ptr:
yaml.dump(pmutt_obj, f_ptr)
Loading pmutt objects can be done by using the object hook:
json_to_pmutt().
import yaml
with open(yaml_path, 'r') as f_ptr:
pmutt_obj = yaml.load(f_ptr)
Sample YAML File
YAML writes in a human-readable syntax. An example showing a H2
Shomate object in YAML format is shown below.
!!python/object:pmutt.empirical.shomate.Shomate
T_high: 1000.0
T_low: 298.0
_units: J/mol/K
a: !!python/object/apply:numpy.core.multiarray._reconstruct
args:
- !!python/name:numpy.ndarray ''
- !!python/tuple [0]
- !!binary |
Yg==
state: !!python/tuple
- 1
- !!python/tuple [8]
- !!python/object/apply:numpy.dtype
args: [f8, 0, 1]
state: !!python/tuple [3, <, null, null, null, -1, -1, 0]
- false
- !!binary |
e9tMhXiIQEDxngPLEbomwP9eCg+a3SZA/G1PkNguBsAZdELooEvEv6MHPgYr9iPAYw0XuaeWZUAA
AAAAAAAAAA==
elements: {H: 2}
misc_models:
- !!python/object:pmutt.empirical.GasPressureAdj {}
model: null
n_sites: null
name: H2
notes: null
phase: G
smiles: null
VASP
Parses OUTCAR files for vibrational frequencies and assigns to output_structure['vib_wavenumber']. |
Gaussian
Reads the pattern from the Gaussian log file. |
|
Reads the zero-point energy from the Gaussian log file. |
|
Reads the electronic energy and zero-point energy from the Gaussian log file. |
|
Reads the frequencies from the Gaussian log file. |
|
Reads the rotational temperatures from the Gaussian log file. |
|
Reads the molecular mass from the Gaussian log file. |
|
Reads the rotational symmetry number from the Gaussian log file. |
Chemkin
Directly read reactions from Chemkin gas.inp or surf.inp files |
|
Writes the EAs.inp or EAg.inp file for Chemkin |
|
Writes the gas.inp Chemkin file. |
|
Writes the surf.inp Chemkin file |
|
Writes the T_flow.inp Chemkin file |
|
Write tube_mole.inp Chemkin file |
OpenMKM
Writes the units, phases, species, lateral interactions, reactions and additional options in the CTI format for OpenMKM |
|
Writes the reactor options in a YAML file for OpenMKM. |
|
Writes the units, phases, species, lateral interactions, reactions and additional options in the CTI format for OpenMKM |
|
Helper method to organize species into its phases |
|
Helper method to organize reaction into its phases |
|
Helper method to organize reaction into its phases |
|
Helper method to organize phase data for OpenMKM |