コード例 #1
0
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.nC4H10O = Species(
            label = 'n-C4H10O',
            conformer = Conformer(
                E0 = (-317.807,'kJ/mol'),
                modes = [
                    IdealGasTranslation(mass=(74.07,"g/mol")),
                    NonlinearRotor(inertia=([41.5091,215.751,233.258],"amu*angstrom^2"), symmetry=1),
                    HarmonicOscillator(frequencies=([240.915,341.933,500.066,728.41,809.987,833.93,926.308,948.571,1009.3,1031.46,1076,1118.4,1184.66,1251.36,1314.36,1321.42,1381.17,1396.5,1400.54,1448.08,1480.18,1485.34,1492.24,1494.99,1586.16,2949.01,2963.03,2986.19,2988.1,2995.27,3026.03,3049.05,3053.47,3054.83,3778.88],"cm^-1")),
                    HinderedRotor(inertia=(0.854054,"amu*angstrom^2"), symmetry=1, fourier=([[0.25183,-1.37378,-2.8379,0.0305112,0.0028088], [0.458307,0.542121,-0.599366,-0.00283925,0.0398529]],"kJ/mol")),
                    HinderedRotor(inertia=(8.79408,"amu*angstrom^2"), symmetry=1, fourier=([[0.26871,-0.59533,-8.15002,-0.294325,-0.145357], [1.1884,0.99479,-0.940416,-0.186538,0.0309834]],"kJ/mol")),
                    HinderedRotor(inertia=(7.88153,"amu*angstrom^2"), symmetry=1, fourier=([[-4.67373,2.03735,-6.25993,-0.27325,-0.048748], [-0.982845,1.76637,-1.57619,0.474364,-0.000681718]],"kJ/mol")),
                    HinderedRotor(inertia=(2.81525,"amu*angstrom^2"), symmetry=3, barrier=(2.96807,"kcal/mol")),
                ],
                spinMultiplicity = 1,
                opticalIsomers = 1,
            ),
            molecularWeight = (74.07,"g/mol"),
            transportData=TransportData(sigma=(5.94, 'angstrom'), epsilon=(559, 'K')),
            energyTransferModel = SingleExponentialDown(alpha0=(447.5*0.011962,"kJ/mol"), T0=(300,"K"), n=0.85),
        )
        
        self.nC4H8 = Species(
            label = 'n-C4H8',
            conformer = Conformer(
                E0 = (-17.8832,'kJ/mol'),
                modes = [
                    IdealGasTranslation(mass=(56.06,"g/mol")),
                    NonlinearRotor(inertia=([22.2748,122.4,125.198],"amu*angstrom^2"), symmetry=1),
                    HarmonicOscillator(frequencies=([308.537,418.67,636.246,788.665,848.906,936.762,979.97,1009.48,1024.22,1082.96,1186.38,1277.55,1307.65,1332.87,1396.67,1439.09,1469.71,1484.45,1493.19,1691.49,2972.12,2994.31,3018.48,3056.87,3062.76,3079.38,3093.54,3174.52],"cm^-1")),
                    HinderedRotor(inertia=(5.28338,"amu*angstrom^2"), symmetry=1, fourier=([[-0.579364,-0.28241,-4.46469,0.143368,0.126756], [1.01804,-0.494628,-0.00318651,-0.245289,0.193728]],"kJ/mol")),
                    HinderedRotor(inertia=(2.60818,"amu*angstrom^2"), symmetry=3, fourier=([[0.0400372,0.0301986,-6.4787,-0.0248675,-0.0324753], [0.0312541,0.0538,-0.493785,0.0965968,0.125292]],"kJ/mol")),
                ],
                spinMultiplicity = 1,
                opticalIsomers = 1,
            ),
        )
        
        self.H2O = Species(
            label = 'H2O',
            conformer = Conformer(
                E0 = (-269.598,'kJ/mol'),
                modes = [
                    IdealGasTranslation(mass=(18.01,"g/mol")),
                    NonlinearRotor(inertia=([0.630578,1.15529,1.78586],"amu*angstrom^2"), symmetry=2),
                    HarmonicOscillator(frequencies=([1622.09,3771.85,3867.85],"cm^-1")),
                ],
                spinMultiplicity = 1,
                opticalIsomers = 1,
            ),
        )

        self.configuration = Configuration(self.nC4H8, self.H2O)
コード例 #2
0
 def setUp(self):
     """
     A function run before each unit test in this class.
     """
     self.inertia = numpy.array([3.415, 16.65, 20.07])
     self.symmetry = 4
     self.quantum = False
     self.mode = NonlinearRotor(
         inertia=(self.inertia, "amu*angstrom^2"),
         symmetry=self.symmetry,
         quantum=self.quantum,
     )
