Warning: Trying to access array offset on value of type null in /home/site/wwwroot/lib/plugins/move/action/rename.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/site/wwwroot/lib/plugins/move/action/rename.php:42) in /home/site/wwwroot/inc/Action/Export.php on line 106

Warning: Cannot modify header information - headers already sent by (output started at /home/site/wwwroot/lib/plugins/move/action/rename.php:42) in /home/site/wwwroot/inc/Action/Export.php on line 106
xml_from_xdds

xml_from_xdds

Macros for the creation of xml files from within a TOPAS .inp file. xml_from_xdds will create an xml file with a separate entry for each xdd within the .inp file, and a separate entry for each str within each xdd. Rietveld statistics, lattice parameters, weight percents and the fit data are all stored. The xml files are a structured format which can be easily used to read the refinement results into other software, such as Python. I recommend using this code to get the xml file into a Python dictionary for further manipulation. This is particularly valuable when working with large datasets, such as variable temperature data collections or analysing maps of diffraction data.

macro xml_create(file) { out file Out_String("<root>") }
 
macro xml_add(file,name,value) {
	out file append
	Out_String("\n\t<") Out_String(name) Out(value,">%e") Out_String("</") Out_String(name) Out_String(">")
}
 
macro xml_close(file) { out file append Out_String("\n</root>") }
 
macro xml_from_xdds(file,append_to_file) {
	#m_ifarg append_to_file 1
		out file append
	#m_else
		out file
		Out_String("<root>")
	#m_endif
		Out(Get(r_wp), "\n\t<r_wp>%V</r_wp>")
		Out(Get(r_exp), "\n\t<r_exp>%V</r_exp>")
		Out(Get(gof), "\n\t<gof>%V</gof>")
		for xdds { Out_String("\n\t<xdd>")
			Out(Get(r_wp), "\n\t\t<r_wp>%V</r_wp>")
			Out(Get(r_exp), "\n\t\t<r_exp>%V</r_exp>")
			Out(Get(gof), "\n\t\t<gof>%V</gof>")
			Out(Get(mixture_density_g_on_cm3), "\n\t\t<mixture_density>%4.8f") Out_String("</mixture_density>")
			for strs { Out_String("\n\t\t<str>")
				Out(Get(phase_name), "\n\t\t\t<phase_name>%s</phase_name>")
				Out(Get(r_bragg), "\n\t\t\t<r_bragg>%V</r_bragg>")
				Out_String("\n\t\t\t<unit_cell>")
					Out(Get(sp_grp_char), "\n\t\t\t\t<space_group>%s</space_group>")
					Out(Get(a), "\n\t\t\t\t<a>%V</a>")
					Out(Get(b), "\n\t\t\t\t<b>%V</b>")
					Out(Get(c), "\n\t\t\t\t<c>%V</c>")
					Out(Get(al), "\n\t\t\t\t<al>%V</al>")
					Out(Get(be), "\n\t\t\t\t<be>%V</be>")
					Out(Get(ga), "\n\t\t\t\t<ga>%V</ga>")
					Out(Get(cell_volume), "\n\t\t\t\t<volume>%V</volume>")
					Out(1.6605402 Get(cell_mass) / Get(cell_volume), "\n\t\t\t\t<density>%4.8f") Out_String("</density>")
				Out_String("\n\t\t\t</unit_cell>")
				Out(Get(weight_percent), "\n\t\t\t<weight_percent>%V</weight_percent>")
				Out(Get(scale) Get(all_scale_pks), "\n\t\t\t<relative_scale>%e") Out_String("</relative_scale>")
				Out(Get(numerical_area), "\n\t\t\t<numerical_area>%V</numerical_area>")
			Out_String("\n\t\t</str>") } 
			Out_String("\n\t\t<data>")
				xdd_out file append load out_record out_fmt out_eqn
				{
	          "\n\t\t\t<X>%0.6f</X>" = X;
	          "<Y>%0.6f</Y>"         = Yobs;
	          "<Ycalc>%0.6f</Ycalc>" = Ycalc;
	          "<Diff>%0.6f</Diff>"   = Yobs-Ycalc;
				}
			out file append
			Out_String("\n\t\t</data>")
		Out_String("\n\t</xdd>") }
	#m_ifarg append_to_file 1
	#m_else
		Out_String("\n</root>")
	#m_endif
	}
macro xml_from_xdds(file) { xml_from_xdds(file,0) }

Example usage 1 - Create a file using the default values stored by xml_from_xdds

Simply add the following towards the end of your .inp file.

xml_from_xdds("myfilename.xml")

Example usage 2 - Adding your own values to the xml file, then using xml_from_xdds to append to the same file

The use of xml_from_xdds writes out the standard data you want want from a refinement, but doesn't allow for the easy addition of other parameters. This example shows how to create an xml file which includes other values you may need to store.

  1. Create an empty xml file using xml_create.
  2. Adds a number of fixed values and parameters to the file using xml_add. The value will be added into the xml file as a node with the name given as the second parameter.
  3. Appends standard details of the xdds using xml_from_xdds. The '1' signifies that this is appending into the file, rather than creating a new file.
  4. Closes the end of the xml description using xml_close.
xml_create("myfilename.xml")
xml_add("myfilename.xml","myvalue1",1.0)
xml_add("myfilename.xml","myvalue2",2.0)
xml_add("myfilename.xml","myvalue3",aTopasPrmName)
xml_from_xdds("myfilename.xml",1)
xml_close("myfilename.xml")