UC-Davis-molecular-computing / scadnano-python-package

Python scripting library for generating designs readable by scadnano.
https://scadnano.org
MIT License
13 stars 7 forks source link

fix oxView export exception with Loopouts #297

Closed dave-doty closed 4 months ago

dave-doty commented 4 months ago

The following design

240210 zigzag growth.sc.txt

raises an exception when executing

import scadnano as sc
design = sc.Design.from_scadnano_file('240210 zigzag growth.sc')
design.write_oxview_file()

This is the error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[3], line 4
      1 import scadnano as sc
      3 design = sc.Design.from_scadnano_file('240210 zigzag growth.sc')
----> 4 design.write_oxview_file()

File C:\Dropbox\git\scadnano-python-package\scadnano\scadnano.py:7877, in Design.write_oxview_file(self, directory, filename, warn_duplicate_strand_names, use_strand_colors)
   7862 def write_oxview_file(self, directory: str = '.', filename: Optional[str] = None,
   7863                       warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> None:
   7864     """Writes an oxView file rerpesenting this design.
   7865 
   7866     :param directory:
   (...)
   7875         of the strand.
   7876     """
-> 7877     oxvsystem = self.to_oxview_format(warn_duplicate_strand_names=warn_duplicate_strand_names,
   7878                                       use_strand_colors=use_strand_colors)
   7879     write_file_same_name_as_running_python_script(json.dumps(oxvsystem), 'oxview', directory, filename)

File C:\Dropbox\git\scadnano-python-package\scadnano\scadnano.py:7772, in Design.to_oxview_format(self, warn_duplicate_strand_names, use_strand_colors)
   7770 import datetime
   7771 self._check_legal_design(warn_duplicate_strand_names)
-> 7772 system = _convert_design_to_oxdna_system(self)
   7774 oxview_strands: List[Dict[str, Any]] = []
   7775 nuc_count = 0

File C:\Dropbox\git\scadnano-python-package\scadnano\scadnano.py:9145, in _convert_design_to_oxdna_system(design)
   9141 elif isinstance(domain, Loopout):
   9142     # we place the loopout nucleotides at temporary nonsense positions and orientations
   9143     # these will be updated later, for now we just need the base
   9144     for _ in range(domain.length):
-> 9145         base = seq[i]
   9146         center = _OxdnaVector()
   9147         normal = _OxdnaVector(0, -1, 0)

IndexError: string index out of range

One clue is that the loop variable _ is unused, and each iteration of the loop is accessing the same symbol seq[i] of the domain's sequence. So it might be that the fix is to replace lines 9144 and 9145 with

for j in range(domain.length):
    base = seq[j]