コード例 #1
0
    def test_3(self):
        """
        Test basic functionality of /tools/merge_models/
        """

        chem_file1 = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                  'diffmodels', 'chem1.inp')
        dict_file1 = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                  'diffmodels', 'species_dictionary1.txt')
        chem_file2 = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                  'diffmodels', 'chem2.inp')
        dict_file2 = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                  'diffmodels', 'species_dictionary2.txt')

        with open(chem_file1) as cf1, open(dict_file1) as df1, open(
                chem_file2) as cf2, open(dict_file2) as df2:
            response = self.client.post(
                '/tools/merge_models/', {
                    'chem_file1': cf1,
                    'dict_file1': df1,
                    'chem_file2': cf2,
                    'dict_file2': df2
                })

        self.assertEqual(response.status_code, 200)

        folder = os.path.join(settings.MEDIA_ROOT, 'rmg', 'tools', 'compare')

        # Check if inputs were correctly uploaded
        chem_input1 = os.path.join(folder, 'chem1.inp')
        dict_input1 = os.path.join(folder, 'RMG_Dictionary1.txt')
        chem_input2 = os.path.join(folder, 'chem2.inp')
        dict_input2 = os.path.join(folder, 'RMG_Dictionary2.txt')

        self.assertTrue(os.path.isfile(chem_input1),
                        'Chemkin file 1 was not uploaded')
        self.assertTrue(os.path.isfile(dict_input1),
                        'Dictionary file 1 was not uploaded')
        self.assertTrue(os.path.isfile(chem_input2),
                        'Chemkin file was 2 not uploaded')
        self.assertTrue(os.path.isfile(dict_input2),
                        'Dictionary file 2 was not uploaded')

        # Check if outputs were correctly generated
        chem_output = os.path.join(folder, 'chem.inp')
        dict_output = os.path.join(folder, 'species_dictionary.txt')
        log_output = os.path.join(folder, 'merging_log.txt')

        self.assertTrue(os.path.isfile(chem_output),
                        'CHEMKIN file was not generated')
        self.assertTrue(os.path.isfile(dict_output),
                        'Species dictionary was not generated')
        self.assertTrue(os.path.isfile(log_output),
                        'Merging log file was not generated')

        shutil.rmtree(folder)
コード例 #2
0
    def test_1(self):
        """
        Test basic functionality of /tools/flux/
        """

        input_file = os.path.join(rmgpy.get_path(), 'tools', 'data', 'flux',
                                  'input_simple.py')
        chem_file = os.path.join(rmgpy.get_path(), 'tools', 'data', 'flux',
                                 'chemkin', 'chem.inp')
        dict_file = os.path.join(rmgpy.get_path(), 'tools', 'data', 'flux',
                                 'chemkin', 'species_dictionary.txt')

        with open(input_file) as nf, open(chem_file) as cf, open(
                dict_file) as df:
            response = self.client.post(
                '/tools/flux/', {
                    'input_file': nf,
                    'chem_file': cf,
                    'dict_file': df,
                    'max_nodes': 50,
                    'max_edges': 50,
                    'time_step': 1.25,
                    'concentration_tol': 1e-6,
                    'species_rate_tol': 1e-6
                })

        self.assertEqual(response.status_code, 200)

        folder = os.path.join(settings.MEDIA_ROOT, 'rmg', 'tools', 'flux')

        # Check if inputs were correctly uploaded
        py_input = os.path.join(folder, 'input.py')
        chem_input = os.path.join(folder, 'chem.inp')
        dict_input = os.path.join(folder, 'species_dictionary.txt')

        self.assertTrue(os.path.isfile(py_input),
                        'RMG input file was not uploaded')
        self.assertTrue(os.path.isfile(chem_input),
                        'Chemkin file was not uploaded')
        self.assertTrue(os.path.isfile(dict_input),
                        'Dictionary file was not uploaded')

        # Check if outputs were correctly generated
        video_output = os.path.join(folder, 'flux', '1', 'flux_diagram.avi')
        species = os.path.join(folder, 'species')

        self.assertTrue(os.path.isfile(video_output),
                        'Video output was not generated')
        self.assertTrue(os.path.isdir(species),
                        'Species directory was not generated')

        shutil.rmtree(folder)
