source: trunk/imports/G2sfact.py @ 623

Last change on this file since 623 was 623, checked in by vondreele, 10 years ago

remove powder read from Data menu
remove 'menu' from import menus
use longFormatName as help for import menu items
remove _init_coll_Import_Items
added updateHKLFdata to process HKLF data sets

File size: 2.3 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2012-02-13 11:33:35 -0600 (Mon, 13 Feb 2012) $
4# $Author: vondreele & toby $
5# $Revision: 482 $
6# $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/G2importphase.py $
7# $Id: G2importphase.py 482 2012-02-13 17:33:35Z vondreele $
8########### SVN repository information ###################
9# short routines to read in structure factors from simple file formats
10#
11import sys
12import numpy as np
13import GSASIIIO as G2IO
14
15class HKLF_ReaderClass(G2IO.ImportStructFactor):
16    'Routines to import reflections from a HKLF file'
17    def __init__(self):
18        super(self.__class__,self).__init__( # fancy way to self-reference
19            extensionlist=('.hkl','.HKL'),
20            strictExtension=False,
21            formatName = 'HKL',
22            longFormatName = 'Simple (hkl Fo sig(Fo)) Structure factor text file'
23            )
24    # Validate the contents
25    def ContentsValidator(self, filepointer):
26        S = filepointer.readline() 
27        while '#' in S[0]:        #get past comments, if any
28            S = filepointer.readline()       
29        for i in range(3): # scan a few lines
30            S = S.split()
31            if len(S) != 5: return False
32            for v in S:
33                try:
34                    float(v)
35                except ValueError:
36                    return False           
37            S = filepointer.readline()
38        return True
39
40    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
41        try:
42            for S in filepointer:
43                if S[0] == '#': continue       #ignore comments, if any
44                h,k,l,Fo,sigFo = S.split()
45                h,k,l = [int(h),int(k),int(l)]
46                Fo = float(Fo)
47                sigFo = float(sigFo)
48                # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,...
49                self.RefList.append([h,k,l,0,0,Fo**2,2.*Fo*sigFo,0,Fo**2,0,0,[],[],0,{}])
50            self.UpdateControls(Type='Fosq',FcalcPresent=False) # set Fobs type & if Fcalc values are loaded
51            self.UpdateParameters(Type='SXC',Wave=None) # histogram type
52            return True
53        except Exception as detail:
54            print self.formatName+' read error:'+str(detail) # for testing
55            import traceback
56            traceback.print_exc(file=sys.stdout)
57            return False
Note: See TracBrowser for help on using the repository browser.