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)
def quantumMechanics( software, method, fileStore = None, scratchDirectory = None, onlyCyclics = False, maxRadicalNumber = 0, ): from rmgpy.qm.main import QMCalculator rmg.quantumMechanics = QMCalculator(software = software, method = method, fileStore = fileStore, scratchDirectory = scratchDirectory, onlyCyclics = onlyCyclics, maxRadicalNumber = maxRadicalNumber, )
def setUp(self): """ A function run before each unit test in this class. """ RMGpy_path = os.path.normpath(os.path.join(getPath(), '..')) qm = QMCalculator(software='mopac', method='pm7', 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) mol1 = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') self.qmmol1 = MopacMolPM7(mol1, qm.settings)
def test_run_jobs(self): """Test that run_jobs() works properly.""" qm = QMCalculator(software='mopac', method='pm3', fileStore=self.fileStore, onlyCyclics=True, maxRadicalNumber=0, ) output_directory = os.path.join(qm.settings.fileStore, '..', '..') qm.set_default_output_directory(output_directory) spc1 = Species().from_smiles('c1ccccc1') spc2 = Species().from_smiles('CC1C=CC=CC=1') spc_list = [spc1, spc2] qm.run_jobs(spc_list, procnum=1)
class TestQMCalculator(unittest.TestCase): """ Contains unit tests for the QMSettings class. """ mopacEnv = os.getenv('MOPAC_DIR', default="/opt/mopac") if os.path.exists(os.path.join(mopacEnv , 'MOPAC2012.exe')): mopExecutablePath = os.path.join(mopacEnv , 'MOPAC2012.exe') elif os.path.exists(os.path.join(mopacEnv , 'MOPAC2009.exe')): mopExecutablePath = os.path.join(mopacEnv , 'MOPAC2009.exe') else: mopExecutablePath = os.path.join(mopacEnv , '(MOPAC 2009 or 2012)') gaussEnv = os.getenv('GAUSS_EXEDIR') or os.getenv('g09root') or os.getenv('g03root') or "" # GAUSS_EXEDIR may be a list like "path1:path2:path3" for possibleDir in gaussEnv.split(':'): if os.path.exists(os.path.join(possibleDir , 'g09')): gaussExecutablePath = os.path.join(possibleDir , 'g09') break elif os.path.exists(os.path.join(possibleDir , 'g03')): gaussExecutablePath = os.path.join(possibleDir , 'g03') break else: gaussExecutablePath = os.path.join(gaussEnv , '(g03 or g09)') def setUp(self): """ A function run before each unit test in this class. """ RMGpy_path = os.path.normpath(os.path.join(getPath(),'..')) fileStore = os.path.join(RMGpy_path, 'testing', 'qm', 'QMfiles') self.mop1 = QMCalculator(software = 'mopac', method = 'pm3', fileStore = fileStore ) self.mop2 = QMCalculator(software = 'mopac', method = 'pm6', ) self.mop3 = QMCalculator(software = 'mopac', method = 'pm7', fileStore = fileStore ) self.mop4 = QMCalculator(software = 'mopac', method = 'pm8', fileStore = fileStore ) self.gauss1 = QMCalculator(software = 'gaussian', method = 'pm3', ) self.gauss2 = QMCalculator(software = 'gaussian', method = 'pm6', fileStore = fileStore ) self.gauss3 = QMCalculator(software = 'gaussian', method = 'pm7', fileStore = fileStore ) self.molpro1 = QMCalculator(software = 'molpro', method = 'mp2', fileStore = fileStore ) self.qmmol1 = QMCalculator(fileStore=fileStore) self.qmmol1.RMG_bin_path = os.path.join(RMGpy_path, 'testing', 'qm', 'bin') self.qmmol2 = QMCalculator(fileStore=fileStore) self.qmmol2.RMG_bin_path = os.path.join(RMGpy_path, 'testing', 'hexadiene', 'input.py') def testSetDefaultOutputDirectory(self): """ Test that setDefaultOutputDirectory() works correctly. """ self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNone(self.mop2.settings.fileStore) self.assertIsNone(self.gauss1.settings.fileStore) self.assertIsNone(self.mop1.settings.scratchDirectory) self.assertIsNone(self.mop2.settings.scratchDirectory) self.assertIsNone(self.mop3.settings.scratchDirectory) self.assertIsNone(self.gauss1.settings.scratchDirectory) self.assertIsNone(self.gauss2.settings.scratchDirectory) # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..','..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop2.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss1.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNotNone(self.mop1.settings.scratchDirectory) self.assertIsNotNone(self.mop2.settings.scratchDirectory) self.assertIsNotNone(self.mop3.settings.scratchDirectory) self.assertIsNotNone(self.gauss1.settings.scratchDirectory) self.assertIsNotNone(self.gauss2.settings.scratchDirectory) def testCheckPaths(self): """ Test that checkPaths() works correctly. """ with self.assertRaises(Exception): self.qmmol1.checkPaths() self.qmmol2.checkPaths() def testInitialize(self): """ Test that initialize() works correctly. """ # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) try: self.mop1.initialize() self.mop2.initialize() self.mop3.initialize() self.gauss1.initialize() self.gauss2.initialize() except AssertionError: self.fail("checkAllSet() raised unexpected AssertionError.") except Exception: self.fail("initialize() raised Exception. Output file paths not correctly set.") def testGetThermoData(self): """ Test that getThermoData() fails when expected. """ outputDirectory = os.path.join(self.mop4.settings.fileStore, '..', '..') self.mop4.setDefaultOutputDirectory(outputDirectory) self.gauss3.setDefaultOutputDirectory(outputDirectory) self.molpro1.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') with self.assertRaises(Exception): self.mop4.getThermoData(mol) self.gauss3.getThermoData(mol) self.molpro1.getThermoData(mol) @unittest.skipIf(os.path.exists(mopExecutablePath)==False, "If MOPAC installed, try checking your environment variables.") def testGetThermoDataMopac(self): """ Test that getThermoData() works correctly. """ outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') try: fileList = os.listdir(self.mop1.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.mop1.settings.fileStore, fileName)) except OSError: pass try: fileList = os.listdir(self.mop2.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.mop2.settings.fileStore, fileName)) except OSError: pass try: fileList = os.listdir(self.mop3.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.mop3.settings.fileStore, fileName)) except OSError: pass thermo1 = self.mop1.getThermoData(mol) thermo2 = self.mop2.getThermoData(mol) thermo3 = self.mop3.getThermoData(mol) self.assertTrue(thermo1.comment.startswith('QM MopacMolPM3')) self.assertTrue(thermo2.comment.startswith('QM MopacMolPM6')) self.assertTrue(thermo3.comment.startswith('QM MopacMolPM7')) self.assertAlmostEqual(thermo1.H298.value_si, 169708.0608, 1) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 334.5007584, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 167704.4270, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.0999241, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.H298.value_si, 166168.8571, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.S298.value_si, 336.3330406, 1) # to 1 decimal place @unittest.skipIf(os.path.exists(gaussExecutablePath)==False, "If GAUSSIAN installed, try checking your environment variables.") def testGetThermoDataGaussian(self): """ Test that getThermoData() works correctly. """ outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') try: fileList = os.listdir(self.gauss1.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.gauss1.settings.fileStore, fileName)) except OSError: pass try: fileList = os.listdir(self.gauss2.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.gauss2.settings.fileStore, fileName)) except OSError: pass thermo1 = self.gauss1.getThermoData(mol) thermo2 = self.gauss2.getThermoData(mol) self.assertTrue(thermo1.comment.startswith('QM GaussianMolPM3')) self.assertTrue(thermo2.comment.startswith('QM GaussianMolPM6')) self.assertAlmostEqual(thermo1.H298.value_si, 169908.3376, 0) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 335.5438748, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 169326.2504, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.2696063, 0) # to 1 decimal place
def saveForm(self, posted, form): """ Save form data into input.py file specified by the path. """ # Clean past history self.rmg = RMG() # Databases #self.rmg.databaseDirectory = settings['database.directory'] self.rmg.thermoLibraries = [] if posted.thermo_libraries.all(): self.rmg.thermoLibraries = [ item.thermolib.encode() for item in posted.thermo_libraries.all() ] self.rmg.reactionLibraries = [] self.rmg.seedMechanisms = [] if posted.reaction_libraries.all(): for item in posted.reaction_libraries.all(): if not item.seedmech and not item.edge: self.rmg.reactionLibraries.append( (item.reactionlib.encode(), False)) elif not item.seedmech: self.rmg.reactionLibraries.append( (item.reactionlib.encode(), True)) else: self.rmg.seedMechanisms.append(item.reactionlib.encode()) self.rmg.statmechLibraries = [] self.rmg.kineticsDepositories = 'default' self.rmg.kineticsFamilies = 'default' self.rmg.kineticsEstimator = 'rate rules' # Species self.rmg.initialSpecies = [] speciesDict = {} initialMoleFractions = {} self.rmg.reactionModel = CoreEdgeReactionModel() for item in posted.reactor_species.all(): structure = Molecule().fromAdjacencyList(item.adjlist.encode()) spec, isNew = self.rmg.reactionModel.makeNewSpecies( structure, label=item.name.encode(), reactive=False if item.inert else True) self.rmg.initialSpecies.append(spec) speciesDict[item.name.encode()] = spec initialMoleFractions[spec] = item.molefrac # Reactor systems self.rmg.reactionSystems = [] for item in posted.reactor_systems.all(): T = Quantity(item.temperature, item.temperature_units.encode()) P = Quantity(item.pressure, item.pressure_units.encode()) termination = [] if item.conversion: termination.append( TerminationConversion(speciesDict[item.species.encode()], item.conversion)) termination.append( TerminationTime( Quantity(item.terminationtime, item.time_units.encode()))) # Sensitivity Analysis sensitiveSpecies = [] if item.sensitivity: if isinstance(item.sensitivity.encode(), str): sensitivity = item.sensitivity.encode().split(',') for spec in sensitivity: sensitiveSpecies.append(speciesDict[spec.strip()]) system = SimpleReactor(T, P, initialMoleFractions, termination, sensitiveSpecies, item.sensitivityThreshold) self.rmg.reactionSystems.append(system) # Simulator tolerances self.rmg.absoluteTolerance = form.cleaned_data['simulator_atol'] self.rmg.relativeTolerance = form.cleaned_data['simulator_rtol'] self.rmg.sensitivityAbsoluteTolerance = form.cleaned_data[ 'simulator_sens_atol'] self.rmg.sensitivityRelativeTolerance = form.cleaned_data[ 'simulator_sens_rtol'] self.rmg.fluxToleranceKeepInEdge = form.cleaned_data[ 'toleranceKeepInEdge'] self.rmg.fluxToleranceMoveToCore = form.cleaned_data[ 'toleranceMoveToCore'] self.rmg.fluxToleranceInterrupt = form.cleaned_data[ 'toleranceInterruptSimulation'] self.rmg.maximumEdgeSpecies = form.cleaned_data['maximumEdgeSpecies'] self.rmg.minCoreSizeForPrune = form.cleaned_data['minCoreSizeForPrune'] self.rmg.minSpeciesExistIterationsForPrune = form.cleaned_data[ 'minSpeciesExistIterationsForPrune'] self.rmg.filterReactions = form.cleaned_data['filterReactions'] # Pressure Dependence pdep = form.cleaned_data['pdep'].encode() if pdep != 'off': self.rmg.pressureDependence = PressureDependenceJob(network=None) self.rmg.pressureDependence.method = pdep # Process interpolation model if form.cleaned_data['interpolation'].encode() == 'chebyshev': self.rmg.pressureDependence.interpolationModel = ( form.cleaned_data['interpolation'].encode(), form.cleaned_data['temp_basis'], form.cleaned_data['p_basis']) else: self.rmg.pressureDependence.interpolationModel = ( form.cleaned_data['interpolation'].encode(), ) # Temperature and pressure range self.rmg.pressureDependence.Tmin = Quantity( form.cleaned_data['temp_low'], form.cleaned_data['temprange_units'].encode()) self.rmg.pressureDependence.Tmax = Quantity( form.cleaned_data['temp_high'], form.cleaned_data['temprange_units'].encode()) self.rmg.pressureDependence.Tcount = form.cleaned_data[ 'temp_interp'] self.rmg.pressureDependence.generateTemperatureList() self.rmg.pressureDependence.Pmin = Quantity( form.cleaned_data['p_low'], form.cleaned_data['prange_units'].encode()) self.rmg.pressureDependence.Pmax = Quantity( form.cleaned_data['p_high'], form.cleaned_data['prange_units'].encode()) self.rmg.pressureDependence.Pcount = form.cleaned_data['p_interp'] self.rmg.pressureDependence.generatePressureList() # Process grain size and count self.rmg.pressureDependence.grainSize = Quantity( form.cleaned_data['maximumGrainSize'], form.cleaned_data['grainsize_units'].encode()) self.rmg.pressureDependence.grainCount = form.cleaned_data[ 'minimumNumberOfGrains'] self.rmg.pressureDependence.maximumAtoms = form.cleaned_data[ 'maximumAtoms'] # Additional Options self.rmg.units = 'si' self.rmg.saveRestartPeriod = Quantity( form.cleaned_data['saveRestartPeriod'], form.cleaned_data['saveRestartPeriodUnits'].encode( )) if form.cleaned_data['saveRestartPeriod'] else None self.rmg.generateOutputHTML = form.cleaned_data['generateOutputHTML'] self.rmg.generatePlots = form.cleaned_data['generatePlots'] self.rmg.saveSimulationProfiles = form.cleaned_data[ 'saveSimulationProfiles'] self.rmg.saveEdgeSpecies = form.cleaned_data['saveEdgeSpecies'] self.rmg.verboseComments = form.cleaned_data['verboseComments'] # Species Constraints speciesConstraints = form.cleaned_data['speciesConstraints'] if speciesConstraints == 'on': allowed = [] if form.cleaned_data['allowed_inputSpecies']: allowed.append('input species') if form.cleaned_data['allowed_seedMechanisms']: allowed.append('seed mechanisms') if form.cleaned_data['allowed_reactionLibraries']: allowed.append('reaction libraries') self.rmg.speciesConstraints['allowed'] = allowed self.rmg.speciesConstraints[ 'maximumCarbonAtoms'] = form.cleaned_data['maximumCarbonAtoms'] self.rmg.speciesConstraints[ 'maximumOxygenAtoms'] = form.cleaned_data['maximumOxygenAtoms'] self.rmg.speciesConstraints[ 'maximumNitrogenAtoms'] = form.cleaned_data[ 'maximumNitrogenAtoms'] self.rmg.speciesConstraints[ 'maximumSiliconAtoms'] = form.cleaned_data[ 'maximumSiliconAtoms'] self.rmg.speciesConstraints[ 'maximumSulfurAtoms'] = form.cleaned_data['maximumSulfurAtoms'] self.rmg.speciesConstraints[ 'maximumHeavyAtoms'] = form.cleaned_data['maximumHeavyAtoms'] self.rmg.speciesConstraints[ 'maximumRadicalElectrons'] = form.cleaned_data[ 'maximumRadicalElectrons'] self.rmg.speciesConstraints['allowSingletO2'] = form.cleaned_data[ 'allowSingletO2'] # Quantum Calculations quantumCalc = form.cleaned_data['quantumCalc'] if quantumCalc == 'on': from rmgpy.qm.main import QMCalculator self.rmg.quantumMechanics = QMCalculator( software=form.cleaned_data['software'].encode(), method=form.cleaned_data['method'].encode(), fileStore=form.cleaned_data['fileStore'].encode(), scratchDirectory=form.cleaned_data['scratchDirectory'].encode( ), onlyCyclics=form.cleaned_data['onlyCyclics'], maxRadicalNumber=form.cleaned_data['maxRadicalNumber'], ) # Save the input.py file self.rmg.saveInput(self.savepath)
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)
class TestQMCalculator(unittest.TestCase): """ Contains unit tests for the QMSettings class. """ mopExecutablePath = Mopac.executablePath if not os.path.exists(mopExecutablePath): NO_MOPAC = NO_LICENCE = True else: NO_MOPAC = False process = subprocess.Popen(mopExecutablePath, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdut, stderr = process.communicate(b'\n') NO_LICENCE = b'To install the MOPAC license' in stderr gaussExecutablePath = Gaussian.executablePath NO_GAUSSIAN = not os.path.exists(gaussExecutablePath) 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) def test_set_default_output_directory(self): """ Test that set_default_output_directory() works correctly. """ self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNone(self.mop2.settings.fileStore) self.assertIsNone(self.gauss1.settings.fileStore) self.assertIsNone(self.mop1.settings.scratchDirectory) self.assertIsNone(self.mop2.settings.scratchDirectory) self.assertIsNone(self.mop3.settings.scratchDirectory) self.assertIsNone(self.gauss1.settings.scratchDirectory) self.assertIsNone(self.gauss2.settings.scratchDirectory) # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.set_default_output_directory(outputDirectory) self.mop2.set_default_output_directory(outputDirectory) self.mop3.set_default_output_directory(outputDirectory) self.gauss1.set_default_output_directory(outputDirectory) self.gauss2.set_default_output_directory(outputDirectory) self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop2.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss1.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNotNone(self.mop1.settings.scratchDirectory) self.assertIsNotNone(self.mop2.settings.scratchDirectory) self.assertIsNotNone(self.mop3.settings.scratchDirectory) self.assertIsNotNone(self.gauss1.settings.scratchDirectory) self.assertIsNotNone(self.gauss2.settings.scratchDirectory) def test_initialize(self): """ Test that initialize() works correctly. """ # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.set_default_output_directory(outputDirectory) self.mop2.set_default_output_directory(outputDirectory) self.mop3.set_default_output_directory(outputDirectory) self.gauss1.set_default_output_directory(outputDirectory) self.gauss2.set_default_output_directory(outputDirectory) try: self.mop1.initialize() self.mop2.initialize() self.mop3.initialize() self.gauss1.initialize() self.gauss2.initialize() except AssertionError: self.fail("initialize() raised unexpected AssertionError.") except Exception: self.fail( "initialize() raised Exception. Output file paths not correctly set." ) def test_get_thermo_data(self): """ Test that get_thermo_data() fails when expected. """ output_directory = os.path.join(self.mop4.settings.fileStore, '..', '..') self.mop4.set_default_output_directory(output_directory) self.gauss3.set_default_output_directory(output_directory) self.molpro1.set_default_output_directory(output_directory) mol = Molecule().from_smiles('C1=CC=C2C=CC=CC2=C1') with self.assertRaises(Exception): self.mop4.get_thermo_data(mol) self.gauss3.get_thermo_data(mol) self.molpro1.get_thermo_data(mol) @unittest.skipIf( NO_MOPAC, "MOPAC not found. Try resetting your environment variables if you want to use it." ) @unittest.skipIf(NO_LICENCE, "MOPAC license not installed. Run mopac for instructions") def test_get_thermo_data_mopac(self): """ Test that Mocpac get_thermo_data() works correctly. """ output_directory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.set_default_output_directory(output_directory) self.mop2.set_default_output_directory(output_directory) self.mop3.set_default_output_directory(output_directory) mol = Molecule().from_smiles('C1=CC=C2C=CC=CC2=C1') for directory in (self.mop1.settings.fileStore, self.mop1.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) for directory in (self.mop2.settings.fileStore, self.mop2.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) for directory in (self.mop3.settings.fileStore, self.mop3.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) thermo1 = self.mop1.get_thermo_data(mol) thermo2 = self.mop2.get_thermo_data(mol) thermo3 = self.mop3.get_thermo_data(mol) self.assertTrue(thermo1.comment.startswith('QM MopacMolPM3')) self.assertTrue(thermo2.comment.startswith('QM MopacMolPM6')) self.assertTrue(thermo3.comment.startswith('QM MopacMolPM7')) self.assertAlmostEqual(thermo1.H298.value_si, 169708.0608, 1) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 334.5007584, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 167704.4270, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.0999241, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.H298.value_si, 166168.8571, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.S298.value_si, 336.3330406, 1) # to 1 decimal place @unittest.skipIf( NO_GAUSSIAN, "Gaussian not found. Try resetting your environment variables if you want to use it." ) def test_get_thermo_data_gaussian(self): """ Test that Gaussian get_thermo_data() works correctly. """ output_directory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.gauss1.set_default_output_directory(output_directory) self.gauss2.set_default_output_directory(output_directory) mol = Molecule().from_smiles('C1=CC=C2C=CC=CC2=C1') for directory in (self.gauss1.settings.fileStore, self.gauss1.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) for directory in (self.gauss1.settings.fileStore, self.gauss2.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) thermo1 = self.gauss1.get_thermo_data(mol) thermo2 = self.gauss2.get_thermo_data(mol) self.assertTrue(thermo1.comment.startswith('QM GaussianMolPM3')) self.assertTrue(thermo2.comment.startswith('QM GaussianMolPM6')) self.assertAlmostEqual(thermo1.H298.value_si, 169908.3376, 0) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 335.5438748, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 169326.2504, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.2696063, 0) # to 1 decimal place @unittest.skipIf( NO_MOPAC, "MOPAC not found. Try resetting your environment variables if you want to use it." ) @unittest.skipIf(NO_LICENCE, "MOPAC license not installed. Run mopac for instructions") def test_run_jobs(self): """Test that run_jobs() works properly.""" qm = QMCalculator( software='mopac', method='pm3', fileStore=self.fileStore, onlyCyclics=True, maxRadicalNumber=0, ) output_directory = os.path.join(qm.settings.fileStore, '..', '..') qm.set_default_output_directory(output_directory) spc1 = Species().from_smiles('c1ccccc1') spc2 = Species().from_smiles('CC1C=CC=CC=1') spc_list = [spc1, spc2] qm.run_jobs(spc_list, procnum=1)
class TestQMCalculator(unittest.TestCase): """ Contains unit tests for the QMSettings class. """ mopExecutablePath = Mopac.executablePath if not os.path.exists(mopExecutablePath): NO_MOPAC = NO_LICENCE = True else: NO_MOPAC = False process = subprocess.Popen(mopExecutablePath, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdut, stderr = process.communicate("\n") NO_LICENCE = 'To install the MOPAC license' in stderr gaussExecutablePath = Gaussian.executablePath NO_GAUSSIAN = not os.path.exists(gaussExecutablePath) def setUp(self): """ A function run before each unit test in this class. """ RMGpy_path = os.path.normpath(os.path.join(getPath(),'..')) fileStore = os.path.join(RMGpy_path, 'testing', 'qm', 'QMfiles') self.mop1 = QMCalculator(software = 'mopac', method = 'pm3', fileStore = fileStore ) self.mop2 = QMCalculator(software = 'mopac', method = 'pm6', ) self.mop3 = QMCalculator(software = 'mopac', method = 'pm7', fileStore = fileStore ) self.mop4 = QMCalculator(software = 'mopac', method = 'pm8', fileStore = fileStore ) self.gauss1 = QMCalculator(software = 'gaussian', method = 'pm3', ) self.gauss2 = QMCalculator(software = 'gaussian', method = 'pm6', fileStore = fileStore ) self.gauss3 = QMCalculator(software = 'gaussian', method = 'pm7', fileStore = fileStore ) self.molpro1 = QMCalculator(software = 'molpro', method = 'mp2', fileStore = fileStore ) self.qmmol1 = QMCalculator(fileStore=fileStore) self.qmmol2 = QMCalculator(fileStore=fileStore) def testSetDefaultOutputDirectory(self): """ Test that setDefaultOutputDirectory() works correctly. """ self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNone(self.mop2.settings.fileStore) self.assertIsNone(self.gauss1.settings.fileStore) self.assertIsNone(self.mop1.settings.scratchDirectory) self.assertIsNone(self.mop2.settings.scratchDirectory) self.assertIsNone(self.mop3.settings.scratchDirectory) self.assertIsNone(self.gauss1.settings.scratchDirectory) self.assertIsNone(self.gauss2.settings.scratchDirectory) # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..','..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop2.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss1.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNotNone(self.mop1.settings.scratchDirectory) self.assertIsNotNone(self.mop2.settings.scratchDirectory) self.assertIsNotNone(self.mop3.settings.scratchDirectory) self.assertIsNotNone(self.gauss1.settings.scratchDirectory) self.assertIsNotNone(self.gauss2.settings.scratchDirectory) def testInitialize(self): """ Test that initialize() works correctly. """ # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) try: self.mop1.initialize() self.mop2.initialize() self.mop3.initialize() self.gauss1.initialize() self.gauss2.initialize() except AssertionError: self.fail("initialize() raised unexpected AssertionError.") except Exception: self.fail("initialize() raised Exception. Output file paths not correctly set.") def testGetThermoData(self): """ Test that getThermoData() fails when expected. """ outputDirectory = os.path.join(self.mop4.settings.fileStore, '..', '..') self.mop4.setDefaultOutputDirectory(outputDirectory) self.gauss3.setDefaultOutputDirectory(outputDirectory) self.molpro1.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') with self.assertRaises(Exception): self.mop4.getThermoData(mol) self.gauss3.getThermoData(mol) self.molpro1.getThermoData(mol) @unittest.skipIf(NO_MOPAC, "MOPAC not found. Try resetting your environment variables if you want to use it.") @unittest.skipIf(NO_LICENCE, "MOPAC license not installed. Run mopac for instructions") def testGetThermoDataMopac(self): """ Test that Mocpac getThermoData() works correctly. """ outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') for directory in (self.mop1.settings.fileStore, self.mop1.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) for directory in (self.mop2.settings.fileStore, self.mop2.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) for directory in (self.mop3.settings.fileStore, self.mop3.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) thermo1 = self.mop1.getThermoData(mol) thermo2 = self.mop2.getThermoData(mol) thermo3 = self.mop3.getThermoData(mol) self.assertTrue(thermo1.comment.startswith('QM MopacMolPM3')) self.assertTrue(thermo2.comment.startswith('QM MopacMolPM6')) self.assertTrue(thermo3.comment.startswith('QM MopacMolPM7')) self.assertAlmostEqual(thermo1.H298.value_si, 169708.0608, 1) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 334.5007584, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 167704.4270, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.0999241, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.H298.value_si, 166168.8571, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.S298.value_si, 336.3330406, 1) # to 1 decimal place @unittest.skipIf(NO_GAUSSIAN, "Gaussian not found. Try resetting your environment variables if you want to use it.") def testGetThermoDataGaussian(self): """ Test that Gaussian getThermoData() works correctly. """ outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') for directory in (self.gauss1.settings.fileStore, self.gauss1.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) for directory in (self.gauss1.settings.fileStore, self.gauss2.settings.scratchDirectory): shutil.rmtree(directory, ignore_errors=True) thermo1 = self.gauss1.getThermoData(mol) thermo2 = self.gauss2.getThermoData(mol) self.assertTrue(thermo1.comment.startswith('QM GaussianMolPM3')) self.assertTrue(thermo2.comment.startswith('QM GaussianMolPM6')) self.assertAlmostEqual(thermo1.H298.value_si, 169908.3376, 0) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 335.5438748, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 169326.2504, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.2696063, 0) # to 1 decimal place
class TestQMCalculator(unittest.TestCase): """ Contains unit tests for the QMSettings class. """ mopacEnv = os.getenv('MOPAC_DIR', default="/opt/mopac") if os.path.exists(os.path.join(mopacEnv , 'MOPAC2012.exe')): mopExecutablePath = os.path.join(mopacEnv , 'MOPAC2012.exe') elif os.path.exists(os.path.join(mopacEnv , 'MOPAC2009.exe')): mopExecutablePath = os.path.join(mopacEnv , 'MOPAC2009.exe') else: mopExecutablePath = os.path.join(mopacEnv , '(MOPAC 2009 or 2012)') gaussEnv = os.getenv('GAUSS_EXEDIR') or os.getenv('g09root') or os.getenv('g03root') or "" # GAUSS_EXEDIR may be a list like "path1:path2:path3" for possibleDir in gaussEnv.split(':'): if os.path.exists(os.path.join(possibleDir , 'g09')): gaussExecutablePath = os.path.join(possibleDir , 'g09') break elif os.path.exists(os.path.join(possibleDir , 'g03')): gaussExecutablePath = os.path.join(possibleDir , 'g03') break else: gaussExecutablePath = os.path.join(gaussEnv , '(g03 or g09)') def setUp(self): """ A function run before each unit test in this class. """ RMGpy_path = os.path.normpath(os.path.join(getPath(),'..')) fileStore = os.path.join(RMGpy_path, 'testing', 'qm', 'QMfiles') self.mop1 = QMCalculator(software = 'mopac', method = 'pm3', fileStore = fileStore ) self.mop2 = QMCalculator(software = 'mopac', method = 'pm6', ) self.mop3 = QMCalculator(software = 'mopac', method = 'pm7', fileStore = fileStore ) self.mop4 = QMCalculator(software = 'mopac', method = 'pm8', fileStore = fileStore ) self.gauss1 = QMCalculator(software = 'gaussian', method = 'pm3', ) self.gauss2 = QMCalculator(software = 'gaussian', method = 'pm6', fileStore = fileStore ) self.gauss3 = QMCalculator(software = 'gaussian', method = 'pm7', fileStore = fileStore ) self.molpro1 = QMCalculator(software = 'molpro', method = 'mp2', fileStore = fileStore ) self.qmmol1 = QMCalculator(fileStore=fileStore) self.qmmol2 = QMCalculator(fileStore=fileStore) def testSetDefaultOutputDirectory(self): """ Test that setDefaultOutputDirectory() works correctly. """ self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNone(self.mop2.settings.fileStore) self.assertIsNone(self.gauss1.settings.fileStore) self.assertIsNone(self.mop1.settings.scratchDirectory) self.assertIsNone(self.mop2.settings.scratchDirectory) self.assertIsNone(self.mop3.settings.scratchDirectory) self.assertIsNone(self.gauss1.settings.scratchDirectory) self.assertIsNone(self.gauss2.settings.scratchDirectory) # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..','..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) self.assertIsNotNone(self.mop1.settings.fileStore) self.assertIsNotNone(self.mop2.settings.fileStore) self.assertIsNotNone(self.mop3.settings.fileStore) self.assertIsNotNone(self.gauss1.settings.fileStore) self.assertIsNotNone(self.gauss2.settings.fileStore) self.assertIsNotNone(self.mop1.settings.scratchDirectory) self.assertIsNotNone(self.mop2.settings.scratchDirectory) self.assertIsNotNone(self.mop3.settings.scratchDirectory) self.assertIsNotNone(self.gauss1.settings.scratchDirectory) self.assertIsNotNone(self.gauss2.settings.scratchDirectory) def testInitialize(self): """ Test that initialize() works correctly. """ # Now set the default directories for those not set outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) try: self.mop1.initialize() self.mop2.initialize() self.mop3.initialize() self.gauss1.initialize() self.gauss2.initialize() except AssertionError: self.fail("checkAllSet() raised unexpected AssertionError.") except Exception: self.fail("initialize() raised Exception. Output file paths not correctly set.") def testGetThermoData(self): """ Test that getThermoData() fails when expected. """ outputDirectory = os.path.join(self.mop4.settings.fileStore, '..', '..') self.mop4.setDefaultOutputDirectory(outputDirectory) self.gauss3.setDefaultOutputDirectory(outputDirectory) self.molpro1.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') with self.assertRaises(Exception): self.mop4.getThermoData(mol) self.gauss3.getThermoData(mol) self.molpro1.getThermoData(mol) @unittest.skipIf(os.path.exists(mopExecutablePath)==False, "If MOPAC installed, try checking your environment variables.") def testGetThermoDataMopac(self): """ Test that getThermoData() works correctly. """ outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.mop1.setDefaultOutputDirectory(outputDirectory) self.mop2.setDefaultOutputDirectory(outputDirectory) self.mop3.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') try: fileList = os.listdir(self.mop1.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.mop1.settings.fileStore, fileName)) except OSError: pass try: fileList = os.listdir(self.mop2.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.mop2.settings.fileStore, fileName)) except OSError: pass try: fileList = os.listdir(self.mop3.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.mop3.settings.fileStore, fileName)) except OSError: pass thermo1 = self.mop1.getThermoData(mol) thermo2 = self.mop2.getThermoData(mol) thermo3 = self.mop3.getThermoData(mol) self.assertTrue(thermo1.comment.startswith('QM MopacMolPM3')) self.assertTrue(thermo2.comment.startswith('QM MopacMolPM6')) self.assertTrue(thermo3.comment.startswith('QM MopacMolPM7')) self.assertAlmostEqual(thermo1.H298.value_si, 169708.0608, 1) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 334.5007584, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 167704.4270, 1) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.0999241, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.H298.value_si, 166168.8571, 1) # to 1 decimal place self.assertAlmostEqual(thermo3.S298.value_si, 336.3330406, 1) # to 1 decimal place @unittest.skipIf(os.path.exists(gaussExecutablePath)==False, "If GAUSSIAN installed, try checking your environment variables.") def testGetThermoDataGaussian(self): """ Test that getThermoData() works correctly. """ outputDirectory = os.path.join(self.mop1.settings.fileStore, '..', '..') self.gauss1.setDefaultOutputDirectory(outputDirectory) self.gauss2.setDefaultOutputDirectory(outputDirectory) mol = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') try: fileList = os.listdir(self.gauss1.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.gauss1.settings.fileStore, fileName)) except OSError: pass try: fileList = os.listdir(self.gauss2.settings.fileStore) for fileName in fileList: os.remove(os.path.join(self.gauss2.settings.fileStore, fileName)) except OSError: pass thermo1 = self.gauss1.getThermoData(mol) thermo2 = self.gauss2.getThermoData(mol) self.assertTrue(thermo1.comment.startswith('QM GaussianMolPM3')) self.assertTrue(thermo2.comment.startswith('QM GaussianMolPM6')) self.assertAlmostEqual(thermo1.H298.value_si, 169908.3376, 0) # to 1 decimal place self.assertAlmostEqual(thermo1.S298.value_si, 335.5438748, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.H298.value_si, 169326.2504, 0) # to 1 decimal place self.assertAlmostEqual(thermo2.S298.value_si, 338.2696063, 0) # to 1 decimal place
from rmgpy import getPath from rmgpy.qm.main import QMCalculator from rmgpy.molecule import Molecule from rmgpy.qm.gaussian import GaussianMolPM3, GaussianMolPM6 gaussEnv = os.getenv('GAUSS_EXEDIR') or os.getenv('g09root') or os.getenv( 'g03root') or "" if os.path.exists(os.path.join(gaussEnv, 'g09')): executablePath = os.path.join(gaussEnv, 'g09') elif os.path.exists(os.path.join(gaussEnv, 'g03')): executablePath = os.path.join(gaussEnv, 'g03') else: executablePath = os.path.join(gaussEnv, '(g03 or g09)') qm = QMCalculator() qm.settings.software = 'gaussian' RMGpy_path = os.path.normpath(os.path.join(getPath(), '..')) qm.settings.fileStore = os.path.join(RMGpy_path, 'testing', 'qm', 'QMfiles') qm.settings.scratchDirectory = None qm.settings.onlyCyclics = False qm.settings.maxRadicalNumber = 0 mol1 = Molecule().fromSMILES('C1=CC=C2C=CC=CC2=C1') class TestGaussianMolPM3(unittest.TestCase): """ Contains unit tests for the Geometry class. """ @unittest.skipIf(
def setUp(self): """ A function run before each unit test in this class. """ RMGpy_path = os.path.normpath(os.path.join(getPath(),'..')) fileStore = os.path.join(RMGpy_path, 'testing', 'qm', 'QMfiles') self.mop1 = QMCalculator(software = 'mopac', method = 'pm3', fileStore = fileStore ) self.mop2 = QMCalculator(software = 'mopac', method = 'pm6', ) self.mop3 = QMCalculator(software = 'mopac', method = 'pm7', fileStore = fileStore ) self.mop4 = QMCalculator(software = 'mopac', method = 'pm8', fileStore = fileStore ) self.gauss1 = QMCalculator(software = 'gaussian', method = 'pm3', ) self.gauss2 = QMCalculator(software = 'gaussian', method = 'pm6', fileStore = fileStore ) self.gauss3 = QMCalculator(software = 'gaussian', method = 'pm7', fileStore = fileStore ) self.molpro1 = QMCalculator(software = 'molpro', method = 'mp2', fileStore = fileStore ) self.qmmol1 = QMCalculator(fileStore=fileStore) self.qmmol1.RMG_bin_path = os.path.join(RMGpy_path, 'testing', 'qm', 'bin') self.qmmol2 = QMCalculator(fileStore=fileStore) self.qmmol2.RMG_bin_path = os.path.join(RMGpy_path, 'testing', 'hexadiene', 'input.py')
if atom == atomLabel[1]: atom.label = atomLabel[0] atLblsP[atomLabel[0]] = True if all(atLblsR.values()) and all(atLblsP.values()): gotOne = True break def calculate(reaction): rxnFamily = reaction.family tsDatabase = rmgDatabase.kinetics.families[rxnFamily].transitionStates reaction = qmCalc.getKineticData(reaction, tsDatabase) for files in os.listdir('./'): if files.startswith('core'): os.remove(files) if not gotOne: print "No reactions found for reaction {2}: {0} = {1}".format( '+'.join([r.molecule[0].toSMILES() for r in testReaction.reactants]), '+'.join([p.molecule[0].toSMILES() for p in testReaction.products]), i) else: qmCalc = QMCalculator( software='gaussian', method='m062x', fileStore='/gss_gpfs_scratch/slakman.b/QMfiles', scratchDirectory='/gss_gpfs_scratch/slakman.b/QMscratch', ) calculate(reaction)
def sorter_key(rxn): """ A key to generate the sort order for reactions. Needs to be consistent across runs, but we want small reactions first, so that it runs faster. """ weight = 0. for r in rxn.reactants: weight += r.molecule[0].getMolecularWeight() return (weight, repr(rxn)) qmCalc = QMCalculator( software='gaussian', method='m062x', fileStore=os.path.expandvars('/gss_gpfs_scratch/harms.n/QMfiles'), scratchDirectory=os.path.expandvars('/gss_gpfs_scratch/harms.n/QMscratch'), ) def calculate(reaction): logging.info("Calculating reaction rate for {!s}".format(reaction)) rxnFamily = reaction.family logging.info( "Selecting the appropriate TS distance database for family {!r}". format(rxnFamily)) tsDatabase = rmgDatabase.kinetics.families[rxnFamily].transitionStates logging.info("Calculating kinetic data by calling qmCalc.getKineticData") reaction = qmCalc.getKineticData(reaction, tsDatabase) logging.info("Removing 'core*' files") for files in os.listdir(
def setUp(self): """ A function run before each unit test in this class. """ RMGpy_path = os.path.normpath(os.path.join(getPath(),'..')) fileStore = os.path.join(RMGpy_path, 'testing', 'qm', 'QMfiles') if not os.path.exists(fileStore): os.makedirs(fileStore) self.mop1 = QMCalculator(fileStore=fileStore) self.mop1.settings.software = 'mopac' self.mop1.settings.method = 'pm3' self.mop1.settings.onlyCyclics = False self.mop1.settings.maxRadicalNumber = 0 self.mop2 = QMCalculator() self.mop2.settings.software = 'mopac' self.mop2.settings.method = 'pm6' self.mop2.settings.onlyCyclics = False self.mop2.settings.maxRadicalNumber = 0 self.mop3 = QMCalculator(fileStore=fileStore) self.mop3.settings.software = 'mopac' self.mop3.settings.method = 'pm7' self.mop3.settings.onlyCyclics = False self.mop3.settings.maxRadicalNumber = 0 self.mop4 = QMCalculator(fileStore=fileStore) self.mop4.settings.software = 'mopac' self.mop4.settings.method = 'pm8' self.mop4.settings.onlyCyclics = False self.mop4.settings.maxRadicalNumber = 0 self.gauss1 = QMCalculator() self.gauss1.settings.software = 'gaussian' self.gauss1.settings.method = 'pm3' self.gauss1.settings.onlyCyclics = False self.gauss1.settings.maxRadicalNumber = 0 self.gauss2 = QMCalculator(fileStore=fileStore) self.gauss2.settings.software = 'gaussian' self.gauss2.settings.method = 'pm6' self.gauss2.settings.onlyCyclics = False self.gauss2.settings.maxRadicalNumber = 0 self.gauss3 = QMCalculator(fileStore=fileStore) self.gauss3.settings.software = 'gaussian' self.gauss3.settings.method = 'pm7' self.gauss3.settings.onlyCyclics = False self.gauss3.settings.maxRadicalNumber = 0 self.molpro1 = QMCalculator(fileStore=fileStore) self.molpro1.settings.software = 'molpro' self.molpro1.settings.method = 'mp2' self.molpro1.settings.onlyCyclics = False self.molpro1.settings.maxRadicalNumber = 0 self.qmmol1 = QMCalculator(fileStore=fileStore) self.qmmol1.RMG_bin_path = os.path.join(RMGpy_path, 'testing', 'qm', 'bin') self.qmmol2 = QMCalculator(fileStore=fileStore) self.qmmol2.RMG_bin_path = os.path.join(RMGpy_path, 'testing', 'hexadiene', 'input.py')
for product in reaction.products: product = product.molecule[0] product.clearLabeledAtoms() for atom in product.atoms: for atomLabel in reaction.labeledAtoms: if atom == atomLabel[1]: atom.label = atomLabel[0] atLblsP[atomLabel[0]] = True if all(atLblsR.values()) and all(atLblsP.values()): gotOne = True rxnFamily = reaction.family.label assert gotOne qmCalc = QMCalculator( software='gaussian', method='m062x', fileStore='/scratch/bhoorasingh.p/QMfiles', scratchDirectory='/scratch/bhoorasingh.p/QMscratch', ) reaction = calculate(reaction) if reaction.kinetics: """ Return the rate coefficient in the appropriate combination of cm^3, mol, and s at temperature `T` in K and pressure `P` in Pa. """ sarathyKin = chemkinRxn['rmgPyKinetics'] Temp = 1000 # Kelvin idx = str(i) row = [idx, rxnFamily] row.extend([mol.label for mol in reaction.reactants]) row.extend([mol.label for mol in reaction.products])