Yes, it is open source, I have attached it in case Brian or Bob are interested in it. At the moment it is written as a filter so I can convert a bunch of data at once.
Carlo On Mon, Oct 17, 2022 at 3:22 PM Brown, Matthew <[email protected]> wrote: > Carlo > > > > I’d be happy to see your code, is it open-source? It would probably be > more useful to Bob though, to save him some time. > > > > Dr. Matthew L. Brown (he/him, they/them) > > Lab Technician V (Chemistry, Crystallography) > > Office: 250-807-8365 | WD Lab (PXRD): x376665 > > > > UBC School of Engineering > > 1540 Innovation Dr. > > Kelowna, BC > > V1V 1V7 > > > > *From:* Carlo Segre <[email protected]> > *Sent:* Monday, October 17, 2022 1:19 PM > *To:* Brown, Matthew <[email protected]> > *Cc:* [email protected] > *Subject:* Re: [Ext] [GSAS-II] Bruker brml files > > > > [*CAUTION:* Non-UBC Email] > > Hi Matthew: > > > > I have written a python program that extracts a gsas file from the Bruker > brml files. I am happy to share it. The brml file is simply a zip file > with an XML folder with all the information about the experiment. > > > > Carlo > > > > On Mon, Oct 17, 2022 at 1:18 PM Brown, Matthew via GSAS-II < > [email protected]> wrote: > > Salutations > > > > I hope I’m sending this to the right place. I was at the Canadian Powder > Diffraction Workshop last week, and noticed that GSAS-II doesn’t seem to > support *.brml files, what my Bruker PXRD saves as by default. That format > is just a zip file full of xml wearing a fancy hat, so it is quite easy to > parse; the python unzip library opens it perfectly. I’m actually doing so > for a project I’m working on.(1) > > > > If GSAS-II wanted to support *.brml files, I’d be glad to help: if someone > gave me a list of what GSAS-II needs to extract from the file, I could work > out where in the XML that is stored for you. I might even be able to write > up the extractor if you told me what output formats you, but I’m not the > world’s greatest programmer(2) so I’m not sure you’d want me directly > contributing code. > > > > 1. Since many of you know I’m very new to PXRD, don’t worry, I’m not > trying to do any actual calculations. I just got tired of looking up the > settings I’d run every experiment at in EVA each time, and worried that I > would make a typo and the user would report the wrong parameters in their > paper, so I wrote up a little python tool that extracts those numbers into > a format I can just copy and paste and send to the user. > 2. My script doesn’t even use an XML parser, I just brute force loop > over RawData0.xml using stuff like “elif line.startswith('<TimePerStep>'):” > > > > Let me know if me documenting any of this would be useful, and I hope I > can help, > > > > Dr. Matthew L. Brown (he/him, they/them) > > Lab Technician V (Chemistry, Crystallography) > > Office: 250-807-8365 | WD Lab (PXRD): x376665 > > > > UBC School of Engineering > > 1540 Innovation Dr. > > Kelowna, BC > > V1V 1V7 > > > > _______________________________________________ > GSAS-II mailing list > [email protected] > https://mailman.aps.anl.gov/mailman/listinfo/gsas-ii > > > > > -- > > Carlo U. Segre (he/him) -- Duchossois Leadership Professor of Physics > > Professor of Materials Science & Engineering > > Director, Center for Synchrotron Radiation Research and Instrumentation > > Illinois Institute of Technology > > Voice: 312.567.3498 Fax: 312.567.3494 > > [email protected] http://phys.iit.edu/~segre [email protected] > > > -- Carlo U. Segre (he/him) -- Duchossois Leadership Professor of Physics Professor of Materials Science & Engineering Director, Center for Synchrotron Radiation Research and Instrumentation Illinois Institute of Technology Voice: 312.567.3498 Fax: 312.567.3494 [email protected] http://phys.iit.edu/~segre [email protected]
#!/usr/bin/env python3 # Name: brml2gsas # Purpose: Take Bruker RawData0.xml file from a brml zip file # and convert to a GSAS format file. # Author: Carlo U. Segre <[email protected]> # # Copyright 2020-2022 Illinois Institute of Technology # # Version: # 1.0 2020/02/12 Carlo Segre # * Initial release # 1.1 2022/04/06 Carlo Segre # * Add option to produce *.xy file # __version__ = '1.1' __rcsid__ = '$Id$' __source__ = '$Source$' import os import sys import argparse from string import * from struct import * import time import numpy as np import xmltodict as xml from zipfile import ZipFile def usage(error=1): usage = """\ Usage: %s INFILE Extract data from Bruker brml file. Options: -h, --help Print this message """ % os.path.basename(sys.argv[0]) if error: sys.stderr.write(usage) sys.exit(1) else: sys.stdout.write(usage) sys.exit() def main(fileName, fileExt, datFile): with ZipFile(fileName + fileExt, 'r') as zipObj : fileList = zipObj.namelist() zipObj.extract('Experiment0/RawData0.xml') with open('Experiment0/RawData0.xml') as fd: doc = xml.parse(fd.read()) # Read the number of data points from the XML document points = int(doc['RawData']['DataRoutes']['DataRoute']['ScanInformation']['MeasurementPoints']) angle = np.zeros(points, dtype=float) counts = np.zeros(points, dtype=int) esds = np.zeros(points, dtype=float) # Extract 2-theta angle and counts from the XML document i=0 while i < points : entry = doc['RawData']['DataRoutes']['DataRoute']['Datum'][i] angle[i] = float(entry.split(',')[2]) counts[i] = int(entry.split(',')[4]) i = i + 1 esds = np.sqrt(counts) # GSAS wants filenames without spaces fixFile = fileName.replace(" ","_") # Write the data out in GSAS format ouFile = open( fixFile + '.gsas', "w" ) ouFile.write( fixFile + ' - ' + 'generated by brml2gsas\n' ) ouFile.write( 'BANK 1 ' + '{:>8d}'.format(points) + '{:>8d}'.format(int(points / 5)) + ' CONST ' + '{:>10.2f}'.format(angle[0] * 100) + '{:>10.2f}'.format((angle[1] - angle[0]) * 100) + ' 0 0 ESD\n' ) i = 0 while i < 5 * (int(points / 5)) : j = 0 while j < 5 : ouFile.write( '{:>8.1f}'.format(counts[i+j]) + '{:>8.1f}'.format(esds[i+j]) ) j = j + 1 ouFile.write( '\n' ) i = i + 5 while i < points : ouFile.write( '{:>8.1f}'.format(counts[i]) + '{:>8.1f}'.format(esds[i]) ) i = i + 1 ouFile.write( '\n' ) ouFile.close() # Write the data out in a 2-column *.dat format if requested if datFile : ouFile = open( fixFile + '.dat', "w" ) i = 0 while i < points : ouFile.write(str(angle[i]) + ' ' + str(counts[i]) + '\n') i = i + 1 ouFile.close() os.remove('Experiment0/RawData0.xml') os.rmdir('Experiment0') if __name__ == '__main__': parser = argparse.ArgumentParser( description='Extracts Bruker XML data to GSAS and optionally to 2-column data file') parser.add_argument('-d', '--data', action='store_true', default=False, dest='data', help='also write 2-column *.dat file') parser.add_argument('files', nargs=argparse.REMAINDER, help='files to extract') parser.add_argument('--version', action='version', version='%(prog)s '+__version__) args = parser.parse_args() if len(args.files) == 0 : parser.print_help(sys.stderr) sys.exit(1) for infile in args.files: filename, fileext = os.path.splitext(infile) main(filename, fileext, args.data)
_______________________________________________ GSAS-II mailing list [email protected] https://mailman.aps.anl.gov/mailman/listinfo/gsas-ii
