source: trunk/imports/G2phase_rmc6f.py @ 4208

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

Set phase name from rmc6f importer = imported file name & set default directory to its location. That facilitates use of RMC/View to see results from any RMCProfile run

File size: 4.1 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 os.path
20import numpy as np
21import random as ran
22import GSASIIobj as G2obj
23import GSASIIlattice as G2lat
24import GSASIIctrlGUI as G2G
25import GSASIIpath
26GSASIIpath.SetVersionNumber("$Revision: 1812 $")
27
28class PhaseReaderClass(G2obj.ImportPhase):
29    'Opens a .rmc6f file and pulls out the phase'
30    def __init__(self):
31        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
32            extensionlist=('.rmc6f',),
33            strictExtension=True,
34            formatName = 'RMCProfile .rmc6f',
35            longFormatName = 'RMCProfile structure (*.rmc6f) file import'
36            )
37       
38    def ContentsValidator(self, filename):
39        "Test if the rmc6f file has a CELL record"
40        fp = open(filename,'r')
41        if fp.readline()[:-1] != '(Version 6f format configuration file)':
42            self.errors = 'This is not a valid .rmc6f file.'
43            fp.close()
44            return False
45        fp.close()
46        return True
47
48    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
49        'Read a rmc6f file using :meth:`ReadINSPhase`'
50        self.Phase = self.Readrmc6fPhase(filename, ParentFrame)
51        return True
52
53    def Readrmc6fPhase(self,filename,parent=None):
54        '''Read a phase from a rmc6f file.
55        '''
56        self.errors = 'Error opening file'
57        fp = open(filename, 'Ur')
58        Phase = {}
59        Title = os.path.split(filename)
60        G2G.SaveGPXdirectory(Title[0])
61        Title = os.path.splitext(Title[1])[0]
62        Atoms = []
63        S = fp.readline()
64        line = 1
65        SGData = None
66        cell = None
67        IA = 'I'
68        Uiso = 0.01
69        Uij = [0. for i in range(6)]
70        while S:
71            self.errors = 'Error reading at line '+str(line)
72            Atom = []
73            if 'Cell' in S[:4]:
74                cellRec = S.split(':')[1].split()
75                abc = cellRec[:3]
76                angles = cellRec[3:]
77                cell=[float(abc[0]),float(abc[1]),float(abc[2]),
78                    float(angles[0]),float(angles[1]),float(angles[2])]
79                Volume = G2lat.calc_V(G2lat.cell2A(cell))
80                AA,AB = G2lat.cell2AB(cell)
81                SGData = G2obj.P1SGData # P 1
82            elif 'Atoms' in S[:5]:
83                S = fp.readline()[:-1]
84                AtRec = S.split()
85                for ix,s in enumerate(AtRec):
86                    if '.' in s:
87                        break       #is points at x
88                while S:
89                    AtRec = S.split()
90                    Atype = AtRec[1]
91                    Aname = Atype+AtRec[0]
92                    Afrac = 1.0
93                    x,y,z = AtRec[ix:ix+3]
94                    XYZ = np.array([float(x),float(y),float(z)])
95                    SytSym,Mult = '1',1
96                    Atom = [Aname,Atype,'',XYZ[0],XYZ[1],XYZ[2],Afrac,SytSym,Mult,IA,Uiso]
97                    Atom += Uij
98                    Atom.append(ran.randint(0,sys.maxsize))
99                    Atoms.append(Atom)
100                    S = fp.readline()[:-1]
101            S = fp.readline()
102            line += 1
103        fp.close()
104        self.errors = 'Error after read complete'
105        Phase = G2obj.SetNewPhase(Name='RMCProfile phase',SGData=SGData,cell=cell+[Volume,])
106        Phase['General']['Name'] = Title
107        Phase['General']['Type'] = 'nuclear'
108        Phase['General']['AtomPtrs'] = [3,1,7,9]
109        Phase['Atoms'] = Atoms
110        return Phase
Note: See TracBrowser for help on using the repository browser.