-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add training #125
Closed
Closed
Add training #125
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
from rmgpy.rmg.model import Species | ||
from rmgpy import settings | ||
from rmgpy.data.kinetics.library import KineticsLibrary | ||
|
||
from rmgpy.data.reference import * | ||
import os.path | ||
from rmgpy.kinetics.arrhenius import Arrhenius | ||
from rmgpy.quantity import ScalarQuantity | ||
from rmgpy.data.base import Entry | ||
from rmgpy.reaction import Reaction | ||
import re | ||
""" | ||
The purpose of this script is to create a reaction library from the least amount of input. | ||
|
||
Might eventually make it so it reads in a csv instead of hard-coding inputs below. | ||
|
||
Currently the numbers below are all made up, so they should not be used by any means. | ||
|
||
For the inputs, every variable that is a list has elements where the indexes correspond with entry in another list | ||
For example, one complete data entry for Arrhenius parameters would be A[i], n[i], and Ea[i] | ||
""" | ||
|
||
#initalize library variables | ||
libraryName = 'test' | ||
library = KineticsLibrary() | ||
library.name = libraryName | ||
library.label =libraryName | ||
library.shortDesc = "Library with made up rates" | ||
library.longDesc = """ | ||
This library is a test created to showcase the createKineticsLibrary.py script | ||
""" | ||
|
||
#smiles for reactants and products | ||
#can use empty string of None for unimolecular reactions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change 'of' to 'or' |
||
react1smiles = ["CC=CC", "C=C", 'CCCCC[CH2]'] | ||
react2smiles = ['[CH3]', '[CH3]', ''] | ||
product1smiles = ["[CH2]C=CC", "[CH]=C", "C[CH]CCCC"] | ||
product2smiles = ['C', 'C', None] | ||
|
||
#kinetics parameters | ||
AunitsBimolecular = 'cm^3/(mol*s)' | ||
AunitsUnimolecular = 's^-1' | ||
EaUnits = 'kcal/mol' | ||
A = [18.06, 26.3, 18.4] | ||
n = [3.27, 3.24, 3.27] | ||
Ea = [6.85, 7.03, 7.15] | ||
|
||
#write comments | ||
shortDesc0 = u"""CBS-QB3 calculation with 1-d rotor treatment at B3LYP/631G(d)""" | ||
longDesc0 = u""" | ||
Quantum chemistry calculations CBS-QB3 calculation with 1-d rotor treatment at | ||
B3LYP/631G(d)" using Gaussian 03 and Gaussian 09. High-pressure-limit rate | ||
coefficient computed TST with Eckart Tunnelling" | ||
""" | ||
reference0 = Article( | ||
authors=["K. Wang", "S. Villano", "A. Dean"], | ||
title=u'Reactions of allylic radicals that impact molecular weight growth kinetics', | ||
journal="Phys. Chem. Chem. Phys.", | ||
volume="17", | ||
pages="""6255-6273""", | ||
year="2015", | ||
) | ||
# flexible lists so that different entries can have different comments | ||
# if you want no shortDesc or longDesc, you should use empty strings for Desc | ||
shortDescList= [shortDesc0, '', ''] | ||
longDescList = [longDesc0, '', ''] | ||
# if you want no reference you should use None | ||
referenceList = [reference0, None, None] | ||
|
||
#done with inputs | ||
################################################################################################################# | ||
#check list lengths (useful check for some assurance you've entered things correctly) | ||
length = len(react1smiles) | ||
assert len(react2smiles) == length, "react2smiles has a different length than other lists" | ||
assert len(product1smiles) == length, "product1smiles has a different length than other lists" | ||
assert len(product2smiles) == length, "product2smiles has a different length than other lists" | ||
assert len(A) == length, "A has a different length than other lists" | ||
assert len(n) == length, "n has a different length than other lists" | ||
assert len(Ea) == length, "Ea has a different length than other lists" | ||
assert len(shortDescList) == length, "shortDescList has a different length than other lists" | ||
assert len(longDescList) == length, "longDescList has a different length than other lists" | ||
assert len(referenceList) == length, "referenceList has a different length than other lists" | ||
|
||
#create entries in the library | ||
speciesDict={} | ||
for index, r1smiles in enumerate(react1smiles): | ||
bimolecular = False | ||
#example item | ||
r2smiles = react2smiles[index] | ||
p1smiles = product1smiles[index] | ||
p2smiles = product2smiles[index] | ||
|
||
#make species | ||
r1 = Species().fromSMILES(r1smiles) | ||
p1 = Species().fromSMILES(p1smiles) | ||
r2 = None | ||
p2 = None | ||
if r2smiles: r2 = Species().fromSMILES(r2smiles) | ||
if p2smiles: p2 = Species().fromSMILES(p2smiles) | ||
|
||
#make species labels | ||
changeDict={} #necessary in case any species already exists in the speciesDict (isomorphic not same instance) | ||
for spec in [r1, r2, p1, p2]: | ||
if spec: | ||
for speciesLabel, existingSpecies in speciesDict.iteritems(): | ||
if spec.isIsomorphic(existingSpecies): | ||
changeDict[spec] = existingSpecies #species already in speciesDict | ||
break | ||
else: #species is new | ||
changeDict[spec] = spec | ||
spec_formula = spec.molecule[0].getFormula() | ||
if spec_formula not in speciesDict: | ||
spec.label = spec_formula | ||
else: | ||
duplicateNumber = 2 | ||
while (spec_formula + '-{}'.format(duplicateNumber)) in speciesDict: | ||
duplicateNumber += 1 | ||
spec.label = spec_formula + '-{}'.format(duplicateNumber) | ||
speciesDict[spec.label] = spec | ||
|
||
#Remake species accounting for duplicates | ||
r1 = changeDict[r1] | ||
p1 = changeDict[p1] | ||
if r2: r2 = changeDict[r2] | ||
if p2: p2 = changeDict[p2] | ||
|
||
#create reaction | ||
newReaction = None | ||
if r2: | ||
bimolecular = True | ||
if p2: | ||
newReaction = Reaction(reactants = [r1, r2], products = [p1, p2]) | ||
else: | ||
newReaction = Reaction(reactants = [r1, r2], products = [p1]) | ||
elif p2: | ||
newReaction = Reaction(reactants = [r1], products = [p1, p2]) | ||
else: | ||
newReaction = Reaction(reactants = [r1], products = [p1]) | ||
|
||
#set Arrhenius | ||
newArrhenius = Arrhenius() | ||
if bimolecular: | ||
Ainstance = ScalarQuantity(A[index], AunitsBimolecular) | ||
else: | ||
Ainstance = ScalarQuantity(A[index], AunitsUnimolecular) | ||
newArrhenius = Arrhenius(A = Ainstance, | ||
n = ScalarQuantity(n[index], ''), | ||
Ea = ScalarQuantity(Ea[index], EaUnits)) | ||
|
||
#create library entry | ||
referenceType = None | ||
if referenceList[index]: referenceType = re.sub('.*\.', '', str(referenceList[index].__class__)) | ||
newEntry = Entry(index= index, | ||
label=str(newReaction), | ||
item=newReaction, | ||
parent=None, | ||
children=None, | ||
data=newArrhenius, | ||
reference=referenceList[index], | ||
referenceType= referenceType, | ||
shortDesc=shortDescList[index], | ||
longDesc=longDescList[index], | ||
rank=None,) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it important to have rank in the inputted data? |
||
|
||
#add to entry to library | ||
library.entries[index] = newEntry | ||
|
||
library.save(os.path.join(settings['database.directory'],'kinetics/libraries/{0}/reactions.py'.format(libraryName))) | ||
library.saveDictionary(os.path.join(settings['database.directory'],'kinetics/libraries/{0}/dictionary.txt'.format(libraryName))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to self: I wrote this for loop workaround to solve the issue that family.saveTrainingReactions doesn't seem to allow different meta-data (shortDesc, reference, referenceType, longDesc) per reactions. The code now labels every single reaction with the same index as well as creates an extra line break after every entry.
Some combination of this causes the training reactions to be un-usable without manual edits
Both of these are taken account into the family. saveTrainingReactions. My initial thoughts is to change this function to allow different meta-data rather than trying to debug the work-around.