예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    def write_chemkin(self, output_directory):
        """
        Appends the thermo block to `chem.inp` and species name to
        `species_dictionary.txt` within the `outut_directory` specified
        """
        species = self.species
        with open(os.path.join(output_directory, 'chem.inp'), 'a') as f:
            if isinstance(species, Species):
                if species.molecule and isinstance(species.molecule[0],
                                                   Molecule):
                    element_counts = get_element_count(species.molecule[0])
                else:
                    try:
                        element_counts = species.props['element_counts']
                    except KeyError:
                        element_counts = self.element_count_from_conformer()
            else:
                element_counts = {'C': 0, 'H': 0}
            chemkin_thermo_string = write_thermo_entry(
                species, element_counts=element_counts, verbose=True)
            f.write('{0}\n'.format(chemkin_thermo_string))

        # write species dictionary
        if isinstance(species, Species):
            if species.molecule and isinstance(species.molecule[0], Molecule):
                spec_dict_path = os.path.join(output_directory,
                                              'species_dictionary.txt')
                is_species_in_dict = False
                if os.path.isfile(spec_dict_path):
                    with open(spec_dict_path, 'r') as f:
                        # check whether the species dictionary contains this species, in which case do not re-append
                        for line in f.readlines():
                            if species.label == line.strip():
                                is_species_in_dict = True
                                break
                if not is_species_in_dict:
                    with open(spec_dict_path, 'a') as f:
                        f.write(species.molecule[0].to_adjacency_list(
                            remove_h=False, label=species.label))
                        f.write('\n')
        return chemkin_thermo_string