Skip to content

Commit

Permalink
refactor: revamp AuxData
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexmmaldonado committed May 19, 2024
1 parent 688bb95 commit 3ea3fad
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions subpex/configs/subpex/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from collections.abc import MutableSequence
from typing import Any

Check warning on line 1 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L1

Added line #L1 was not covered by tests

from collections.abc import Callable, MutableSequence

Check warning on line 3 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L3

Added line #L3 was not covered by tests

import MDAnalysis as mda
from pydantic import BaseModel, Field, computed_field

Check warning on line 6 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L5-L6

Added lines #L5 - L6 were not covered by tests

from ...fop.compute import get_fop_volume_convenience
from ...pocket.compute import (

Check warning on line 9 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L8-L9

Added lines #L8 - L9 were not covered by tests
get_pocket_jaccard_convenience,
get_pocket_rmsd_convenience,
get_pocket_rog_convenience,
)
from ...protein.compute import get_backbone_rmsd

Check warning on line 14 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L14

Added line #L14 was not covered by tests


class AuxData(BaseModel):
label: str
Expand All @@ -18,6 +29,27 @@ class AuxData(BaseModel):
"""File extension if saving."""
write: bool = Field(default=False)
"""Flag to write file containing data."""
compute_function: Callable[[Any], float | MutableSequence[float]] = Field(

Check warning on line 32 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L27-L32

Added lines #L27 - L32 were not covered by tests
default=None, exclude=True
)
"""Function to compute the descriptor value."""

Check warning on line 35 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L35

Added line #L35 was not covered by tests

def compute_frame( # type: ignore

Check warning on line 37 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L37

Added line #L37 was not covered by tests
self,
atoms_frame: mda.AtomGroup,
subpex_config,
atoms_ref: mda.AtomGroup | None = None,
*args: Any,
**kwargs: Any
) -> None:
"""Will use `compute_function` to compute and then append the value to
`values`.
"""
if self.compute_function is not None:
result = self.compute_function(

Check warning on line 49 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L48-L49

Added lines #L48 - L49 were not covered by tests
atoms_frame, subpex_config, atoms_ref, *args, **kwargs
)
self.values.append(result)

Check warning on line 52 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L52

Added line #L52 was not covered by tests

@computed_field # type: ignore[misc]
@property
Expand All @@ -29,14 +61,11 @@ class DataConfig(BaseModel):

aux: MutableSequence[AuxData] = Field(

Check warning on line 62 in subpex/configs/subpex/data.py

View check run for this annotation

Codecov / codecov/patch

subpex/configs/subpex/data.py#L62

Added line #L62 was not covered by tests
default_factory=lambda: [
AuxData(label="progress_coord"),
AuxData(label="pocket_volume"),
AuxData(label="pocket_rog"),
AuxData(label="pocket_rmsd"),
AuxData(label="pocket_fop"),
AuxData(label="pocket_jd"),
AuxData(label="backbone_rmsd"),
AuxData(label="composite"),
AuxData(label="pocket_volume", compute_function=get_fop_volume_convenience),
AuxData(label="pocket_rog", compute_function=get_pocket_rog_convenience),
AuxData(label="pocket_rmsd", compute_function=get_pocket_rmsd_convenience),
AuxData(label="pocket_jd", compute_function=get_pocket_jaccard_convenience),
AuxData(label="backbone_rmsd", compute_function=get_backbone_rmsd),
]
)

Expand Down

0 comments on commit 3ea3fad

Please sign in to comment.