Skip to content

Commit 64f0852

Browse files
committed
does commenting out some code fix the self-test?
1 parent b3bb0fe commit 64f0852

File tree

1 file changed

+132
-141
lines changed

1 file changed

+132
-141
lines changed

GSASII/imports/G2phase_RRUFF.py

Lines changed: 132 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -18,146 +18,137 @@ def __init__(self):
1818
longFormatName = 'RRUFF database DIF file download (*.txt)'
1919
)
2020

21-
def ContentsValidator(self, filename):
22-
"Test if the file has CELL PARAMETERS: and SPACE GROUP: entries"
23-
with open(filename,'r') as fp:
24-
txt = fp.read()
25-
status = True
26-
for s in ('CELL PARAMETERS:','SPACE GROUP:'):
27-
if not s in txt:
28-
print(s,'not found')
29-
if self.errors is None: self.errors = ''
30-
self.errors += f'no {s} record found; not valid. '
31-
status = False
32-
if not ' ATOM ' in txt:
33-
print('ATOM line not found')
34-
if self.errors is None: self.errors = ''
35-
self.errors += 'no ATOM record found; no structure. '
36-
status = False
37-
fp.close()
38-
return status
21+
# def ContentsValidator(self, filename):
22+
# "Test if the file has CELL PARAMETERS: and SPACE GROUP: entries"
23+
# with open(filename,'r') as fp:
24+
# txt = fp.read()
25+
# status = True
26+
# for s in ('CELL PARAMETERS:','SPACE GROUP:'):
27+
# if not s in txt:
28+
# print(s,'not found')
29+
# if self.errors is None: self.errors = ''
30+
# self.errors += f'no {s} record found; not valid. '
31+
# status = False
32+
# if not ' ATOM ' in txt:
33+
# print('ATOM line not found')
34+
# if self.errors is None: self.errors = ''
35+
# self.errors += 'no ATOM record found; no structure. '
36+
# status = False
37+
# fp.close()
38+
# return status
3939

