コード例 #1
0
def INTC_commandline(filename2):
    print("Running Lumerical INTERCONNECT using the command interface.")
    import sys, os, string

    if sys.platform.startswith('linux'):
        import subprocess
        # Linux-specific code here...
        print("Running INTERCONNECT")
        # Location of INTERCONNECT program (this found from RPM installation)
        file_path = '/opt/lumerical/interconnect/bin/interconnect'
        subprocess.Popen([file_path, '-run', filename2])

    elif sys.platform.startswith('darwin'):
        # OSX specific
        import sys
        if int(sys.version[0]) > 2:
            import subprocess
            subprocess.Popen([
                '/usr/bin/open -n /Applications/Lumerical/INTERCONNECT/INTERCONNECT.app',
                '-run',
                '--args -run %s' % filename2
            ])
        else:
            import commands
            print("Running INTERCONNECT")
            runcmd = (
                'source ~/.bash_profile; /usr/bin/open -n /Applications/Lumerical/INTERCONNECT/INTERCONNECT.app --args -run %s'
                % filename2)
            print("Running in shell: %s" % runcmd)
            a = commands.getstatusoutput(runcmd)
            print(a)

    elif sys.platform.startswith('win'):
        # Windows specific code here
        import subprocess
        print("Running INTERCONNECT")
        #check Interconnect installation directory
        file_path_a = 'C:\\Program Files\\Lumerical\\INTERCONNECT\\bin\\interconnect.exe'
        file_path_b = 'C:\\Program Files (x86)\\Lumerical\\INTERCONNECT\\bin\\interconnect.exe'
        if (os.path.isfile(file_path_a) == True):
            subprocess.Popen(args=[file_path_a, '-run', filename2], shell=True)
        elif (os.path.isfile(file_path_b) == True):
            subprocess.Popen(args=[file_path_b, '-run', filename2], shell=True)
        else:
            warning_window = pya.QMessageBox()
            warning_window.setText(
                "Warning: The program could not find INTERCONNECT.")
            warning_window.setInformativeText(
                "Do you want to specify it manually?")
            warning_window.setStandardButtons(pya.QMessageBox.Yes
                                              | pya.QMessageBox.Cancel)
            warning_window.setDefaultButton(pya.QMessageBox.Yes)
            response = warning_window.exec_()
            if (response == pya.QMessageBox.Yes):
                dialog = pya.QFileDialog()
                path = str(dialog.getOpenFileName())
                path = path.replace('/', '\\')
                subprocess.Popen(args=[path, '-run', filename2], shell=True)
