forked from ReactionMechanismGenerator/RMG-Py
-
Notifications
You must be signed in to change notification settings - Fork 3
/
speciesTest.py
111 lines (100 loc) · 5.5 KB
/
speciesTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module contains unit tests of the rmgpy.species module.
"""
import unittest
from rmgpy.species import Species, LennardJones
from rmgpy.molecule import Molecule
from rmgpy.thermo import ThermoData
from rmgpy.statmech import Conformer, IdealGasTranslation, NonlinearRotor, HarmonicOscillator
import rmgpy.constants as constants
################################################################################
class TestSpecies(unittest.TestCase):
"""
Contains unit tests for the Species class.
"""
def setUp(self):
"""
A method that is run before each unit test in this class.
"""
self.species = Species(
index=1,
label='C2H4',
thermo=ThermoData(
Tdata=([300.0,400.0,500.0,600.0,800.0,1000.0,1500.0],'K'),
Cpdata=([3.0,4.0,5.0,6.0,8.0,10.0,15.0],'cal/(mol*K)'),
H298=(-20.0,'kcal/mol'),
S298=(50.0,'cal/(mol*K)'),
Tmin=(300.0,'K'),
Tmax=(2000.0,'K'),
),
conformer=Conformer(
E0=(0.0,'kJ/mol'),
modes=[
IdealGasTranslation(mass=(28.03,'amu')),
NonlinearRotor(inertia=([5.6952e-47, 2.7758e-46, 3.3454e-46],'kg*m^2'), symmetry=1),
HarmonicOscillator(frequencies=([834.50, 973.31, 975.37, 1067.1, 1238.5, 1379.5, 1472.3, 1691.3, 3121.6, 3136.7, 3192.5, 3221.0],'cm^-1')),
],
spinMultiplicity=1,
opticalIsomers=1,
),
molecule=[Molecule().fromSMILES('C=C')],
lennardJones=LennardJones(sigma=(1,'angstrom'), epsilon=(100,'K')),
molecularWeight=(28.03,'amu'),
reactive=True,
)
def testPickle(self):
"""
Test that a Species object can be successfully pickled and
unpickled with no loss of information.
"""
import cPickle
species = cPickle.loads(cPickle.dumps(self.species))
self.assertEqual(self.species.index, species.index)
self.assertEqual(self.species.label, species.label)
self.assertEqual(self.species.thermo.H298.value_si, species.thermo.H298.value_si)
self.assertEqual(self.species.thermo.H298.units, species.thermo.H298.units)
self.assertEqual(len(self.species.conformer.modes), len(species.conformer.modes))
self.assertEqual(len(self.species.molecule), len(species.molecule))
self.assertTrue(self.species.molecule[0].isIsomorphic(species.molecule[0]))
self.assertEqual(self.species.conformer.E0.value_si, species.conformer.E0.value_si)
self.assertEqual(self.species.conformer.E0.units, species.conformer.E0.units)
self.assertEqual(self.species.lennardJones.sigma.value_si, species.lennardJones.sigma.value_si)
self.assertEqual(self.species.lennardJones.sigma.units, species.lennardJones.sigma.units)
self.assertAlmostEqual(self.species.lennardJones.epsilon.value_si / 1.381e-23, species.lennardJones.epsilon.value_si / 1.381e-23, 4)
self.assertEqual(self.species.lennardJones.epsilon.units, species.lennardJones.epsilon.units)
self.assertEqual(self.species.molecularWeight.value_si, species.molecularWeight.value_si)
self.assertEqual(self.species.molecularWeight.units, species.molecularWeight.units)
self.assertEqual(self.species.reactive, species.reactive)
def testOutput(self):
"""
Test that a Species object can be successfully reconstructed
from its repr() output with no loss of information.
"""
exec('species = {0!r}'.format(self.species))
self.assertEqual(self.species.index, species.index)
self.assertEqual(self.species.label, species.label)
self.assertEqual(self.species.thermo.H298.value_si, species.thermo.H298.value_si)
self.assertEqual(self.species.thermo.H298.units, species.thermo.H298.units)
self.assertEqual(len(self.species.conformer.modes), len(species.conformer.modes))
self.assertEqual(len(self.species.molecule), len(species.molecule))
self.assertTrue(self.species.molecule[0].isIsomorphic(species.molecule[0]))
self.assertEqual(self.species.conformer.E0.value_si, species.conformer.E0.value_si)
self.assertEqual(self.species.conformer.E0.units, species.conformer.E0.units)
self.assertEqual(self.species.lennardJones.sigma.value_si, species.lennardJones.sigma.value_si)
self.assertEqual(self.species.lennardJones.sigma.units, species.lennardJones.sigma.units)
self.assertAlmostEqual(self.species.lennardJones.epsilon.value_si, species.lennardJones.epsilon.value_si, 3)
self.assertEqual(self.species.lennardJones.epsilon.units, species.lennardJones.epsilon.units)
self.assertEqual(self.species.molecularWeight.value_si, species.molecularWeight.value_si)
self.assertEqual(self.species.molecularWeight.units, species.molecularWeight.units)
self.assertEqual(self.species.reactive, species.reactive)
def testToAdjacencyList(self):
"""
Test that toAdjacencyList() works as expected.
"""
string = self.species.toAdjacencyList()
self.assertTrue(string.startswith(self.species.molecule[0].toAdjacencyList(label=self.species.label,removeH=True)))
################################################################################
if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))