def checkAndSetElements(elements):
    """ Utility to check if input is a valid list of elements.

    @param  elements: The elements to check.
    <br/><b>type</b> elements: list
    @return: The checked list of elements.
    """

    if elements is None:
        raise RuntimeError(
            "No element(s) specified. Give at least one chemical element.")
    elements = checkAndSetInstance(list, elements, None)

    # Check each element.
    for element in elements:
        symbol, stoch, chrg = checkAndSetInstance(list, element, None)
        if symbol not in ALL_ELEMENTS:
            raise ValueError('%s is not a valid chemical element symbol.' %
                             (symbol))
        stoch = checkAndSetPositiveInteger(stoch)
        chrg = checkAndSetInteger(chrg)
        if chrg < -1:
            raise ValueError("Charge must be >= -1.")

        element = [symbol, stoch, chrg]
    return elements
Exemple #2
0
    def testCheckAndSetPositiveInteger(self):
        """ Test the check method for positive integers. """

        # Check with correct parameter.
        self.assertEqual( 1, checkAndSetPositiveInteger(1) )

        # Check default.
        self.assertEqual( 1, checkAndSetPositiveInteger(None, 1) )

        # Check exception if parameter not an int.
        self.assertRaises( TypeError, checkAndSetPositiveInteger, "not an integer")

        # Check exception if parameter < 0.
        self.assertRaises( TypeError, checkAndSetPositiveInteger, -1)

        # Check exception if parameter = 0.
        self.assertRaises( TypeError, checkAndSetPositiveInteger, 0)
    def testCheckAndSetPositiveInteger(self):
        """ Test the check method for positive integers. """

        # Check with correct parameter.
        self.assertEqual( 1, checkAndSetPositiveInteger(1) )

        # Check default.
        self.assertEqual( 1, checkAndSetPositiveInteger(None, 1) )

        # Check exception if parameter not an int.
        self.assertRaises( TypeError, checkAndSetPositiveInteger, "not an integer")

        # Check exception if parameter < 0.
        self.assertRaises( TypeError, checkAndSetPositiveInteger, -1)

        # Check exception if parameter = 0.
        self.assertRaises( TypeError, checkAndSetPositiveInteger, 0)
def _checkAndSetNodesPerTask(value=None):
    """ """
    """ Utility function to check validity of input for number of nodes per
    task.

    :param value: The value to check.
    :type value: int

    :return: The checked value, default 1.
    """

    return checkAndSetPositiveInteger(value, 1)
def _checkAndSetCPUsPerTask(value=None):
    """ """
    """ Utility function to check validity of input for number of cpus per task.

    :param value: The value to check.
    :type value: (int | str)

    :return: The checked value, default 1.
    """

    # Check type
    if isinstance(value, str):
        if not value == "MAX":
            raise ValueError(
                'cpus_per_task must be a positive integer or string "MAX".')
        return value

    return checkAndSetPositiveInteger(value, 1)
