def testDataInterfaceQueries(self):
        """ Check that the data interface queries work. """

        # Get test instance.G
        # Setup pmi parameters.
        pmi_parameters = {
            'number_of_trajectories': 1,
            'number_of_steps': 100,
            'sample_path': TestUtilities.generateTestFilePath('sample.h5')
        }
        test_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=self.input_h5,
            output_path='pmi_out.h5',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        # Get expected and provided data descriptors.
        expected_data = test_interactor.expectedData()
        provided_data = test_interactor.providedData()

        # Check types are correct.
        self.assertIsInstance(expected_data, list)
        self.assertIsInstance(provided_data, list)
        for d in expected_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
        for d in provided_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
    def testRotationRandom(self):
        """ Check that by default no rotation is applied and that random rotation has an effect."""

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {
            'number_of_trajectories': 1,
            'number_of_steps': 100,
            'random_rotation': True,
        }

        test_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=self.input_h5,
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        # Call backengine
        status = test_interactor.backengine()

        # Check that the backengine returned zero.
        self.assertEqual(status, 0)

        # Check we have generated the expected output.
        # Check rotation angle.
        with h5py.File(
                os.path.join(test_interactor.output_path,
                             'pmi_out_0000001.h5'), 'r') as h5:
            angle = h5['data/angle'].value[0]

            # Check we have a non-zero rotation.
            self.assertNotEqual(numpy.linalg.norm(angle), 0.)
    def testIssue53(self):
        """ Check that xmdyn_demo writes the Nph variable according to bugfix 53."""

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {
            'number_of_trajectories': 10,
            'number_of_steps': 100,
        }

        pmi = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=self.input_h5,
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('2nip.pdb'))

        # Call backengine
        status = pmi.backengine()

        h5 = h5py.File('pmi/pmi_out_0000001.h5')
        Nph = h5['/data/snp_0000001/Nph']

        self.assertEqual(Nph.shape, (1, ))
    def testBackengine(self):
        """ Check that the backengine method works correctly. """


        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {'number_of_trajectories' : 1,
                          'number_of_steps'        : 100,
                         }

        test_interactor = XMDYNDemoPhotonMatterInteractor(parameters=pmi_parameters,
                                                          input_path=self.input_h5,
                                                          output_path='pmi',
                                                          sample_path = TestUtilities.generateTestFilePath('sample.h5') )

        # Call backengine
        status = test_interactor.backengine()

        # Check that the backengine returned zero.
        self.assertEqual(status, 0)

        # Check we have generated the expected output.
        self.assertTrue( 'pmi_out_0000001.h5' in os.listdir( test_interactor.output_path ) )
    def testBackengine(self):
        """ Check that the backengine method works correctly. """

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {
            'number_of_trajectories': 1,
            'number_of_steps': 100,
        }

        test_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=self.input_h5,
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        # Call backengine
        status = test_interactor.backengine()

        # Check that the backengine returned zero.
        self.assertEqual(status, 0)

        # Check we have generated the expected output.
        self.assertTrue(
            'pmi_out_0000001.h5' in os.listdir(test_interactor.output_path))
    def testDataInterfaceQueries(self):
        """ Check that the data interface queries work. """

        # Get test instance.
        # Setup pmi parameters.
        pmi_parameters = {'number_of_trajectories' : 1,
                          'number_of_steps'        : 100,
                          'sample_path' : TestUtilities.generateTestFilePath('sample.h5')
                         }
        test_interactor = XMDYNDemoPhotonMatterInteractor(parameters=pmi_parameters,
                                                          input_path=self.input_h5,
                                                          output_path='pmi_out.h5',
                                                          sample_path = TestUtilities.generateTestFilePath('sample.h5') )

        # Get expected and provided data descriptors.
        expected_data = test_interactor.expectedData()
        provided_data = test_interactor.providedData()

        # Check types are correct.
        self.assertIsInstance(expected_data, list)
        self.assertIsInstance(provided_data, list)
        for d in expected_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
        for d in provided_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
    def testRotationNone(self):
        """ Check that by default no rotation is applied and that random rotation has an effect."""

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {
            'number_of_trajectories': 1,
            'number_of_steps': 100,
        }

        test_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=self.input_h5,
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        # Call backengine
        status = test_interactor.backengine()

        # Check that the backengine returned zero.
        self.assertEqual(status, 0)

        # Check we have generated the expected output.
        # Check rotation angle.
        with h5py.File(
                os.path.join(test_interactor.output_path,
                             'pmi_out_0000001.h5'), 'r') as h5:
            angle = h5['data/angle'].value
            self.assertEqual(angle[0, 0], 0.)
            self.assertEqual(angle[0, 1], 0.)
            self.assertEqual(angle[0, 2], 0.)
            self.assertEqual(angle[0, 3], 0.)

            # Get atom positions.
            atom_positions = h5['data/snp_0000001/r'].value

        # Now do same calculation again.
        test_interactor.backengine()

        # Get atom positions from new calculation.
        with h5py.File(
                os.path.join(test_interactor.output_path,
                             'pmi_out_0000001.h5'), 'r') as h5:
            new_atom_positions = h5['data/snp_0000001/r'].value

        # They should coincide since no rotation has been applied.
        self.assertAlmostEqual(
            1e10 * numpy.linalg.norm(atom_positions - new_atom_positions), 0.0,
            7)
