def testInitialSpecies(self): " Test we can check whether the solvent is listed as one of the initial species in various scenarios " # Case 1. when SMILES for solvent is available, the molecular structures of the initial species and the solvent # are compared to check whether the solvent is in the initial species list # Case 1-1: the solvent water is not in the initialSpecies list, so it raises Exception rmg=RMG() rmg.initialSpecies = [] solute = Species(label='n-octane', molecule=[Molecule().fromSMILES('C(CCCCC)CC')]) rmg.initialSpecies.append(solute) rmg.solvent = 'water' solventStructure = Species().fromSMILES('O') self.assertRaises(Exception, self.database.checkSolventinInitialSpecies, rmg, solventStructure) # Case 1-2: the solvent is now octane and it is listed as the initialSpecies. Although the string # names of the solute and the solvent are different, because the solvent SMILES is provided, # it can identify the 'n-octane' as the solvent rmg.solvent = 'octane' solventStructure = Species().fromSMILES('CCCCCCCC') self.database.checkSolventinInitialSpecies(rmg, solventStructure) self.assertTrue(rmg.initialSpecies[0].isSolvent) # Case 2: the solvent SMILES is not provided. In this case, it can identify the species as the # solvent by looking at the string name. # Case 2-1: Since 'n-octane and 'octane' are not equal, it raises Exception solventStructure = None self.assertRaises(Exception, self.database.checkSolventinInitialSpecies, rmg, solventStructure) # Case 2-2: The label 'n-ocatne' is corrected to 'octane', so it is identified as the solvent rmg.initialSpecies[0].label = 'octane' self.database.checkSolventinInitialSpecies(rmg, solventStructure) self.assertTrue(rmg.initialSpecies[0].isSolvent)
from rmgpy.rmg.model import CoreEdgeReactionModel from rmgpy.rmg.main import RMG from rmgpy import settings from rmgpy.data.rmg import RMGDatabase rmg = RMG() rmg.database = RMGDatabase() path = os.path.join(settings['database.directory']) rmg.database.loadThermo(os.path.join(path,'thermo')) mol = Molecule().fromSMILES('C1=CC=CC=C1') tdt = rmg.database.thermo.estimateThermoViaGroupAdditivity(mol) print tdt.comment print mol.isAromatic() spc = Species().fromSMILES('C1=CC=CC=C1') tdt = rmg.database.thermo.getThermoDataFromGroups(spc) print tdt.comment print '\n' rmg.reactionModel = CoreEdgeReactionModel() spc, isNew = rmg.reactionModel.makeNewSpecies(mol) rmg.reactionModel.addSpeciesToEdge(spc) rmg.initialSpecies = [] rmg.initialSpecies.append(spc) for species in rmg.initialSpecies: #species.generateThermoData(rmg.database, quantumMechanics=rmg.reactionModel.quantumMechanics) #print species.thermo.comment tdt = rmg.database.thermo.getThermoDataFromGroups(spc) print tdt.comment
rmg.scratchDirectory = '.' rmg.databaseDirectory = databaseDirectory rmg.thermoLibraries = ['primaryThermoLibrary'] rmg.kineticsFamilies = ['H_Abstraction',] rmg.reactionLibraries = [('KlippensteinH2O2', False),] rmgpy.rmg.input.rmg = rmg # put it in this scope so these functions can modify it #rmg.loadDatabase() # this seems to hang (forever??) but turns out it's not needed! logging.info("Loaded database.") # In[4]: rmg.reactionModel = rmgpy.rmg.model.CoreEdgeReactionModel() rmg.reactionModel.kineticsEstimator = 'rate rules' rmg.reactionModel.verboseComments = True rmg.initialSpecies = [] rmg.reactionSystems = [] def makeOrEmptyDirectory(path): """Either create a directory at `path` or delete everything in it if it exists""" if os.path.exists(path): assert os.path.isdir(path), "Path {0} exists but is not a directory".format(path) # empty it out for root, dirs, files in os.walk(path, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) else: os.makedirs(path)