Skip to content

Commit

Permalink
refactor and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
dnanto committed Aug 17, 2024
1 parent 43519ca commit 2dc55d2
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 109 deletions.
13 changes: 6 additions & 7 deletions py/src/democapsid/__main__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#!/usr/bin/env python3

import sys
from functools import partial

from .cli import parse_args
from .democapsid import calc_ckm, calc_ckv, calc_ico, calc_lattice, cylinderize

args = parse_args(sys.argv[1:])
h, k, H, K, s, R, t, c = args.h, args.k, args.H, args.K, args.symmetry, args.radius, args.tile, args.sphericity
h, k, H, K, a, R, t, s, m = (getattr(args, key) for key in "h,k,H,K,a,R,t,s,m".split(","))

ckp = (h, k, H, K)
lattice = calc_lattice(t, R)
ckv = calc_ckv(h, k, H, K, lattice[0])
ckm = calc_ckm(ckv, lattice)

if args.mode == "ico":
inflater = spherize if h == H and k == K else partial(cylinderize, s=s)
meshes = calc_ico(ckv, ckm, s, c, inflater)
if m == "ico":
meshes = calc_ico(ckp, lattice, a, s)
elif m == "tri":
meshes = calc_ckm(ckp, lattice)

print("x", "y", "z", "face", "polygon", "point", sep="\t")
for i, mesh in enumerate(meshes[1:], start=1):
Expand Down
12 changes: 6 additions & 6 deletions py/src/democapsid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def parse_args(argv):
for ele in "hkHK":
parser.add_argument(ele, default=1, type=int, help=f"the {ele} lattice parameter")
choices = (5, 3, 2)
parser.add_argument("-symmetry", default=choices[0], type=int, help=f"the axial symmetry: {choices}")
parser.add_argument("-radius", default=1, type=int, help="the hexagonal lattice unit radius")
parser.add_argument("-a", "-axis", default=choices[0], type=int, help=f"the axial symmetry: {choices}")
parser.add_argument("-R", "-radius", default=1, type=int, help="the hexagonal lattice unit circumradius")
choices = ("hex", "trihex", "snubhex", "rhombitrihex")
choices = (*choices, *("dual" + ele for ele in choices))
parser.add_argument("-tile", default=choices[0], help="the hexagonal lattice unit tile")
parser.add_argument("-sphericity", default=0, type=float, help="the sphericity value")
choices = ("ico", "net")
parser.add_argument("-mode", default=choices[0], help="the sphericity value")
parser.add_argument("-t", "-tile", default=choices[0], help="the hexagonal lattice unit tile")
parser.add_argument("-s", "-sphericity", default=0, type=float, help="the sphericity value")
choices = ("ico", "tri")
parser.add_argument("-m", "-mode", default=choices[0], help="the render mode")
return parser.parse_args(argv)
Loading

0 comments on commit 2dc55d2

Please sign in to comment.