예제 #8
0
    def testCheckInterfaceConsistency(self):
        """ Test if the check for interface consistency works correctly. """

        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        pmi_parameters = {
            'sample_path': TestUtilities.generateTestFilePath('sample.h5')
        }
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 2,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 1,
            'number_of_diffraction_patterns': 2,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
            'number_of_MPI_processes': 2,
        }
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        interfaces_are_consistent = pxs._checkInterfaceConsistency()

        self.assertTrue(interfaces_are_consistent)
    def testDefaultConstruction(self):
        """ Testing the default construction of the class. """

        # Construct the object.
        interactor = XMDYNDemoPhotonMatterInteractor(
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        self.assertIsInstance(interactor, XMDYNDemoPhotonMatterInteractor)
예제 #10
0
    def testConstruction(self):
        """ Testing the default construction of the class. """

        # Construct the object.
        diffractor = XMDYNDemoPhotonMatterInteractor(parameters=None,
                                                     input_path=self.input_h5,
                                                     output_path='pmi')

        self.assertIsInstance(diffractor, XMDYNDemoPhotonMatterInteractor)
    def testDataInterfaceQueries(self):
        """ Check that the data interface queries work. """

        # Get test instance.
        test_interactor = XMDYNDemoPhotonMatterInteractor(parameters=None, input_path=self.input_h5, output_path='pmi_out.h5')

        # Get expected and provided data descriptors.
        expected_data = test_interactor.expectedData()
        provided_data = test_interactor.providedData()

        # Check types are correct.
        self.assertIsInstance(expected_data, list)
        self.assertIsInstance(provided_data, list)
        for d in expected_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
        for d in provided_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
예제 #12
0
    def testConstruction(self):
        """ Test the default constructor of this class. """
        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 2,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 1,
            'number_of_diffraction_patterns': 2,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
            'number_of_MPI_processes': 2,
        }
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check instance.
        self.assertIsInstance(pxs, PhotonExperimentSimulation)
    def testBackengineDefaultPaths(self):
        """ Check that the backengine method works correctly. """

        # Prepare input.
        shutil.copytree( TestUtilities.generateTestFilePath('prop_out'), os.path.abspath( 'prop' ) )
        self.__dirs_to_remove.append( 'prop' )
        self.__dirs_to_remove.append( 'pmi' )

        test_interactor = XMDYNDemoPhotonMatterInteractor(sample_path=TestUtilities.generateTestFilePath('sample.h5') )

        # Call backengine
        status = test_interactor.backengine()

        # Check that the backengine returned zero.
        self.assertEqual(status, 0)

        # Check we have generated the expected output.
        self.assertTrue( os.path.isdir( os.path.abspath( 'prop' ) ) )
        self.assertIn( 'pmi_out_0000001.h5' , os.listdir( test_interactor.output_path ) )
        self.assertIn( 'pmi_out_0000002.h5' , os.listdir( test_interactor.output_path ) )
    def testLoadPDBFile(self):
        """ Check that the sample can be taken from a pdb directly. """

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {'number_of_trajectories' : 10,
                          'number_of_steps'        : 100,
                         }

        pmi = XMDYNDemoPhotonMatterInteractor(parameters=pmi_parameters,
                                              input_path=self.input_h5,
                                              output_path='pmi',
                                              sample_path=TestUtilities.generateTestFilePath('2nip.pdb') )

        # Call backengine
        status = pmi.backengine()

        self.assertEqual(status, 0 )
    def testOPMD(self):
        """ Check that the input directory scanner filters out the opmd files."""

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Setup parameters.
        pmi_parameters = {'number_of_trajectories' : 10,
                          'number_of_steps'        : 100,
                         }

        test_interactor = XMDYNDemoPhotonMatterInteractor(parameters=pmi_parameters,
                                                          input_path=TestUtilities.generateTestFilePath('prop_out'),
                                                          output_path='pmi',
                                                          sample_path=TestUtilities.generateTestFilePath('sample.h5') )

        # Call backengine
        status = test_interactor.backengine()

        self.assertEqual(status, 0 )