コード例 #3
0
    def createOutput(self):
        """
        Generate output html file from the path containing chemkin and dictionary files.
        """
        import re
        import subprocess
        import rmgpy

        command = (
            'python',
            os.path.join(os.path.dirname(rmgpy.get_path()), 'scripts',
                         'generateReactions.py'),
            self.input,
        )
        try:
            subprocess.check_output(command, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            error_message = e.output.splitlines()[-1].decode()
            bad_library = re.search(r'Library \S+ not found', error_message)
            if bad_library:
                error_message = f'{bad_library.group()}. It seems like you are using a non-built-in ' \
                                f'library. RMG-website populating reactions module does not support ' \
                                f'third-party library. Please try this module on your local machine.'
            else:
                error_message += '. It is likely that your inputs are invalid.'
        else:
            error_message = ''
        return error_message
コード例 #4
0
    def createOutput(self, arguments):
        """
        Generate flux diagram output from the path containing input file, chemkin and
        species dictionary, and the arguments of flux diagram module.
        """

        import re
        import subprocess
        import rmgpy

        input_file = os.path.join(self.path, 'input.py')
        chem_file = os.path.join(self.path, 'chem.inp')
        dict_file = os.path.join(self.path, 'species_dictionary.txt')

        command = [
            'python',
            os.path.join(os.path.dirname(rmgpy.get_path()), 'scripts',
                         'generateFluxDiagram.py'),
            input_file,
            chem_file,
            dict_file,
            '-n',
            str(arguments['max_nodes']),
            '-e',
            str(arguments['max_edges']),
            '-c',
            str(arguments['concentration_tol']),
            '-r',
            str(arguments['species_rate_tol']),
            '-t',
            str(arguments['time_step']),
        ]
        if arguments['chem_output']:
            command.insert(5, arguments['chem_output'])
        if arguments['java']:
            command.append('--java')

        # It is important to learn why flux diagram generation fails
        try:
            subprocess.check_output(command, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            error_message = e.output.splitlines()[-1].decode()
            bad_library = re.search(r'Library \S+ not found', error_message)
            if bad_library:
                error_message = f'{bad_library.group()}. It seems like you are using a non-built-in ' \
                                f'library. Since flux diagram module does not need library ' \
                                f'information. Please remove this libary from RMG input file and try again.'
            else:
                error_message += '. It is likely that your inputs are invalid.'
        else:
            error_message = ''

        return error_message
コード例 #5
0
    def test_1(self):
        """
        Test post functionality of /tools/chemkin/
        """

        chem_file = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                 'diffmodels', 'chem1.inp')
        dict_file = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                 'diffmodels', 'species_dictionary1.txt')

        with open(chem_file) as cf, open(dict_file) as df:
            response = self.client.post('/tools/chemkin/', {
                'chem_file': cf,
                'dict_file': df
            })

        self.assertEqual(response.status_code, 200)

        folder = os.path.join(settings.MEDIA_ROOT, 'rmg', 'tools', 'chemkin')

        # Check if inputs were correctly uploaded
        chem_input = os.path.join(folder, 'chemkin', 'chem.inp')
        dict_input = os.path.join(folder, 'RMG_Dictionary.txt')

        self.assertTrue(os.path.isfile(chem_input),
                        'Chemkin file was not uploaded')
        self.assertTrue(os.path.isfile(dict_input),
                        'Dictionary file was not uploaded')

        # Check if outputs were correctly generated
        html_output = os.path.join(folder, 'output.html')

        self.assertTrue(os.path.isfile(html_output),
                        'HTML Output was not generated')

        # Clean up
        shutil.rmtree(folder)
コード例 #6
0
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        rmg_path = os.path.normpath(os.path.join(get_path(), '..'))

        self.settings1 = QMSettings(software='mopac',
                                    method='pm3',
                                    fileStore=os.path.join(rmg_path, 'testing', 'qm', 'QMfiles'),
                                    scratchDirectory=None,
                                    onlyCyclics=False,
                                    maxRadicalNumber=0,
                                    )

        self.settings2 = QMSettings()
