Skip to content

Commit d4c3799

Browse files
committed
Many rigid body changes - still not correct.
1 parent 9c9926e commit d4c3799

6 files changed

Lines changed: 241 additions & 296 deletions

File tree

GSASII/GSASIIconstrGUI.py

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,7 @@ def SaveVectorRB(event):
28742874
filename = os.path.splitext(filename)[0]+'.vecbody' # set extension
28752875
fp = open(filename,'w')
28762876
fp.write('Name: '+data['Vector'][rbid]['RBname']+'\n')
2877+
fp.write('symAxis: '+str(data['Vector'][rbid]['symAxis'])+'\n')
28772878
fp.write('Trans: ')
28782879
for i in data['Vector'][rbid]['VectMag']:
28792880
fp.write(str(i)+" ")
@@ -2909,7 +2910,13 @@ def ReadVectorRB(event):
29092910
+l+'\ninvalid file',parent=G2frame)
29102911
return
29112912
name = l.split(':')[1].strip()
2912-
trans = fp.readline().strip().split(':')[1].split()
2913+
l = fp.readline().strip()
2914+
if 'symAxis' in l:
2915+
symAxis = eval(l.strip().split(':')[1])
2916+
l = fp.readline().strip()
2917+
else:
2918+
symAxis = [0,0,1]
2919+
trans = l.strip().split(':')[1].split()
29132920
vecMag = [float(i) for i in trans]
29142921
ntrans = len(trans)
29152922
vecs = [[] for i in range(ntrans)]
@@ -2937,10 +2944,9 @@ def ReadVectorRB(event):
29372944
if 'RBname' in data['Vector'][key]]
29382945
name = G2obj.MakeUniqueLabel(name,namelist)
29392946
data['Vector'][rbid] = {'RBname':name,'VectMag':vecMag,
2940-
'rbXYZ':np.zeros((natoms,3)),
2941-
'rbRef':[0,1,2,False],'VectRef':ntrans*[False],
2942-
'rbTypes':types,
2943-
'rbVect':vecs,'useCount':0}
2947+
'rbRef':[0,1,2,False],'rbXYZ':np.zeros((natoms,3)),
2948+
'symAxis':symAxis,'VectRef':ntrans*[False],
2949+
'rbTypes':types,'rbVect':vecs,'useCount':0}
29442950
data['RBIds']['Vector'].append(rbid)
29452951
UpdateVectorRB()
29462952

@@ -3226,57 +3232,39 @@ def OnPlotRB(event):
32263232

32273233
def rbRefAtmSizer(rbid,rbData):
32283234

3229-
def OnRefSel(event):
3235+
def OnSymRadioSet(event):
3236+
'''Set the polar axis for the sp. harm. as
3237+
RBdata['Spin'][RBId]['symAxis'].
3238+
'''
32303239
Obj = event.GetEventObject()
3231-
iref = Indx[Obj.GetId()]
3232-
sel = Obj.GetValue()
3233-
rbData['rbRef'][iref] = atNames.index(sel)
3234-
FillRefChoice(rbid,rbData)
3240+
axis = ([1,0,0],[0,1,0],[0,0,1],[1,1,0],[1,1,1])[Obj.GetSelection()]
3241+
rbData['symAxis'] = axis
32353242

