├── PyPLANE ├── __init__.py ├── core_info.py ├── resources │ ├── gallery_1D.json │ └── gallery_2D.json ├── defaults.py ├── gallery.py ├── ui_layouts.py ├── analysis.py ├── equations.py ├── trajectory.py └── ui_main_window.py ├── MANIFEST.in ├── requirements.txt ├── screenshot_1.png ├── screenshot_2.png ├── screenshot_3.png ├── tests ├── context.py ├── test_SystemOfEquations.py └── test_DifferentialEquation.py ├── setup.py ├── .pre-commit-config.yaml ├── .gitignore ├── bin └── run.py ├── .github └── workflows │ └── greetings.yml ├── run.py ├── README.md ├── CODE_OF_CONDUCT.md └── LICENSE /PyPLANE/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include PyPLANE/resources/*.json 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | sympy 3 | matplotlib 4 | PyQt5 5 | scipy 6 | pre-commit 7 | -------------------------------------------------------------------------------- /screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-squared96/PyPLANE/HEAD/screenshot_1.png -------------------------------------------------------------------------------- /screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-squared96/PyPLANE/HEAD/screenshot_2.png -------------------------------------------------------------------------------- /screenshot_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-squared96/PyPLANE/HEAD/screenshot_3.png -------------------------------------------------------------------------------- /PyPLANE/core_info.py: -------------------------------------------------------------------------------- 1 | # A single place to set core info about PyPLANE 2 | 3 | VERSION = "0.2-beta" 4 | LICENCE = "GPL-3.0" 5 | -------------------------------------------------------------------------------- /tests/context.py: -------------------------------------------------------------------------------- 1 | # This file is used to allow the test files to find the source files in source/ 2 | import os 3 | import sys 4 | 5 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) 6 | 7 | import PyPLANE 8 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from PyPLANE.core_info import VERSION 3 | 4 | setup ( 5 | name = "PyPLANE", 6 | packages = ["PyPLANE"], 7 | version = VERSION, 8 | scripts = ['bin/run.py'], 9 | license = "GPL V3", 10 | include_package_data = True, 11 | ) 12 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v2.3.0 4 | hooks: 5 | - id: check-yaml 6 | - id: end-of-file-fixer 7 | - id: trailing-whitespace 8 | - repo: https://github.com/psf/black 9 | rev: 19.3b0 10 | hooks: 11 | - id: black 12 | language_version: python3.7 13 | -------------------------------------------------------------------------------- /tests/test_SystemOfEquations.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import sympy as sp 4 | from sympy import symbols 5 | 6 | import context 7 | from PyPLANE.equations import DifferentialEquation 8 | 9 | from PyPLANE.equations import SystemOfEquations 10 | 11 | 12 | class TestSystemOfEquations(unittest.TestCase): 13 | pass 14 | 15 | 16 | if __name__ == "__main__": 17 | unittest.main() 18 | -------------------------------------------------------------------------------- /PyPLANE/resources/gallery_1D.json: -------------------------------------------------------------------------------- 1 | { 2 | "gallery" : [ 3 | { 4 | "system_name": "Example system - sine wave", 5 | "system_coords": ["x"], 6 | "ode_expr_strings": ["a*sin(bx)"], 7 | "params": {"a": 1, "b": 1}, 8 | "t_f": 5, 9 | "t_r": -5, 10 | "axes_limits": [[-5, 5], [-10, 10]] 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled Python files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # VS Code directory files 7 | .vscode/ 8 | 9 | # Python virtual environment 10 | env/ 11 | 12 | # Vim swap files 13 | *.swp 14 | 15 | # PyCharm files 16 | .idea/ 17 | 18 | # snap packages 19 | *.snap 20 | 21 | # Kde Advanced Text Editor (Kate) Project file 22 | .kateproject 23 | 24 | # pyinstaller files 25 | build/ 26 | dist/ 27 | *.spec 28 | -------------------------------------------------------------------------------- /bin/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | This is used to execute PyPLANE from the snap package 4 | """ 5 | 6 | import sys 7 | import os 8 | from PyQt5.QtWidgets import QApplication 9 | from PyQt5.QtGui import QIcon 10 | from PyPLANE.ui_main_window import MainWindow 11 | 12 | print(os.getcwd()) 13 | 14 | app = QApplication(sys.argv) 15 | app_main_window = MainWindow() 16 | app.setWindowIcon(QIcon("/snap/pyplane/current/meta/gui/pyplane.png")) 17 | sys.exit(app.exec()) 18 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: 'Hi and thanks for taking the time to contribute to PyPLANE, the little ODE solver that can! Feel free to fork the repo to get started on this issue if you have a solution in mind.' 13 | pr-message: 'Hi and thanks for submitting the pull request. This will be seen all the sooner if you assign a reviewer!' 14 | -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | This file should be used to run PyPLANE from the project folder while testing. 4 | eg. `python3 ./run` 5 | 6 | It is also to be used to build the Windows binary 7 | ie. `pyinstaller.exe --onefile --noconsole .\run` (DEPRICATED) 8 | """ 9 | 10 | import sys 11 | import os 12 | from PyQt5.QtWidgets import QApplication 13 | from PyQt5.QtGui import QIcon 14 | from PyPLANE.ui_main_window import MainWindow 15 | 16 | print(os.getcwd()) 17 | 18 | app = QApplication(sys.argv) 19 | app_main_window = MainWindow() 20 | app.setWindowIcon(QIcon("snap/gui/pyplane.png")) 21 | sys.exit(app.exec()) 22 | -------------------------------------------------------------------------------- /PyPLANE/defaults.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from PyPLANE.equations import SystemOfEquations 4 | from PyPLANE.trajectory import PhaseSpace2D 5 | from PyPLANE.gallery import Gallery 6 | 7 | 8 | def psp_by_dimensions(dims) -> PhaseSpace2D: 9 | 10 | if dims == 1: 11 | return one_dimensional_default() 12 | if dims == 2: 13 | return two_dimensional_default() 14 | else: 15 | raise ValueError("Unsupported number of ODE system dimensions") 16 | 17 | 18 | def one_dimensional_default() -> dict: 19 | 20 | gallery_1D = Gallery("resources/gallery_1D.json", 1) 21 | default_sys = "Example system - sine wave" 22 | sys_params = gallery_1D.get_system(default_sys) 23 | return sys_params 24 | 25 | 26 | def two_dimensional_default() -> dict: 27 | 28 | gallery_2D = Gallery("resources/gallery_2D.json", 2) 29 | default_sys = "Van der Pol's Equation" 30 | sys_params = gallery_2D.get_system(default_sys) 31 | return sys_params 32 | -------------------------------------------------------------------------------- /tests/test_DifferentialEquation.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import sympy as sp 4 | from sympy import symbols 5 | 6 | import context 7 | from PyPLANE.equations import DifferentialEquation 8 | 9 | 10 | class TestDifferentialEquation(unittest.TestCase): 11 | def test_expression_parsed_correctly(self): 12 | 13 | ode = DifferentialEquation("x", ["x", "y"], "x*sin(y)^2 - y^3") 14 | x, y = symbols("x, y") 15 | expected_expr = x * sp.sin(y) ** 2 - y ** 3 16 | self.assertEqual(expected_expr, ode.expr) 17 | 18 | def test_parameters_are_extracted_correctly(self): 19 | 20 | ode = DifferentialEquation("x", ["x", "y"], "ax + bcy") 21 | expected_params = set(symbols("a, b, c")) 22 | self.assertEqual(set(expected_params), set(ode.params)) 23 | 24 | ode = DifferentialEquation("x", ["x"], "eftx") 25 | expected_params = set(symbols("e, f")) 26 | self.assertEqual(set(expected_params), set(ode.params)) 27 | 28 | def test_set_param(self): 29 | 30 | ode = DifferentialEquation("x", ["x", "y"], "ax + bcy") 31 | ode.set_param("a", 10) 32 | self.assertEqual(ode.param_values["a"], 10) 33 | 34 | 35 | if __name__ == "__main__": 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /PyPLANE/gallery.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | 4 | class Gallery: 5 | def __init__(self, gallery_file_name, num_dims): 6 | self.num_dims = num_dims 7 | 8 | with open(gallery_file_name, "r") as f: 9 | gallery_dict = json.load(f) 10 | 11 | gallery_list = gallery_dict["gallery"] 12 | self.SOE_params = {sys["system_name"]: sys for sys in gallery_list} 13 | 14 | def __str__(self): 15 | gallery_str = json.dumps(self.SOE_params, sort_keys=True, indent=4) 16 | return gallery_str 17 | 18 | def get_system_names(self): 19 | return list(self.SOE_params.keys()) 20 | 21 | def get_system(self, sys_name): 22 | return self.SOE_params[sys_name] 23 | 24 | def __iter__(self): 25 | return GalleryIterator(self) 26 | 27 | 28 | class GalleryIterator: 29 | def __init__(self, gallery): 30 | self.gallery = gallery 31 | self.index = 0 32 | self.gallery_items = gallery.get_system_names() 33 | self.gallery_len = len(self.gallery_items) 34 | 35 | def __next__(self): 36 | if self.index > self.gallery_len - 1: 37 | raise StopIteration 38 | sys_name = self.gallery_items[self.index] 39 | self.index += 1 40 | return self.gallery.get_system(sys_name) 41 | 42 | 43 | if __name__ == "__main__": 44 | g = Gallery("resources/gallery_2D.json", 2) 45 | print(g) 46 | -------------------------------------------------------------------------------- /PyPLANE/ui_layouts.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtWidgets import ( 2 | QHBoxLayout, 3 | QLineEdit, 4 | QLabel, 5 | ) 6 | 7 | class EquationEntryLayout(QHBoxLayout): 8 | def __init__(self, dep_var, equation_rhs): 9 | QHBoxLayout.__init__(self) 10 | self.dep_var = dep_var 11 | self.eqn_rhs_line_edit = QLineEdit(equation_rhs) 12 | self.addWidget(QLabel(dep_var + "' =")) 13 | self.addWidget(self.eqn_rhs_line_edit) 14 | 15 | def text(self): 16 | return self.eqn_rhs_line_edit.text() 17 | 18 | def set_text(self, text): 19 | self.eqn_rhs_line_edit.setText(text) 20 | 21 | def clear(self): 22 | self.eqn_rhs_line_edit.clear() 23 | 24 | 25 | class ParameterEntryLayout(QHBoxLayout): 26 | def __init__(self, param_name="", param_val=""): 27 | QHBoxLayout.__init__(self) 28 | self.param_name_line_edit = QLineEdit(param_name) 29 | self.param_val_line_edit = QLineEdit(str(param_val)) 30 | 31 | self.addWidget(self.param_name_line_edit) 32 | self.addWidget(QLabel("=")) 33 | self.addWidget(self.param_val_line_edit) 34 | 35 | def param_name_text(self): 36 | return self.param_name_line_edit.text() 37 | 38 | def param_val_text(self): 39 | return self.param_val_line_edit.text() 40 | 41 | def set_param_name_text(self, name): 42 | self.param_name_line_edit.setText(name) 43 | 44 | def set_param_val_text(self, val): 45 | self.param_val_line_edit.setText(str(val)) 46 | 47 | def set_name_val_text(self, name, val): 48 | self.set_param_name_text(name) 49 | self.set_param_val_text(str(val)) 50 | 51 | def clear(self): 52 | self.param_name_line_edit.clear() 53 | self.param_val_line_edit.clear() 54 | 55 | 56 | class AxisLimitEntryLayout(QHBoxLayout): 57 | def __init__(self, var_name, var_min_val, var_max_val): 58 | QHBoxLayout.__init__(self) 59 | self.var_name = var_name 60 | self.min_val_line_edit = QLineEdit(str(var_min_val)) 61 | self.max_val_line_edit = QLineEdit(str(var_max_val)) 62 | 63 | self.addWidget(QLabel(f"Max {var_name} =")) 64 | self.addWidget(self.max_val_line_edit) 65 | self.addWidget(QLabel(f"Min {var_name} =")) 66 | self.addWidget(self.min_val_line_edit) 67 | 68 | def max_val_text(self): 69 | return self.max_val_line_edit.text() 70 | 71 | def min_val_text(self): 72 | return self.min_val_line_edit.text() 73 | 74 | def set_min_val_text(self, val): 75 | self.min_val_line_edit.setText(str(val)) 76 | 77 | def set_max_val_text(self, val): 78 | self.max_val_line_edit.setText(str(val)) 79 | 80 | def set_min_max_text(self, min_val, max_val): 81 | self.set_min_val_text(min_val) 82 | self.set_max_val_text(max_val) 83 | 84 | def clear(self): 85 | self.min_val_line_edit.clear() 86 | self.max_val_line_edit.clear() 87 | 88 | -------------------------------------------------------------------------------- /PyPLANE/resources/gallery_2D.json: -------------------------------------------------------------------------------- 1 | { 2 | "gallery" : [ 3 | { 4 | "system_name": "Default 2D system", 5 | "system_coords": ["x", "y"], 6 | "ode_expr_strings": ["ax-y+b(x^2-y^2)+axy", "x-cy-d(x^2-y^2)+cxy"], 7 | "params": {"a": 2, "b": 3, "c": 3, "d": 3}, 8 | "t_f": 10, 9 | "t_r": -10, 10 | "axes_limits": [[-10, 10], [-10, 10]] 11 | }, 12 | { 13 | "system_name": "Linear system", 14 | "system_coords": ["x", "y"], 15 | "ode_expr_strings": ["ax + by", "cx + dy"], 16 | "params": {"a": 1, "b": -1, "c": 1, "d": 1}, 17 | "t_f": 10, 18 | "t_r": -10, 19 | "axes_limits": [[-5, 5], [-5, 5]] 20 | }, 21 | { 22 | "system_name":"Vibrating string", 23 | "system_coords": ["x", "y"], 24 | "ode_expr_strings": ["y", "-(kx + dy)/m"], 25 | "params": {"k": 3, "d": 0, "m": 1}, 26 | "t_f": 10, 27 | "t_r": -10, 28 | "axes_limits": [[-5, 5], [-5, 5]] 29 | }, 30 | { 31 | "system_name":"Pendulum", 32 | "system_coords": ["x", "y"], 33 | "ode_expr_strings": ["y", "-(g/l) * sin(x) - (c/ml) * y"], 34 | "params": {"g": 9.8, "l": 9.8, "m": 1, "c": 0}, 35 | "t_f": 10, 36 | "t_r": -10, 37 | "axes_limits": [[-10, 10], [-4, 4]] 38 | }, 39 | 40 | { 41 | "system_name":"Predator / Prey", 42 | "system_coords": ["x", "y"], 43 | "ode_expr_strings": ["(a-by)x", "(dx-c)y"], 44 | "params": {"a": 0.4, "b": 0.01, "c": 0.3, "d": 0.005}, 45 | "t_f": 10, 46 | "t_r": -10, 47 | "axes_limits": [[0, 120], [0, 80]] 48 | }, 49 | { 50 | "system_name":"Competing Species", 51 | "system_coords": ["x", "y"], 52 | "ode_expr_strings": ["(1-x-y)x", "(a-bx-cy)y"], 53 | "params": {"a": 4, "b": 2, "c": 7}, 54 | "t_f": 10, 55 | "t_r": -10, 56 | "axes_limits": [[0, 1], [0, 1]] 57 | }, 58 | { 59 | "system_name":"Van der Pol's Equation", 60 | "system_coords": ["x", "y"], 61 | "ode_expr_strings": ["mx - y - x^3", "x"], 62 | "params": {"m": 2}, 63 | "t_f": 10, 64 | "t_r": -10, 65 | "axes_limits": [[-5, 5], [-5, 5]] 66 | }, 67 | { 68 | "system_name":"Duffing Equation", 69 | "system_coords": ["x", "y"], 70 | "ode_expr_strings": ["y", "-(kx - cy + lx^3)/m"], 71 | "params": {"k": -1, "c": 0, "l": 1, "m": 1}, 72 | "t_f": 10, 73 | "t_r": -10, 74 | "axes_limits": [[-5, 5], [-5, 5]] 75 | }, 76 | { 77 | "system_name":"Milonni-Eberly laser model", 78 | "system_coords": ["x", "y"], 79 | "ode_expr_strings": ["gxy - kx", "-gxy - fy + p"], 80 | "params": {"g": 2, "k": 1, "f": 1, "p": 1}, 81 | "t_f": 10, 82 | "t_r": -10, 83 | "axes_limits": [[0, 4], [0, 4]] 84 | } 85 | ] 86 | } 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyPLANE 2 | 3 | An open source replacement to the traditional DFIELD and PPLANE applications for solving systems of ODEs 4 | 5 | ![Default 2D system](screenshot_1.png) 6 | ![2D system with trajectories](screenshot_2.png) 7 | ![1D system with trajectories](screenshot_3.png) 8 | 9 | ## About 10 | 11 | PyPLANE is an open source Python application used for the visualisation and (numerical/graphical) solving of systems of 12 | ODEs. PyPLANE is released under the GPL-3.0 13 | 14 | ## Installing Pyplane 15 | 16 | PyPLANE is available on the Snap Store for Linux 17 | 18 | [![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/pyplane) 19 | 20 | ## Quick Start 21 | 22 | If you are using Linux and have installed via the Snap store PyPLANE should appear in your application launcher. If you use 23 | Windows or Mac instead, or don't use the Snap store on Linux, you can clone the repository from GitHub and run the top-level 24 | run.py file using Python 3. Note that you will need to have installed the following Python libraries for this method: 25 | * NumPy 26 | * SymPy 27 | * SciPy 28 | * Matplotlib 29 | * PyQt5 30 | 31 | The code snippet below will set up a Python environment to run PyPLANE in isolation without affecting the global Python 32 | install. The required libraries listed above will also be installed: 33 | 34 | #### Linux 35 | Ensure that git, and Python3 and the corresponding venv package (`python3-venv` on Ubuntu) are installed. Then clone the PyPLANE repository and set up the virtual environment as follows. 36 | ```bash 37 | $ git clone https://github.com/m-squared96/PyPLANE 38 | $ cd PyPLANE/ 39 | $ python3 -m venv env 40 | $ source env/bin/activate 41 | $ pip install -r requirements.txt 42 | ``` 43 | 44 | PyPLANE can then be launched using: 45 | ```bash 46 | $ cd /path/to/PyPLANE 47 | $ source env/bin/activate 48 | $ python3 ./run.py 49 | ``` 50 | 51 | One way or another, you should now have launched PyPLANE! 52 | 53 | ## Quick User Guide 54 | 55 | ### The Phase Space Plot 56 | The phase space plot on the right hand side of the application GUI can be interfaced directly with the mouse. By 57 | double-clicking on the plot a trajectory is plotted, with the click-coordinates used as an initial condition. 58 | 59 | Furthermore, nullclines and fixed points can be toggle on/off from the Edit menu. 60 | 61 | ### Editing the System 62 | One of PyPLANE's main features is its ability to analyse both one- and two-dimensional systems. To change the number of 63 | dimensions select the appropriate option from the Dimensions menu. 64 | 65 | On the one-dimensional interface, the only dependent variable is x, with the independent variable being t. For two 66 | dimensions the dependent variables are x and y. 67 | 68 | In the text box(es) in the top left of the screen, the user can define the expressions used for the system's 69 | derivative(s). Any symbols in the text boxes should conform to one of the points below: 70 | * Mathematical operators/functions (i.e. +,-,*,/,sin,cos etc.); 71 | * References to the dependent or independent variables (t,x,y); 72 | * References to parameters; 73 | 74 | Parameters are constants which can take any value; they can be edited in the text boxes provided below the axes limits. 75 | Any constant parameters referenced in the derivative definitions should be defined in the boxes provided. 76 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | 78 | -------------------------------------------------------------------------------- /PyPLANE/analysis.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtWidgets import ( 2 | QApplication, 3 | QMainWindow, 4 | QWidget, 5 | QLabel, 6 | QLineEdit, 7 | QPushButton, 8 | QVBoxLayout, 9 | QHBoxLayout, 10 | QAction, 11 | QWidgetAction, 12 | QComboBox, 13 | QMenu, 14 | QMessageBox, 15 | QListWidget, 16 | QListWidgetItem, 17 | QAbstractItemView, 18 | QScrollBar, 19 | QCheckBox, 20 | QRadioButton, 21 | ) 22 | import numpy as np 23 | import matplotlib.pyplot as plt 24 | from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 25 | from mpl_toolkits.mplot3d import Axes3D 26 | 27 | 28 | class TCAWindow(QWidget): 29 | """ 30 | Selection menu consisting of candidate trajectories for TCA. 31 | """ 32 | def __init__(self, traj_dict) -> None: 33 | super().__init__() 34 | 35 | self.tvsx = True 36 | self.tvsy = False 37 | self.tvsxvsy = False 38 | 39 | self.plot_separately = True 40 | self.plot_together = False 41 | 42 | # Define layout and widgets 43 | self.layout = QVBoxLayout() 44 | 45 | # Listbox for selection of curves 46 | self.listwidget_label = QLabel().setText("Select curves for analysis") 47 | 48 | self.listwidget = QListWidget() # List widget for selecting trajectories 49 | self.listwidget.setGeometry(50, 70, 150, 80) 50 | self.listwidget.setSelectionMode(QAbstractItemView.MultiSelection) 51 | scroll_bar = QScrollBar(self) 52 | self.listwidget.setVerticalScrollBar(scroll_bar) 53 | #self.listwidget.addPermanentWidget(self.listwidget_label) 54 | 55 | self.traj_dict = traj_dict 56 | self.list_traj() 57 | 58 | # Tickboxes (AKA checkboxes) for components 59 | self.tickbox_label = QLabel().setText("Select components for analysis") 60 | 61 | self.component_tickbox_layout = QHBoxLayout() 62 | 63 | self.tickbox_tvsx = QCheckBox("t vs x(t)",self) 64 | self.tickbox_tvsx.setChecked(True) 65 | self.tickbox_tvsx.stateChanged.connect(self.toggle_tvsx) 66 | 67 | self.tickbox_tvsy = QCheckBox("t vs y(t)",self) 68 | self.tickbox_tvsy.stateChanged.connect(self.toggle_tvsy) 69 | 70 | self.tickbox_tvsxvsy = QCheckBox("t vs x(t) vs y(t)",self) 71 | self.tickbox_tvsxvsy.stateChanged.connect(self.toggle_tvsxvsy) 72 | 73 | self.component_tickbox_layout.addWidget(self.tickbox_tvsx) 74 | self.component_tickbox_layout.addWidget(self.tickbox_tvsy) 75 | self.component_tickbox_layout.addWidget(self.tickbox_tvsxvsy) 76 | 77 | # Radio buttons for plotting method 78 | self.radiobutton_label = QLabel().setText("Plot components together or separately") 79 | 80 | self.plotting_method_layout = QHBoxLayout() 81 | 82 | self.radiobutton_sep = QRadioButton("Separately", self) 83 | self.radiobutton_sep.setChecked(True) 84 | self.radiobutton_sep.toggled.connect(self.toggle_method_sep) 85 | 86 | self.radiobutton_tog = QRadioButton("Together", self) 87 | self.radiobutton_tog.setChecked(False) 88 | self.radiobutton_tog.toggled.connect(self.toggle_method_tog) 89 | 90 | self.plotting_method_layout.addWidget(self.radiobutton_sep) 91 | self.plotting_method_layout.addWidget(self.radiobutton_tog) 92 | 93 | # Big ol' plot button 94 | self.plot_button = QPushButton("Plot", self) 95 | self.plot_button.clicked.connect(self.plot_button_clicked) 96 | 97 | # Tying everything up 98 | #self.layout.addWidget(self.listwidget_label) 99 | self.layout.addWidget(self.listwidget) 100 | 101 | #self.layout.addWidget(self.tickbox_label) 102 | self.layout.addLayout(self.component_tickbox_layout) 103 | 104 | #self.layout.addWidget(self.radiobutton_label) 105 | self.layout.addLayout(self.plotting_method_layout) 106 | 107 | self.layout.addWidget(self.plot_button) 108 | 109 | self.setLayout(self.layout) 110 | 111 | def list_traj(self) -> None: 112 | """ 113 | Add trajectories to list widget 114 | """ 115 | keys = tuple(self.traj_dict.keys()) 116 | 117 | for k in keys: 118 | item = QListWidgetItem("Curve " + str(k)) 119 | self.listwidget.addItem(item) 120 | 121 | def toggle_tvsx(self): 122 | self.tvsx = not(self.tvsx) 123 | 124 | def toggle_tvsy(self): 125 | self.tvsy = not(self.tvsy) 126 | 127 | def toggle_tvsxvsy(self): 128 | self.tvsxvsy = not(self.tvsxvsy) 129 | 130 | def toggle_method_sep(self) -> None: 131 | self.plot_separately = True 132 | self.plot_together = False 133 | 134 | def toggle_method_tog(self) -> None: 135 | self.plot_separately = False 136 | self.plot_together = True 137 | 138 | def plot_button_clicked(self) -> None: 139 | curves = [int(i.text().replace("Curve ", "")) 140 | for i in self.listwidget.selectedItems()] 141 | 142 | self.tca_graphs(curves) 143 | 144 | #self.close() 145 | 146 | def tca_graphs(self, curves: list) -> None: 147 | 148 | if self.tvsx: 149 | self.tca_tvsx(curves, sep=self.plot_separately) 150 | 151 | if self.tvsy: 152 | self.tca_tvsy(curves, sep=self.plot_separately) 153 | 154 | if self.tvsxvsy: 155 | self.tca_tvsxvsy(curves, sep=self.plot_separately) 156 | 157 | plt.show() 158 | 159 | def tca_tvsx(self, curves: list, sep: bool) -> None: 160 | if not sep: 161 | plt.figure() 162 | 163 | for c in curves: 164 | if sep: 165 | plt.figure() 166 | 167 | traj_data = self.traj_dict[c] 168 | 169 | time_lims = traj_data["time_lims"] 170 | sol_f = traj_data["sol_f"].y[0,:] 171 | sol_r = np.flip(traj_data["sol_r"].y[0,:]) 172 | 173 | full_time = np.linspace(time_lims[0], time_lims[1], len(sol_f) + len(sol_r)) 174 | full_curve = np.concatenate((sol_r, sol_f)) 175 | 176 | plt.plot(full_time, full_curve, label="Curve " + str(c)) 177 | plt.legend() 178 | plt.xlabel(r'$t$') 179 | plt.ylabel(r'$x(t)$') 180 | plt.title('PyPLANE: ' + r'$t$' + ' vs ' + r'$x(t)$') 181 | 182 | def tca_tvsy(self, curves: list, sep: bool) -> None: 183 | if not sep: 184 | plt.figure() 185 | 186 | for c in curves: 187 | if sep: 188 | plt.figure() 189 | 190 | traj_data = self.traj_dict[c] 191 | 192 | time_lims = traj_data["time_lims"] 193 | sol_f = traj_data["sol_f"].y[1,:] 194 | sol_r = np.flip(traj_data["sol_r"].y[1,:]) 195 | 196 | full_time = np.linspace(time_lims[0], time_lims[1], len(sol_f) + len(sol_r)) 197 | full_curve = np.concatenate((sol_r, sol_f)) 198 | 199 | plt.plot(full_time, full_curve, label="Curve " + str(c)) 200 | plt.legend() 201 | plt.xlabel(r'$t$') 202 | plt.ylabel(r'$y(t)$') 203 | plt.title('PyPLANE: ' + r'$t$' + ' vs ' + r'$y(t)$') 204 | 205 | def tca_tvsxvsy(self, curves: list, sep: bool) -> None: 206 | 207 | #if not sep: 208 | fig = plt.figure() 209 | ax = fig.add_subplot(111, projection='3d') 210 | 211 | for c in curves: 212 | 213 | traj_data = self.traj_dict[c] 214 | time_lims = traj_data["time_lims"] 215 | 216 | sol_f_x = traj_data["sol_f"].y[0,:] 217 | sol_r_x = np.flip(traj_data["sol_r"].y[0,:]) 218 | full_curve_x = np.concatenate((sol_r_x, sol_f_x)) 219 | 220 | sol_f_y = traj_data["sol_f"].y[1,:] 221 | sol_r_y = np.flip(traj_data["sol_r"].y[1,:]) 222 | full_curve_y = np.concatenate((sol_r_y, sol_f_y)) 223 | 224 | full_time = np.linspace(time_lims[0], time_lims[1], len(full_curve_x)) 225 | 226 | ax.plot(full_time, full_curve_x, full_curve_y, label="Curve " + str(c)) 227 | 228 | ax.set_title(r'$t$' + ' vs ' + r'$x(t)$' + ' vs ' + r'$y(t)$') 229 | ax.set_xlabel(r'$t$') 230 | ax.set_ylabel(r'$x(t)$') 231 | ax.set_zlabel(r'$y(t)$') 232 | ax.legend() 233 | 234 | #else: 235 | # figlist = [] 236 | # for c in curves: 237 | 238 | # traj_data = self.traj_dict[c] 239 | # time_lims = traj_data["time_lims"] 240 | 241 | # sol_f_x = traj_data["sol_f"].y[0,:] 242 | # sol_r_x = np.flip(traj_data["sol_r"].y[0,:]) 243 | # full_curve_x = np.concatenate((sol_r_x, sol_f_x)) 244 | 245 | # sol_f_y = traj_data["sol_f"].y[1,:] 246 | # sol_r_y = np.flip(traj_data["sol_r"].y[1,:]) 247 | # full_curve_y = np.concatenate((sol_r_y, sol_f_y)) 248 | 249 | # full_time = np.linspace(time_lims[0], time_lims[1], len(full_curve_x)) 250 | 251 | # fig = plt.figure() 252 | # ax = fig.add_subplot(111, projection='3d') 253 | 254 | # ax.plot(full_time, full_curve_x, full_curve_y, label="Curve " + str(c)) 255 | 256 | # ax.set_title(r'$t$' + ' vs ' + r'$x(t)$' + ' vs ' + r'$y(t)$') 257 | # ax.set_xlabel(r'$t$') 258 | # ax.set_ylabel(r'$x(t)$') 259 | # ax.set_zlabel(r'$y(t)$') 260 | # ax.legend() 261 | 262 | # figlist.append(fig, ax) 263 | -------------------------------------------------------------------------------- /PyPLANE/equations.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import sympy as sp 4 | 5 | from scipy.integrate import solve_ivp 6 | from sympy.utilities.lambdify import lambdify 7 | from sympy import symbols, Matrix 8 | from sympy.matrices.dense import matrix2numpy 9 | from sympy.parsing.sympy_parser import ( 10 | parse_expr, 11 | standard_transformations, 12 | split_symbols, 13 | implicit_multiplication, 14 | convert_xor, 15 | ) 16 | 17 | # transformation functions that modify the equation parser 18 | TRANSFORMATIONS = standard_transformations + ( 19 | split_symbols, # used for implicit multiplication 20 | implicit_multiplication, # makes multiplication operator (*) optional 21 | convert_xor, # ^ used for exponentiation 22 | ) 23 | 24 | 25 | class DifferentialEquation: 26 | """ 27 | Handles first-order ODE's 28 | """ 29 | 30 | def __init__(self, dep_var, phase_coords, expr_string) -> None: 31 | # dep_var is converted from a string into the corresponding Sympy symbol 32 | self.dep_var = symbols(dep_var) 33 | 34 | # indep_var is the t in dx/dt = f(x, t). For now it will be set to "t" for time 35 | self.indep_var = symbols("t") 36 | 37 | # phase_coords is an iterable of the degrees of freedom of the system. 38 | # It is passed as an iterable of single-char strings 39 | self.phase_coords = tuple(symbols(phase_coords)) 40 | 41 | # expr is the Sympy expression representing the RHS of the ODE. 42 | self.expr = parse_expr(expr_string, transformations=TRANSFORMATIONS) 43 | 44 | # params are the symbols in the expression less the independent variable and the phase coordinates 45 | self.params = [ 46 | s 47 | for s in self.expr.free_symbols 48 | if s not in (self.phase_coords + (self.indep_var,)) 49 | ] 50 | 51 | # param_values maps a parameter string to its numerical value. 52 | # It is used when the ODE is evaluated as a function. 53 | # Each parameter in param_values must be set before the ODE expression 54 | # can be numerically evaluated. 55 | self.param_values = dict.fromkeys([str(p) for p in self.params]) 56 | 57 | # func is the mathematical function generated from self.expr. 58 | # It is used to numerically solve the equation. 59 | self.func = lambdify( 60 | [self.indep_var, self.phase_coords, *self.params], self.expr 61 | ) 62 | 63 | def set_param(self, param, value) -> None: 64 | """ 65 | Sets self.param_values[param] to value. 66 | If 67 | """ 68 | if param in self.param_values: 69 | self.param_values[param] = value 70 | 71 | def eval_rhs(self, t, r): 72 | # the r argument is expected to be a vector, so scalars are first packed into a list 73 | if np.isscalar(r): 74 | r = [r] 75 | return self.func(t, r, **self.param_values) 76 | 77 | def __str__(self) -> str: # implemented for readable printing of equation 78 | return f"d{self.dep_var}/dt = {self.expr}" 79 | 80 | 81 | class SystemOfEquations: 82 | """ 83 | System of ODE's. Handles solving and evaluating the ODE's. 84 | """ 85 | 86 | def __init__( 87 | self, system_coords, ode_expr_strings, solve_method="RK45", params=None, *args, **kwargs 88 | ) -> None: 89 | # ode_expr_strings is a dictionary that maps the dependent variable 90 | # of the equation (e.g. x in dx/dt = f(x,t)) to the corresponding 91 | # differential equation. 92 | self.ode_expr_strings = ode_expr_strings 93 | self.system_coords = system_coords 94 | self.system_coord_symbols = symbols(system_coords) 95 | self.dims = len(self.system_coords) 96 | 97 | # generate the list of expressions representing the system. 98 | # The elements in system_coords and ode_expr_strings are assumed 99 | # to correspond to each other in the order given. 100 | # i.e. system_coords[i] pairs with ode_expr_strings[i] 101 | self.equations = [ 102 | DifferentialEquation(coord, system_coords, expr) 103 | for coord, expr in zip(system_coords, ode_expr_strings) 104 | ] 105 | 106 | # Set the parameters in the ODEs 107 | self.params = params 108 | for p, val in params.items(): 109 | for eqn in self.equations: 110 | eqn.set_param(p, val) 111 | 112 | # Calculate the symbolic Jacobian of the system 113 | r = Matrix([equation.expr for equation in self.equations]) 114 | self.jacobian = r.jacobian(self.system_coord_symbols) 115 | # print(f"Jacobian: {self.jac}") 116 | 117 | # calculated fixed points are cached here 118 | try: 119 | self.fixed_points = self.calc_fixed_points() 120 | except: 121 | print("Could not symbolically calculate fixed points.") 122 | 123 | self.valid_solve_methods = ["RK45", "RK23", "DOP853", "Radau", "BDF", "LSODA"] 124 | self.set_solve_method(solve_method) 125 | 126 | def __str__(self) -> str: 127 | return f"{self.__repr__()}" + "\n".join(f"{eqn}" for eqn in self.equations) 128 | 129 | def set_solve_method(self, method: str): 130 | """ 131 | Sets the method for solving the system of ODEs. 132 | 133 | The solver method can be one of the following: 134 | RK45 - Explicit Runge-Kutta method of order 5(4). 135 | RK23 - Explicit Runge-Kutta method of order 3(2). 136 | DOP853 - Explicit Runge-Kutta method of order 8. 137 | Radau - Implicit Runge-Kutta method of the Radau IIA family of order 5 138 | BDF - Implicit multi-step variable-order (1 to 5) method based on a 139 | backward differentiation formula for the derivative approximation. 140 | LSODA - Adams/BDF method with automatic stiffness detection and switching. 141 | 142 | For more information, see the solve_ivp documentation: 143 | https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html 144 | """ 145 | 146 | if method not in self.valid_solve_methods: 147 | raise ValueError( 148 | "Solver method must be one of the following: {}".format( 149 | self.valid_solve_methods 150 | ) 151 | ) 152 | else: 153 | self.solve_method = method 154 | 155 | def solve(self, t_span, r0, method=None): 156 | method = method if method is not None else self.solve_method 157 | return solve_ivp( 158 | self.phasespace_eval, t_span, r0, method=method, max_step=0.005 159 | ) 160 | 161 | def phasespace_eval(self, t, r) -> tuple: 162 | """ 163 | Allows for the phase space to be evaluated using the SOE class. 164 | 165 | Example: 166 | >>> import numpy as np 167 | >>> from equations import SystemOfEquations 168 | >>> sys = SystemOfEquations(phase_coords, eqns, params=params) 169 | >>> X, Y = np.meshgrid(np.arange(-10, 10, 1), np.arange(-10, 10, 1)) 170 | >>> U, V = sys.phasespace_eval(t=None, r=np.array([X,Y])) 171 | 172 | Added by Mikie on 29/05/2019 173 | """ 174 | return tuple(eqn.eval_rhs(t=t, r=r) for eqn in self.equations) 175 | 176 | def eval_jacobian(self, r): 177 | """ 178 | Evaluates the symbolic Jacobian of the system at the point r 179 | """ 180 | # The subs method substitutes one symbol or value for another 181 | jacobian = self.jacobian.subs(self.params) 182 | jacobian = jacobian.subs(list(zip(self.system_coord_symbols, r))) 183 | return jacobian 184 | 185 | def show_jacobian(self, eval=False, r=None): 186 | """ 187 | Prints Jacobian. May be evaluated at a point first, or printed symbolically 188 | """ 189 | 190 | jacobian = self.eval_jacobian(r) if eval else self.jacobian 191 | sp.pprint(jacobian) 192 | 193 | def eigenvects(self, r=None): 194 | """ 195 | Calculates the eigenvalues and eigenvectors of the system's Jacobian. 196 | Return list of triples (eigenval, multiplicity, eigenspace). 197 | """ 198 | 199 | jacobian = self.eval_jacobian(r) if r is not None else self.jacobian 200 | return jacobian.eigenvects(simplify=True) 201 | 202 | def calc_fixed_points(self): 203 | """ 204 | Returns a set of fixed points as tuples. 205 | """ 206 | 207 | eqns = [eqn.expr for eqn in self.equations] 208 | eqns = [eqn.subs(self.params) for eqn in eqns] 209 | _, fps = sp.solve(eqns, self.system_coord_symbols, set=True) 210 | 211 | fps_as_cmplx = {tuple(complex(z) for z in fp) for fp in fps} 212 | fps_rounded = {tuple(round_complex(z, 3) for z in fp) for fp in fps_as_cmplx} 213 | fps_no_cmplx = { 214 | fp for fp in fps_rounded if all(not abs(z.imag) > 0 for z in fp) 215 | } 216 | fps_real = {tuple(z.real for z in fp) for fp in fps_no_cmplx} 217 | 218 | return fps_real 219 | 220 | def find_fixed_point(self, r_init): 221 | """ 222 | Returns the value of a fixed point based a Newton's method computation. 223 | See https://en.wikipedia.org/wiki/Newton%27s_method for details. 224 | """ 225 | 226 | num_iter = 50 227 | r = r_init 228 | 229 | for _ in range(num_iter): 230 | J = self.eval_jacobian(r) 231 | J_inv = matrix2numpy(J.inv(), dtype="float") 232 | r = r - J_inv.dot(self.phasespace_eval(t=None, r=r)) 233 | 234 | self.fixed_points.add(r) 235 | return r 236 | 237 | 238 | def round_complex(x, n): 239 | return round(x.real, n) + round(x.imag, n) * 1j 240 | 241 | 242 | def get_closest_point(point, other_points): 243 | 244 | closest_point = None 245 | closest_distance = None 246 | 247 | for pt in other_points: 248 | if closest_distance is None: 249 | closest_point = pt 250 | closest_distance = np.hypot(pt, point) 251 | continue 252 | 253 | distance = np.hypot(point, pt) 254 | if distance < closest_distance: 255 | closest_point = pt 256 | closest_distance = distance 257 | 258 | return closest_point 259 | 260 | 261 | def example(): 262 | # 2-D 263 | system_coords = ["x", "y"] 264 | # eqns = ["ax + by", "cx + dy"] 265 | eqns = ["2x - y + 3(x^2-y^2) + 2xy", "x - 3y - 3(x^2-y^2) + 3xy"] 266 | params = {"a": -1, "b": 5, "c": -4, "d": -2} 267 | r0 = [0.4, -0.3] 268 | t_span = (0, 40) 269 | 270 | sys = SystemOfEquations(system_coords, eqns, params=params) 271 | print(sys) 272 | 273 | # r = [0.5, 0.5] 274 | r = [-1, -1] 275 | print(f"Jacobian evaluated at {r}:") 276 | sys.show_jacobian(eval=True, r=r) 277 | 278 | print(f"finding fixed point from initial guess {r}...") 279 | fp = sys.find_fixed_point(r) 280 | print(f"fixed point: {fp}") 281 | fp_jac = sys.eval_jacobian(fp) 282 | sp.pprint(fp_jac) 283 | sp.pprint(fp_jac.trace()) 284 | sp.pprint(fp_jac.det()) 285 | 286 | print("\nFixed points:\n") 287 | print(sys.calc_fixed_points()) 288 | 289 | # Calculate eigenvalues and eigenvectors 290 | sp.pprint(sys.eigenvects(r)) 291 | 292 | sol = sys.solve(t_span, r0) 293 | print(sol) 294 | plt.plot(sol.y[0], sol.y[1]) 295 | plt.show() 296 | 297 | 298 | if __name__ == "__main__": 299 | example() 300 | -------------------------------------------------------------------------------- /PyPLANE/trajectory.py: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterable 2 | 3 | import numpy as np 4 | import matplotlib 5 | import matplotlib.pyplot as plt 6 | from matplotlib.figure import Figure 7 | from matplotlib.backend_bases import NavigationToolbar2, Event 8 | from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigCanvas 9 | from mpl_toolkits.mplot3d import Axes3D 10 | 11 | from PyPLANE.equations import SystemOfEquations 12 | 13 | DEFAULT_TRAJ_COLOUR = "#0066FF" 14 | DEFAULT_MARK_COLOUR = "#FF0000" 15 | 16 | class PhaseSpaceParent(FigCanvas): 17 | """ 18 | Accepts a system of equations (equations.SystemOfEqutions object) and produces 19 | a phase plot. Individual trajectories evaluated upon click event. 20 | 21 | For now, can handle up to three-dimensional systems. An arbitrary number of dimensions 22 | may require a lot of work. 23 | """ 24 | 25 | def __init__( 26 | self, 27 | dimensions: int, 28 | fw_time_lim: float = 5.0, 29 | bw_time_lim: float = -5.0, 30 | *args, 31 | **kwargs, 32 | ) -> None: 33 | 34 | self.dimensions = dimensions 35 | self.fig = Figure() 36 | object.__init__(self) 37 | FigCanvas.__init__(self, self.fig) 38 | self.ax = self.fig.add_subplot(111) 39 | self.time_f = fw_time_lim 40 | self.time_r = bw_time_lim 41 | 42 | NavigationToolbar2.home = self.handle_home 43 | 44 | def get_calc_limits(self, lims: list) -> (float, float): 45 | """ 46 | Returns the limits to be used in the mesh grid generation expanded with the 47 | self.quiver_expansion_factor variable 48 | """ 49 | extension = np.abs(lims[1] - lims[0]) * self.quiver_expansion_factor * 0.5 50 | min_lim = lims[0] - extension 51 | max_lim = lims[1] + extension 52 | 53 | return min_lim, max_lim 54 | 55 | def toggle_nullclines(self) -> None: 56 | """ 57 | Toggles nullcline visibility on plot 58 | """ 59 | 60 | if not self.nullclines_init: 61 | self.nullcline_contour_sets = self.plot_nullclines() 62 | self.nullclines_init = True 63 | else: 64 | for contour in self.nullcline_contour_sets: 65 | # The QuadContourSet object usually has a collections (list) attribute 66 | # with a single LineCollection object in it 67 | nc = contour.collections[0] 68 | nc.set_visible(not nc.get_visible()) 69 | self.nullclines_init = False 70 | 71 | self.draw() 72 | 73 | def toggle_fixed_points(self): 74 | if not self.fixed_points_init: 75 | self.fixed_point_markers = self.ax.plot( 76 | *zip(*self.system.fixed_points), "ro", markersize=5 77 | ) 78 | self.fixed_points_init = True 79 | else: 80 | for fp in self.fixed_point_markers: 81 | fp.set_visible(not fp.get_visible()) 82 | self.fixed_points_init = False 83 | 84 | self.draw() 85 | 86 | def reduce_array_density( 87 | self, full_array: np.ndarray, axes_points: int 88 | ) -> np.ndarray: 89 | """ 90 | Accepts a square, 2D Numpy array (array) and an integer variable (axes_points). 91 | Returns a less dense, 2D, square Numpy array with a size of (at least) axes_points squared. 92 | """ 93 | if len(full_array.shape) == 2 and full_array.shape[0] == full_array.shape[1]: 94 | step = int(full_array.shape[0] / axes_points) 95 | return np.array(full_array[::step, ::step], dtype=float) 96 | 97 | def onclick(self, event: matplotlib.backend_bases.MouseEvent) -> None: 98 | """ 99 | Function called upon mouse click event 100 | """ 101 | if not event.inaxes == self.ax: 102 | return 103 | 104 | if event.dblclick and self.trajectory_count < self.max_trajectories: 105 | self.add_trajectory(event) 106 | self.plot_trajectories() 107 | else: 108 | self.regen_quiver(event) 109 | 110 | def regen_quiver(self, event=None, force=False) -> None: 111 | new_lims = np.asarray((tuple(self.ax.get_xlim()), tuple(self.ax.get_ylim()))) 112 | 113 | if not np.all(self.axes_limits == new_lims) or force: 114 | self.axes_limits = new_lims 115 | self.clear_plane() 116 | self.draw_quiver() 117 | self.plot_trajectories() 118 | self.toggle_nullclines() 119 | self.toggle_nullclines() 120 | 121 | self.toggle_fixed_points() 122 | self.toggle_fixed_points() 123 | 124 | def clear_plane(self) -> None: 125 | self.ax.cla() 126 | for traj in list(self.trajectories.keys()): 127 | self.trajectories[traj]["plotted"] = False 128 | 129 | def handle_home(self) -> None: 130 | self.ax.set_xlim(self.original_axes_limits[0]) 131 | self.ax.set_ylim(self.original_axes_limits[1]) 132 | 133 | self.regen_quiver() 134 | 135 | def toggle_annotation(self) -> None: 136 | self.annotate_plots = not(self.annotate_plots) 137 | self.regen_quiver(force=True) 138 | 139 | class PhaseSpace1D(PhaseSpaceParent): 140 | def __init__( 141 | self, 142 | system: SystemOfEquations, 143 | fw_time_lim: float = 5.0, 144 | bw_time_lim: float = -5.0, 145 | axes_limits: tuple = ((-5, 5), (-5, 5)), 146 | max_trajectories: int = 10, 147 | quiver_expansion_factor: float = 0.2, 148 | axes_points: int = 20, 149 | mesh_density: int = 200, 150 | *args, 151 | **kwargs, 152 | ) -> None: 153 | 154 | super().__init__(1, fw_time_lim, bw_time_lim) 155 | 156 | self.annotate_plots = False 157 | self.cid = self.fig.canvas.mpl_connect("button_press_event", self.onclick) 158 | self.release_cid = self.fig.canvas.mpl_connect( 159 | "button_release_event", self.regen_quiver 160 | ) 161 | 162 | self.original_axes_limits = axes_limits 163 | 164 | self.init_space( 165 | system, 166 | fw_time_lim, 167 | bw_time_lim, 168 | axes_limits, 169 | max_trajectories, 170 | quiver_expansion_factor, 171 | axes_points, 172 | mesh_density, 173 | ) 174 | 175 | def init_space( 176 | self, 177 | system: SystemOfEquations, 178 | fw_time_lim: float = 5, 179 | bw_time_lim: float = -5, 180 | axes_limits: tuple = ((-5, 5), (-5, 5)), 181 | max_trajectories: int = 10, 182 | quiver_expansion_factor: float = 0.2, 183 | axes_points: int = 20, 184 | mesh_density: int = 200, 185 | ) -> None: 186 | 187 | self.ax.cla() 188 | self.fig.tight_layout() 189 | self.system = system 190 | 191 | self.time_f = fw_time_lim 192 | self.time_r = bw_time_lim 193 | 194 | self.quiver_expansion_factor = quiver_expansion_factor 195 | 196 | # Two-dimensional array in the form [[x1min, x1max], [x2min, x2max], ...] etc 197 | if isinstance(axes_limits[0], Iterable): 198 | self.axes_limits = np.array(axes_limits) 199 | else: 200 | self.axes_limits = np.array( 201 | (float(bw_time_lim), float(fw_time_lim)), 202 | (axes_limits[0], axes_limits[1]), 203 | ) 204 | 205 | # axes_points = number of points along each axis if quiver_expansion_factor = 0 206 | # self.axes_points = axes_points * (1 + self.quiver_expansion_factor) ==> expands vector field beyond FOV 207 | # whilst preserving as much as possible the spacing between individual vectors. 208 | # Another possible approach would be to explicitly define the spacing between vectors, but this method 209 | # could cause performance issues if large axis limits are required and the vector spacing is not adjusted 210 | # accordingly. 211 | self.axes_points = int(axes_points * (1 + self.quiver_expansion_factor)) 212 | 213 | # TODO: explain 214 | self.mesh_density = mesh_density 215 | 216 | self.max_trajectories = max_trajectories 217 | self.trajectory_count = 0 218 | self.trajectories = {} 219 | 220 | self.nullclines_init = False 221 | self.nullcline_contour_sets = None 222 | self.fixed_points_init = False 223 | self.fixed_point_markers = None 224 | 225 | display_vars = self.system.system_coords 226 | 227 | for var in display_vars: 228 | if not (var in self.system.system_coords): 229 | return 230 | 231 | self.display_vars = display_vars 232 | self.draw_quiver() 233 | 234 | def derivative_expression_resolve(self, display_vars: list, dimensions: int, 235 | positions: list) -> np.ndarray: 236 | eval_seq = [self.system.system_coords[0]] 237 | return np.array(eval_seq) 238 | 239 | def generate_meshes(self) -> (np.ndarray, np.ndarray): 240 | tmin, tmax = self.get_calc_limits(self.axes_limits[0]) 241 | xmin, xmax = self.get_calc_limits(self.axes_limits[1]) 242 | 243 | R = np.meshgrid( 244 | np.linspace(tmin, tmax, self.mesh_density), 245 | np.linspace(xmin, xmax, self.mesh_density), 246 | ) 247 | 248 | dependent_primes = self.system.phasespace_eval(t=None, r=np.array([R[1]]))[ 249 | 0 250 | ] 251 | Rprime = [np.ones(R[0].shape), dependent_primes] 252 | return R, Rprime 253 | 254 | def plot_nullclines(self) -> list: 255 | """ 256 | Plots the nullclines for the current 2-D system. 257 | """ 258 | X, *_ = self.quiver_data["t"] 259 | Y, V, *_ = self.quiver_data[self.system.system_coords[0]] 260 | contours_y = self.ax.contour(X, Y, V, levels=[0], colors="yellow") 261 | return [contours_y] 262 | 263 | def draw_quiver(self) -> None: 264 | R, Rprime = self.generate_meshes() 265 | quiver_data = {} 266 | 267 | quiver_data["t"] = ( 268 | R[0], 269 | Rprime[0], 270 | self.axes_limits[0][0], 271 | self.axes_limits[0][1], 272 | ) 273 | quiver_data[self.system.system_coords[0]] = ( 274 | R[1], 275 | Rprime[1], 276 | self.axes_limits[1][0], 277 | self.axes_limits[1][1], 278 | ) 279 | 280 | self.quiver_data = quiver_data 281 | 282 | # Display vars are the system variables to be plotted. 283 | # Given a system with coords [x, y], display_vars can take 4 forms: 284 | # 1. ["x"], 2. ["y"], 3. ["x", "y"], 4. ["y", "x"] 285 | # In the one-dimensional cases, the quiverplot will be t vs x, or t vs y. 286 | # In the two-dimensional cases, the variables plotted on a given axis depend on the order of display_vars. 287 | # If display_vars = ["y", "x"] the y variable is plotted on the x-axis, and x on the y-axis. Trippy, I know. 288 | 289 | X, U, xmin, xmax = self.quiver_data["t"] 290 | Y, V, ymin, ymax = self.quiver_data[self.display_vars[0]] 291 | 292 | self.ax.set_xlim(xmin, xmax) 293 | self.ax.set_ylim(ymin, ymax) 294 | 295 | U, V = log_transform(U, V) 296 | self.quiver = self.ax.quiver( 297 | self.reduce_array_density(X, self.axes_points), 298 | self.reduce_array_density(Y, self.axes_points), 299 | self.reduce_array_density(U, self.axes_points), 300 | self.reduce_array_density(V, self.axes_points), 301 | pivot="middle", 302 | angles="xy", 303 | ) 304 | 305 | self.trajectory = self.ax.plot(0, 0) # Need an initial 'trajectory' 306 | 307 | self.draw() 308 | 309 | def add_trajectory(self, event: matplotlib.backend_bases.MouseEvent) -> None: 310 | 311 | x_event = event.xdata 312 | y_event = event.ydata 313 | 314 | # Recall that in a 1D scenario, the x_event variable is essentially the inital time of the trajectory 315 | solution_f = self.system.solve((x_event, self.time_f), r0=[y_event]) 316 | solution_r = self.system.solve((x_event, self.time_r), r0=[y_event]) 317 | 318 | self.trajectory_count += 1 319 | 320 | traj_dict = {} 321 | traj_dict["x_event"] = x_event 322 | traj_dict["y_event"] = y_event 323 | traj_dict["sol_f"] = solution_f 324 | traj_dict["sol_r"] = solution_r 325 | traj_dict["plotted"] = False 326 | 327 | self.trajectories[self.trajectory_count] = traj_dict 328 | 329 | def plot_trajectories(self) -> None: 330 | 331 | for traj in list(self.trajectories.keys()): 332 | traj_dict = self.trajectories[traj] 333 | 334 | if traj_dict["plotted"]: 335 | continue 336 | 337 | x_event = traj_dict["x_event"] 338 | y_event = traj_dict["y_event"] 339 | solution_f = traj_dict["sol_f"] 340 | solution_r = traj_dict["sol_r"] 341 | 342 | self.ax.plot(x_event, y_event, ls="", marker="x", c="#FF0000") 343 | 344 | for sol, t in zip((solution_f, solution_r), (self.time_f, self.time_r)): 345 | if sol.success: 346 | y = sol.y[0, :] 347 | if x_event != t: 348 | x = np.linspace(x_event, t, y.size) 349 | elif x_event == t: 350 | x = x_event 351 | self.trajectory = self.ax.plot(x, y, c="#0066FF") 352 | self.fig.canvas.draw() 353 | else: 354 | print(sol.message) 355 | 356 | 357 | class PhaseSpace2D(PhaseSpaceParent): 358 | def __init__( 359 | self, 360 | system: SystemOfEquations, 361 | fw_time_lim: float = 5.0, 362 | bw_time_lim: float = -5.0, 363 | axes_limits: tuple = ((-5, 5), (-5, 5)), 364 | max_trajectories: int = 10, 365 | quiver_expansion_factor: float = 0.2, 366 | axes_points: int = 20, 367 | mesh_density: int = 200, 368 | *args, 369 | **kwargs, 370 | ) -> None: 371 | 372 | super().__init__(2) 373 | 374 | self.annotate_plots = False 375 | self.cid = self.fig.canvas.mpl_connect("button_press_event", self.onclick) 376 | self.release_cid = self.fig.canvas.mpl_connect( 377 | "button_release_event", self.regen_quiver 378 | ) 379 | self.original_axes_limits = axes_limits 380 | 381 | self.init_space( 382 | system, 383 | fw_time_lim, 384 | bw_time_lim, 385 | axes_limits, 386 | max_trajectories, 387 | quiver_expansion_factor, 388 | axes_points, 389 | mesh_density, 390 | ) 391 | 392 | def init_space( 393 | self, 394 | system: SystemOfEquations, 395 | fw_time_lim: float = 5.0, 396 | bw_time_lim: float = -5.0, 397 | axes_limits: tuple = ((-5, 5), (-5, 5)), 398 | max_trajectories: int = 10, 399 | quiver_expansion_factor: float = 0.2, 400 | axes_points: int = 20, 401 | mesh_density: int = 200, 402 | ) -> None: 403 | 404 | self.ax.cla() 405 | self.fig.tight_layout() 406 | self.system = system 407 | 408 | self.time_f = fw_time_lim 409 | self.time_r = bw_time_lim 410 | 411 | self.quiver_expansion_factor = quiver_expansion_factor 412 | 413 | # Two-dimensional array in the form [[x1min, x1max], [x2min, x2max], ...] etc 414 | self.axes_limits = np.array(axes_limits) 415 | 416 | # axes_points = number of points along each axis if quiver_expansion_factor = 0 417 | # self.axes_points = axes_points * (1 + self.quiver_expansion_factor) ==> expands vector field beyond FOV 418 | # whilst preserving as much as possible the spacing between individual vectors. 419 | # Another possible approach would be to explicitly define the spacing between vectors, but this method 420 | # could cause performance issues if large axis limits are required and the vector spacing is not adjusted 421 | # accordingly. 422 | self.axes_points = int(axes_points * (1 + self.quiver_expansion_factor)) 423 | 424 | # TODO: explain 425 | self.mesh_density = mesh_density 426 | 427 | self.max_trajectories = ( 428 | max_trajectories 429 | ) 430 | self.trajectory_count = 0 431 | self.trajectories = {} 432 | 433 | self.nullclines_init = False 434 | self.nullcline_contour_sets = None 435 | self.fixed_points_init = False 436 | self.fixed_point_markers = None 437 | 438 | self.display_vars = self.system.system_coords 439 | for var in self.display_vars: 440 | if not (var in self.system.system_coords): 441 | return 442 | 443 | self.draw_quiver() 444 | 445 | def derivative_expression_resolve( 446 | self, display_vars: list, dimensions: int, positions: list 447 | ) -> np.ndarray: 448 | """ 449 | Function to resolve the coordinates of an argument to the order of 450 | coordinates in an equations.SystemOfEquations object 451 | """ 452 | eval_seq = [] 453 | for var in self.system.system_coords: 454 | if not (var in display_vars): 455 | eval_seq.append(0) 456 | 457 | elif var in display_vars: 458 | eval_seq.append(positions[display_vars.index(var)]) 459 | return np.array(eval_seq) 460 | 461 | def generate_meshes(self) -> (np.ndarray, np.ndarray): 462 | xmin, xmax = self.get_calc_limits(self.axes_limits[0]) 463 | ymin, ymax = self.get_calc_limits(self.axes_limits[1]) 464 | 465 | R = np.meshgrid( 466 | np.linspace(xmin, xmax, self.mesh_density), 467 | np.linspace(ymin, ymax, self.mesh_density), 468 | ) 469 | Rprime = self.system.phasespace_eval(t=None, r=R) 470 | return R, Rprime 471 | 472 | def plot_nullclines(self) -> list: 473 | """ 474 | Plots the nullclines for the current 2-D system. 475 | """ 476 | X, U, *_ = self.quiver_data[self.system.system_coords[0]] 477 | Y, V, *_ = self.quiver_data[self.system.system_coords[1]] 478 | contours_x = self.ax.contour(X, Y, U, levels=[0], colors="red") 479 | contours_y = self.ax.contour(X, Y, V, levels=[0], colors="yellow") 480 | return [contours_x, contours_y] 481 | 482 | def draw_quiver(self) -> None: 483 | R, Rprime = self.generate_meshes() 484 | quiver_data = {} 485 | 486 | for label, mesh, prime_mesh, axlims in zip( 487 | self.system.system_coords, R, Rprime, self.axes_limits 488 | ): 489 | axmin, axmax = tuple(axlims) 490 | quiver_data[label] = (mesh, prime_mesh, axmin, axmax) 491 | 492 | self.quiver_data = quiver_data 493 | 494 | # Display vars are the system variables to be plotted. 495 | # Given a system with coords [x, y], display_vars can take 4 forms: 496 | # 1. ["x"], 2. ["y"], 3. ["x", "y"], 4. ["y", "x"] 497 | # In the one-dimensional cases, the quiverplot will be t vs x, or t vs y. 498 | # In the two-dimensional cases, the variables plotted on a given axis depend on the order of display_vars. 499 | # If display_vars = ["y", "x"] the y variable is plotted on the x-axis, and x on the y-axis. Trippy, I know. 500 | 501 | X, U, xmin, xmax = self.quiver_data[self.display_vars[0]] 502 | Y, V, ymin, ymax = self.quiver_data[self.display_vars[1]] 503 | 504 | self.ax.set_xlim(xmin, xmax) 505 | self.ax.set_ylim(ymin, ymax) 506 | 507 | U, V = log_transform(U, V) 508 | 509 | self.quiver = self.ax.quiver( 510 | self.reduce_array_density(X, self.axes_points), 511 | self.reduce_array_density(Y, self.axes_points), 512 | self.reduce_array_density(U, self.axes_points), 513 | self.reduce_array_density(V, self.axes_points), 514 | pivot="middle", 515 | angles="xy", 516 | ) 517 | 518 | self.trajectory = self.ax.plot(0, 0) # Need an initial 'trajectory' 519 | 520 | self.draw() 521 | 522 | def plot_trajectories(self) -> None: 523 | 524 | for traj in list(self.trajectories.keys()): 525 | traj_dict = self.trajectories[traj] 526 | 527 | if traj_dict["plotted"]: 528 | continue 529 | 530 | x_event = traj_dict["x_event"] 531 | y_event = traj_dict["y_event"] 532 | solution_f = traj_dict["sol_f"] 533 | solution_r = traj_dict["sol_r"] 534 | 535 | self.ax.plot(x_event, y_event, ls="", marker="x", c="#FF0000") 536 | 537 | if self.annotate_plots: 538 | self.ax.annotate("Curve " + str(traj), (x_event, y_event)) 539 | 540 | for sol in (solution_f, solution_r): 541 | if sol.success: 542 | # sol.y has shape (2, n_points) for a 2-D system 543 | x = sol.y[self.system.system_coords.index(self.display_vars[0]), :] 544 | y = sol.y[self.system.system_coords.index(self.display_vars[1]), :] 545 | self.trajectory = self.ax.plot(x, y, c="#0066FF") 546 | self.fig.canvas.draw() 547 | else: 548 | print(sol.message) 549 | 550 | self.draw() 551 | 552 | def add_trajectory(self, event: matplotlib.backend_bases.MouseEvent) -> None: 553 | 554 | x_event = event.xdata 555 | y_event = event.ydata 556 | 557 | # Trajectory production and plotting 558 | # eval_point is the point on the quiverplot that has been clicked by the user. However, the coordinates are made 559 | # consistent with the ordering of the system coordinates. For example, on a graph with y vs x, the x_event variable 560 | # will correspond to a value on x-axis, which represents the y variable of the system. Similarly with the y_event variable 561 | # representing the x variable of the system. In this case, eval_point = (y_event, x_event) such that the coordinates 562 | # are in the order (x, y) for the SOE to solve and evaluate. 563 | eval_point = self.derivative_expression_resolve( 564 | self.display_vars, self.dimensions, (x_event, y_event) 565 | ) 566 | solution_f = self.system.solve((0, self.time_f), r0=eval_point) 567 | solution_r = self.system.solve((0, self.time_r), r0=eval_point) 568 | 569 | self.trajectory_count += 1 570 | 571 | traj_dict = {} 572 | traj_dict["x_event"] = x_event 573 | traj_dict["y_event"] = y_event 574 | traj_dict["sol_f"] = solution_f 575 | traj_dict["sol_r"] = solution_r 576 | traj_dict["time_lims"] = (self.time_r, self.time_f) 577 | traj_dict["plotted"] = False 578 | 579 | self.trajectories[self.trajectory_count] = traj_dict 580 | 581 | 582 | def log_transform(u: np.ndarray, v: np.ndarray) -> np.ndarray: 583 | arrow_lengths = np.sqrt(u * u + v * v) 584 | len_adjust_factor = np.log10(arrow_lengths + 1) / arrow_lengths 585 | return u * len_adjust_factor, v * len_adjust_factor 586 | -------------------------------------------------------------------------------- /PyPLANE/ui_main_window.py: -------------------------------------------------------------------------------- 1 | """ 2 | Draws the main window of the PyPLANE Qt5 interface 3 | """ 4 | 5 | import sys 6 | import os 7 | import functools 8 | 9 | from PyQt5.QtWidgets import ( 10 | QApplication, 11 | QMainWindow, 12 | QWidget, 13 | QLabel, 14 | QPushButton, 15 | QVBoxLayout, 16 | QHBoxLayout, 17 | QAction, 18 | QWidgetAction, 19 | QComboBox, 20 | QMenu, 21 | QMessageBox, 22 | QListWidget, 23 | QListWidgetItem, 24 | QAbstractItemView, 25 | QScrollBar, 26 | QCheckBox, 27 | QRadioButton, 28 | ) 29 | import numpy as np 30 | import matplotlib.pyplot as plt 31 | from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 32 | from mpl_toolkits.mplot3d import Axes3D 33 | 34 | from PyPLANE.core_info import VERSION 35 | from PyPLANE.equations import DifferentialEquation, SystemOfEquations 36 | from PyPLANE.trajectory import PhaseSpace1D, PhaseSpace2D 37 | from PyPLANE.gallery import Gallery 38 | from PyPLANE.defaults import psp_by_dimensions 39 | from PyPLANE.analysis import TCAWindow 40 | from PyPLANE.ui_layouts import ( 41 | EquationEntryLayout, 42 | ParameterEntryLayout, 43 | AxisLimitEntryLayout, 44 | ) 45 | 46 | 47 | class MainWindow(QMainWindow): 48 | """ 49 | The application's main window. 50 | Contains sections for inputting a system of equations, 51 | a matplotlib canvas where the phase space is plotted, 52 | as well as a menu bar for access to common options. 53 | """ 54 | 55 | def __init__(self) -> None: 56 | super().__init__() 57 | 58 | # Working directory changed so that resources can be loaded 59 | main_window_file_path = os.path.abspath(__file__) 60 | main_window_file_dir = os.path.dirname(main_window_file_path) 61 | os.chdir(main_window_file_dir) 62 | self.working_dir = main_window_file_dir 63 | print("New working directory: {}".format(self.working_dir)) 64 | 65 | self.load_gallery("resources/gallery_2D.json", "gallery_2D", 2) 66 | self.load_gallery("resources/gallery_1D.json", "gallery_1D", 1) 67 | self.show_2D() 68 | self.draw_window() 69 | 70 | def load_gallery(self, filename: str, gallery_name: str, num_dims: int) -> None: 71 | setattr(self, gallery_name, Gallery(filename, num_dims)) 72 | 73 | def draw_window(self, app_name="PyPLANE", app_version=VERSION) -> None: 74 | self.setWindowTitle(app_name + " " + app_version) 75 | self.show() 76 | 77 | def basic_popup( 78 | self, 79 | icon=QMessageBox.Information, 80 | button=QMessageBox.Ok, 81 | text="Pop-Up" 82 | ): 83 | """ 84 | Basic pop-up window facility. Displays pop-up which grabs screen's attention. 85 | 86 | icon -> Icon displayed in top-left corner. Can take the following values: 87 | - QMessageBox.Critical 88 | - QMessageBox.Warning 89 | - QMessageBox.Information 90 | - QMessageBox.Question 91 | 92 | button -> Button displayed on bottom of pop-up. Can take the following values: 93 | - QMessageBox.Ok 94 | - QMessageBox.Open 95 | - QMessageBox.Save 96 | - QMessageBox.Cancel 97 | - QMessageBox.Close 98 | - QMessageBox.Yes 99 | - QMessageBox.No 100 | - QMessageBox.Abort 101 | - QMessageBox.Retry 102 | - QMessageBox.Ignore 103 | 104 | text -> Main message of pop-up 105 | """ 106 | 107 | msg = QMessageBox() 108 | msg.setWindowTitle("PyPLANE") 109 | msg.setText(text) 110 | 111 | # If a non-permitted icon value passed -> default to info 112 | try: 113 | msg.setIcon(icon) 114 | except: 115 | msg.setIcon(QMessageBox.Information) 116 | 117 | # If a non-permitted button value passed -> default to OK 118 | try: 119 | msg.setStandardButtons(button) 120 | except: 121 | msg.setStandardButtons(QMessageBox.Ok) 122 | 123 | # Show pop-up 124 | msg.exec_() 125 | 126 | def draw_menubar(self) -> None: 127 | """ 128 | Draws the menu bar that appears at the top of the window. If method is recalled, existing menu bar 129 | is cleared and redrawn. 130 | TODO: File > New Window 131 | """ 132 | 133 | menu_bar = self.menuBar() 134 | menu_bar.clear() # If menu_bar already exists, clears and redraws. 135 | 136 | # Add menus to the bar 137 | self.menu_file = menu_bar.addMenu("File") 138 | self.menu_edit = menu_bar.addMenu("Edit") 139 | self.menu_dims = menu_bar.addMenu("Dimensions") 140 | self.menu_analysis = menu_bar.addMenu("Analysis") 141 | self.menu_gallery = menu_bar.addMenu("Gallery") 142 | 143 | # File > Quit 144 | self.action_quit = QAction("Quit", self) 145 | self.menu_file.addAction(self.action_quit) 146 | self.action_quit.triggered.connect(self.close) 147 | 148 | # Edit > Show Nullclines 149 | self.action_nullclines = QAction("Show Nullclines", self, checkable=True) 150 | self.menu_edit.addAction(self.action_nullclines) 151 | self.action_nullclines.changed.connect(self.phase_plot.toggle_nullclines) 152 | 153 | # Edit > Show Fixed Points 154 | self.action_fixed_points = QAction("Show Fixed Points", self, checkable=True) 155 | self.menu_edit.addAction(self.action_fixed_points) 156 | self.action_fixed_points.changed.connect(self.phase_plot.toggle_fixed_points) 157 | 158 | # Dimensions > 1D 159 | self.action_1D = QAction("One-Dimensional PyPLANE", self) 160 | self.menu_dims.addAction(self.action_1D) 161 | self.action_1D.triggered.connect(self.show_1D) 162 | 163 | # Dimensions > 2D 164 | self.action_2D = QAction("Two-Dimensional PyPLANE", self) 165 | self.menu_dims.addAction(self.action_2D) 166 | self.action_2D.triggered.connect(self.show_2D) 167 | 168 | # Analysis 169 | self.action_tca = QAction("Trajectory Component Analysis", self) 170 | self.menu_analysis.addAction(self.action_tca) 171 | self.action_tca.triggered.connect(self.tca_init) 172 | 173 | # Gallery 174 | self.create_gallery_menu("gallery_1D", "One-Dimensional", 1) 175 | self.create_gallery_menu("gallery_2D", "Two-Dimensional", 2) 176 | 177 | def create_gallery_menu( 178 | self, gallery_name: str, submenu_name: str, num_dims: int 179 | ) -> None: 180 | gallery_menu = self.menu_gallery.addMenu(submenu_name) 181 | gallery_actions = [] 182 | gallery = getattr(self, gallery_name) 183 | 184 | for system in gallery: 185 | gall_item_action = QAction(system["system_name"], self) 186 | plot_sys_func = functools.partial(self.plot_gallery_item, system, num_dims) 187 | gall_item_action.triggered.connect(plot_sys_func) 188 | gallery_menu.addAction(gall_item_action) 189 | gallery_actions.append(gall_item_action) 190 | 191 | setattr(self, "menu_" + gallery_name, gallery_menu) 192 | setattr(self, "actions_" + gallery_name, gallery_actions) 193 | 194 | def tca_init(self) -> None: 195 | 196 | if self.phase_plot.system.dims == 1: 197 | self.handle_tca_dim_error() 198 | return 199 | 200 | self.phase_plot.toggle_annotation() 201 | 202 | #if self.tca_window is None: 203 | self.tca_window = TCAWindow(self.phase_plot.trajectories) 204 | self.tca_window.show() 205 | 206 | #self.phase_plot.toggle_annotation() 207 | 208 | def handle_tca_dim_error(self) -> None: 209 | self.basic_popup( 210 | icon=QMessageBox.Warning, 211 | button=QMessageBox.Ok, 212 | text="Trajectory component analysis only available for 2D systems" 213 | ) 214 | 215 | def handle_tca_null_error(self) -> None: 216 | self.basic_popup( 217 | icon=QMessageBox.Warning, 218 | button=QMessageBox.Ok, 219 | text="Trajectories must be plotted before TCA can occur" 220 | ) 221 | 222 | def handle_empty_entry(self, phase_coords: list, passed_params: dict) -> None: 223 | self.basic_popup( 224 | icon=QMessageBox.Warning, 225 | button=QMessageBox.Ok, 226 | text="Blank detected" 227 | ) 228 | 229 | def handle_invalid_eqns(self) -> None: 230 | 231 | warning = """ 232 | Equation string should not contain the following symbols: 233 | I, E, S, N, C, O, or Q 234 | """ 235 | 236 | self.basic_popup( 237 | icon=QMessageBox.Warning, 238 | button=QMessageBox.Ok, 239 | text=warning 240 | ) 241 | 242 | def required_fields_full(self, phase_coords: list, passed_params: dict) -> bool: 243 | """ 244 | Checks if all of the required entry boxes on the GUI are full and are compatible, where applicable. 245 | Returns True if all full. 246 | Returns False if any are empty 247 | """ 248 | if self.equations_undefined(): 249 | return False 250 | 251 | for var, eqn in zip(phase_coords, self.eqn_entries): 252 | if self.params_undefined(var, phase_coords, eqn, passed_params): 253 | return False 254 | 255 | return not self.lims_undefined() 256 | 257 | def equations_undefined(self) -> bool: 258 | """ 259 | Checks if either ODE expression entry boxes are entry. Returns True if either 260 | are empty. Returns False if both are not empty 261 | """ 262 | for string_eqn in self.eqn_entries: 263 | if string_eqn == "": 264 | return True 265 | 266 | return False 267 | 268 | def params_undefined( 269 | self, dep_var: str, phase_coords: list, ode_str: str, passed_params: dict 270 | ) -> bool: 271 | """ 272 | Checks for undefined parameters in ODE expressions. 273 | Returns True if undefined parameters found. 274 | Returns False otherwise 275 | """ 276 | for val in passed_params.values(): 277 | try: 278 | float(val) 279 | except ValueError: 280 | return True 281 | 282 | ode = DifferentialEquation(dep_var, phase_coords, ode_str) 283 | 284 | # Currently unused, except to determine that there are undefined params. 285 | # Could be used later to highlight offending ode expression? 286 | undefined_params = [ 287 | str(sym) for sym in ode.params if str(sym) not in passed_params.keys() 288 | ] 289 | 290 | return len(undefined_params) != 0 291 | 292 | def lims_undefined(self) -> bool: 293 | """ 294 | Checks for undefined axes limits. Returns True if any of the axes limits 295 | entry boxes are empty or contain non-numerical characters. 296 | Returns False if all contain text that can be converted to floats. 297 | """ 298 | for lim in self.lim_entries: 299 | if lim == "": 300 | return True 301 | try: 302 | float(lim) 303 | except ValueError: 304 | return True 305 | return False 306 | 307 | def show_1D(self) -> None: 308 | self.active_dims = 1 309 | self.init_ui() 310 | 311 | def show_2D(self) -> None: 312 | self.active_dims = 2 313 | self.init_ui() 314 | 315 | def show_ND(self, num_dims: int) -> None: 316 | show_ND_funcs = {1: self.show_1D, 2: self.show_2D} 317 | try: 318 | if self.active_dims != num_dims: 319 | show_ND_funcs[num_dims]() 320 | except KeyError: 321 | raise ValueError("Trying to set to an unsupported number of dimensions") 322 | 323 | def init_equation_layouts(self) -> None: 324 | """ 325 | Draw the labels and widgets to allow inputing 326 | of equations (Including the plot button) 327 | """ 328 | self.equation_entry_layout = QVBoxLayout() 329 | 330 | var1_name = self.phase_plot.system.system_coords[0] 331 | var1_equation = self.phase_plot.system.ode_expr_strings[0] 332 | self.var1_equation_layout = EquationEntryLayout(var1_name, var1_equation) 333 | self.equation_entry_layout.addLayout(self.var1_equation_layout) 334 | 335 | if self.active_dims == 2: 336 | var2_name = self.phase_plot.system.system_coords[1] 337 | var2_equation = self.phase_plot.system.ode_expr_strings[1] 338 | self.var2_equation_layout = EquationEntryLayout(var2_name, var2_equation) 339 | self.equation_entry_layout.addLayout(self.var2_equation_layout) 340 | 341 | def init_plot_button_layout(self) -> None: 342 | self.plot_button = QPushButton("Plot") 343 | self.plot_button.clicked.connect(self.plot_button_clicked) 344 | self.button_layout = QHBoxLayout() 345 | self.button_layout.addStretch() 346 | self.button_layout.addWidget(self.plot_button) 347 | self.button_layout.addStretch() 348 | 349 | def init_limit_layouts(self) -> None: 350 | """ 351 | Entry boxes for the max and min values to be plotted 352 | on the x and y axes of the phase plot 353 | """ 354 | self.lim_layout = QVBoxLayout() 355 | self.lim_layout.addWidget(QLabel("Limits of Axes:")) 356 | 357 | var1_name = self.phase_plot.system.system_coords[0] 358 | var1_max_val = self.phase_plot.axes_limits[0][1] 359 | var1_min_val = self.phase_plot.axes_limits[0][0] 360 | self.var1_lim_layout = AxisLimitEntryLayout(var1_name, var1_min_val, 361 | var1_max_val) 362 | self.lim_layout.addLayout(self.var1_lim_layout) 363 | 364 | if self.active_dims == 2: 365 | var2_name = self.phase_plot.system.system_coords[1] 366 | var2_max_val = self.phase_plot.axes_limits[1][1] 367 | var2_min_val = self.phase_plot.axes_limits[1][0] 368 | self.var2_lim_layout = AxisLimitEntryLayout(var2_name, var2_min_val, 369 | var2_max_val) 370 | self.lim_layout.addLayout(self.var2_lim_layout) 371 | 372 | def init_param_layouts(self) -> None: 373 | """ 374 | Entry boxes for the names and values of the SOE parameters. 375 | """ 376 | soe_params = self.setup_dict["params"] 377 | min_num_param_inputs = 5 378 | num_params = len(soe_params) 379 | self.num_param_inputs = max(min_num_param_inputs, num_params) 380 | 381 | self.parameters_layout = QVBoxLayout() 382 | self.parameters_layout.addWidget(QLabel("Parameters (Optional) :")) 383 | for name, val in soe_params.items(): 384 | self.parameters_layout.addLayout(ParameterEntryLayout(name, val)) 385 | 386 | num_empty_param_inputs = max(0, min_num_param_inputs - num_params) 387 | for i in range(num_empty_param_inputs): 388 | self.parameters_layout.addLayout(ParameterEntryLayout()) 389 | 390 | def combine_input_layouts(self) -> None: 391 | self.inputs_layout = QVBoxLayout() # All input boxes 392 | self.inputs_layout.addLayout(self.equation_entry_layout) 393 | self.inputs_layout.addLayout(self.button_layout) 394 | self.inputs_layout.addLayout(self.lim_layout) 395 | self.inputs_layout.addLayout(self.parameters_layout) 396 | self.inputs_layout.addStretch() 397 | 398 | def init_ui(self) -> None: 399 | """ 400 | Puts together various compnents of the UI 401 | """ 402 | # This will hold all UI elements apart from the menu bar 403 | self.cent_widget = QWidget(self) 404 | self.setCentralWidget(self.cent_widget) 405 | self.psp_canvas_default() 406 | self.draw_menubar() 407 | 408 | self.init_equation_layouts() 409 | self.init_plot_button_layout() 410 | self.init_limit_layouts() 411 | self.init_param_layouts() 412 | self.combine_input_layouts() 413 | 414 | plot_layout = QVBoxLayout() 415 | plot_layout.addWidget(NavigationToolbar(self.phase_plot, self)) 416 | 417 | try: 418 | plot_layout.removeWidget(self.phase_plot) 419 | except AttributeError: 420 | pass 421 | 422 | plot_layout.addWidget(self.phase_plot) 423 | 424 | self.overall_layout = QHBoxLayout() 425 | self.overall_layout.addLayout(self.inputs_layout) 426 | self.overall_layout.addLayout(plot_layout) 427 | 428 | self.cent_widget.setLayout(self.overall_layout) 429 | 430 | def psp_canvas_default(self) -> None: 431 | """ 432 | Initialises default PSP 433 | """ 434 | 435 | self.setup_dict = psp_by_dimensions(self.active_dims) 436 | if self.active_dims == 1: 437 | correct_phase_space = PhaseSpace1D 438 | elif self.active_dims == 2: 439 | correct_phase_space = PhaseSpace2D 440 | 441 | # Unpacks self.setup_dict into SOE. 442 | sys = SystemOfEquations(**self.setup_dict) 443 | self.phase_plot = correct_phase_space(sys, **self.setup_dict) 444 | 445 | def equations_valid(self, equations: list) -> bool: 446 | """ 447 | Parses equation inputs and checks for invalid/disallowed symbols. 448 | Returns True if equation contains no offending characters. 449 | 450 | List of disallowed symbols can be found in the SymPy docs: 451 | https://docs.sympy.org/latest/gotchas.html 452 | """ 453 | disallowed_symbols = ("I","E","S","N","C","O","Q") 454 | 455 | for eqn in equations: 456 | for sym in disallowed_symbols: 457 | if eqn.find(sym) != -1: 458 | return False 459 | 460 | return True 461 | 462 | def plot_button_clicked(self) -> None: 463 | """ 464 | Gathers phase_coords and passed_params to feed into GUI checks. 465 | If GUI checks pass, self.update_psp is called. 466 | Else, self.handle_empty_entry is called. 467 | """ 468 | 469 | if self.active_dims == 1: 470 | phase_coords = ["x"] 471 | elif self.active_dims == 2: 472 | phase_coords = ["x", "y"] 473 | 474 | # Grab parameters 475 | passed_params = {} 476 | for param_layout in self.parameters_layout.children(): 477 | param_name = param_layout.param_name_text() 478 | param_val = param_layout.param_val_text() 479 | if param_name: 480 | try: 481 | # For scenario where parameter label is entered but given no value 482 | # Cannot convert empty string to float 483 | param_val = float(param_val) 484 | except ValueError: 485 | pass 486 | # This will then be passed to DE object and rejected gracefully 487 | passed_params[param_name] = param_val 488 | 489 | self.eqn_entries = [self.var1_equation_layout.text()] 490 | self.lim_entries = [ 491 | self.var1_lim_layout.min_val_text(), 492 | self.var1_lim_layout.max_val_text() 493 | ] 494 | 495 | if self.active_dims == 2: 496 | self.eqn_entries.append(self.var2_equation_layout.text()) 497 | self.lim_entries.extend([ 498 | self.var2_lim_layout.min_val_text(), 499 | self.var2_lim_layout.max_val_text() 500 | ]) 501 | 502 | if not self.required_fields_full(phase_coords, passed_params): 503 | self.handle_empty_entry(phase_coords, passed_params) 504 | 505 | elif not self.equations_valid(self.eqn_entries): 506 | self.handle_invalid_eqns() 507 | 508 | else: 509 | self.update_psp(phase_coords, passed_params) 510 | 511 | def solve_method_changed(self) -> None: 512 | self.solve_method = self.solve_method_combo.currentText() 513 | self.phase_plot.system.set_solve_method(self.solve_method) 514 | 515 | def update_psp(self, phase_coords: list, passed_params: dict) -> None: 516 | """ 517 | Gathers entry information from GUI and updates phase plot 518 | """ 519 | f_1 = self.var1_equation_layout.text() 520 | eqns = [f_1] 521 | 522 | if self.active_dims == 2: 523 | f_2 = self.var2_equation_layout.text() 524 | eqns.append(f_2) 525 | 526 | system_of_eqns = SystemOfEquations(phase_coords, eqns, params=passed_params) 527 | 528 | self.action_nullclines.setChecked(False) 529 | lim_floats = [float(lim) for lim in self.lim_entries] 530 | 531 | if self.active_dims == 1: 532 | axes_limits = ((-5, 5), (lim_floats[0], lim_floats[1])) 533 | 534 | elif self.active_dims == 2: 535 | axes_limits = ( 536 | (lim_floats[0], lim_floats[1]), 537 | (lim_floats[2], lim_floats[3]), 538 | ) 539 | 540 | self.phase_plot.init_space( 541 | system_of_eqns, axes_limits=axes_limits, axes_points=20 542 | ) 543 | 544 | def clear_param_inputs(self) -> None: 545 | for param_layout in self.parameters_layout.children(): 546 | param_layout.clear() 547 | 548 | def clear_equation_inputs(self) -> None: 549 | self.var1_equation_layout.clear() 550 | if self.active_dims == 2: 551 | self.var2_equation_layout.clear() 552 | 553 | def clear_limits_inputs(self) -> None: 554 | self.var1_lim_layout.clear() 555 | if self.active_dims == 2: 556 | self.var2_lim_layout.clear() 557 | 558 | def clear_all_inputs(self) -> None: 559 | self.clear_equation_inputs() 560 | self.clear_limits_inputs() 561 | self.clear_param_inputs() 562 | 563 | def plot_gallery_item(self, system: SystemOfEquations, num_dims: int) -> None: 564 | print("Plotting system - {}".format(system)) 565 | 566 | self.show_ND(num_dims) 567 | 568 | self.clear_all_inputs() 569 | 570 | # Equations 571 | system_equations = system["ode_expr_strings"] 572 | var1_equation = system_equations[0] 573 | self.var1_equation_layout.set_text(var1_equation) 574 | if self.active_dims == 2: 575 | var2_equation = system_equations[1] 576 | self.var2_equation_layout.set_text(var2_equation) 577 | 578 | # Limits 579 | axes_limits = system["axes_limits"] 580 | self.var1_lim_layout.set_min_max_text(*axes_limits[0]) 581 | 582 | if self.active_dims == 2: 583 | self.var2_lim_layout.set_min_max_text(*axes_limits[1]) 584 | 585 | # Parameters 586 | sys_name = system["system_name"] 587 | print("Plotting", sys_name) 588 | sys_params = system["params"] 589 | param_names = list(sys_params.keys()) 590 | num_sys_params = len(param_names) 591 | 592 | # This loop assumes that the number of system params is fewer than 593 | # the number of parameter layouts. TODO: fix that. 594 | for param_num in range(num_sys_params): 595 | param_name = str(param_names[param_num]) 596 | param_val = str(sys_params[param_name]) 597 | param_layout = self.parameters_layout.children()[param_num] 598 | param_layout.set_name_val_text(param_name, param_val) 599 | 600 | self.plot_button_clicked() 601 | 602 | 603 | if __name__ == "__main__": 604 | app = QApplication(sys.argv) 605 | app_main_window = MainWindow() 606 | sys.exit(app.exec_()) 607 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------