コード例 #3
0
ファイル: inputTest.py プロジェクト: shihchengli/RMG-Py
    def test_transition_state(self):
        """
        Test loading a transition state from input file-like kew word arguments
        """
        label0 = 'TS1'
        kwargs = {
            'E0': (39.95, 'kcal/mol'),
            'spinMultiplicity':
            2,
            'opticalIsomers':
            1,
            'frequency': (-1934, 'cm^-1'),
            'modes': [
                HarmonicOscillator(frequencies=(
                    [792, 987, 1136, 1142, 1482, 2441, 3096, 3183], 'cm^-1')),
                NonlinearRotor(rotationalConstant=([0.928, 0.962,
                                                    5.807], "cm^-1"),
                               symmetry=1,
                               quantum=False),
                IdealGasTranslation(mass=(31.01843, "g/mol"))
            ]
        }

        ts0 = transitionState(label0, **kwargs)
        self.assertEqual(ts0.label, 'TS1')
        self.assertAlmostEqual(ts0.conformer.E0.value_si, 167150.8)
        self.assertEqual(ts0.conformer.spin_multiplicity, 2)
        self.assertEqual(ts0.conformer.optical_isomers, 1)
        self.assertEqual(ts0.frequency.value_si, -1934.0)
        self.assertEqual(len(ts0.conformer.modes), 3)
コード例 #4
0
ファイル: rotationTest.py プロジェクト: KEHANG/RMG-Py
 def setUp(self):
     """
     A function run before each unit test in this class.
     """
     self.inertia = numpy.array([3.415, 16.65, 20.07])
     self.symmetry = 4
     self.quantum = False
     self.mode = NonlinearRotor(
         inertia=(self.inertia, "amu*angstrom^2"), symmetry=self.symmetry, quantum=self.quantum
     )
コード例 #5
0
ファイル: inputTest.py プロジェクト: shihchengli/RMG-Py
    def test_species(self):
        """
        Test loading a species from input file-like kew word arguments
        """
        label0 = 'CH2O'
        kwargs = {
            'E0': (28.69, 'kcal/mol'),
            'structure':
            SMILES('C=O'),
            'collisionModel':
            TransportData(sigma=(3.69e-10, 'm'), epsilon=(4.0, 'kJ/mol')),
            'energyTransferModel':
            SingleExponentialDown(alpha0=(0.956, 'kJ/mol'),
                                  T0=(300, 'K'),
                                  n=0.95),
            'spinMultiplicity':
            1,
            'opticalIsomers':
            1,
            'modes': [
                HarmonicOscillator(
                    frequencies=([1180, 1261, 1529, 1764, 2931, 2999],
                                 'cm^-1')),
                NonlinearRotor(rotationalConstant=([
                    1.15498821005263, 1.3156969584727, 9.45570474524524
                ], "cm^-1"),
                               symmetry=2,
                               quantum=False),
                IdealGasTranslation(mass=(30.0106, "g/mol")),
            ]
        }

        spc0 = species(label0, **kwargs)
        self.assertEqual(spc0.label, 'CH2O')
        self.assertEqual(spc0.smiles, 'C=O')
        self.assertAlmostEqual(spc0.conformer.E0.value_si, 120038.96)
        self.assertEqual(spc0.conformer.spin_multiplicity, 1)
        self.assertEqual(spc0.conformer.optical_isomers, 1)
        self.assertEqual(len(spc0.conformer.modes), 3)
        self.assertIsInstance(spc0.transport_data, TransportData)
        self.assertIsInstance(spc0.energy_transfer_model,
                              SingleExponentialDown)
