diff options
author | Mark Sims <mark@nanorex.com> | 2008-12-26 08:00:53 +0000 |
---|---|---|
committer | Mark Sims <mark@nanorex.com> | 2008-12-26 08:00:53 +0000 |
commit | e7ad04cb2877f8cea4b161ee8ae27e37111ab1af (patch) | |
tree | 17dea076f42cd346998dc6adac2031437305dbe0 | |
parent | 0daefac07a019d1e946c8665478ad87aac7426f0 (diff) | |
download | nanoengineer-e7ad04cb2877f8cea4b161ee8ae27e37111ab1af.tar.gz nanoengineer-e7ad04cb2877f8cea4b161ee8ae27e37111ab1af.zip |
Partially fixes 2958: "Copying and pasting protein chunks doesn't work."
-rwxr-xr-x | cad/src/model/chunk.py | 3 | ||||
-rw-r--r-- | cad/src/protein/model/Protein.py | 73 |
2 files changed, 74 insertions, 2 deletions
diff --git a/cad/src/model/chunk.py b/cad/src/model/chunk.py index ccc1274de..da4c13225 100755 --- a/cad/src/model/chunk.py +++ b/cad/src/model/chunk.py @@ -271,7 +271,8 @@ class Chunk(NodeWithAtomContents, InvalMixin, save_as_pam = "" # PAM model to use for saving self (not normally set; not set means use save-op params) copyable_attrs = _superclass.copyable_attrs + ('display', 'color', - 'display_as_pam', 'save_as_pam') + 'display_as_pam', 'save_as_pam', + 'protein') # this extends the tuple from Node # (could add _colorfunc, but better to handle it separately in case this # gets used for mmp writing someday. as of 051003 _colorfunc would diff --git a/cad/src/protein/model/Protein.py b/cad/src/protein/model/Protein.py index eade6919a..d61f09df4 100644 --- a/cad/src/protein/model/Protein.py +++ b/cad/src/protein/model/Protein.py @@ -629,7 +629,7 @@ class Protein: def edit(self, win): """ - Edit the protein chunk + Edit the protein chunk. @note: Probably this method should not reside here, since this file is for the actual model. Maybe we'll take care of that when we move to the @@ -637,6 +637,77 @@ class Protein: """ win.commandSequencer.userEnterCommand('EDIT_PROTEIN') return + + def _getCopyOfResidues(self): + """ + Returns a (deep copy) of the residues dict. + @note: NIY + """ + for aa in self.residues.values(): + print aa + return + + # override abstract method of DataMixin + def _copyOfObject(self, copyfunc): + """ + Create and return a copy of protein. + """ + + protein = Protein() + protein.set_chain_id(self.get_chain_id()) + protein.set_pdb_id(self.get_pdb_id()) + protein.set_current_amino_acid_index(self.get_current_amino_acid_index()) + + #@@@ BUG: residues_list, ca_atom_list, and residues aren't copied + # completely since they contain compound objects (i.e. Residues with + # lists, dicts, etc). + # See add_pdb_atom() code to see how residues are created for + # these lists/dicts. Need help from Bruce. --Mark 2008-12-25 + if 1: + protein.residues_list = list(self.residues_list) + protein.ca_atom_list = list(self.ca_atom_list) + protein.residues = dict(self.residues) + else: + # Using copy.deepcopy also fails. Found a reference here: + # http://mail.python.org/pipermail/python-dev/2008-June/080772.html + # which states that it's possible that "residues_list" contains an + # object that cannot be copied (i.e. array.array). + # Evidently the problem was corrected with python 2.4.4. + # I am running Python 2.4. Is it worth upgrading to 2.4.4? + # --Mark 2008-12-25 + + import copy + protein.residues_list = copy.deepcopy(self.residues_list) + protein.ca_atom_list = copy.deepcopy(self.ca_atom_list) + protein.residues = copy.deepcopy(self.residues) + + protein.residues_dl = None # DL gets rebuilt in ProteinChunks.drawchunk_realtime + + print "Protein._copyOfObject(): HERE!" + return protein + + # override abstract method of DataMixin. + # Ask Bruce to review. --Mark 2008-12-25 + def __eq__(self, other): + """ + Compare self with other. + """ + print "Protein.__eq__(): HERE!" + if self.chain_id != other.chain_id: + return False + elif self.pdb_id != other.pdb_id: + return False + elif self.current_aa_idx != other.current_aa_idx: + return False + elif self.residues is not other.residues: # Is this right? + return False + elif self.residues_list is not other.residues_list: # Is this right? + return False + elif self.ca_atom_list is not other.ca_atom_list: # Is this right? + return False + else: + return True + pass pass # end of class Protein |