コード例 #2
0
def load_lumapi(verbose=False):
    import pya
    if verbose:
        print("SiEPIC.lumerical.load_lumapi")

    import sys

    try:
        import numpy
    except:
        try:
            import pip
            import pya
            install = pya.MessageBox.warning(
                "Install package?",
                "Install package 'numpy' using pip? [required for Lumerical tools]",
                pya.MessageBox.Yes + pya.MessageBox.No)
            if install == pya.MessageBox.Yes:
                # try installing using pip
                from SiEPIC.install import get_pip_main
                main = get_pip_main()
                main(['install', 'numpy'])
        except ImportError:
            pass

    import os, platform, sys, inspect

    # Load the Lumerical software location from KLayout configuration
    path = pya.Application.instance().get_config(
        'siepic_tools_Lumerical_Python_folder')

    # if it isn't defined, start with Lumerical's defaults
    if not path:
        if platform.system() == 'Darwin':
            path_fdtd = "/Applications/Lumerical 2019b.app/Contents/API/Python"
            if os.path.exists(path_fdtd):
                path = path_fdtd
            path_intc = "/Applications/Lumerical 2019b.app/Contents/API/Python"
            if os.path.exists(path_intc):
                path = path_intc
        elif platform.system() == 'Linux':
            path_fdtd = "/opt/lumerical/fdtd/api/python"
            if os.path.exists(path_fdtd):
                path = path_fdtd
            path_intc = "/opt/lumerical/interconnect/api/python"
            if os.path.exists(path_intc):
                path = path_intc
        elif platform.system() == 'Windows':
            path_fdtd = "C:\\Program Files\\Lumerical\\FDTD Solutions\\api\\python"
            if os.path.exists(path_fdtd):
                path = path_fdtd
            path_intc = "C:\\Program Files\\Lumerical\\INTERCONNECT\\api\\python"
            if os.path.exists(path_intc):
                path = path_intc
        else:
            print('Not a supported OS')
            return

    # if it is still not found, ask the user
    if not os.path.exists(path):
        print('SiEPIC.lumerical.load_api: Lumerical software not found')
        question = pya.QMessageBox()
        question.setStandardButtons(pya.QMessageBox.Yes | pya.QMessageBox.No)
        question.setDefaultButton(pya.QMessageBox.Yes)
        question.setText(
            "Lumerical software not found. \nDo you wish to locate the software?"
        )
        if (pya.QMessageBox_StandardButton(
                question.exec_()) == pya.QMessageBox.Yes):
            p = pya.QFileDialog()
            p.setFileMode(pya.QFileDialog.DirectoryOnly)
            p.exec_()
            path = p.directory().path
            if verbose:
                print(path)
        else:
            return

    # check if we have the correct path, containing lumapi.py
    if not os.path.exists(os.path.join(path, 'lumapi.py')):
        # check sub-folders for lumapi.py
        import fnmatch
        dir_path = path
        search_str = 'lumapi.py'
        matches = []
        for root, dirnames, filenames in os.walk(dir_path, followlinks=True):
            for filename in fnmatch.filter(filenames, search_str):
                matches.append(root)
        if matches:
            if verbose:
                print(matches)
            path = matches[0]

        if not os.path.exists(os.path.join(path, 'lumapi.py')):
            print('SiEPIC.lumerical.load_api: Lumerical lumapi.py not found')
            warning = pya.QMessageBox()
            warning.setStandardButtons(pya.QMessageBox.Cancel)
            warning.setText("Lumerical's lumapi.py not found.")
            warning.setInformativeText(
                "Some SiEPIC-Tools Lumerical functionality will not be available."
            )
            pya.QMessageBox_StandardButton(warning.exec_())
            return

    # Save the Lumerical software location to the KLayout configuration
    pya.Application.instance().set_config(
        'siepic_tools_Lumerical_Python_folder', path)

    CWD = os.path.dirname(os.path.abspath(__file__))

    if platform.system() == 'Darwin':
        # Check if any Lumerical tools are installed
        ##################################################################
        # Configure OSX Path to include Lumerical tools:

        # Copy the launch control file into user's Library folder
        # execute launctl to register the new paths
        import os, fnmatch
        siepic_tools_lumerical_folder = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))

        os.environ[
            'PATH'] += ':/Applications/Lumerical/FDTD Solutions/FDTD Solutions.app/Contents/MacOS'
        os.environ[
            'PATH'] += ':/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/MacOS'
        os.environ[
            'PATH'] += ':/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/API/Python'
        os.environ[
            'PATH'] += ':/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/API/Matlab'

        # Also add path for use in the Terminal
        home = os.path.expanduser("~")
        if not os.path.exists(home + "/.bash_profile"):
            text_bash = '\n'
            text_bash += '# Setting PATH for Lumerical API\n'
            text_bash += 'export PATH=/Applications/Lumerical/FDTD\ Solutions/FDTD\ Solutions.app/Contents/MacOS:$PATH\n'
            text_bash += 'export PATH=/Applications/Lumerical/MODE\ Solutions/MODE\ Solutions.app/Contents/MacOS:$PATH\n'
            text_bash += 'export PATH=/Applications/Lumerical/DEVICE/DEVICE.app/Contents/MacOS:$PATH\n'
            text_bash += 'export PATH=/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/MacOS:$PATH\n'
            text_bash += '\n'
            file = open(home + "/.bash_profile", 'w')
            file.write(text_bash)
            file.close()

        if not path in sys.path:
            sys.path.append(path)
        # Fix for Lumerical Python OSX API, for < March 5 2018 versions:
        if not os.path.exists(os.path.join(path, 'libinterop-api.1.dylib')):
            lumapi_osx_fix = siepic_tools_lumerical_folder + '/lumapi_osx_fix.bash'
            lumapi_osx_fix_lib = path + '/libinterop-api.so.1'
            if not os.path.exists(lumapi_osx_fix_lib):
                warning = pya.QMessageBox()
                warning.setStandardButtons(pya.QMessageBox.Ok)
                warning.setText(
                    "We need to do a fix in the Lumerical software folder for Python integration. \nPlease note that for this to work, we assume that Lumerical INTERCONNECT is installed in the default path: /Applications/Lumerical/INTERCONNECT/\nPlease enter the following in a Terminal.App window, and enter your root password when prompted. Ok to continue when done."
                )
                warning.setInformativeText("source %s" % lumapi_osx_fix)
                pya.QMessageBox_StandardButton(warning.exec_())
                if not os.path.exists(lumapi_osx_fix_lib):
                    import sys
                    if int(sys.version[0]) > 2:
                        import subprocess
                        subprocess.Popen([
                            '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal',
                            '-run', lumapi_osx_fix
                        ])
                    else:
                        import commands
                        print(
                            commands.getstatusoutput(
                                '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal %s'
                                % lumapi_osx_fix))

    # Windows
    elif platform.system() == 'Windows':
        if os.path.exists(path):
            if not path in sys.path:
                sys.path.append(path)  # windows
            os.chdir(path)
    # Linux
    elif platform.system() == 'Linux':
        if os.path.exists(path):
            if not path in sys.path:
                sys.path.append(path)  # windows
            os.chdir(path)

    # for all operating systems:
    from .. import _globals
    if not _globals.LUMAPI:
        try:
            import lumapi
            _globals.LUMAPI = lumapi
        except:
            print('import lumapi failed')
            return

    print('import lumapi success, %s' % _globals.LUMAPI)
    #    _globals.INTC = lumapi.open('interconnect')
    #    _globals.FDTD = lumapi.open('fdtd')

    os.chdir(CWD)
