Exemplo n.º 1
0
    def create_current_phil(self, phil):
        # Create master PHIL based on backend and settings
        if phil.__class__.__name__ == "scope_extract":
            backend = self.determine_backend(prm=phil)
        elif phil.__class__.__name__ == "scope":
            backend = self.determine_backend(phil=phil)
        else:
            return None

        if not backend:
            return None

        if backend.lower() in ("ha14", "cctbx"):
            from iota.etc.iota_cctbx_ha14 import ha14_str

            new_phil = ip.parse(master_phil_str + ha14_str)
        else:
            new_phil = master_phil

        # Append GUI PHIL if it should be there:
        from libtbx.phil import find_scope

        gui_phil = find_scope(phil, "gui")
        if gui_phil and not find_scope(new_phil, "gui"):
            from iota.gui.base import gui_phil

            new_phil.adopt_scope(gui_phil)

        return new_phil
Exemplo n.º 2
0
    def create_current_phil(self, phil):
        # Create master PHIL based on backend and settings
        if phil.__class__.__name__ == 'scope_extract':
            backend = self.determine_backend(prm=phil)
        elif phil.__class__.__name__ == 'scope':
            backend = self.determine_backend(phil=phil)
        else:
            return None

        if not backend:
            return None

        if backend.lower() in ('ha14', 'cctbx'):
            from iota.components.iota_cctbx_ha14 import ha14_str
            new_phil = ip.parse(master_phil_str + ha14_str)
        else:
            new_phil = master_phil

        # Append GUI PHIL if it should be there:
        from libtbx.phil import find_scope
        gui_phil = find_scope(phil, 'gui')
        if gui_phil:
            from iota.components.iota_ui_base import gui_phil
            new_phil.adopt_scope(gui_phil)

        return new_phil
Exemplo n.º 3
0
    def get_parameter_type(self, name):
        """Find the parameter type for a scaling phil option."""
        phil_scope = phil.parse(
            """include scope dials.command_line.scale.phil_scope""",
            process_includes=True,
        )
        obj = phil.find_scope(phil_scope, name)
        if not obj:
            raise ValueError(
                """Unable to resolve %s in the phil scope, make sure full phil path
is provided. For example, physical.decay_correction rather than decay_correction"""
                % name)
        return obj.type.phil_type  # a str: "int", "bool" etc
Exemplo n.º 4
0
def get_input_phil(paramfile=None, phil_args=None, ha14=False, gui=False):
    """Generate PHIL from file, master, and/or command arguments.

    :param args: command line arguments
    :param phil_args: PHIL settings as command line arguments
    :param paramfile: file with input settings in PHIL format
    :return:
    """
    from libtbx.phil.command_line import argument_interpreter
    from libtbx.utils import Sorry

    # Depending on mode, either read input from file, or generate defaults
    if paramfile:
        with open(paramfile, "r") as inpf:
            user_phil = ip.parse(inpf.read())
        phil_fixer = PHILFixer()
        working_phil = phil_fixer.run(old_phil=user_phil, write_file=True)

    else:
        if ha14:
            from iota.etc.iota_cctbx_ha14 import ha14_str

            working_phil = ip.parse(master_phil_str + ha14_str,
                                    process_includes=True)
        else:
            working_phil = master_phil

    if gui:
        from libtbx.phil import find_scope

        if not find_scope(working_phil, "gui"):
            from iota.gui.base import gui_phil

            working_phil.adopt_scope(gui_phil)

    # Parse in-line params into phil
    bad_args = []
    if phil_args:
        argument_interpreter = argument_interpreter(master_phil=working_phil)
        for arg in phil_args:
            try:
                command_line_params = argument_interpreter.process(arg=arg)
                working_phil = working_phil.fetch(
                    sources=[command_line_params])
            except Sorry:
                bad_args.append(arg)

    # Self-fetch to resolve variables
    working_phil = working_phil.fetch(source=working_phil)

    return working_phil, bad_args