def clean_species(self): """ Custom validation for the species field to ensure that a valid adjacency list has been provided. """ try: nasa = self.cleaned_data['NASA'] if nasa == '': return '' read_thermo_entry(nasa) except Exception: import traceback traceback.print_exc() raise forms.ValidationError('Invalid NASA Polynomial.') return nasa
def test_read_thermo_block_5_elem(self): """Test that we can read a thermo block with 5 elements""" species, thermo, formula = read_thermo_entry(self.entry2) self.assertEqual(species, 'CH3NO2X') self.assertEqual(formula, {'X': 1, 'C': 1, 'O': 2, 'H': 3, 'N': 1}) self.assertTrue(self.nasa.is_identical_to(thermo))
def test_read_thermo_block(self): """Test that we can read a normal thermo block""" species, thermo, formula = read_thermo_entry(self.entry1) self.assertEqual(species, 'C2H6') self.assertEqual(formula, {'H': 6, 'C': 2}) self.assertTrue(self.nasa.is_identical_to(thermo))
def evaluateNASA(request): """ Creates webpage form form entering a chemkin format NASA Polynomial and quickly obtaining it's enthalpy and Cp values. """ from rmgpy.chemkin import read_thermo_entry form = NASAForm() thermo = None thermo_data = None if request.method == 'POST': posted = NASAForm(request.POST, error_class=DivErrorList) initial = request.POST.copy() if posted.is_valid(): nasa = posted.cleaned_data['nasa'] if nasa != '': species, thermo, formula = read_thermo_entry(nasa) try: thermo_data = thermo.to_thermo_data() except: # if we cannot convert the thermo to thermo data, we will not be able to display the # H298, S298, and Cp values, but that's ok. pass form = NASAForm(initial, error_class=DivErrorList) return render(request, 'NASA.html', {'form': form, 'thermo': thermo, 'thermoData': thermo_data})
def test_read_thermo_entry_bad_element_count(self, mock_logging): """ Test that invalid element count logs the appropriate warning. This test uses the `mock` module in order to test calls to logging. The `mock.patch` decorator replaces the logging module instance in rmgpy.chemkin with a mock instance that can be accessed by this unit test. By using the mock instance, it is possible to assert that the expected logging statements are being created. """ entry = """C2H6 H XC X L 100.000 5000.000 827.28 1 2.44813916E+00 1.83377834E-02-7.25714119E-06 1.35300042E-09-9.60327447E-14 2 -1.19655244E+04 8.07917520E+00 3.50507145E+00-3.65219841E-03 6.32200490E-05 3 -8.01049582E-08 3.19734088E-11-1.15627878E+04 6.67152939E+00 4 """ with self.assertRaises(ValueError): read_thermo_entry(entry) mock_logging.info.assert_called_with( "Trouble reading line 'C2H6 H XC X L 100.000 5000.000 827.28 1' element segment 'H X'")
def test_read_thermo_entry_no_temperature_range(self): """Test that missing temperature range can be handled for thermo entry.""" entry = """C2H6 H 6C 2 G 1 2.44813916E+00 1.83377834E-02-7.25714119E-06 1.35300042E-09-9.60327447E-14 2 -1.19655244E+04 8.07917520E+00 3.50507145E+00-3.65219841E-03 6.32200490E-05 3 -8.01049582E-08 3.19734088E-11-1.15627878E+04 6.67152939E+00 4 """ species, thermo, formula = read_thermo_entry(entry, Tmin=100.0, Tint=827.28, Tmax=5000.0) self.assertEqual(species, 'C2H6') self.assertEqual(formula, {'H': 6, 'C': 2}) self.assertTrue(isinstance(thermo, NASA))
def test_read_thermo_entry_not_float(self, mock_logging): """ Test that non-float parameters log the appropriate warning. This test uses the `mock` module in order to test calls to logging. The `mock.patch` decorator replaces the logging module instance in rmgpy.chemkin with a mock instance that can be accessed by this unit test. By using the mock instance, it is possible to assert that the expected logging statements are being created. """ entry = """C2H6 H 6C 2 G 100.000 5000.000 827.28 1 X.44813916E+00 1.83377834E-02-7.25714119E-06 1.35300042E-09-9.60327447E-14 2 -1.19655244E+04 8.07917520E+00 3.50507145E+00-3.65219841E-03 6.32200490E-05 3 -8.01049582E-08 3.19734088E-11-1.15627878E+04 6.67152939E+00 4 """ species, thermo, formula = read_thermo_entry(entry) mock_logging.warning.assert_called_with("could not convert string to float: 'X.44813916E+00'") self.assertEqual(species, 'C2H6') self.assertIsNone(formula) self.assertIsNone(thermo)