diff options
author | Bruce Smith <bruce@nanorex.com> | 2008-05-11 06:13:55 +0000 |
---|---|---|
committer | Bruce Smith <bruce@nanorex.com> | 2008-05-11 06:13:55 +0000 |
commit | 3c84ccd50247d3c7ba263f1b63664718ff441ac1 (patch) | |
tree | 12228876668a62cfc5f1be30f9f28a2e0a7a78e9 | |
parent | 3fc603e1fa80e53ba163dabfec251ed970709cb5 (diff) | |
download | nanoengineer-theirix-3c84ccd50247d3c7ba263f1b63664718ff441ac1.tar.gz nanoengineer-theirix-3c84ccd50247d3c7ba263f1b63664718ff441ac1.zip |
move rail_end_atom_to_ladder from DnaLadder to dna_updater_globals
-rw-r--r-- | cad/src/dna/model/DnaLadder.py | 37 | ||||
-rw-r--r-- | cad/src/dna/model/DnaLadderRailChunk.py | 18 | ||||
-rw-r--r-- | cad/src/dna/model/outtakes/BaseIterator.py | 4 | ||||
-rw-r--r-- | cad/src/dna/model/pam3plus5_ops.py | 47 | ||||
-rw-r--r-- | cad/src/dna/updater/dna_updater_globals.py | 32 |
5 files changed, 57 insertions, 81 deletions
diff --git a/cad/src/dna/model/DnaLadder.py b/cad/src/dna/model/DnaLadder.py index e82381d25..88e8c424c 100644 --- a/cad/src/dna/model/DnaLadder.py +++ b/cad/src/dna/model/DnaLadder.py @@ -104,6 +104,8 @@ from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_OK from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_ERROR from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_NOOP_BUT_OK +from dna.updater.dna_updater_globals import rail_end_atom_to_ladder + # == ### REVIEW: should a DnaLadder contain any undoable state? @@ -420,7 +422,7 @@ class DnaLadder(object, DnaLadder_pam_conversion_methods): self.valid = val if val: # tell the rail end atoms their ladder; - # see _rail_end_atom_to_ladder for how this hint is interpreted + # see rail_end_atom_to_ladder for how this hint is interpreted for atom in self.rail_end_baseatoms(): # (could debug-warn if already set to a valid ladder) if atom._DnaLadder__ladder is not None and atom._DnaLadder__ladder.valid: @@ -730,7 +732,7 @@ class DnaLadder(object, DnaLadder_pam_conversion_methods): (strand1.bond_direction, self) end_atom = strand1.end_baseatoms()[end] assert not end_atom._dna_updater__error # otherwise we should not get this far with it - assert self is _rail_end_atom_to_ladder(end_atom) # sanity check + assert self is rail_end_atom_to_ladder(end_atom) # sanity check bond_direction_to_other = LADDER_BOND_DIRECTION_TO_OTHER_AT_END_OF_STRAND1[end] next_atom = end_atom.strand_next_baseatom(bond_direction = bond_direction_to_other) # (note: strand_next_baseatom returns None if end_atom or the atom it @@ -741,11 +743,11 @@ class DnaLadder(object, DnaLadder_pam_conversion_methods): # (report error in that case??) return None assert not next_atom._dna_updater__error - other = _rail_end_atom_to_ladder(next_atom) + other = rail_end_atom_to_ladder(next_atom) # other ladder (might be self in case of ring) if other.error: return None - # other.valid was checked in _rail_end_atom_to_ladder + # other.valid was checked in rail_end_atom_to_ladder if other is self: return None if len(self) + len(other) > MAX_LADDER_LENGTH: @@ -1371,7 +1373,7 @@ class DnaLadder(object, DnaLadder_pam_conversion_methods): # (note: strand_next_baseatom returns None if end_atom or the atom it # might return has ._dna_updater__error set, or if it reaches a non-Ss atom.) if next_atom is not None: - return _rail_end_atom_to_ladder(next_atom) + return rail_end_atom_to_ladder(next_atom) return None pass # end of class DnaLadder @@ -1465,31 +1467,6 @@ class DnaSingleStrandDomain(DnaLadder): # == -def _rail_end_atom_to_ladder(atom): # FIX: not really private, and part of an import cycle (used here and in DnaLadderRailChunk). - """ - Atom is believed to be the end-atom of a rail in a valid DnaLadder. - Return that ladder. If anything looks wrong, either console print an error message - and return None (which is likely to cause exceptions in the caller), - or raise some kind of exception (which is what we do now, since easiest). - """ - # various exceptions are possible from the following; all are errors - try: - ladder = atom._DnaLadder__ladder - assert isinstance(ladder, DnaLadder) - assert ladder.valid, "%r not valid" % ladder - # note: changes in _ladder_set_valid mean this will become common for bugs, attrerror will be rare [080413] - # or: if not, print "likely bug: invalid ladder %r found on %r during merging" % (ladder, atom) #k - # REVIEW: it might be better to return an invalid ladder than no ladder or raise an exception, - # so we might change this to return one, provided the atom is in the end_baseatoms. #### - assert atom in ladder.rail_end_baseatoms() - return ladder - except: - error = atom._dna_updater__error and ("[%s]" % atom._dna_updater__error) or "" - print "\nfollowing exception is an error in _rail_end_atom_to_ladder(%r%s): " % \ - (atom, error) - raise - pass - def _end_to_end_bonded( atom1, atom2, strandQ): """ Are the expected end-to-end bonds present between end atoms diff --git a/cad/src/dna/model/DnaLadderRailChunk.py b/cad/src/dna/model/DnaLadderRailChunk.py index 2218f3f92..f5dacfa69 100644 --- a/cad/src/dna/model/DnaLadderRailChunk.py +++ b/cad/src/dna/model/DnaLadderRailChunk.py @@ -15,6 +15,8 @@ from model.chunk import Chunk from model.elements import Singlet from model.elements import Pl5 +from files.mmp.files_mmp_writing import writemmp_mapping + from utilities.constants import gensym from utilities.constants import black from utilities.constants import ave_colors @@ -35,9 +37,7 @@ from PyQt4.Qt import QFont, QString # for debug code from utilities.debug_prefs import debug_pref, Choice_boolean_False -# see also: -## from dna_model.DnaLadder import _rail_end_atom_to_ladder -# (below, perhaps in a cycle) +from dna.updater.dna_updater_globals import rail_end_atom_to_ladder # == @@ -242,12 +242,7 @@ class DnaLadderRailChunk(Chunk): # should print the missing atoms if we can, but for now print the present atoms: print " present atoms are", self.atoms.values() - # following import is a KLUGE to avoid recursive import - # (still has import cycle, ought to ### FIX -- should refile that func somehow) - from dna.model.DnaLadder import _rail_end_atom_to_ladder - # todo: make not private... or get by without it here (another init arg??) - # review: make this import toplevel? right now it's probably in a cycle. - self.ladder = _rail_end_atom_to_ladder( chain.baseatoms[0] ) + self.ladder = rail_end_atom_to_ladder( chain.baseatoms[0] ) self._set_properties_from_grab_atom_info( use_disp, use_picked, use_display_as_pam, use_save_as_pam) # uses args and self attrs to set self.display and self.hidden @@ -266,8 +261,7 @@ class DnaLadderRailChunk(Chunk): self.ladder.ladder_invalidate_and_assert_permitted() self.ladder = ladder # can't do this, no self.chain; could do it if passed the chain: - ## from dna_model.DnaLadder import _rail_end_atom_to_ladder - ## assert self.ladder == _rail_end_atom_to_ladder( self.chain.baseatoms[0] ) + ## assert self.ladder == rail_end_atom_to_ladder( self.chain.baseatoms[0] ) return _counted_chunks = () # kluge, so len is always legal, @@ -751,8 +745,6 @@ class DnaLadderRailChunk(Chunk): # since (if this happens to be a PAM5 chunk) we use the memo # to interleave the Pl atoms into the best order for writing # (one that permits an upcoming mmp format optimization). - from files.mmp.files_mmp_writing import writemmp_mapping - # might be import cycle, might be a problem if done at toplevel mapping = writemmp_mapping(self.assy) initial_atoms = self.indexed_atoms_in_order(mapping = mapping) diff --git a/cad/src/dna/model/outtakes/BaseIterator.py b/cad/src/dna/model/outtakes/BaseIterator.py index b61c35441..21805b615 100644 --- a/cad/src/dna/model/outtakes/BaseIterator.py +++ b/cad/src/dna/model/outtakes/BaseIterator.py @@ -96,10 +96,10 @@ class BaseIterator(object): assert next_atom != -1 # if this fails, prior dna updater run didn't do enough of its job # todo: handle exceptions in the following ## next_chunk = next_atom.molecule ### BUG: invalid during updater, chunks get broken. ##### BIG LOGIC BUG, uhoh @@@@@@ -## # can we use _rail_end_atom_to_ladder? i guess so, it got set by last updater run... ladder is still valid... ###DOIT +## # can we use rail_end_atom_to_ladder? i guess so, it got set by last updater run... ladder is still valid... ###DOIT ## assert next_chunk ## next_ladder = next_chunk.ladder -## next_ladder = _rail_end_atom_to_ladder(next_atom) # IMPORT - nevermind, see below +## next_ladder = rail_end_atom_to_ladder(next_atom) # IMPORT - nevermind, see below ## assert next_ladder #k redundant? # now scan through whichrail and whichend until we find next_atom... what about len==1 case?? # ah, in that case use new rail's neighbor_baseatoms to find our own... or can we use wholechain for all this? ###DECIDE diff --git a/cad/src/dna/model/pam3plus5_ops.py b/cad/src/dna/model/pam3plus5_ops.py index 63b77c42d..8675c8d26 100644 --- a/cad/src/dna/model/pam3plus5_ops.py +++ b/cad/src/dna/model/pam3plus5_ops.py @@ -23,14 +23,22 @@ from utilities.constants import Pl_STICKY_BOND_DIRECTION from model.elements import Pl5, Singlet from utilities import debug_flags -##from utilities.constants import MODEL_PAM5 - -##from dna.updater.dna_updater_prefs import pref_dna_updater_convert_to_PAM3plus5 import foundation.env as env from utilities.Log import redmsg, graymsg from model.bond_constants import find_bond, find_Pl_bonds +from model.bond_constants import V_SINGLE + +from model.bonds import bond_atoms_faster + +from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_NOOP_BUT_OK +from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_OK +from dna.updater.dna_updater_globals import temporarily_set_dnaladder_inval_policy +from dna.updater.dna_updater_globals import restore_dnaladder_inval_policy + +from dna.updater.dna_updater_globals import _f_atom_to_ladder_location_dict +from dna.updater.dna_updater_globals import rail_end_atom_to_ladder # == @@ -117,14 +125,6 @@ def kill_Pl_and_rebond_neighbors(atom): # could also assert no dna updater error - if 1: - # kluge: do these at runtime to avoid import recursion issues. - # clean this up asap after the release. - from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_NOOP_BUT_OK - from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_OK - from dna.updater.dna_updater_globals import temporarily_set_dnaladder_inval_policy - from dna.updater.dna_updater_globals import restore_dnaladder_inval_policy - _old = temporarily_set_dnaladder_inval_policy( DNALADDER_INVAL_IS_NOOP_BUT_OK) # REVIEW: can this ever be called outside dna updater? # If so, we might not want to change the policy then @@ -312,14 +312,6 @@ def insert_Pl_between(s1, s2): #bruce 080409/080410 @return: the Pl5 atom we made. (Never returns None. Errors are either not detected or cause exceptions.) """ - if 1: - # kluge: do these at runtime to avoid import recursion issues. - # clean this up asap after the release. - from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_NOOP_BUT_OK - from dna.updater.dna_updater_globals import DNALADDER_INVAL_IS_OK - from dna.updater.dna_updater_globals import temporarily_set_dnaladder_inval_policy - from dna.updater.dna_updater_globals import restore_dnaladder_inval_policy - _old = temporarily_set_dnaladder_inval_policy( DNALADDER_INVAL_IS_NOOP_BUT_OK) # REVIEW: can this ever be called outside dna updater? # If so, we might not want to change the policy then @@ -377,9 +369,6 @@ def _insert_Pl_between_0(s1, s2): # tell caller it needs to, and is allowed to, correct pos # bond it to s1 and s2 - from model.bonds import bond_atoms_faster - from model.bond_constants import V_SINGLE - # runtime imports, since we're imported indirectly by chem.py b1 = bond_atoms_faster(Pl, s1, V_SINGLE) b2 = bond_atoms_faster(Pl, s2, V_SINGLE) @@ -478,24 +467,12 @@ def _f_find_new_ladder_location_of_baseatom(self): # that atom.molecule.ladder can find fresh ladders # that didn't yet remake their chunks -## # buggy version (the assert ladder.valid below will typically always fail) -## ladder = self.molecule.ladder -## assert ladder -## assert ladder.valid # routinely fails (for a known reason)... -## whichrail, index = ladder.whichrail_and_index_of_baseatom(self) -## # TODO: pass index hint to optimize? - - # keep these as runtime imports for now, see comment at top of module; - # WARNING: these will freak out the import cycle graph; no trivial fix at the moment - from dna.updater.dna_updater_globals import _f_atom_to_ladder_location_dict - from dna.model.DnaLadder import _rail_end_atom_to_ladder # refile this sometime soon! - locator = _f_atom_to_ladder_location_dict data = locator.get(self.key) if data: return data # (ladder, whichrail, index) # otherwise it must be an end atom on a non-fresh ladder - ladder = _rail_end_atom_to_ladder(self) + ladder = rail_end_atom_to_ladder(self) whichrail, index = ladder.whichrail_and_index_of_baseatom(self) # by search in ladder, optimized to try the ends first return ladder, whichrail, index diff --git a/cad/src/dna/updater/dna_updater_globals.py b/cad/src/dna/updater/dna_updater_globals.py index 5be6b75fb..646c0e511 100644 --- a/cad/src/dna/updater/dna_updater_globals.py +++ b/cad/src/dna/updater/dna_updater_globals.py @@ -173,7 +173,7 @@ _f_atom_to_ladder_location_dict = {} #bruce 080411, to permit finding ladder/rail/index of atoms in freshly # made ladders which didn't yet remake their chunks # (needn't store all end atoms, since those can be found using - # _rail_end_atom_to_ladder -- important for bridging Pls + # rail_end_atom_to_ladder -- important for bridging Pls # between fresh and old-untouched ladders) DNALADDER_INVAL_IS_OK = 0 @@ -220,4 +220,34 @@ def restore_dnaladder_inval_policy(old): # bruce 080413 dnaladder_inval_policy = old return +# == + +def rail_end_atom_to_ladder(atom): + """ + Atom is believed to be the end-atom of a rail in a valid DnaLadder. + Return that ladder. If anything looks wrong, either console print an error message + and return None (which is likely to cause exceptions in the caller), + or raise some kind of exception (which is what we do now, since easiest). + """ + #bruce 080510 moved this from DnaLadder.py to avoid import cycles + # various exceptions are possible from the following; all are errors + try: + ladder = atom._DnaLadder__ladder + # note: this attribute name is hardcoded in several files + ## assert isinstance(ladder, DnaLadder) + # (not worth the trouble, since we don't want the DnaLadder import) + assert ladder.valid, "%r not valid" % ladder + # note: changes in _ladder_set_valid mean this will become common for bugs, attrerror will be rare [080413] + # or: if not, print "likely bug: invalid ladder %r found on %r during merging" % (ladder, atom) #k + # REVIEW: it might be better to return an invalid ladder than no ladder or raise an exception, + # so we might change this to return one, provided the atom is in the end_baseatoms. #### + assert atom in ladder.rail_end_baseatoms() + return ladder + except: + error = atom._dna_updater__error and ("[%s]" % atom._dna_updater__error) or "" + print "\nfollowing exception is an error in rail_end_atom_to_ladder(%r%s): " % \ + (atom, error) + raise + pass + # end |