コード例 #6
0
class TestNonlinearRotor(unittest.TestCase):
    """
    Contains unit tests of the NonlinearRotor class.
    """
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.inertia = numpy.array([3.415, 16.65, 20.07])
        self.symmetry = 4
        self.quantum = False
        self.mode = NonlinearRotor(
            inertia=(self.inertia, "amu*angstrom^2"),
            symmetry=self.symmetry,
            quantum=self.quantum,
        )

    def test_getRotationalConstant(self):
        """
        Test getting the NonlinearRotor.rotationalConstant property.
        """
        Bexp = numpy.array([4.93635, 1.0125, 0.839942])
        Bact = self.mode.rotationalConstant.value_si
        for B0, B in zip(Bexp, Bact):
            self.assertAlmostEqual(B0, B, 4)

    def test_setRotationalConstant(self):
        """
        Test setting the NonlinearRotor.rotationalConstant property.
        """
        B = self.mode.rotationalConstant
        B.value_si *= 2
        self.mode.rotationalConstant = B
        Iexp = 0.5 * self.inertia
        Iact = self.mode.inertia.value_si * constants.Na * 1e23
        for I0, I in zip(Iexp, Iact):
            self.assertAlmostEqual(I0, I, 4)

    def test_getPartitionFunction_classical(self):
        """
        Test the NonlinearRotor.getPartitionFunction() method for a classical
        rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Qexplist = numpy.array([651.162, 1401.08, 3962.84, 7280.21, 11208.6])
        for T, Qexp in zip(Tlist, Qexplist):
            Qact = self.mode.getPartitionFunction(T)
            self.assertAlmostEqual(Qexp, Qact, delta=1e-4 * Qexp)

    def test_getHeatCapacity_classical(self):
        """
        Test the NonlinearRotor.getHeatCapacity() method using a classical
        rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Cvexplist = numpy.array([1.5, 1.5, 1.5, 1.5, 1.5]) * constants.R
        for T, Cvexp in zip(Tlist, Cvexplist):
            Cvact = self.mode.getHeatCapacity(T)
            self.assertAlmostEqual(Cvexp, Cvact, delta=1e-4 * Cvexp)

    def test_getEnthalpy_classical(self):
        """
        Test the NonlinearRotor.getEnthalpy() method using a classical rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Hexplist = numpy.array([1.5, 1.5, 1.5, 1.5, 1.5]) * constants.R * Tlist
        for T, Hexp in zip(Tlist, Hexplist):
            Hact = self.mode.getEnthalpy(T)
            self.assertAlmostEqual(Hexp, Hact, delta=1e-4 * Hexp)

    def test_getEntropy_classical(self):
        """
        Test the NonlinearRotor.getEntropy() method using a classical rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Sexplist = numpy.array([7.97876, 8.74500, 9.78472, 10.3929, 10.8244
                                ]) * constants.R
        for T, Sexp in zip(Tlist, Sexplist):
            Sact = self.mode.getEntropy(T)
            self.assertAlmostEqual(Sexp, Sact, delta=1e-4 * Sexp)

    def test_getSumOfStates_classical(self):
        """
        Test the NonlinearRotor.getSumOfStates() method using a classical rotor.
        """
        self.mode.quantum = False
        Elist = numpy.arange(0, 1000 * 11.96, 1 * 11.96)
        sumStates = self.mode.getSumOfStates(Elist)
        densStates = self.mode.getDensityOfStates(Elist)
        for n in range(10, len(Elist)):
            self.assertTrue(
                0.8 < numpy.sum(densStates[0:n]) / sumStates[n] < 1.25,
                '{0} != {1}'.format(numpy.sum(densStates[0:n]), sumStates[n]))

    def test_getDensityOfStates_classical(self):
        """
        Test the NonlinearRotor.getDensityOfStates() method using a classical
        rotor.
        """
        self.mode.quantum = False
        Elist = numpy.arange(0, 1000 * 11.96, 1 * 11.96)
        densStates = self.mode.getDensityOfStates(Elist)
        T = 100
        Qact = numpy.sum(densStates * numpy.exp(-Elist / constants.R / T))
        Qexp = self.mode.getPartitionFunction(T)
        self.assertAlmostEqual(Qexp, Qact, delta=1e-2 * Qexp)

    def test_repr(self):
        """
        Test that a NonlinearRotor object can be reconstructed from its
        repr() output with no loss of information.
        """
        mode = None
        exec('mode = {0!r}'.format(self.mode))
        self.assertEqual(self.mode.inertia.value.shape,
                         mode.inertia.value.shape)
        for I0, I in zip(self.mode.inertia.value, mode.inertia.value):
            self.assertAlmostEqual(I0, I, 6)
        self.assertEqual(self.mode.inertia.units, mode.inertia.units)
        self.assertEqual(self.mode.symmetry, mode.symmetry)
        self.assertEqual(self.mode.quantum, mode.quantum)

    def test_pickle(self):
        """
        Test that a NonlinearRotor object can be pickled and unpickled with
        no loss of information.
        """
        import cPickle
        mode = cPickle.loads(cPickle.dumps(self.mode, -1))
        self.assertEqual(self.mode.inertia.value.shape,
                         mode.inertia.value.shape)
        for I0, I in zip(self.mode.inertia.value, mode.inertia.value):
            self.assertAlmostEqual(I0, I, 6)
        self.assertEqual(self.mode.inertia.units, mode.inertia.units)
        self.assertEqual(self.mode.symmetry, mode.symmetry)
        self.assertEqual(self.mode.quantum, mode.quantum)
