def debug_check_bond_direction(self, when = ""): """ Verify our bond direction is set correctly (if possible), and assertfail and/or print a debug warning if not. """ ## assert self.strandQ assert self.baseatoms, "%r has no baseatoms" % self if not self.strandQ: return assert self._bond_direction assert not self._bond_direction_error if self.bond_direction_is_arbitrary(): return # no way to check it # verify it by comparing it to actual bonds if when: when = " (%s)" % when # STUB: only works fully for PAM3 atom1 = self.baseatoms[0] atom2 = self.baseatoms[1] bond = find_bond(atom1, atom2) errormsg = "" # might be set to an error string actual_direction = 0 # might be set to a bond direction if bond: actual_direction = bond.bond_direction_from(atom1) elif atom1.Pl_neighbors() or atom2.Pl_neighbors(): # look for atom1-Pl-atom2 (2 bonds, same direction) bond1, bond2 = find_Pl_bonds(atom1, atom2) # might be None, None if not bond1: errormsg = "no Pl5 between adjacent baseatoms %r and %r" % (atom1, atom2) else: dir1 = bond1.bond_direction_from(atom1) dir2 = - bond2.bond_direction_from(atom2) if dir1 == dir2: actual_direction = dir1 # might be 0 else: errormsg = "Pl5 between %r and %r has inconsistent or unset bond directions" % (atom1, atom2) else: errormsg = "no bond between adjacent baseatoms %r and %r" % (atom1, atom2) if not errormsg: # check actual_direction ## not needed: assert actual_direction recorded_direction = self._bond_direction assert recorded_direction # redundant with earlier assert if actual_direction != recorded_direction: # error errormsg = "bond direction from %r to %r: recorded %r, actual %r" % \ (atom1, atom2, recorded_direction, actual_direction) # now errormsg tells whether there is an error. if errormsg: prefix = "debug_check_bond_direction%s in %r" % (when, self) msg = "%s: ERROR: %s" % (prefix, errormsg) print "\n*** %s ***\n" % msg summary_format = "DNA updater: bug: [N] failure(s) of debug_check_bond_direction, see console prints" env.history.deferred_summary_message( redmsg(summary_format)) return
def find_Pl_between(s1, s2): #bruce 080409 """ Assume s1 and s2 are Ss3 and/or Ss5 atoms which might be directly bonded or might have a Pl5 between them. If they are directly bonded, return None. If they have a Pl between them, return it. If neither is true, raise an exception. """ # optimize for the Pl being found bond1, bond2 = find_Pl_bonds(s1, s2) if bond1: return bond1.other(s1) else: assert find_bond(s1, s2) return None pass