source: trunk/exports/G2export_PDB.py @ 1089

Last change on this file since 1089 was 1089, checked in by vondreele, 8 years ago

start on PDB exporter

File size: 3.6 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3########### SVN repository information ###################
4# $Date: $
5# $Author: $
6# $Revision: -1 $
7# $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/exports/G2export_CIF.py $
8# $Id: G2export_CIF.py -1   $
9########### SVN repository information ###################
10'''Code to demonstrate how export routines are created
11'''
12import os.path
13import GSASIIpath
14GSASIIpath.SetVersionNumber("$Revision: -1 $")
15import GSASIIIO as G2IO
16#import GSASIIgrid as G2gd
17import GSASIIstrIO as G2stIO
18#import GSASIImath as G2mth
19import GSASIIlattice as G2lat
20import GSASIIspc as G2spc
21#import GSASIIphsGUI as G2pg
22#import GSASIIstrMain as G2stMn
23
24class ExportPhasePDB(G2IO.ExportBaseclass):
25    '''Used to create a PDB file for a phase
26
27    :param wx.Frame G2frame: reference to main GSAS-II frame
28    '''
29    def __init__(self,G2frame):
30        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
31            G2frame=G2frame,
32            formatName = 'PDB',
33            extension='.PDB',
34            longFormatName = 'Export phase as .PDB file'
35            )
36        self.exporttype = ['phase']
37        self.multiple = True
38
39    def Exporter(self,event=None):
40        '''Export as a PDB file
41        '''
42        # the export process starts here
43        # load all of the tree into a set of dicts
44        self.loadTree()
45        # create a dict with refined values and their uncertainties
46        self.loadParmDict()
47        if self.SetupExport(event,                         # set export parameters
48                            AskFile=True
49                            ): return 
50        for phasenam in self.phasenam:
51            phasedict = self.Phases[phasenam] # pointer to current phase info
52            General = phasedict['General']
53            if General['Type'] != 'macromolecular':
54                print 'not macromolecular phase'
55                return
56            print phasedict.keys()
57            print General['SGData'].keys()           
58            i = self.Phases[phasenam]['pId']
59            if len(self.phasenam) > 1: # if more than one filename is included, add a phase #
60                nam,ext = os.path.splitext(self.filename)
61                fil = nam+"_"+str(i)+ext
62            else:
63                fil = self.filename
64            fp = self.OpenFile(fil)
65            self.Write("HEADER phase "+str(phasenam)+" from "+str(self.G2frame.GSASprojectfile))
66            # get cell parameters
67            pfx = str(phasedict['pId'])+'::'
68            A,sigA = G2stIO.cellFill(pfx,phasedict['General']['SGData'],self.parmDict,self.sigDict)
69            line = "CRYST1 {:8.3f} {:8.3f} {:8.3f} {:6.2f} {:6.2f} {:6.2f} ".format(*G2lat.A2cell(A))
70            line += General['SGData']['SpGrp'].ljust(13)
71            line += '%2d'%(len(General['SGData']['SGOps'])*len(General['SGData']['SGCen']))
72            self.Write(line)
73            self.Write('ORIGX1      1.000000  0.000000  0.000000        0.00000')
74            self.Write('ORIGX2      0.000000  1.000000  0.000000        0.00000')
75            self.Write('ORIGX3      0.000000  0.000000  1.000000        0.00000')
76            G = G2lat.A2Gmat(A)[0]
77            A,B = G2lat.Gmat2AB(G)
78            self.Write('SCALE1     {:9.6f} {:9.6f} {:9.6f}        0.00000'.format(*B[0]))
79            self.Write('SCALE2     {:9.6f} {:9.6f} {:9.6f}        0.00000'.format(*B[1]))
80            self.Write('SCALE3     {:9.6f} {:9.6f} {:9.6f}        0.00000'.format(*B[2]))
81            Atoms = phasedict['Atoms']
82           
83
84            self.CloseFile()
85            print('Phase '+str(phasenam)+' written to file '+str(fil))
Note: See TracBrowser for help on using the repository browser.