コード例 #7
0
ファイル: networkTest.py プロジェクト: shihchengli/RMG-Py
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.nC4H10O = Species(
            label='n-C4H10O',
            conformer=Conformer(
                E0=(-317.807, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(74.07, "g/mol")),
                    NonlinearRotor(inertia=([41.5091, 215.751,
                                             233.258], "amu*angstrom^2"),
                                   symmetry=1),
                    HarmonicOscillator(frequencies=([
                        240.915, 341.933, 500.066, 728.41, 809.987, 833.93,
                        926.308, 948.571, 1009.3, 1031.46, 1076, 1118.4,
                        1184.66, 1251.36, 1314.36, 1321.42, 1381.17, 1396.5,
                        1400.54, 1448.08, 1480.18, 1485.34, 1492.24, 1494.99,
                        1586.16, 2949.01, 2963.03, 2986.19, 2988.1, 2995.27,
                        3026.03, 3049.05, 3053.47, 3054.83, 3778.88
                    ], "cm^-1")),
                    HinderedRotor(inertia=(0.854054, "amu*angstrom^2"),
                                  symmetry=1,
                                  fourier=([[
                                      0.25183, -1.37378, -2.8379, 0.0305112,
                                      0.0028088
                                  ],
                                            [
                                                0.458307, 0.542121, -0.599366,
                                                -0.00283925, 0.0398529
                                            ]], "kJ/mol")),
                    HinderedRotor(
                        inertia=(8.79408, "amu*angstrom^2"),
                        symmetry=1,
                        fourier=([[
                            0.26871, -0.59533, -8.15002, -0.294325, -0.145357
                        ], [1.1884, 0.99479, -0.940416, -0.186538,
                            0.0309834]], "kJ/mol")),
                    HinderedRotor(inertia=(7.88153, "amu*angstrom^2"),
                                  symmetry=1,
                                  fourier=([[
                                      -4.67373, 2.03735, -6.25993, -0.27325,
                                      -0.048748
                                  ],
                                            [
                                                -0.982845, 1.76637, -1.57619,
                                                0.474364, -0.000681718
                                            ]], "kJ/mol")),
                    HinderedRotor(inertia=(2.81525, "amu*angstrom^2"),
                                  symmetry=3,
                                  barrier=(2.96807, "kcal/mol")),
                ],
                spin_multiplicity=1,
                optical_isomers=1,
            ),
            molecular_weight=(74.07, "g/mol"),
            transport_data=TransportData(sigma=(5.94, 'angstrom'),
                                         epsilon=(559, 'K')),
            energy_transfer_model=SingleExponentialDown(
                alpha0=(447.5 * 0.011962, "kJ/mol"), T0=(300, "K"), n=0.85),
        )

        self.nC4H8 = Species(
            label='n-C4H8',
            conformer=Conformer(
                E0=(-17.8832, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(56.06, "g/mol")),
                    NonlinearRotor(inertia=([22.2748, 122.4,
                                             125.198], "amu*angstrom^2"),
                                   symmetry=1),
                    HarmonicOscillator(frequencies=([
                        308.537, 418.67, 636.246, 788.665, 848.906, 936.762,
                        979.97, 1009.48, 1024.22, 1082.96, 1186.38, 1277.55,
                        1307.65, 1332.87, 1396.67, 1439.09, 1469.71, 1484.45,
                        1493.19, 1691.49, 2972.12, 2994.31, 3018.48, 3056.87,
                        3062.76, 3079.38, 3093.54, 3174.52
                    ], "cm^-1")),
                    HinderedRotor(inertia=(5.28338, "amu*angstrom^2"),
                                  symmetry=1,
                                  fourier=([[
                                      -0.579364, -0.28241, -4.46469, 0.143368,
                                      0.126756
                                  ],
                                            [
                                                1.01804, -0.494628,
                                                -0.00318651, -0.245289,
                                                0.193728
                                            ]], "kJ/mol")),
                    HinderedRotor(
                        inertia=(2.60818, "amu*angstrom^2"),
                        symmetry=3,
                        fourier=([[
                            0.0400372, 0.0301986, -6.4787, -0.0248675,
                            -0.0324753
                        ], [0.0312541, 0.0538, -0.493785, 0.0965968,
                            0.125292]], "kJ/mol")),
                ],
                spin_multiplicity=1,
                optical_isomers=1,
            ),
        )

        self.H2O = Species(
            label='H2O',
            conformer=Conformer(
                E0=(-269.598, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(18.01, "g/mol")),
                    NonlinearRotor(inertia=([0.630578, 1.15529,
                                             1.78586], "amu*angstrom^2"),
                                   symmetry=2),
                    HarmonicOscillator(
                        frequencies=([1622.09, 3771.85, 3867.85], "cm^-1")),
                ],
                spin_multiplicity=1,
                optical_isomers=1,
            ),
        )

        self.N2 = Species(
            label='N2',
            molecular_weight=(28.04, "g/mol"),
            transport_data=TransportData(sigma=(3.41, "angstrom"),
                                         epsilon=(124, "K")),
            energy_transfer_model=None,
        )

        self.TS = TransitionState(
            label='TS',
            conformer=Conformer(
                E0=(-42.4373, "kJ/mol"),
                modes=[
                    IdealGasTranslation(mass=(74.07, "g/mol")),
                    NonlinearRotor(inertia=([40.518, 232.666,
                                             246.092], "u*angstrom**2"),
                                   symmetry=1,
                                   quantum=False),
                    HarmonicOscillator(frequencies=([
                        134.289, 302.326, 351.792, 407.986, 443.419, 583.988,
                        699.001, 766.1, 777.969, 829.671, 949.753, 994.731,
                        1013.59, 1073.98, 1103.79, 1171.89, 1225.91, 1280.67,
                        1335.08, 1373.9, 1392.32, 1417.43, 1469.51, 1481.61,
                        1490.16, 1503.73, 1573.16, 2972.85, 2984.3, 3003.67,
                        3045.78, 3051.77, 3082.37, 3090.44, 3190.73, 3708.52
                    ], "kayser")),
                    HinderedRotor(inertia=(2.68206, "amu*angstrom^2"),
                                  symmetry=3,
                                  barrier=(3.35244, "kcal/mol")),
                    HinderedRotor(inertia=(9.77669, "amu*angstrom^2"),
                                  symmetry=1,
                                  fourier=([[
                                      0.208938, -1.55291, -4.05398, -0.105798,
                                      -0.104752
                                  ],
                                            [
                                                2.00518, -0.020767, -0.333595,
                                                0.137791, -0.274578
                                            ]], "kJ/mol")),
                ],
                spin_multiplicity=1,
                optical_isomers=1,
            ),
            frequency=(-2038.34, 'cm^-1'),
        )

        self.reaction = Reaction(
            label='dehydration',
            reactants=[self.nC4H10O],
            products=[self.nC4H8, self.H2O],
            transition_state=self.TS,
        )

        self.network = Network(
            label='n-butanol',
            isomers=[Configuration(self.nC4H10O)],
            reactants=[],
            products=[Configuration(self.nC4H8, self.H2O)],
            path_reactions=[self.reaction],
            bath_gas={self.N2: 1.0},
        )
