Example #1
0
    def __init__(self, config):
        # ============================================================================>
        # Dataset
        # ============================================================================>
        # # Dataloader
        self.dataloader = DefaultDataloader(config.input.data_dirs,
                                            config.input.pdb_style,
                                            config.input.mtz_style,
                                            config.input.regex.pdb_regex,
                                            config.input.regex.mtz_regex,
                                            config.input.regex.dir_regex,
                                            config.input.flags.only_datasets,
                                            config.input.flags.ignore_datasets,
                                            config.output.dataset_prefix,
                                            config.output.out_dir,
                                            config.input.lig_style
                                            )

        # # Reference
        self.get_reference = DefaultReferenceGetter(out_dir=config.output.out_dir,
                                                    reference_pdb_path=None,
                                                    reference_mtz_path=None,
                                                    reference_structure_factors=None,
                                                    structure_factors=config.params.diffraction_data.structure_factors
                                                    )

        # # Output
        # self.pandda_output = PanddaOutputSetup(config.output.out_dir,
        #                                        config.input.lig_style
        #                                        )

        # # Transforms
        self.transform_data_check = PanddaDataChecker(config.params.diffraction_data.structure_factors,
                                                      config.params.diffraction_data.checks.low_resolution_completeness,
                                                      config.params.diffraction_data.checks.all_data_are_valid_values
                                                      )

        self.transform_scale_diffraction = PanddaDiffractionScaler(
            config.params.diffraction_data.apply_b_factor_scaling
        )

        self.transform_filter_structure = PanddaDatasetFilterer(
            config.params.filtering.flags.similar_models_only,
            config.params.filtering.max_rfree,
            config.params.filtering.flags.same_space_group_only
        )

        self.transform_filter_wilson = PanddaDatasetFiltererWilsonRMSD(
            config.params.excluding.max_wilson_plot_z_score,
            config.params.diffraction_data.apply_b_factor_scaling,
            config.params.diffraction_data.structure_factors
        )

        self.transform_align = PanddaDefaultStructureAligner(
            method=config.params.alignment.method,
            cpus=config.settings.cpus
        )

        # # Sample loader
        self.grid_loader = PanDDAGridSetup(cpus=int(config.settings.cpus),
                                           mask_pdb=config.params.masks.pdb,
                                           align_mask_to_reference=bool(
                                               config.params.masks.align_mask_to_reference),
                                           alignment_method=config.params.alignment.method,
                                           outer_mask=float(config.params.masks.outer_mask),
                                           inner_mask=float(config.params.masks.inner_mask),
                                           inner_mask_symmetry=float(config.params.masks.inner_mask_symmetry),
                                           grid_spacing=float(config.params.maps.grid_spacing),
                                           padding=float(config.params.maps.padding),
                                           verbose=bool(config.settings.verbose),
                                           mask_selection_string=(None
                                                                  if str(
                                               config.params.z_map_anlysis.masks.selection_string) == "None"
                                                                  else str(
                                               config.params.z_map_anlysis.masks.selection_string)
                                                                  )
                                           )

        self.sample_loader = DefaultSampleLoader(config.params.maps.resolution_factor,
                                                 config.params.maps.density_scaling,
                                                 int(config.settings.cpus),
                                                 bool(config.settings.verbose),
                                                 self.grid_loader
                                                 )

        # # Refernce map loader
        self.reference_map_getter = PanddaReferenceMapLoader(config.params.maps.resolution_factor,
                                                             config.params.maps.density_scaling,
                                                             )

        # # Partititioner
        test = str(config.input.flags.test).split(",") if (str(config.input.flags.test) != "None") else None
        train = str(config.input.flags.train).split(",") if (str(config.input.flags.train) != "None") else None
        not_test = str(config.input.flags.not_test).split(",") if (
                str(config.input.flags.not_test) != "None") else None
        not_train = str(config.input.flags.not_train).split(",") if (
                str(config.input.flags.not_train) != "None") else None

        self.partitioner = DefaultPanDDAPartitionsGetter(test=test,
                                                         train=train,
                                                         not_test=not_test,
                                                         not_train=not_train,
                                                         )

        # ============================================================================>
        # Event Model
        # ============================================================================>
        self.statistical_model = statistical_model.PanDDANormalModel(method="adjusted+uncertainty",
                                                                     cpus=config.settings.cpus,
                                                                     )

        self.clusterer = cluster_outliers.PanDDADefaultCluster(
            grid_clustering_cutoff=float(
                config.params.z_map_anlysis.agglomerative_hierarchical.clustering_cutoff),
            negative_values=bool(config.params.z_map_anlysis.negative_values),
            cluster_method=config.params.z_map_anlysis.clustering_method,
            contour_level=float(config.params.z_map_anlysis.contour_level),
            outer_mask=float(config.params.masks.outer_mask),
            inner_mask_symmetry=float(config.params.masks.inner_mask_symmetry)
        )

        self.event_finder = filter_clusters.PanDDADefaultEventFinder(
            min_blob_z_peak=float(config.params.z_map_anlysis.min_blob_z_peak),
            grid_minimum_volume=float(
                config.params.z_map_anlysis.min_blob_volume),
            grid_spacing=float(config.params.maps.grid_spacing)
        )

        self.diffraction_data_truncator = PanddaDiffractionDataTruncater()

        #
        # self.bdc_calculator = PanDDADefaultBDCCalculator(config.params.background_correction.max_bdc,
        #                                                  config.params.background_correction.min_bdc,
        #                                                  config.params.background_correction.increment,
        #                                                  config.params.background_correction.output_multiplier
        #                                                  )
        #
        self.event_analyser = event_analyser.EventAnalyser(max_bdc=config.params.background_correction.max_bdc,
                                                           min_bdc=config.params.background_correction.min_bdc,
                                                           increment=config.params.background_correction.increment,
                                                           output_multiplier=config.params.background_correction.output_multiplier,
                                                           )
        #
        # self.map_maker = PanDDADefaultMapMaker()
        #
        # self.event_table_maker = PanDDADefaultEventTableShell(order_by=config.results.events.order_by)

        # self.event_model = PanDDAEventModel(self.statistical_model,
        #                                     self.clusterer,
        #                                     self.event_finder,
        #                                     statistics=[])

        # ############################
        # Criticism
        # ############################
        self.map_loader = MapLoaderDask(config.settings.verbose,
                                        config.params.maps.resolution_factor,
                                        config.params.maps.density_scaling,
                                        )
