Skip to content

Commit 9760687

Browse files
committed
New exporter for XYZ positions, bonds & polyhedron faces from Drawing Atoms list suitable for laser etched glass provider
1 parent 32ba486 commit 9760687

File tree

2 files changed

+115
-6
lines changed

2 files changed

+115
-6
lines changed

GSASII/GSASIIphsGUI.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10287,7 +10287,7 @@ def SetChoice(name,c,n=0):
1028710287
atomData[r][c] = parms
1028810288
drawAtoms.SetCellValue(r,c,parms)
1028910289
FindBondsDraw(data)
10290-
G2plt.PlotStructure(G2frame,data)
10290+
# G2plt.PlotStructure(G2frame,data)
1029110291
dlg.Destroy()
1029210292
elif drawAtoms.GetColLabelValue(c) == 'Label':
1029310293
dlg = wx.SingleChoiceDialog(G2frame,'Select','Atom labelling style',labelChoice)
@@ -10681,8 +10681,7 @@ def AddSphere(event=None,selection=None,radius=None,targets=None):
1068110681
indx = selection
1068210682
else:
1068310683
indx = getAtomSelections(drawAtoms,ct-1,
10684-
'as center of sphere addition',
10685-
includeView=True)
10684+
'as center of sphere addition',includeView=True)
1068610685
if not indx: return
1068710686
generalData = data['General']
1068810687
Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
@@ -16064,7 +16063,7 @@ def OnPeaksSave(event):
1606416063

1606516064
def OnPeaksDelete(event):
1606616065
if 'Map Peaks' in data:
16067-
mapPeaks = data['Map Peaks']
16066+
mapPeaks = np.array(data['Map Peaks'])
1606816067
Ind = getAtomSelections(mapPeaks)
1606916068
Ind.sort()
1607016069
Ind.reverse()
@@ -16122,7 +16121,8 @@ def OnRollMap(event):
1612216121

1612316122
def OnPeaksEquiv(event):
1612416123
if 'Map Peaks' in data:
16125-
Ind = getAtomSelections(G2frame.MapPeaks)
16124+
mapPeaks = np.array(data['Map Peaks'])
16125+
Ind = getAtomSelections(mapPeaks)
1612616126
if Ind:
1612716127
wx.BeginBusyCursor()
1612816128
try:
@@ -16149,7 +16149,7 @@ def OnShowBonds(event):
1614916149

1615016150
def OnPeaksUnique(event):
1615116151
if 'Map Peaks' in data:
16152-
mapPeaks = data['Map Peaks']
16152+
mapPeaks = np.array(data['Map Peaks'])
1615316153
Ind = getAtomSelections(G2frame.MapPeaks)
1615416154
if Ind:
1615516155
choice = ['x=0','y=0','z=0','origin','center']

