Skip to content

Commit

Permalink
Merge pull request #1604 from ReactionMechanismGenerator/group_is
Browse files Browse the repository at this point in the history
Added GroupAtom isNitrogen() and isCarbon() methods
  • Loading branch information
alongd authored May 24, 2019
2 parents cb77e28 + 171e92e commit 8ce334d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
4 changes: 4 additions & 0 deletions rmgpy/molecule/group.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ cdef class GroupAtom(Vertex):

cpdef bint isSulfur(self)

cpdef bint isNitrogen(self)

cpdef bint isCarbon(self)

cpdef list countBonds(self, wildcards = ?)

cpdef bint hasWildcards(self)
Expand Down
35 changes: 22 additions & 13 deletions rmgpy/molecule/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def isSpecificCaseOf(self, other):
return False
else:
if group.lonePairs: return False
#Each charge in self must have an equivalent in other
# Each charge in self must have an equivalent in other
if self.charge:
for charge1 in self.charge:
if group.charge:
Expand All @@ -462,7 +462,6 @@ def isSpecificCaseOf(self, other):
# Otherwise self is in fact a specific case of other
return True


def isSurfaceSite(self):
"""
Return ``True`` if the atom represents a surface site or ``False`` if not.
Expand All @@ -472,31 +471,42 @@ def isSurfaceSite(self):

def isOxygen(self):
"""
Return ``True`` if the atom represents an oxygen atom or ``False`` if
not.
Return ``True`` if the atom represents an oxygen atom or ``False`` if not.
"""
allOxygens = [atomTypes['O']] + atomTypes['O'].specific
checkList=[x in allOxygens for x in self.atomType]

checkList = [x in allOxygens for x in self.atomType]
return all(checkList)

def isSulfur(self):
"""
Return ``True`` if the atom represents an sulfur atom or ``False`` if
not.
Return ``True`` if the atom represents an sulfur atom or ``False`` if not.
"""
allSulfur = [atomTypes['S']] + atomTypes['S'].specific
checkList=[x in allSulfur for x in self.atomType]
checkList = [x in allSulfur for x in self.atomType]
return all(checkList)

def isNitrogen(self):
"""
Return ``True`` if the atom represents an sulfur atom or ``False`` if not.
"""
allNitrogen = [atomTypes['N']] + atomTypes['N'].specific
checkList = [x in allNitrogen for x in self.atomType]
return all(checkList)

def isCarbon(self):
"""
Return ``True`` if the atom represents an sulfur atom or ``False`` if not.
"""
allCarbon = [atomTypes['C']] + atomTypes['C'].specific
checkList = [x in allCarbon for x in self.atomType]
return all(checkList)

def hasWildcards(self):
"""
Return ``True`` if the atom has wildcards in any of the attributes:
atomtype, electronpairs, lone pairs, charge, and bond order. Returns
atomtype, radical electrons, lone pairs, charge, and bond order. Returns
''False'' if no attribute has wildcards.
"""

if len(self.atomType) > 1:
return True
elif len(self.radicalElectrons) > 1 or len(self.radicalElectrons) == 0:
Expand All @@ -506,7 +516,6 @@ def hasWildcards(self):
for bond in self.bonds.values():
if len(bond.order) > 1:
return True

return False

def countBonds(self, wildcards = False):
Expand All @@ -516,7 +525,7 @@ def countBonds(self, wildcards = False):
If the argument wildcards is turned off then any bonds with multiple
options for bond orders will not be counted
"""
#count up number of bonds
# count up number of bonds
single = 0; rDouble = 0; oDouble = 0; sDouble = 0; triple = 0; quadruple = 0; benzene = 0
for atom2, bond12 in self.bonds.iteritems():
if not wildcards and len(bond12.order) > 1:
Expand Down
21 changes: 12 additions & 9 deletions rmgpy/statmech/conformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ cdef class Conformer(RMGObject):
Finally, the reduced moment of inertia is evaluated from the moment of inertia
of each top via the formula (I1*I2)/(I1+I2).
Option corresponds to 3 possible ways of calculating the internal reduced moment of inertia
as discussed in East and Radom [2]
``option`` is an integer corresponding to one of three possible ways of calculating the internal reduced moment
of inertia, as discussed in East and Radom [2]
+----------+---------------------------------------------------------------------------------------------------+
|option = 1|moments of inertia of each rotating group calculated about the axis containing the twisting bond |
+----------+---------------------------------------------------------------------------------------------------+
|option = 2|(unimplemented) each moment of inertia of each rotating group is calculated about an axis parallel |
|option = 2|each moment of inertia of each rotating group is calculated about an axis parallel |
| |to the twisting bond and passing through its center of mass |
+----------+---------------------------------------------------------------------------------------------------+
|option = 3|moments of inertia of each rotating group calculated about the axis passing through the |
Expand All @@ -371,9 +371,11 @@ cdef class Conformer(RMGObject):

# Check that exactly one pivot atom is in the specified top
if pivots[0] not in top1 and pivots[1] not in top1:
raise ValueError('No pivot atom included in top; you must specify which pivot atom belongs with the specified top.')
raise ValueError('No pivot atom included in top; you must specify which pivot atom belongs with the'
' specified top.')
elif pivots[0] in top1 and pivots[1] in top1:
raise ValueError('Both pivot atoms included in top; you must specify only one pivot atom that belongs with the specified top.')
raise ValueError('Both pivot atoms included in top; you must specify only one pivot atom that belongs'
' with the specified top.')

# Enumerate atoms in other top
top2 = [i+1 for i in range(Natoms) if i+1 not in top1]
Expand Down Expand Up @@ -412,8 +414,9 @@ cdef class Conformer(RMGObject):
# Determine moments of inertia of each top
I1 = 0.0
for atom in top1:
r1 = coordinates[atom-1,:] - top1CenterOfMass #shift to the center of mass (goes through center of mass)
r1 -= numpy.dot(r1, axis) * axis #remove components parallel to the bond axis
# shift to the center of mass (goes through center of mass)
r1 = coordinates[atom-1,:] - top1CenterOfMass
r1 -= numpy.dot(r1, axis) * axis # remove components parallel to the bond axis
I1 += mass[atom-1] * numpy.linalg.norm(r1)**2
I2 = 0.0
for atom in top2:
Expand Down Expand Up @@ -442,9 +445,9 @@ cdef class Conformer(RMGObject):

else:

raise ValueError("option {0} unimplemented or non-existant".format(option))
raise ValueError('Option {0} is invalid. Should be either 1, 2, or 3.'.format(option))

return I1*I2/(I1+I2)
return I1 * I2 / (I1 + I2)

@cython.boundscheck(False)
@cython.wraparound(False)
Expand Down

0 comments on commit 8ce334d

Please sign in to comment.