예제 #16
0
    def reference2NIP(self):
        """ Testing that diffraction intensities with 9fs 5keV pulses through SPB-SFX KB beamline are of the order of Yoon 2016. """

        source_file = "/data/netapp/grotec/datadump/5keV_9fs_2015_slice12_fromYoon2016.h5"
        #source_file = TestUtilities.generateTestFilePath("FELsource_out.h5")

        # Propagate
        propagator = XFELPhotonPropagator(parameters=None,
                                          input_path=source_file,
                                          output_path="prop_out.h5")
        propagator.backengine()
        propagator.saveH5()

        pmi = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=propagator.output_path,
            output_path="pmi",
            sample_path=TestUtilities.generateTestFilePath("sample.h5"))
        pmi.backengine()

        #  Diffraction with parameters.
        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 100,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 1,
            'number_of_diffraction_patterns': 1,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
            'number_of_MPI_processes': 8,
        }

        diffractor = SingFELPhotonDiffractor(parameters=diffraction_parameters,
                                             input_path=pmi.output_path,
                                             output_path="diffr_out.h5")
        diffractor.backengine()
예제 #17
0
    def testDataInterfaceQueries(self):
        """ Check that the data interface queries work. """

        # Get test instance.
        test_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=self.input_h5,
            output_path='pmi_out.h5')

        # Get expected and provided data descriptors.
        expected_data = test_interactor.expectedData()
        provided_data = test_interactor.providedData()

        # Check types are correct.
        self.assertIsInstance(expected_data, list)
        self.assertIsInstance(provided_data, list)
        for d in expected_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
        for d in provided_data:
            self.assertIsInstance(d, str)
            self.assertEqual(d[0], '/')
    def testLoadPDBFile(self):
        """ Check that the sample can be taken from a pdb directly. """

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {
            'number_of_trajectories': 10,
            'number_of_steps': 100,
        }

        pmi = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=self.input_h5,
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('2nip.pdb'))

        # Call backengine
        status = pmi.backengine()

        self.assertEqual(status, 0)
    def testOPMD(self):
        """ Check that the input directory scanner filters out the opmd files."""

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Setup parameters.
        pmi_parameters = {
            'number_of_trajectories': 10,
            'number_of_steps': 100,
        }

        test_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            input_path=TestUtilities.generateTestFilePath('prop_out'),
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        # Call backengine
        status = test_interactor.backengine()

        self.assertEqual(status, 0)
    def testIssue53(self):
        """ Check that xmdyn_demo writes the Nph variable according to bugfix 53."""

        # Clean up.
        self.__dirs_to_remove.append('pmi')

        # Get test instance.
        pmi_parameters = {'number_of_trajectories' : 10,
                          'number_of_steps'        : 100,
                         }

        pmi = XMDYNDemoPhotonMatterInteractor(parameters=pmi_parameters,
                                              input_path=self.input_h5,
                                              output_path='pmi',
                                              sample_path=TestUtilities.generateTestFilePath('2nip.pdb') )

        # Call backengine
        status = pmi.backengine()

        h5 = h5py.File('pmi/pmi_out_0000001.h5')
        Nph = h5['/data/snp_0000001/Nph']

        self.assertEqual(Nph.shape, (1,))
    def testBackengineDefaultPaths(self):
        """ Check that the backengine method works correctly. """

        # Prepare input.
        shutil.copytree(TestUtilities.generateTestFilePath('prop_out'),
                        os.path.abspath('prop'))
        self.__dirs_to_remove.append('prop')
        self.__dirs_to_remove.append('pmi')

        test_interactor = XMDYNDemoPhotonMatterInteractor(
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        # Call backengine
        status = test_interactor.backengine()

        # Check that the backengine returned zero.
        self.assertEqual(status, 0)

        # Check we have generated the expected output.
        self.assertTrue(os.path.isdir(os.path.abspath('prop')))
        self.assertIn('pmi_out_0000001.h5',
                      os.listdir(test_interactor.output_path))
        self.assertIn('pmi_out_0000002.h5',
                      os.listdir(test_interactor.output_path))
예제 #22
0
    def testCheckInterfaceConsistency(self):
        """ Test if the check for interface consistency works correctly. """

        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        pmi_parameters = {
            'sample_path': TestUtilities.generateTestFilePath('sample.h5')
        }
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = self.diffractorParam_1
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        interfaces_are_consistent = pxs._checkInterfaceConsistency()

        self.assertTrue(interfaces_are_consistent)
예제 #23
0
    def testCalculatorQueries(self):
        """ Test that the calculator queries return the correct calculators. """
        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = self.diffractorParam_2
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check queries.
        self.assertIs(pxs.photon_source, photon_source)
        self.assertIs(pxs.photon_propagator, photon_propagator)
        self.assertIs(pxs.photon_interactor, photon_interactor)
        self.assertIs(pxs.photon_diffractor, photon_diffractor)
        self.assertIs(pxs.photon_detector, photon_detector)
        self.assertIs(pxs.photon_analyzer, photon_analyzer)
    def testShapedConstruction(self):
        """ Testing the construction of the class with parameters. """

        # Setup pmi parameters.
        pmi_parameters = {
            'number_of_trajectories': 1,
            'number_of_steps': 100,
        }

        interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=pmi_parameters,
            output_path='pmi_out',
            input_path='pmi_in',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'),
        )

        self.assertIsInstance(interactor, XMDYNDemoPhotonMatterInteractor)
