def setUp(self): """setUp gets called before each test""" from rmg import constants, log import rmg.cantera_loader import ctml_writer as cti constants.scratchDirectory = os.path.join(self.testfolder,'temp') if os.path.isdir(constants.scratchDirectory): shutil.rmtree(constants.scratchDirectory) os.makedirs(constants.scratchDirectory) if cti._species: reload(cti) if rmg.cantera_loader._species: reload(rmg.cantera_loader) log.initialize(verbose=20, fstr='RMG.log')
sys.path.append('../source') import rmg.thermo as thermo import rmg.species as species import rmg.structure as structure from rmg.structure import Structure propane = structure.Structure(SMILES='CCC') propane.updateAtomTypes() GAthermoData = species.getThermoData(propane,thermoClass=thermo.ThermoGAData) WilhoitData = thermo.convertGAtoWilhoit(GAthermoData, atoms=11, rotors=2, linear=False) NASAthermoData = thermo.convertWilhoitToNASA(WilhoitData) """ test1 = "for T in range(600,1100,100):\n\tGAthermoData.getEnthalpy(T)" test2 = "for T in range(600,1100,100):\n\tWilhoitData.getEnthalpy(T)" test3 = "for T in range(600,1100,100):\n\tNASAthermoData.getEnthalpy(T)" print "****" print "Timing getEnthalpy:" t = Timer(test1,startup) times = t.repeat(repeat=5,number=1000) print " ThermoGAData took %.3f milliseconds (%s)"%(min(times), times) t = Timer(test2,startup) times = t.repeat(repeat=3,number=1000) print " ThermoWilhoitData took %.3f milliseconds (%s)"%(min(times), times) t = Timer(test3,startup) times = t.repeat(repeat=3,number=1000) print " ThermoNASAData took %.3f milliseconds (%s)"%(min(times), times) print "****\n\nContinuing with tests..." # Show debug messages (as databases are loading) logging.initialize(10,'RMG.log') unittest.main( testRunner = unittest.TextTestRunner(verbosity=2) )
for product in reaction.products: if product0.isIsomorphic(product): match = True self.assertTrue(match) for kin0 in reaction0.kinetics: match = False for kin in reaction.kinetics: if kin0.equals(kin): match = True self.assertTrue(match) self.assertTrue(reaction0.family.label == reaction.family.label) self.assertTrue(reaction0.atomLabels.keys() == reaction.atomLabels.keys()) self.assertTrue(reaction0.multiplier == reaction.multiplier) self.assertTrue(reaction0.bestKinetics == reaction.bestKinetics) #self.assertTrue(reaction0.reverse == reaction.reverse) ################################################################################ if __name__ == '__main__': # Show debug messages as databases are loading log.initialize(10, 'RMG.log') # Load databases databasePath = '../data/RMG_database' loadThermoDatabases(databasePath) loadKineticsDatabases(databasePath, only_families=['R_Recombination']) # Show info messages during tests log.initialize(20, 'RMG.log') # Conduct tests unittest.main( testRunner = unittest.TextTestRunner(verbosity=2) )
elif len(data) == 2: settings.wallTime = int(data[-1]) + 60 * int(data[-2]) elif len(data) == 3: settings.wallTime = int(data[-1]) + 60 * int(data[-2]) + 3600 * int(data[-3]) elif len(data) == 4: settings.wallTime = int(data[-1]) + 60 * int(data[-2]) + 3600 * int(data[-3]) + 86400 * int(data[-4]) else: raise ValueError('Invalid format for wall time; should be HH:MM:SS.') except ValueError, e: raise ValueError('Invalid format for wall time; should be HH:MM:SS.') # Save initialization time settings.initializationTime = time.time() # Set up log (uses stdout and a file) logging.initialize(options.verbose, os.path.join(settings.outputDirectory,'RMG.log')) # Log start timestamp logging.info('RMG execution initiated at ' + time.asctime() + '\n') # Print out RMG header logging.logHeader() # Make output subdirectories plotDir = os.path.join(settings.outputDirectory, 'plot') if os.path.exists(plotDir): for f in os.listdir(plotDir): os.remove(plotDir + '/' + f) os.rmdir(plotDir) os.mkdir(plotDir)
for atomType, count in localAtomTypeCount.iteritems(): logging.info( '\t%i instances of %s' % (count, atomType) ) logging.info( '' ) # Print the totals logging.info( 'Totals:' ) for atomType, count in totalAtomTypeCount.iteritems(): logging.info( '\t%i instances of %s' % (count, atomType) ) ################################################################################ if __name__ == '__main__': import math # Show debug messages (as databases are loading) logging.initialize(10,'database.log') # Load databases databasePath = '../data/RMG_database' # loadThermoDatabases(databasePath) loadKineticsDatabases(databasePath,only_families=['H_Abstraction']) # findCatchallNodes() fit_groups() # fit_groups(['H abstraction']) # graph = fit_groups() # write_xml() # for node in graph.get_node_list(): # node.set_style('filled') # node.set_fontcolor('#FFFFFFFF')
def execute(inputFile, options): # Set directories settings.libraryDirectory = options.libraryDirectory # Set up log (uses stdout and a file) logging.initialize(options.verbose, os.path.join(settings.outputDirectory,'RMG.log')) # Log start timestamp logging.info('RMG execution initiated at ' + time.asctime() + '\n') # Print out RMG header logging.logHeader() # Read input file network, Tlist, Plist, grainSize, numGrains, method, model = io.readInputFile(inputFile) # Shift network such that lowest-energy isomer has a ground state of 0.0 logging.info('Zeroing lowest energy isomer...') network.shiftToZeroEnergy() # Determine energy grains logging.info('Determining energy grains...') Elist = network.determineEnergyGrains(grainSize, numGrains, max(Tlist)) # Calculate density of states for all isomers in network logging.info('Calculating densities of states...') network.calculateDensitiesOfStates(Elist) # # DEBUG: Plot densities of states # import pylab # legend = [] # for isomer in network.isomers: # if isomer.densStates is not None: # pylab.semilogy(Elist / 1000.0, isomer.densStates, '-') # #legend.append(str(isomer)) # pylab.xlabel('Energy (kJ/mol)') # pylab.ylabel('Density of states (mol/J)') # #pylab.legend(legend, loc=4) # pylab.show() # Determine phenomenological rate coefficients logging.info('Calculating phenomenological rate coefficients...') K = network.calculateRateCoefficients(Tlist, Plist, Elist, method) # Create net reaction objects network.netReactions = [] index = 0 for i, reactantIsomer in enumerate(network.isomers): for j, productIsomer in enumerate(network.isomers[0:i]): netReaction = reaction.PDepReaction(reactantIsomer.species, productIsomer.species, network, None) netReaction.id = 'netReaction%i' % (index+1) index += 1 network.netReactions.append(netReaction) # Fit interpolation model if model[0].lower() == 'chebyshev': modelType, degreeT, degreeP = model chebyshev = kinetics.ChebyshevKinetics() chebyshev.fitToData(Tlist, Plist, K[:,:,j,i], degreeT, degreeP) netReaction.kinetics = [chebyshev] elif model.lower() == 'pdeparrhenius': pDepArrhenius = kinetics.PDepArrheniusKinetics() pDepArrhenius.fitToData(Tlist, Plist, K[:,:,j,i]) netReaction.kinetics = [pDepArrhenius] else: pass # Save results to file logging.info('Saving results...') outputFile = os.path.join(os.path.dirname(inputFile), 'output.xml') io.writeOutputFile(outputFile, network, Tlist, Plist, Elist, method, model) logging.info('') # Log end timestamp logging.info('RMG execution terminated at ' + time.asctime())
structure4.fromAdjacencyList(''' 1 *1 H 0 {2,S} 2 *2 H 0 {1,S} ''') C6H10, isNew = makeNewSpecies(structure1) H, isNew = makeNewSpecies(structure2) C6H9, isNew = makeNewSpecies(structure3) H2, isNew = makeNewSpecies(structure4) reaction1, isNew = makeNewReaction([C6H9, H2], [C6H10, H], \ [C6H9.structure[0], H2.structure[0]], \ [C6H10.structure[0], H.structure[0]], \ None) """ test1 = "reaction1, isNew = makeNewReaction([C6H9, H2], [C6H10, H], [C6H9.structure[0], H2.structure[0]], [C6H10.structure[0], H.structure[0]], None)" print "Timing makeNewReaction:" t = Timer(test1,startup) # times = t.repeat(repeat=1,number=10000) # print " Test1 took %.3f microseconds (%s)"%(min(times)*1000/10, [tt*1000/10 for tt in times]) print "**************" # run a certain check without catching errors (turn on PDB debugger first) import rmg.log as logging logging.initialize(5,'reactiontest.log') #import pdb ReactionSetCheck('test12Cycloaddition').debug() # now run all the unit tests unittest.main( testRunner = unittest.TextTestRunner(verbosity=2) )