@@ -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