Skip to content

Commit a5e92e8

Browse files
committed
fix bug: check entry.item instead entry itself is LogicNode
also add an assertion test preventing child is same as parent
1 parent 4205e6f commit a5e92e8

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

testing/databaseTest.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def kinetics_checkGroupsFoundInTree(self, family_name):
272272
ascendParent = ascendParent.parent
273273
nose.tools.assert_true(ascendParent is not None, "Group {group} in {family} family was found in the tree without a proper parent.".format(group=child, family=family_name))
274274
nose.tools.assert_true(child in ascendParent.children, "Group {group} in {family} family was found in the tree without a proper parent.".format(group=nodeName, family=family_name))
275+
nose.tools.assert_false(child is ascendParent, "Group {group} in {family} family is a parent to itself".format(group=nodeName, family=family_name))
275276

276277
def kinetics_checkGroupsNonidentical(self, family_name):
277278
"""
@@ -304,18 +305,21 @@ def kinetics_checkChildParentRelationships(self, family_name):
304305
# This is a mistake in the database, but it should be caught by kinetics_checkGroupsFoundInTree
305306
# so rather than report it twice or crash, we'll just silently carry on to the next node.
306307
continue
308+
elif parentNode in originalFamily.forwardTemplate.products:
309+
#This is a product node made by training reactions which we do not need to check
310+
continue
307311
# Check whether the node has proper parents unless it is the top reactant or product node
308312
# The parent should be more general than the child
309313
nose.tools.assert_true(family.matchNodeToChild(parentNode, childNode),
310314
"In {family} family, group {parent} is not a proper parent of its child {child}.".format(family=family_name, parent=parentNode, child=nodeName))
311315

312316
#check that parentNodes which are LogicOr do not have an ancestor that is a Group
313317
#If it does, then the childNode must also be a child of the ancestor
314-
if isinstance(parentNode, LogicOr):
315-
ancestorNode = childNode
316-
while ancestorNode not in originalFamily.groups.top and isinstance(ancestorNode, LogicOr):
318+
if isinstance(parentNode.item, LogicOr):
319+
ancestorNode = parentNode
320+
while ancestorNode not in originalFamily.groups.top and isinstance(ancestorNode.item, LogicOr):
317321
ancestorNode = ancestorNode.parent
318-
if isinstance(ancestorNode, Group):
322+
if isinstance(ancestorNode.item, Group):
319323
nose.tools.assert_true(family.matchNodeToChild(ancestorNode, childNode),
320324
"In {family} family, group {ancestor} is not a proper ancestor of its child {child}.".format(family=family_name, ancestor=ancestorNode, child=nodeName))
321325

@@ -394,8 +398,6 @@ def kinetics_checkCdAtomType(self, family_name):
394398
family = self.database.kinetics.families[family_name]
395399
targetLabel=['Cd', 'CO', 'CS', 'Cdd']
396400
targetAtomTypes=[atomTypes[x] for x in targetLabel]
397-
oxygen=[atomTypes['O']] + atomTypes['O'].specific
398-
sulfur=[atomTypes['S']] + atomTypes['S'].specific
399401

400402
#ignore product entries that get created from training reactions
401403
ignore=[]
@@ -426,8 +428,8 @@ def kinetics_checkCdAtomType(self, family_name):
426428
#Ignore ligands that are not double bonded
427429
if 'D' in bond.order:
428430
for ligAtomType in ligand.atomType:
429-
if ligand.atomType[0] in oxygen: correctAtomList.append('CO')
430-
elif ligand.atomType[0] in sulfur: correctAtomList.append('CS')
431+
if ligand.atomType[0].isSpecificCaseOf(atomTypes['O']): correctAtomList.append('CO')
432+
elif ligand.atomType[0].isSpecificCaseOf(atomTypes['S']): correctAtomList.append('CS')
431433

432434
#remove duplicates from correctAtom:
433435
correctAtomList=list(set(correctAtomList))
@@ -451,6 +453,7 @@ def general_checkNodesFoundInTree(self, group_name, group):
451453
ascendParent = ascendParent.parent
452454
nose.tools.assert_true(ascendParent is not None, "Node {node} in {group} group was found in the tree without a proper parent.".format(node=child, group=group_name))
453455
nose.tools.assert_true(child in ascendParent.children, "Node {node} in {group} group was found in the tree without a proper parent.".format(node=nodeName, group=group_name))
456+
nose.tools.assert_false(child is ascendParent, "Node {node} in {group} is a parent to itself".format(node=nodeName, group=group_name))
454457

455458
def general_checkGroupsNonidentical(self, group_name, group):
456459
"""
@@ -483,11 +486,11 @@ def general_checkChildParentRelationships(self, group_name, group):
483486

484487
#check that parentNodes which are LogicOr do not have an ancestor that is a Group
485488
#If it does, then the childNode must also be a child of the ancestor
486-
if isinstance(parentNode, LogicOr):
487-
ancestorNode = childNode
488-
while ancestorNode not in group.top and isinstance(ancestorNode, LogicOr):
489+
if isinstance(parentNode.item, LogicOr):
490+
ancestorNode = parentNode
491+
while ancestorNode not in group.top and isinstance(ancestorNode.item, LogicOr):
489492
ancestorNode = ancestorNode.parent
490-
if isinstance(ancestorNode, Group):
493+
if isinstance(ancestorNode.item, Group):
491494
nose.tools.assert_true(group.matchNodeToChild(ancestorNode, childNode),
492495
"In {group} group, node {ancestor} is not a proper ancestor of its child {child}.".format(group=group_name, ancestor=ancestorNode, child=nodeName))
493496

@@ -522,8 +525,6 @@ def general_checkCdAtomType(self, group_name, group):
522525
"""
523526
targetLabel=['Cd', 'CO', 'CS', 'Cdd']
524527
targetAtomTypes=[atomTypes[x] for x in targetLabel]
525-
oxygen=[atomTypes['O']] + atomTypes['O'].specific
526-
sulfur=[atomTypes['S']] + atomTypes['S'].specific
527528

528529
for entryName, entry in group.entries.iteritems():
529530
if isinstance(entry.item, Group):
@@ -543,8 +544,8 @@ def general_checkCdAtomType(self, group_name, group):
543544
#Ignore ligands that are not double bonded
544545
if 'D' in bond.order:
545546
for ligAtomType in ligand.atomType:
546-
if ligand.atomType[0] in oxygen: correctAtomList.append('CO')
547-
elif ligand.atomType[0] in sulfur: correctAtomList.append('CS')
547+
if ligand.atomType[0].isSpecificCaseOf(atomTypes['O']): correctAtomList.append('CO')
548+
elif ligand.atomType[0].isSpecificCaseOf(atomTypes['S']): correctAtomList.append('CS')
548549

549550
#remove duplicates from correctAtom:
550551
correctAtomList=list(set(correctAtomList))

0 commit comments

Comments
 (0)