source: trunk/imports/G2phase_rmc6f.py @ 4206

Last change on this file since 4206 was 4206, checked in by vondreele, 22 months ago

add importer for phase from RMCProfile rmc6f file - structure result from RMC run
implement optional inclusion of isotropic sample broadening (size & mustrain) to formation of RMCProfile .inst file

File size: 4.0 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2015-04-27 13:22:06 -0500 (Mon, 27 Apr 2015) $
4# $Author: vondreele $
5# $Revision: 1812 $
6# $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/imports/G2phase_GPX.py $
7# $Id: G2phase_GPX.py 1812 2015-04-27 18:22:06Z vondreele $
8########### SVN repository information ###################
9'''
10*Module G2phase_rmc6f: Import phase from RMCProfile rmc6f file*
11--------------------------------------------------------
12
13Copies a phase from SHELX ins file into the
14current project.
15
16'''
17from __future__ import division, print_function
18import sys
19import numpy as np
20import random as ran
21import GSASIIobj as G2obj
22import GSASIIspc as G2spc
23import GSASIIlattice as G2lat
24import GSASIIpath
25GSASIIpath.SetVersionNumber("$Revision: 1812 $")
26
27class PhaseReaderClass(G2obj.ImportPhase):
28    'Opens a .rmc6f file and pulls out the phase'
29    def __init__(self):
30        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
31            extensionlist=('.rmc6f',),
32            strictExtension=True,
33            formatName = 'RMCProfile .rmc6f',
34            longFormatName = 'RMCProfile structure (*.rmc6f) file import'
35            )
36       
37    def ContentsValidator(self, filename):
38        "Test if the rmc6f file has a CELL record"
39        fp = open(filename,'r')
40        if fp.readline()[:-1] != '(Version 6f format configuration file)':
41            self.errors = 'This is not a valid .rmc6f file.'
42            fp.close()
43            return False
44        fp.close()
45        return True
46
47    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
48        'Read a rmc6f file using :meth:`ReadINSPhase`'
49        self.Phase = self.Readrmc6fPhase(filename, ParentFrame)
50        return True
51
52    def Readrmc6fPhase(self,filename,parent=None):
53        '''Read a phase from a rmc6f file.
54        '''
55        self.errors = 'Error opening file'
56        fp = open(filename, 'Ur')
57        Phase = {}
58        Title = 'RMCProfile box'
59        Atoms = []
60        S = fp.readline()
61        line = 1
62        SGData = None
63        cell = None
64        IA = 'I'
65        Uiso = 0.01
66        Uij = [0. for i in range(6)]
67        while S:
68            self.errors = 'Error reading at line '+str(line)
69            Atom = []
70            if 'Cell' in S[:4]:
71                cellRec = S.split(':')[1].split()
72                abc = cellRec[:3]
73                angles = cellRec[3:]
74                cell=[float(abc[0]),float(abc[1]),float(abc[2]),
75                    float(angles[0]),float(angles[1]),float(angles[2])]
76                Volume = G2lat.calc_V(G2lat.cell2A(cell))
77                AA,AB = G2lat.cell2AB(cell)
78                SGData = G2obj.P1SGData # P 1
79            elif 'Atoms' in S[:5]:
80                S = fp.readline()[:-1]
81                AtRec = S.split()
82                for ix,s in enumerate(AtRec):
83                    if '.' in s:
84                        break       #is points at x
85                while S:
86                    AtRec = S.split()
87                    Atype = AtRec[1]
88                    Aname = Atype+AtRec[0]
89                    Afrac = 1.0
90                    x,y,z = AtRec[ix:ix+3]
91                    XYZ = np.array([float(x),float(y),float(z)])
92                    SytSym,Mult = '1',1
93                    Atom = [Aname,Atype,'',XYZ[0],XYZ[1],XYZ[2],Afrac,SytSym,Mult,IA,Uiso]
94                    Atom += Uij
95                    Atom.append(ran.randint(0,sys.maxsize))
96                    Atoms.append(Atom)
97                    S = fp.readline()[:-1]
98            S = fp.readline()
99            line += 1
100        fp.close()
101        self.errors = 'Error after read complete'
102        Phase = G2obj.SetNewPhase(Name='RMCProfile phase',SGData=SGData,cell=cell+[Volume,])
103        Phase['General']['Name'] = Title
104        Phase['General']['Type'] = 'nuclear'
105        Phase['General']['AtomPtrs'] = [3,1,7,9]
106        Phase['Atoms'] = Atoms
107        return Phase
Note: See TracBrowser for help on using the repository browser.