Skip to content

Commit

Permalink
Add return type annotations to sails interface functions
Browse files Browse the repository at this point in the history
This commit adds explicit return type annotations to functions in package/src/sails/interface.py. This improves code readability and type checking, ensuring that the returned values are consistent with the expected types.
  • Loading branch information
Dialpuri committed Aug 21, 2024
1 parent 8951206 commit 2ca3d34
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions package/src/sails/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import numpy as np


def read_sf_cif(mtz: Path):
def read_sf_cif(mtz: Path) -> gemmi.Mtz:
"""
:param mtz: Path to the CIF file containing structure factor data.
:return: MTZ file containing the converted structure factor data.
"""
doc = gemmi.cif.read(str(mtz))
rblocks = gemmi.as_refln_blocks(doc)
Expand All @@ -20,7 +19,11 @@ def read_sf_cif(mtz: Path):
return cif2mtz.convert_block_to_mtz(rblocks[0])


def get_sails_map(map: gemmi.Ccp4Map | gemmi.FloatGrid | Path | str):
def get_sails_map(map: gemmi.Ccp4Map | gemmi.FloatGrid | Path | str) -> sails.Grid:
"""
:param map: The input map, which can be of type gemmi.Ccp4Map, gemmi.FloatGrid, Path or str.
:return: The Sails map extracted from the input.
"""
if isinstance(map, gemmi.Ccp4Map):
sails_grid = extract_gemmi_grid(map.grid)
elif isinstance(map, gemmi.FloatGrid):
Expand All @@ -36,7 +39,9 @@ def get_sails_map(map: gemmi.Ccp4Map | gemmi.FloatGrid | Path | str):
return sails_grid


def get_sails_mtz(mtz: gemmi.Mtz | Path | str, f: str, sigf: str, fwt: str, phwt: str):
def get_sails_mtz(
mtz: gemmi.Mtz | Path | str, f: str, sigf: str, fwt: str, phwt: str
) -> sails.MTZ:
"""
:param mtz: Path to an MTZ file, an instance of gemmi.Mtz, or a string representing the path to an MTZ file.
:param f: Column name of the F values in the MTZ file.
Expand Down Expand Up @@ -81,7 +86,7 @@ def get_sails_mtz(mtz: gemmi.Mtz | Path | str, f: str, sigf: str, fwt: str, phwt
return sails_mtz


def get_sails_structure(structure):
def get_sails_structure(structure) -> sails.Structure:
"""
Retrieves the Sails structure from the provided input.
Expand All @@ -104,7 +109,7 @@ def get_sails_structure(structure):
return sails_structure


def extract_gemmi_structure(structure: gemmi.Structure):
def extract_gemmi_structure(structure: gemmi.Structure) -> sails.Structure:
os = sails.Structure()
os.set_cell(
sails.Cell(
Expand Down

0 comments on commit 2ca3d34

Please sign in to comment.