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 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 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(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 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)
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 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)
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 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(
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])
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')
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)