Skip to content

Commit

Permalink
testing update
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Oct 23, 2024
1 parent 8cda261 commit 3cc8171
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions meteor/sfcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .rsmap import Map


def sf_calc(structure: gemmi.Structure, *, high_resolution_limit: float) -> 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)
Expand All @@ -24,4 +24,4 @@ def pdb_to_calculated_map(pdb_file: Path, *, high_resolution_limit: float) -> Ma
msg = f"could not find file: {pdb_file}"
raise OSError(msg)
structure = gemmi.read_structure(str(pdb_file))
return sf_calc(structure, high_resolution_limit=high_resolution_limit)
return structure_to_calculated_map(structure, high_resolution_limit=high_resolution_limit)
7 changes: 6 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@


@pytest.fixture(scope="session")
def test_data_dir() -> Path:
def data_dir() -> Path:
return Path(__file__).parent.resolve() / "data"


@pytest.fixture(scope="session")
def example_pdb_file(data_dir: Path) -> Path:
return data_dir / "rsEGFP2_dark_no-chromophore.pdb"
42 changes: 41 additions & 1 deletion test/unit/test_sfcalc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
from pathlib import Path

import gemmi
import numpy as np
import pytest
from numpy import testing as npt

def test_sf_calc(test_data_dir: Path): ...
from meteor import sfcalc
from meteor.rsmap import Map
from meteor.testing import single_carbon_structure

RESOLUTION = 1.0
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")
CARBON1_POSITION = (5.0, 5.0, 5.0)


@pytest.fixture
def structure() -> gemmi.Structure:
return single_carbon_structure(CARBON1_POSITION, SPACE_GROUP, UNIT_CELL)


def test_sf_calc(structure: gemmi.Structure) -> None:
calc_map: Map = sfcalc.structure_to_calculated_map(structure, high_resolution_limit=RESOLUTION)
assert calc_map.resolution_limits[1] == RESOLUTION
assert calc_map.spacegroup == SPACE_GROUP
assert calc_map.cell == UNIT_CELL
assert not calc_map.has_uncertainties
assert np.any(calc_map.amplitudes != 0.0)
assert np.any(calc_map.phases != 0.0)


def test_pdb_to_calculated_map(example_pdb_file: Path) -> None:
calc_map: Map = sfcalc.pdb_to_calculated_map(example_pdb_file, high_resolution_limit=RESOLUTION)
npt.assert_allclose(calc_map.resolution_limits[1], RESOLUTION, atol=1e-5)

# CRYST1 51.990 62.910 72.030 90.00 90.00 90.00 P 21 21 21
assert calc_map.spacegroup == gemmi.find_spacegroup_by_name("P 21 21 21")
assert calc_map.cell == gemmi.UnitCell(
a=51.990, b=62.910, c=72.030, alpha=90, beta=90, gamma=90
)

assert np.any(calc_map.amplitudes != 0.0)
assert np.any(calc_map.phases != 0.0)

0 comments on commit 3cc8171

Please sign in to comment.