def checkAndSetElements(elements):
    """ Utility to check if input is a valid list of elements.

    @param  elements: The elements to check.
    <br/><b>type</b> elements: list
    @return: The checked list of elements.
    """

    if elements is None:
        raise RuntimeError( "No element(s) specified. Give at least one chemical element.")
    elements = checkAndSetInstance( list, elements, None )

    # Check each element.
    for element in elements:
        symbol, stoch, chrg = checkAndSetInstance( list, element, None )
        if symbol not in ALL_ELEMENTS:
            raise ValueError( '%s is not a valid chemical element symbol.' % (symbol) )
        stoch = checkAndSetPositiveInteger(stoch)
        chrg = checkAndSetInteger(chrg)
        if chrg < -1:
            raise ValueError( "Charge must be >= -1.")

        element = [symbol, stoch, chrg]
    return elements
    def __init__(self,  parameters=None, input_path=None, output_path=None):
        """
        Constructor for the xfel photon propagator.

        @param  parameters : singFEL parameters.
        <br/><b>type</b>              : dict
        <br/><b>example</b> : parameters={ 'uniform_rotation'    : True,
                     'calculate_Compton'              : False,
                     'pmi_start_ID'                   : 1,
                     'pmi_stop_ID'                    : 1,
                     'number_of_diffraction_patterns' : 2,
                     'number_of_MPI_processes'        : 2,
                     'slice_interval'                 : 10,
                     'number_of_slices'               : 100,
                     'beam_parameter_file'            : 's2e.beam',
                     'beam_geometry_file'             : 's2e.geom',
                     }

        @param parameters['uniform_rotation']  : Whether or not to apply uniform sampling of the sample's rotations.
        <br/><b>type</b> : boolean

        @param parameters['calculate_Compton'] : Whether or not to calculate incoherent (Compton) scattering.
        <br/><b>type</b> : Bool

        @param parameters['pmi_start_ID'] : Index of the pmi file to start from.
        <br/><b>type</b> : int

        @param parameters['pmi_stop_ID'] : Index of the pmi file to stop at.
        <br/><b>type</b> : int

        @param parameters['number_of_diffraction_patterns'] : The number of diffraction patterns to calculate from each photon-matter interaction trajectory.
        <br/><b>type</b> : int

        @param parameters['number_of_MPI_processes'] : The number of MPI processes to use
        <br/><b>type</b> : int

        @param parameters['slice_interval'] : The number of time slices to skip between two samplings of the photon-matter interaction trajectory.
        <br/><b>type</b> : int

        @param parameters['number_of_slices'] : Total number of slices in the pmi files."
        <br/><b>type</b> : int

        @param parameters['beam_parameter_file'] : Path of the beam parameter (.beam) file.
        <br/><b>type</b> : string

        @param parameters['beam_geometry_file'] : Path of the beam geometry (.geom) file.
        <br/><b>type</b> : string

        <br/><b>note</b>: The number of generated files is the number of pmi data files * number_of_diffraction_patterns.
        """

        super(SingFELPhotonDiffractor, self).__init__(parameters,input_path,output_path)

        # Check parameters.
        # Check that only accepted parameters are present.
        accepted_keys = ['uniform_rotation',
                         'calculate_Compton',
                         'slice_interval',
                         'number_of_slices',
                         'number_of_diffraction_patterns',
                         'number_of_MPI_processes',
                         'pmi_start_ID',
                         'pmi_stop_ID',
                         'beam_parameter_file',
                         'beam_geometry_file']

        for k in self.parameters.keys():
            if k not in accepted_keys:
                raise RuntimeError( "The parameter '%s' is not a valid parameter for the SingFELPhotonDiffractor. " % (k))
        # Check each parameter individually and set defaults if not set.
        self.parameters['uniform_rotation'] = checkAndSetInstance(bool, self.parameters['uniform_rotation'], True)
        self.parameters['calculate_Compton'] = checkAndSetInstance(bool, self.parameters['calculate_Compton'], True)
        self.parameters['slice_interval'] = checkAndSetPositiveInteger(self.parameters['slice_interval'], 1)
        self.parameters['number_of_slices'] = checkAndSetPositiveInteger(self.parameters['number_of_slices'], 1)
        self.parameters['number_of_diffraction_patterns'] = checkAndSetPositiveInteger(self.parameters['number_of_diffraction_patterns'], 1)
        self.parameters['number_of_MPI_processes'] = checkAndSetPositiveInteger(self.parameters.get('number_of_MPI_processes',2))
        self.parameters['pmi_start_ID'] = checkAndSetPositiveInteger(self.parameters['pmi_start_ID'], 1)
        self.parameters['pmi_stop_ID'] = checkAndSetPositiveInteger(self.parameters['pmi_stop_ID'], 1)
        self.parameters['beam_parameter_file'] = checkAndSetInstance(str, self.parameters['beam_parameter_file'])
        if not os.path.isfile(self.parameters['beam_parameter_file']):
            raise IOError("%s is not a file." % (self.parameters['beam_parameter_file']))
        self.parameters['beam_geometry_file'] = checkAndSetInstance(str, self.parameters['beam_geometry_file'])
        if not os.path.isfile(self.parameters['beam_geometry_file']):
            raise IOError("%s is not a file." % (self.parameters['beam_geometry_file']))

        self.__expected_data = ['/data/snp_<7 digit index>/ff',
                                '/data/snp_<7 digit index>/halfQ',
                                '/data/snp_<7 digit index>/Nph',
                                '/data/snp_<7 digit index>/r',
                                '/data/snp_<7 digit index>/T',
                                '/data/snp_<7 digit index>/Z',
                                '/data/snp_<7 digit index>/xyz',
                                '/data/snp_<7 digit index>/Sq_halfQ',
                                '/data/snp_<7 digit index>/Sq_bound',
                                '/data/snp_<7 digit index>/Sq_free',
                                '/history/parent/detail',
                                '/history/parent/parent',
                                '/info/package_version',
                                '/info/contact',
                                '/info/data_description',
                                '/info/method_description',
                                '/version']

        self.__provided_data = [
                                '/data/data',
                                '/data/diffr',
                                '/data/angle',
                                '/history/parent/detail',
                                '/history/parent/parent',
                                '/info/package_version',
                                '/info/contact',
                                '/info/data_description',
                                '/info/method_description',
                                '/params/geom/detectorDist',
                                '/params/geom/pixelWidth',
                                '/params/geom/pixelHeight',
                                '/params/geom/mask',
                                '/params/beam/photonEnergy',
                                '/params/beam/photons',
                                '/params/beam/focusArea',
                                '/params/info',
                                ]