Example #2
0
    def __init__(self, config):
        # ============================================================================>
        # Dataset
        # ============================================================================>
        # # Dataloader
        self.dataloader = DefaultDataloader(
            config.input.data_dirs, config.input.pdb_style,
            config.input.mtz_style, config.input.regex.pdb_regex,
            config.input.regex.mtz_regex, config.input.regex.dir_regex,
            config.input.flags.only_datasets,
            config.input.flags.ignore_datasets, config.output.dataset_prefix,
            config.output.out_dir, config.input.lig_style)

        # # Reference
        self.get_reference = DefaultReferenceGetter(
            out_dir=config.output.out_dir,
            reference_pdb_path=None,
            reference_mtz_path=None,
            reference_structure_factors=None,
            structure_factors=config.params.diffraction_data.structure_factors)

        # # Output
        # self.pandda_output = PanddaOutputSetup(config.output.out_dir,
        #                                        config.input.lig_style
        #                                        )

        # # Transforms
        self.transform_data_check = PanddaDataChecker(
            config.params.diffraction_data.structure_factors,
            config.params.diffraction_data.checks.low_resolution_completeness,
            config.params.diffraction_data.checks.all_data_are_valid_values)

        self.transform_scale_diffraction = PanddaDiffractionScaler(
            config.params.diffraction_data.apply_b_factor_scaling)

        self.transform_filter_structure = PanddaDatasetFilterer(
            config.params.filtering.flags.similar_models_only,
            config.params.filtering.max_rfree,
            config.params.filtering.flags.same_space_group_only)

        self.transform_filter_wilson = PanddaDatasetFiltererWilsonRMSD(
            config.params.excluding.max_wilson_plot_z_score,
            config.params.diffraction_data.apply_b_factor_scaling,
            config.params.diffraction_data.structure_factors)

        self.transform_align = PanddaDefaultStructureAligner(
            method=config.params.alignment.method, cpus=config.settings.cpus)

        # # Sample loader
        self.grid_loader = PanDDAGridSetup(
            cpus=int(config.settings.cpus),
            mask_pdb=config.params.masks.pdb,
            align_mask_to_reference=bool(
                config.params.masks.align_mask_to_reference),
            alignment_method=config.params.alignment.method,
            outer_mask=float(config.params.masks.outer_mask),
            inner_mask=float(config.params.masks.inner_mask),
            inner_mask_symmetry=float(config.params.masks.inner_mask_symmetry),
            grid_spacing=float(config.params.maps.grid_spacing),
            padding=float(config.params.maps.padding),
            verbose=bool(config.settings.verbose),
            mask_selection_string=(
                None if str(config.params.z_map_anlysis.masks.selection_string)
                == "None" else str(
                    config.params.z_map_anlysis.masks.selection_string)))

        self.sample_loader = DefaultSampleLoader(
            config.params.maps.resolution_factor,
            config.params.maps.density_scaling, int(config.settings.cpus),
            bool(config.settings.verbose), self.grid_loader)

        # # Refernce map loader
        self.reference_map_getter = PanddaReferenceMapLoader(
            config.params.maps.resolution_factor,
            config.params.maps.density_scaling,
        )

        # # Partititioner
        test = str(config.input.flags.test).split(",") if (
            str(config.input.flags.test) != "None") else None
        train = str(config.input.flags.train).split(",") if (
            str(config.input.flags.train) != "None") else None
        not_test = str(config.input.flags.not_test).split(",") if (
            str(config.input.flags.not_test) != "None") else None
        not_train = str(config.input.flags.not_train).split(",") if (
            str(config.input.flags.not_train) != "None") else None

        self.partitioner = DefaultPanDDAPartitionsGetter(
            test=test,
            train=train,
            not_test=not_test,
            not_train=not_train,
        )

        # ============================================================================>
        # Event Model
        # ============================================================================>
        self.statistical_model = statistical_model.PanDDANormalModel(
            method="adjusted+uncertainty",
            cpus=config.settings.cpus,
        )

        self.clusterer = cluster_outliers.PanDDADefaultCluster(
            grid_clustering_cutoff=float(
                config.params.z_map_anlysis.agglomerative_hierarchical.
                clustering_cutoff),
            negative_values=bool(config.params.z_map_anlysis.negative_values),
            cluster_method=config.params.z_map_anlysis.clustering_method,
            contour_level=float(config.params.z_map_anlysis.contour_level),
            outer_mask=float(config.params.masks.outer_mask),
            inner_mask_symmetry=float(config.params.masks.inner_mask_symmetry))

        self.event_finder = filter_clusters.PanDDADefaultEventFinder(
            min_blob_z_peak=float(config.params.z_map_anlysis.min_blob_z_peak),
            grid_minimum_volume=float(
                config.params.z_map_anlysis.min_blob_volume),
            grid_spacing=float(config.params.maps.grid_spacing))

        self.diffraction_data_truncator = PanddaDiffractionDataTruncater()

        #
        # self.bdc_calculator = PanDDADefaultBDCCalculator(config.params.background_correction.max_bdc,
        #                                                  config.params.background_correction.min_bdc,
        #                                                  config.params.background_correction.increment,
        #                                                  config.params.background_correction.output_multiplier
        #                                                  )
        #
        self.event_analyser = event_analyser.EventAnalyser(
            max_bdc=config.params.background_correction.max_bdc,
            min_bdc=config.params.background_correction.min_bdc,
            increment=config.params.background_correction.increment,
            output_multiplier=config.params.background_correction.
            output_multiplier,
        )
        #
        # self.map_maker = PanDDADefaultMapMaker()
        #
        # self.event_table_maker = PanDDADefaultEventTableShell(order_by=config.results.events.order_by)

        # self.event_model = PanDDAEventModel(self.statistical_model,
        #                                     self.clusterer,
        #                                     self.event_finder,
        #                                     statistics=[])

        # ############################
        # Criticism
        # ############################
        self.map_loader = MapLoaderDask(
            config.settings.verbose,
            config.params.maps.resolution_factor,
            config.params.maps.density_scaling,
        )

        # Get dataset loader
        self.load_dataset = load_dataset.LoadDataset(
            dataloader=self.dataloader,
            sample_loader=self.sample_loader,
        )

        # Get reference loader
        self.get_reference = self.get_reference

        # Get dataset transformer
        self.transform_dataset = transform_dataset.TransformDataset(
            transform_data_check=self.transform_data_check,
            transform_scale_diffraction=self.transform_scale_diffraction,
            transform_filter_structure=self.transform_filter_structure,
            transform_filter_wilson=self.transform_filter_wilson,
            transform_align=self.transform_align,
        )

        # Get grid loader
        self.get_grid = self.grid_loader

        # Get partitioner
        self.partitioner = self.partitioner

        # Get output handler
        self.define_tree = define_tree.DefineTree(
            output_dir=config.output.out_dir)
        self.make_tree = make_tree.MakeTree(overwrite=config.output.overwrite)
        self.copy_dataset_files = copy_dataset_files.DatasetFileCopier()

        self.output = output.Output(
            define_tree=self.define_tree,
            make_tree=self.make_tree,
            copy_dataset_files=self.copy_dataset_files,
        )

        # Get resolution shell scheme
        self.create_shells = create_shells.CreateShells(
            min_train_datasets=60,
            max_test_datasets=60,
            cutoff=0.1,
        )

        # Get Resolution shell processor
        diffraction_data_truncator_obj = self.diffraction_data_truncator
        reference_map_getter_obj = self.reference_map_getter
        get_reference_map_obj = get_reference_map.GetReferenceMap()

        map_loader_obj = self.map_loader
        statistical_model_obj = self.statistical_model
        fit_model_obj = fit_model.FitModel()
        evaluate_model_obj = evaluate_model.EvaluateModel()
        cluster_outliers_obj = self.clusterer
        filter_clusters_obj = self.event_finder
        event_analyser_obj = self.event_analyser

        make_event_map_obj = make_event_map.MakeEventMap()
        make_z_map_obj = make_z_map.MakeZMap()
        make_mean_map_obj = make_mean_map.MakeMeanMap()
        make_event_table_obj = make_event_table.MakeEventTable()

        process_in_shell = processor.ProcessorDictJoblib()

        self.process_shell = process_shell.ProcessShell(
            diffraction_data_truncator=diffraction_data_truncator_obj,
            reference_map_getter=reference_map_getter_obj,
            get_reference_map=get_reference_map_obj,
            map_loader=map_loader_obj,
            statistical_model=statistical_model_obj,
            fit_model=fit_model_obj,
            evaluate_model=evaluate_model_obj,
            cluster_outliers=cluster_outliers_obj,
            filter_clusters=filter_clusters_obj,
            event_analyser=event_analyser_obj,
            make_event_map=make_event_map_obj,
            make_z_map=make_z_map_obj,
            make_mean_map=make_mean_map_obj,
            make_event_table=make_event_table_obj,
            process=process_in_shell,
        )

        # self.processer = processor.ProcessorLuigi(jobs=10,
        #                                           parallel_env="smp",
        #                                           n_cpu=12,
        #                                           run_locally=False,
        #                                           )
        self.processer = processor.Processor()

        # Get site table creator
        self.create_sites_table = create_sites_table.CreateSitesTable()

        # Get event table outputter
        self.output_sites_table = output_sites_table.OutputSitesTable()

        # Get event table processor
        self.create_event_table = create_event_table.CreateEventTable()

        # Get event table outputter
        self.output_event_table = output_event_table.OutputEventTable()

        # Autobuilders
        self.autobuilder = autobuild.AutobuildQFit()
Example #3
0
    def __init__(self, config):
        # ============================================================================>
        # Dataset
        # ============================================================================>
        # # Dataloader
        self.dataloader = DefaultDataloader(config.input.data_dirs,
                                            config.input.pdb_style,
                                            config.input.mtz_style,
                                            config.input.regex.pdb_regex,
                                            config.input.regex.mtz_regex,
                                            config.input.regex.dir_regex,
                                            config.input.flags.only_datasets,
                                            config.input.flags.ignore_datasets,
                                            config.output.dataset_prefix,
                                            config.output.out_dir,
                                            config.input.lig_style
                                            )

        # # Reference
        self.get_reference = DefaultReferenceGetter(out_dir=config.output.out_dir,
                                                    reference_pdb_path=None,
                                                    reference_mtz_path=None,
                                                    reference_structure_factors=None,
                                                    structure_factors=config.params.diffraction_data.structure_factors
                                                    )

        # # Transforms
        self.transform_data_check = PanddaDataChecker(config.params.diffraction_data.structure_factors,
                                                      config.params.diffraction_data.checks.low_resolution_completeness,
                                                      config.params.diffraction_data.checks.all_data_are_valid_values
                                                      )

        self.transform_scale_diffraction = PanddaDiffractionScaler(
            config.params.diffraction_data.apply_b_factor_scaling
        )

        self.transform_filter_structure = PanddaDatasetFilterer(
            config.params.filtering.flags.similar_models_only,
            config.params.filtering.max_rfree,
            config.params.filtering.flags.same_space_group_only
        )

        self.transform_filter_wilson = PanddaDatasetFiltererWilsonRMSD(
            config.params.excluding.max_wilson_plot_z_score,
            config.params.diffraction_data.apply_b_factor_scaling,
            config.params.diffraction_data.structure_factors
        )

        self.transform_align = PanddaDefaultStructureAligner(
            method=config.params.alignment.method,
            cpus=config.settings.cpus
        )

        # # Sample loader
        self.grid_loader = PanDDAGridSetup(cpus=int(config.settings.cpus),
                                           mask_pdb=config.params.masks.pdb,
                                           align_mask_to_reference=bool(
                                               config.params.masks.align_mask_to_reference),
                                           alignment_method=config.params.alignment.method,
                                           outer_mask=float(config.params.masks.outer_mask),
                                           inner_mask=float(config.params.masks.inner_mask),
                                           inner_mask_symmetry=float(config.params.masks.inner_mask_symmetry),
                                           grid_spacing=float(config.params.maps.grid_spacing),
                                           padding=float(config.params.maps.padding),
                                           verbose=bool(config.settings.verbose),
                                           mask_selection_string=(None
                                                                  if str(
                                               config.params.z_map_anlysis.masks.selection_string) == "None"
                                                                  else str(
                                               config.params.z_map_anlysis.masks.selection_string)
                                                                  )
                                           )

        # # Refernce map loader
        self.reference_map_getter = PanddaReferenceMapLoader(config.params.maps.resolution_factor,
                                                             config.params.maps.density_scaling,
                                                             )

        # # Partititioner
        # Order:
        # ignore datsets (remove from test and train)
        # only datasets (remove all others from test and train)
        # exclude datasets (remove from test)
        # ground state (remove all others from test)
        ignore = str(config.input.flags.ignore_datasets).split(",") if (
                    str(config.input.flags.ignore_datasets) != "None") else []
        only = str(config.input.flags.only_datasets).split(",") if (
                    str(config.input.flags.only_datasets) != "None") else []
        exclude = str(config.input.flags.exclude_from_characterisation).split(",") if (
                    str(config.input.flags.exclude_from_characterisation) != "None") else []
        ground_state_datasets = str(config.input.flags.ground_state_datasets).split(",") if (
                    str(config.input.flags.ground_state_datasets) != "None") else []

        not_test = set(ignore)
        not_train = set(ignore).union(set(exclude))

        test = set(only).difference(not_train)
        train = set(ground_state_datasets).intersection(set(only)).difference(not_test)

        self.partitioner = partitioner.DefaultPanDDAPartitionsGetter(test=test,
                                                                     train=train,
                                                                     )

        # ============================================================================>
        # Event Model
        # ============================================================================>
        self.statistical_model = statistical_model.PanDDANormalModel(method="adjusted+uncertainty",
                                                                     cpus=config.settings.cpus,
                                                                     )

        self.clusterer = cluster_outliers.PanDDADefaultCluster(
            grid_clustering_cutoff=float(
                config.params.z_map_anlysis.agglomerative_hierarchical.clustering_cutoff),
            negative_values=bool(config.params.z_map_anlysis.negative_values),
            cluster_method=config.params.z_map_anlysis.clustering_method,
            contour_level=float(config.params.z_map_anlysis.contour_level),
            outer_mask=float(config.params.masks.outer_mask),
            inner_mask_symmetry=float(config.params.masks.inner_mask_symmetry)
        )

        self.event_finder = filter_clusters.PanDDADefaultEventFinder(
            min_blob_z_peak=float(config.params.z_map_anlysis.min_blob_z_peak),
            grid_minimum_volume=float(
                config.params.z_map_anlysis.min_blob_volume),
            grid_spacing=float(config.params.maps.grid_spacing)
        )

        self.diffraction_data_truncator = PanddaDiffractionDataTruncater()

        self.event_analyser = event_analyser.EventAnalyser(max_bdc=config.params.background_correction.max_bdc,
                                                           min_bdc=config.params.background_correction.min_bdc,
                                                           increment=config.params.background_correction.increment,
                                                           output_multiplier=config.params.background_correction.output_multiplier,
                                                           )

        # ############################
        # Criticism
        # ############################
        self.map_loader = MapLoaderDask(config.settings.verbose,
                                        config.params.maps.resolution_factor,
                                        config.params.maps.density_scaling,
                                        )

        # Get dataset loader
        self.load_dataset = load_dataset.LoadDataset(dataloader=self.dataloader,
                                                     )

        # Get dataset transformer
        self.transform_dataset = transform_dataset.TransformDataset(transform_data_check=self.transform_data_check,
                                                                    transform_scale_diffraction=self.transform_scale_diffraction,
                                                                    transform_filter_structure=self.transform_filter_structure,
                                                                    transform_filter_wilson=self.transform_filter_wilson,
                                                                    transform_align=self.transform_align,
                                                                    )

        # Get grid loader
        self.get_grid = self.grid_loader

        # Get output handler
        self.define_tree = define_tree.DefineTree(output_dir=config.output.out_dir)
        self.make_tree = make_tree.MakeTree(overwrite=config.output.overwrite)
        self.copy_dataset_files = copy_dataset_files.DatasetFileCopier()

        self.output = output.Output(define_tree=self.define_tree,
                                    make_tree=self.make_tree,
                                    copy_dataset_files=self.copy_dataset_files,
                                    )

        # Get resolution shell scheme
        self.create_shells = create_shells.CreateShells(
            min_train_datasets=config.params.statistical_maps.min_build_datasets,
            max_test_datasets=config.params.statistical_maps.max_build_datasets,
            cutoff=0.1,
            )

        # Get Resolution shell processor
        self.n_cpus_shells = config.processing.process_dict_n_cpus
        self.h_vmem = config.processing.h_vmem
        self.m_mem_free = config.processing.m_mem_free

        if config.processing.process_dict == "joblib":
            process_in_shell = processor.ProcessorDictJoblib(config.processing.process_dict_n_cpus)

        elif config.processing.process_dict == "seriel":
            process_in_shell = processor.ProcessorDict()

        self.process_shell = process_shell.ProcessShell(diffraction_data_truncator=self.diffraction_data_truncator,
                                                        reference_map_getter=self.reference_map_getter,
                                                        get_reference_map=get_reference_map.GetReferenceMap(),
                                                        map_loader=self.map_loader,
                                                        statistical_model=self.statistical_model,
                                                        fit_model=fit_model.FitModel(),
                                                        evaluate_model=evaluate_model.EvaluateModel(),
                                                        cluster_outliers=self.clusterer,
                                                        filter_clusters=self.event_finder,
                                                        event_analyser=self.event_analyser,
                                                        make_event_map=make_event_map.MakeEventMap(),
                                                        make_z_map=make_z_map.MakeZMap(),
                                                        make_mean_map=make_mean_map.MakeMeanMap(),
                                                        make_event_table=make_event_table.MakeEventTable(),
                                                        process=process_in_shell,
                                                        )

        if config.processing.process_shells == "luigi":
            self.processer = processor.ProcessorLuigi(jobs=10,
                                                      parallel_env="smp",
                                                      run_locally=False,
                                                      n_cpu=self.n_cpus_shells,
                                                      h_vmem=self.h_vmem,
                                                      m_mem_free=self.m_mem_free,
                                                      )
        elif config.processing.process_shells == "seriel":
            self.processer = processor.Processor()

        # Get site table creator
        self.create_sites_table = create_sites_table.CreateSitesTable()

        # Get event table outputter
        self.output_sites_table = output_sites_table.OutputSitesTable()

        # Get event table processor
        self.create_event_table = create_event_table.CreateEventTable()

        # Get event table outputter
        self.output_event_table = output_event_table.OutputEventTable()
Example #4
0
    def __init__(self, phil):

        # ============================================================================>
        # Transform Variables
        # ============================================================================>
        # input
        # input = phil.input
        # data_dirs = str(phil.input.data_dirs)
        # pdb_style = phil.input.pdb_style
        # mtz_style = phil.input.mtz_style
        #
        # # # input.regex
        # regex = input.regex
        # pdb_regex = regex.pdb_regex
        # mtz_regex = regex.mtz_regex
        # dir_regex = regex.dir_regex
        #
        # # # input.flags
        # flags = input.flags
        # only_datasets = flags.only_datasets
        config = Config(phil)
        #
        # cpus = int(config["args"]["cpus"])
        #
        # resolution_factor = config["maps"]["resolution_factor"]
        # density_scaling = config["maps"]["density_scaling"]

        # ============================================================================>
        # Dataset
        # ============================================================================>
        # # Dataloader
        if config["dataset"]["dataloader"] == "default":
            self.dataloader = DefaultDataloader(
                config.input.data_dirs, config.input.pdb_style,
                config.input.mtz_style, config.input.regex.pdb_regex,
                config.input.regex.mtz_regex, config.input.regex.dir_regex,
                config.input.flags.only_datasets,
                config.input.flags.ignore_datasets,
                config.output.dataset_prefix, config.output.out_dir,
                config.input.lig_style)

        # # Reference
        if config["dataset"]["get_reference"] == "default":
            self.get_reference = DefaultReferenceGetter(
                out_dir=config.output.out_dir,
                reference_pdb_path=None,
                reference_mtz_path=None,
                reference_structure_factors=config.params.diffraction_data.
                structure_factors,
                structure_factors=config.params.diffraction_data.
                structure_factors)

        # # Output
        if config["output"]["version"] == "pandda":
            self.pandda_output = PanddaOutputSetup(config.output.out_dir,
                                                   config.input.lig_style)

        # # Transforms
        self.dataset_transforms = OrderedDict()
        if config["transforms"]["PanddaDataChecker"] == "True":
            self.dataset_transforms["data_check"] = PanddaDataChecker(
                config.params.diffraction_data.structure_factors,
                config.params.diffraction_data.low_resolution_completeness,
                config.params.diffraction_data.all_data_are_valid_values)

        if config["transforms"]["PanddaDiffractionScaler"] == "True":
            self.dataset_transforms[
                "scale_diffraction"] = PanddaDiffractionScaler(
                    config.params.diffraction_data.apply_b_factor_scaling)

        if config["transforms"]["PanddaDatasetFilterer"] == "True":
            self.dataset_transforms[
                "filter_structure"] = PanddaDatasetFilterer(
                    config.params.filtering.flags.similar_models_only,
                    config.params.filtering.max_rfree,
                    config.params.filtering.flags.same_space_group_only)

        if config["transforms"]["PanddaDatasetFiltererWilsonRMSD"] == "True":
            self.dataset_transforms[
                "filter_wilson"] = PanddaDatasetFiltererWilsonRMSD(
                    config.params.excluding.max_wilson_plot_z_score,
                    config.params.diffraction_data.apply_b_factor_scaling,
                    config.params.diffraction_data.structure_factors)

        if config["transforms"]["PanddaDefaultStructureAligner"] == "True":
            method = str(config["transforms"]["align_method"])
            self.dataset_transforms["align"] = PanddaDefaultStructureAligner(
                method=config.params.alignment.method,
                cpus=config.settings.cpus)

            # # Sample loader
        if config["dataset"]["sample_loader"] == "default":
            grid_loader = PanDDAGridSetup(
                cpus=int(config.settings.cpus),
                mask_pdb=config.params.masks.pdb,
                align_mask_to_reference=bool(
                    config.params.masks.align_mask_to_reference),
                alignment_method=config.params.alignment.method,
                outer_mask=float(config.params.masks.outer_mask),
                inner_mask=float(config.params.masks.inner_mask),
                inner_mask_symmetry=float(
                    config.params.masks.inner_mask_symmetry),
                grid_spacing=float(config.params.maps.grid_spacing),
                padding=float(config.params.maps.padding),
                verbose=bool(config.settings.verbose),
                mask_selection_string=str(
                    config.params.z_map_anlysis.masks.selection_string))

            self.sample_loader = DefaultSampleLoader(
                config.params.maps.resolution_factor,
                config.params.maps.density_scaling, int(config.settings.cpus),
                bool(config.settings.verbose), grid_loader)

        # # Refernce map loader
        self.reference_map_getter = PanddaReferenceMapLoader(
            config.params.maps.resolution_factor,
            config.params.maps.density_scaling)

        # # Partititioner
        test = str(config["partitioner"]["test"]).split(",") if (
            str(config["partitioner"]["test"]) != "None") else None
        train = str(config["partitioner"]["train"]).split(",") if (
            str(config["partitioner"]["train"]) != None) else None
        not_test = str(config["partitioner"]["not_test"]).split(",") if bool(
            str(config["partitioner"]["not_test"])) else None
        not_train = str(config["partitioner"]["not_train"]).split(",") if bool(
            str(config["partitioner"]["not_train"])) else None

        if config["dataset"]["partitioner"] == "default":
            self.partitioner = DefaultPanDDAPartitionsGetter(
                test=test, train=train, not_test=not_test, not_train=not_train)

        # ============================================================================>
        # Event Model
        # ============================================================================>
        bdc_calculator = config["event_model"]["bdc_calculator"]
        max_bdc = float(config["bdc_calculator"]["max_bdc"])
        min_bdc = float(config["bdc_calculator"]["min_bdc"])
        increment = float(config["bdc_calculator"]["increment"])
        output_multiplier = float(
            config["bdc_calculator"]["output_multiplier"])

        map_maker = config["event_model"]["map_maker"]
        order_by = config["event_table"]["order_by"]

        event_table_maker = config["event_model"]["event_table_maker"]

        if config["event_model"]["model"] == "PanDDAEventModel":

            self.statistical_model = None
            if config["event_model"][
                    "statistical_model"] == "PanDDANormalModel":
                self.statistical_model = PanDDANormalModel(
                    method="adjusted+uncertainty", cpus=1)

            self.clusterer = None
            if config["event_model"]["clusterer"] == "PanDDADefaultCluster":
                self.clusterer = PanDDADefaultCluster(
                    grid_clustering_cutoff=float(
                        config.params.z_map_anlysis.agglomerative_hierarchical.
                        clustering_cutoff),
                    negative_values=bool(
                        config.params.z_map_anlysis.negative_values),
                    cluster_method=config.params.z_map_anlysis.
                    clustering_method,
                    contour_level=float(
                        config.params.z_map_anlysis.contour_level),
                    outer_mask=float(config.params.masks.outer_mask),
                    inner_mask_symmetry=float(
                        config.params.masks.inner_mask_symmetry))

            self.event_finder = None
            if config["event_model"][
                    "event_finder"] == "PanDDADefaultEventFinder":
                self.event_finder = PanDDADefaultEventFinder(
                    min_blob_z_peak=float(
                        config.params.z_map_anlysis.min_blob_z_peak),
                    grid_minimum_volume=float(
                        config.params.z_map_anlysis.min_blob_volume),
                    grid_spacing=float(config.params.maps.grid_spacing))

            if bdc_calculator == "PanDDADefaultBDCCalculator":
                self.bdc_calculator = PanDDADefaultBDCCalculator(
                    config.params.background_correction.max_bdc,
                    config.params.background_correction.min_bdc,
                    config.params.background_correction.increment,
                    config.params.background_correction.output_multiplier)

            if map_maker == "PanDDADefaultMapMaker":
                self.map_maker = PanDDADefaultMapMaker()

            if event_table_maker == "PanDDADefaultEventTableShell":
                self.event_table_maker = PanDDADefaultEventTableShell(
                    order_by=order_by)

            self.event_model = PanDDAEventModel(self.statistical_model,
                                                self.clusterer,
                                                self.event_finder,
                                                statistics=[])

        # ############################
        # Criticism
        # ############################
        verbose = bool(config["args"]["verbose"])
        resolution_factor = float(config["maps"]["resolution_factor"])
        density_scaling = str(config["maps"]["density_scaling"])

        self.map_loader = MapLoaderDask(verbose, resolution_factor,
                                        density_scaling)

        self.criticiser = Criticiser()
        self.criticiser_all = CriticiserAll(self.map_loader, event_table_maker,
                                            map_maker)