Skip to content

Commit

Permalink
Merge pull request #1685 from ReactionMechanismGenerator/arkane_absolute
Browse files Browse the repository at this point in the history
Allow relative paths in Arkane statmech
  • Loading branch information
goldmanm authored Sep 26, 2019
2 parents 77cdd46 + 5f32f40 commit 581ca34
Show file tree
Hide file tree
Showing 15 changed files with 24,802 additions and 12 deletions.
2 changes: 2 additions & 0 deletions arkane/commonTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,7 @@ def test_get_mass(self):
self.assertEquals(get_element_mass('Bk'), (247.0703073, 97)) # test a two-element array (no isotope data)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
1,330 changes: 1,330 additions & 0 deletions arkane/data/H2O2/freq_a19031.out

Large diffs are not rendered by default.

22,906 changes: 22,906 additions & 0 deletions arkane/data/H2O2/scan_a19034.out

Large diffs are not rendered by default.

470 changes: 470 additions & 0 deletions arkane/data/H2O2/sp_a19032.out

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions arkane/explorerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,7 @@ def test_job_rxns(self):
self.assertIn(rxn, self.explorer_job.networks[0].path_reactions)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
2 changes: 2 additions & 0 deletions arkane/gaussianTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ def test_determine_qm_software(self):
self.assertIsInstance(log, GaussianLog)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
1 change: 0 additions & 1 deletion arkane/inputTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,5 @@ def test_process_model_chemistry(self):

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


if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
2 changes: 2 additions & 0 deletions arkane/kineticsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,7 @@ def test_get_tlist_for_kineticsjob(self):
inverse_tlist[-1] - inverse_tlist[-2]))


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
2 changes: 2 additions & 0 deletions arkane/mainTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ def tearDownClass(cls):
shutil.rmtree(item_path)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
2 changes: 2 additions & 0 deletions arkane/molproTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,7 @@ def test_get_t1_diagnostic(self):
self.assertAlmostEqual(t1_diagnostic, 0.01152184)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
6 changes: 6 additions & 0 deletions arkane/pdepTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ def tearDown(cls):
for f in files:
if 'pdep_sa' not in f:
os.remove(os.path.join(settings['test_data.directory'], 'arkane', 'tst1', f))


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
2 changes: 2 additions & 0 deletions arkane/qchemTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ def test_load_co_modes_from_qchem_log(self):
self.assertTrue(len([mode for mode in conformer.modes if isinstance(mode, HinderedRotor)]) == 0)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
42 changes: 32 additions & 10 deletions arkane/statmech.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,19 @@ def load(self, pdep=False, plot=False):
except KeyError:
raise InputError('Model chemistry {0!r} not found in from dictionary of energy values in species file '
'{1!r}.'.format(self.modelChemistry, path))
if not os.path.isfile(energy.path):
modified_energy_path = os.path.join(directory, energy.path)
if not os.path.isfile(modified_energy_path):
raise InputError('Could not find single point energy file for species {0} '
'in the specified path {1}'.format(self.species.label, energy.path))
else:
energy.path = modified_energy_path
e0, e_electronic = None, None # E0 = e_electronic + ZPE
energy_log = None
if isinstance(energy, Log) and type(energy).__name__ == 'Log':
energy_log = determine_qm_software(os.path.join(directory, energy.path))
energy_log = determine_qm_software(energy.path)
elif isinstance(energy, Log) and type(energy).__name__ != 'Log':
energy_log = energy
energy_log.path = os.path.join(directory, energy_log.path)
elif isinstance(energy, float):
e_electronic = energy
elif isinstance(energy, tuple) and len(energy) == 2:
Expand All @@ -345,16 +351,26 @@ def load(self, pdep=False, plot=False):
statmech_log = local_context['frequencies']
except KeyError:
raise InputError('Required attribute "frequencies" not found in species file {0!r}.'.format(path))
if not os.path.isfile(statmech_log.path):
modified_statmech_path = os.path.join(directory, statmech_log.path)
if not os.path.isfile(modified_statmech_path):
raise InputError('Could not find Arkane statmech file for species {0} '
'in the specified path {1}'.format(self.species.label, statmech_log.path))
else:
statmech_log.path = modified_statmech_path
if isinstance(statmech_log, Log) and type(statmech_log).__name__ == 'Log':
statmech_log = determine_qm_software(os.path.join(directory, statmech_log.path))
else:
statmech_log.path = os.path.join(directory, statmech_log.path)
statmech_log = determine_qm_software(statmech_log.path)
try:
geom_log = local_context['geometry']
if not os.path.isfile(geom_log.path):
modified_geom_path = os.path.join(directory, geom_log.path)
if not os.path.isfile(modified_geom_path):
raise InputError('Could not find Arkane statmech file for species {0} '
'in the specified path {1}'.format(self.species.label, geom_log.path))
else:
geom_log.path = modified_geom_path
if isinstance(geom_log, Log) and type(geom_log).__name__ == 'Log':
geom_log = determine_qm_software(os.path.join(directory, geom_log.path))
else:
geom_log.path = os.path.join(directory, geom_log.path)
geom_log = determine_qm_software(geom_log.path)
except KeyError:
geom_log = statmech_log
logging.debug("Reading geometry from the specified frequencies file.")
Expand Down Expand Up @@ -517,9 +533,15 @@ def load(self, pdep=False, plot=False):
# the symmetry number will be derived from the scan
scan_log, pivots, top, fit = q
# Load the hindered rotor scan energies
if not os.path.isfile(scan_log.path):
modified_scan_path = os.path.join(directory, scan_log.path)
if not os.path.isfile(modified_scan_path):
raise InputError('Could not find scan energy file for species {0} '
'in the specified path {1}'.format(self.species.label, scan_log.path))
else:
scan_log.path = modified_scan_path
if isinstance(scan_log, Log) and type(scan_log).__name__ == 'Log':
scan_log = determine_qm_software(os.path.join(directory, scan_log.path))
scan_log.path = os.path.join(directory, scan_log.path)
scan_log = determine_qm_software(scan_log.path)
if isinstance(scan_log, (GaussianLog, QChemLog)):
v_list, angle = scan_log.load_scan_energies()
try:
Expand Down
43 changes: 43 additions & 0 deletions arkane/statmechTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import numpy as np