예제 #25
0
    def testConstruction(self):
        """ Test the default constructor of this class. """
        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = self.diffractorParam_1
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check instance.
        self.assertIsInstance(pxs, PhotonExperimentSimulation)
    def testSimS2EWorkflowDirectories(self):
        """ Testing that a workflow akin to the simS2E example workflow works.
            Two sources, two diffraction patterns."""

        # Setup directories.
        working_directory = 'SPI'
        source_dir = os.path.join(working_directory, 'FELsource')
        prop_dir = os.path.join(working_directory, 'prop')
        pmi_dir = os.path.join(working_directory, 'pmi')
        diffr_dir = os.path.join(working_directory, 'diffr')
        detector_dir = os.path.join(working_directory, 'detector')
        recon_dir = os.path.join(working_directory, 'recon')

        # Make directories.
        os.mkdir(working_directory)
        os.mkdir(source_dir)
        os.mkdir(prop_dir)
        os.mkdir(pmi_dir)
        os.mkdir(diffr_dir)
        os.mkdir(detector_dir)
        os.mkdir(recon_dir)

        # Ensure proper cleanup.
        self.__dirs_to_remove.append(working_directory)

        # Location of the FEL source file.
        source_input = TestUtilities.generateTestFilePath('FELsource_out')

        # Photon source.
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path=source_dir)

        # Photon propagator, default parameters.
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path=source_dir,
                                                 output_path=prop_dir)

        # Photon interactor with default parameters.
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=prop_dir,
            output_path=pmi_dir,
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        #  Diffraction with parameters.
        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 2,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 2,
            'number_of_diffraction_patterns': 2,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
        }

        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=pmi_dir,
            output_path=diffr_dir)

        # Reconstruction: EMC+DM
        emc_parameters = {
            'initial_number_of_quaternions': 1,
            'max_number_of_quaternions': 9,
            'max_number_of_iterations': 3,
            'min_error': 1.0e-8,
            'beamstop': 1.0e-5,
            'detailed_output': False
        }

        dm_parameters = {
            'number_of_trials': 5,
            'number_of_iterations': 2,
            'averaging_start': 15,
            'leash': 0.2,
            'number_of_shrink_cycles': 2,
        }

        reconstructor = S2EReconstruction(parameters={
            'EMC_Parameters': emc_parameters,
            'DM_Parameters': dm_parameters
        },
                                          input_path=diffr_dir,
                                          output_path=recon_dir)

        # Setup the photon experiment.
        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=None,
            photon_analyzer=reconstructor,
        )

        # Run the experiment.
        pxs.run()
    def testSimS2EWorkflowSingleFile(self):
        """ Testing that a workflow akin to the simS2E example workflow works. Only one I/O file per calculator. """

        # These directories and files are expected to be present after a successfull calculation.
        expected_dirs = [
            'pmi',
            'diffr',
        ]

        expected_symlinks = ['detector']

        expected_files = [
            'FELsource_out.h5',
            'prop_out.h5',
            'pmi/pmi_out_0000001.h5',
            'diffr/diffr_out_0000001.h5',
            'detector/diffr_out_0000001.h5',
            'recon.h5',
            'orient_out.h5',
        ]

        # Ensure proper cleanup.
        self.__files_to_remove = expected_files + expected_symlinks
        self.__files_to_remove.append('prepHDF5.py')
        self.__dirs_to_remove = expected_dirs

        # Location of the FEL source file.
        source_input = TestUtilities.generateTestFilePath(
            'FELsource_out/FELsource_out_0000001.h5')

        # Photon source.
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')

        # Photon propagator, default parameters.
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')

        # Photon interactor with default parameters.
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path='prop_out.h5',
            output_path='pmi',
            sample_path=TestUtilities.generateTestFilePath('sample.h5'))

        #  Diffraction with parameters.
        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 2,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 1,
            'number_of_diffraction_patterns': 1,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
        }

        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path='pmi',
            output_path='diffr')

        # Perfect detector.
        photon_detector = PerfectPhotonDetector(parameters=None,
                                                input_path='diffr',
                                                output_path='detector')

        # Reconstruction: EMC+DM
        emc_parameters = {
            'initial_number_of_quaternions': 1,
            'max_number_of_quaternions': 9,
            'max_number_of_iterations': 3,
            'min_error': 1.0e-8,
            'beamstop': 1.0e-5,
            'detailed_output': False
        }

        dm_parameters = {
            'number_of_trials': 5,
            'number_of_iterations': 2,
            'averaging_start': 15,
            'leash': 0.2,
            'number_of_shrink_cycles': 2,
        }

        reconstructor = S2EReconstruction(parameters={
            'EMC_Parameters': emc_parameters,
            'DM_Parameters': dm_parameters
        },
                                          input_path='detector',
                                          output_path='recon.h5')

        # Setup the photon experiment.
        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=reconstructor,
        )

        # Run the experiment.
        pxs.run()

        # Check that all output files and directories are present.
        for directory in expected_dirs + expected_symlinks:
            self.assertTrue(os.path.isdir(directory))
        for f in expected_files:
            print f
            self.assertTrue(os.path.isfile(f))
