Skip to content
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

How do hold "parent" references? #1

Open
JonStargaryen opened this issue Apr 3, 2023 · 3 comments
Open

How do hold "parent" references? #1

JonStargaryen opened this issue Apr 3, 2023 · 3 comments

Comments

@JonStargaryen
Copy link
Member

Let's say you want to create multiple representations from a structure:

builder = Root()
structure = builder.download(url=f"https://www.ebi.ac.uk/pdbe/entry-files/download/{id.lower()}_updated.cif")\
    .parse(format="mmcif")\
    .structure()
structure.component(selector="protein")\
    .representation(type="cartoon", color="white")
structure.component(selector="ligand")\
    .representation(type="ball-and-stick")

How would this be done without holding structure in a variable? Are we fine with this? Should component() be components() and take all requested components are argument? Generics + parent()/leave()/exit() method?

@dsehnal
Copy link
Member

dsehnal commented Apr 17, 2023

Brainstrorming:

from view_builder import nodes as ns

builder = Root()
structure = builder.download(url=f"https://www.ebi.ac.uk/pdbe/entry-files/download/{id.lower()}_updated.cif")\
    .parse(format="mmcif")\
    .structure()

def download(url: str, is_binary: bool = False, children: list[ParseNode | ...]): 
    return DownloadNode(url=url, is_binary=is_binary, children=children)

def parse(format: Literal["mmcif"], *children: Any): 
    return DownloadNode(url=url, is_binary=is_binary, children=children)

tree = download(
    url="test",
    children=[parse(
        format="mmcif",
        children=[structure(
            kind="assembly",

        )]
    )]
)


(structure
    .component(selector="protein")
    .representation(type="cartoon", color="white"))
(structure
    .component(selector="ligand")
    .representation(type="ball-and-stick"))




    # .children(lambda n: [
    #     n.component(selector="protein").representation(type="cartoon", color="white"),
    #     n.component(selector="ligand").representation(type="cartoon", color="white"),
    # ])
    # .children(
    #     ns.component(selector="protein").representation(type="cartoon", color="white"),
    #     ns.component(selector="ligand").representation(type="cartoon", color="white"),
    # )


class None:
    allowed_children_kinds = ["download", "..."]

    def _validate_child(self, child: BuilderBase):
        if child.kind not in self.allowed_children_kinds:
            raise ValueError(...)


def many(cb: Callable[[T], list[Builder]]) -> Root:
    pass

def many(*children: list[Builder]) -> Root:
    pass


structure.component(selector="protein")\
    .representation(type="cartoon", color="white")
structure.component(selector="ligand")\
    .representation(type="ball-and-stick")

@JonStargaryen
Copy link
Member Author

The outcome of the discussion was: No immediate changes, but revisit in the future, right?

@dsehnal
Copy link
Member

dsehnal commented Apr 17, 2023

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants