Skip to content

Commit

Permalink
Propagate unindexed as separate experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Oct 23, 2023
1 parent f387377 commit 9b2d4d2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/dials/algorithms/refinement/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def rmsds_for_experiment(self, exp):
"""calculate unweighted RMSDs for the selected experiment."""

self.update_matches()
sel = self._matches.get_selection_for_experiment_identifier(exp)
sel = self._matches.get_selection_for_experiment_identifier(exp.identifier)
n = sel.count(True)
if n == 0:
return None
Expand Down
15 changes: 14 additions & 1 deletion src/dials/command_line/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def _index_experiments(
):
if log_text:
logger.info(log_text)
reflections["original_id"] = copy.deepcopy(reflections["id"])
idxr = indexer.Indexer.from_parameters(
reflections,
experiments,
Expand All @@ -117,8 +118,20 @@ def _index_experiments(
)
idxr.index()
idx_refl = copy.deepcopy(idxr.refined_reflections)
n_unindex = len(experiments)
idxr.unindexed_reflections["id"] = idxr.unindexed_reflections["original_id"]
for i, expt in enumerate(experiments):
idxr.unindexed_reflections.experiment_identifiers()[i] = expt.identifier
for id_ in sorted(set(idx_refl["id"]), reverse=True):
identifier = idx_refl.experiment_identifiers()[id_]
del idx_refl.experiment_identifiers()[id_]
idx_refl.experiment_identifiers()[id_ + n_unindex] = identifier

idx_refl["id"] += n_unindex
idx_refl.extend(idxr.unindexed_reflections)
return idxr.refined_experiments, idx_refl
del idx_refl["original_id"]
experiments.extend(idxr.refined_experiments)
return experiments, idx_refl


def index(experiments, reflections, params):
Expand Down
33 changes: 30 additions & 3 deletions src/dials/command_line/refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,12 @@ def run_dials_refine(experiments, reflections, params):
table_rows = {}
for (el, refl, refiner, _), ids in zip(refinement_results, disjoint_sets):
header, rows = refiner.calc_exp_rmsd_table()
for new_id, orig_id in enumerate(ids):
experiments[orig_id] = el[new_id]
rows[new_id][0] = str(orig_id)
table_rows[orig_id] = rows[new_id]
table_headers.append(header)

reflections = flex.reflection_table.concat([i[1] for i in refinement_results])

experiments = ExperimentList([experiments[i] for i in range(len(experiments))])
Expand Down Expand Up @@ -603,13 +608,35 @@ def run(args=None, phil=working_phil):
logger.info("The following parameters have been modified:\n")
logger.info(diff_phil)

if not all(experiments.identifiers()):
from dials.util.multi_dataset_handling import generate_experiment_identifiers

generate_experiment_identifiers(experiments)
for i, expt in enumerate(experiments):
reflections.experiment_identifiers()[i] = expt.identifier

experiments_to_refine = ExperimentList([e for e in experiments if e.crystal])
experiments = ExperimentList([e for e in experiments if not e.crystal])
reflections_to_refine = reflections.select_on_experiment_identifiers(
experiments_to_refine.identifiers()
)
reflections_to_refine.reset_ids()
reflections = reflections.select_on_experiment_identifiers(
experiments.identifiers()
)

# Run refinement
try:
experiments, reflections, refiner, history = run_dials_refine(
experiments, reflections, params
)
(
experiments_to_refine,
reflections_to_refine,
refiner,
history,
) = run_dials_refine(experiments_to_refine, reflections_to_refine, params)
except (DialsRefineConfigError, DialsRefineRuntimeError) as e:
sys.exit(str(e))
experiments.extend(experiments_to_refine)
reflections = flex.reflection_table.concat([reflections, reflections_to_refine])

# For the usual case of refinement of one crystal, print that model for information
crystals = experiments.crystals()
Expand Down

0 comments on commit 9b2d4d2

Please sign in to comment.