<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

################################################################################
#
#	RMG - Reaction Mechanism Generator
#
#	Copyright (c) 2002-2009 Prof. <NAME> (<EMAIL>) and the
#	RMG Team (<EMAIL>)
#
#	Permission is hereby granted, free of charge, to any person obtaining a
#	copy of this software and associated documentation files (the 'Software'),
#	to deal in the Software without restriction, including without limitation
#	the rights to use, copy, modify, merge, publish, distribute, sublicense,
#	and/or sell copies of the Software, and to permit persons to whom the
#	Software is furnished to do so, subject to the following conditions:
#
#	The above copyright notice and this permission notice shall be included in
#	all copies or substantial portions of the Software.
#
#	THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#	DEALINGS IN THE SOFTWARE.
#
################################################################################

"""
Contains classes for working with the reaction model generated by RMG.
"""

import logging
import math
import numpy
import os.path

from rmgpy.display import display

from rmgpy.quantity import Quantity, constants
import rmgpy.species
from rmgpy.thermo import Wilhoit, MultiNASA

from rmgpy.data.thermo import *
from rmgpy.data.kinetics import *
from rmgpy.data.states import *
import rmgpy.data.rmg

#needed to call the generate3dTS method in Reaction class
from rmgpy.reaction import Reaction

from pdep import PDepReaction, PDepNetwork, PressureDependenceError
# generateThermoDataFromQM under the Species class imports the qm package


################################################################################

class Species(rmgpy.species.Species):

    def __init__(self, index=-1, label='', thermo=None, states=None, molecule=None, E0=0.0, lennardJones=None, molecularWeight=0.0, collisionModel=None, reactive=True, coreSizeAtCreation=0):
        rmgpy.species.Species.__init__(self, index, label, thermo, states, molecule, E0, lennardJones, molecularWeight, collisionModel, reactive)
        self.coreSizeAtCreation = coreSizeAtCreation

    def __reduce__(self):
        """
        A helper function used when pickling an object.
        """
        return (Species, (self.index, self.label, self.thermo, self.states, self.molecule, self.E0, self.lennardJones, self.molecularWeight, self.reactive, self.coreSizeAtCreation),)
    
    def generateThermoData(self, database, thermoClass=MultiNASA, quantumMechanics=None):
        """
        Generates thermo data, using either QM or Database.
        
        If quantumMechanics is not None, it is aksed to calculate the thermo.
        Failing that, the database is used.
        
        The database enerates the thermo data for each structure (resonance isomer),
        picks that with lowest H298 value.
        
        It then calls :meth:`processThermoData`.
        Result stored in `self.thermo` and returned.
        """
        thermo0 = None
        
        thermo0 = database.thermo.getThermoDataFromLibraries(self)
        
        if thermo0 is not None:
            logging.info("Found thermo for {0} in thermo library".format(self.label))
            
        elif quantumMechanics:
            molecule = self.molecule[0]
            if quantumMechanics.settings.onlyCyclics and not molecule.isCyclic():
                pass
                #logging.info("Skipping QM calculation for noncyclic molecule {0}".format(molecule.toSMILES()))
            else: # try a QM calculation
                if self.molecule[0].getRadicalCount() > quantumMechanics.settings.maxRadicalNumber:
                    # Too many radicals for direct calculation: use HBI.
                    logging.info("{0} radicals on {1} exceeds limit of {2}. Using HBI method.".format(
                        self.molecule[0].getRadicalCount(),
                        self.label,
                        quantumMechanics.settings.maxRadicalNumber,
                        ))
                    thermo0 = database.thermo.estimateRadicalThermoViaHBI(molecule, quantumMechanics.getThermoData)
                else: # Not too many radicals: do a direct calculation.
                    thermo0 = quantumMechanics.getThermoData(molecule) # returns None if it fails
        if thermo0 is None:
            thermo0 = database.thermo.getThermoData(self)

        return self.processThermoData(thermo0, thermoClass)
<commit_msg>Append to a thermoHBIcheck.txt for debugging HBI thermo estimates.<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

