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
|
# Copyright 2006-2008 Nanorex, Inc. See LICENSE file for details.
"""
DnaDuplexGenerator.py
@author: Mark Sims
@version: $Id$
@copyright: 2006-2008 Nanorex, Inc. See LICENSE file for details.
History:
Mark 2007-10-18:
- Created. Major rewrite of DnaGenerator.py.
"""
from foundation.Group import Group
from utilities.Log import redmsg, greenmsg
from geometry.VQT import V, Veq
from dna.commands.BuildDuplex.DnaDuplex import B_Dna_PAM3
from command_support.GeneratorBaseClass import GeneratorBaseClass
from utilities.exception_classes import CadBug, PluginBug, UserError
from dna.commands.BuildDuplex.DnaDuplexPropertyManager import DnaDuplexPropertyManager
############################################################################
# DnaDuplexPropertyManager must come BEFORE GeneratorBaseClass in this list
class DnaDuplexGenerator(DnaDuplexPropertyManager, GeneratorBaseClass):
cmd = greenmsg("Build DNA: ")
sponsor_keyword = 'DNA'
prefix = 'DNA-' # used for gensym
# Generators for DNA, nanotubes and graphene have their MT name
# generated (in GeneratorBaseClass) from the prefix.
create_name_from_prefix = True
# pass window arg to constructor rather than use a global, wware 051103
def __init__(self, win):
DnaDuplexPropertyManager.__init__(self)
GeneratorBaseClass.__init__(self, win)
self._random_data = []
# ##################################################
# How to build this kind of structure, along with
# any necessary helper functions.
def gather_parameters(self):
"""
Return the parameters from the property manager UI.
@return: All the parameters:
- numberOfBases
- dnaForm
- basesPerTurn
- endPoint1
- endPoint2
@rtype: tuple
"""
numberOfBases = self.numberOfBasesSpinBox.value()
dnaForm = str(self.conformationComboBox.currentText())
basesPerTurn = self.basesPerTurnDoubleSpinBox.value()
# First endpoint (origin) of DNA duplex
x1 = self.x1SpinBox.value()
y1 = self.y1SpinBox.value()
z1 = self.z1SpinBox.value()
# Second endpoint (direction vector/axis) of DNA duplex.
x2 = self.x2SpinBox.value()
y2 = self.y2SpinBox.value()
z2 = self.z2SpinBox.value()
endPoint1 = V(x1, y1, z1)
endPoint2 = V(x2, y2, z2)
return (numberOfBases,
dnaForm,
basesPerTurn,
endPoint1,
endPoint2)
def build_struct(self, name, params, position):
"""
Build the DNA helix based on parameters in the UI.
@param name: The name to assign the node in the model tree.
@type name: str
@param params: The list of parameters gathered from the PM.
@type params: tuple
@param position: The position in 3d model space at which to
create the DNA strand. This is always 0, 0, 0.
@type position: position
"""
# No error checking in build_struct, do all your error
# checking in gather_parameters
numberOfBases, \
dnaForm, \
basesPerTurn, \
endPoint1, \
endPoint2 = params
if Veq(endPoint1, endPoint2):
raise CadBug("DNA endpoints cannot be the same point.")
if numberOfBases < 1:
msg = redmsg("Cannot to preview/insert a DNA duplex with 0 bases.")
self.MessageGroupBox.insertHtmlMessage(msg, setAsDefault=False)
self.dna = None # Fixes bug 2530. Mark 2007-09-02
return None
if dnaForm == 'B-DNA':
dna = B_Dna_PAM3()
else:
raise PluginBug("Unsupported DNA Form: " + dnaForm)
self.dna = dna # needed for done msg
# Create the model tree group node.
dnaGroup = Group(self.name,
self.win.assy,
self.win.assy.part.topnode)
try:
# Make the DNA duplex. <dnaGroup> will contain three chunks:
# - Strand1
# - Strand2
# - Axis
dna.make(dnaGroup,
numberOfBases,
basesPerTurn,
endPoint1,
endPoint2)
return dnaGroup
except (PluginBug, UserError):
# Why do we need UserError here? Mark 2007-08-28
rawDnaGroup.kill()
raise PluginBug("Internal error while trying to create DNA duplex.")
pass
###################################################
# The done message
#@ THIS SHOULD BE REMOVED. Mark
def done_msg(self):
if not self.dna: # Mark 2007-06-01
return "No DNA added."
return "Done creating a strand of %s." % (self.dna.form)
|