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

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

allow per-helix-group geometry #306

Open dave-doty opened 1 month ago

dave-doty commented 1 month ago

See https://github.com/UC-Davis-molecular-computing/scadnano/issues/993

In the Python package this just means adding a field HelixGroup.geometry and updating the methods HelixGroup.to_json_serializable and HelixGroup.from_scadnano_json_map to write/read it if necessary.

dave-doty commented 1 month ago

Release notes

HelixGroups custom geometry

See also https://github.com/UC-Davis-molecular-computing/scadnano/issues/993#issuecomment-2365320437.

There is a new optional field HelixGroup.geometry, which overrides the Geometry parameters of the Design.geometry field. For instance, the following code:

import scadnano as sc

def create_design() -> sc.Design:
    group0 = sc.HelixGroup(grid=sc.square)
    group1 = sc.HelixGroup(grid=sc.square, 
                           # NOTE: here's the custom geometry for helix 1
                           geometry=sc.Geometry(bases_per_turn=18),
                           position=sc.Position3D(0, 3, 0))
    groups = {"group 0": group0, "group 1": group1}
    helices = [sc.Helix(idx=idx, max_offset=40, group=group) for idx, group in
               [(0, "group 0"), (1, "group 1")]]
    design = sc.Design(helices=helices, groups=groups, strands=[])
    design.draw_strand(0, 0).move(40)
    design.draw_strand(0, 40).move(-40)
    design.draw_strand(1, 0).move(40)
    design.draw_strand(1, 40).move(-40)

    return design

if __name__ == '__main__':
    d = create_design()
    d.write_scadnano_file(directory='output_designs')

produces this design with helix 0 having 10.5 base pairs per turn, and helix 1 having 18 base pairs per turn:

image