Skip to content

Commit

Permalink
Add warn_duplicate_strand_names argument to from_scadnano_file
Browse files Browse the repository at this point in the history
  • Loading branch information
cgevans committed Sep 9, 2022
1 parent 724a4a8 commit a8a0ec2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scadnano/scadnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -4681,7 +4681,8 @@ def __init__(self, *,
strands: List[Strand] = None,
grid: Grid = Grid.none,
helices_view_order: List[int] = None,
geometry: Geometry = None) -> None:
geometry: Geometry = None,
warn_duplicate_strand_names: bool = True) -> None:
"""
:param helices:
List of :any:`Helix`'s; if missing, set based on `strands`.
Expand Down Expand Up @@ -4763,9 +4764,9 @@ def __init__(self, *,
helices_in_group = [self.helices[idx] for idx in helix_idxs_in_group]
_check_helices_grid_legal(group.grid, helices_in_group)

self.__post_init__()
self.__post_init__(warn_duplicate_strand_names=warn_duplicate_strand_names)

def __post_init__(self) -> None:
def __post_init__(self, warn_duplicate_strand_names: bool = True) -> None:
# XXX: exact order of these calls is important
self._ensure_helices_distinct_objects()
self._ensure_strands_distinct_objects()
Expand All @@ -4774,7 +4775,7 @@ def __post_init__(self) -> None:
self._set_helices_min_max_offsets(update=False)
self._ensure_helix_groups_exist()
self._assign_default_helices_view_orders_to_groups()
self._check_legal_design()
self._check_legal_design(warn_duplicate_strand_names=warn_duplicate_strand_names)

if self.automatically_assign_color:
self._assign_colors_to_strands()
Expand Down Expand Up @@ -4861,7 +4862,7 @@ def roll_of_helix(self, helix: Helix) -> float:
return self.groups[helix.group].roll + helix.roll

@staticmethod
def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 support dropped
def from_scadnano_file(filename: str, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
"""
Loads a :any:`Design` from the file with the given name.
Expand All @@ -4870,10 +4871,10 @@ def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 s
"""
with open(filename) as f:
json_str = f.read()
return Design.from_scadnano_json_str(json_str)
return Design.from_scadnano_json_str(json_str, warn_duplicate_strand_names=warn_duplicate_strand_names)

@staticmethod
def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3.6 support dropped
def from_scadnano_json_str(json_str: str, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
"""
Loads a :any:`Design` from the given JSON string.
Expand All @@ -4882,7 +4883,7 @@ def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3
"""
json_map = json.loads(json_str)
try:
design = Design.from_scadnano_json_map(json_map)
design = Design.from_scadnano_json_map(json_map, warn_duplicate_strand_names=warn_duplicate_strand_names)
return design
except KeyError as e:
raise IllegalDesignError(f'I was expecting a JSON key but did not find it: {e}')
Expand Down Expand Up @@ -5075,7 +5076,7 @@ def _helices_and_groups_and_grid_from_json(json_map: Dict) -> Tuple[List[Helix],

@staticmethod
def from_scadnano_json_map(
json_map: dict) -> 'Design': # remove quotes when Py3.6 support dropped
json_map: dict, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
"""
Loads a :any:`Design` from the given JSON object (i.e., Python object obtained by calling
json.loads(json_str) from a string representing contents of a JSON file.
Expand Down Expand Up @@ -5131,6 +5132,7 @@ def from_scadnano_json_map(
grid=grid,
helices_view_order=helices_view_order,
geometry=geometry,
warn_duplicate_strand_names=warn_duplicate_strand_names,
)

def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> Dict[str, Any]:
Expand Down

0 comments on commit a8a0ec2

Please sign in to comment.