def species(label, *args, **kwargs): """Load a species from an input file""" global speciesDict, jobList if label in speciesDict: raise ValueError( 'Multiple occurrences of species with label {0!r}.'.format(label)) logging.info('Loading species {0}...'.format(label)) spec = Species(label=label) speciesDict[label] = spec path = None if len(args) == 1: # The argument is a path to a conformer input file path = args[0] job = StatMechJob(species=spec, path=path) logging.debug('Added species {0} to a stat mech job.'.format(label)) jobList.append(job) elif len(args) > 1: raise InputError('species {0} can only have two non-keyword argument ' 'which should be the species label and the ' 'path to a quantum file.'.format(spec.label)) if len(kwargs) > 0: # The species parameters are given explicitly structure = None E0 = None modes = [] spinMultiplicity = 0 opticalIsomers = 1 molecularWeight = None collisionModel = None energyTransferModel = None thermo = None reactive = True for key, value in kwargs.items(): if key == 'structure': structure = value elif key == 'E0': E0 = value elif key == 'modes': modes = value elif key == 'spinMultiplicity': spinMultiplicity = value elif key == 'opticalIsomers': opticalIsomers = value elif key == 'molecularWeight': molecularWeight = value elif key == 'collisionModel': collisionModel = value elif key == 'energyTransferModel': energyTransferModel = value elif key == 'thermo': thermo = value elif key == 'reactive': reactive = value else: raise TypeError( 'species() got an unexpected keyword argument {0!r}.'. format(key)) if structure: spec.molecule = [structure] spec.conformer = Conformer(E0=E0, modes=modes, spinMultiplicity=spinMultiplicity, opticalIsomers=opticalIsomers) if molecularWeight is not None: spec.molecularWeight = molecularWeight elif spec.molecularWeight is None and is_pdep(jobList): # If a structure was given, simply calling spec.molecularWeight will calculate the molecular weight # If one of the jobs is pdep and no molecular weight is given or calculated, raise an error raise ValueError( "No molecularWeight was entered for species {0}. Since a structure wasn't given" " as well, the molecularWeight, which is important for pressure dependent jobs," " cannot be reconstructed.".format(spec.label)) spec.transportData = collisionModel spec.energyTransferModel = energyTransferModel spec.thermo = thermo spec.reactive = reactive if spec.reactive and path is None and spec.thermo is None and spec.conformer.E0 is None: if not spec.molecule: raise InputError( 'Neither thermo, E0, species file path, nor structure specified, cannot estimate' ' thermo properties of species {0}'.format(spec.label)) try: db = getDB('thermo') if db is None: raise DatabaseError('Thermo database is None.') except DatabaseError: logging.warn( "The database isn't loaded, cannot estimate thermo for {0}. " "If it is a bath gas, set reactive = False to avoid generating thermo." .format(spec.label)) else: logging.info( 'No E0 or thermo found, estimating thermo and E0 of species {0} using' ' RMG-Database...'.format(spec.label)) spec.thermo = db.getThermoData(spec) if spec.thermo.E0 is None: th = spec.thermo.toWilhoit() spec.conformer.E0 = th.E0 spec.thermo.E0 = th.E0 else: spec.conformer.E0 = spec.thermo.E0 if spec.reactive and spec.thermo and not spec.hasStatMech( ) and structure is not None: # generate stat mech info if it wasn't provided before spec.generateStatMech() if not energyTransferModel: # default to RMG's method of generating energyTransferModel spec.generateEnergyTransferModel() return spec
def species(label, *args, **kwargs): global speciesDict, jobList if label in speciesDict: raise ValueError('Multiple occurrences of species with label {0!r}.'.format(label)) logging.info('Loading species {0}...'.format(label)) spec = Species(label=label) speciesDict[label] = spec path = None if len(args) == 1: # The argument is a path to a conformer input file path = args[0] job = StatMechJob(species=spec, path=path) logging.debug('Added species {0} to a stat mech job.'.format(label)) jobList.append(job) elif len(args) > 1: raise InputError('species {0} can only have two non-keyword argument ' 'which should be the species label and the ' 'path to a quantum file.'.format(spec.label)) if len(kwargs) > 0: # The species parameters are given explicitly structure = None E0 = None modes = [] spinMultiplicity = 0 opticalIsomers = 1 molecularWeight = None collisionModel = None energyTransferModel = None thermo = None reactive = True for key, value in kwargs.items(): if key == 'structure': structure = value elif key == 'E0': E0 = value elif key == 'modes': modes = value elif key == 'spinMultiplicity': spinMultiplicity = value elif key == 'opticalIsomers': opticalIsomers = value elif key == 'molecularWeight': molecularWeight = value elif key == 'collisionModel': collisionModel = value elif key == 'energyTransferModel': energyTransferModel = value elif key == 'thermo': thermo = value elif key == 'reactive': reactive = value else: raise TypeError('species() got an unexpected keyword argument {0!r}.'.format(key)) if structure: spec.molecule = [structure] spec.conformer = Conformer(E0=E0, modes=modes, spinMultiplicity=spinMultiplicity, opticalIsomers=opticalIsomers) if molecularWeight is not None: spec.molecularWeight = molecularWeight elif spec.molecularWeight is None and is_pdep(jobList): # If a structure was given, simply calling spec.molecularWeight will calculate the molecular weight # If one of the jobs is pdep and no molecular weight is given or calculated, raise an error raise ValueError("No molecularWeight was entered for species {0}. Since a structure wasn't given" " as well, the molecularWeight, which is important for pressure dependent jobs," " cannot be reconstructed.".format(spec.label)) spec.transportData = collisionModel spec.energyTransferModel = energyTransferModel spec.thermo = thermo spec.reactive = reactive if spec.reactive and path is None and spec.thermo is None and spec.conformer.E0 is None: if not spec.molecule: raise InputError('Neither thermo, E0, species file path, nor structure specified, cannot estimate' ' thermo properties of species {0}'.format(spec.label)) try: db = getDB('thermo') if db is None: raise DatabaseError('Thermo database is None.') except DatabaseError: logging.warn("The database isn't loaded, cannot estimate thermo for {0}. " "If it is a bath gas, set reactive = False to avoid generating thermo.".format(spec.label)) else: logging.info('No E0 or thermo found, estimating thermo and E0 of species {0} using' ' RMG-Database...'.format(spec.label)) spec.thermo = db.getThermoData(spec) if spec.thermo.E0 is None: th = spec.thermo.toWilhoit() spec.conformer.E0 = th.E0 spec.thermo.E0 = th.E0 else: spec.conformer.E0 = spec.thermo.E0 if spec.reactive and spec.thermo and not spec.hasStatMech() and structure is not None: # generate stat mech info if it wasn't provided before spec.generateStatMech() if not energyTransferModel: # default to RMG's method of generating energyTransferModel spec.generateEnergyTransferModel() return spec