-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tjlane/diffmap_script-refactor
- Loading branch information
Showing
27 changed files
with
3,214 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/data/scaled-test-data.mtz filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""https://www.ccp4.ac.uk/html/mtzformat.html | ||
https://www.globalphasing.com/buster/wiki/index.cgi?MTZcolumns | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import re | ||
from typing import Final | ||
|
||
OBSERVED_INTENSITY_LABELS: Final[list[str]] = [ | ||
"I", # generic | ||
"IMEAN", # CCP4 | ||
"I-obs", # phenix | ||
] | ||
|
||
OBSERVED_AMPLITUDE_LABELS: Final[list[str]] = [ | ||
"F", # generic | ||
"FP", # CCP4 & GLPh native | ||
r"FPH\d", # CCP4 derivative | ||
"F-obs", # phenix | ||
] | ||
|
||
OBSERVED_UNCERTAINTY_LABELS: Final[list[str]] = [ | ||
"SIGF", # generic | ||
"SIGFP", # CCP4 & GLPh native | ||
r"SIGFPH\d", # CCP4 | ||
] | ||
|
||
COMPUTED_AMPLITUDE_LABELS: Final[list[str]] = ["FC"] | ||
|
||
COMPUTED_PHASE_LABELS: Final[list[str]] = ["PHIC"] | ||
|
||
|
||
class AmbiguousMtzLabelError(ValueError): ... | ||
|
||
|
||
def _infer_mtz_label(labels_to_search: list[str], labels_to_look_for: list[str]) -> str: | ||
# the next line consumes ["FOO", "BAR", "BAZ"] and produces regex strings like "^(FOO|BAR|BAZ)$" | ||
regex = re.compile(f"^({'|'.join(labels_to_look_for)})$") | ||
matches = [regex.match(label) for label in labels_to_search if regex.match(label) is not None] | ||
|
||
if len(matches) == 0: | ||
msg = "cannot infer MTZ column name; " | ||
msg += f"cannot find any of {labels_to_look_for} in {labels_to_search}" | ||
raise AmbiguousMtzLabelError(msg) | ||
if len(matches) > 1: | ||
msg = "cannot infer MTZ column name; " | ||
msg += f">1 instance of {labels_to_look_for} in {labels_to_search}" | ||
raise AmbiguousMtzLabelError(msg) | ||
|
||
[match] = matches | ||
if match is None: | ||
msg = "`None` not filtered during regex matching" | ||
raise RuntimeError(msg) | ||
|
||
return match.group(0) | ||
|
||
|
||
def find_observed_intensity_label(mtz_column_labels: list[str]) -> str: | ||
return _infer_mtz_label(mtz_column_labels, OBSERVED_INTENSITY_LABELS) | ||
|
||
|
||
def find_observed_amplitude_label(mtz_column_labels: list[str]) -> str: | ||
return _infer_mtz_label(mtz_column_labels, OBSERVED_AMPLITUDE_LABELS) | ||
|
||
|
||
def find_observed_uncertainty_label(mtz_column_labels: list[str]) -> str: | ||
return _infer_mtz_label(mtz_column_labels, OBSERVED_UNCERTAINTY_LABELS) | ||
|
||
|
||
def find_computed_amplitude_label(mtz_column_labels: list[str]) -> str: | ||
return _infer_mtz_label(mtz_column_labels, COMPUTED_AMPLITUDE_LABELS) | ||
|
||
|
||
def find_computed_phase_label(mtz_column_labels: list[str]) -> str: | ||
return _infer_mtz_label(mtz_column_labels, COMPUTED_PHASE_LABELS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pathlib import Path | ||
|
||
import gemmi | ||
|
||
from .rsmap import Map | ||
|
||
|
||
def structure_to_calculated_map(structure: gemmi.Structure, *, high_resolution_limit: float) -> Map: | ||
density_map = gemmi.DensityCalculatorX() | ||
density_map.d_min = high_resolution_limit | ||
density_map.grid.setup_from(structure) | ||
for i, _ in enumerate(structure): | ||
density_map.put_model_density_on_grid(structure[i]) | ||
|
||
ccp4_map = gemmi.Ccp4Map() | ||
ccp4_map.grid = density_map.grid | ||
ccp4_map.update_ccp4_header() | ||
|
||
return Map.from_ccp4_map(ccp4_map, high_resolution_limit=high_resolution_limit) | ||
|
||
|
||
def pdb_to_calculated_map(pdb_file: Path, *, high_resolution_limit: float) -> Map: | ||
if not pdb_file.exists(): | ||
msg = f"could not find file: {pdb_file}" | ||
raise OSError(msg) | ||
structure = gemmi.read_structure(str(pdb_file)) | ||
return structure_to_calculated_map(structure, high_resolution_limit=high_resolution_limit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.