-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Representation params #41
base: master
Are you sure you want to change the base?
Conversation
@dsehnal Is this the right direction? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is what I had in mind.
molviewspec/molviewspec/nodes.py
Outdated
class CartoonParams(RepresentationParams): | ||
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding type: Literal["cartoon"] = "cartoon"
here would help with the issue you mentioned, where you would not be able to mix properties for different kinds (although, for that, might have to add class Config: extra = "forbid"
to the pydantic model).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked into this and updated make_params
to raise an exception if there are "unconsumed" properties (a9b471b). Doesn't affect other examples and, at least, gives users an error rather than silently ignoring potential mistakes.
molviewspec/molviewspec/nodes.py
Outdated
RepresentationTypeParams: Dict[RepresentationTypeT, Type[Union[CartoonParams, BallAndStickParams, SurfaceParams]]] = { | ||
"cartoon": CartoonParams, | ||
"ball_and_stick": BallAndStickParams, | ||
"surface": SurfaceParams, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the dictionary approach. Maybe can do this too so the type
doesn't have to be repeated:
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) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, moved to that impl with 9a46576.
Description
Basic support for representation-specific parameters.
Any other params that we want to support at this point?
Should we add some validation? Things like
component.representation(type="cartoon", ignore_hydrogens=True)
can be done, butignore_hydrogens
won't be propagated to the final JSON.Actions
[Unreleased]
section ofCHANGELOG.md
app/api/examples.py