32363243
refAtmSizer = wx.BoxSizer(wx.HORIZONTAL)
3237-
atNames = [name+str(i) for i,name in enumerate(rbData['rbTypes'])]
3238-
rbRef = rbData.get('rbRef',[0,1,2,False])
3239-
rbData['rbRef'] = rbRef
3244+
choices = [' x ',' y ',' z ','x+y','x+y+z']
3245+
rbData['symAxis'] = rbData.get('symAxis',[0,0,1]) #set default as 'z', if needed
3246+
symax = dict(zip([str(x) for x in [[1,0,0],[0,1,0],[0,0,1],[1,1,0],[1,1,1]]],choices))[str(rbData['symAxis'])]
32403247
if rbData['useCount']:
32413248
refAtmSizer.Add(wx.StaticText(VectorRBDisplay,-1,
3242-
'Orientation reference atoms A-B-C: %s, %s, %s'%(atNames[rbRef[0]], \
3243-
atNames[rbRef[1]],atNames[rbRef[2]])),0)
3249+
'RB polar axis is aligned along: %s'%symax),WACV,0)
32443250
else:
3245-
refAtmSizer.Add(wx.StaticText(VectorRBDisplay,-1,
3246-
'Orientation reference atoms A-B-C: '),0,WACV)
3247-
for i in range(3):
3248-
choices = [atNames[j] for j in refChoice[rbid][i]]
3249-
refSel = wx.ComboBox(VectorRBDisplay,-1,value='',
3250-
choices=choices,style=wx.CB_READONLY|wx.CB_DROPDOWN)
3251-
refSel.SetValue(atNames[rbRef[i]])
3252-
refSel.Bind(wx.EVT_COMBOBOX, OnRefSel)
3253-
Indx[refSel.GetId()] = i
3254-
refAtmSizer.Add(refSel,0,WACV)
3255-
refHelpInfo = '''
3256-
* The "Orientation Reference" control defines the Cartesian
3257-
axes for rigid bodies with the three atoms, A, B and C.
3258-
The vector from B to A defines the x-axis and the y axis is placed
3259-
in the plane defined by B to A and C to A. A,B,C must not be collinear.
3260-
'''
3261-
hlp = G2G.HelpButton(VectorRBDisplay,refHelpInfo,wrap=400)
3262-
refAtmSizer.Add(hlp,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,2)
3251+
symRadioSet = wx.RadioBox(VectorRBDisplay,choices=choices,label='RB polar axis is aligned along:')
3252+
symRadioSet.SetStringSelection(symax)
3253+
symRadioSet.Bind(wx.EVT_RADIOBOX, OnSymRadioSet)
3254+
refAtmSizer.Add(symRadioSet)
3255+
# refHelpInfo = '''
3256+
# * The "Orientation Reference" control defines the Cartesian
3257+
# axes for rigid bodies with the three atoms, A, B and C.
3258+
# The vector from B to A defines the x-axis and the y axis is placed
3259+
# in the plane defined by B to A and C to A. A,B,C must not be collinear.
3260+
# '''
3261+
# hlp = G2G.HelpButton(VectorRBDisplay,refHelpInfo,wrap=400)
3262+
# refAtmSizer.Add(hlp,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL,2)
32633263
return refAtmSizer
32643264

32653265
def rbVectMag(rbid,imag,rbData):
32663266

3267-
def OnRBVectorMag(event):
3268-
event.Skip()
3269-
Obj = event.GetEventObject()
3270-
rbid,imag = Indx[Obj.GetId()]
3271-
try:
3272-
val = float(Obj.GetValue())
3273-
if val <= 0.:
3274-
raise ValueError
3275-
rbData['VectMag'][imag] = val
3276-
except ValueError:
3277-
pass
3278-
Obj.SetValue('%8.4f'%(val))
3279-
wx.CallAfter(UpdateVectorRB,VectorRB.GetScrollPos(wx.VERTICAL))
3267+
def OnRBVectorMag(invalid,value,tc):
32803268
G2plt.PlotRigidBody(G2frame,'Vector',AtInfo,data['Vector'][rbid],plotDefaults)
32813269

32823270
def OnRBVectorRef(event):
@@ -3286,12 +3274,7 @@ def OnRBVectorRef(event):
32863274

32873275
magSizer = wx.BoxSizer(wx.HORIZONTAL)
32883276
magSizer.Add(wx.StaticText(VectorRBDisplay,-1,'Translation magnitude: '),0,WACV)
3289-
magValue = wx.TextCtrl(VectorRBDisplay,-1,'%8.4f'%(rbData['VectMag'][imag]),
3290-
style=wx.TE_PROCESS_ENTER)
3291-
Indx[magValue.GetId()] = [rbid,imag]
3292-
magValue.Bind(wx.EVT_TEXT_ENTER,OnRBVectorMag)
3293-
magValue.Bind(wx.EVT_KILL_FOCUS,OnRBVectorMag)
3294-
magSizer.Add(magValue,0,WACV)
3277+
magSizer.Add(G2G.ValidatedTxtCtrl(VectorRBDisplay,rbData['VectMag'],imag,OnLeave=OnRBVectorMag),0,WACV)
32953278
magSizer.Add((5,0),)
32963279
magref = wx.CheckBox(VectorRBDisplay,label=' Refine?')
32973280
magref.SetValue(rbData['VectRef'][imag])
@@ -3629,7 +3612,7 @@ def OnPlotRB(event):
36293612
Indx[stripH.GetId()] = rbid
36303613
nameSizer.Add(stripH,0,WACV)
36313614
nameSizer.Add(wx.StaticText(ResidueRBDisplay,-1,' body type #'+
3632-
str(data['RBIds']['Residue'].index(rbid))),0,WACV)
3615+
str(data['RBIds']['Residue'].index(rbid))),0,WACV)
36333616
nameSizer.Add((-1,-1),1,wx.EXPAND,1)
36343617
return nameSizer
36353618

GSASII/GSASIIctrlGUI.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,9 @@ def SetScaling(self,iscale):
997997

998998
def SetScaledRange(self,xmin,xmax):
999999
self.SetRange(ci(xmin*self.iscale),ci(xmax*self.iscale))
1000+
1001+
def SetLineSize(self,value):
1002+
wx.Slider.SetLineSize(self,ci(self.iscale*value))
10001003

