Skip to content

Commit

Permalink
changed PointEnum to an is_lattice boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
grinner committed May 15, 2018
1 parent c250c9d commit 6d52e65
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cadnano/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def setViewNames(self, view_name_list: List[str], do_clear: bool = False):
def createNucleicAcidPart( self,
use_undostack: bool = True,
grid_type: EnumType = GridEnum.NONE,
point_type: EnumType = PointEnum.Z_ONLY
is_lattice: bool = True
) -> NucleicAcidPart:
"""Create and store a new DnaPart and instance, and return the instance.
Expand All @@ -756,7 +756,7 @@ def createNucleicAcidPart( self,
Returns
new :obj:`NucleicAcidPart`
"""
dna_part = NucleicAcidPart(document=self, grid_type=grid_type, point_type=point_type)
dna_part = NucleicAcidPart(document=self, grid_type=grid_type, is_lattice=is_lattice)
self._addPart(dna_part, use_undostack=use_undostack)
return dna_part
# end def
Expand Down
6 changes: 5 additions & 1 deletion cadnano/fileio/c25decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ def decode(document: DocT, obj: dict, emit_signals: bool = True):
if lattice_type == LatticeEnum.HONEYCOMB:
doLattice = HoneycombDnaPart.latticeCoordToModelXY
isEven = HoneycombDnaPart.isEvenParity
grid_type = GridEnum.HONEYCOMB
elif lattice_type == LatticeEnum.SQUARE:
doLattice = SquareDnaPart.latticeCoordToModelXY
isEven = SquareDnaPart.isEvenParity
grid_type = GridEnum.SQUARE
else:
raise TypeError("Lattice type not recognized")
part = document.createNucleicAcidPart(use_undostack=False)
part = document.createNucleicAcidPart( use_undostack=False,
is_lattice=True,
grid_type=grid_type)
part.setActive(True)
setBatch(True)
# POPULATE VIRTUAL HELICES
Expand Down
4 changes: 3 additions & 1 deletion cadnano/fileio/v2decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def decode(document: DocT, obj: dict, emit_signals: bool = True):
isEven = SquareDnaPart.isEvenParity
else:
raise TypeError("Lattice type not recognized")
part = document.createNucleicAcidPart(grid_type=grid_type, use_undostack=False)
part = document.createNucleicAcidPart( grid_type=grid_type,
is_lattice=True,
use_undostack=False)
part.setActive(True)
document.setGridType(grid_type)
# document.setSliceOrGridViewVisible(OrthoViewEnum.SLICE)
Expand Down
12 changes: 10 additions & 2 deletions cadnano/fileio/v3decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,23 @@ def decodePart( document: DocT,
grid_type:
emit_signals:
"""
part = document.createNucleicAcidPart(use_undostack=False, grid_type=grid_type)
if ( part_dict.get('point_type') == PointEnum.ARBITRARY or
not part_dict.get('is_lattice', True) ):
is_lattice = False
else:
is_lattice = True

part = document.createNucleicAcidPart( use_undostack=False,
is_lattice=is_lattice,
grid_type=grid_type)
part.setActive(True)

vh_id_list = part_dict.get('vh_list')
vh_props = part_dict.get('virtual_helices')
origins = part_dict.get('origins')
keys = list(vh_props.keys())

if part_dict.get('point_type') == PointEnum.ARBITRARY:
if not is_lattice:
# TODO add code to deserialize parts
pass
else:
Expand Down
6 changes: 3 additions & 3 deletions cadnano/fileio/v3encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def encodePart(part: PartT) -> dict:
# iterate through virtualhelix list
group_props = part.getModelProperties().copy()

if group_props.get('point_type') == PointEnum.ARBITRARY:
if not group_props.get('is_lattice', True):
# TODO add code to encode Parts with ARBITRARY point configurations
pass
else:
Expand Down Expand Up @@ -96,7 +96,7 @@ def reEmitPart(part: PartT):
# iterate through virtualhelix list
group_props = part.getModelProperties().copy()

if group_props.get('point_type') == PointEnum.ARBITRARY:
if not group_props.get('is_lattice', True):
# TODO add code to encode Parts with ARBITRARY point configurations
pass
else:
Expand Down Expand Up @@ -175,7 +175,7 @@ def encodePartList(part_instance: ObjectInstance, vh_group_list: List[int]) -> d
group_props = part.getModelProperties().copy()
assert('grid_type' in group_props)

if group_props.get('point_type') == PointEnum.ARBITRARY:
if not group_props.get('is_lattice', True):
# TODO add code to encode Parts with ARBITRARY point configurations
pass
else:
Expand Down
8 changes: 4 additions & 4 deletions cadnano/part/nucleicacidpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def __init__(self, *args, **kwargs):
uuid: str
do_copy
grid_type
point_type
is_lattice
'''
super(NucleicAcidPart, self).__init__(*args, **kwargs)
do_copy: bool = kwargs.get('do_copy', False)
grid_type: EnumType = kwargs.get('grid_type', GridEnum.NONE)
point_type: EnumType = kwargs.get('point_type', PointEnum.Z_ONLY)
is_lattice: EnumType = kwargs.get('is_lattice', True)

if do_copy:
return
Expand Down Expand Up @@ -216,7 +216,7 @@ def __init__(self, *args, **kwargs):
gps['neighbor_active_angle'] = ''
gps['grid_type'] = grid_type
gps['virtual_helix_order'] = []
gps['point_type'] = point_type
gps['is_lattice'] = is_lattice

############################
# Begin low level attributes
Expand Down Expand Up @@ -2394,7 +2394,7 @@ def isZEditable(self) -> bool:
Returns:
``True`` or ``False``
"""
return self._group_properties['point_type'] == PointEnum.Z_ONLY
return self._group_properties['is_lattice'] == True
# end def

def getVirtualHelicesInArea(self, rect: RectT) -> Set[int]:
Expand Down
3 changes: 3 additions & 0 deletions cadnano/proxies/cnenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class PartEnum(IntEnum):
class PointEnum(IntEnum):
"""For serializing virtual helices as only pointing in the Z direction
or pointing in arbitrary directions.
NOTE: This exists for legacy part importing of lattice designs when moving
towards the v3 file convention
"""
Z_ONLY = 0
ARBITRARY = 1
Expand Down
2 changes: 1 addition & 1 deletion cadnano/tests/nucleicacidparttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def create3Helix(doc, direction, length):
part = doc.createNucleicAcidPart()
part = doc.createNucleicAcidPart(is_lattice=True)
assert len(part.getidNums()) == 0
radius = part.radius()
origin_pt00 = (0, 0, 0)
Expand Down
17 changes: 12 additions & 5 deletions cadnano/views/cnmainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,20 +961,27 @@ def actionCreateNucleicAcidPartHoneycomb(self) -> NucleicAcidPartT:
# TODO[NF]: Docstring
return self.actionCreateNucleicAcidPart(
grid_type=GridEnum.HONEYCOMB,
point_type=PointEnum.Z_ONLY
is_lattice=True
)

def actionCreateNucleicAcidPartSquare(self) -> NucleicAcidPartT:
# TODO[NF]: Docstring
return self.actionCreateNucleicAcidPart(
grid_type=GridEnum.SQUARE,
point_type=PointEnum.Z_ONLY
is_lattice=True
)

def actionCreateNucleicAcidPart(self,
grid_type: EnumType,
point_type: EnumType = PointEnum.ARBITRARY) -> NucleicAcidPartT:
# TODO[NF]: Docstring
is_lattice: bool = False) -> NucleicAcidPartT:
'''
Args:
grid_type:
is_lattice: defaults to False, aka freeform
Returns:
the part created
'''
if ONLY_ONE:
if len(self._document.children()) is not 0:
if self.promptSaveDialog() is SAVE_DIALOG_OPTIONS['CANCEL']:
Expand All @@ -983,7 +990,7 @@ def actionCreateNucleicAcidPart(self,
doc = self._document
part = doc.createNucleicAcidPart( use_undostack=True,
grid_type=grid_type,
point_type=point_type)
is_lattice=is_lattice)
active_part = doc.activePart()
if active_part is not None:
active_part.setActive(False)
Expand Down
2 changes: 1 addition & 1 deletion misc/examples/04_threejs/vhelixpythree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
],
"source": [
"doc = Document()\n",
"part = doc.createNucleicAcidPart()\n",
"part = doc.createNucleicAcidPart(is_lattice=False)\n",
"vh_points = [\n",
" (2, 0, 0, (0, 0, 1.)),\n",
" (-2, 0, 0, (0, 0, 1.)),\n",
Expand Down

0 comments on commit 6d52e65

Please sign in to comment.