def test_exp_P1():
    """Create a mock experiments object."""
    exp = Experiment()
    exp_dict = {
        "__id__": "crystal",
        "real_space_a": [1.0, 0.0, 0.0],
        "real_space_b": [0.0, 1.0, 0.0],
        "real_space_c": [0.0, 0.0, 1.0],
        "space_group_hall_symbol": " P 1",
    }
    crystal = Crystal.from_dict(exp_dict)
    exp.crystal = crystal
    return exp
Beispiel #2
0
def create_datastructures_for_target_mtz(experiments, mtz_file):
    """Read a merged mtz file and extract miller indices, intensities and
    variances."""
    m = mtz.object(mtz_file)
    ind = m.extract_miller_indices()
    cols = m.columns()
    col_dict = {c.label(): c for c in cols}
    r_t = flex.reflection_table()
    if "I" in col_dict:  # nice and simple
        r_t["miller_index"] = ind
        r_t["intensity"] = col_dict["I"].extract_values().as_double()
        r_t["variance"] = flex.pow2(col_dict["SIGI"].extract_values().as_double())
    elif "IMEAN" in col_dict:  # nice and simple
        r_t["miller_index"] = ind
        r_t["intensity"] = col_dict["IMEAN"].extract_values().as_double()
        r_t["variance"] = flex.pow2(col_dict["SIGIMEAN"].extract_values().as_double())
    elif "I(+)" in col_dict:  # need to combine I+ and I- together into target Ih
        if col_dict["I(+)"].n_valid_values() == 0:  # use I(-)
            r_t["miller_index"] = ind
            r_t["intensity"] = col_dict["I(-)"].extract_values().as_double()
            r_t["variance"] = flex.pow2(
                col_dict["SIGI(-)"].extract_values().as_double()
            )
        elif col_dict["I(-)"].n_valid_values() == 0:  # use I(+)
            r_t["miller_index"] = ind
            r_t["intensity"] = col_dict["I(+)"].extract_values().as_double()
            r_t["variance"] = flex.pow2(
                col_dict["SIGI(+)"].extract_values().as_double()
            )
        else:  # Combine both - add together then use Ih table to calculate I and sigma
            r_tplus = flex.reflection_table()
            r_tminus = flex.reflection_table()
            r_tplus["miller_index"] = ind
            r_tplus["intensity"] = col_dict["I(+)"].extract_values().as_double()
            r_tplus["variance"] = flex.pow2(
                col_dict["SIGI(+)"].extract_values().as_double()
            )
            r_tminus["miller_index"] = ind
            r_tminus["intensity"] = col_dict["I(-)"].extract_values().as_double()
            r_tminus["variance"] = flex.pow2(
                col_dict["SIGI(-)"].extract_values().as_double()
            )
            r_tplus.extend(r_tminus)
            r_tplus.set_flags(
                flex.bool(r_tplus.size(), False), r_tplus.flags.bad_for_scaling
            )
            r_tplus = r_tplus.select(r_tplus["variance"] != 0.0)
            Ih_table = create_Ih_table(
                [experiments[0]], [r_tplus], anomalous=True
            ).blocked_data_list[0]
            r_t["intensity"] = Ih_table.Ih_values
            inv_var = (
                Ih_table.weights * Ih_table.h_index_matrix
            ) * Ih_table.h_expand_matrix
            r_t["variance"] = 1.0 / inv_var
            r_t["miller_index"] = Ih_table.miller_index
    else:
        assert 0, """Unrecognised intensities in mtz file."""
    r_t = r_t.select(r_t["variance"] > 0.0)
    r_t["d"] = (
        miller.set(
            crystal_symmetry=crystal.symmetry(
                space_group=m.space_group(), unit_cell=m.crystals()[0].unit_cell()
            ),
            indices=r_t["miller_index"],
        )
        .d_spacings()
        .data()
    )
    r_t.set_flags(flex.bool(r_t.size(), True), r_t.flags.integrated)

    exp = Experiment()
    exp.crystal = deepcopy(experiments[0].crystal)
    exp.identifier = str(uuid.uuid4())
    r_t.experiment_identifiers()[len(experiments)] = exp.identifier
    r_t["id"] = flex.int(r_t.size(), len(experiments))

    # create a new KB scaling model for the target and set as scaled to fix scale
    # for targeted scaling.
    params = Mock()
    params.KB.decay_correction.return_value = False
    exp.scaling_model = KBScalingModel.from_data(params, [], [])
    exp.scaling_model.set_scaling_model_as_scaled()  # Set as scaled to fix scale.

    return exp, r_t
Beispiel #3
0
    import pylab as plt
    plt.imshow(img, vmax=100)
    plt.title("Ground truth image")
    plt.show()
SIM.D.raw_pixels *= 0

P = phil_scope.extract()
E = Experiment()

if "G" in args.perturb:
    P.init.G = SIM.D.spot_scale * 10
else:
    P.init.G = SIM.D.spot_scale

if "crystal" in args.perturb:
    E.crystal = C2
else:
    E.crystal = C

if "Nabc" in args.perturb:
    P.init.Nabc = 20, 20, 20
else:
    P.init.Nabc = SIM.crystal.Ncells_abc

if "detz_shift" in args.perturb:
    P.init.detz_shift = 1
else:
    P.init.detz_shift = 0

if "eta" in args.perturb:
    P.init.eta_abc = [0.12, 0.13, 0.14]
from __future__ import division

from simtbx.diffBragg import utils
from simtbx.nanoBragg.tst_nanoBragg_basic import pdb_lines
from simtbx.diffBragg.phil import hopper_phil, philz
from libtbx.phil import parse
from simtbx.nanoBragg import tst_nanoBragg_multipanel
from dxtbx.model import Experiment
import numpy as np

# make a dummie experiment
expt = Experiment()
expt.detector = tst_nanoBragg_multipanel.whole_det
expt.beam = tst_nanoBragg_multipanel.beam
expt.crystal = tst_nanoBragg_multipanel.cryst

# write a dummie PDB file
PDB = "1234.pdb"
o = open(PDB, "w")
o.write(pdb_lines)
o.close()

# Create a miller array from on-disk PDB file
F = utils.get_complex_fcalc_from_pdb(PDB,
    wavelength=expt.beam.get_wavelength(),
    dmin=2, dmax=20, k_sol=0.2, b_sol=20)
F = F.as_amplitude_array()
Fmap = {h: amp for h,amp in zip(F.indices(), F.data())}

# Create a sim_data class instance as would be done for hopper_utils.refine for example
phil_scope = parse(hopper_phil+philz)
Beispiel #5
0
for i in range(N):
    iset = isets[i]
    path = iset.get_path(0)
    d = df2_filt0.query("imgpaths=='%s'" % path)
    if has_master:
        master_index = iset.indices()[0]
        d = d.query("master_indices==%d" % master_index)
    if len(d) != 1:
        continue
    A = d.Amats.values[0]
    #break
    C = deepcopy(crystals[i])
    #C.set_A(A)
    Ex = Experiment()
    Ex.crystal = C
    Ex.imageset = iset
    Ex.beam = beams[i]
    Ex.detector = D
    El2.append(Ex)

    Rsel = R.select(R['id']==i)
    nref = len(Rsel)
    Rsel['id'] = flex.int(nref, new_id)
    R2.extend(Rsel)
    new_id += 1
    print (new_id)

el_file = "%s.expt" % args.tag
R_file = "%s.refl" % args.tag
El2.as_file(el_file)