Ejemplo n.º 1
0
 def openEnergyFile(self, energies):
     """Open a new energy file (doesn't work right now !)"""
     filepath = tkfd.askopenfilename(title="Open a new file",
                                     filetypes=[('Gaussian files', '.out'),
                                                ('all files', '.*')])
     newOutputFile = fc.File(filepath)
     newOutputFile.infoCalcs(False)
     newEnergies = newOutputFile.getEnergy()
Ejemplo n.º 2
0
 def openSpecFile(self, freqs, ints, specList):
     """Open a new file"""
     filepath = tkfd.askopenfilename(title="Open a new file",
                                     filetypes=[('Gaussian files', '.out'),
                                                ('all files', '.*')])
     newOutputFile = fc.File(filepath)
     newOutputFile.infoCalcs(False)
     newOutputFile.getSpectrum()
     if newOutputFile.specType == 'harmonic':
         fqs, its = newOutputFile.buildHarmSpecLists()
         freqs[filepath.split('/')[-1]] = fqs
         ints[filepath.split('/')[-1]] = its
         specList.insert('end', filepath.split('/')[-1])
     elif newOutputFile.specType == 'anharmonic':
         hfqs, hits = newOutputFile.buildHarmSpecLists()
         specList.insert('end', filepath.split('/')[-1]+' harmonic')
         freqs[filepath.split('/')[-1]+' harmonic'] = hfqs
         ints[filepath.split('/')[-1]+' harmonic'] = hits
         afqs, aits = newOutputFile.buildAnharmSpecLists()
         specList.insert('end', filepath.split('/')[-1]+' anharmonic')
         freqs[filepath.split('/')[-1]+' anharmonic'] = afqs
         ints[filepath.split('/')[-1]+' anharmonic'] = aits
Ejemplo n.º 3
0
                    help="Plot element appearances")
args = parser.parse_args()

if not args.fileName:
    # Open visual interface without a file
    mw = tkw.mainWindow()
    mw.mainloop()
else:

    if args.visual:
        # Open visual interface with a file
        mw = tkw.mainWindow()
        mw.openFile(args.fileName)
        mw.mainloop()
    else:
        outputFile = fc.File(args.fileName)
        outputFile.infoCalcs()

        if args.energy:
            if args.quick:
                energy = outputFile.getEnergyQuick()
                print(energy)
            else:
                energies = outputFile.getEnergy()
                for i, ct in outputFile.calcTypes.items():
                    print('{} : {} a.u'.format(i, energies[i][-1]))
                    if 'Geometry optimization' in ct:
                        pf.plotEnergy(energies[i])

        if args.geometry:
            outputFile.getGeo()
