Skip to content

Commit

Permalink
Merge pull request #1542 from ReactionMechanismGenerator/catemp2
Browse files Browse the repository at this point in the history
Non-cat changes to master from cat branch, 2
  • Loading branch information
mjohnson541 authored Feb 6, 2019
2 parents f4d8a0b + 7ff2527 commit 87ed3a5
Show file tree
Hide file tree
Showing 19 changed files with 372 additions and 158 deletions.
1 change: 1 addition & 0 deletions documentation/source/users/rmg/output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ network.
The Solver Folder
------------------
RMG currently includes a solver for isothermal batch reactors. This is in fact a critical part of the model enlargement algorithm. If you have included simulations in your input file, the solutions will be located in ``/solver``. You will probably only be interested in the files with the largest number tags.
Please note that up to and including RMG-Py version 2.3.0 these files showed mole fraction of each species at each step, but they now show amount (number of moles) of each species; you must divide by the sum if you wish to get a mole fraction.
10 changes: 10 additions & 0 deletions documentation/source/users/rmg/releaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
Release Notes
*************


RMG-Py Version 2.3....
======================
(pre-release development version)

- Miscellaneous changes:
- Output files in 'solver' directory now show species amounts (numbers of moles) not mole fractions.



RMG-Py Version 2.3.0
====================
Date: Dec 20, 2018
Expand Down
6 changes: 5 additions & 1 deletion rmgpy/data/kinetics/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ def loadLibraries(self, path, libraries=None):
label=os.path.dirname(library_file)[len(path)+1:]
logging.info('Loading kinetics library {0} from {1}...'.format(label, library_file))
library = KineticsLibrary(label=label)
library.load(library_file, self.local_context, self.global_context)
try:
library.load(library_file, self.local_context, self.global_context)
except:
logging.error("Problem loading reaction library {0!r}".format(library_file))
raise
self.libraries[library.label] = library
self.libraryOrder.append((library.label,'Reaction Library'))

Expand Down
9 changes: 8 additions & 1 deletion rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ def __apply(self, struct, doForward, unique):
elif (action[0] == 'FORM_BOND' and doForward) or (action[0] == 'BREAK_BOND' and not doForward):
if struct.hasBond(atom1, atom2):
raise InvalidActionError('Attempted to create an existing bond.')
bond = GroupBond(atom1, atom2, order=[1]) if pattern else Bond(atom1, atom2, order=1)
if info not in (1, 0): # Can only form single or vdW bonds
raise InvalidActionError('Attempted to create bond of type {:!r}'.format(info))
bond = GroupBond(atom1, atom2, order=[info]) if pattern else Bond(atom1, atom2, order=info)
struct.addBond(bond)
atom1.applyAction(['FORM_BOND', label1, info, label2])
atom2.applyAction(['FORM_BOND', label1, info, label2])
Expand Down Expand Up @@ -1402,11 +1404,16 @@ def applyRecipe(self, reactantStructures, forward=True, unique=True):
# reaction templates
return None

# Remove vdW bonds
for struct in productStructures:
struct.removeVanDerWaalsBonds()

# Make sure we don't create a different net charge between reactants and products
reactant_net_charge = product_net_charge = 0
for struc in reactantStructures:
struc.update()
reactant_net_charge += struc.getNetCharge()

for struct in productStructures:
# If product structures are Molecule objects, update their atom types
# If product structures are Group objects and the reaction is in certain families
Expand Down
4 changes: 3 additions & 1 deletion rmgpy/molecule/adjlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import logging
import warnings
import re
import numpy as np
from .molecule import Atom, Bond, getAtomType
from .group import GroupAtom, GroupBond
from .element import getElement, PeriodicSystem
Expand Down Expand Up @@ -89,7 +90,8 @@ def check_partial_charge(atom):

theoretical = valence - order - atom.radicalElectrons - 2*atom.lonePairs

