def test_model_chemistry_consistency(self): """ Test that ErrorCancelingReaction objects properly check that all species use the same model chemistry """ # Take ethane as the target ethane = ErrorCancelingSpecies(self.molecule1, (100.0, 'kJ/mol'), 'test_A') methyl = ErrorCancelingSpecies(self.molecule2, (20.0, 'kcal/mol'), 'test_B', (21000.0, 'cal/mol')) # This should throw an exception because the model chemistry is different with self.assertRaises(ValueError): ErrorCancelingReaction(ethane, {methyl: 2})
def test_error_canceling_reactions(self): """ Test that ErrorCancelingReaction object can be created and that hf298 can be calculated for the target """ # Take ethane as the target ethane = ErrorCancelingSpecies(self.molecule1, (100.0, 'kJ/mol'), 'test') methyl = ErrorCancelingSpecies(self.molecule2, (20.0, 'kcal/mol'), 'test', (21000.0, 'cal/mol')) # This reaction is not an isodesmic reaction, but that does not matter for the unit test rxn = ErrorCancelingReaction(ethane, {methyl: 2}) self.assertAlmostEqual(rxn.calculate_target_thermo().value_si, 2*21000.0*4.184-(2*20.0*4184-100.0*1000))
def test_error_canceling_species(self): """ Test that ErrorCancelingSpecies can be created properly """ error_canceling_species = ErrorCancelingSpecies(self.molecule1, (123.4, 'kcal/mol'), 'test', (100.0, 'kJ/mol')) self.assertIsInstance(error_canceling_species, ErrorCancelingSpecies) self.assertAlmostEqual(error_canceling_species.low_level_hf298.value_si, 123.4*4184) # For target species the high level data is not given target_species = ErrorCancelingSpecies(self.molecule2, (10.1, 'J/mol'), 'test') self.assertIs(target_species.high_level_hf298, None)
def setUpClass(cls): """ A method called before each unit test in this class. """ # Give all species a low level Hf298 of 100 J/mol--this is not important for this test hf = (100.0, 'J/mol') cls.propene = ErrorCancelingSpecies(Molecule(smiles='CC=C'), hf, 'test') cls.butane = ErrorCancelingSpecies(Molecule(smiles='CCCC'), hf, 'test') cls.benzene = ErrorCancelingSpecies(Molecule(smiles='c1ccccc1'), hf, 'test') cls.caffeine = ErrorCancelingSpecies(Molecule(smiles='CN1C=NC2=C1C(=O)N(C(=O)N2C)C'), hf, 'test') cls.ethyne = ErrorCancelingSpecies(Molecule(smiles='C#C'), hf, 'test')
def to_error_canceling_spcs(self, level_of_theory, source=None): """ Extract calculated and reference data from a specified model chemistry and source and return as a new ErrorCancelingSpecies object Args: level_of_theory ((Composite)LevelOfTheory): Level of theory to use as the low level data source (str): Reference data source to take the high level data from Raises: KeyError: If ``level_of_theory`` is not available for this reference species Returns: ErrorCancelingSpecies """ if level_of_theory not in self.calculated_data: raise KeyError( f'Level of theory `{level_of_theory}` not available for species {self}' ) molecule = Molecule().from_adjacency_list( self.adjacency_list, raise_atomtype_exception=False, raise_charge_exception=False) reference_enthalpy = self.get_reference_enthalpy(source=source) low_level_h298 = self.calculated_data[level_of_theory].thermo_data.H298 return ErrorCancelingSpecies(molecule, low_level_h298, level_of_theory, high_level_hf298=reference_enthalpy.h298, source=reference_enthalpy.source)
def test_molecule_input_in_error_canceling_species(self): """ Test that an exception is raised if an rmgpy Molecule object is not passed to an ErrorCancelingSpecies """ with self.assertRaises(ValueError): ErrorCancelingSpecies(self.species, (100.0, 'J/mol'), LevelOfTheory('test'))
def setUpClass(cls): try: import pyomo as pyo except ImportError: pyo = None cls.pyo = pyo lot = LevelOfTheory('test') cls.propene = ErrorCancelingSpecies(Molecule(smiles='CC=C'), (100, 'kJ/mol'), lot, (105, 'kJ/mol')) cls.propane = ErrorCancelingSpecies(Molecule(smiles='CCC'), (75, 'kJ/mol'), lot, (80, 'kJ/mol')) cls.butane = ErrorCancelingSpecies(Molecule(smiles='CCCC'), (150, 'kJ/mol'), lot, (145, 'kJ/mol')) cls.butene = ErrorCancelingSpecies(Molecule(smiles='C=CCC'), (175, 'kJ/mol'), lot, (180, 'kJ/mol')) cls.pentane = ErrorCancelingSpecies(Molecule(smiles='CCCCC'), (200, 'kJ/mol'), lot, (190, 'kJ/mol')) cls.pentene = ErrorCancelingSpecies(Molecule(smiles='C=CCCC'), (225, 'kJ/mol'), lot, (220, 'kJ/mol')) cls.hexane = ErrorCancelingSpecies(Molecule(smiles='CCCCCC'), (250, 'kJ/mol'), lot, (260, 'kJ/mol')) cls.hexene = ErrorCancelingSpecies(Molecule(smiles='C=CCCCC'), (275, 'kJ/mol'), lot, (275, 'kJ/mol')) cls.benzene = ErrorCancelingSpecies(Molecule(smiles='c1ccccc1'), (-50, 'kJ/mol'), lot, (-80, 'kJ/mol')) cls.caffeine = ErrorCancelingSpecies( Molecule(smiles='CN1C=NC2=C1C(=O)N(C(=O)N2C)C'), (300, 'kJ/mol'), lot) cls.ethyne = ErrorCancelingSpecies(Molecule(smiles='C#C'), (200, 'kJ/mol'), lot)