def testOutputPath(self): """ Check that the default path is set correctly. """ # Setup the calculator. feff = FEFFPhotonMatterInteractor(parameters=self.__parameters) self.__dirs_to_remove.append('pmi') # Execute the code. status = feff.backengine() # Check that the pmi dir was created. self.assertTrue(os.path.isdir('pmi'))
def testShapedConstructionPaths(self): """ Testing the construction of the class with parameters. """ # Construct. feff = FEFFPhotonMatterInteractor( parameters=self.__parameters, input_path=TestUtilities.generateTestFilePath('prop'), output_path='absorption.h5') # Check type. self.assertIsInstance(feff, FEFFPhotonMatterInteractor) # Get parameters and check. parameters = feff.parameters self.assertEqual(parameters.atoms, self.__atoms) self.assertEqual(parameters.potentials, self.__potentials) self.assertEqual(parameters.edge, self.__edge) self.assertEqual(parameters.amplitude_reduction_factor, self.__amplitude_reduction_factor) self.assertEqual(parameters.effective_path_distance, self.__effective_path_distance) self.assertEqual(feff.output_path, os.path.join(os.getcwd(), 'absorption.h5'))
def testBackengine(self): """ Test the backengine execution. """ # Setup the calculator. feff = FEFFPhotonMatterInteractor(parameters=self.__parameters) self.__dirs_to_remove.append('pmi') # Execute the code. status = feff.backengine() # Check success. self.assertEqual(status, 0) # Check directory content. self.assertIn('atoms.dat', os.listdir(feff.working_directory)) self.assertIn('chi.dat', os.listdir(feff.working_directory)) self.assertIn('feff.bin', os.listdir(feff.working_directory)) self.assertIn('feff.inp', os.listdir(feff.working_directory)) self.assertIn('feff85L', os.listdir(feff.working_directory)) self.assertIn('fort.38', os.listdir(feff.working_directory)) self.assertIn('fort.39', os.listdir(feff.working_directory)) self.assertIn('fpf0.dat', os.listdir(feff.working_directory)) self.assertIn('geom.dat', os.listdir(feff.working_directory)) self.assertIn('global.dat', os.listdir(feff.working_directory)) self.assertIn('list.dat', os.listdir(feff.working_directory)) self.assertIn('log.dat', os.listdir(feff.working_directory)) self.assertIn('log1.dat', os.listdir(feff.working_directory)) self.assertIn('log2.dat', os.listdir(feff.working_directory)) self.assertIn('log4.dat', os.listdir(feff.working_directory)) self.assertIn('log5.dat', os.listdir(feff.working_directory)) self.assertIn('log6.dat', os.listdir(feff.working_directory)) self.assertIn('mod1.inp', os.listdir(feff.working_directory)) self.assertIn('mod2.inp', os.listdir(feff.working_directory)) self.assertIn('mod3.inp', os.listdir(feff.working_directory)) self.assertIn('mod4.inp', os.listdir(feff.working_directory)) self.assertIn('mod5.inp', os.listdir(feff.working_directory)) self.assertIn('mod6.inp', os.listdir(feff.working_directory)) self.assertIn('mpse.dat', os.listdir(feff.working_directory)) self.assertIn('paths.dat', os.listdir(feff.working_directory)) self.assertIn('phase.bin', os.listdir(feff.working_directory)) self.assertIn('pot.bin', os.listdir(feff.working_directory)) self.assertIn('s02.inp', os.listdir(feff.working_directory)) self.assertIn('xmu.dat', os.listdir(feff.working_directory)) self.assertIn('xsect.bin', os.listdir(feff.working_directory))
def testWorkingDirectorySetup(self): """ Test the initialization of the working directory. """ # Requirements: # - By default, setup tmp dir, copy executable and write serialize parameters # - User may specify working directory ### TODO # - If feff.inp already exists: backup and overwrite. ### TODO # - enhancement: initialize parameters from given feff.inp ### TODO # Test default behavior. self.__dirs_to_remove.append('pmi') feff = FEFFPhotonMatterInteractor(parameters=self.__parameters) # Setup working directory. feff._setupWorkingDirectory() # Assert it is created. self.assertTrue(os.path.isdir(feff.working_directory))
def testShapedConstruction(self): """ Testing the construction of the class with parameters. """ # Construct. self.__dirs_to_remove.append( 'pmi' ) feff = FEFFPhotonMatterInteractor(parameters=self.__parameters) # Check type. self.assertIsInstance( feff, FEFFPhotonMatterInteractor ) # Get parameters and check. parameters = feff.parameters self.assertEqual( parameters.atoms, self.__atoms) self.assertEqual( parameters.potentials, self.__potentials) self.assertEqual( parameters.edge, self.__edge) self.assertEqual( parameters.amplitude_reduction_factor, self.__amplitude_reduction_factor) self.assertEqual( parameters.effective_path_distance, self.__effective_path_distance)
def testSaveH5(self): # Setup the calculator. feff = FEFFPhotonMatterInteractor(parameters=self.__parameters, output_path='feff.h5') self.__files_to_remove.append(feff.output_path) # Execute the code. status = feff.backengine() # Save. feff.saveH5() # Check content of newly generated file. expected_sets = [ 'data/snp_0000001/r', #'data/snp_0000001/xyz', #'data/snp_0000001/Z', #'data/snp_0000001/T', 'data/snp_0000001/E', 'data/snp_0000001/DeltaE', 'data/snp_0000001/k', 'data/snp_0000001/mu', 'data/snp_0000001/mu0', 'data/snp_0000001/chi', 'data/snp_0000001/ampl', 'data/snp_0000001/phase', 'data/snp_0000001/potential_index', 'params/amplitude_reduction_factor', 'params/edge', 'params/effective_path_distance', #'history/parent', #'misc/polarization_tensor', #'misc/evec', #'misc/xivec', #'misc/spvec', #'misc/nabs', #'misc/iphabs', #'misc/cf_average_data', #'misc/ipol', #'misc/ispin', #'misc/le2', #'misc/elpty', #'misc/angks', 'info/contact', 'info/data_description', 'info/interface_version', 'info/credits', 'info/package_version', ] with h5py.File(feff.output_path, 'r') as h5: for st in expected_sets: self.assertIsInstance(h5[st], h5py.Dataset) # Check attributes self.assertEqual(h5['data/snp_0000001/r'].attrs['unit'], 'Angstrom') self.assertEqual(h5['data/snp_0000001/E'].attrs['unit'], 'eV') self.assertEqual(h5['data/snp_0000001/DeltaE'].attrs['unit'], 'eV') self.assertEqual(h5['data/snp_0000001/k'].attrs['unit'], '1') self.assertEqual(h5['data/snp_0000001/mu'].attrs['unit'], '1/Angstrom') self.assertEqual(h5['data/snp_0000001/mu0'].attrs['unit'], '1/Angstrom') self.assertEqual(h5['data/snp_0000001/chi'].attrs['unit'], '1') self.assertEqual(h5['data/snp_0000001/ampl'].attrs['unit'], '1') self.assertEqual(h5['data/snp_0000001/phase'].attrs['unit'], 'rad') self.assertEqual( h5['data/snp_0000001/potential_index'].attrs['unit'], '1') self.assertEqual( h5['params/amplitude_reduction_factor'].attrs['unit'], '1') self.assertEqual(h5['params/edge'].attrs['unit'], '') self.assertEqual( h5['params/effective_path_distance'].attrs['unit'], 'Angstrom') h5.close()