コード例 #3
0
def load_lumapi(verbose=False):
    if verbose:
        print("SiEPIC.lumerical.load_lumapi")

    try:
        import numpy
    except:
        print('Missing numpy. Cannot load Lumerical Python integration')
        warning = pya.QMessageBox()
        warning.setStandardButtons(pya.QMessageBox.Cancel)
        warning.setText(
            "Missing Python module numpy.  \nCannot load Lumerical Python integration. "
        )
        warning.setInformativeText(
            "Some SiEPIC-Tools Lumerical functionality will not be available.\nPlease install numpy.  For Windows users, install the Package Windows_Python_packages_for_KLayout."
        )
        pya.QMessageBox_StandardButton(warning.exec_())
        return

    import os, platform, sys, inspect

    # Load the Lumerical software location from KLayout configuration
    path = pya.Application.instance().get_config(
        'siepic_tools_Lumerical_Python_folder')

    # if it isn't defined, start with Lumerical's defaults
    if not path:
        if platform.system() == 'Darwin':
            path_fdtd = "/Applications/Lumerical/FDTD Solutions/FDTD Solutions.app/Contents/API/Python"
            if os.path.exists(path_fdtd):
                path = path_fdtd
            path_intc = "/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/API/Python"
            if os.path.exists(path_intc):
                path = path_intc
        elif platform.system() == 'Windows':
            path_fdtd = "C:\\Program Files\\Lumerical\\FDTD Solutions\\api\\python"
            if os.path.exists(path_fdtd):
                path = path_fdtd
            path_intc = "C:\\Program Files\\Lumerical\\INTERCONNECT\\api\\python"
            if os.path.exists(path_intc):
                path = path_intc
        else:
            print('Not a supported OS')
            return

    # if it is still not found, ask the user
    if not os.path.exists(path):
        print('SiEPIC.lumerical.load_api: Lumerical software not found')
        question = pya.QMessageBox()
        question.setStandardButtons(pya.QMessageBox.Yes | pya.QMessageBox.No)
        question.setDefaultButton(pya.QMessageBox.Yes)
        question.setText(
            "Lumerical software not found. \nDo you wish to locate the software?"
        )
        if (pya.QMessageBox_StandardButton(
                question.exec_()) == pya.QMessageBox.Yes):
            p = pya.QFileDialog()
            p.setFileMode(pya.QFileDialog.DirectoryOnly)
            p.exec_()
            path = p.directory().path
            if verbose:
                print(path)
        else:
            return

    # check if we have the correct path, containing lumapi.py
    if not os.path.exists(os.path.join(path, 'lumapi.py')):
        # check sub-folders for lumapi.py
        import fnmatch
        dir_path = path
        search_str = 'lumapi.py'
        matches = []
        for root, dirnames, filenames in os.walk(dir_path, followlinks=True):
            for filename in fnmatch.filter(filenames, search_str):
                matches.append(root)
        if matches:
            if verbose:
                print(matches)
            path = matches[0]

        if not os.path.exists(os.path.join(path, 'lumapi.py')):
            print('SiEPIC.lumerical.load_api: Lumerical lumapi.py not found')
            warning = pya.QMessageBox()
            warning.setStandardButtons(pya.QMessageBox.Cancel)
            warning.setText("Lumerical's lumapi.py not found.")
            warning.setInformativeText(
                "Some SiEPIC-Tools Lumerical functionality will not be available."
            )
            pya.QMessageBox_StandardButton(warning.exec_())
            return

    # Save the Lumerical software location to the KLayout configuration
    pya.Application.instance().set_config(
        'siepic_tools_Lumerical_Python_folder', path)

    CWD = os.path.dirname(os.path.abspath(__file__))

    if platform.system() == 'Darwin':
        # Check if any Lumerical tools are installed
        ##################################################################
        # Configure OSX Path to include Lumerical tools:

        # Copy the launch control file into user's Library folder
        # execute launctl to register the new paths
        import os, fnmatch, commands
        siepic_tools_lumerical_folder = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))

        if 0:

            filename = (siepic_tools_lumerical_folder +
                        '/SiEPIC_Tools_Lumerical_KLayout_environment.plist')
            if not os.path.exists(filename):
                raise Exception('Missing file: %s' % filename)

            # Check if Paths are correctly set, and KLayout Python sees them
            a, b = commands.getstatusoutput(
                'echo $SiEPIC_Tools_Lumerical_KLayout_environment')
            if b == '':
                # Not yet installed... copy files, install
                cmd1 = ('launchctl unload  %s' % filename)
                a, b = commands.getstatusoutput(cmd1)
                if a != 0:
                    raise Exception('Error calling: %s, %s' % (cmd1, b))
                cmd1 = ('launchctl load  %s' % filename)
                a, b = commands.getstatusoutput(cmd1)
                if a != 0 or b != '':
                    raise Exception('Error calling: %s, %s' % (cmd1, b))
                cmd1 = ('killall Dock')
                a, b = commands.getstatusoutput(cmd1)
                if a != 0 or b != '':
                    raise Exception('Error calling: %s, %s' % (cmd1, b))

                # Check if Paths are correctly set, and KLayout Python sees them
                a, b = commands.getstatusoutput(
                    'echo $SiEPIC_Tools_Lumerical_KLayout_environment')
                if b == '':
                    # Not loaded
                    print(
                        "The System paths have been updated. Please restart KLayout to use Lumerical tools."
                    )
                    #          raise Exception ('The System paths have been updated. Please restart KLayout to use Lumerical tools.')
                    warning = pya.QMessageBox()
                    warning.setStandardButtons(pya.QMessageBox.Ok)
                    warning.setText(
                        "The System paths have been updated. \nPlease restart KLayout to use Lumerical tools, and try this again."
                    )
                    #          warning.setInformativeText("Do you want to Proceed?")
                    pya.QMessageBox_StandardButton(warning.exec_())
                    return
        if 1:
            os.environ[
                'PATH'] += ':/Applications/Lumerical/FDTD Solutions/FDTD Solutions.app/Contents/MacOS'
            os.environ[
                'PATH'] += ':/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/MacOS'
            os.environ[
                'PATH'] += ':/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/API/Python'
            os.environ[
                'PATH'] += ':/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/API/Matlab'

        # Also add path for use in the Terminal
        home = os.path.expanduser("~")
        if not os.path.exists(home + "/.bash_profile"):
            text_bash = '\n'
            text_bash += '# Setting PATH for Lumerical API\n'
            text_bash += 'export PATH=/Applications/Lumerical/FDTD\ Solutions/FDTD\ Solutions.app/Contents/MacOS:$PATH\n'
            text_bash += 'export PATH=/Applications/Lumerical/MODE\ Solutions/MODE\ Solutions.app/Contents/MacOS:$PATH\n'
            text_bash += 'export PATH=/Applications/Lumerical/DEVICE/DEVICE.app/Contents/MacOS:$PATH\n'
            text_bash += 'export PATH=/Applications/Lumerical/INTERCONNECT/INTERCONNECT.app/Contents/MacOS:$PATH\n'
            text_bash += '\n'
            file = open(home + "/.bash_profile", 'w')
            file.write(text_bash)
            file.close()

        if 1:
            # Fix for Lumerical Python OSX API:
            if not path in sys.path:
                sys.path.append(path)
    #    os.chdir(path)
            lumapi_osx_fix = siepic_tools_lumerical_folder + '/lumapi_osx_fix.bash'
            lumapi_osx_fix_lib = path + '/libinterop-api.so.1'
            if not os.path.exists(lumapi_osx_fix_lib):
                warning = pya.QMessageBox()
                warning.setStandardButtons(pya.QMessageBox.Ok)
                warning.setText(
                    "We need to do a fix in the Lumerical software folder for Python integration. \nPlease note that for this to work, we assume that Lumerical INTERCONNECT is installed in the default path: /Applications/Lumerical/INTERCONNECT/\nPlease enter the following in a Terminal.App window, and enter your root password when prompted. Ok to continue when done."
                )
                warning.setInformativeText("source %s" % lumapi_osx_fix)
                pya.QMessageBox_StandardButton(warning.exec_())
                #        print (commands.getstatusoutput('chmod a+x %s' % lumapi_osx_fix ))
                if not os.path.exists(lumapi_osx_fix_lib):
                    print(
                        commands.getstatusoutput(
                            '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal %s'
                            % lumapi_osx_fix))

    # Windows
    elif platform.system() == 'Windows':
        if os.path.exists(path):
            if not path in sys.path:
                sys.path.append(path)  # windows
            os.chdir(path)

    # for all operating systems:
    from .. import _globals
    if not _globals.LUMAPI:
        try:
            import lumapi
            _globals.LUMAPI = lumapi
        except:
            print('import lumapi failed')
            return

    print('import lumapi success, %s' % _globals.LUMAPI)
    #    _globals.INTC = lumapi.open('interconnect')
    #    _globals.FDTD = lumapi.open('fdtd')

    os.chdir(CWD)
