Skip to content

Commit dab5653

Browse files
committed
create bilbao self-tests (currently to run manually)
1 parent 2876c13 commit dab5653

File tree

4 files changed

+359
-68
lines changed

4 files changed

+359
-68
lines changed

GSASII/GSASIIpwdGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4840,11 +4840,11 @@ def OnLatSym(event):
48404840
else:
48414841
dlg.Destroy()
48424842
return
4843-
wx.BeginBusyCursor()
48444843
wx.MessageBox(' For use of PSEUDOLATTICE, please cite:\n\n'+
48454844
G2G.GetCite('Bilbao: PSEUDOLATTICE'),
48464845
caption='Bilbao PSEUDOLATTICE',
48474846
style=wx.ICON_INFORMATION)
4847+
wx.BeginBusyCursor()
48484848
page = kSUB.subBilbaoCheckLattice(sgNum,cell,tolerance)
48494849
wx.EndBusyCursor()
48504850
if not page: return

GSASII/SUBGROUPS.py

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# -*- coding: utf-8 -*-
2+
'''
3+
Module SUBGROUPS
4+
========================
5+
6+
Routines that access the Bilbao Crystallographic Server.
7+
8+
Note that there is a test for some of these routines in
9+
file ``tests/run_bilbao.py``.
10+
'''
11+
212
from __future__ import division, print_function
313
import re
414
import copy
@@ -22,6 +32,7 @@
2232
def postpostURL(page):
2333
'''warn on Bilbao down
2434
'''
35+
if page is None: return
2536
if "currently down" in page:
2637
# Bilbao is down. Tell user
2738
import re
@@ -263,7 +274,6 @@ def subBilbaoCheckLattice(spgNum,cell,tol=5):
263274
cellstr = '+'.join(['{:.5f}'.format(i) for i in cell])
264275
datastr = "sgr={:}&cell={:}&tol={:}&submit=Show".format(
265276
str(int(spgNum)),cellstr,str(int(tol)))
266-
# self-tested?
267277
page = GSASIIpath.postURL(psSite,datastr,timeout=timeout)
268278
if postpostURL(page): return None
269279
if not page:
@@ -368,7 +378,6 @@ def GetSupergroup(SGnum,dlg=None):
368378
import re
369379
Site = bilbaoSite + 'nph-minsup'
370380
if dlg: dlg.Update(0,newmsg='Waiting for initial web response')
371-
# self-tested?
372381
out = GSASIIpath.postURL(Site,{'gnum':f'{SGnum:}'},timeout=timeout)
373382
if postpostURL(out): return None
374383
if not out: return None
@@ -396,7 +405,6 @@ def GetSupergroup(SGnum,dlg=None):
396405
for i,line in enumerate(xforms):
397406
click = line[-1]
398407
print(SGnum,click)
399-
# self-tested?
400408
out1 = GSASIIpath.postURL(Site,{'gnum':SGnum,'show':'show','click':click}
401409
,timeout=timeout)
402410
if postpostURL(out1): return None
@@ -572,7 +580,6 @@ def BilbaoSymSearch1(sgnum, phase, maxdelta=2, angtol=None,
572580
postdict["stru"] += f"{el:4s} {i} - {atom[cx]:.5f} {atom[cx+1]:.5f} {atom[cx+2]:.5f}\n"
573581
# if GSASIIpath.GetConfigValue('debug'): print(postdict["stru"])
574582
savedcookies = {}
575-
# self-tested?
576583
page0 = GSASIIpath.postURL(bilbaoSite+pseudosym,postdict,
577584
getcookie=savedcookies,timeout=timeout)
578585
if postpostURL(page0): return None
@@ -666,7 +673,6 @@ def BilbaoLowSymSea1(valsdict,row,savedcookies,pagelist=None):
666673
num = row[0]
667674
if GSASIIpath.GetConfigValue('debug'): print(f"processing cell #{num}")
668675
postdict['lattice'] = num
669-
# self-tested?
670676
page1 = GSASIIpath.postURL(bilbaoSite+pseudosym,postdict,
671677
usecookie=savedcookies,timeout=timeout)
672678
if postpostURL(page1) or not page1: return None,None,None,None
@@ -703,7 +709,6 @@ def BilbaoLowSymSea2(num,valsdict,row,savedcookies,pagelist=None):
703709
postdict.update(valsdict)
704710
postdict['super_numind'] = row[1]
705711
if GSASIIpath.GetConfigValue('debug'): print(f"processing cell #{num} supergroup {row[1]}")
706-
# self-tested?
707712
page1 = GSASIIpath.postURL(bilbaoSite+pseudosym,postdict,
708713
usecookie=savedcookies,timeout=timeout)
709714
if postpostURL(page1) or page1 is None: return '',None
@@ -734,7 +739,6 @@ def BilbaoSymSearch2(valsdict,csdict,rowdict,savedcookies,
734739
postdict = {}
735740
postdict.update(valsdict)
736741
postdict['cs'] = num
737-
# self-tested?
738742
page1 = GSASIIpath.postURL(bilbaoSite+pseudosym,postdict,
739743
usecookie=savedcookies,timeout=timeout)
740744
if postpostURL(page1) or pagelist is not None:
@@ -797,7 +801,6 @@ def BilbaoReSymSearch(key,postdict,pagelist=None):
797801
798802
'''
799803
savedcookies = {}
800-
# self-tested?
801804
page1 = GSASIIpath.postURL(bilbaoSite+pseudosym,postdict
802805
,getcookie=savedcookies,timeout=timeout)
803806
if postpostURL(page1) or pagelist is not None:
@@ -810,7 +813,10 @@ def BilbaoReSymSearch(key,postdict,pagelist=None):
810813
def createStdSetting(cifFile,rd):
811814
'''Use the Bilbao "CIF to Standard Setting" web service to obtain a
812815
structure in a standard setting. Then update the reader object with
813-
the space group, cell and atom positions from this.
816+
the space group, cell and atom positions from this. This is called
817+
from the CIF importer in :mod:`G2phase_CIF` when a structure is
818+
encountered that has different symmetry operators from what GSAS-II
819+
generates.
814820
'''
815821
try:
816822
import requests # delay this until now, since rarely needed
@@ -854,61 +860,5 @@ def createStdSetting(cifFile,rd):
854860
if i == int(natom)-1: break
855861
del rd.SymOps['xyz'] # as-read sym ops now obsolete
856862

857-
def test():
858-
'''This tests that routines in Bilbao Crystallographic Server
859-
are accessible and produce output that we can parse. The output
860-
is displayed but not checked to see that it agrees with what
861-
has been provided previously.
862-
863-
864-
The list of routines that access the Bilbao site and are tested here are:
865-
* GetNonStdSubgroupsmag (uses subgrmag1_general_GSAS.pl)
866-
* GetNonStdSubgroups (subgrmag1_general_GSAS.pl)
867-
* GetStdSGset (checkgr.pl)
868-
869-
The other routines are not yet tested that access the Bilbao site are:
870-
871-
* subBilbaoCheckLattice
872-
* GetSupergroup
873-
* BilbaoSymSearch1
874-
* BilbaoSymSearch2
875-
* BilbaoReSymSearch
876-
* createStdSetting
877-
878-
'''
879-
SGData = G2spc.SpcGroup('f d -3 m')[1]
880-
881-
print('test SUBGROUPSMAG')
882-
results,baseList = GetNonStdSubgroupsmag(SGData,('0','0','0',' ',' ',' ',' ',' ',' ',' '))
883-
print(results)
884-
if results:
885-
for [spgp,bns,mv,gid,altList,supList] in results:
886-
if gid in baseList:
887-
print('Space group: %d %s BNS: %s'%(gid,spgp,bns))
888-
print('MV',mv)
889-
print('altList:',altList)
890-
print('superList: ',supList)
891-
892-
print('\n\ntest SUBGROUPS')
893-
results,baseList = GetNonStdSubgroups(SGData,('1/3','1/3','1/2',' ',' ',' ',' ',' ',' ',' '))
894-
print(results)
895-
if results:
896-
for [spgp,mv,gid,altList,supList] in results:
897-
if gid in baseList:
898-
print('Space group: %d %s'%(gid,spgp))
899-
print('MV',mv)
900-
print('altList:',altList)
901-
print('superList: ',supList)
902-
903-
print('\n\ntest Bilbao IDENTIFY GROUP')
904-
sgnum,sgsym,xmat,xoff = GetStdSGset(G2spc.SpcGroup('R 3 C r')[1])
905-
if sgnum:
906-
print(f'Space group R3c (rhomb) transforms to std setting: {sgsym} (#{sgnum})')
907-
print(' xform matrix',xmat)
908-
print(' coord offset:',xoff)
909-
910-
if __name__ == '__main__':
911-
# run self-tests
912-
selftestquiet = False
913-
test()
914-
print ("OK")
863+
#if __name__ == '__main__':
864+
# Note that self-tests have been moved to file ``tests/run_bilbao.py``.

tests/run_bilbao.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
'''
2+
run_bilbao.py
3+
=====================
4+
5+
Run self-tests using the Bilbao Crystallographic Server
6+
checking that the server is accessible and that the GSAS-II
7+
routines that access the server work.
8+
No attempt is made for any comprehensive testing of the server.
9+
10+
Routines tested:
11+
12+
* createStdSetting (uses nph-cif2std)
13+
* subBilbaoCheckLattice (uses nph-pseudolattice)
14+
* GetNonStdSubgroupsmag (uses subgrmag1_general_GSAS.pl)
15+
* GetNonStdSubgroups (uses subgrmag1_general_GSAS.pl)
16+
* GetStdSGset (uses checkgr.pl)
17+
18+
The other major routines are:
19+
20+
* BilbaoSymSearch1 (pseudosym)
21+
* BilbaoSymSearch2 (pseudosym)
22+
* BilbaoReSymSearch (pseudosym)
23+
24+
These are not tested as they use the GUI extensively, but there is
25+
a test that:
26+
27+
* directly calls pseudosym & checks output with scanBilbaoSymSearch1
28+
'''
29+
30+
import os
31+
import sys
32+
import importlib.util
33+
home = os.path.dirname(__file__)
34+
if importlib.util.find_spec('GSASII') is None: # hack path if GSASII not installed into Python
35+
sys.path.append(os.path.dirname(home))
36+
from GSASII import GSASIIobj
37+
from GSASII import SUBGROUPS
38+
from GSASII import GSASIIpath
39+
from GSASII import GSASIIspc as G2spc
40+
41+
def test_createStdSetting():
42+
rd = GSASIIobj.ImportPhase('Null')
43+
rd.Phase = {}
44+
rd.Phase['General'] = {}
45+
rd.SymOps['xyz'] = None
46+
cifFile = os.path.join(home,'testinp','diamond.cif')
47+
SUBGROUPS.createStdSetting(cifFile,rd)
48+
assert len(rd.Phase['Atoms']) == 1
49+
assert rd.Phase['General']['Cell'][1] == 3.5668
50+
assert len(rd.Phase['General']['SGData']['SGOps']) == 24
51+
52+
def test_CheckLattice():
53+
print('test PSEUDOLATTICE')
54+
cell = [14.259, 22.539, 8.741, 90.0, 114.1, 90.0]
55+
page = SUBGROUPS.subBilbaoCheckLattice(12,cell,5)
56+
found = SUBGROUPS.parseBilbaoCheckLattice(page)
57+
assert found[0][0][0] == found[0][0][1] == 22.5418
58+
assert found[0][0][5] == 120.
59+
60+
def test_pseudosym():
61+
postdict = {'formulae': '', 'cifile': '', 'filename': '', 'what': 'minsup',
62+
'maxik': '1', 'onlythisik': '1', 'mysuper2': '211',
63+
'x1': '1', 'x2': '0', 'x3': '0',
64+
'y1': '0', 'y2': '1', 'y3': '0',
65+
'z1': '0', 'z2': '0', 'z3': '1', 'x4': '0',
66+
'y4': '0', 'z4': '0',
67+
'angtol': '5', 'submit': 'Show', 'maxdelta': '2.0',
68+
'stru': '# Space Group ITA number\n227\n# Lattice parameters\n5.43123 5.43123 5.43123 90.0 90.0 90.0\n# number of atoms & atoms\n1\nSi 1 - 0.12500 0.12500 0.12500\n'}
69+
savedcookies = {}
70+
URL = SUBGROUPS.bilbaoSite+ SUBGROUPS.pseudosym
71+
print('test PSEUDOSYM')
72+
page0 = GSASIIpath.postURL(URL,postdict,
73+
getcookie=savedcookies,timeout=SUBGROUPS.timeout)
74+
res = SUBGROUPS.scanBilbaoSymSearch1(page0,postdict)+[savedcookies]
75+
assert res[2]['1'][0] == 'Pn-3m'
76+
assert abs(float(res[2]['1'][5].split()[0]) - 5.43123/2) < 2e-5
77+
78+
def test_SUBGROUPSMAG():
79+
SGData = G2spc.SpcGroup('f d -3 m')[1]
80+
81+
print('test SUBGROUPSMAG')
82+
results,baseList = SUBGROUPS.GetNonStdSubgroupsmag(
83+
SGData,('0','0','0',' ',' ',' ',' ',' ',' ',' '))
84+
assert len(results) == 322
85+
assert results[0][0] == "Fd'-3'm'"
86+
assert results[1][0] == "Fd-3m'"
87+
#print(results)
88+
89+
def test_SUBGROUPS():
90+
SGData = G2spc.SpcGroup('f d -3 m')[1]
91+
print('\n\ntest SUBGROUPS')
92+
results,baseList = SUBGROUPS.GetNonStdSubgroups(
93+
SGData,('1/3','1/3','1/2',' ',' ',' ',' ',' ',' ',' '))
94+
assert len(results) == 51
95+
assert results[0][0] == "P21/c"
96+
assert results[-1][0] == "P1"
97+
98+
def test_GetStdSGset():
99+
print('\n\ntest Bilbao IDENTIFY GROUP')
100+
sgnum,sgsym,xmat,xoff = SUBGROUPS.GetStdSGset(G2spc.SpcGroup('R 3 C r')[1])
101+
assert sgnum == 161
102+
assert sgsym == 'R 3 c'
103+
assert xoff == [0,0,0]
104+
105+
#GSASIIpath.IPyBreak_base()
106+
107+
108+
if __name__ == '__main__':
109+
# run self-tests
110+
test_GetStdSGset()
111+
test_SUBGROUPSMAG()
112+
test_SUBGROUPS()
113+
test_pseudosym()
114+
test_CheckLattice()
115+
test_createStdSetting()
116+
print ("OK")

0 commit comments

Comments
 (0)