Esempio n. 1
0
    def testOneVibration(self):
        """
        Unit tests involving fitting of one vibrational frequency and zero
        hindered rotors.
        """
        frequencies = [500.0, 1000.0, 1500.0, 2000.0, 2500.0, 3000.0]
        Tlist = numpy.arange(300.0, 2001.0, 100.0, numpy.float64)

        colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']
        for i, freq in enumerate(frequencies):
            ho = HarmonicOscillator(frequencies=[freq])
            Cv_data = ho.getHeatCapacities(Tlist) / constants.R

            modes = fitStatesToHeatCapacity(Tlist, Cv_data, Nvib=1, Nrot=0)
            
            self.assertTrue(len(modes) == 1)
            self.assertTrue(isinstance(modes[0], HarmonicOscillator))
            self.assertTrue(len(modes[0].frequencies) == 1)
            self.assertAlmostEqual(modes[0].frequencies[0] / freq, 1.0, 4, 'Fitted vibrational frequency of %g cm^-1 does not match expected value of %g cm^-1.' % (modes[0].frequencies[0], freq))

            Cv_model = numpy.zeros_like(Tlist)
            for mode in modes:
                Cv_model += mode.getHeatCapacities(Tlist) / constants.R

            pylab.plot(Tlist, Cv_data, 'o%s' % colors[i], Tlist, Cv_model, '-%s' % colors[i])

        pylab.xlabel('Temperature (K)')
        pylab.ylabel('Heat capacity / R')
        if showPlots: pylab.show()
Esempio n. 2
0
    def testOneRotor(self):
        """
        Unit tests involving fitting of zero vibrational frequencies and one
        hindered rotor.
        """
        rotors = [(300.0, 100.0), (300.0, 1000.0), (300.0, 3000.0), (1000.0, 100.0), (1000.0, 500.0), (1000.0, 3000.0)]
        Tlist = numpy.arange(300.0, 2001.0, 100.0, numpy.float64)

        colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']
        for i, rotor in enumerate(rotors):
            freq, barr = rotor

            hr = makeHinderedRotor(freq, barr)
            Cv_data = hr.getHeatCapacities(Tlist) / constants.R

            modes = fitStatesToHeatCapacity(Tlist, Cv_data, Nvib=0, Nrot=1)
            
            self.assertTrue(len(modes) == 1)
            self.assertTrue(isinstance(modes[0], HinderedRotor))
            freq0 = modes[0].getFrequency()
            barr0 = modes[0].barrier / (constants.h * constants.c * 100.0 * constants.Na)
            self.assertAlmostEqual(freq0 / freq, 1.0, 4, 'Fitted rotor frequency of %g cm^-1 does not match expected value of %g cm^-1.' % (freq0, freq))
            self.assertAlmostEqual(barr0 / barr, 1.0, 4, 'Fitted rotor barrier of %g cm^-1 does not match expected value of %g cm^-1.' % (barr0, barr))

            Cv_model = numpy.zeros_like(Tlist)
            for mode in modes:
                Cv_model += mode.getHeatCapacities(Tlist) / constants.R

            pylab.plot(Tlist, Cv_data, 'o%s' % colors[i], Tlist, Cv_model, '-%s' % colors[i])

        pylab.xlabel('Temperature (K)')
        pylab.ylabel('Heat capacity / R')
        if showPlots: pylab.show()
Esempio n. 3
0
    def testManyVibrations(self):
        """
        Unit tests involving fitting of many vibrational frequency and zero
        hindered rotors.
        """
        frequencies = numpy.arange(300.0, 3001.0, 300.0, numpy.float64)
        Tlist = numpy.arange(300.0, 2001.0, 100.0, numpy.float64)

        ho = HarmonicOscillator(frequencies=list(frequencies))
        Cv_data = ho.getHeatCapacities(Tlist) / constants.R

        modes = fitStatesToHeatCapacity(Tlist, Cv_data, Nvib=len(frequencies), Nrot=0)
        
        self.assertTrue(len(modes) == 1)
        self.assertTrue(isinstance(modes[0], HarmonicOscillator))
        self.assertTrue(len(modes[0].frequencies) == len(frequencies))
        for i in range(len(frequencies)):
            self.assertAlmostEqual(modes[0].frequencies[i] / frequencies[i], 1.0, 2, 'Fitted vibrational frequency of %g cm^-1 does not match expected value of %g cm^-1.' % (modes[0].frequencies[i], frequencies[i]))
        
        T_model = numpy.arange(300.0, 2001.0, 100.0, numpy.float64)
        Cv_model = numpy.zeros_like(T_model)
        for mode in modes:
            Cv_model += mode.getHeatCapacities(T_model) / constants.R

        pylab.plot(Tlist, Cv_data, 'ok', T_model, Cv_model, '-k')

        pylab.xlabel('Temperature (K)')
        pylab.ylabel('Heat capacity / R')
        if showPlots: pylab.show()