コード例 #4
0
    def __init__(self, parent=None):
        super(ImageToLayout, self).__init__()
        self.setWindowTitle("Image to Layout")

        self.window_width = 800
        self.window_height = 600

        self.resize(self.window_width, self.window_height)

        self.layout = pya.QGridLayout(self)

        self.input_text = pya.QLineEdit(self)
        self.input_text.setAcceptDrops(True)
        self.input_text.setFont(pya.QFont('Times', 15))

        self.input_text.setText("select image:")

        self.file_dialog = pya.QFileDialog(self)
        self.file_dialog.setFont(pya.QFont('Times', 10))

        self.select_file_button = pya.QPushButton("select image", self)
        self.select_file_button.setFont(pya.QFont('Times', 15, pya.QFont.Bold))
        self.select_file_button.clicked(self.select_file_button_clicked)

        self.convert_button = pya.QPushButton("convert to OASIS file", self)
        self.convert_button.setFont(pya.QFont('Times', 15, pya.QFont.Bold))
        self.convert_button.clicked(self.covert_buttion_clicked)

        self.raw_image_label = pya.QLabel()

        self.raw_image_info_label = pya.QLabel("image size:")
        self.raw_image_info_label.setVisible(False)

        self.threshold_text = pya.QLineEdit(self)
        self.threshold_text.setAcceptDrops(True)
        self.threshold_text.setFont(pya.QFont('Times', 15))
        self.threshold_text.setText("set threshold: 0 - 255")

        self.dbu_text = pya.QLineEdit(self)
        self.dbu_text.setAcceptDrops(True)
        self.dbu_text.setFont(pya.QFont('Times', 15))
        self.dbu_text.setText("set DBU: ")

        self.inverse_checkbox = pya.QCheckBox("inverse", self)
        self.inverse_checkbox.setFont(pya.QFont('Times', 15))

        self.progress_bar = pya.QProgressBar(self)

        self.layout.addWidget(self.input_text, 0, 0)
        self.layout.addWidget(self.select_file_button, 0, 1)
        self.layout.addWidget(self.raw_image_label, 1, 0, 3, 1)

        self.layout.addWidget(self.threshold_text, 1, 1)
        self.layout.addWidget(self.inverse_checkbox, 2, 1)
        self.layout.addWidget(self.dbu_text, 3, 1)

        self.layout.addWidget(self.raw_image_info_label, 4, 0)

        self.layout.addWidget(self.progress_bar, 5, 0)
        self.layout.addWidget(self.convert_button, 5, 1)

        self.setLayout(self.layout)