Ejemplo n.º 4
0
    def operateWithoutCanvas(self,data):
        
        def findSpaces(s):
            n=0
            for c in s:
                if c==' ':
                    n+=1
                else:
                    break
            return n
            
        def findLine(s,n):
            #if s[n]=='\n', it is the last line
            i=0
            lineNum=0
            while i<n:
                c=s[i]
                if c=='\n':
                    lineNum +=1
                i+=1
            if s[n]=='\n':
                lineNum -=1
            return lineNum
            
        if self.pressed == True:
            if self.name=='Zoom in':
                if data.wordSize<50:
                    data.wordSize += 5
                    if data.wordSize <35:
                        h=data.wordSize +1
                    else:
                        h=data.wordSize +2
                    data.cellSize=[data.wordSize*3/5,h]
            elif self.name=='Zoom out':
                if data.wordSize>15:
                    data.wordSize -= 5
                    if data.wordSize<35:
                        h=data.wordSize +1
                    else:
                        h=data.wordSize +2
                    data.cellSize=[data.wordSize*3/5,h]
                    
                    
                    
                    
            elif self.name=='Comment':
                if data.isHighlighting==False:
                    data.lines[data.currLine] = "#"+data.lines[data.currLine]
                    data.cursorIndex+=1
                else:
                    start=findLine(data.text1,data.HLstart)
                    end=findLine(data.text1,data.HLend-1)
                    for i in range(start,end+1):
                        data.lines[i] = "#" +data.lines[i]
                    data.cursorIndex+=end-start+1
                data.text=('\n').join(data.lines)
                data.text1=data.text
                
            elif self.name=='Uncomment':
                if data.isHighlighting==False:
                    if data.lines[data.currLine].startswith('#'):
                        data.lines[data.currLine]=data.lines[data.currLine][1:]
                        data.cursorIndex -=1
                else:
                    start=findLine(data.text1,data.HLstart)
                    end=findLine(data.text1,data.HLend-1)
                    for i in range(start,end+1):
                        if data.lines[i].startswith('#'):
                            data.lines[i]=data.lines[i][1:]
                            data.cursorIndex -=1
                data.text=('\n').join(data.lines)
                data.text1=data.text
                
            elif self.name=='Indent':
                if data.isHighlighting==False:
                    data.lines[data.currLine]='    '+data.lines[data.currLine]
                    data.cursorIndex+=4
                else:
                    start=findLine(data.text1,data.HLstart)
                    end=findLine(data.text1,data.HLend-1)
                    for i in range(start,end+1):
                        data.lines[i]='    '+data.lines[i]
                    data.cursorIndex+=end-start+4
                data.text=('\n').join(data.lines)
                data.text1=data.text
                
            elif self.name=='Dedent':
                if data.isHighlighting==False:
                    n=findSpaces(data.lines[data.currLine])
                    if n>4:
                        data.lines[data.currLine]=data.lines[data.currLine][4:]
                        data.cursorIndex -=4
                    elif n>0:
                        data.lines[data.currLine]=data.lines[data.currLine][n:]
                        data.cursorIndex -=n
                
                else:
                    start=findLine(data.text1,data.HLstart)
                    end=findLine(data.text1,data.HLend-1)
                    for i in range(start,end+1):
                        n=findSpaces(data.lines[data.currLine])
                        if n>4:
                            data.lines[data.currLine]=data.lines[data.currLine][4:]
                            data.cursorIndex -=4
                        elif n>0:
                            data.lines[data.currLine]=data.lines[data.currLine][n:]
                            data.cursorIndex -=n    
                data.text=('\n').join(data.lines)
                data.text1=data.text


            elif self.name=='New':
                tmpCount=0
                for file in data.allFiles:
                    if 'tmp' in file.name:
                        tmpCount +=1
                newF=fileClass.File('tmp'+str(tmpCount),'',data.pathRoot)
                data.allFiles.append(newF)
                data.currFile=data.allFiles[-1]
                data.text=data.currFile.content
                data.text1=data.text
                data.lines=data.text1.splitlines()
                if data.lines==[]:
                    data.lines=['']

                

            
                    

                

                            
Ejemplo n.º 5
0
    def openFile(self, filepath='noFile'):
        """Open a file in main window, either with file name in argument
        or via a graphic interface"""
        if filepath == 'noFile':
            filepath = tkfd.askopenfilename(title="Open a new file",
                                            filetypes=[('Gaussian files',
                                                        '.out'),
                                                       ('all files', '.*')])
        outputFile = fc.File(filepath)
        outputFile.infoCalcs(False)

        self.nameFrame.grid_forget()
        self.nameFrame.destroy()
        self.infoFrame.grid_forget()
        self.infoFrame.destroy()
        self.calcFrame.grid_forget()
        self.calcFrame.destroy()

        self.nameFrame = tk.Frame(self, bd=2)
        nameLabel = tk.Label(self.nameFrame, text=outputFile.shortName)
        self.infoFrame = tk.Frame(self, bd=2, pady=5)
        softLabel = tk.Label(self.infoFrame,
                             text='Software: ' + outputFile.software)
        methodLabel = tk.Label(self.infoFrame,
                               text='Method: ' + outputFile.method[1])
        basisLabel = tk.Label(self.infoFrame,
                              text='Basis set: ' + outputFile.basis[1])
        self.calcFrame = tk.Frame(self, bd=2, pady=5)
        calcLabel = tk.Label(self.calcFrame, text='Calculations:')
        cln = list()
        for k in outputFile.calcTypes:
            for v in outputFile.calcTypes[k]:
                cln.append(len(str(v)))
        clnmax = sorted(cln)[-1]
        calcList = tk.Listbox(self.calcFrame, width=clnmax)

        for k in outputFile.calcTypes:
            for c in outputFile.calcTypes[k]:
                calcList.insert('end', c)
        calcList.select_set(0)

        buttonFrame = tk.Frame(self, borderwidth=2)
        quitButton = tk.Button(buttonFrame, text="Quit", command=self.quit)
        showButton = tk.Button(buttonFrame, text="Show",
                               command=lambda: self.new_window(outputFile,
                                                               calcList))
        geoButton = tk.Button(buttonFrame, text="Geometry",
                              command=lambda: self.new_window(outputFile,
                                                              calcList, True))

        self.nameFrame.grid(column=0, row=0, columnspan=2)
        nameLabel.pack()
        self.infoFrame.grid(column=0, row=1)
        softLabel.pack()
        methodLabel.pack()
        basisLabel.pack()
        self.calcFrame.grid(column=1, row=1)
        calcLabel.pack()
        calcList.pack()
        buttonFrame.grid(column=0, row=3, columnspan=2, sticky='we')
        quitButton.pack(side='right', padx=5)
        showButton.pack(side='left', padx=5)
        geoButton.pack(side='left', padx=5)

        self.grid_columnconfigure(0, weight=1)