예제 #28
0
from SimEx.PhotonExperimentSimulation.PhotonExperimentSimulation import PhotonExperimentSimulation


# Location of the FEL source file.
source_input = TestUtilities.generateTestFilePath('FELsource_out/FELsource_out_0000001.h5')

# Photon source.
photon_source = XFELPhotonSource(parameters=None, input_path=source_input, output_path='FELsource_out_0000001.h5')

# Photon propagator, default parameters.
photon_propagator = XFELPhotonPropagator(parameters=None, input_path='FELsource_out_0000001.h5', output_path='prop_out_0000001.h5')

# Photon interactor with default parameters.
pmi_parameters= {'sample_path' :TestUtilities.generateTestFilePath('sample.h5')}
photon_interactor = XMDYNDemoPhotonMatterInteractor( parameters=pmi_parameters,
                                                     input_path='prop_out_0000001.h5',
                                                     output_path='pmi')

#  Diffraction with parameters.
diffraction_parameters={ 'uniform_rotation': 1,
             'calculate_Compton' : False,
             'slice_interval' : 100,
             'number_of_slices' : 2,
             'pmi_start_ID' : 1,
             'pmi_stop_ID'  : 1,
             'number_of_diffraction_patterns' : 2,
             'beam_parameter_file' : TestUtilities.generateTestFilePath('s2e.beam'),
             'beam_geometry_file' : TestUtilities.generateTestFilePath('s2e.geom'),
             }