10011004
def SetScaledValue(self,value):
10021005
wx.Slider.SetValue(self, ci(self.iscale*value))
@@ -1065,6 +1068,7 @@ def onValSet(*args,**kwargs):
10651068
vScale = G2Slider(parent,style=wx.SL_HORIZONTAL,size=(200,25))
10661069
vScale.SetScaling(iscale)
10671070
vScale.SetScaledRange(xmin,xmax)
1071+
vScale.SetLineSize(1)
10681072
vScale.SetScaledValue(loc[key])
10691073
vScale.Bind(wx.EVT_SLIDER, onScale)
10701074
if nDig is None:
@@ -1080,8 +1084,8 @@ def onValSet(*args,**kwargs):
10801084
hSizer.Add(vScale,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL)
10811085
return vEntry,vScale
10821086

1083-
def G2SpinWidget(parent,loc,key,label,xmin=None,xmax=None,
1084-
onChange=None,onChangeArgs=[],hsize=35):
1087+
def G2SpinWidget(parent,loc,key,label,xmin=None,xmax=None,nDig=None,
1088+
onChange=None,typeHint=int,onChangeArgs=[],size=(50,25)):
10851089
'''A customized combination of a wx.SpinButton and a validated
10861090
wx.TextCtrl (see :class:`ValidatedTxtCtrl`) that allows either
10871091
a the spin button or text entry to set a value within a range.
@@ -1102,14 +1106,16 @@ def G2SpinWidget(parent,loc,key,label,xmin=None,xmax=None,
11021106
:param int xmin: the minimum allowed valid value. If None it is ignored.
11031107
11041108
:param int xmax: the maximum allowed valid value. If None it is ignored.
1109+
1110+
:param list nDig: as defined for ValidatedTxtCtrl
11051111
11061112
:param callable onChange: function to call when value is changed.
11071113
Default is None where nothing will be called.
11081114
11091115
:param list onChangeArgs: arguments to be passed to onChange function
11101116
when called.
11111117
1112-
:param int hsize: length of TextCtrl in pixels. Defaults to 35.
1118+
:param int size: size of TextCtrl in pixels. Defaults to (50,25).
11131119
11141120
:returns: returns a wx.BoxSizer containing the widgets
11151121
'''
@@ -1124,22 +1130,21 @@ def _onSpin(event):
11241130
wx.TextCtrl.SetValue(vEntry,str(loc[key])) # will not trigger onValSet
11251131
Obj.SetValue(0)
11261132
if onChange: onChange(*onChangeArgs)
1127-
def _onValSet(*args,**kwargs):
1133+
def onValSet(*args,**kwargs):
11281134
if onChange: onChange(*onChangeArgs)
11291135
if xmin is not None:
11301136
loc[key] = max(xmin,loc[key])
11311137
if xmax is not None:
11321138
loc[key] = min(xmax,loc[key])
11331139
hSizer = wx.BoxSizer(wx.HORIZONTAL)
11341140
if label:
1135-
hSizer.Add(wx.StaticText(parent,wx.ID_ANY,label),0,
1136-
wx.ALL|wx.ALIGN_CENTER_VERTICAL)
1141+
hSizer.Add(wx.StaticText(parent,wx.ID_ANY,label),0,WACV)
11371142
spin = wx.SpinButton(parent,style=wx.SP_VERTICAL,size=wx.Size(20,20))
11381143
spin.SetRange(-1,1)
11391144
spin.Bind(wx.EVT_SPIN, _onSpin)
11401145
loc[key] = int(loc[key]+0.5)
1141-
vEntry = ValidatedTxtCtrl(parent,loc,key,OnLeave=_onValSet,
1142-
xmin=xmin,xmax=xmax,typeHint=int,size=(hsize,-1))
1146+
vEntry = ValidatedTxtCtrl(parent,loc,key,OnLeave=onValSet,nDig=nDig,
1147+
xmin=xmin,xmax=xmax,typeHint=typeHint,size=size)
11431148
hSizer.Add(vEntry,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL,5)
11441149
hSizer.Add(spin,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL)
11451150
return hSizer

GSASII/GSASIIlattice.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,6 @@ def prodMGMT(G,Mat):
493493
494494
'''
495495
return np.inner(np.inner(Mat,G),Mat) #right
496-
# return np.inner(Mat,np.inner(Mat,G)) #right
497-
# return np.inner(np.inner(G,Mat).T,Mat) #right
498-
# return np.inner(Mat,np.inner(G,Mat).T) #right
499496

500497
def TransformCell(cell,Trans):
501498
'''Transform lattice parameters by matrix

0 commit comments

Comments
 (0)