Skip to content
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

Add is_polar() utility for classifying polar space groups #176

Merged
merged 6 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reciprocalspaceship/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
is_centric,
to_structurefactor,
)
from reciprocalspaceship.utils.symop import apply_to_hkl, phase_shift
from reciprocalspaceship.utils.symmetry import apply_to_hkl, is_polar, phase_shift
from reciprocalspaceship.utils.units import angstroms2ev, ev2angstroms
2 changes: 1 addition & 1 deletion reciprocalspaceship/utils/asu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from reciprocalspaceship.decorators import cellify, spacegroupify
from reciprocalspaceship.utils.cell import generate_reciprocal_cell
from reciprocalspaceship.utils.structurefactors import is_absent, is_centric
from reciprocalspaceship.utils.symop import apply_to_hkl, phase_shift
from reciprocalspaceship.utils.symmetry import apply_to_hkl, phase_shift

# fmt: off
ccp4_hkl_asu = [
Expand Down
2 changes: 1 addition & 1 deletion reciprocalspaceship/utils/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_phase_restrictions(H, spacegroup):
list is returned for Miller indices without phase restrictions
"""
from reciprocalspaceship.utils.asu import is_absent, is_centric
from reciprocalspaceship.utils.symop import apply_to_hkl, phase_shift
from reciprocalspaceship.utils.symmetry import apply_to_hkl, phase_shift

friedel_op = gemmi.Op("-x,-y,-z")
# Grabs all the non-identity symops
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np

from reciprocalspaceship.decorators import spacegroupify


def apply_to_hkl(H, op):
"""
Expand Down Expand Up @@ -56,3 +58,23 @@ def phase_shift(H, op):
array of phase shifts
"""
return -2 * np.pi * np.matmul(H, op.tran) / op.DEN


@spacegroupify
def is_polar(spacegroup):
"""
Classify whether spacegroup is polar

Parameters
----------
spacegroup : str, int, gemmi.SpaceGroup
Spacegroup to classify as polar

Returns
-------
bool
Whether the spacegroup is polar
"""
sym_ops = spacegroup.operations().sym_ops
a = np.array([op.rot for op in sym_ops])
return ~(a < 0).any(axis=1).any(axis=0).all()
21 changes: 21 additions & 0 deletions tests/data/gen_sgtbx_is_polar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Generate test data using sgtbx classifications of polar spacegroups
"""

import pandas as pd
from cctbx import sgtbx

# Classify all space group settings
is_polar = []
xhms = []
for sg in sgtbx.space_group_symbol_iterator():
sgtbx_polar = (
sgtbx.space_group(sg).info().number_of_continuous_allowed_origin_shifts() > 0
)
xhm = sg.universal_hermann_mauguin()
is_polar.append(sgtbx_polar)
xhms.append(xhm)

# Write out CSV
df = pd.DataFrame({"xhm": xhms, "is_polar": is_polar})
df.to_csv("sgtbx/sgtbx_polar.csv", index=None)
Loading