from rmgpy.species import Species
from rmgpy.exceptions import InputError

from arkane import Arkane
Expand Down Expand Up @@ -153,6 +154,48 @@ def test_is_linear(self):
self.assertFalse(is_linear(xyz8))
self.assertFalse(is_linear(xyz10))

def test_specifying_absolute_file_paths(self):
"""Test specifying absolute file paths of statmech files"""
h2o2_input = """#!/usr/bin/env python
# -*- coding: utf-8 -*-
bonds = {{'H-O': 2, 'O-O': 1}}
externalSymmetry = 2
spinMultiplicity = 1
opticalIsomers = 1
energy = {{'b3lyp/6-311+g(3df,2p)': Log('{energy}')}}
geometry = Log('{freq}')
frequencies = Log('{freq}')
rotors = [HinderedRotor(scanLog=Log('{scan}'), pivots=[1, 2], top=[1, 3], symmetry=1, fit='fourier')]
"""
abs_arkane_path = os.path.abspath(os.path.dirname(__file__)) # this is the absolute path to `.../RMG-Py/arkane`
energy_path = os.path.join('arkane', 'data', 'H2O2', 'sp_a19032.out')
freq_path = os.path.join('arkane', 'data', 'H2O2', 'freq_a19031.out')
scan_path = os.path.join('arkane', 'data', 'H2O2', 'scan_a19034.out')
h2o2_input = h2o2_input.format(energy=energy_path, freq=freq_path, scan=scan_path)
h2o2_path = os.path.join(abs_arkane_path, 'data', 'H2O2', 'H2O2.py')
if not os.path.exists(os.path.dirname(h2o2_path)):
os.makedirs(os.path.dirname(h2o2_path))
with open(h2o2_path, 'w') as f:
f.write(h2o2_input)
h2o2 = Species(label='H2O2', smiles='OO')
self.assertIsNone(h2o2.conformer)
statmech_job = StatMechJob(species=h2o2, path=h2o2_path)
statmech_job.modelChemistry = 'b3lyp/6-311+g(3df,2p)'
statmech_job.load(pdep=False, plot=False)
self.assertAlmostEqual(h2o2.conformer.E0.value_si, -146031.49933673252)
os.remove(h2o2_path)


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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
2 changes: 1 addition & 1 deletion arkane/thermoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def test_element_count_from_conformer(self):
element_count = self.thermo_job.element_count_from_conformer()
self.assertEqual(element_count, {'H': 4, 'C': 2})

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

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

if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))

0 comments on commit 581ca34

Please sign in to comment.