if atom.charge != theoretical:
if not (-0.301 < atom.charge - theoretical < 0.301):
# It should be 0, but -0.1 is caused by a Hydrogen bond
raise InvalidAdjacencyListError(
('Invalid valency for atom {symbol} ({type}) with {radicals} unpaired electrons, '
'{lonePairs} pairs of electrons, {charge} charge, and bonds [{bonds}].'
Expand Down
1 change: 1 addition & 0 deletions rmgpy/molecule/atomtype.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ cdef class AtomType:
cdef public list oDouble
cdef public list sDouble
cdef public list triple
cdef public list quadruple
cdef public list benzene
cdef public list lonePairs
cdef public list charge
Expand Down
236 changes: 133 additions & 103 deletions rmgpy/molecule/atomtype.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rmgpy/molecule/atomtypeTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def testCarbonTypes(self):
self.assertEqual(self.atomType(self.mol59, 0), 'C2dc')
self.assertEqual(self.atomType(self.mol60, 2), 'C2dc')
self.assertEqual(self.atomType(self.mol20, 0), 'C2tc')
self.assertEqual(self.atomType(self.mol29, 0), 'C2tc')
self.assertEqual(self.atomType(self.mol29, 0), 'C2tc') # todo: add in a ciq unit test?

def testNitrogenTypes(self):
"""
Expand Down Expand Up @@ -571,7 +571,7 @@ def testSiliconTypes(self):
self.assertEqual(self.atomType(self.mol4, 1), 'SiO')
self.assertEqual(self.atomType(self.mol4, 5), 'Sid')
self.assertEqual(self.atomType(self.mol4, 4), 'Sidd')
self.assertEqual(self.atomType(self.mol4, 7), 'Sit')
self.assertEqual(self.atomType(self.mol4, 7), 'Sit') #todo: add in Siq unit test?

def testSulfurTypes(self):
"""
Expand Down
21 changes: 14 additions & 7 deletions rmgpy/molecule/atomtypedatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
"""

class AbstractAtomType(object):
def __init__(self, element = None, label=None, double=-1, triple=-1, benzene=-1, lp=-1, chrg=-1):
def __init__(self, element = None, label=None, double=-1, triple=-1, quadruple=-1, benzene=-1, lp=-1, chrg=-1):
self.element = element
self.label = label
self.double = double
self.triple = triple
self.quadruple = quadruple
self.benzene = benzene
self.lp = lp
self.chrg = chrg
Expand All @@ -61,37 +62,43 @@ def __init__(self, *args, **kwargs):
class Xs(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene = 0, 0, 0
self.double, self.triple, self.benzene, self.quadruple = 0, 0, 0, 0
self.label = 's'

class Xd(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene = 1, 0, 0
self.double, self.triple, self.benzene, self.quadruple = 1, 0, 0, 0
self.label = 'd'

class Xdd(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene = 2, 0, 0
self.double, self.triple, self.benzene, self.quadruple = 2, 0, 0, 0
self.label = 'dd'

class Xt(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene = 0, 1, 0
self.double, self.triple, self.benzene, self.quadruple = 0, 1, 0, 0
self.label = 't'

class Xq(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene, self.quadruple = 0, 0, 0, 1
self.label = 'q'

class Xb(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene = 0, 0, 2
self.double, self.triple, self.benzene, self.quadruple = 0, 0, 2, 0
self.label = 'b'

class Xbf(AbstractAtomType):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.double, self.triple, self.benzene = 0, 0, 3
self.double, self.triple, self.benzene, self.quadruple = 0, 0, 3, 0
self.label = 'bf'

def create_atom_types():
Expand Down
7 changes: 4 additions & 3 deletions rmgpy/molecule/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def toRDKitMol(mol, removeHs=True, returnMapping=False, sanitize=True):
rdAtomIndices[atom] = index

rdBonds = Chem.rdchem.BondType
orders = {'S': rdBonds.SINGLE, 'D': rdBonds.DOUBLE, 'T': rdBonds.TRIPLE, 'B': rdBonds.AROMATIC}
orders = {'S': rdBonds.SINGLE, 'D': rdBonds.DOUBLE, 'T': rdBonds.TRIPLE, 'B': rdBonds.AROMATIC, 'Q': rdBonds.QUADRUPLE}
# Add the bonds
for atom1 in mol.vertices:
for atom2, bond in atom1.edges.iteritems():
Expand Down Expand Up @@ -154,6 +154,7 @@ def fromRDKitMol(mol, rdkitmol):
if rdbondtype.name == 'SINGLE': order = 1
elif rdbondtype.name == 'DOUBLE': order = 2
elif rdbondtype.name == 'TRIPLE': order = 3
elif rdbondtype.name == 'QUADRUPLE': order = 4
elif rdbondtype.name == 'AROMATIC': order = 1.5

bond = mm.Bond(mol.vertices[i], mol.vertices[j], order)
Expand Down Expand Up @@ -221,7 +222,7 @@ def toOBMol(mol, returnMapping=False):
a.SetIsotope(atom.element.isotope)
a.SetFormalCharge(atom.charge)
obAtomIds[atom] = a.GetId()
orders = {1: 1, 2: 2, 3: 3, 1.5: 5}
orders = {1: 1, 2: 2, 3: 3, 4: 4, 1.5: 5}
for atom1 in mol.vertices:
for atom2, bond in atom1.edges.iteritems():
index1 = atoms.index(atom1)
Expand Down Expand Up @@ -274,7 +275,7 @@ def fromOBMol(mol, obmol):
for obbond in openbabel.OBMolBondIter(obmol):
# Process bond type
oborder = obbond.GetBondOrder()
if oborder not in [1,2,3] and obbond.IsAromatic() :
if oborder not in [1,2,3,4] and obbond.IsAromatic() :
oborder = 1.5

bond = mm.Bond(mol.vertices[obbond.GetBeginAtomIdx() - 1], mol.vertices[obbond.GetEndAtomIdx() - 1], oborder)#python array indices start at 0
Expand Down
15 changes: 14 additions & 1 deletion rmgpy/molecule/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,15 @@ def __renderBond(self, atom1, atom2, bond, cr):
dv = math.sin(angle + math.pi / 2)
if (self.symbols[atom1] != '' or \
self.symbols[atom2] != ''):
if bond.isTriple():
if bond.isQuadruple():
# Draw quadruple bond centered on bond axis
du *= 1.5; dv *= 1.5
self.__drawLine(cr, x1 - du, y1 - dv, x2 - du, y2 - dv)
self.__drawLine(cr, x1 + du, y1 + dv, x2 + du, y2 + dv)
du *= 2.2; dv *= 2.2
self.__drawLine(cr, x1 - du, y1 - dv, x2 - du, y2 - dv)
self.__drawLine(cr, x1 + du, y1 + dv, x2 + du, y2 + dv)
elif bond.isTriple():
# Draw triple bond centered on bond axis
du *= 3; dv *= 3
self.__drawLine(cr, x1 - du, y1 - dv, x2 - du, y2 - dv)
Expand Down Expand Up @@ -1087,6 +1095,11 @@ def __renderBond(self, atom1, atom2, bond, cr):
du *= 3; dv *= 3; dx = 2 * dx / bondLength; dy = 2 * dy / bondLength
self.__drawLine(cr, x1 - du + dx, y1 - dv + dy, x2 - du - dx, y2 - dv - dy)
self.__drawLine(cr, x1 + du + dx, y1 + dv + dy, x2 + du - dx, y2 + dv - dy, dashed=True)
elif bond.isQuadruple():
du *= 3; dv *= 3; dx = 2 * dx / bondLength; dy = 2 * dy / bondLength
self.__drawLine(cr, x1 - du + dx, y1 - dv + dy, x2 - du - dx, y2 - dv - dy)
self.__drawLine(cr, x1 + du + dx, y1 + dv + dy, x2 + du - dx, y2 + dv - dy)
self.__drawLine(cr, x1 + 2 * du + dx, y1 + 2 * dv + dy, x2 + 2 * du - dx, y2 + 2 * dv - dy)

def __renderAtom(self, symbol, atom, x0, y0, cr, heavyFirst=True, drawLonePairs=False):
"""
Expand Down
2 changes: 2 additions & 0 deletions rmgpy/molecule/group.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ cdef class Group(Graph):

cpdef removeBond(self, GroupBond bond)

cpdef removeVanDerWaalsBonds(self)

cpdef sortAtoms(self)

cpdef list sortByConnectivity(self, list atomList)
Expand Down
Loading

0 comments on commit 87ed3a5

Please sign in to comment.