Exemple #1
0
def isCorrectlyParsed(mol, identifier):
    """Check if molecule object has been correctly parsed."""
    conditions = []

    if mol.atoms:
        conditions.append(True)
    else:
        conditions.append(False)

    if 'InChI' in identifier:
        inchi_elementcount = util.retrieveElementCount(identifier)
        mol_elementcount = util.retrieveElementCount(mol)
        conditions.append(inchi_elementcount == mol_elementcount)

    return all(conditions)
Exemple #2
0
def isCorrectlyParsed(mol, identifier):
    """Check if molecule object has been correctly parsed."""
    conditions = []

    if mol.atoms:
        conditions.append(True)
    else:
        conditions.append(False)

    if 'InChI' in identifier:
        inchi_elementcount = util.retrieveElementCount(identifier)
        mol_elementcount = util.retrieveElementCount(mol)
        conditions.append(inchi_elementcount == mol_elementcount)

    return all(conditions)
Exemple #3
0
def _check_output(mol, identifier):
    """Check if molecule object has been correctly parsed."""
    conditions = []

    # Check that the molecule has atoms
    conditions.append(bool(mol.atoms))
    # Check that the identifier is not blank
    conditions.append(bool(identifier.strip()))

    # Check that the InChI element count matches the molecule
    if 'InChI=1' in identifier:
        inchi_elementcount = util.retrieveElementCount(identifier)
        mol_elementcount = util.retrieveElementCount(mol)
        conditions.append(inchi_elementcount == mol_elementcount)

    return all(conditions)
def _check_output(mol, identifier):
    """Check if molecule object has been correctly parsed."""
    conditions = []

    # Check that the molecule has atoms
    conditions.append(bool(mol.atoms))
    # Check that the identifier is not blank
    conditions.append(bool(identifier.strip()))

    # Check that the InChI element count matches the molecule
    if 'InChI=1' in identifier:
        inchi_elementcount = util.retrieveElementCount(identifier)
        mol_elementcount = util.retrieveElementCount(mol)
        conditions.append(inchi_elementcount == mol_elementcount)

    return all(conditions)
Exemple #5
0
    def save(self, outputFile):
        """
        Save the results of the thermodynamics job to the file located
        at `path` on disk.
        """
        species = self.species
        logging.info('Saving thermo for {0}...'.format(species.label))
        
        f = open(outputFile, 'a')
    
        f.write('# Thermodynamics for {0}:\n'.format(species.label))
        H298 = species.getThermoData().getEnthalpy(298) / 4184.
        S298 = species.getThermoData().getEntropy(298) / 4.184
        f.write('#   Enthalpy of formation (298 K)   = {0:9.3f} kcal/mol\n'.format(H298))
        f.write('#   Entropy of formation (298 K)    = {0:9.3f} cal/(mol*K)\n'.format(S298))
        f.write('#    =========== =========== =========== =========== ===========\n')
        f.write('#    Temperature Heat cap.   Enthalpy    Entropy     Free energy\n')
        f.write('#    (K)         (cal/mol*K) (kcal/mol)  (cal/mol*K) (kcal/mol)\n')
        f.write('#    =========== =========== =========== =========== ===========\n')
        for T in [300,400,500,600,800,1000,1500,2000,2400]:
            try:
                Cp = species.getThermoData().getHeatCapacity(T) / 4.184
                H = species.getThermoData().getEnthalpy(T) / 4184.
                S = species.getThermoData().getEntropy(T) / 4.184
                G = species.getThermoData().getFreeEnergy(T) / 4184.
                f.write('#    {0:11g} {1:11.3f} {2:11.3f} {3:11.3f} {4:11.3f}\n'.format(T, Cp, H, S, G))
            except ValueError:
                logging.debug("Valid thermo for {0} is outside range for temperature {1}".format(species,T))
        f.write('#    =========== =========== =========== =========== ===========\n')

        thermo_string = 'thermo(label={0!r}, thermo={1!r})'.format(species.label, species.getThermoData())
        f.write('{0}\n\n'.format(prettify(thermo_string)))
        
        f.close()
        # write chemkin file
        f = open(os.path.join(os.path.dirname(outputFile), 'chem.inp'), 'a')
        if isinstance(species, Species):
            if species.molecule and isinstance(species.molecule[0], Molecule):
                elementCounts = retrieveElementCount(species.molecule[0])
            else:
                try:
                    elementCounts = species.props['elementCounts']
                except KeyError:
                    elementCounts = {'C': 0, 'H': 0}
        else:
            elementCounts = {'C': 0, 'H': 0}
        chemkin_thermo_string = writeThermoEntry(species, elementCounts=elementCounts, verbose=True)
        f.write('{0}\n'.format(chemkin_thermo_string))
        f.close()

        # write species dictionary
        if isinstance(species, Species):
            if species.molecule and isinstance(species.molecule[0], Molecule):
                with open(os.path.join(os.path.dirname(outputFile), 'species_dictionary.txt'), 'a') as f:
                    f.write(species.molecule[0].toAdjacencyList(removeH=False, label=species.label))
                    f.write('\n')
        return chemkin_thermo_string
Exemple #6
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 = retrieveElementCount(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 = writeThermoEntry(species, elementCounts=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].toAdjacencyList(removeH=False, label=species.label))
                        f.write('\n')
        return chemkin_thermo_string