コード例 #8
0
ファイル: rotationTest.py プロジェクト: KEHANG/RMG-Py
class TestNonlinearRotor(unittest.TestCase):
    """
    Contains unit tests of the NonlinearRotor class.
    """

    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.inertia = numpy.array([3.415, 16.65, 20.07])
        self.symmetry = 4
        self.quantum = False
        self.mode = NonlinearRotor(
            inertia=(self.inertia, "amu*angstrom^2"), symmetry=self.symmetry, quantum=self.quantum
        )

    def test_getRotationalConstant(self):
        """
        Test getting the NonlinearRotor.rotationalConstant property.
        """
        Bexp = numpy.array([4.93635, 1.0125, 0.839942])
        Bact = self.mode.rotationalConstant.value_si
        for B0, B in zip(Bexp, Bact):
            self.assertAlmostEqual(B0, B, 4)

    def test_setRotationalConstant(self):
        """
        Test setting the NonlinearRotor.rotationalConstant property.
        """
        B = self.mode.rotationalConstant
        B.value_si *= 2
        self.mode.rotationalConstant = B
        Iexp = 0.5 * self.inertia
        Iact = self.mode.inertia.value_si * constants.Na * 1e23
        for I0, I in zip(Iexp, Iact):
            self.assertAlmostEqual(I0, I, 4)

    def test_getPartitionFunction_classical(self):
        """
        Test the NonlinearRotor.getPartitionFunction() method for a classical
        rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Qexplist = numpy.array([651.162, 1401.08, 3962.84, 7280.21, 11208.6])
        for T, Qexp in zip(Tlist, Qexplist):
            Qact = self.mode.getPartitionFunction(T)
            self.assertAlmostEqual(Qexp, Qact, delta=1e-4 * Qexp)

    def test_getHeatCapacity_classical(self):
        """
        Test the NonlinearRotor.getHeatCapacity() method using a classical
        rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Cvexplist = numpy.array([1.5, 1.5, 1.5, 1.5, 1.5]) * constants.R
        for T, Cvexp in zip(Tlist, Cvexplist):
            Cvact = self.mode.getHeatCapacity(T)
            self.assertAlmostEqual(Cvexp, Cvact, delta=1e-4 * Cvexp)

    def test_getEnthalpy_classical(self):
        """
        Test the NonlinearRotor.getEnthalpy() method using a classical rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Hexplist = numpy.array([1.5, 1.5, 1.5, 1.5, 1.5]) * constants.R * Tlist
        for T, Hexp in zip(Tlist, Hexplist):
            Hact = self.mode.getEnthalpy(T)
            self.assertAlmostEqual(Hexp, Hact, delta=1e-4 * Hexp)

    def test_getEntropy_classical(self):
        """
        Test the NonlinearRotor.getEntropy() method using a classical rotor.
        """
        self.mode.quantum = False
        Tlist = numpy.array([300, 500, 1000, 1500, 2000])
        Sexplist = numpy.array([7.97876, 8.74500, 9.78472, 10.3929, 10.8244]) * constants.R
        for T, Sexp in zip(Tlist, Sexplist):
            Sact = self.mode.getEntropy(T)
            self.assertAlmostEqual(Sexp, Sact, delta=1e-4 * Sexp)

    def test_getSumOfStates_classical(self):
        """
        Test the NonlinearRotor.getSumOfStates() method using a classical rotor.
        """
        self.mode.quantum = False
        Elist = numpy.arange(0, 1000 * 11.96, 1 * 11.96)
        sumStates = self.mode.getSumOfStates(Elist)
        densStates = self.mode.getDensityOfStates(Elist)
        for n in range(10, len(Elist)):
            self.assertTrue(
                0.8 < numpy.sum(densStates[0:n]) / sumStates[n] < 1.25,
                "{0} != {1}".format(numpy.sum(densStates[0:n]), sumStates[n]),
            )

    def test_getDensityOfStates_classical(self):
        """
        Test the NonlinearRotor.getDensityOfStates() method using a classical
        rotor.
        """
        self.mode.quantum = False
        Elist = numpy.arange(0, 1000 * 11.96, 1 * 11.96)
        densStates = self.mode.getDensityOfStates(Elist)
        T = 100
        Qact = numpy.sum(densStates * numpy.exp(-Elist / constants.R / T))
        Qexp = self.mode.getPartitionFunction(T)
        self.assertAlmostEqual(Qexp, Qact, delta=1e-2 * Qexp)

    def test_repr(self):
        """
        Test that a NonlinearRotor object can be reconstructed from its
        repr() output with no loss of information.
        """
        mode = None
        exec("mode = {0!r}".format(self.mode))
        self.assertEqual(self.mode.inertia.value.shape, mode.inertia.value.shape)
        for I0, I in zip(self.mode.inertia.value, mode.inertia.value):
            self.assertAlmostEqual(I0, I, 6)
        self.assertEqual(self.mode.inertia.units, mode.inertia.units)
        self.assertEqual(self.mode.symmetry, mode.symmetry)
        self.assertEqual(self.mode.quantum, mode.quantum)

    def test_pickle(self):
        """
        Test that a NonlinearRotor object can be pickled and unpickled with
        no loss of information.
        """
        import cPickle

        mode = cPickle.loads(cPickle.dumps(self.mode, -1))
        self.assertEqual(self.mode.inertia.value.shape, mode.inertia.value.shape)
        for I0, I in zip(self.mode.inertia.value, mode.inertia.value):
            self.assertAlmostEqual(I0, I, 6)
        self.assertEqual(self.mode.inertia.units, mode.inertia.units)
        self.assertEqual(self.mode.symmetry, mode.symmetry)
        self.assertEqual(self.mode.quantum, mode.quantum)
コード例 #9
0
ファイル: inputTest.py プロジェクト: shihchengli/RMG-Py
    def test_reaction(self):
        """
        Test loading a reaction from input file-like kew word arguments
        """

        species(label='methoxy',
                structure=SMILES('C[O]'),
                E0=(9.44, 'kcal/mol'),
                modes=[
                    HarmonicOscillator(frequencies=(
                        [758, 960, 1106, 1393, 1403, 1518, 2940, 3019, 3065],
                        'cm^-1')),
                    NonlinearRotor(rotationalConstant=([0.916, 0.921,
                                                        5.251], "cm^-1"),
                                   symmetry=3,
                                   quantum=False),
                    IdealGasTranslation(mass=(31.01843, "g/mol"))
                ],
                spinMultiplicity=2,
                opticalIsomers=1,
                molecularWeight=(31.01843, 'amu'),
                collisionModel=TransportData(sigma=(3.69e-10, 'm'),
                                             epsilon=(4.0, 'kJ/mol')),
                energyTransferModel=SingleExponentialDown(alpha0=(0.956,
                                                                  'kJ/mol'),
                                                          T0=(300, 'K'),
                                                          n=0.95))

        species(label='formaldehyde',
                E0=(28.69, 'kcal/mol'),
                molecularWeight=(30.0106, "g/mol"),
                collisionModel=TransportData(sigma=(3.69e-10, 'm'),
                                             epsilon=(4.0, 'kJ/mol')),
                energyTransferModel=SingleExponentialDown(alpha0=(0.956,
                                                                  'kJ/mol'),
                                                          T0=(300, 'K'),
                                                          n=0.95),
                spinMultiplicity=1,
                opticalIsomers=1,
                modes=[
                    HarmonicOscillator(
                        frequencies=([1180, 1261, 1529, 1764, 2931, 2999],
                                     'cm^-1')),
                    NonlinearRotor(rotationalConstant=([
                        1.15498821005263, 1.3156969584727, 9.45570474524524
                    ], "cm^-1"),
                                   symmetry=2,
                                   quantum=False),
                    IdealGasTranslation(mass=(30.0106, "g/mol"))
                ])

        species(label='H',
                E0=(0.000, 'kcal/mol'),
                molecularWeight=(1.00783, "g/mol"),
                collisionModel=TransportData(sigma=(3.69e-10, 'm'),
                                             epsilon=(4.0, 'kJ/mol')),
                energyTransferModel=SingleExponentialDown(alpha0=(0.956,
                                                                  'kJ/mol'),
                                                          T0=(300, 'K'),
                                                          n=0.95),
                modes=[IdealGasTranslation(mass=(1.00783, "g/mol"))],
                spinMultiplicity=2,
                opticalIsomers=1)

        transitionState(
            label='TS3',
            E0=(34.1, 'kcal/mol'),
            spinMultiplicity=2,
            opticalIsomers=1,
            frequency=(-967, 'cm^-1'),
            modes=[
                HarmonicOscillator(frequencies=(
                    [466, 581, 1169, 1242, 1499, 1659, 2933, 3000], 'cm^-1')),
                NonlinearRotor(rotationalConstant=([0.970, 1.029,
                                                    3.717], "cm^-1"),
                               symmetry=1,
                               quantum=False),
                IdealGasTranslation(mass=(31.01843, "g/mol"))
            ])

        reactants = ['formaldehyde', 'H']
        products = ['methoxy']
        tunneling = 'Eckart'

        rxn = reaction('CH2O+H=Methoxy',
                       reactants,
                       products,
                       'TS3',
                       tunneling=tunneling)
        self.assertEqual(rxn.label, 'CH2O+H=Methoxy')
        self.assertEqual(len(rxn.reactants), 2)
        self.assertEqual(len(rxn.products), 1)
        self.assertAlmostEqual(rxn.reactants[0].conformer.E0.value_si, 0)
        self.assertAlmostEqual(rxn.reactants[1].conformer.E0.value_si,
                               120038.96)
        self.assertAlmostEqual(rxn.products[0].conformer.E0.value_si, 39496.96)
        self.assertAlmostEqual(rxn.transition_state.conformer.E0.value_si,
                               142674.4)
        self.assertAlmostEqual(rxn.transition_state.frequency.value_si, -967.0)
        self.assertIsInstance(rxn.transition_state.tunneling, Eckart)
コード例 #10
0
class TestNonlinearRotor(unittest.TestCase):
    """
    Contains unit tests of the NonlinearRotor class.
    """
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.inertia = np.array([3.415, 16.65, 20.07])
        self.symmetry = 4
        self.quantum = False
        self.mode = NonlinearRotor(
            inertia=(self.inertia, "amu*angstrom^2"),
            symmetry=self.symmetry,
            quantum=self.quantum,
        )

    def test_get_rotational_constant(self):
        """
        Test getting the NonlinearRotor.rotationalConstant property.
        """
        b_exp = np.array([4.93635, 1.0125, 0.839942])
        b_act = self.mode.rotationalConstant.value_si
        for rotational_constant0, rotational_constant in zip(b_exp, b_act):
            self.assertAlmostEqual(rotational_constant0, rotational_constant,
                                   4)

    def test_set_rotational_constant(self):
        """
        Test setting the NonlinearRotor.rotationalConstant property.
        """
        rotational_constant = self.mode.rotationalConstant
        rotational_constant.value_si *= 2
        self.mode.rotationalConstant = rotational_constant
        i_exp = 0.5 * self.inertia
        i_act = self.mode.inertia.value_si * constants.Na * 1e23
        for inertia0, inertia in zip(i_exp, i_act):
            self.assertAlmostEqual(inertia0, inertia, 4)

    def test_get_partition_function_classical(self):
        """
        Test the NonlinearRotor.get_partition_function() method for a classical
        rotor.
        """
        self.mode.quantum = False
        t_list = np.array([300, 500, 1000, 1500, 2000])
        q_exp_list = np.array([651.162, 1401.08, 3962.84, 7280.21, 11208.6])
        for temperature, q_exp in zip(t_list, q_exp_list):
            q_act = self.mode.get_partition_function(temperature)
            self.assertAlmostEqual(q_exp, q_act, delta=1e-4 * q_exp)

    def test_get_heat_capacity_classical(self):
        """
        Test the NonlinearRotor.get_heat_capacity() method using a classical
        rotor.
        """
        self.mode.quantum = False
        t_list = np.array([300, 500, 1000, 1500, 2000])
        cv_exp_list = np.array([1.5, 1.5, 1.5, 1.5, 1.5]) * constants.R
        for temperature, cv_exp in zip(t_list, cv_exp_list):
            cv_act = self.mode.get_heat_capacity(temperature)
            self.assertAlmostEqual(cv_exp, cv_act, delta=1e-4 * cv_exp)

    def test_get_enthalpy_classical(self):
        """
        Test the NonlinearRotor.get_enthalpy() method using a classical rotor.
        """
        self.mode.quantum = False
        t_list = np.array([300, 500, 1000, 1500, 2000])
        h_exp_list = np.array([1.5, 1.5, 1.5, 1.5, 1.5]) * constants.R * t_list
        for temperature, h_exp in zip(t_list, h_exp_list):
            h_act = self.mode.get_enthalpy(temperature)
            self.assertAlmostEqual(h_exp, h_act, delta=1e-4 * h_exp)

    def test_get_entropy_classical(self):
        """
        Test the NonlinearRotor.get_entropy() method using a classical rotor.
        """
        self.mode.quantum = False
        t_list = np.array([300, 500, 1000, 1500, 2000])
        s_exp_list = np.array([7.97876, 8.74500, 9.78472, 10.3929, 10.8244
                               ]) * constants.R
        for temperature, s_exp in zip(t_list, s_exp_list):
            s_act = self.mode.get_entropy(temperature)
            self.assertAlmostEqual(s_exp, s_act, delta=1e-4 * s_exp)

    def test_get_sum_of_states_classical(self):
        """
        Test the NonlinearRotor.get_sum_of_states() method using a classical rotor.
        """
        self.mode.quantum = False
        e_list = np.arange(0, 1000 * 11.96, 1 * 11.96)
        sum_states = self.mode.get_sum_of_states(e_list)
        dens_states = self.mode.get_density_of_states(e_list)
        for n in range(10, len(e_list)):
            self.assertTrue(
                0.8 < np.sum(dens_states[0:n]) / sum_states[n] < 1.25,
                '{0} != {1}'.format(np.sum(dens_states[0:n]), sum_states[n]))

    def test_get_sensity_of_states_classical(self):
        """
        Test the NonlinearRotor.get_density_of_states() method using a classical
        rotor.
        """
        self.mode.quantum = False
        e_list = np.arange(0, 1000 * 11.96, 1 * 11.96)
        dens_states = self.mode.get_density_of_states(e_list)
        temperature = 100
        q_act = np.sum(dens_states *
                       np.exp(-e_list / constants.R / temperature))
        q_exp = self.mode.get_partition_function(temperature)
        self.assertAlmostEqual(q_exp, q_act, delta=1e-2 * q_exp)

    def test_repr(self):
        """
        Test that a NonlinearRotor object can be reconstructed from its
        repr() output with no loss of information.
        """
        namespace = {}
        exec('mode = {0!r}'.format(self.mode), globals(), namespace)
        self.assertIn('mode', namespace)
        mode = namespace['mode']
        self.assertEqual(self.mode.inertia.value.shape,
                         mode.inertia.value.shape)
        for inertia_0, inertia in zip(self.mode.inertia.value,
                                      mode.inertia.value):
            self.assertAlmostEqual(inertia_0, inertia, 6)
        self.assertEqual(self.mode.inertia.units, mode.inertia.units)
        self.assertEqual(self.mode.symmetry, mode.symmetry)
        self.assertEqual(self.mode.quantum, mode.quantum)

    def test_pickle(self):
        """
        Test that a NonlinearRotor object can be pickled and unpickled with
        no loss of information.
        """
        import pickle
        mode = pickle.loads(pickle.dumps(self.mode, -1))
        self.assertEqual(self.mode.inertia.value.shape,
                         mode.inertia.value.shape)
        for inertia_0, inertia in zip(self.mode.inertia.value,
                                      mode.inertia.value):
            self.assertAlmostEqual(inertia_0, inertia, 6)
        self.assertEqual(self.mode.inertia.units, mode.inertia.units)
        self.assertEqual(self.mode.symmetry, mode.symmetry)
        self.assertEqual(self.mode.quantum, mode.quantum)
コード例 #11
0
ファイル: reactionTest.py プロジェクト: thackray/RMG-Py
    def setUp(self):
        """
        A method that is called prior to each unit test in this class.
        """
        ethylene = Species(
            label='C2H4',
            conformer=Conformer(
                E0=(44.7127, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(28.0313, 'amu'), ),
                    NonlinearRotor(
                        inertia=(
                            [3.41526, 16.6498, 20.065],
                            'amu*angstrom^2',
                        ),
                        symmetry=4,
                    ),
                    HarmonicOscillator(frequencies=(
                        [
                            828.397, 970.652, 977.223, 1052.93, 1233.55,
                            1367.56, 1465.09, 1672.25, 3098.46, 3111.7,
                            3165.79, 3193.54
                        ],
                        'cm^-1',
                    ), ),
                ],
                spinMultiplicity=1,
                opticalIsomers=1,
            ),
        )

        hydrogen = Species(
            label='H',
            conformer=Conformer(
                E0=(211.794, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(1.00783, 'amu'), ),
                ],
                spinMultiplicity=2,
                opticalIsomers=1,
            ),
        )

        ethyl = Species(
            label='C2H5',
            conformer=Conformer(
                E0=(111.603, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(29.0391, 'amu'), ),
                    NonlinearRotor(
                        inertia=(
                            [4.8709, 22.2353, 23.9925],
                            'amu*angstrom^2',
                        ),
                        symmetry=1,
                    ),
                    HarmonicOscillator(frequencies=(
                        [
                            482.224, 791.876, 974.355, 1051.48, 1183.21,
                            1361.36, 1448.65, 1455.07, 1465.48, 2688.22,
                            2954.51, 3033.39, 3101.54, 3204.73
                        ],
                        'cm^-1',
                    ), ),
                    HinderedRotor(
                        inertia=(1.11481, 'amu*angstrom^2'),
                        symmetry=6,
                        barrier=(0.244029, 'kJ/mol'),
                        semiclassical=None,
                    ),
                ],
                spinMultiplicity=2,
                opticalIsomers=1,
            ),
        )

        TS = TransitionState(
            label='TS',
            conformer=Conformer(
                E0=(266.694, 'kJ/mol'),
                modes=[
                    IdealGasTranslation(mass=(29.0391, 'amu'), ),
                    NonlinearRotor(
                        inertia=(
                            [6.78512, 22.1437, 22.2114],
                            'amu*angstrom^2',
                        ),
                        symmetry=1,
                    ),
                    HarmonicOscillator(frequencies=(
                        [
                            412.75, 415.206, 821.495, 924.44, 982.714, 1024.16,
                            1224.21, 1326.36, 1455.06, 1600.35, 3101.46,
                            3110.55, 3175.34, 3201.88
                        ],
                        'cm^-1',
                    ), ),
                ],
                spinMultiplicity=2,
                opticalIsomers=1,
            ),
            frequency=(-750.232, 'cm^-1'),
        )

        self.reaction = Reaction(
            reactants=[hydrogen, ethylene],
            products=[ethyl],
            kinetics=Arrhenius(
                A=(501366000.0, 'cm^3/(mol*s)'),
                n=1.637,
                Ea=(4.32508, 'kJ/mol'),
                T0=(1, 'K'),
                Tmin=(300, 'K'),
                Tmax=(2500, 'K'),
            ),
            transitionState=TS,
        )

        # CC(=O)O[O]
        acetylperoxy = Species(
            label='acetylperoxy',
            thermo=Wilhoit(Cp0=(4.0 * constants.R, "J/(mol*K)"),
                           CpInf=(21.0 * constants.R, "J/(mol*K)"),
                           a0=-3.95,
                           a1=9.26,
                           a2=-15.6,
                           a3=8.55,
                           B=(500.0, "K"),
                           H0=(-6.151e+04, "J/mol"),
                           S0=(-790.2, "J/(mol*K)")),
        )

        # C[C]=O
        acetyl = Species(
            label='acetyl',
            thermo=Wilhoit(Cp0=(4.0 * constants.R, "J/(mol*K)"),
                           CpInf=(15.5 * constants.R, "J/(mol*K)"),
                           a0=0.2541,
                           a1=-0.4712,
                           a2=-4.434,
                           a3=2.25,
                           B=(500.0, "K"),
                           H0=(-1.439e+05, "J/mol"),
                           S0=(-524.6, "J/(mol*K)")),
        )

        # [O][O]
        oxygen = Species(
            label='oxygen',
            thermo=Wilhoit(Cp0=(3.5 * constants.R, "J/(mol*K)"),
                           CpInf=(4.5 * constants.R, "J/(mol*K)"),
                           a0=-0.9324,
                           a1=26.18,
                           a2=-70.47,
                           a3=44.12,
                           B=(500.0, "K"),
                           H0=(1.453e+04, "J/mol"),
                           S0=(-12.19, "J/(mol*K)")),
        )

        self.reaction2 = Reaction(
            reactants=[acetyl, oxygen],
            products=[acetylperoxy],
            kinetics=Arrhenius(
                A=(2.65e12, 'cm^3/(mol*s)'),
                n=0.0,
                Ea=(0.0, 'kJ/mol'),
                T0=(1, 'K'),
                Tmin=(300, 'K'),
                Tmax=(2000, 'K'),
            ),
        )