Skip to content

Commit

Permalink
tweak repr param typing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbittrich committed Dec 20, 2024
1 parent 6c3ebe6 commit 9a46576
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file, following t
- Breaking: Renamed geometrical primitive `line` to `tube`
- Breaking: Change multiple geometrical primitive parameters
- Multi-state data model tweaks
- Support for representation-specific parameters (customize presentation visuals)


## [v1.1.0] - 2024-12-09
Expand Down
2 changes: 1 addition & 1 deletion molviewspec/app/api/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ async def repr_params_example() -> MVSResponse:
"""
builder = create_builder()
component = (
builder.download(url=_url_for_mmcif("4hhb")).parse(format="mmcif").model_structure(ref="structure").component()
builder.download(url=_url_for_mmcif("1a23")).parse(format="mmcif").model_structure(ref="structure").component()
)
component.representation(type="cartoon", size_factor=1.5, tubular_helices=True)
component.representation(type="surface", ignore_hydrogens=True).opacity(opacity=0.8)
Expand Down
11 changes: 5 additions & 6 deletions molviewspec/molviewspec/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

from datetime import datetime, timezone
from typing import Any, Dict, Literal, Mapping, Optional, Tuple, Type, TypeVar, Union
from typing import Any, Literal, Mapping, Optional, Tuple, TypeVar, Union
from uuid import uuid4

from pydantic import BaseModel, Field
Expand Down Expand Up @@ -439,26 +439,25 @@ class RepresentationParams(BaseModel):


class CartoonParams(RepresentationParams):
type: Literal["cartoon"] = "cartoon"
size_factor: Optional[float] = Field(description="Scales the corresponding visuals.")
tubular_helices: Optional[bool] = Field(description="Simplify corkscrew helices to tubes.")
# TODO support for variable size, e.g. based on b-factors?


class BallAndStickParams(RepresentationParams):
type: Literal["ball_and_stick"] = "ball_and_stick"
ignore_hydrogens: Optional[bool] = Field(descripton="Controls whether hydrogen atoms are drawn.")
size_factor: Optional[float] = Field(description="Scales the corresponding visuals.")


class SurfaceParams(RepresentationParams):
type: Literal["surface"] = "surface"
ignore_hydrogens: Optional[bool] = Field(descripton="Controls whether hydrogen atoms are drawn.")
size_factor: Optional[float] = Field(description="Scales the corresponding visuals.")


RepresentationTypeParams: Dict[RepresentationTypeT, Type[Union[CartoonParams, BallAndStickParams, SurfaceParams]]] = {
"cartoon": CartoonParams,
"ball_and_stick": BallAndStickParams,
"surface": SurfaceParams,
}
RepresentationTypeParams = {t.__fields__["type"].default: t for t in (CartoonParams, BallAndStickParams, SurfaceParams)}


SchemaT = Literal[
Expand Down

0 comments on commit 9a46576

Please sign in to comment.