################################################################################
#
#	RMG - Reaction Mechanism Generator
#
#	Copyright (c) 2002-2009 Prof. <NAME> (<EMAIL>) and the
#	RMG Team (<EMAIL>)
#
#	Permission is hereby granted, free of charge, to any person obtaining a
#	copy of this software and associated documentation files (the 'Software'),
#	to deal in the Software without restriction, including without limitation
#	the rights to use, copy, modify, merge, publish, distribute, sublicense,
#	and/or sell copies of the Software, and to permit persons to whom the
#	Software is furnished to do so, subject to the following conditions:
#
#	The above copyright notice and this permission notice shall be included in
#	all copies or substantial portions of the Software.
#
#	THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#	DEALINGS IN THE SOFTWARE.
#
################################################################################

"""
Contains classes for working with the reaction model generated by RMG.
"""

import logging
import math
import numpy
import os.path

from rmgpy.display import display

from rmgpy.quantity import Quantity, constants
import rmgpy.species
from rmgpy.thermo import Wilhoit, MultiNASA

from rmgpy.data.thermo import *
from rmgpy.data.kinetics import *
from rmgpy.data.states import *
import rmgpy.data.rmg

#needed to call the generate3dTS method in Reaction class
from rmgpy.reaction import Reaction

from pdep import PDepReaction, PDepNetwork, PressureDependenceError
# generateThermoDataFromQM under the Species class imports the qm package


################################################################################

class Species(rmgpy.species.Species):

    def __init__(self, index=-1, label='', thermo=None, states=None, molecule=None, E0=0.0, lennardJones=None, molecularWeight=0.0, collisionModel=None, reactive=True, coreSizeAtCreation=0):
        rmgpy.species.Species.__init__(self, index, label, thermo, states, molecule, E0, lennardJones, molecularWeight, collisionModel, reactive)
        self.coreSizeAtCreation = coreSizeAtCreation

    def __reduce__(self):
        """
        A helper function used when pickling an object.
        """
        return (Species, (self.index, self.label, self.thermo, self.states, self.molecule, self.E0, self.lennardJones, self.molecularWeight, self.reactive, self.coreSizeAtCreation),)
    
    def generateThermoData(self, database, thermoClass=MultiNASA, quantumMechanics=None):
        """
        Generates thermo data, using either QM or Database.
        
        If quantumMechanics is not None, it is aksed to calculate the thermo.
        Failing that, the database is used.
        
        The database enerates the thermo data for each structure (resonance isomer),
        picks that with lowest H298 value.
        
        It then calls :meth:`processThermoData`.
        Result stored in `self.thermo` and returned.
        """
        thermo0 = None
        
        thermo0 = database.thermo.getThermoDataFromLibraries(self)
        
        if thermo0 is not None:
            logging.info("Found thermo for {0} in thermo library".format(self.label))
            
        elif quantumMechanics:
            molecule = self.molecule[0]
            if quantumMechanics.settings.onlyCyclics and not molecule.isCyclic():
                pass
                #logging.info("Skipping QM calculation for noncyclic molecule {0}".format(molecule.toSMILES()))
            else: # try a QM calculation
                if self.molecule[0].getRadicalCount() > quantumMechanics.settings.maxRadicalNumber:
                    # Too many radicals for direct calculation: use HBI.
                    logging.info("{0} radicals on {1} exceeds limit of {2}. Using HBI method.".format(
                        self.molecule[0].getRadicalCount(),
                        self.label,
                        quantumMechanics.settings.maxRadicalNumber,
                        ))
                    #import ipdb; ipdb.set_trace()
                    thermo0 = database.thermo.estimateRadicalThermoViaHBI(molecule, quantumMechanics.getThermoData)
                    with open('thermoHBIcheck.txt','a') as f:
                        f.write('// {0!r}\n'.format(thermo0).replace('),','),\n//           '))
                        f.write('{0}\n'.format(molecule.toSMILES()))
                        f.write('{0}\n\n'.format(molecule.toAdjacencyList(removeH=True)))
                else: # Not too many radicals: do a direct calculation.
                    thermo0 = quantumMechanics.getThermoData(molecule) # returns None if it fails
        if thermo0 is None:
            thermo0 = database.thermo.getThermoData(self)

        return self.processThermoData(thermo0, thermoClass)

{'fraction_non_alphanumeric': 0.12346527845987625, 'fraction_numerical': 0.00785777428543365, 'mean_word_length': 3.113939393939394, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3555401', 'n_tokens_mistral': 2887, 'n_tokens_neox': 2661, 'n_words': 925}