photon_diffractor = SingFELPhotonDiffractor(
예제 #29
0
    def testSimS2EWorkflowDefaultPaths(self):
        """ Testing that a workflow akin to the simS2E example workflow works. No IO paths specified. """

        # These directories and files are expected to be present after a successfull calculation.
        expected_dirs = [
            'source_in',
            'source',
            'prop',
            'pmi',
            'diffr',
            'analysis',
        ]

        expected_files = [
            'source/FELsource_out_0000000.h5',
            'source/FELsource_out_0000001.h5',
            'prop/prop_out_0000000.h5',
            'prop/prop_out_0000001.h5',
            'pmi/pmi_out_0000001.h5',
            'pmi/pmi_out_0000002.h5',
            'diffr/diffr_out_0000001.h5',
            'analysis/orient_out.h5',
            'analysis/phase_out.h5',
        ]

        # Ensure proper cleanup.
        self.__dirs_to_remove = expected_dirs
        self.__files_to_remove.append('diffr.h5')
        self.__files_to_remove.append('detector')

        # Get proper FEL source files to start from.
        shutil.copytree(TestUtilities.generateTestFilePath('FELsource_out'),
                        'source_in')

        # Photon source.
        photon_source = XFELPhotonSource(input_path='source_in')

        # Photon propagator, default parameters.
        photon_propagator = XFELPhotonPropagator()

        # Photon interactor with default parameters.
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            sample_path=self.__sample_path)

        #  Diffraction with parameters.
        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 2,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 2,
            'number_of_diffraction_patterns': 1,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
            'number_of_MPI_processes': 2
        }

        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=TestUtilities.generateTestFilePath('pmi_out'))

        photon_diffractor.parameters.cpus_per_task = 1

        # Reconstruction: EMC+DM
        emc_parameters = {
            'initial_number_of_quaternions': 1,
            'max_number_of_quaternions': 2,
            'max_number_of_iterations': 10,
            'min_error': 1.0e-6,
            'beamstop': True,
            'detailed_output': False
        }

        dm_parameters = {
            'number_of_trials': 5,
            'number_of_iterations': 2,
            'averaging_start': 15,
            'leash': 0.2,
            'number_of_shrink_cycles': 2,
        }

        reconstructor = S2EReconstruction(parameters={
            'EMC_Parameters': emc_parameters,
            'DM_Parameters': dm_parameters
        })

        # Setup the photon experiment.
        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_analyzer=reconstructor,
        )

        # Run the experiment.
        pxs.run()

        # Check that all output files and directories are present.
        for directory in expected_dirs:
            print(directory)
            self.assertTrue(os.path.isdir(directory))
        for f in expected_files:
            print(f)
            self.assertTrue(os.path.isfile(f))