Ejemplo n.º 6
0
def init(data):

    #find the desktop's directory
    data.pathRoot = os.path.join(
        os.path.join(os.path.expanduser('~')), 'Desktop'
    )  #https://stackoverflow.com/questions/34275782/how-to-get-desktop-location-using-python
    data.colors = ['lightskyblue', 'powderblue', 'paleturquoise']
    data.backgroundColor = rgbString(4, 22, 58)
    data.fontFamily = 'Courier'
    #text and text1: the current file
    data.text = ''
    data.text1 = data.text
    data.lines = ['']
    newF = fileClass.File('tmp', data.text, data.pathRoot)
    data.allFiles = [newF]
    data.currFile = data.allFiles[-1]
    #file name=data.currFile.name

    data.wordSize = 15
    data.menuHeight = 30
    data.menuWidth = data.width
    data.cellSize = [9, 16]

    #draw animation
    data.lastBound = (40, 30, 40, 30 + data.cellSize[1])
    data.speed = 5
    data.planetList = []
    data.colorMap = []

    #cursor and highlight
    data.mouseX1 = None
    data.mouseY1 = None
    data.mouseX2 = None
    data.mouseY2 = None
    data.isHighlighting = False
    data.HLstart = None  #index
    data.HLend = None  #index
    data.mouse1justchanged = False
    data.cursorIndex = 0
    data.currLine = 0

    #indention
    data.indention = 0  #a number store how many
    #parenthesis
    #check if they are balanced. if not,draw a short line below it
    #def
    data.round = 0
    data.box = 0
    data.curly = 0
    data.angle = 0

    #buttons
    #these two let us know which button is pressed
    data.pressedIndex = None
    data.pressedOperation = None
    data.buttonwidth = 50
    fileButton = buttonclass.Button('File', data.buttonwidth, data.menuHeight,
                                    ['New', 'Open', 'Save'])
    editButton = buttonclass.Button(
        'Edit', data.buttonwidth, data.menuHeight, [
            'Undo', 'Redo', 'Copy', 'Paste', 'Indent', 'Dedent', 'Comment',
            'Uncomment'
        ])
    viewButton = buttonclass.Button('View', data.buttonwidth, data.menuHeight,
                                    ['Zoom in', 'Zoom out'])
    helpButton = buttonclass.Button('Help', data.buttonwidth, data.menuHeight,
                                    ['Introduction', 'CaPS'])
    data.buttons = [fileButton, editButton, viewButton, helpButton]
    data.windowOpen = False
    #only one button can be true in the moment

    #file

    data.destination = data.pathRoot
    data.dList = ['DeskTop']
    data.dDict = {'DeskTop': '/Users/yh/Desktop'}
    data.folderChoices = withOS.makeFolderChoices(
        data.destination)  #change this whenever destination is changed
    data.name = ''
    data.open = False
    data.targetContent = ''
    data.target = None  #if i click another folder, set target to none again
    data.windowRoll = 0