40-
def Reader(self,filename,ParentFrame=None, **unused):
41-
'Read a DIF file from RRUFF'
42-
#self.errors = 'Error opening file'
43-
from .. import GSASIIspc as G2spc
44-
from .. import GSASIIlattice as G2lat
45-
Title = ''
46-
atomsmode = False
47-
fp = open(filename, 'r')
48-
SGData = None
49-
Atoms = []
50-
cell = None
51-
for line in fp.readlines():
52-
if len(line) == 0: continue
53-
line = line.strip()
54-
if atomsmode:
55-
# all DIF files appear to have atoms as element, X, Y, Z, OCCUPANCY, ISO(B)
56-
if r'\par' in line: # some files seem to have some formatting
57-
line = line.split('\\par')[0]
58-
try:
59-
Atype = line.split()[0]
60-
x,y,z,Afrac,B = [float(i) for i in line.split()[1:]]
61-
Uiso = B/(8*np.pi**2)
62-
XYZ = np.array([float(x),float(y),float(z)])
63-
XYZ = np.where(np.abs(XYZ)<0.00001,0,XYZ)
64-
SytSym,Mult = G2spc.SytSym(XYZ,SGData)[:2]
65-
IA = 'I'
66-
i = 1
67-
while f"{Atype}{i}" in [i[0] for i in Atoms]:
68-
i += 1
69-
if i > 999:
70-
Aname = f"{Atype}?"
71-
break
72-
else:
73-
Aname = f"{Atype}{i}"
74-
if Atype.upper() in ['WA','OH','OW','OA','OB','OC','OD','OE','OL','OP','OO']:
75-
Atype = 'O'
76-
Atom = [Aname,Atype,'',x,y,z,Afrac,SytSym,Mult,IA,Uiso]
77-
Atom += 6*[0]
78-
Atom.append(ran.randint(0,sys.maxsize))
79-
Atoms.append(Atom)
80-
except:
81-
atomsmode = False
82-
break
83-
if Title == '':
84-
if '\\rtf' in line: continue
85-
Title = line
86-
if r'\par' in line: # some files seem to have some formatting
87-
Title = line.split()[-1].split('\\')[0]
88-
if 'CELL PARAMETERS:' in line:
89-
L = line.split(':')[1]
90-
if r'\par' in line: # some files seem to have some formatting
91-
L = L.split('\\par')[0]
92-
cellRec = L.split()
93-
abc = cellRec[0:3]
94-
angles = cellRec[3:]
95-
cell=[float(abc[0]),float(abc[1]),float(abc[2]),
96-
float(angles[0]),float(angles[1]),float(angles[2])]
97-
Volume = float(G2lat.calc_V(G2lat.cell2A(cell)))
98-
elif 'SPACE GROUP:' in line:
99-
SGData = G2obj.P1SGData # P 1
100-
S = line.split(':')[1].strip()
101-
if r'\par' in S: # some files seem to have some formatting
102-
S = S.split()[0]
103-
Sinit = S
104-
E,SGData = G2spc.SpcGroup(S)
105-
if E:
106-
SpGrpNorm = G2spc.StandardizeSpcName(S)
107-
if SpGrpNorm:
108-
E,SGData = G2spc.SpcGroup(SpGrpNorm)
109-
if E and '_' in S:
110-
S = S.replace('_','')
111-
if E:
112-
E,SGData = G2spc.SpcGroup(S[0]+' '+S[1:])
113-
# some space group names that show up in RRUFF
114-
SGfixDict = {'B2/b': 'B 2/b 1 1', 'Bb21m':'B b 21 m',
115-
'P21/b': 'P 21/b 1 1', 'P21212': 'P 21 21 2',
116-
'P21ca': 'P 21 c a', 'P21cn': 'P 21 c n',
117-
'P21nb': 'P21 n b', 'P21nm': 'P21 n m',
118-
'P63cm': 'P63 c m', 'P63mc': 'P63 m c',
119-
'Pn21a': 'P n 21 a', 'Pn21m': 'P n 21 m'}
40+
# def Reader(self,filename,ParentFrame=None, **unused):
41+
# 'Read a DIF file from RRUFF'
42+
# #self.errors = 'Error opening file'
43+
# from .. import GSASIIspc as G2spc
44+
# from .. import GSASIIlattice as G2lat
45+
# Title = ''
46+
# atomsmode = False
47+
# fp = open(filename, 'r')
48+
# SGData = None
49+
# Atoms = []
50+
# cell = None
51+
# for line in fp.readlines():
52+
# if len(line) == 0: continue
53+
# line = line.strip()
54+
# if atomsmode:
55+
# # all DIF files appear to have atoms as element, X, Y, Z, OCCUPANCY, ISO(B)
56+
# if r'\par' in line: # some files seem to have some formatting
57+
# line = line.split('\\par')[0]
58+
# try:
59+
# Atype = line.split()[0]
60+
# x,y,z,Afrac,B = [float(i) for i in line.split()[1:]]
61+
# Uiso = B/(8*np.pi**2)
62+
# XYZ = np.array([float(x),float(y),float(z)])
63+
# XYZ = np.where(np.abs(XYZ)<0.00001,0,XYZ)
64+
# SytSym,Mult = G2spc.SytSym(XYZ,SGData)[:2]
65+
# IA = 'I'
66+
# i = 1
67+
# while f"{Atype}{i}" in [i[0] for i in Atoms]:
68+
# i += 1
69+
# if i > 999:
70+
# Aname = f"{Atype}?"
71+
# break
72+
# else:
73+
# Aname = f"{Atype}{i}"
74+
# if Atype.upper() in ['WA','OH','OW','OA','OB','OC','OD','OE','OL','OP','OO']:
75+
# Atype = 'O'
76+
# Atom = [Aname,Atype,'',x,y,z,Afrac,SytSym,Mult,IA,Uiso]
77+
# Atom += 6*[0]
78+
# Atom.append(ran.randint(0,sys.maxsize))
79+
# Atoms.append(Atom)
80+
# except:
81+
# atomsmode = False
82+
# break
83+
# if Title == '':
84+
# if '\\rtf' in line: continue
85+
# Title = line
86+
# if r'\par' in line: # some files seem to have some formatting
87+
# Title = line.split()[-1].split('\\')[0]
88+
# if 'CELL PARAMETERS:' in line:
89+
# L = line.split(':')[1]
90+
# if r'\par' in line: # some files seem to have some formatting
91+
# L = L.split('\\par')[0]
92+
# cellRec = L.split()
93+
# abc = cellRec[0:3]
94+
# angles = cellRec[3:]
95+
# cell=[float(abc[0]),float(abc[1]),float(abc[2]),
96+
# float(angles[0]),float(angles[1]),float(angles[2])]
97+
# Volume = float(G2lat.calc_V(G2lat.cell2A(cell)))
98+
# elif 'SPACE GROUP:' in line:
99+
# SGData = G2obj.P1SGData # P 1
100+
# S = line.split(':')[1].strip()
101+
# if r'\par' in S: # some files seem to have some formatting
102+
# S = S.split()[0]
103+
# Sinit = S
104+
# E,SGData = G2spc.SpcGroup(S)
105+
# if E:
106+
# SpGrpNorm = G2spc.StandardizeSpcName(S)
107+
# if SpGrpNorm:
108+
# E,SGData = G2spc.SpcGroup(SpGrpNorm)
109+
# if E and '_' in S:
110+
# S = S.replace('_','')
111+
# if E:
112+
# E,SGData = G2spc.SpcGroup(S[0]+' '+S[1:])
113+
# # some space group names that show up in RRUFF
114+
# SGfixDict = {'B2/b': 'B 2/b 1 1', 'Bb21m':'B b 21 m',
115+
# 'P21/b': 'P 21/b 1 1', 'P21212': 'P 21 21 2',
116+
# 'P21ca': 'P 21 c a', 'P21cn': 'P 21 c n',
117+
# 'P21nb': 'P21 n b', 'P21nm': 'P21 n m',
118+
# 'P63cm': 'P63 c m', 'P63mc': 'P63 m c',
119+
# 'Pn21a': 'P n 21 a', 'Pn21m': 'P n 21 m'}
120120

