1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
# Copyright 2007-2008 Nanorex, Inc. See LICENSE file for details.
"""
DnaSegment.py
@author: Bruce, Ninad
@version: $Id$
@copyright: 2007-2008 Nanorex, Inc. See LICENSE file for details.
Note:
*DnaSegment has the following direct members --
-- DnaAxisChunks,
-- DnaSegmentMarkers
*It can also have following logical contents --
-- DnaStrandChunks (can be accessed using DnaAxisChunk.ladder)
-- DnaStrandMarkers
-- maybe some more?
"""
import foundation.env as env
from dna.model.DnaStrandOrSegment import DnaStrandOrSegment
from dna.model.DnaLadderRailChunk import DnaAxisChunk
from utilities.debug import print_compact_stack, print_compact_traceback
from model.chunk import Chunk
from model.chem import Atom
from model.bonds import Bond
from geometry.VQT import V, norm, vlen
from dna.model.Dna_Constants import getDuplexRiseFromNumberOfBasePairs
from utilities.icon_utilities import imagename_to_pixmap
from utilities.Comparison import same_vals
from utilities.constants import MODEL_PAM3
from dna.model.Dna_Constants import getNumberOfBasePairsFromDuplexLength
_superclass = DnaStrandOrSegment
class DnaSegment(DnaStrandOrSegment):
"""
Model object which represents a Dna Segment inside a Dna Group.
Internally, this is just a specialized Group containing various
subobjects, described in the superclass docstring.
Among its (self's) Group.members are its DnaAxisChunks and its
DnaSegmentMarkers, including exactly one controlling marker.
These occur in undefined order (??). Note that its DnaStrand
atoms are not inside it; they are easily found from the DnaAxisChunks.
"""
# This should be a tuple of classifications that appear in
# files_mmp._GROUP_CLASSIFICATIONS, most general first.
# See comment in class Group for more info. [bruce 080115]
_mmp_group_classifications = ('DnaSegment',)
_duplexRise = None
_basesPerTurn = None
# TODO: undo or copy code for those attrs,
# and updating them when the underlying structure changes.
# But maybe that won't be needed, if they are replaced
# by computing them from the atom geometry as needed.
# [bruce 080227 comment]
autodelete_when_empty = True
# (but only if current command permits that for this class --
# see comment near Group.autodelete_when_empty for more info,
# and implems of Command.keep_empty_group)
iconPath = "ui/modeltree/DnaSegment.png"
hide_iconPath = "ui/modeltree/DnaSegment-hide.png"
copyable_attrs = DnaStrandOrSegment.copyable_attrs + ('_duplexRise',
'_basesPerTurn')
def __init__(self, name, assy, dad, members = (), editCommand = None):
self._duplexRise = 3.18 #Default value.
self._basesPerTurn = 10 #Default value
_superclass.__init__(self,
name,
assy,
dad,
members = members,
editCommand = editCommand)
###BUG: not all callers pass an editCommand. It would be better
# to figure out on demand which editCommand would be appropriate.
# [bruce 080227 comment]
return
def edit(self):
"""
Edit this DnaSegment.
@see: DnaSegment_EditCommand
"""
commandSequencer = self.assy.w.commandSequencer
commandSequencer.userEnterCommand('DNA_SEGMENT')
assert commandSequencer.currentCommand.commandName == 'DNA_SEGMENT'
commandSequencer.currentCommand.editStructure(self)
def draw_highlighted(self, glpane, color):
"""
Draw the strand and axis chunks as highlighted. (Calls the related
methods in the chunk class)
@param: GLPane object
@param color: The highlight color
@see: Chunk.draw_highlighted()
@see: SelectChunks_GraphicsMode.draw_highlightedChunk()
@see: SelectChunks_GraphicsMode._get_objects_to_highlight()
"""
#Note: As of 2008-04-07, there is no 'highlightPolicy' for
#a DnaSegment like in DnaStrand.
#(Not needed but can be easily implemented)
for c in self.members:
if isinstance(c, DnaAxisChunk):
c.draw_highlighted(glpane, color)
def getNumberOfNucleotides(self):
"""
Method provided for conveneince. Returns the number of basepairs
of this dna segment.
@see: PM_DnaSearchResultTable
"""
return self.getNumberOfAxisAtoms()
def getNumberOfBasePairs(self):
#@REVIEW: Is it okay to simply return the number of axis atoms within
#the segment (like done below)? But what if there is a bare axis atom
#within the segment?In any case, the way we compute the numberOfBase
#pairs is again an estimatebased on the duplex length! (i.e. it doesn't
#count the individual base-pairs. BTW, a segment may even have a single
#strand,so the word basepair is not always correct. -- Ninad 2008-04-08
numberOfBasePairs = self.getNumberOfAxisAtoms()
return numberOfBasePairs
def getDefaultToolTipInfo(self):
"""
"""
tooltipString = ""
n = self.getNumberOfAxisAtoms()
tooltipString += "<font color=\"#0000FF\">Parent segment:</font> %s"%(self.name)
tooltipString += "<br><font color=\"#0000FF\">Number of axis atoms: </font> %d"%(n)
return tooltipString
def getNumberOfAxisAtoms(self):
"""
Returns the number of axis atoms present within this dna segment
Returns None if more than one axis chunks are present
This is a temporary method until dna data model is fully working.
@see: DnaSegment_EditCommand.editStructure() where it is used.
"""
#THIS WORKS ONLY WITH DNA DATA MODEL. pre-dna data model implementation
#rfor this method not supported -- Ninad 2008-04-08
numberOfAxisAtoms = 0
for m in self.members:
if isinstance(m, DnaAxisChunk):
numberOfAxisAtoms += len(m.get_baseatoms())
return numberOfAxisAtoms
def isEmpty(self):
"""
Returns True if there are no axis chunks as its members.
"""
for m in self.members:
if isinstance(m, DnaAxisChunk):
return False
return True
#Following methods are likely to be revised in a fully functional dna data
# model. These methods are mainly created to get working many core UI
# operations for Rattlesnake. -- Ninad 2008-02-01
def kill(self):
"""
Overrides superclass method. For a Dnasegment , as of 2008-04-09,
the default implementation is that deleting a segment will delete
the segment along with its logical contents (see bug 2749).
"""
# It is tempting to call self.kill_with_contents , BUT DON'T CALL IT HERE!
# ...as kill_with_contents is used elsewhere (before bug 2749 NFR was
# suggested and it calls self.kill() at the end. So that will create
# infinite recursions.
### TODO: code cleanup/ refactoring to resolve kill_with_content issue
#The following block is copied over from self.kill_with_contents()
#It implements behavior suggested in bug 2749 (deleting a segment will
#delete the segment along with its logical contents )
#See method docsting above on why we shouldn't call that method instead
for member in self.members:
if isinstance(member, DnaAxisChunk):
ladder = member.ladder
try:
#See a note in dna_model.kill_strand_chunks. Should we
#instead call ladder.kill() and thus kill bothstrand
#and axis chunks. ?
ladder.kill_strand_chunks()
except:
print_compact_traceback("bug in killing the ladder chunk")
DnaStrandOrSegment.kill(self)
def kill_with_contents(self):
"""
Kill this Node including the 'logical contents' of the node. i.e.
the contents of the node that are self.members as well as non-members.
Example: A DnaSegment's logical contents are AxisChunks and StrandChunks
Out of these, only AxisChunks are the direct members of the DnaSegment
but the 'StrandChunks are logical contents of it (non-members) .
So, some callers may specifically want to delete self along with its
members and logical contents. These callers should use this method.
The default implementation just calls self.kill()
@see: B{Node.DnaSegment.kill_with_contents} which is overridden here
method.
@see: EditCommand._removeStructure() which calls this Node API method
@see: InsertDna_EditCommand._removeSegments()
@see: dna_model.DnaLadder.kill_strand_chunks() for a comment.
@see: A note in self.kill() about NFR bug 2749
"""
for member in self.members:
if isinstance(member, DnaAxisChunk):
ladder = member.ladder
try:
#See a note in dna_model.kill_strand_chunks. Should we
#instead call ladder.kill() and thus kill bothstrand
#and axis chunks. ?
ladder.kill_strand_chunks()
except:
print_compact_traceback("bug in killing the ladder chunk")
DnaStrandOrSegment.kill_with_contents(self)
def get_DnaSegments_reachable_thru_crossovers(self):
"""
Return a list of DnaSegments that are reachable through the crossovers.
@see: ops_select_Mixin.expandDnaComponentSelection()
@see: ops_select_Mixin.contractDnaComponentSelection()
@see: ops_select_Mixin._expandDnaStrandSelection()
@see:ops_select_Mixin._contractDnaStrandSelection()
@see: ops_select_Mixin._contractDnaSegmentSelection()
@see: DnaStrand.get_DnaStrandChunks_sharing_basepairs()
@see: DnaSegment.get_DnaSegments_reachable_thru_crossovers()
@see: NFR bug 2749 for details.
@see: SelectChunks_GraphicsMode.chunkLeftDouble()
"""
neighbor_segments = []
content_strand_chunks = self.get_content_strand_chunks()
for c in content_strand_chunks:
strand_rail = c.get_ladder_rail()
for atm in strand_rail.neighbor_baseatoms:
if not atm:
continue
axis_neighbor = atm.axis_neighbor()
if not axis_neighbor:
continue
dnaSegment = axis_neighbor.molecule.parent_node_of_class(DnaSegment)
if dnaSegment and dnaSegment is not self:
if dnaSegment not in neighbor_segments:
neighbor_segments.append(dnaSegment)
return neighbor_segments
def get_content_strand_chunks(self):
"""
"""
content_strand_chunks = []
for member in self.members:
if isinstance(member, DnaAxisChunk):
ladder = member.ladder
content_strand_chunks.extend(ladder.strand_chunks())
return content_strand_chunks
def getAllAxisAtoms(self):
allAtomList = []
for member in self.members:
if isinstance(member, DnaAxisChunk):
allAtomList.extend(member.atoms.values())
return allAtomList
def get_all_content_strand_rail_end_baseatoms(self):
"""
Return a list of all strand end baseatoms of the 'strand rails'
contained within this DnaSegment
"""
ladders = self.getDnaLadders()
strand_rails = []
for ladder in ladders:
strand_rails.extend(ladder.strand_rails)
strand_atoms = []
for rail in strand_rails:
strand_atoms.extend(rail.end_baseatoms())
return strand_atoms
def get_all_content_three_prime_ends(self):
"""
Return a list of all the three prime end base atoms, contained within
this DnaSegment
@see:self.get_all_content_strand_rail_end_baseatoms()
@see:self.get_all_content_five_prime_ends()
"""
strand_atoms = self.get_all_content_strand_rail_end_baseatoms()
three_prime_end_atoms = filter(lambda atm: atm.isThreePrimeEndAtom(),
strand_atoms)
return three_prime_end_atoms
def get_all_content_five_prime_ends(self):
"""
Return a list of all the five prime end base atoms, contained within
this DnaSegment
@see:self.get_all_content_strand_rail_end_baseatoms()
@see:self.get_all_content_three_prime_ends()
"""
strand_atoms = self.get_all_content_strand_rail_end_baseatoms()
five_prime_end_atoms = filter(lambda atm: atm.isFivePrimeEndAtom(),
strand_atoms)
return five_prime_end_atoms
def is_PAM3_DnaSegment(self):
"""
Returns true if all the baseatoms in the DnaLadders of this segment
are PAM3 baseatoms (axis or strands) Otherwise returns False
@see: DnaSegment_EditCommand.model_changed()
@see: DnaSegment_EditCommand.isResizableStructure()
"""
is_PAM3 = False
ladderList = self.getDnaLadders()
if len(ladderList) == 0:
is_PAM3 = False
for ladder in ladderList:
pam_model = ladder.pam_model()
if pam_model == MODEL_PAM3:
is_PAM3 = True
else:
is_PAM3 = False
break
return is_PAM3
def getDnaLadders(self):
"""
Returns a list of all DnaLadders within this segment
"""
ladderList = []
for member in self.members:
if isinstance(member, DnaAxisChunk):
ladder = member.ladder
if ladder not in ladderList:
ladderList.append(ladder)
return ladderList
def get_wholechain(self):
"""
Return the 'wholechain' of this DnaSegment. Method provided for
convenience.
Delegates this to self.get_segment_wholechain()
"""
return self.get_segment_wholechain()
def get_segment_wholechain(self):
"""
@return: the 'wholechain' of this DnaSegment
(same as wholechain of each of its DnaAxisChunks),
or None if it doesn't have one
(i.e. if it's empty -- should never happen
if called on a live DnaSegment not modified since
the last dna updater run).
@see: Wholechain
@see: get_strand_wholechain
"""
for member in self.members:
if isinstance(member, DnaAxisChunk):
return member.wholechain
return None
def get_all_content_chunks(self):
"""
Return all the chunks contained within this DnaSegment. This includes
the chunks which are members of the DnaSegment groups, and also the ones
which are not 'members' but are 'logical contents' of this DnaSegment.
I.e. in dna data model, the DnaSegment only has DnaAxisChunks as its
members. But the DnaStrand chunks to which these axis atoms are
connected can be treated as logical contents of the DnaSegment.
This method returns all such chunks (including the direct members).
@see: DnaSegment_GraphicsMode.leftDrag() where this list is used to
drag the whole DnaSegment including the logical contents.
[overrides superclass method]
"""
all_content_chunk_list = []
for member in self.members:
if isinstance(member, DnaAxisChunk):
ladder = member.ladder
all_content_chunk_list.extend(ladder.all_chunks())
#Now search for any strand chunks whose strand atoms are not connected
#to the axis atoms, but still logically belong to the DnaSegment.
#A hairpin loop is an example of such a strand chunk
axis_end_atoms = self.getAxisEndAtoms()
for atm in axis_end_atoms:
if not atm:
continue
strand_atoms = atm.strand_neighbors()
for s_atom in strand_atoms:
rail = s_atom.molecule.get_ladder_rail()
next_rail_base_atoms = rail.neighbor_baseatoms
##print "*** next_rail_base_atoms = ", next_rail_base_atoms
for a in next_rail_base_atoms:
if a is None:
continue
##print "***a.axis_neighbor() = ", a.axis_neighbor()
if not a.axis_neighbor():
if a.molecule not in all_content_chunk_list:
all_content_chunk_list.append(a.molecule)
return all_content_chunk_list
def getAxisEndAtomAtPosition(self, position):
"""
Given a position, return the axis end atom at that position (if it
exists)
"""
axisEndAtom = None
endAtom1, endAtom2 = self.getAxisEndAtoms()
for atm in (endAtom1, endAtom2):
if atm is not None and same_vals(position, atm.posn()):
axisEndAtom = atm
break
return axisEndAtom
def getOtherAxisEndAtom(self, axisEndAtom):
"""
Return the axis end atom at the opposite end
@param axisEndAtom: Axis end atom at a given end. We will use this to
find the axis end atom at the opposite end.
"""
#@TODO:
#1. Optimize this further?
#2. Can a DnaSegment have more than two axis end atoms?
#I guess 'No' . so okay to do the following -- Ninad 2008-03-24
other_axisEndAtom = None
endAtom1, endAtom2 = self.getAxisEndAtoms()
for atm in (endAtom1, endAtom2):
if atm is not None and not atm is axisEndAtom:
other_axisEndAtom = atm
return other_axisEndAtom
def getAxisEndAtoms(self):
"""
THIS RETURNS AXIS END ATOMS ONLY FOR DNA DATA MODEL.
DOESN'T ANYMORE SUPPORT THE PRE DATA MODEL CASE -- 2008-03-24
"""
#pre dna data model
##return self._getAxisEndAtoms_preDataModel()
#post dna data model
return self._getAxisEndAtoms_postDataModel()
def _getAxisEndAtoms_postDataModel(self):
"""
"""
atm1, atm2 = self.get_axis_end_baseatoms()
#Figure out which end point (atom) is which. endPoint1 will be the
#endPoint
#on the left side of the 3D workspace and endPoint2 is the one on
#the 'more right hand side' of the 3D workspace.
#It uses some code from bond_constants.bonded_atoms_summary
# [following code is also duplicated in a method below]
if atm1 and atm2:
atmPosition1 = atm1.posn()
atmPosition2 = atm2.posn()
glpane = self.assy.o
quat = glpane.quat
vec = atmPosition2 - atmPosition1
vec = quat.rot(vec)
if vec[0] < 0.0:
atm1, atm2 = atm2, atm1
elif vec[0] == 0.0 and vec[1] < 0.0:
atm1, atm2 = atm2, atm1
return atm1, atm2
def _getAxisEndAtoms_preDataModel(self):
"""
To be removed post dna data model
"""
endAtomList = []
for member in self.members:
if isinstance(member, Chunk) and member.isAxisChunk():
for atm in member.atoms.itervalues():
if atm.element.symbol == 'Ae3':
endAtomList.append(atm)
if len(endAtomList) == 2:
atm1 = endAtomList[0]
atm2 = endAtomList[1]
#Figure out which end point (atom) is which. endPoint1 will be the
#endPoint
#on the left side of the 3D workspace and endPoint2 is the one on
#the 'more right hand side' of the 3D workspace.
#It uses some code from bond_constants.bonded_atoms_summary
# [following code is also duplicated in a method below]
atmPosition1 = atm1.posn()
atmPosition2 = atm2.posn()
glpane = self.assy.o
quat = glpane.quat
vec = atmPosition2 - atmPosition1
vec = quat.rot(vec)
if vec[0] < 0.0:
atm1, atm2 = atm2, atm1
return atm1, atm2
elif len(endAtomList) > 2:
print_compact_stack("bug: The axis chunk has more than 2 'Ae3' atoms: ")
else:
return None, None
return endAtomList
def getStrandEndAtomsFor(self, strand):
"""
TODO: To be revised/ removed post dna data model.
returns the strand atoms connected to the ends of the
axis atoms. The list could return 1 or 2 strand atoms. The caller
should check for the correctness.
@see: DnaStrand_EditCommand.updateHandlePositions()
"""
assert strand.dad is self
strandNeighbors = []
strandEndAtomList = []
for axisEndAtom in self.getAxisEndAtoms():
strandNeighbors = axisEndAtom.strand_neighbors()
strand_end_atom_found = False
for atm in strandNeighbors:
if atm.molecule is strand:
strandEndAtomList.append(atm)
strand_end_atom_found = True
break
if not strand_end_atom_found:
strandEndAtomList.append(None)
return strandEndAtomList
def getStrandEndPointsFor(self, strand):
"""
TODO: To be revised/ removed post dna data model.
@see: DnaStrand_EditCommand.updateHandlePositions()
@see: self.getStrandEndAtomsFor()
"""
strandEndAtoms = self.getStrandEndAtomsFor(strand)
strandEndPoints = []
for atm in strandEndAtoms:
if atm is not None:
strandEndPoints.append(atm.posn())
else:
strandEndPoints.append(None)
return strandEndPoints
def getAxisEndPoints(self):
"""
Derives and returns the two axis end points based on the atom positions
of the segment.
@note: this method definition doesn't fully make sense, since a segment
can be a ring.
@return: a list containing the two endPoints of the Axis.
@rtype: list
"""
endpoint1, endpoint2 = self._getAxisEndPoints_preDataModel()
if endpoint1 is None:
return self._getAxisEndPoints_postDataModel()
else:
return (endpoint1, endpoint2)
def _getAxisEndPoints_preDataModel(self):
#Temporary implementation that uses chunk class to distinguish an
#axis chunk from an ordinary chunk. This method can be revised after
#Full dna data model implementation -- Ninad 2008-01-21
# (Note, this seems to assume that the axis is a single chunk.
# This may often be true pre-data-model, but I'm not sure --
# certainly it's not enforced, AFAIK. This will print_compact_stack
# when more than one axis chunk is in a segment. [bruce 080212 comment])
endPointList = []
for atm in self.getAxisEndAtoms():
if atm is not None:
endPointList.append(atm.posn())
else:
endPointList.append(None)
if len(endPointList) == 2:
atmPosition1 = endPointList[0]
atmPosition2 = endPointList[1]
return atmPosition1, atmPosition2
return None, None
def _getAxisEndPoints_postDataModel(self): # bruce 080212
atom1, atom2 = self.get_axis_end_baseatoms()
if atom1 is None:
return None, None
atmPosition1, atmPosition2 = [atom.posn() for atom in (atom1, atom2)]
# following code is duplicated from a method above
glpane = self.assy.o
quat = glpane.quat
vec = atmPosition2 - atmPosition1
vec = quat.rot(vec)
if vec[0] < 0.0:
atmPosition1, atmPosition2 = atmPosition2, atmPosition1
return atmPosition1, atmPosition2
def get_axis_end_baseatoms(self): # bruce 080212
"""
Return a sequence of length 2 of atoms or None:
for a chain: its two end baseatoms (arbitrary order);
for a ring: None, None.
"""
# this implem only works in the dna data model
# find an arbitrary DnaAxisChunk among our members
# (not the best way in theory, once we have proper attrs set,
# namely our controlling marker)
member = None
for member in self.members:
if isinstance(member, DnaAxisChunk):
break
if not isinstance(member, DnaAxisChunk):
# no DnaAxisChunk members (should not happen)
return None, None
end_baseatoms = member.wholechain.end_baseatoms()
if not end_baseatoms:
# ring
return None, None
# chain
return end_baseatoms
def getAxisVector(self, atomAtVectorOrigin = None):
"""
Returns the unit axis vector of the segment (vector between two axis
end points)
"""
endPoint1, endPoint2 = self.getAxisEndPoints()
if endPoint1 is None or endPoint2 is None:
return V(0, 0, 0)
if atomAtVectorOrigin is not None:
#If atomAtVectorOrigin is specified, we will return a vector that
#starts at this atom and ends at endPoint1 or endPoint2 .
#Which endPoint to choose will be dicided by the distance between
#atomAtVectorOrigin and the respective endPoints. (will choose the
#frthest endPoint
origin = atomAtVectorOrigin.posn()
if vlen(endPoint2 - origin ) > vlen(endPoint1 - origin):
return norm(endPoint2 - endPoint1)
else:
return norm(endPoint1 - endPoint2)
return norm(endPoint2 - endPoint1)
def setProps(self, props):
"""
Sets some properties. These will be used while editing the structure.
(but if the structure is read from an mmp file, this won't work. As a
fall back, it returns some constant values)
@see: InsertDna_EditCommand.createStructure which calls this method.
@see: self.getProps, DnaSegment_EditCommand.editStructure
"""
duplexRise, basesPerTurn = props
self.setDuplexRise(duplexRise)
self.setBasesPerTurn(basesPerTurn)
def getProps(self):
"""
Returns some properties such as duplexRise. This is a temporary
@see: DnaSegment_EditCommand.editStructure where it is used.
@see: DnaSegment_PropertyManager.getParameters
@see: DnaSegmentEditCommand._createStructure
"""
props = (self.getBasesPerTurn(),
self.getDuplexRise() )
return props
def getDuplexRise(self):
return self._duplexRise
def setDuplexRise(self, duplexRise):
if duplexRise:
self._duplexRise = duplexRise
def getBasesPerTurn(self):
return self._basesPerTurn
def setBasesPerTurn(self, basesPerTurn):
if basesPerTurn:
self._basesPerTurn = basesPerTurn
def setColor(self, color):
"""
Public method provided for convenience. Delegates the color
assignment task to self.setStrandColor()
@see: DnaOrCntPropertyManager._changeStructureColor()
"""
self.setSegmentColor(color)
def setSegmentColor(self, color):
"""
Set the color of the all the axis chunks within this DNA segment group
to the given color
@see: self.setColor()
"""
m = None
for m in self.members:
if isinstance(m, DnaAxisChunk):
m.setcolor(color)
def getColor(self):
"""
Returns the color of an arbitrary internal axis chunk. It iterates
over the axisChunk list until it gets a valid color. If no color
is assigned to any of its axis chunks, it simply returns None.
"""
color = None
for m in self.members:
if isinstance(m, DnaAxisChunk):
color = m.color
if color is not None:
break
return color
def writemmp_other_info_opengroup(self, mapping):
"""
"""
#This method is copied over from NanotubeSegment class .
#Retaining comments by Bruce in that method. Method added to write
#bases per turn and related info to the mmp file. -- Ninad 2008-06-26
#bruce 080507 refactoring (split this out of Group.writemmp)
# (I think the following condition is always true, but I didn't
# prove this just now, so I left in the test for now.)
encoded_classifications = self._encoded_classifications()
if encoded_classifications == "DnaSegment":
# Write the parameters into an info record so we can read and
#restore them in the next session.
mapping.write("info opengroup dnaSegment-parameters = %0.3f, %0.3f \n" % (self.getBasesPerTurn(),
self.getDuplexRise()))
pass
return
def readmmp_info_opengroup_setitem( self, key, val, interp ):
"""
[extends superclass method]
"""
#bruce 080507 refactoring (split this out of the superclass method)
if key == ['dnaSegment-parameters']:
# val includes all the parameters, separated by commas.
basesPerTurn, duplexRise = val.split(",")
self.setBasesPerTurn(float(basesPerTurn))
self.setDuplexRise(float(duplexRise))
else:
_superclass.readmmp_info_opengroup_setitem( self, key, val, interp)
return
def _computeDuplexRise(self):
"""
Compute the duplex rise
@see: self.getProps
TODO: THIS METHOD IS DEPRECATED AS OF 2008-03-05 AND IS SCHEDULED
FOR REMOVAL. IT MIGHT HAVE BUGS.
"""
duplexRise = None
numberOfAxisAtoms = self.getNumberOfAxisAtoms()
if numberOfAxisAtoms:
numberOfBasePairs = numberOfAxisAtoms
duplexLength = self.getSegmentLength()
duplexRise = getDuplexRiseFromNumberOfBasePairs(numberOfBasePairs,
duplexLength)
return duplexRise
def getSegmentLength(self):
"""
Returns the length of the segment.
"""
endPoint1, endPoint2 = self.getAxisEndPoints()
if endPoint1 is None:
#bruce 080212 mitigate a bug
env.history.orangemsg("Warning: segment length can't be determined")
return 10
segmentLength = vlen(endPoint1 - endPoint2)
return segmentLength
def isAncestorOf(self, obj):
"""
Checks whether the object <obj> is contained within the DnaSegment
Example: If the object is an Atom, it checks whether the
atom's chunk is a member of this DnaSegment (chunk.dad is self)
It also considers all the logical contents of the DnaSegment to determine
whetehr self is an ancestor. (returns True even for logical contents)
@see: self.get_all_content_chunks()
@see: DnaSegment_GraphicsMode.leftDrag
@Note: when dna data model is fully implemented, the code below that is
flaged 'pre-Dna data model' and thus the method should be revised
"""
#start of POST DNA DATA MODEL IMPLEMENTATION ===========================
c = None
if isinstance(obj, Atom):
c = obj.molecule
elif isinstance(obj, Bond):
chunk1 = obj.atom1.molecule
chunk2 = obj.atom1.molecule
if chunk1 is chunk2:
c = chunk1
elif isinstance(obj, Chunk):
c = obj
if c is not None:
if c in self.get_all_content_chunks():
return True
#end of POST DNA DATA MODEL IMPLEMENTATION =============================
#start of PRE- DNA DATA MODEL IMPLEMENTATION ===========================
#NOTE: Need to check if the isinstance checks are acceptable (apparently
#don't add any import cycle) Also this method needs to be revised
#after we completely switch to dna data model.
if isinstance(obj, Atom):
chunk = obj.molecule
if chunk.dad is self:
return True
else:
ladder = getattr(chunk, 'ladder', None)
if ladder:
pass
elif isinstance(obj, Bond):
chunk1 = obj.atom1.molecule
chunk2 = obj.atom1.molecule
if (chunk1.dad is self) or (chunk2.dad is self):
return True
elif isinstance(obj, Chunk):
if obj.dad is self:
return True
#end of PRE- DNA DATA MODEL IMPLEMENTATION ===========================
return False
def node_icon(self, display_prefs):
del display_prefs # unused
if self.all_content_is_hidden():
return imagename_to_pixmap( self.hide_iconPath)
else:
return imagename_to_pixmap( self.iconPath)
# end
|