Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix nasa as dict #1630

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions arkane/inputTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
from rmgpy.statmech.rotation import NonlinearRotor
from rmgpy.kinetics.tunneling import Eckart
from rmgpy.exceptions import InputError
from rmgpy.thermo.nasa import NASAPolynomial, NASA
from rmgpy.molecule import Molecule

from arkane.input import species, transitionState, reaction, SMILES, loadInputFile, process_model_chemistry

Expand Down Expand Up @@ -81,6 +83,37 @@ def test_species(self):
self.assertIsInstance(spc0.transportData, TransportData)
self.assertIsInstance(spc0.energyTransferModel, SingleExponentialDown)

def test_species_atomic_NASA_polynomial(self):
"""
Test loading a atom with NASA polynomials
"""
label0 = "H(1)"
kwargs = {"structure": SMILES('[H]'),
"thermo": NASA(polynomials=[NASAPolynomial(coeffs=[2.5, 0, 0, 0, 0, 25473.7, -0.446683], Tmin=(200, 'K'), Tmax=(1000, 'K')),
NASAPolynomial(coeffs=[2.5, 0, 0, 0, 0, 25473.7, -0.446683], Tmin=(1000, 'K'), Tmax=(6000, 'K'))],
Tmin=(200, 'K'), Tmax=(6000, 'K'), comment="""Thermo library: FFCM1(-)"""),
"energyTransferModel": SingleExponentialDown(alpha0=(3.5886, 'kJ/mol'), T0=(300, 'K'), n=0.85)}
spc0 = species(label0, **kwargs)
self.assertEqual(spc0.label, label0)
self.assertEqual(spc0.SMILES, '[H]')
self.assertTrue(spc0.hasStatMech())
self.assertEqual(spc0.thermo, kwargs['thermo'])

def test_species_polyatomic_NASA_polynomial(self):
"""
Test loading a species with NASA polynomials
"""
label0 = "benzyl"
kwargs = {"structure": SMILES('[c]1ccccc1'),
"thermo": NASA(polynomials=[NASAPolynomial(coeffs=[2.78632, 0.00784632, 7.97887e-05, -1.11617e-07, 4.39429e-11, 39695, 11.5114], Tmin=(100, 'K'), Tmax=(943.73, 'K')),
NASAPolynomial(coeffs=[13.2455, 0.0115667, -2.49996e-06, 4.66496e-10, -4.12376e-14, 35581.1, -49.6793], Tmin=(943.73, 'K'), Tmax=(5000, 'K'))],
Tmin=(100, 'K'), Tmax=(5000, 'K'), comment="""Thermo library: Fulvene_H + radical(CbJ)"""),
"energyTransferModel": SingleExponentialDown(alpha0=(3.5886, 'kJ/mol'), T0=(300, 'K'), n=0.85)}
spc0 = species(label0, **kwargs)
self.assertEqual(spc0.label, label0)
self.assertTrue(spc0.hasStatMech())
self.assertEqual(spc0.thermo, kwargs['thermo'])

def test_transitionState(self):
"""
Test loading a transition state from input file-like kew word arguments
Expand Down
15 changes: 10 additions & 5 deletions rmgpy/thermo/nasa.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,16 @@ cdef class NASA(HeatCapacityModel):
poly_dict[key]['coeffs'] = poly.coeffs.tolist()
i = i + 1
output_dict['polynomials'] = poly_dict
output_dict['Tmin'] = self.Tmin.as_dict()
output_dict['Tmax'] = self.Tmax.as_dict()
output_dict['E0'] = self.E0.as_dict()
output_dict['Cp0'] = self.Cp0.as_dict()
output_dict['CpInf'] = self.CpInf.as_dict()
if self.Tmin:
output_dict['Tmin'] = self.Tmin.as_dict()
if self.Tmax:
output_dict['Tmax'] = self.Tmax.as_dict()
if self.E0:
output_dict['E0'] = self.E0.as_dict()
if self.Cp0:
output_dict['Cp0'] = self.Cp0.as_dict()
if self.CpInf:
output_dict['CpInf'] = self.CpInf.as_dict()
if self.label != '':
output_dict['label'] = self.label
if self.comment != '':
Expand Down
30 changes: 30 additions & 0 deletions rmgpy/thermo/nasaTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,33 @@ def testToNASA(self):
self.assertEqual(wilhoit.comment,nasa.comment)

# nasa to wilhoi performed in wilhoitTest

def test_nasa_as_dict_full(self):
"""
Test that NASA.as_dict functions properly with all attributes
"""
nasa_dict = self.nasa.as_dict()
self.assertEqual(nasa_dict['E0']['value'], self.E0)
self.assertEqual(nasa_dict['Tmin']['value'], self.Tmin)
self.assertEqual(nasa_dict['Tmax']['value'], self.Tmax)
self.assertEqual(nasa_dict['comment'], self.comment)
self.assertTupleEqual(tuple(nasa_dict['polynomials']['polynomial1']['coeffs']), tuple(self.coeffs_low))
self.assertTupleEqual(tuple(nasa_dict['polynomials']['polynomial2']['coeffs']), tuple(self.coeffs_high))
self.assertEqual(nasa_dict['polynomials']['polynomial1']['Tmin']['value'], self.Tmin)
self.assertEqual(nasa_dict['polynomials']['polynomial1']['Tmax']['value'], self.Tint)
self.assertEqual(nasa_dict['polynomials']['polynomial2']['Tmin']['value'], self.Tint)
self.assertEqual(nasa_dict['polynomials']['polynomial2']['Tmax']['value'], self.Tmax)

def test_nasa_as_dict_minimal(self):
"""
Test that NASA.as_dict does not contain empty, optional attributes
"""
nasa_dict = NASA().as_dict()
keys = nasa_dict.keys()
self.assertNotIn('Tmin', keys)
self.assertNotIn('Tmax', keys)
self.assertNotIn('E0', keys)
self.assertNotIn('Cp0', keys)
self.assertNotIn('CpInf', keys)
self.assertNotIn('label', keys)
self.assertNotIn('comment', keys)