Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved coding style in Arkane #1596

Merged
merged 28 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
37534fc
Style: Simplified boolean expressions
alongd May 9, 2019
d912cd2
Style: Simplified chained comparisons in Arkane kinetics.py
alongd May 9, 2019
0c4ef2d
Style: Define instance attributes inside __init__ in Arkane explorer.py
alongd May 9, 2019
f71b473
Style: Changed first parameter in test setUp/tearDown to `cls`
alongd May 9, 2019
6640fc8
Added __init__ call of super class for ArkaneSpecies
alongd May 9, 2019
9b225c3
Added various missing docstrings in Arkane
alongd May 9, 2019
7e88460
PEP 8 coding style fixes in Arkane common.py
alongd May 9, 2019
602d185
PEP 8 coding style fixes in Arkane commonTest.py
alongd May 9, 2019
553d204
PEP 8 coding style fixes in Arkane explorer.py
alongd May 9, 2019
a81eb93
PEP 8 coding style fixes in Arkane explorerTest.py
alongd May 9, 2019
4519edd
PEP 8 coding style fixes in Arkane gaussian.py
alongd May 9, 2019
c27ee75
PEP 8 coding style fixes in Arkane gaussianTest.py
alongd May 9, 2019
6e08c91
PEP 8 coding style fixes in Arkane input.py
alongd May 9, 2019
e2303b5
PEP 8 coding style fixes in Arkane kinetics.py
alongd May 9, 2019
01e944f
PEP 8 coding style fixes in Arkane log.py
alongd May 9, 2019
66e42ef
PEP 8 coding style fixes in Arkane main.py
alongd May 9, 2019
a2fb559
PEP 8 coding style fixes in Arkane output.py
alongd May 9, 2019
064ce44
PEP 8 coding style fixes in Arkane pdep.py
alongd May 9, 2019
11a7156
PEP 8 coding style fixes in Arkane pdepTest.py
alongd May 9, 2019
9a87780
PEP 8 coding style fixes in Arkane qchem.py
alongd May 9, 2019
afb051b
PEP 8 coding style fixes in Arkane qchemTest.py
alongd May 9, 2019
8eaf944
PEP 8 coding style fixes in Arkane sensitivity.py
alongd May 9, 2019
c415475
PEP 8 coding style fixes in Arkane statmech.py
alongd May 9, 2019
e0a88dd
PEP 8 coding style fixes in Arkane thermo.py
alongd May 9, 2019
ec04139
Style: Removed redundant paranthesis in Arkane statmech.py
alongd May 9, 2019
41e1913
Minor: Renamed 'string' as 'rxn_str'
alongd May 9, 2019
7a34b5a
Changed warning in Arkane common.py to the string.format method
alongd May 10, 2019
0982f57
Arkane common test: Removed `msg=None`
alongd May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arkane/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
initialize imports
"""

###############################################################################
# #
# RMG - Reaction Mechanism Generator #
Expand Down
303 changes: 192 additions & 111 deletions arkane/common.py

Large diffs are not rendered by default.

114 changes: 61 additions & 53 deletions arkane/commonTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,23 @@
from arkane.statmech import InputError, StatMechJob
from arkane.input import jobList


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


class CommonTest(unittest.TestCase):
"""
Contains unit tests of Arkane's common functions.
"""

def test_check_conformer_energy(self):
"""
test the check_conformer_energy function with an list of energies.
"""
v_list = [-272.2779012225, -272.2774933703, -272.2768397635, -272.2778432059, -272.278645477, -272.2789602654,
-272.2788749196, -272.278496709, -272.2779350675, -272.2777008843, -272.2777167286, -272.2780937643,
-272.2784838846, -272.2788050464, -272.2787865352, -272.2785091607, -272.2779977452, -272.2777957743,
-272.2779134906, -272.2781827547, -272.278443339, -272.2788244214, -272.2787748749]
-272.2788749196, -272.278496709, -272.2779350675, -272.2777008843, -272.2777167286, -272.2780937643,
-272.2784838846, -272.2788050464, -272.2787865352, -272.2785091607, -272.2779977452, -272.2777957743,
-272.2779134906, -272.2781827547, -272.278443339, -272.2788244214, -272.2787748749]
v_list = numpy.array(v_list, numpy.float64)
v_diff = (v_list[0] - numpy.min(v_list)) * constants.E_h * constants.Na / 1000
self.assertAlmostEqual(v_diff / 2.7805169838282797, 1, 5)
Expand All @@ -73,160 +75,163 @@ class TestArkaneJob(unittest.TestCase):
"""
Contains unit tests of the Arkane module and its interactions with other RMG modules.
"""

@classmethod
def setUp(self):
def setUp(cls):
"""A method that is run before each unit test in this class"""
arkane = Arkane()
jobList = arkane.loadInputFile(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'data', 'methoxy.py'))
'data', 'methoxy.py'))
pdepjob = jobList[-1]
self.kineticsjob = jobList[0]
cls.kineticsjob = jobList[0]
pdepjob.activeJRotor = True
network = pdepjob.network
self.Nisom = len(network.isomers)
self.Nreac = len(network.reactants)
self.Nprod = len(network.products)
self.Npath = len(network.pathReactions)
self.PathReaction2 = network.pathReactions[2]
self.TminValue = pdepjob.Tmin.value
self.Tmaxvalue = pdepjob.Tmax.value
self.TmaxUnits = pdepjob.Tmax.units
self.TlistValue = pdepjob.Tlist.value
self.PminValue = pdepjob.Pmin.value
self.Pcount = pdepjob.Pcount
self.Tcount = pdepjob.Tcount
self.GenTlist = pdepjob.generateTemperatureList()
self.PlistValue = pdepjob.Plist.value
self.maximumGrainSizeValue = pdepjob.maximumGrainSize.value
self.method = pdepjob.method
self.rmgmode = pdepjob.rmgmode
cls.Nisom = len(network.isomers)
cls.Nreac = len(network.reactants)
cls.Nprod = len(network.products)
cls.Npath = len(network.pathReactions)
cls.PathReaction2 = network.pathReactions[2]
cls.TminValue = pdepjob.Tmin.value
cls.Tmaxvalue = pdepjob.Tmax.value
cls.TmaxUnits = pdepjob.Tmax.units
cls.TlistValue = pdepjob.Tlist.value
cls.PminValue = pdepjob.Pmin.value
cls.Pcount = pdepjob.Pcount
cls.Tcount = pdepjob.Tcount
cls.GenTlist = pdepjob.generateTemperatureList()
cls.PlistValue = pdepjob.Plist.value
cls.maximumGrainSizeValue = pdepjob.maximumGrainSize.value
cls.method = pdepjob.method
cls.rmgmode = pdepjob.rmgmode

# test Arkane's interactions with the network module
def testNisom(self):
"""
Test the number of isomers identified.
"""
self.assertEqual(self.Nisom, 2, msg=None)
self.assertEqual(self.Nisom, 2)

def testNreac(self):
"""
Test the number of reactants identified.
"""
self.assertEqual(self.Nreac, 1, msg=None)
self.assertEqual(self.Nreac, 1)

def testNprod(self):
"""
Test the number of products identified.
"""
self.assertEqual(self.Nprod, 1, msg=None)
self.assertEqual(self.Nprod, 1)

def testNpathReactions(self):
"""
Test the whether or not RMG mode is turned on.
"""
self.assertEqual(self.Npath, 3, msg=None)
self.assertEqual(self.Npath, 3)

def testPathReactions(self):
"""
Test a path reaction label
"""
self.assertEqual(str(self.PathReaction2), 'CH2OH <=> methoxy', msg=None)
self.assertEqual(str(self.PathReaction2), 'CH2OH <=> methoxy')

# test Arkane's interactions with the pdep module
def testTemperaturesUnits(self):
"""
Test the Temperature Units.
"""
self.assertEqual(str(self.TmaxUnits), 'K', msg=None)
self.assertEqual(str(self.TmaxUnits), 'K')

def testTemperaturesValue(self):
"""
Test the temperature value.
"""
self.assertEqual(self.TminValue, 450.0, msg=None)
self.assertEqual(self.TminValue, 450.0)

def testTemperaturesList(self):
"""
Test the temperature list.
"""
self.assertEqual(numpy.array_equal(self.TlistValue, numpy.array([450, 500, 678, 700])), True, msg=None)
self.assertTrue(numpy.array_equal(self.TlistValue, numpy.array([450, 500, 678, 700])))

def testPminValue(self):
"""
Test the minimum pressure value.
"""
self.assertEqual("%0.7f" % self.PminValue, str(0.0101325), msg=None)
self.assertEqual("%0.7f" % self.PminValue, str(0.0101325))

def testPcount(self):
"""
Test the number pressures specified.
"""
self.assertEqual(self.Pcount, 7, msg=None)
self.assertEqual(self.Pcount, 7)

def testTcount(self):
"""
Test the number temperatures specified.
"""
self.assertEqual(self.Tcount, 4, msg=None)
self.assertEqual(self.Tcount, 4)

def testPressureList(self):
"""
Test the pressure list.
"""
self.assertEqual(numpy.array_equal(self.PlistValue, numpy.array([0.01, 0.1, 1, 3, 10, 100, 1000])), True, msg=None)
self.assertTrue(numpy.array_equal(self.PlistValue, numpy.array([0.01, 0.1, 1, 3, 10, 100, 1000])))

def testGenerateTemperatureList(self):
"""
Test the generated temperature list.
"""
self.assertEqual(list(self.GenTlist), [450.0, 500.0, 678.0, 700.0], msg=None)
self.assertEqual(list(self.GenTlist), [450.0, 500.0, 678.0, 700.0])

def testmaximumGrainSizeValue(self):
"""
Test the max grain size value.
"""
self.assertEqual(self.maximumGrainSizeValue, 0.5, msg=None)
self.assertEqual(self.maximumGrainSizeValue, 0.5)

def testMethod(self):
"""
Test the master equation solution method chosen.
"""
self.assertEqual(self.method, 'modified strong collision', msg=None)
self.assertEqual(self.method, 'modified strong collision')

def testRmgmode(self):
"""
Test the whether or not RMG mode is turned on.
"""
self.assertEqual(self.rmgmode, False, msg=None)
self.assertEqual(self.rmgmode, False)

# Test Arkane's interactions with the kinetics module
def testCalculateTSTRateCoefficient(self):
"""
Test the calculation of the high-pressure limit rate coef for one of the kinetics jobs at Tmin and Tmax.
"""
self.assertEqual("%0.7f" % self.kineticsjob.reaction.calculateTSTRateCoefficient(self.TminValue),
str(46608.5904933), msg=None)
str(46608.5904933))
self.assertEqual("%0.5f" % self.kineticsjob.reaction.calculateTSTRateCoefficient(self.Tmaxvalue),
str(498796.64535), msg=None)
str(498796.64535))

def testTunneling(self):
"""
Test the whether or not tunneling has been included in a specific kinetics job.
"""
self.assertEqual(self.kineticsjob.reaction.transitionState.tunneling, None, msg=None)
self.assertEqual(self.kineticsjob.reaction.transitionState.tunneling, None)


class TestArkaneInput(unittest.TestCase):
"""
Contains unit tests for loading and processing Arkane input files.
"""

@classmethod
def setUp(self):
def setUp(cls):
"""Preparation for all unit tests in this class."""
self.directory = os.path.join(os.path.dirname(os.path.dirname(rmgpy.__file__)), 'examples', 'arkane')
self.modelChemistry = "cbs-qb3"
self.frequencyScaleFactor = 0.99
self.useHinderedRotors = False
self.useBondCorrections = True
cls.directory = os.path.join(os.path.dirname(os.path.dirname(rmgpy.__file__)), 'examples', 'arkane')
cls.modelChemistry = "cbs-qb3"
cls.frequencyScaleFactor = 0.99
cls.useHinderedRotors = False
cls.useBondCorrections = True

def testSpecies(self):
"""Test loading of species input file."""
Expand Down Expand Up @@ -262,7 +267,7 @@ def testTransitionState(self):
"""Test loading of transition state input file."""
ts = input.transitionState('TS', os.path.join(self.directory, 'reactions', 'H+C2H4=C2H5', 'TS.py'))
self.assertTrue(isinstance(ts, TransitionState))

def testTransitionStateStatmech(self):
"""Test loading of statmech job from transition state input file."""
job = jobList[-1]
Expand All @@ -278,11 +283,13 @@ class TestStatmech(unittest.TestCase):
"""
Contains unit tests of statmech.py
"""

@classmethod
def setUp(self):
def setUp(cls):
"""A method that is run before each unit test in this class"""
arkane = Arkane()
self.job_list = arkane.loadInputFile(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'data', 'Benzyl', 'input.py'))
cls.job_list = arkane.loadInputFile(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'data', 'Benzyl', 'input.py'))

def test_gaussian_log_file_error(self):
"""Test that the proper error is raised if gaussian geometry and frequency file paths are the same"""
Expand Down Expand Up @@ -364,7 +371,7 @@ def tearDownClass(cls):
item_path = os.path.join(path, name)
if os.path.isfile(item_path):
extension = name.split('.')[-1]
if name in cls.files_to_delete or\
if name in cls.files_to_delete or \
(extension in cls.extensions_to_delete and name not in cls.files_to_keep):
os.remove(item_path)
else:
Expand All @@ -376,6 +383,7 @@ class TestGetMass(unittest.TestCase):
"""
Contains unit tests of common.py
"""

def test_get_mass(self):
"""Test that the correct mass/number/isotop is returned from get_element_mass"""
self.assertEquals(get_element_mass(1), (1.00782503224, 1)) # test input by integer
Expand Down
Loading