Skip to content
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
8 changes: 8 additions & 0 deletions abismal/command_line/parser/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,13 @@
}
),

(
(
"--enable-index-ambiguation",
),{
"help": "Randomize the indexing solution by a random twinning operator.",
"action": "store_true",
}
),

)
45 changes: 45 additions & 0 deletions abismal/io/ambiguation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from abismal.symmetry import Op
from reciprocalspaceship.decorators import spacegroupify,cellify
import gemmi
import numpy as np

class Ambiguator():
def __init__(self, ops):
self.ops = [Op(op) for op in ops]

@classmethod
@spacegroupify
@cellify
def from_symmetry(cls, cell, spacegroup):
reindexing_ops = ["x,y,z"]
ops = gemmi.find_twin_laws(cell, spacegroup, 3.0, False)
reindexing_ops = reindexing_ops + [op.triplet() for op in ops]
return cls(reindexing_ops)

def ambiguate(self, hkl):
op = np.random.choice(self.ops)
hkl = op(hkl)
return hkl

def __call__(self, X, Y):
(
asu_id,
hkl_in,
resolution,
wavelength,
metadata,
iobs,
sigiobs,
) = X
hkl = self.ambiguate(hkl_in)
X = (
asu_id,
hkl,
resolution,
wavelength,
metadata,
iobs,
sigiobs,
)
return (X, Y)

9 changes: 8 additions & 1 deletion abismal/io/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, inputs, dmin, cell=None, spacegroup=None,
num_cpus=None, separate=False, wavelength=None, ray_log_level="ERROR",
test_fraction=0., separate_friedel_mates=False, cell_tol=None, isigi_cutoff=None,
shuffle_buffer_size=0, batch_size=100, steps_per_epoch=None, validation_steps=None,
epochs=30,
epochs=30, ambiguate=False
):
if separate_friedel_mates and separate:
raise ValueError("Cannot combine --separate-friedel-mates and --separate")
Expand All @@ -64,6 +64,7 @@ def __init__(self, inputs, dmin, cell=None, spacegroup=None,
self.steps_per_epoch = steps_per_epoch
self.validation_steps = validation_steps
self.epochs = epochs
self.ambiguate = ambiguate

def get_config(self):
conf = {
Expand All @@ -84,6 +85,7 @@ def get_config(self):
'steps_per_epoch' : self.steps_per_epoch,
'validation_steps' : self.validation_steps,
'epochs' : self.epochs,
'ambiguate' : self.ambiguate,
}
return conf

Expand Down Expand Up @@ -114,6 +116,7 @@ def from_parser(cls, parser):
steps_per_epoch = parser.steps_per_epoch,
validation_steps = parser.validation_steps,
epochs = parser.epochs,
ambiguate = parser.enable_index_ambiguation,
)

@property
Expand Down Expand Up @@ -222,6 +225,10 @@ def get_dataset(self):
if self.separate_friedel_mates:
self.num_asus = 2

if self.ambiguate:
from abismal.io.ambiguation import Ambiguator
amb = Ambiguator.from_symmetry(self.cell, self.spacegroup)
data = data.map(amb)
return data

@property
Expand Down
Loading