Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions rmgpy/molecule/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,17 @@ def equivalent(self, other):
if radical1 == radical2 and spin1 == spin2: break
else:
return False
#Each charge in self must have an equivalent in other
#Each charge in self must have an equivalent in other (and vice versa)
for charge1 in self.charge:
for charge2 in other.charge:
if charge1 == charge2: break
else:
return False
for charge1 in other.charge:
for charge2 in self.charge:
if charge1 == charge2: break
else:
return False
#The label must be the same
if not self.label==other.label: return False
# Otherwise the two atom groups are equivalent
return True

Expand Down Expand Up @@ -359,13 +362,10 @@ def isSpecificCaseOf(self, other):
return False
#Each charge in self must have an equivalent in other
for charge1 in self.charge:
for charge2 in self.charge:
for charge2 in other.charge:
if charge1 == charge2: break
else:
return False

#The label must be the same
if not self.label==other.label: return False
# Otherwise self is in fact a specific case of other
return True
################################################################################
Expand Down Expand Up @@ -792,7 +792,6 @@ def isIdentical(self, other):
The function `isIsomorphic` respects wildcards, while this function
does not, make it more useful for checking groups to groups (as
opposed to molecules to groups)

"""
# It only makes sense to compare a Group to a Group for full
# isomorphism, so raise an exception if this is not what was requested
Expand Down
22 changes: 20 additions & 2 deletions rmgpy/molecule/groupTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import unittest
from external.wip import work_in_progress

from rmgpy.molecule.group import *
from rmgpy.molecule.atomtype import atomTypes
Expand Down Expand Up @@ -153,7 +154,17 @@ def testEquivalent(self):
else:
self.assertFalse(atom1.equivalent(atom2), '{0!s} is equivalent to {1!s}'.format(atom1, atom2))
self.assertFalse(atom2.equivalent(atom1), '{0!s} is equivalent to {1!s}'.format(atom2, atom1))

# Now see if charge and radical count are checked properly
for charge in range(3):
for radicals in range(2):
atom3 = GroupAtom(atomType=[atomType1], radicalElectrons=[radicals], spinMultiplicity=[radicals + 1], charge=[charge], label='*1')
if radicals == 1 and charge == 0:
self.assertTrue(atom1.equivalent(atom3), '{0!s} is not equivalent to {1!s}'.format(atom1, atom3))
self.assertTrue(atom1.equivalent(atom3), '{0!s} is not equivalent to {1!s}'.format(atom3, atom1))
else:
self.assertFalse(atom1.equivalent(atom3), '{0!s} is equivalent to {1!s}'.format(atom1, atom3))
self.assertFalse(atom1.equivalent(atom3), '{0!s} is equivalent to {1!s}'.format(atom3, atom1))

def testIsSpecificCaseOf(self):
"""
Test the GroupAtom.isSpecificCaseOf() method.
Expand All @@ -162,10 +173,17 @@ def testIsSpecificCaseOf(self):
for label2, atomType2 in atomTypes.iteritems():
atom1 = GroupAtom(atomType=[atomType1], radicalElectrons=[1], spinMultiplicity=[2], charge=[0], label='*1')
atom2 = GroupAtom(atomType=[atomType2], radicalElectrons=[1], spinMultiplicity=[2], charge=[0], label='*1')
# And make more generic types of these two atoms
atom1gen = GroupAtom(atomType=[atomType1], radicalElectrons=[0, 1], spinMultiplicity=[1, 2], charge=[0, 1], label='*1')
atom2gen = GroupAtom(atomType=[atomType2], radicalElectrons=[0, 1], spinMultiplicity=[1, 2], charge=[0, 1], label='*1')
if label1 == label2 or atomType2 in atomType1.generic:
self.assertTrue(atom1.isSpecificCaseOf(atom2), '{0!s} is not a specific case of {1!s}'.format(atom1, atom2))
self.assertTrue(atom1.isSpecificCaseOf(atom2gen), '{0!s} is not a specific case of {1!s}'.format(atom1, atom2gen))
self.assertFalse(atom1gen.isSpecificCaseOf(atom2), '{0!s} is a specific case of {1!s}'.format(atom1gen, atom2))
else:
self.assertFalse(atom1.isSpecificCaseOf(atom2), '{0!s} is not a specific case of {1!s}'.format(atom1, atom2))
self.assertFalse(atom1.isSpecificCaseOf(atom2), '{0!s} is a specific case of {1!s}'.format(atom1, atom2))
self.assertFalse(atom1.isSpecificCaseOf(atom2gen), '{0!s} is a specific case of {1!s}'.format(atom1, atom2gen))
self.assertFalse(atom1gen.isSpecificCaseOf(atom2), '{0!s} is a specific case of {1!s}'.format(atom1gen, atom2))

def testCopy(self):
"""
Expand Down