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)
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 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()
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 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)
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))
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.")