コード例 #7
0
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        rmg_path = os.path.normpath(os.path.join(get_path(), '..'))
        self.fileStore = os.path.join(rmg_path, 'testing', 'qm', 'QMfiles')

        self.mop1 = QMCalculator(software='mopac',
                                 method='pm3',
                                 fileStore=self.fileStore
                                 )

        self.mop2 = QMCalculator(software='mopac',
                                 method='pm6',
                                 )

        self.mop3 = QMCalculator(software='mopac',
                                 method='pm7',
                                 fileStore=self.fileStore
                                 )

        self.mop4 = QMCalculator(software='mopac',
                                 method='pm8',
                                 fileStore=self.fileStore
                                 )

        self.gauss1 = QMCalculator(software='gaussian',
                                   method='pm3',
                                   )

        self.gauss2 = QMCalculator(software='gaussian',
                                   method='pm6',
                                   fileStore=self.fileStore
                                   )

        self.gauss3 = QMCalculator(software='gaussian',
                                   method='pm7',
                                   fileStore=self.fileStore
                                   )

        self.molpro1 = QMCalculator(software='molpro',
                                    method='mp2',
                                    fileStore=self.fileStore
                                    )

        self.qmmol1 = QMCalculator(fileStore=self.fileStore)

        self.qmmol2 = QMCalculator(fileStore=self.fileStore)
コード例 #8
0
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        rmgpy_path = os.path.normpath(os.path.join(get_path(), '..'))

        qm = QMCalculator(software='mopac',
                          method='pm3',
                          fileStore=os.path.join(rmgpy_path, 'testing', 'qm', 'QMfiles'),
                          scratchDirectory=os.path.join(rmgpy_path, 'testing', 'qm', 'QMscratch'),
                          )

        if not os.path.exists(qm.settings.fileStore):
            os.makedirs(qm.settings.fileStore)

        self.qmmol1 = MopacMolPM3(mol1, qm.settings)
コード例 #9
0
    def test_1(self):
        """
        Test basic functionality of /tools/populate_reactions/
        """

        from rmgpy.chemkin import load_chemkin_file
        from rmgpy.rmg.model import ReactionModel

        input_file = os.path.join(rmgpy.get_path(), 'tools', 'data',
                                  'generate', 'input.py')

        with open(input_file) as fp:
            response = self.client.post('/tools/populate_reactions/',
                                        {'input_file': fp})

        self.assertEqual(response.status_code, 200)

        folder = os.path.join(settings.MEDIA_ROOT, 'rmg', 'tools',
                              'populateReactions')

        # Check if inputs were correctly uploaded
        py_input = os.path.join(folder, 'input.txt')

        self.assertTrue(os.path.isfile(py_input),
                        'RMG input file was not uploaded')

        # Check if outputs were correctly generated
        html_output = os.path.join(folder, 'output.html')
        chem_output = os.path.join(folder, 'chemkin', 'chem.inp')
        dict_output = os.path.join(folder, 'chemkin', 'species_dictionary.txt')

        self.assertTrue(os.path.isfile(html_output),
                        'HTML Output was not generated')
        self.assertTrue(os.path.isfile(chem_output),
                        'CHEMKIN file was not generated')
        self.assertTrue(os.path.isfile(dict_output),
                        'Species dictionary was not generated')

        # Check that the output is not empty
        model = ReactionModel()
        model.species, model.reactions = load_chemkin_file(
            chem_output, dict_output)

        self.assertTrue(model.species, 'No species were generated')
        self.assertTrue(model.reactions, 'No reactions were generated')

        shutil.rmtree(folder)
コード例 #10
0
from unittest.mock import patch

from nose.plugins.attrib import attr

import pandas as pd

from rmgpy.rmg.main import RMG, initialize_log, make_profile_graph
from rmgpy.rmg.main import RMG_Memory
from rmgpy import get_path
from rmgpy import settings
from rmgpy.data.rmg import RMGDatabase
from rmgpy.rmg.model import CoreEdgeReactionModel

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

originalPath = get_path()


@attr('functional')
class TestMain(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        """A function that is run ONCE before all unit tests in this class."""
        cls.testDir = os.path.join(originalPath, 'rmg', 'test_data',
                                   'mainTest')
        cls.outputDir = 'output'
        cls.databaseDirectory = settings['database.directory']

        cls.seedKinetics = os.path.join(cls.databaseDirectory, 'kinetics',
                                        'libraries', 'testSeed')
        cls.seedKineticsEdge = os.path.join(cls.databaseDirectory, 'kinetics',