Ejemplo n.º 1
0
class TestThermoReadWrite(unittest.TestCase):
    def setUp(self):
        """This method is run once before each test."""
        coeffs_low = [
            4.03055, -0.00214171, 4.90611e-05, -5.99027e-08, 2.38945e-11,
            -11257.6, 3.5613
        ]
        coeffs_high = [
            -0.307954, 0.0245269, -1.2413e-05, 3.07724e-09, -3.01467e-13,
            -10693, 22.628
        ]
        Tmin = 300.
        Tmax = 3000.
        Tint = 650.73
        E0 = -782292.  # J/mol.
        comment = "C2H6"
        self.nasa = NASA(
            polynomials=[
                NASAPolynomial(coeffs=coeffs_low,
                               Tmin=(Tmin, "K"),
                               Tmax=(Tint, "K")),
                NASAPolynomial(coeffs=coeffs_high,
                               Tmin=(Tint, "K"),
                               Tmax=(Tmax, "K")),
            ],
            Tmin=(Tmin, "K"),
            Tmax=(Tmax, "K"),
            E0=(E0, "J/mol"),
            comment=comment,
        )

        # Chemkin entries for testing - note that the values are all the same
        self.entry1 = """C2H6                    C   2H   6          G   300.000  3000.000  650.73      1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13    2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05    3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00                   4
"""

        self.entry2 = """CH3NO2X                                     G   300.000  3000.000  650.73      1&
C 1 H 3 N 1 O 2 X 1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13    2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05    3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00                   4
"""

        self.entry3 = """CH3NO2SX                                    G   300.000  3000.000  650.73      1&
C 1 H 3 N 1 O 2 S 1 X 1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13    2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05    3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00                   4
"""

    def test_write_thermo_block(self):
        """Test that we can write a normal thermo block"""
        species = Species(smiles='CC')
        species.thermo = self.nasa

        result = write_thermo_entry(species, verbose=False)

        self.assertEqual(result, self.entry1)

    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 test_write_thermo_block_5_elem(self):
        """Test that we can write a thermo block for a species with 5 elements"""
        species = Species().from_adjacency_list("""
1 O u0 p3 c-1 {3,S}
2 O u0 p2 c0 {3,D}
3 N u0 p0 c+1 {1,S} {2,D} {4,S}
4 C u0 p0 c0 {3,S} {5,S} {6,S} {7,S}
5 H u0 p0 c0 {4,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {4,S}
8 X u0 p0 c0
""")
        species.thermo = self.nasa

        result = write_thermo_entry(species, verbose=False)

        self.assertEqual(result, self.entry2)

    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_write_thermo_block_6_elem(self):
        """Test that we can write a thermo block for a species with 6 elements"""
        species = Species().from_adjacency_list("""
1 O u0 p3 c-1 {2,S}
2 N u0 p0 c+1 {1,S} {3,D} {4,S}
3 O u0 p2 c0 {2,D}
4 C u0 p0 c0 {2,S} {5,S} {6,S} {7,S}
5 S u0 p2 c0 {4,S} {8,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {4,S}
8 H u0 p0 c0 {5,S}
9 X u0 p0 c0
""")
        species.thermo = self.nasa

        result = write_thermo_entry(species, verbose=False)

        self.assertEqual(result, self.entry3)

    def test_read_thermo_block_6_elem(self):
        """Test that we can read a thermo block with 6 elements"""
        species, thermo, formula = read_thermo_entry(self.entry3)

        self.assertEqual(species, 'CH3NO2SX')
        self.assertEqual(formula, {
            'X': 1,
            'C': 1,
            'O': 2,
            'H': 3,
            'N': 1,
            'S': 1
        })
        self.assertTrue(self.nasa.is_identical_to(thermo))