예제 #30
0
    def testHistory(self):
        """ Testing that all generated output files contain the history """

        # Setup directories.
        working_directory = 'SPI'
        self.__dirs_to_remove.append(working_directory)

        source_dir = os.path.join(working_directory, 'FELsource')
        prop_dir = os.path.join(working_directory, 'prop')
        pmi_dir = os.path.join(working_directory, 'pmi')
        diffr_dir = os.path.join(working_directory, 'diffr')
        detector_dir = os.path.join(working_directory, 'detector')
        recon_dir = os.path.join(working_directory, 'recon')

        # Make directories.
        os.mkdir(working_directory)
        os.mkdir(source_dir)
        os.mkdir(prop_dir)
        os.mkdir(pmi_dir)
        os.mkdir(diffr_dir)
        os.mkdir(detector_dir)
        os.mkdir(recon_dir)

        # Location of the FEL source file.
        source_input = TestUtilities.generateTestFilePath('FELsource_out')

        # Photon source.
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path=source_dir)

        # Photon propagator, default parameters.
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path=source_dir,
                                                 output_path=prop_dir)

        # Photon interactor with default parameters.
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=prop_dir,
            output_path=pmi_dir,
            sample_path=self.__sample_path)

        #  Diffraction with parameters.
        diffraction_parameters = self.diffractorParam_2

        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=TestUtilities.generateTestFilePath('pmi_out'),
            output_path=diffr_dir)

        # Reconstruction: EMC+DM
        emc_parameters = {
            'initial_number_of_quaternions': 1,
            'max_number_of_quaternions': 9,
            'max_number_of_iterations': 3,
            'min_error': 1.0e-8,
            'beamstop': True,
            'detailed_output': False
        }

        dm_parameters = {
            'number_of_trials': 5,
            'number_of_iterations': 2,
            'averaging_start': 15,
            'leash': 0.2,
            'number_of_shrink_cycles': 2,
        }

        reconstructor = S2EReconstruction(parameters={
            'EMC_Parameters': emc_parameters,
            'DM_Parameters': dm_parameters
        },
                                          input_path=diffr_dir,
                                          output_path=recon_dir)

        # Perfect detector.
        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr',
                                              output_path='detector')

        # Setup the photon experiment.
        pxs = PhotonExperimentSimulation(
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=reconstructor,
        )

        # Run the experiment.
        pxs.run()

        # Check histories.
        # prop.
        with h5py.File(os.path.join(prop_dir, 'prop_out_0000000.h5'),
                       'r') as prop_h5:
            self.assertIn('history', list(prop_h5.keys()))
            self.assertIn('parent', list(prop_h5['history'].keys()))
            self.assertIn('detail', list(prop_h5['history/parent'].keys()))
            self.assertIn('parent', list(prop_h5['history/parent'].keys()))

            prop_h5.close()

        # pmi.
        with h5py.File(os.path.join(pmi_dir, 'pmi_out_0000001.h5'),
                       'r') as pmi_h5:

            self.assertIn('history', list(pmi_h5.keys()))
            self.assertIn('parent', list(pmi_h5['history'].keys()))
            self.assertIn('detail', list(pmi_h5['history/parent'].keys()))
            self.assertIn('parent', list(pmi_h5['history/parent'].keys()))
            self.assertIn('detail',
                          list(pmi_h5['history/parent/parent'].keys()))
            self.assertIn('parent',
                          list(pmi_h5['history/parent/parent'].keys()))

            pmi_h5.close()

        # diffr.
        with h5py.File(os.path.join(diffr_dir, 'diffr_out_0000001.h5'),
                       'r') as diffr_h5:

            tasks = list(diffr_h5['data'].keys())
            for task in tasks:
                self.assertIn('history', list(diffr_h5["data"][task].keys()))
                self.assertIn('parent',
                              list(diffr_h5["data"][task]['history'].keys()))
                self.assertIn(
                    'detail',
                    list(diffr_h5["data"][task]['history/parent'].keys()))
                self.assertIn(
                    'parent',
                    list(diffr_h5["data"][task]['history/parent'].keys()))
                self.assertIn(
                    'parent',
                    list(diffr_h5["data"][task]
                         ['history/parent/parent'].keys()))
                self.assertIn(
                    'detail',
                    list(diffr_h5["data"][task]
                         ['history/parent/parent'].keys()))
                self.assertIn(
                    'parent',
                    list(diffr_h5["data"][task]
                         ['history/parent/parent/parent'].keys()))
                self.assertIn(
                    'detail',
                    list(diffr_h5["data"][task]
                         ['history/parent/parent/parent'].keys()))

            diffr_h5.close()

        # phase.
        with h5py.File(os.path.join(recon_dir, 'phase_out.h5'), 'r') as dm_h5:

            self.assertIn('history', list(dm_h5.keys()))
            self.assertIn('error', list(dm_h5['history'].keys()))
            self.assertIn('object', list(dm_h5['history'].keys()))

            dm_h5.close()
예제 #31
0
    def testConstructionExceptions(self):
        """ Test that the appropriate exceptions are thrown if the object is constructed incorrectly. """
        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = self.diffractorParam_1
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        # Check wrong source.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=None,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_propagator,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong propagator.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=None,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_source,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong interactor.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=None,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_source,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong diffractor.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=None,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_source,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong analyzer.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=None,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_diffractor,
        )
