Skip to content

Commit

Permalink
Add flag in RMG input for restarting from a seed mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
amarkpayne committed Aug 10, 2019
1 parent 840b105 commit 2763615
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/rmg/commented/input.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Uncomment either of the blocks below to restart from a seed mechanism
#
# # Option 1: Specify the path to an RMG (version > 2.4.1) generated seed mechanism folder, which contains all of the
# # required files (core and edge seed, filters and mappings) in their default locations and names in the seed folder.
# restartFromSeed(path='seed') # Location of the seed mechanism (with `Filters` subfolder) to load for restarting
#
# # Option 2: Specify the paths of each of the required files individually.
# restartFromSeed(coreSeed='seed/Seed' # Path to core seed folder. Must contain `reactions.py` and `dictionary.txt`
# edgeSeed='seed/Seed_edge' # Path to edge seed folder containing `reactions.py` and `dictionary.txt`
# filters='seed/Filters/filters.h5',
# speciesMap='seed/Filters/species_map.yml')

# Data sources
database(
# overrides RMG thermo calculation of RMG with these values.
Expand Down
45 changes: 45 additions & 0 deletions rmgpy/rmg/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,50 @@ def uncertainty(localAnalysis=False, globalAnalysis=False, uncorrelated=True, co
}


def restartFromSeed(path=None, coreSeed=None, edgeSeed=None, filters=None, speciesMap=None):
parentDir = os.path.dirname(rmg.inputFile)
rmg.restart = True
docLink = 'http://reactionmechanismgenerator.github.io/RMG-Py/users/rmg/input.html#restarting-from-a-seed-mechanism.'

if path:
if any((coreSeed, edgeSeed, filters, speciesMap)):
raise InputError('For restarting an RMG job from a seed mechanism, either the path to the RMG generated '
'seed mechanism should be given as `path`, or the path for each of the required files '
'should be explicitly given, but not both. Please take one approach or the other. For '
'further information see the RMG documentation on restarting from a seed mechanism at '
'{0}.'.format(docLink))

if not os.path.isabs(path):
path = os.path.join(parentDir, path)

if not os.path.exists(path):
raise ValueError('Unable to find the path to the restart seed folder. {0} does not exist'.format(path))

# Try to find the paths for all of the required modules
rmg.coreSeedPath = os.path.join(path, 'Seed')
rmg.edgeSeedPath = os.path.join(path, 'Seed_edge')
rmg.filtersPath = os.path.join(path, 'Filters', 'filters.h5')
rmg.speciesMapPath = os.path.join(path, 'Filters', 'species_map.yml')

else: # The user has specified each of the paths individually
rmg.coreSeedPath = coreSeed
rmg.edgeSeedPath = edgeSeed
rmg.filtersPath = filters
rmg.speciesMapPath = speciesMap

rmgPaths = [rmg.coreSeedPath, rmg.edgeSeedPath, rmg.filtersPath, rmg.speciesMapPath]
pathErrors = [filePath for filePath in rmgPaths if not os.path.exists(filePath)]

if pathErrors:
if path:
raise InputError('Could not find one or more of the required files/directories for restarting from a seed '
'mechanism: {0}. Try specifying the file paths individually. See the RMG documentation '
'at {1} for more information'.format(pathErrors, docLink))
else:
raise InputError('Could not find one or more of the required files/directories for restarting from a seed '
'mechanism: {0}. See the RMG documentation at {1} for more information'.format(pathErrors,
docLink))

################################################################################

def setGlobalRMG(rmg0):
Expand Down Expand Up @@ -831,6 +875,7 @@ def readInputFile(path, rmg0):
'generatedSpeciesConstraints': generatedSpeciesConstraints,
'thermoCentralDatabase': thermoCentralDatabase,
'uncertainty': uncertainty,
'restartFromSeed': restartFromSeed,
}

try:
Expand Down
5 changes: 5 additions & 0 deletions rmgpy/rmg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def clear(self):
self.wallTime = '00:00:00:00'
self.initializationTime = 0
self.kineticsdatastore = None
self.restart = False
self.coreSeedPath = None
self.edgeSeedPath = None
self.filtersPath = None
self.speciesMapPath = None

self.name = 'Seed'
self.generateSeedEachIteration = True
Expand Down

0 comments on commit 2763615

Please sign in to comment.