Loading sample_simulation_mcvine/base/scatterer-xml.py 0 → 100644 +52 −0 Original line number Diff line number Diff line def grid_sq_kernel(histogram_hdf_path, q_range_start, q_range_end): """ Generates XML code for a homogeneous scatterer with parameterized histogram-hdf-path and Q-range values. Parameters: - histogram_hdf_path (str): Path to the histogram file. - q_range_start (float): Start value of the Q-range. - q_range_end (float): End value of the Q-range. Returns: - str: XML code with the specified parameters. """ xml_template = """<?xml version="1.0"?> <!DOCTYPE scatterer> <!-- mcweights: monte-carlo weights for 3 possible processes: absorption, scattering, transmission --> <!--homogeneous_scatterer mcweights="0.333, 0.333, 0.333" max_multiplescattering_loops="1" --> <homogeneous_scatterer> <KernelContainer average="yes"> <!-- <Phonon_IncoherentElastic_Kernel dw_core='0.00701434948808*angstrom**2'> </Phonon_IncoherentElastic_Kernel> --> <SQkernel Q-range='{q_range_start}*angstrom**-1,{q_range_end}*angstrom**-1'> <GridSQ histogram-hdf-path="{histogram_hdf_path}" auto-normalization='1'/> </SQkernel> </KernelContainer> </homogeneous_scatterer> <!-- weights: absorption, scattering, transmission --> """ text = xml_template.format( histogram_hdf_path=histogram_hdf_path, q_range_start=q_range_start, q_range_end=q_range_end ) with open(os.path.join('{}', '{}-scatterer.xml').format(pathTosave, sampleName), "w") as sam_new: sam_new.write(text) # Example usage #histogram_path = "example_path.h5/S" #q_range_start = 1.5 #q_range_end = 11.5 #xml_code = generate_scatterer_xml(histogram_path, q_range_start, q_range_end) #print(xml_code) Loading
sample_simulation_mcvine/base/scatterer-xml.py 0 → 100644 +52 −0 Original line number Diff line number Diff line def grid_sq_kernel(histogram_hdf_path, q_range_start, q_range_end): """ Generates XML code for a homogeneous scatterer with parameterized histogram-hdf-path and Q-range values. Parameters: - histogram_hdf_path (str): Path to the histogram file. - q_range_start (float): Start value of the Q-range. - q_range_end (float): End value of the Q-range. Returns: - str: XML code with the specified parameters. """ xml_template = """<?xml version="1.0"?> <!DOCTYPE scatterer> <!-- mcweights: monte-carlo weights for 3 possible processes: absorption, scattering, transmission --> <!--homogeneous_scatterer mcweights="0.333, 0.333, 0.333" max_multiplescattering_loops="1" --> <homogeneous_scatterer> <KernelContainer average="yes"> <!-- <Phonon_IncoherentElastic_Kernel dw_core='0.00701434948808*angstrom**2'> </Phonon_IncoherentElastic_Kernel> --> <SQkernel Q-range='{q_range_start}*angstrom**-1,{q_range_end}*angstrom**-1'> <GridSQ histogram-hdf-path="{histogram_hdf_path}" auto-normalization='1'/> </SQkernel> </KernelContainer> </homogeneous_scatterer> <!-- weights: absorption, scattering, transmission --> """ text = xml_template.format( histogram_hdf_path=histogram_hdf_path, q_range_start=q_range_start, q_range_end=q_range_end ) with open(os.path.join('{}', '{}-scatterer.xml').format(pathTosave, sampleName), "w") as sam_new: sam_new.write(text) # Example usage #histogram_path = "example_path.h5/S" #q_range_start = 1.5 #q_range_end = 11.5 #xml_code = generate_scatterer_xml(histogram_path, q_range_start, q_range_end) #print(xml_code)