Skip to content

Commit

Permalink
changes to allow packaging with cx_freeze. Unfortunately I had to cha…
Browse files Browse the repository at this point in the history
…nge some packages such as matplotlib and tvtk so freezing will only work on my computer
  • Loading branch information
JannickWeisshaupt committed Feb 9, 2018
1 parent 7c91b57 commit 2fcd300
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ __pycache__
MANIFEST
/logfiles
/testfiles
defaults.pkl
defaults.pkl
/build
/dist
main.spec
33 changes: 33 additions & 0 deletions build_freeze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys
import os
from cx_Freeze import setup, Executable
import cx_Freeze.hooks
def hack(finder, module):
return
cx_Freeze.hooks.load_matplotlib = hack
import scipy
import matplotlib
from encodings import ascii
from encodings import idna
from encodings import unicode_escape

scipy_path = os.path.dirname(scipy.__file__) #use this if you are also using scipy in your application

build_exe_options = {"packages": ["pyface.ui.qt4", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_qt4",'pkg_resources._vendor','pkg_resources.extern','pygments.lexers',
'tvtk.pyface.ui.qt4'],
"include_files": [(str(scipy_path), "scipy"), #for scipy
(matplotlib.get_data_path(), "mpl-data"),'/home/jannick/python_programs/OpenDFT/data'],
"includes":['numpy.core._methods', 'numpy.lib.format','PyQt4.QtCore','PyQt4.QtGui'],
'excludes':'Tkinter'
}

executables = [
Executable('main.py', targetName="OpenDFT")
]

setup(name='OpenDFT',
version='1.0',
description='OpenDFT',
options = {"build_exe": build_exe_options},
executables=executables
)
16 changes: 14 additions & 2 deletions little_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyface.qt import QtGui, QtCore
import numpy as np

import sys
import os

class no_error_dictionary:
def __init__(self,dic_in):
Expand Down Expand Up @@ -107,4 +108,15 @@ def get_proc_name():
buff = create_string_buffer(128)
# 16 == PR_GET_NAME from <linux/prctl.h>
libc.prctl(16, byref(buff), 0, 0, 0)
return buff.value
return buff.value

def find_data_file(filename):
if getattr(sys, 'frozen', False):
# The application is frozen
datadir = os.path.dirname(sys.executable)
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = os.path.dirname(__file__)

return datadir + filename
9 changes: 6 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import sys
import os
import numpy as np
from encodings import ascii
from encodings import idna
from encodings import unicode_escape

os.environ['ETS_TOOLKIT'] = 'qt4'
from pyface.qt import QtGui, QtCore
from visualization import StructureVisualization, BandStructureVisualization, ScfVisualization,OpticalSpectrumVisualization,colormap_list,BrillouinVisualization
import solid_state_tools as sst
from solid_state_tools import p_table,p_table_rev
from little_helpers import no_error_dictionary,CopySelectedCellsAction,PasteIntoTable,set_procname,get_proc_name
from little_helpers import no_error_dictionary,CopySelectedCellsAction,PasteIntoTable,set_procname,get_proc_name,find_data_file
from TerminalClass import PythonTerminal
import pickle
import time
Expand Down Expand Up @@ -266,7 +269,7 @@ def __init__(self, parent=None):
self.make_menubar()
self.custom_window_title = 'OpenDFT Python scripting '
self.setWindowTitle(self.custom_window_title)
self.setWindowIcon(QtGui.QIcon('icon.ico'))
self.setWindowIcon(QtGui.QIcon(find_data_file('icon.ico')))
self.error_widget = QtGui.QErrorMessage(parent=self)

self.update_fields_timer = QtCore.QTimer()
Expand Down Expand Up @@ -2811,7 +2814,7 @@ def update_program(self):
current_time = time.localtime()
current_time_string = [str(x) for x in current_time[:3]]

installation_folder = os.path.dirname(__file__)
# installation_folder = os.path.dirname(find_data_file(''))
temp_folder = os.path.expanduser("~")+"/.OpenDFT"

if not os.path.exists(temp_folder):
Expand Down
3 changes: 2 additions & 1 deletion solid_state_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
from scipy.spatial import ConvexHull,Voronoi
import os
from little_helpers import find_data_file

try:
from pymatgen.symmetry.bandstructure import HighSymmKpath
Expand All @@ -16,7 +17,7 @@

bohr = 0.52917721067

cov_radii = np.loadtxt(os.path.dirname(__file__)+'/data/cov_radii.dat')/bohr
cov_radii = np.loadtxt(find_data_file('/data/cov_radii.dat'))/bohr

p_table = {i: el.__repr__() for i, el in enumerate(pt.elements)}
p_table_rev = {el.__repr__(): i for i, el in enumerate(pt.elements)}
Expand Down
5 changes: 3 additions & 2 deletions visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import matplotlib as mpl
mpl.use('Qt4Agg')
mpl.rcParams['backend.qt4']='PySide'
from little_helpers import find_data_file
from bisect import bisect
# mpl.rc('font',**{'size': 22, 'family':'serif','serif':['Palatino']})
# mpl.rc('text', usetex=True)
Expand All @@ -31,7 +32,7 @@

bohr = 0.52917721

cov_radii = np.loadtxt(os.path.dirname(__file__)+'/data/cov_radii.dat')/bohr
cov_radii = np.loadtxt(find_data_file('/data/cov_radii.dat'))/bohr

colors = {1: (0.8, 0.8, 0.8),3:(0,0.75,0.75),11:(0,0.75,0.75),19:(0,0.75,0.75),37:(0,0.75,0.75),5:(0.78,0.329,0.1176),7:(0,0,1),
6:(0.25,.25,.25), 8: (1, 0, 0),9:(0,1,0),17:(0,1,0),35:(0,1,0),16:(1,1,0),13:(0.68,0.229,0.1176),31:(0.58,0.15,0.07),15:(0,0,0.8),33:(48/255,139/255,229/255)}
Expand All @@ -46,7 +47,7 @@
colors[i] = (0,1,1)

try:
with open(os.path.dirname(__file__)+'/data/colormaps.dat') as f:
with open(find_data_file('/data/colormaps.dat')) as f:
t = f.read()
t = t.replace("'",'')
s = t.split()
Expand Down

0 comments on commit 2fcd300

Please sign in to comment.