Ejemplo n.º 2
0
class TestThermoReadWrite(unittest.TestCase):
    def setUp(self):
        """This method is run once before each test."""
        coeffs_low = [
            4.03055, -0.00214171, 4.90611e-05, -5.99027e-08, 2.38945e-11,
            -11257.6, 3.5613
        ]
        coeffs_high = [
            -0.307954, 0.0245269, -1.2413e-05, 3.07724e-09, -3.01467e-13,
            -10693, 22.628
        ]
        Tmin = 300.
        Tmax = 3000.
        Tint = 650.73
        E0 = -782292.  # J/mol.
        comment = "C2H6"
        self.nasa = NASA(
            polynomials=[
                NASAPolynomial(coeffs=coeffs_low,
                               Tmin=(Tmin, "K"),
                               Tmax=(Tint, "K")),
                NASAPolynomial(coeffs=coeffs_high,
                               Tmin=(Tint, "K"),
                               Tmax=(Tmax, "K")),
            ],
            Tmin=(Tmin, "K"),
            Tmax=(Tmax, "K"),
            E0=(E0, "J/mol"),
            comment=comment,
        )

        # Chemkin entries for testing - note that the values are all the same
        self.entry1 = """C2H6                    C   2H   6          G   300.000  3000.000  650.73      1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13    2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05    3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00                   4
"""

        self.entry2 = """CH3NO2X                                     G   300.000  3000.000  650.73      1&
C 1 H 3 N 1 O 2 X 1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13    2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05    3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00                   4
"""

        self.entry3 = """CH3NO2SX                                    G   300.000  3000.000  650.73      1&
C 1 H 3 N 1 O 2 S 1 X 1
-3.07954000E-01 2.45269000E-02-1.24130000E-05 3.07724000E-09-3.01467000E-13    2
-1.06930000E+04 2.26280000E+01 4.03055000E+00-2.14171000E-03 4.90611000E-05    3
-5.99027000E-08 2.38945000E-11-1.12576000E+04 3.56130000E+00                   4
"""

    def test_write_thermo_block(self):
        """Test that we can write a normal thermo block"""
        species = Species(smiles='CC')
        species.thermo = self.nasa

        result = write_thermo_entry(species, verbose=False)

        self.assertEqual(result, self.entry1)

    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 test_write_thermo_block_5_elem(self):
        """Test that we can write a thermo block for a species with 5 elements"""
        species = Species().from_adjacency_list("""
1 O u0 p3 c-1 {3,S}
2 O u0 p2 c0 {3,D}
3 N u0 p0 c+1 {1,S} {2,D} {4,S}
4 C u0 p0 c0 {3,S} {5,S} {6,S} {7,S}
5 H u0 p0 c0 {4,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {4,S}
8 X u0 p0 c0
""")
        species.thermo = self.nasa

        result = write_thermo_entry(species, verbose=False)

        self.assertEqual(result, self.entry2)

    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_write_thermo_block_6_elem(self):
        """Test that we can write a thermo block for a species with 6 elements"""
        species = Species().from_adjacency_list("""
1 O u0 p3 c-1 {2,S}
2 N u0 p0 c+1 {1,S} {3,D} {4,S}
3 O u0 p2 c0 {2,D}
4 C u0 p0 c0 {2,S} {5,S} {6,S} {7,S}
5 S u0 p2 c0 {4,S} {8,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {4,S}
8 H u0 p0 c0 {5,S}
9 X u0 p0 c0
""")
        species.thermo = self.nasa

        result = write_thermo_entry(species, verbose=False)

        self.assertEqual(result, self.entry3)

    def test_read_thermo_block_6_elem(self):
        """Test that we can read a thermo block with 6 elements"""
        species, thermo, formula = read_thermo_entry(self.entry3)

        self.assertEqual(species, 'CH3NO2SX')
        self.assertEqual(formula, {
            'X': 1,
            'C': 1,
            'O': 2,
            'H': 3,
            'N': 1,
            'S': 1
        })
        self.assertTrue(self.nasa.is_identical_to(thermo))

    def test_write_bidentate_species(self):
        """Test that species with 2 or more surface sites get proper formatting"""

        folder = os.path.join(os.path.dirname(rmgpy.__file__),
                              'test_data/chemkin/chemkin_py')
        chemkin_path = os.path.join(folder, 'surface', 'chem-surface.inp')
        dictionary_path = os.path.join(folder, 'surface',
                                       'species_dictionary.txt')
        chemkin_save_path = os.path.join(folder, 'surface',
                                         'chem-surface-test.inp')
        species, reactions = load_chemkin_file(chemkin_path, dictionary_path)

        surface_atom_count = species[3].molecule[0].get_num_atoms('X')
        self.assertEqual(surface_atom_count, 3)
        save_chemkin_surface_file(chemkin_save_path,
                                  species,
                                  reactions,
                                  verbose=False,
                                  check_for_duplicates=False)

        bidentate_test = "    CH2OX2(52)/2/             \n"
        tridentate_test = "    CHOX3(61)/3/             \n"
        with open(chemkin_save_path, "r") as f:
            for i, line in enumerate(f):
                if i == 3:
                    bidentate_read = line
                if i == 4:
                    tridentate_read = line

        self.assertEqual(bidentate_test.strip(), bidentate_read.strip())
        self.assertEqual(tridentate_test.strip(), tridentate_read.strip())

        os.remove(chemkin_save_path)