Skip to content

Commit f970844

Browse files
committed
fix geometry issues for deformation
1 parent 43b1b3d commit f970844

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

GSASII/GSASIIphsGUI.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11972,6 +11972,22 @@ def SelDeformAtom(event):
1197211972

1197311973
def UpdateDeformation(AtdId):
1197411974

11975+
def MakeUVmat(defData,U,V):
11976+
MX = U
11977+
if 'A' in defData['MUV']:
11978+
MY = V
11979+
MZ = np.cross(MX,MY)
11980+
MZ /= nl.norm(MZ)
11981+
MY = np.cross(MZ,MX)
11982+
MY /= nl.norm(MY)
11983+
else:
11984+
MZ = V
11985+
MY = np.cross(MZ,MX)
11986+
MY /= nl.norm(MY)
11987+
MZ = np.cross(MX,MY)
11988+
MZ /= nl.norm(MZ)
11989+
return np.array([MX,MY,MZ])
11990+
1197511991
def OnDeformRef(event):
1197611992
Obj = event.GetEventObject()
1197711993
dId,oId,dkey = Indx[Obj.GetId()]
@@ -11997,6 +12013,10 @@ def OnMatSel(event):
1199712013
Obj = event.GetEventObject()
1199812014
dId = Indx[Obj.GetId()]
1199912015
deformationData[-dId]['MUV'] = Obj.GetValue()
12016+
U = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['U'])]
12017+
V = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['V'])]
12018+
UVmat = MakeUVmat(deformationData[-dId],U,V)
12019+
data['Deformations'][-dId]['UVmat'] = UVmat
1200012020
wx.CallAfter(UpdateDeformation,dId)
1200112021

1200212022
def OnUvec(event):
@@ -12006,20 +12026,9 @@ def OnUvec(event):
1200612026
if Obj.GetValue() == deformationData[-dId]['V']:
1200712027
Obj.SetValue(deformationData[-dId]['U'])
1200812028
else:
12009-
MX = UVvec[dId][Obj.GetSelection()]
12010-
if 'A' in deformationData[-dId]['MUV']:
12011-
MY = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['V'])]
12012-
MZ = np.cross(MX,MY)
12013-
MZ /= nl.norm(MZ)
12014-
MY = np.cross(MZ,MX)
12015-
MY /= nl.norm(MY)
12016-
else:
12017-
MZ = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['V'])]
12018-
MY = np.cross(MZ,MX)
12019-
MY /= nl.norm(MY)
12020-
MZ = np.cross(MX,MY)
12021-
MZ /= nl.norm(MZ)
12022-
UVmat = np.array([MX,MY,MZ])
12029+
U = UVvec[dId][Obj.GetSelection()]
12030+
V = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['V'])]
12031+
UVmat = MakeUVmat(deformationData[-dId],U,V)
1202312032
if np.any(np.isnan(UVmat)):
1202412033
Obj.SetValue(deformationData[-dId]['U'])
1202512034
G2G.G2MessageBox(G2frame,'ERROR: Z: U-vector zero or parallel to V','Invalid vector choice')
@@ -12028,6 +12037,7 @@ def OnUvec(event):
1202812037
UVmat *= -1.
1202912038
deformationData[-dId]['U'] = Obj.GetValue()
1203012039
data['Deformations'][-dId]['UVmat'] = UVmat
12040+
wx.CallAfter(UpdateDeformation,dId)
1203112041

