-
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.
- Loading branch information
tjlane
committed
Aug 25, 2024
1 parent
6f6b0bf
commit aecf5e0
Showing
2 changed files
with
84 additions
and
103 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,82 @@ | ||
|
||
import gemmi | ||
import numpy as np | ||
|
||
from meteor.utils import compute_coefficients_from_map | ||
|
||
|
||
def generate_single_carbon_density( | ||
carbon_position: tuple[float, float, float], | ||
space_group: gemmi.SpaceGroup, | ||
unit_cell: gemmi.UnitCell, | ||
d_min: float, | ||
) -> gemmi.FloatGrid: | ||
model = gemmi.Model("single_atom") | ||
chain = gemmi.Chain("A") | ||
|
||
residue = gemmi.Residue() | ||
residue.name = "X" | ||
residue.seqid = gemmi.SeqId("1") | ||
|
||
atom = gemmi.Atom() | ||
atom.name = "C" | ||
atom.element = gemmi.Element("C") | ||
atom.pos = gemmi.Position(*carbon_position) | ||
|
||
residue.add_atom(atom) | ||
chain.add_residue(residue) | ||
model.add_chain(chain) | ||
|
||
structure = gemmi.Structure() | ||
structure.add_model(model) | ||
structure.cell = unit_cell | ||
structure.spacegroup_hm = space_group.hm | ||
|
||
density_map = gemmi.DensityCalculatorX() | ||
density_map.d_min = d_min | ||
density_map.grid.setup_from(structure) | ||
density_map.put_model_density_on_grid(structure[0]) | ||
|
||
return density_map.grid | ||
|
||
|
||
def displaced_single_atom_difference_map_coefficients( | ||
*, | ||
noise_sigma: float, | ||
) -> rs.DataSet: | ||
unit_cell = gemmi.UnitCell(a=10.0, b=10.0, c=10.0, alpha=90, beta=90, gamma=90) | ||
space_group = gemmi.find_spacegroup_by_name("P1") | ||
d_min = 1.0 | ||
|
||
carbon_position1 = (5.0, 5.0, 5.0) | ||
carbon_position2 = (5.1, 5.0, 5.0) | ||
|
||
density1 = generate_single_carbon_density(carbon_position1, space_group, unit_cell, d_min) | ||
density2 = generate_single_carbon_density(carbon_position2, space_group, unit_cell, d_min) | ||
|
||
ccp4_map = gemmi.Ccp4Map() | ||
grid_values = ( | ||
np.array(density2) - np.array(density1) + noise_sigma * np.random.randn(*density2.shape) | ||
) | ||
ccp4_map.grid = gemmi.FloatGrid(grid_values.astype(np.float32), unit_cell, space_group) | ||
ccp4_map.update_ccp4_header() | ||
|
||
difference_map_coefficients = compute_coefficients_from_map( | ||
ccp4_map=ccp4_map, | ||
high_resolution_limit=d_min, | ||
amplitude_label="DF", | ||
phase_label="PHIC", | ||
) | ||
assert (difference_map_coefficients.max() > 0.0).any() | ||
|
||
return difference_map_coefficients | ||
|
||
|
||
@pytest.fixture | ||
def noise_free_map() -> rs.DataSet: | ||
return displaced_single_atom_difference_map_coefficients(noise_sigma=0.0) | ||
|
||
|
||
@pytest.fixture | ||
def noisy_map() -> rs.DataSet: | ||
return displaced_single_atom_difference_map_coefficients(noise_sigma=0.03) | ||
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