GSASII/exports/G2export_PDB.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,113 @@ def Exporter(self,event=None):
231231
self.Write(fmt.format(atom[ct],*xyz))
232232
self.CloseFile()
233233
print('Phase '+phasenam+' written to XYZ file '+self.fullpath)
234+
235+
class ExportDrawPhaseCartXYZ(G2fil.ExportBaseclass):
236+
'''Used to create a Cartesian XYZ file for a phase draw atoms
237+
238+
:param wx.Frame G2frame: reference to main GSAS-II frame
239+
'''
240+
def __init__(self,G2frame):
241+
super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
242+
G2frame=G2frame,
243+
formatName = 'Draw Atoms Cartesian XYZ',
244+
extension='.XYZ',
245+
longFormatName = 'Export draw atoms with Cartesian coordinates as .XYZ file'
246+
)
247+
self.exporttype = ['phase']
248+
self.multiple = True
249+
250+
def Exporter(self,event=None):
251+
252+
def getRadius(atom):
253+
atNum = General['AtomTypes'].index(atom[ct])
254+
if 'H' == atom[ct]:
255+
if drawingData['showHydrogen']:
256+
if 'vdW' in atom[cs]:
257+
radius = vdwScale*vdWRadii[atNum]
258+
else:
259+
radius = ballScale*drawingData['sizeH']
260+
else:
261+
radius = 0.0
262+
else:
263+
if 'vdW' in atom[cs]:
264+
radius = vdwScale*vdWRadii[atNum]
265+
else:
266+
radius = ballScale*BondRadii[atNum]
267+
return radius
268+
269+
'''Export as a XYZ file
270+
'''
271+
# the export process starts here
272+
self.InitExport(event)
273+
# load all of the tree into a set of dicts
274+
self.loadTree()
275+
# create a dict with refined values and their uncertainties
276+
self.loadParmDict()
277+
if self.ExportSelect(): # set export parameters; ask for file name
278+
return
279+
filename = self.filename
280+
self.OpenFile()
281+
for phasenam in self.phasenam:
282+
phasedict = self.Phases[phasenam] # pointer to current phase info
283+
General = phasedict['General']
284+
i = self.Phases[phasenam]['pId']
285+
drawingData = phasedict['Drawing']
286+
vdwScale = drawingData['vdwScale']
287+
vdWRadii = General['vdWRadii']
288+
BondRadii = General['BondRadii']
289+
bondR = drawingData['bondRadius']
290+
ballScale = drawingData['ballScale']
291+
cx,ct,cs,ci = drawingData['atomPtrs']
292+
Atoms = drawingData['Atoms']
293+
if not len(Atoms):
294+
print('**** ERROR - Phase '+phasenam+' has no atoms! ****')
295+
continue
296+
if len(self.phasenam) > 1: # if more than one filename is included, add a phase #
297+
self.filename = os.path.splitext(filename)[1] + "_" + str(i) + self.extension
298+
Cell = General['Cell'][1:7]
299+
A,B = G2lat.cell2AB(Cell)
300+
fmt = '{:4s}'+4*'{:10.3f}'
301+
line = ' line: ('+3*'{:10.3f}'+') - ('+3*'{:10.3f}'+')'
302+
stick = ' stick: ('+3*'{:10.3f}'+') - ('+3*'{:10.3f}'+') r = '+'{:10.3}'
303+
face = ' face: ('+3*'{:10.3f}'+') - ('+3*'{:10.3f}'+') - ('+3*'{:10.3f}'+')'
304+
self.Write('Atoms: number: {:6d}'.format(len(Atoms)))
305+
self.Write('Atoms list: element, X , Y, Z, radius')
306+
for atom in Atoms:
307+
radius = getRadius(atom)
308+
xyz = np.inner(A,np.array(atom[cx:cx+3]))
309+
self.Write(fmt.format(atom[ct],*xyz,radius))
310+
if drawingData['unitCellBox']:
311+
uBox = np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]])
312+
uEdges = np.array([
313+
[uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]],
314+
[uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]],
315+
[uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]])
316+
self.Write('cell edges:')
317+
xyz = [[0,0,0],[1,1,1]]
318+
for edge in uEdges:
319+
xyz = [np.inner(A,edge[0]),np.inner(A,edge[1])]
320+
self.Write(line.format(xyz[0][0],xyz[0][1],xyz[0][2],xyz[1][0],xyz[1][1],xyz[1][2]))
321+
self.Write('bonds:')
322+
for atom in Atoms:
323+
xyz = np.inner(A,np.array(atom[cx:cx+3]))
324+
radius = getRadius(atom)
325+
Bonds = atom[-2]
326+
for bond in Bonds:
327+
vec = np.inner(A,bond)
328+
dist = np.sqrt(np.sum(vec**2))
329+
xyz0 = xyz+vec*(radius/dist)
330+
bxyz = xyz+vec
331+
if 'sticks' in atom[cs]:
332+
self.Write(stick.format(xyz0[0],xyz0[1],xyz0[2],bxyz[0],bxyz[1],bxyz[2],bondR))
333+
self.Write('polygons:')
334+
for atom in Atoms:
335+
xyz = np.inner(A,np.array(atom[cx:cx+3]))
336+
Faces = atom[-1]
337+
for facet in Faces:
338+
vx = facet[0]+xyz
339+
self.Write(face.format(vx[0,0],vx[0,1],vx[0,2],vx[1,0],vx[1,1],vx[1,2],vx[2,0],vx[2,1],vx[2,2]))
340+
self.CloseFile()
341+
print('Phase Draw Atoms '+phasenam+' written to XYZ file '+self.fullpath)
342+
234343

0 commit comments

Comments
 (0)