-
Notifications
You must be signed in to change notification settings - Fork 4
fix issue 17 #115
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
fix issue 17 #115
Changes from all commits
f36ab63
6e3010d
e8cbcb4
91c5d96
73e4098
f1de0e7
6b76fd7
c37069b
4e92fe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| # https://github.com/diff-use/sampleworks/issues/122 | ||
| class Experiment: | ||
| protein: str | ||
| occ_a: float | ||
| altloc_occupancies: dict[str, float] | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| model: str | ||
| method: str | None | ||
| scaler: str | ||
|
|
@@ -27,6 +27,12 @@ class Experiment: | |
| base_map_path: Path | None = None | ||
| error: Exception | None = None | ||
|
|
||
| @property | ||
| def occ_key(self) -> tuple[tuple[str, float], ...]: | ||
| """Hashable key for caches. Zero-occupancy altlocs are omitted for | ||
| consistency with occupancy_to_str / extract_protein_and_occupancy.""" | ||
| return tuple(sorted((k, v) for k, v in self.altloc_occupancies.items() if abs(v) > 1e-6)) | ||
|
|
||
|
|
||
| class ExperimentList(list[Experiment]): | ||
| def summarize(self): | ||
|
|
@@ -59,23 +65,27 @@ def __post_init__(self): | |
| def is_selection_valid(self, selection: str) -> bool: | ||
| return selection is not None and selection.strip() != "" | ||
|
|
||
| def get_base_map_path_for_occupancy(self, altloc_occupancies: dict[str, float]) -> Path | None: | ||
| """Return the base-map path for the given altloc occupancies, or ``None``. | ||
|
|
||
| def get_base_map_path_for_occupancy(self, occupancy_a: float) -> Path | None: | ||
| occ_str = occupancy_to_str(occupancy_a, use_6b8x_format=self.protein == "6b8x") | ||
| Parameters | ||
| ---------- | ||
| altloc_occupancies : dict[str, float] | ||
| Mapping of altloc labels to occupancy values, | ||
| e.g. ``{"A": 0.5, "B": 0.5}`` or ``{"A": 0.5, "B": 0.3, "C": 0.2}``. | ||
|
marcuscollins marked this conversation as resolved.
|
||
| """ | ||
| try: | ||
| occ_str = occupancy_to_str(**altloc_occupancies) | ||
| except ValueError as e: | ||
| logger.warning( | ||
| f"Cannot determine occupancy string for {self.protein} with occupancies" | ||
| f" {altloc_occupancies}: {e}" | ||
| ) | ||
| return None | ||
| map_path = self.base_map_dir / self.map_pattern.format(occ_str=occ_str) | ||
| if map_path.exists(): | ||
| return map_path | ||
|
|
||
| # TODO: this is a kluge we should work to remove @kchrispens | ||
| alt_patterns = [] | ||
| if self.protein == "6b8x": | ||
| alt_patterns.append(f"6b8x_{occupancy_to_str(occupancy_a)}_1.74A.ccp4") | ||
|
|
||
| for alt in alt_patterns: | ||
| alt_path = self.base_map_dir / alt | ||
| if alt_path.exists(): | ||
| return alt_path | ||
|
|
||
| logger.warning(f"Base map for protein {self.protein} ({map_path}) NOT FOUND") | ||
| return None | ||
|
|
||
|
|
@@ -90,24 +100,32 @@ def load_map( | |
|
|
||
| return xmap | ||
|
|
||
| def get_reference_structure_path(self, occupancy_a: float) -> Path | None: | ||
| def get_reference_structure_path(self, altloc_occupancies: dict[str, float]) -> Path | None: | ||
| """Return the reference-structure path for the given altloc occupancies, or ``None``. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| altloc_occupancies : dict[str, float] | ||
| Mapping of altloc labels to occupancy values, | ||
| e.g. ``{"A": 0.5, "B": 0.5}`` or ``{"A": 0.5, "B": 0.3, "C": 0.2}``. | ||
| """ | ||
| if not self.structure_pattern: | ||
| return None | ||
|
|
||
| occ_str = occupancy_to_str(occupancy_a, use_6b8x_format=self.protein == "6b8x") | ||
| try: | ||
| occ_str = occupancy_to_str(**altloc_occupancies) | ||
| except ValueError as e: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when does this happen? Can we prevent it with input validation?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this happens when the altlocs have negative or >1 occupancy
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where input validation can really help. Maybe make an issue to add this feature. |
||
| logger.warning( | ||
| f"Cannot determine occupancy string for {self.protein} with occupancies" | ||
| f" {altloc_occupancies}: {e}" | ||
| ) | ||
| return None | ||
| structure_path = self.base_map_dir / self.structure_pattern.format(occ_str=occ_str) | ||
| if structure_path.exists(): | ||
| return structure_path | ||
|
|
||
| # Try shifted version for 6b8x | ||
| if self.protein == "6b8x": | ||
| _pattern = self.structure_pattern.format(occ_str=occ_str) | ||
| shifted_path = self.base_map_dir / _pattern.replace(".cif", "_shifted.cif") | ||
| if shifted_path.exists(): | ||
| return shifted_path | ||
|
|
||
| logger.warning( | ||
| f"Reference structure for {self.protein} with occ {occupancy_a} " | ||
| f"Reference structure for {self.protein} with occupancies {altloc_occupancies} " | ||
| f"not found: {structure_path}" | ||
| ) | ||
| return None | ||
|
|
||
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.
Is there a reason not to use itertools.product? I used it to facilitate possible future parallelization with joblib.