Exemple #8
0
    def __init__(self, parameters=None, input_path=None, output_path=None):
        """
        Constructor for the xfel photon propagator.

        @param  parameters : singFEL parameters.
        <br/><b>type</b>              : dict
        <br/><b>example</b> : parameters={ 'uniform_rotation'    : True,
                     'calculate_Compton'              : False,
                     'pmi_start_ID'                   : 1,
                     'pmi_stop_ID'                    : 1,
                     'number_of_diffraction_patterns' : 2,
                     'number_of_MPI_processes'        : 2,
                     'slice_interval'                 : 10,
                     'number_of_slices'               : 100,
                     'beam_parameter_file'            : 's2e.beam',
                     'beam_geometry_file'             : 's2e.geom',
                     }

        @param parameters['uniform_rotation']  : Whether or not to apply uniform sampling of the sample's rotations.
        <br/><b>type</b> : boolean

        @param parameters['calculate_Compton'] : Whether or not to calculate incoherent (Compton) scattering.
        <br/><b>type</b> : Bool

        @param parameters['pmi_start_ID'] : Index of the pmi file to start from.
        <br/><b>type</b> : int

        @param parameters['pmi_stop_ID'] : Index of the pmi file to stop at.
        <br/><b>type</b> : int

        @param parameters['number_of_diffraction_patterns'] : The number of diffraction patterns to calculate from each photon-matter interaction trajectory.
        <br/><b>type</b> : int

        @param parameters['number_of_MPI_processes'] : The number of MPI processes to use
        <br/><b>type</b> : int

        @param parameters['slice_interval'] : The number of time slices to skip between two samplings of the photon-matter interaction trajectory.
        <br/><b>type</b> : int

        @param parameters['number_of_slices'] : Total number of slices in the pmi files."
        <br/><b>type</b> : int

        @param parameters['beam_parameter_file'] : Path of the beam parameter (.beam) file.
        <br/><b>type</b> : string

        @param parameters['beam_geometry_file'] : Path of the beam geometry (.geom) file.
        <br/><b>type</b> : string

        <br/><b>note</b>: The number of generated files is the number of pmi data files * number_of_diffraction_patterns.
        """

        super(SingFELPhotonDiffractor, self).__init__(parameters, input_path,
                                                      output_path)

        # Check parameters.
        # Check that only accepted parameters are present.
        accepted_keys = [
            'uniform_rotation', 'calculate_Compton', 'slice_interval',
            'number_of_slices', 'number_of_diffraction_patterns',
            'number_of_MPI_processes', 'pmi_start_ID', 'pmi_stop_ID',
            'beam_parameter_file', 'beam_geometry_file'
        ]

        for k in self.parameters.keys():
            if k not in accepted_keys:
                raise RuntimeError(
                    "The parameter '%s' is not a valid parameter for the SingFELPhotonDiffractor. "
                    % (k))
        # Check each parameter individually and set defaults if not set.
        self.parameters['uniform_rotation'] = checkAndSetInstance(
            bool, self.parameters['uniform_rotation'], True)
        self.parameters['calculate_Compton'] = checkAndSetInstance(
            bool, self.parameters['calculate_Compton'], True)
        self.parameters['slice_interval'] = checkAndSetPositiveInteger(
            self.parameters['slice_interval'], 1)
        self.parameters['number_of_slices'] = checkAndSetPositiveInteger(
            self.parameters['number_of_slices'], 1)
        self.parameters[
            'number_of_diffraction_patterns'] = checkAndSetPositiveInteger(
                self.parameters['number_of_diffraction_patterns'], 1)
        self.parameters[
            'number_of_MPI_processes'] = checkAndSetPositiveInteger(
                self.parameters.get('number_of_MPI_processes', 2))
        self.parameters['pmi_start_ID'] = checkAndSetPositiveInteger(
            self.parameters['pmi_start_ID'], 1)
        self.parameters['pmi_stop_ID'] = checkAndSetPositiveInteger(
            self.parameters['pmi_stop_ID'], 1)
        self.parameters['beam_parameter_file'] = checkAndSetInstance(
            str, self.parameters['beam_parameter_file'])
        if not os.path.isfile(self.parameters['beam_parameter_file']):
            raise IOError("%s is not a file." %
                          (self.parameters['beam_parameter_file']))
        self.parameters['beam_geometry_file'] = checkAndSetInstance(
            str, self.parameters['beam_geometry_file'])
        if not os.path.isfile(self.parameters['beam_geometry_file']):
            raise IOError("%s is not a file." %
                          (self.parameters['beam_geometry_file']))

        self.__expected_data = [
            '/data/snp_<7 digit index>/ff', '/data/snp_<7 digit index>/halfQ',
            '/data/snp_<7 digit index>/Nph', '/data/snp_<7 digit index>/r',
            '/data/snp_<7 digit index>/T', '/data/snp_<7 digit index>/Z',
            '/data/snp_<7 digit index>/xyz',
            '/data/snp_<7 digit index>/Sq_halfQ',
            '/data/snp_<7 digit index>/Sq_bound',
            '/data/snp_<7 digit index>/Sq_free', '/history/parent/detail',
            '/history/parent/parent', '/info/package_version', '/info/contact',
            '/info/data_description', '/info/method_description', '/version'
        ]

        self.__provided_data = [
            '/data/data',
            '/data/diffr',
            '/data/angle',
            '/history/parent/detail',
            '/history/parent/parent',
            '/info/package_version',
            '/info/contact',
            '/info/data_description',
            '/info/method_description',
            '/params/geom/detectorDist',
            '/params/geom/pixelWidth',
            '/params/geom/pixelHeight',
            '/params/geom/mask',
            '/params/beam/photonEnergy',
            '/params/beam/photons',
            '/params/beam/focusArea',
            '/params/info',
        ]