예제 #32
0
    def testConstructionExceptions(self):
        """ Test that the appropriate exceptions are thrown if the object is constructed incorrectly. """
        # Setup a minimal experiment simulation.
        source_input = TestUtilities.generateTestFilePath('FELsource_out.h5')
        diffr_input = TestUtilities.generateTestFilePath('pmi_out_0000001.h5')
        pmi_input = TestUtilities.generateTestFilePath('prop_out.h5')
        photon_source = XFELPhotonSource(parameters=None,
                                         input_path=source_input,
                                         output_path='FELsource_out.h5')
        photon_propagator = XFELPhotonPropagator(parameters=None,
                                                 input_path='FELsource_out.h5',
                                                 output_path='prop_out.h5')
        photon_interactor = XMDYNDemoPhotonMatterInteractor(
            parameters=None,
            input_path=pmi_input,
            output_path='pmi_out.h5',
            sample_path=self.__sample_path)

        diffraction_parameters = {
            'uniform_rotation': True,
            'calculate_Compton': False,
            'slice_interval': 100,
            'number_of_slices': 2,
            'pmi_start_ID': 1,
            'pmi_stop_ID': 1,
            'number_of_diffraction_patterns': 2,
            'beam_parameter_file':
            TestUtilities.generateTestFilePath('s2e.beam'),
            'beam_geometry_file':
            TestUtilities.generateTestFilePath('s2e.geom'),
            'number_of_MPI_processes': 2,
        }
        photon_diffractor = SingFELPhotonDiffractor(
            parameters=diffraction_parameters,
            input_path=diffr_input,
            output_path='diffr_out.h5')

        photon_detector = IdealPhotonDetector(parameters=None,
                                              input_path='diffr_out.h5',
                                              output_path='detector_out.h5')
        photon_analyzer = S2EReconstruction(parameters=None,
                                            input_path='detector_out.h5',
                                            output_path='analyzer_out.h5')

        # Check wrong source.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=None,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_propagator,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong propagator.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=None,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_source,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong interactor.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=None,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_source,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong diffractor.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=None,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_source,
            photon_detector=photon_detector,
            photon_analyzer=photon_analyzer,
        )

        # Check wrong analyzer.
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=None,
        )
        self.assertRaises(
            TypeError,
            PhotonExperimentSimulation,
            photon_source=photon_source,
            photon_propagator=photon_propagator,
            photon_interactor=photon_interactor,
            photon_diffractor=photon_diffractor,
            photon_detector=photon_detector,
            photon_analyzer=photon_diffractor,
        )
예제 #33
0
    'FELsource_out/FELsource_out_0000001.h5')

# Photon source.
photon_source = XFELPhotonSource(parameters=None,
                                 input_path=source_input,
                                 output_path='FELsource_out_0000001.h5')

# Photon propagator, default parameters.
photon_propagator = XFELPhotonPropagator(parameters=None,
                                         input_path='FELsource_out_0000001.h5',
                                         output_path='prop_out_0000001.h5')

# Photon interactor with default parameters.
photon_interactor = XMDYNDemoPhotonMatterInteractor(
    parameters=None,
    input_path='prop_out_0000001.h5',
    output_path='pmi',
    sample_path=TestUtilities.generateTestFilePath('sample.h5'))

#  Diffraction with parameters.
diffraction_parameters = {
    'uniform_rotation': 1,
    'calculate_Compton': False,
    'slice_interval': 100,
    'number_of_slices': 2,
    'pmi_start_ID': 1,
    'pmi_stop_ID': 1,
    'number_of_diffraction_patterns': 2,
    'beam_parameter_file': TestUtilities.generateTestFilePath('s2e.beam'),
    'beam_geometry_file': TestUtilities.generateTestFilePath('s2e.geom'),
}
예제 #34
0
파일: pmi.py 프로젝트: syam-s/SimEx
import sys
from SimEx.Calculators.XMDYNDemoPhotonMatterInteractor import XMDYNDemoPhotonMatterInteractor

# Define the input path (location of propagated pulse data).
prop_path = "prop_out/prop_s2e_example.h5"

# Define the sample as pdb code + ".pdb" extension.
sample="2NIP.pdb"

# Setup propagation parameters.
parameters=None

# Construct the propagator
pmi_calculator = XMDYNDemoPhotonMatterInteractor( parameters=parameters, input_path=prop_path,
        sample_path=sample)

# Read the data.
pmi_calculator._readH5()

# Call the backengine.
status = pmi_calculator.backengine()

if status != 0:
    print("PMI calculation failed, check output.")
    sys.exit()

print("PMI calculation succeeded.")