Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
dnanto committed Aug 16, 2024
1 parent afcd4da commit 43519ca
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
paper/paper.html
paper/paper.log
paper/paper.pdf
/py/src/democapsid.egg-info
156 changes: 78 additions & 78 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,37 @@

cff-version: 1.2.0
title: >-
democapsid
message: 'If you use this software, please cite it as below.'
democapsid
message: "If you use this software, please cite it as below."
type: software
authors:
- given-names: Daniel
family-names: Negrón
email: [email protected]
affiliation: George Mason University
orcid: 'https://orcid.org/0000-0002-6123-2441'
identifiers:
- type: doi
value: 10.1101/2020.12.02.408252
description: The bioRxiv preprint of the paper.
repository-code: 'https://github.com/dnanto/democapsid'
url: 'https://github.com/dnanto/democapsid/capsid.html'
abstract: >-
This work implements Caspar-Klug Theory to
generate high-quality, vectorized capsid cartoons
in the browser and is the first online tool that
provides comprehensive style customization,
geometry, and SVG export of icosahedra and nets
with different lattice structures.
keywords:
- virus
- capsid
- caspar-klug
- moody
- icosahedron
- prolate
- oblate
- elongated
- lattice
- 2D
- 3D
- svg
- biology
- graphics
- render
- projection
- perspective
- publication
- figure
- demoscene
license: MIT
preferred-citation:
type: article
authors:
- given-names: Daniel
family-names: Negrón
email: [email protected]
affiliation: George Mason University
orcid: 'https://orcid.org/0000-0002-6123-2441'
doi: 10.1101/2020.12.02.408252
journal: bioRxiv
abstract: >-
orcid: "https://orcid.org/0000-0002-6123-2441"
identifiers:
- type: doi
value: 10.1101/2020.12.02.408252
description: The bioRxiv preprint of the paper.
repository-code: "https://github.com/dnanto/democapsid"
url: "https://github.com/dnanto/democapsid/capsid.html"
abstract: >-
This work implements Caspar-Klug Theory to
generate high-quality, vectorized capsid cartoons
in the browser and is the first online tool that
provides comprehensive style customization,
geometry, and SVG export of icosahedra and nets
with different lattice structures.
Motivation Few online services exist for rendering
high-quality viral capsid figures compatible with
common productivity software to develop effective
infographics in the field of virology.
Results The capsid.js library renders class I viral
capsids within an online application that
parameterizes style options, perspectives, and
lattice patterns with SVG export.
Availability This project is actively developed on
GitHub (https://github.com/dnanto/capsid),
distributed under the MIT License, hosted on GitHub
Pages, and runs on modern browsers
(https://dnanto.github.io/capsid/capsid.html).
Supplementary information Supplementary data are
available on GitHub.
month: 12
title: >-
Vectorized Capsid Rendering in the Browser with
Capsid.js
year: 2021
keywords:
keywords:
- virus
- capsid
- caspar-klug
- moody
- icosahedron
- prolate
- oblate
- elongated
- elongated
- lattice
- 2D
- 3D
Expand All @@ -110,4 +45,69 @@ preferred-citation:
- perspective
- publication
- figure
- demoscene
- demoscene
license: MIT
preferred-citation:
type: article
authors:
- given-names: Daniel
family-names: Negrón
email: [email protected]
affiliation: George Mason University
orcid: "https://orcid.org/0000-0002-6123-2441"
doi: 10.1101/2020.12.02.408252
journal: bioRxiv
abstract: >-
This work implements Caspar-Klug Theory to
generate high-quality, vectorized capsid cartoons
in the browser and is the first online tool that
provides comprehensive style customization,
geometry, and SVG export of icosahedra and nets
with different lattice structures.
Motivation Few online services exist for rendering
high-quality viral capsid figures compatible with
common productivity software to develop effective
infographics in the field of virology.
Results The capsid.js library renders class I viral
capsids within an online application that
parameterizes style options, perspectives, and
lattice patterns with SVG export.
Availability This project is actively developed on
GitHub (https://github.com/dnanto/capsid),
distributed under the MIT License, hosted on GitHub
Pages, and runs on modern browsers
(https://dnanto.github.io/capsid/capsid.html).
Supplementary information Supplementary data are
available on GitHub.
month: 12
title: >-
Vectorized Capsid Rendering in the Browser with
Capsid.js
year: 2021
keywords:
- 2D
- 3D
- biology
- capsid
- caspar-klug
- demoscene
- elongated
- figure
- graphics
- icosahedron
- lattice
- oblate
- perspective
- projection
- prolate
- publication
- render
- svg
- virology
- virus
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [ ] comments/documentation
- [ ] python package
- [ ] R package
- [ ] Blender addo
3 changes: 0 additions & 3 deletions democapsid/README.md

This file was deleted.

1 change: 0 additions & 1 deletion democapsid/src/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions env.yml

This file was deleted.

21 changes: 21 additions & 0 deletions py/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 - 2024, Daniel Antonio Negrón (dnanto/remaindeer)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions py/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==========
democapsid
==========


Calculate meshes for icosahedral virus capsids.
2 changes: 1 addition & 1 deletion democapsid/pyproject.toml → py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [
maintainers = [
{ name="Daniel Antonio Negrón", email="[email protected]" },
]
description = "This package includes methods to calculate the coordinates of viral capsids."
description = "Calculate meshes for icosahedral virus capsids."
readme = "README.md"
license = {text = "MIT License"}
requires-python = ">=3.9.11"
Expand Down
7 changes: 7 additions & 0 deletions py/src/democapsid/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python3

"""Top-level package for democapsid."""

__author__ = """Daniel Antonio Negrón"""
__email__ = '[email protected]'
__version__ = '0.0.1'
24 changes: 24 additions & 0 deletions py/src/democapsid/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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

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)

print("x", "y", "z", "face", "polygon", "point", sep="\t")
for i, mesh in enumerate(meshes[1:], start=1):
for j, polygon in enumerate(mesh, start=1):
for k, point in enumerate(polygon[0], start=1):
print(*point, i, j, k, sep="\t")
21 changes: 21 additions & 0 deletions py/src/democapsid/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

def parse_args(argv):
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
parser = ArgumentParser(
prog="democapsid",
formatter_class=ArgumentDefaultsHelpFormatter,
description="Calculate meshes for icosahedral virus capsids."
)
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")
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")
return parser.parse_args(argv)
70 changes: 2 additions & 68 deletions democapsid/src/democapsid.py → py/src/democapsid/democapsid.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#!/usr/bin/env python3

import sys
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from itertools import chain
from functools import partial
from itertools import chain

import numpy as np

try:
import bpy
except ImportError:
pass


SQRT2 = np.sqrt(2)
SQRT3 = np.sqrt(3)
SQRT5 = np.sqrt(5)
PHI = (1 + SQRT5) / 2


ICO_CONFIG = (
(),
(),
Expand Down Expand Up @@ -561,63 +555,3 @@ def calc_ico(ckv, ckm, s, c, inflater):
M = np.transpose(np.apply_along_axis(roro, 1, coors[v_idx,], t=i * (2 * np.pi) / s)) @ A
meshes.append([([inflater(M @ point, coors, c) for point in vertices], edges) for vertices, edges in ckm[t_idx]])
return meshes


def parse_args(argv):
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
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")
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")
return parser.parse_args(argv)


def main(argv):
args = parse_args(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

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)
else:
meshes = ckm

if "bpy" in sys.modules:
for obj in bpy.data.objects:
bpy.data.objects.remove(obj, do_unlink=True)

for i, mesh in enumerate(meshes[1:], start=1):
collection = bpy.data.collections.new(f"face-{i}")
bpy.context.scene.collection.children.link(collection)
for j, polygon in enumerate(mesh, start=1):
mesh = bpy.data.meshes.new(name=f"polygon_msh[{i},{j}]")
mesh.from_pydata(*polygon, [])
mesh.validate(verbose=True)
obj = bpy.data.objects.new(f"polygon_obj-[{i},{j}]", mesh)
collection.objects.link(obj)
else:
print("x", "y", "z", "face", "polygon", "point", sep="\t")
for i, mesh in enumerate(meshes[1:], start=1):
for j, polygon in enumerate(mesh, start=1):
for k, point in enumerate(polygon[0], start=1):
print(*point, i, j, k, sep="\t")

return 0


if __name__ == "__main__":
if "bpy" in sys.modules:
main(["capsid", "1", "1", "1", "2", "-symmetry", "5", "-sphericity", "0"])
else:
sys.exit(main(sys.argv))

0 comments on commit 43519ca

Please sign in to comment.