121-
if E and S in SGfixDict:
122-
E,SGData = G2spc.SpcGroup(SGfixDict[S])
123-
if E:
124-
self.warnings += f'ERROR in space group symbol {Sinit!r}'
125-
self.warnings += '\nThe space group has been set to "P 1". '
126-
self.warnings += "Change this in phase's General tab."
127-
self.warnings += " Error msg="+G2spc.SGErrors(E)
128-
print(self.warnings)
129-
#import GSASII.GSASIIpath
130-
#GSASII.GSASIIpath.IPyBreak_base()
131-
elif SGData['SpGrp'] in G2spc.spg2origins:
132-
self.warnings += f"WARNING space group {SGData['SpGrp']} has two Origins"
133-
#import GSASII.GSASIIpath
134-
#GSASII.GSASIIpath.IPyBreak_base()
135-
elif 'ATOM ' in line:
136-
atomsmode = True
137-
if SGData is None:
138-
if self.errors is None: self.errors = ''
139-
self.errors += 'no Space Group record found; not valid. '
140-
return False
141-
if cell is None:
142-
if self.errors is None: self.errors = ''
143-
self.errors += 'no CELL record found; not valid. '
144-
return False
145-
if len(Atoms) == 0:
146-
if self.errors is None: self.errors = ''
147-
self.errors += 'no Atoms found; not valid. '
148-
return False
149-
if cell[3] == cell[4] == cell[5] and cell[3] != 90:
150-
self.warnings += f'Note: {filename!r} has rhombohedral cell, changing space group'
151-
E,SGData = G2spc.SpcGroup(SGData['SpGrp'] + ' R')
152-
print(self.warnings)
153-
#import GSASII.GSASIIpath
154-
#GSASII.GSASIIpath.IPyBreak_base()
155-
#breakpoint()
156-
self.MPhase = None
157-
self.Phase = G2obj.SetNewPhase(Name=Title,SGData=SGData,cell=cell+[Volume,])
158-
self.Phase['General']['Name'] = Title
159-
self.Phase['General']['Type'] = 'nuclear'
160-
self.Phase['General']['AtomPtrs'] = [3,1,7,9]
161-
self.Phase['Atoms'] = Atoms
162-
fp.close()
163-
return True
121+
# if E and S in SGfixDict:
122+
# E,SGData = G2spc.SpcGroup(SGfixDict[S])
123+
# if E:
124+
# self.warnings += f'ERROR in space group symbol {Sinit!r}'
125+
# self.warnings += '\nThe space group has been set to "P 1". '
126+
# self.warnings += "Change this in phase's General tab."
127+
# self.warnings += " Error msg="+G2spc.SGErrors(E)
128+
# elif SGData['SpGrp'] in G2spc.spg2origins:
129+
# self.warnings += f"WARNING space group {SGData['SpGrp']} has two Origins"
130+
# elif 'ATOM ' in line:
131+
# atomsmode = True
132+
# if SGData is None:
133+
# if self.errors is None: self.errors = ''
134+
# self.errors += 'no Space Group record found; not valid. '
135+
# return False
136+
# if cell is None:
137+
# if self.errors is None: self.errors = ''
138+
# self.errors += 'no CELL record found; not valid. '
139+
# return False
140+
# if len(Atoms) == 0:
141+
# if self.errors is None: self.errors = ''
142+
# self.errors += 'no Atoms found; not valid. '
143+
# return False
144+
# if cell[3] == cell[4] == cell[5] and cell[3] != 90:
145+
# self.warnings += f'Note: {filename!r} has rhombohedral cell, changing space group'
146+
# E,SGData = G2spc.SpcGroup(SGData['SpGrp'] + ' R')
147+
# self.MPhase = None
148+
# self.Phase = G2obj.SetNewPhase(Name=Title,SGData=SGData,cell=cell+[Volume,])
149+
# self.Phase['General']['Name'] = Title
150+
# self.Phase['General']['Type'] = 'nuclear'
151+
# self.Phase['General']['AtomPtrs'] = [3,1,7,9]
152+
# self.Phase['Atoms'] = Atoms
153+
# fp.close()
154+
# return True

0 commit comments

Comments
 (0)