1203212042
def OnVvec(event):
1203312043
"Cartesian axes: A: X'=U, Y'=(UxV)xU & Z'=UxV,B: X'=U, Y'=UxV & Z'=Ux(UxV)"
@@ -12036,20 +12046,9 @@ def OnVvec(event):
1203612046
if Obj.GetValue() == deformationData[-dId]['U']:
1203712047
Obj.SetValue(deformationData[-dId]['V'])
1203812048
else:
12039-
MX = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['U'])]
12040-
if 'A' in deformationData[-dId]['MUV']:
12041-
MY = UVvec[dId][Obj.GetSelection()]
12042-
MZ = np.cross(MX,MY)
12043-
MZ /= nl.norm(MZ)
12044-
MY = np.cross(MZ,MX)
12045-
MY /= nl.norm(MY)
12046-
else:
12047-
MZ = UVvec[dId][Obj.GetSelection()]
12048-
MY = np.cross(MZ,MX)
12049-
MY /= nl.norm(MY)
12050-
MZ = np.cross(MX,MY)
12051-
MZ /= nl.norm(MZ)
12052-
UVmat = np.array([MX,MY,MZ])
12049+
U = UVvec[dId][UVchoice[dId].index(deformationData[-dId]['U'])]
12050+
V = UVvec[dId][Obj.GetSelection()]
12051+
UVmat = MakeUVmat(deformationData[-dId],U,V)
1205312052
if np.any(np.isnan(UVmat)):
1205412053
Obj.SetValue(deformationData[-dId]['V'])
1205512054
G2G.G2MessageBox(G2frame,'ERROR: V-vector zero or parallel to U','Invalid vector choice')
@@ -12058,6 +12057,7 @@ def OnVvec(event):
1205812057
UVmat *= -1.
1205912058
deformationData[-dId]['V'] = Obj.GetValue()
1206012059
data['Deformations'][-dId]['UVmat'] = UVmat
12060+
wx.CallAfter(UpdateDeformation,dId)
1206112061

1206212062
def OnAtSel(event):
1206312063
dId = atomList[atSel.GetValue()]
@@ -12097,10 +12097,13 @@ def OnAtSel(event):
1209712097

1209812098
mainSizer = wx.BoxSizer(wx.VERTICAL)
1209912099
topSizer = wx.BoxSizer(wx.HORIZONTAL)
12100-
topSizer.Add(wx.StaticText(deformation,label=' Select an atom '),0,WACV)
12101-
atSel = wx.ComboBox(deformation,value=AtChoice,choices=list(atomList.keys()),style=wx.CB_READONLY|wx.CB_DROPDOWN)
12102-
atSel.Bind(wx.EVT_COMBOBOX,OnAtSel)
12103-
topSizer.Add(atSel,0,WACV)
12100+
if dId is None:
12101+
topSizer.Add(wx.StaticText(deformation,label='No atoms in deformation list. Do add atom first'),0,WACV)
12102+
else:
12103+
topSizer.Add(wx.StaticText(deformation,label=' Select an atom '),0,WACV)
12104+
atSel = wx.ComboBox(deformation,value=AtChoice,choices=list(atomList.keys()),style=wx.CB_READONLY|wx.CB_DROPDOWN)
12105+
atSel.Bind(wx.EVT_COMBOBOX,OnAtSel)
12106+
topSizer.Add(atSel,0,WACV)
1210412107
mainSizer.Add(topSizer,0,wx.EXPAND)
1210512108
if dId is not None:
1210612109
Indx = {}
@@ -12134,7 +12137,6 @@ def OnAtSel(event):
1213412137
UVvec[dId] += [neigh[1][3]/neigh[1][2],(neigh[0][3]+neigh[1][3])/np.sqrt(neigh[0][2]**2+neigh[1][2]**2),] #B, A+B
1213512138
if Nneigh == 4:
1213612139
UVvec[dId] += [(neigh[0][3]+neigh[1][3]+neigh[2][3])/np.sqrt(neigh[0][2]**2+neigh[1][2]**2+neigh[2][2]**2),] #A+B+C
12137-
1213812140
plotAtm = wx.Button(deformation,label='Plot')
1213912141
plotAtm.Bind(wx.EVT_BUTTON,OnPlotAtm)
1214012142
Indx[plotAtm.GetId()] = dId

0 commit comments

Comments
 (0)