├── doc ├── requirements.txt ├── examples │ ├── crystal-gel.ipynb │ └── periodic_glass.ipynb ├── api │ ├── modules.rst │ └── boo.rst ├── Makefile ├── index.rst ├── conf.py └── intro.rst ├── MANIFEST.in ├── boo ├── __init__.py ├── test_boo.py └── boo.py ├── README.rst ├── setup.py └── LICENSE /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | nbsphinx 2 | ipykernel 3 | -------------------------------------------------------------------------------- /doc/examples/crystal-gel.ipynb: -------------------------------------------------------------------------------- 1 | ../../boo/examples/crystal-gel.ipynb -------------------------------------------------------------------------------- /doc/examples/periodic_glass.ipynb: -------------------------------------------------------------------------------- 1 | ../../boo/examples/periodic_glass.ipynb -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md LICENSE 2 | recursive-include boo/examples *.ipynb *.xyz *.dat 3 | -------------------------------------------------------------------------------- /doc/api/modules.rst: -------------------------------------------------------------------------------- 1 | boo 2 | === 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | boo 8 | -------------------------------------------------------------------------------- /boo/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | A Python package to compute bond orientational order parameters 6 | as defined by Steinhardt Physical Review B (1983) 7 | doi:10.1103/PhysRevB.28.784. 8 | """ 9 | 10 | __version__ = "1.0.0" 11 | 12 | from .boo import vect2Ylm, single_pos2qlm, bonds2qlm, ngbs2qlm, coarsegrain_qlm 13 | from .boo import product, ql, wl 14 | from .boo import x_bonds, x_ngbs, x_particles, crystallinity, gG_l 15 | -------------------------------------------------------------------------------- /doc/api/boo.rst: -------------------------------------------------------------------------------- 1 | boo package 2 | =========== 3 | 4 | Submodules 5 | ---------- 6 | 7 | boo\.boo module 8 | --------------- 9 | 10 | .. automodule:: boo.boo 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | boo\.test\_boo module 16 | --------------------- 17 | 18 | .. automodule:: boo.test_boo 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: boo 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = Pyboo 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. Pyboo documentation master file, created by 2 | sphinx-quickstart on Fri Nov 24 11:57:13 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Pyboo's documentation! 7 | ================================= 8 | 9 | A Python package to compute bond orientational order parameters as defined by Steinhardt Physical Review B (1983) `doi:10.1103/PhysRevB.28.784 `_. 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | :caption: Contents: 14 | 15 | intro 16 | examples/crystal-gel.ipynb 17 | examples/periodic_glass.ipynb 18 | api/modules.rst 19 | 20 | 21 | 22 | Indices and tables 23 | ================== 24 | 25 | * :ref:`genindex` 26 | * :ref:`modindex` 27 | * :ref:`search` 28 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Pyboo 2 | ===== 3 | 4 | A Python package to compute bond orientational order parameters as 5 | defined by Steinhardt Physical Review B (1983) 6 | doi:10.1103/PhysRevB.28.784. 7 | 8 | Steinhardt's bond orientational order parameter is a popular method 9 | (>20k citations of the original paper) to identify local symmetries in 10 | an assembly of particles in 3D. It can be used in particle-based 11 | simulations (typically molecular dynamics, brownian dynamics, 12 | monte-carlo, etc.) or in particle-tracking experiments (colloids, 13 | granular materials) where the coordinates of all particles are known. 14 | 15 | Licence, citations, contact 16 | --------------------------- 17 | 18 | This code is under GPL 3.0 licence. See LICENCE file. 19 | 20 | Please cite Pyboo and it's author(s) in any scientific publication using 21 | this software. 22 | 23 | :: 24 | 25 | @misc{ 26 | pyboo, 27 | title={Pyboo: A Python package to compute bond orientational order parameters}, 28 | author={Mathieu Leocmach}, 29 | year={2017}, 30 | doi={10.5281/zenodo.1066568}, 31 | url={https://github.com/MathieuLeocmach/pyboo} 32 | } 33 | 34 | Contact Mathieu LEOCMACH, Institut Lumière Matière, UMR-CNRS 5306, Lyon, 35 | France mathieu.leocmach AT univ-lyon1.fr 36 | 37 | Installation 38 | ------------ 39 | 40 | Dependencies are numpy, scipy and numba. Tested with python 2.7 and 41 | python 3.5. 42 | 43 | You can install with pip: pip install pyboo 44 | 45 | Documentation 46 | ------------- 47 | 48 | Documentation is avaiable on Readthedocs: [http://pyboo.readthedocs.io] 49 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """A setuptools based setup module. 2 | 3 | See: 4 | https://packaging.python.org/en/latest/distributing.html 5 | https://github.com/pypa/sampleproject 6 | """ 7 | 8 | # Always prefer setuptools over distutils 9 | from setuptools import setup, find_packages 10 | # To use a consistent encoding 11 | from codecs import open 12 | from os import path 13 | 14 | import boo 15 | 16 | here = path.abspath(path.dirname(__file__)) 17 | 18 | # Get the long description from the README file 19 | with open(path.join(here, 'README.rst'), encoding='utf-8') as f: 20 | long_description = f.read() 21 | 22 | setup( 23 | name='pyboo', 24 | 25 | # Versions should comply with PEP440. For a discussion on single-sourcing 26 | # the version across setup.py and the project code, see 27 | # https://packaging.python.org/en/latest/single_source_version.html 28 | version=boo.__version__, 29 | 30 | description='A Python package to compute bond orientational order parameters', 31 | long_description=long_description, 32 | 33 | # The project's main homepage. 34 | url='https://github.com/MathieuLeocmach/pyboo', 35 | 36 | # Author details 37 | author='Mathieu Leocmach', 38 | author_email='mathieu.leocmach@univ-lyon1 in France', 39 | 40 | # Choose your license 41 | license='GPL', 42 | 43 | # See https://pypi.python.org/pypi?%3Aaction=list_classifiers 44 | classifiers=[ 45 | # How mature is this project? Common values are 46 | # 3 - Alpha 47 | # 4 - Beta 48 | # 5 - Production/Stable 49 | 'Development Status :: 5 - Production/Stable', 50 | 51 | # Indicate who your project is intended for 52 | 'Intended Audience :: Science/Research', 53 | 'Topic :: Scientific/Engineering :: Chemistry', 54 | 'Topic :: Scientific/Engineering :: Physics', 55 | 56 | # Pick your license as you wish (should match "license" above) 57 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 58 | 59 | # Specify the Python versions you support here. In particular, ensure 60 | # that you indicate whether you support Python 2, Python 3 or both. 61 | 'Programming Language :: Python :: 2', 62 | 'Programming Language :: Python :: 2.7', 63 | 'Programming Language :: Python :: 3', 64 | 'Programming Language :: Python :: 3.5', 65 | ], 66 | 67 | # What does your project relate to? 68 | keywords='structure crystallography glass', 69 | 70 | # You can just specify the packages manually here if your project is 71 | # simple. Or you can use find_packages(). 72 | packages=find_packages(),#exclude=['contrib', 'docs', 'tests']), 73 | 74 | # Alternatively, if you want to distribute just a my_module.py, uncomment 75 | # this: 76 | # py_modules=["my_module"], 77 | 78 | # List run-time dependencies here. These will be installed by pip when 79 | # your project is installed. For an analysis of "install_requires" vs pip's 80 | # requirements files see: 81 | # https://packaging.python.org/en/latest/requirements.html 82 | install_requires=['numpy', 'scipy >= 0.18', 'numba'], 83 | 84 | # List additional groups of dependencies here (e.g. development 85 | # dependencies). You can install these using the following syntax, 86 | # for example: 87 | # $ pip install -e .[dev,test] 88 | extras_require={ 89 | 'dev': ['check-manifest'], 90 | 'test': ['pytest'], 91 | 'doc': ['sphinx', 'nbsphinx'], 92 | }, 93 | 94 | # If there are data files included in your packages that need to be 95 | # installed, specify them here. If using Python 2.6 or less, then these 96 | # have to be included in MANIFEST.in as well. 97 | package_data={ 98 | 'sample': [ 99 | 'examples/AR-Res06A_scan2_t890.xyz', 100 | 'examples/crystal-gel.ipynb', 101 | 'examples/3d_6_0.54_0.dat', 102 | 'examples/periodic_glass.ipynb', 103 | ], 104 | }, 105 | 106 | # Although 'package_data' is the preferred approach, in some case you may 107 | # need to place data files outside of your packages. See: 108 | # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa 109 | # In this case, 'data_file' will be installed into '/my_data' 110 | #data_files=[('my_data', ['data/data_file'])], 111 | 112 | # To provide executable scripts, use entry points in preference to the 113 | # "scripts" keyword. Entry points provide cross-platform support and allow 114 | # pip to create the appropriate form of executable for the target platform. 115 | #entry_points={ 116 | # 'console_scripts': [ 117 | # 'sample=sample:main', 118 | # ], 119 | #}, 120 | ) 121 | 122 | -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Pyboo documentation build configuration file, created by 5 | # sphinx-quickstart on Fri Nov 24 11:57:13 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | # import os 21 | # import sys 22 | # sys.path.insert(0, os.path.abspath('.')) 23 | 24 | 25 | # -- General configuration ------------------------------------------------ 26 | 27 | # If your documentation needs a minimal Sphinx version, state it here. 28 | # 29 | # needs_sphinx = '1.0' 30 | 31 | # Add any Sphinx extension module names here, as strings. They can be 32 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 33 | # ones. 34 | extensions = ['sphinx.ext.autodoc', 35 | 'sphinx.ext.coverage', 36 | 'sphinx.ext.mathjax', 37 | 'sphinx.ext.viewcode', 38 | 'sphinx.ext.intersphinx', 39 | 'sphinx.ext.githubpages', 40 | 'sphinx.ext.napoleon', 41 | 'nbsphinx'] 42 | 43 | # Add any paths that contain templates here, relative to this directory. 44 | templates_path = ['_templates'] 45 | 46 | # The suffix(es) of source filenames. 47 | # You can specify multiple suffix as a list of string: 48 | # 49 | # source_suffix = ['.rst', '.md'] 50 | source_suffix = '.rst' 51 | 52 | # The master toctree document. 53 | master_doc = 'index' 54 | 55 | # General information about the project. 56 | project = 'Pyboo' 57 | copyright = '2017, Mathieu Leocmach' 58 | author = 'Mathieu Leocmach' 59 | 60 | # The version info for the project you're documenting, acts as replacement for 61 | # |version| and |release|, also used in various other places throughout the 62 | # built documents. 63 | # 64 | # The short X.Y version. 65 | version = '1.0.0' 66 | # The full version, including alpha/beta/rc tags. 67 | release = '1.0.0' 68 | 69 | # The language for content autogenerated by Sphinx. Refer to documentation 70 | # for a list of supported languages. 71 | # 72 | # This is also used if you do content translation via gettext catalogs. 73 | # Usually you set "language" from the command line for these cases. 74 | language = None 75 | 76 | # List of patterns, relative to source directory, that match files and 77 | # directories to ignore when looking for source files. 78 | # This patterns also effect to html_static_path and html_extra_path 79 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '**.ipynb_checkpoints'] 80 | 81 | # The name of the Pygments (syntax highlighting) style to use. 82 | pygments_style = 'sphinx' 83 | 84 | # If true, `todo` and `todoList` produce output, else they produce nothing. 85 | todo_include_todos = False 86 | 87 | 88 | # -- Options for HTML output ---------------------------------------------- 89 | 90 | # The theme to use for HTML and HTML Help pages. See the documentation for 91 | # a list of builtin themes. 92 | # 93 | html_theme = 'alabaster' 94 | 95 | # Theme options are theme-specific and customize the look and feel of a theme 96 | # further. For a list of options available for each theme, see the 97 | # documentation. 98 | # 99 | # html_theme_options = {} 100 | 101 | # Add any paths that contain custom static files (such as style sheets) here, 102 | # relative to this directory. They are copied after the builtin static files, 103 | # so a file named "default.css" will overwrite the builtin "default.css". 104 | html_static_path = ['_static'] 105 | 106 | # Custom sidebar templates, must be a dictionary that maps document names 107 | # to template names. 108 | # 109 | # This is required for the alabaster theme 110 | # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars 111 | html_sidebars = { 112 | '**': [ 113 | 'about.html', 114 | 'navigation.html', 115 | 'relations.html', # needs 'show_related': True theme option to display 116 | 'searchbox.html', 117 | 'donate.html', 118 | ] 119 | } 120 | 121 | 122 | # -- Options for HTMLHelp output ------------------------------------------ 123 | 124 | # Output file base name for HTML help builder. 125 | htmlhelp_basename = 'Pyboodoc' 126 | 127 | 128 | # -- Options for LaTeX output --------------------------------------------- 129 | 130 | latex_elements = { 131 | # The paper size ('letterpaper' or 'a4paper'). 132 | # 133 | # 'papersize': 'letterpaper', 134 | 135 | # The font size ('10pt', '11pt' or '12pt'). 136 | # 137 | # 'pointsize': '10pt', 138 | 139 | # Additional stuff for the LaTeX preamble. 140 | # 141 | # 'preamble': '', 142 | 143 | # Latex figure (float) alignment 144 | # 145 | # 'figure_align': 'htbp', 146 | } 147 | 148 | # Grouping the document tree into LaTeX files. List of tuples 149 | # (source start file, target name, title, 150 | # author, documentclass [howto, manual, or own class]). 151 | latex_documents = [ 152 | (master_doc, 'Pyboo.tex', 'Pyboo Documentation', 153 | 'Mathieu Leocmach', 'manual'), 154 | ] 155 | 156 | 157 | # -- Options for manual page output --------------------------------------- 158 | 159 | # One entry per manual page. List of tuples 160 | # (source start file, name, description, authors, manual section). 161 | man_pages = [ 162 | (master_doc, 'pyboo', 'Pyboo Documentation', 163 | [author], 1) 164 | ] 165 | 166 | 167 | # -- Options for Texinfo output ------------------------------------------- 168 | 169 | # Grouping the document tree into Texinfo files. List of tuples 170 | # (source start file, target name, title, author, 171 | # dir menu entry, description, category) 172 | texinfo_documents = [ 173 | (master_doc, 'Pyboo', 'Pyboo Documentation', 174 | author, 'Pyboo', 'One line description of project.', 175 | 'Miscellaneous'), 176 | ] 177 | 178 | 179 | intersphinx_mapping = { 180 | 'python': ('https://docs.python.org/3', None), 181 | 'numpy': ('https://docs.scipy.org/doc/numpy/', None), 182 | 'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None), 183 | 'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None) 184 | } 185 | -------------------------------------------------------------------------------- /boo/test_boo.py: -------------------------------------------------------------------------------- 1 | from math import sqrt, floor 2 | import numpy as np 3 | import pytest 4 | from scipy.spatial import cKDTree as KDTree 5 | from numba import jit 6 | from . import boo 7 | 8 | 9 | def bonds2ngbs(bonds, nb_particles=None): 10 | """convert from bonds to ngb""" 11 | if nb_particles is None: 12 | nb_particles = bonds.max()+1 13 | nngbs = np.zeros(nb_particles, int) 14 | np.add.at(nngbs, bonds.ravel(), 1) 15 | ngbs = np.full((nb_particles, nngbs.max()), -1, int) 16 | for a, b in bonds: 17 | ngbs[a, np.where(ngbs[a] == -1)[0][0]] = b 18 | ngbs[b, np.where(ngbs[b] == -1)[0][0]] = a 19 | return ngbs 20 | 21 | 22 | @jit(nopython=True) #numba to speed up our brute force approach 23 | def periodic_neighbours(pos, maxdist, L): 24 | maxdistsq = maxdist**2 25 | rL = 1./L 26 | bonds = [] 27 | dists = [] 28 | for i in range(len(pos)-1): 29 | for j in range(i+1, len(pos)): 30 | distsq = 0 31 | for d in range(pos.shape[1]): 32 | diff = pos[i,d] - pos[j,d] 33 | diff -= L * floor(diff * rL + 0.5) 34 | distsq += diff*diff 35 | if distsq < maxdistsq: 36 | bonds.append(i) 37 | bonds.append(j) 38 | dists.append(distsq) 39 | return np.array(bonds, np.int64).reshape((len(dists), 2)), np.sqrt(np.array(dists, np.float64)) 40 | 41 | 42 | 43 | @jit(nopython=True) #numba to speed up our brute force approach 44 | def shortest_bonds2ngbs(bonds, dists, N, Nngb=12): 45 | """Convert from bonds to neighbour array (at most Nngb neighbours)""" 46 | ngbs = np.full((N, Nngb), -1, np.int64) 47 | nngbs = np.zeros(N, np.int64) 48 | #sort bonds by increasing length to be able to use first-in-first-served 49 | sbonds = bonds[np.argsort(dists)] 50 | for i in range(len(sbonds)): 51 | a = sbonds[i,0] 52 | b = sbonds[i,1] 53 | if nngbs[a]< ngbs.shape[1]: 54 | ngbs[a, nngbs[a]] = b 55 | nngbs[a] += 1 56 | if nngbs[b]< ngbs.shape[1]: 57 | ngbs[b, nngbs[b]] = a 58 | nngbs[b] += 1 59 | return ngbs 60 | 61 | 62 | 63 | 64 | def known_structure_test(pos, bonds, q6, w6, q4): 65 | """Generic test for known structures""" 66 | q6m = boo.bonds2qlm(pos, bonds) 67 | assert boo.ql(q6m)[0] == pytest.approx(q6) 68 | assert boo.wl(q6m)[0] == pytest.approx(w6) 69 | assert boo.ql(q6m)[0] == pytest.approx(sqrt(boo.product(q6m, q6m)[0])) 70 | q4m = boo.bonds2qlm(pos, bonds, l=4) 71 | assert boo.ql(q4m)[0] == pytest.approx(q4) 72 | q6m_b = boo.ngbs2qlm(pos, bonds2ngbs(bonds)) 73 | assert np.all(q6m_b[0] == q6m[0]) 74 | assert np.all(boo.ql(q6m_b) <= boo.ql(q6m)) 75 | 76 | 77 | 78 | 79 | def test_ico(): 80 | """13 particles icosahedron""" 81 | golden = (1 + sqrt(5))/2 82 | pos = np.array([ 83 | [0, 0, 0], 84 | [0, 1, golden], [0, 1, -golden], [0, -1, golden], [0, -1, -golden], 85 | [1, golden, 0], [1, -golden, 0], [-1, golden, 0], [-1, -golden, 0], 86 | [golden, 0, 1], [golden, 0, -1], [-golden, 0, 1], [-golden, 0, -1], 87 | ]) 88 | bonds = np.column_stack((np.zeros(12, int), np.arange(12)+1)) 89 | known_structure_test( 90 | pos, bonds, 91 | 0.66332495807107972, 92 | -0.052131352806275739, 93 | 0) 94 | 95 | 96 | 97 | def test_fcc(): 98 | """Face centered cubic""" 99 | pos = np.array([ 100 | [0, 0, 0], 101 | [1, 1, 0], [1, -1, 0], [-1, 1, 0], [-1, -1, 0], 102 | [0, 1, 1], [0, -1, 1], [0, 1, -1], [0, -1, -1], 103 | [1, 0, 1], [1, 0, -1], [-1, 0, 1], [-1, 0, -1] 104 | ]) 105 | bonds = np.column_stack((np.zeros(12, int), np.arange(12)+1)) 106 | known_structure_test( 107 | pos, bonds, 108 | 0.57452425971406984, 109 | -0.0026260383340077592, 110 | 0.19094065395649326) 111 | 112 | def test_hcp(): 113 | """Hexagonal compact""" 114 | pos = np.array([ 115 | [0, 0, 0], 116 | [1, 0, 0], [0.5, sqrt(3)/2, 0], [-0.5, sqrt(3)/2, 0], 117 | [-1, 0, 0], [0.5, -sqrt(3)/2, 0], [-0.5, -sqrt(3)/2, 0], 118 | [0.5, 1/(2*sqrt(3)), sqrt(2/3)], 119 | [-0.5, 1/(2*sqrt(3)), sqrt(2/3)], 120 | [0, -1/sqrt(3), sqrt(2/3)], 121 | [0.5, 1/(2*sqrt(3)), -sqrt(2/3)], 122 | [-0.5, 1/(2*sqrt(3)), -sqrt(2/3)], 123 | [0, -1/sqrt(3), -sqrt(2/3)] 124 | ]) 125 | bonds = np.column_stack((np.zeros(12, int), np.arange(12)+1)) 126 | known_structure_test( 127 | pos, bonds, 128 | 0.48476168522368324, 129 | -0.0014913304119056434, 130 | 0.097222222222222085) 131 | 132 | 133 | 134 | def test_bcc9(): 135 | """Body centered cubic (the 8 closest particles)""" 136 | pos = np.array([ 137 | [0, 0, 0], 138 | [1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], 139 | [-1, 1, 1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1], 140 | ]) 141 | bonds = np.column_stack((np.zeros(8, int), np.arange(8)+1)) 142 | known_structure_test( 143 | pos, bonds, 144 | 0.62853936105470865, 145 | 0.0034385344925653301, 146 | 0.50917507721731547) 147 | 148 | def test_crystal_gel(): 149 | """Experimental data from a crystallizing gel.""" 150 | pos = np.loadtxt('examples/AR-Res06A_scan2_t890.xyz', skiprows=1) 151 | maxbondlength = 12.5 152 | #spatial indexing 153 | tree = KDTree(pos, 12) 154 | #query 155 | bonds = tree.query_pairs(maxbondlength, output_type='ndarray') 156 | inside = np.all((pos - pos.min(0) > maxbondlength) & (pos.max() - pos > maxbondlength), -1) 157 | #number of neighbours per particle 158 | Nngb = np.zeros(len(pos), int) 159 | np.add.at(Nngb, bonds.ravel(), 1) 160 | inside[Nngb<4] = False 161 | #tensorial boo 162 | q6m = boo.bonds2qlm(pos, bonds, l=6) 163 | q4m = boo.bonds2qlm(pos, bonds, l=4) 164 | #coarse-graining 165 | Q6m, inside2 = boo.coarsegrain_qlm(q6m, bonds, inside) 166 | Q4m, inside3 = boo.coarsegrain_qlm(q4m, bonds, inside) 167 | assert np.all(inside2 == inside3) 168 | #crystals 169 | xpos = boo.x_particles(q6m, bonds) 170 | assert xpos.sum() == 14188 171 | #surface particles 172 | surf = boo.x_particles(q6m, bonds, nb_thr=2) & np.bitwise_not(xpos) 173 | assert surf.sum() == 9288 174 | 175 | def test_periodic_glass(): 176 | """Monte-Carlo simulation data of a polydisperse hard sphere glass.""" 177 | #prepare input 178 | L = 203. 179 | xyzr = np.loadtxt('examples/3d_6_0.54_0.dat') 180 | radius = xyzr[:, -1] 181 | pos = xyzr[:, :-1] 182 | #bond network (oversized bond length) 183 | maxbondlength = 15. 184 | bonds, dists = periodic_neighbours(pos, maxbondlength, L) 185 | #12 closest (surface distance) neighbours 186 | drij = dists - (radius[bonds[:, 0]] + radius[bonds[:, 1]]) 187 | ngbs = shortest_bonds2ngbs(bonds, drij, len(pos)) 188 | #tensorial boo 189 | q6m = boo.ngbs2qlm(pos, ngbs, l=6, periods=L) 190 | q4m = boo.ngbs2qlm(pos, ngbs, l=4, periods=L) 191 | #crystals 192 | xpos = boo.x_ngbs(q6m, ngbs).sum(-1) > 6 193 | assert xpos.sum() == 22 194 | #surface particles 195 | surf = (boo.x_ngbs(q6m, ngbs).sum(-1) > 2) & np.bitwise_not(xpos) 196 | assert surf.sum() == 748 197 | #icosahedra 198 | w6 = boo.wl(q6m) 199 | ico = w6 < -0.028 200 | assert ico.sum() == 111 201 | -------------------------------------------------------------------------------- /doc/intro.rst: -------------------------------------------------------------------------------- 1 | Introduction to Pyboo 2 | ===================== 3 | 4 | A Python package to compute bond orientational order parameters as defined by Steinhardt Physical Review B (1983) `doi:10.1103/PhysRevB.28.784 `_. 5 | 6 | Steinhardt's bond orientational order parameter is a popular method (>20k citations of the original paper) to identify local symmetries in an assembly of particles in 3D. It can be used in particle-based simulations (typically molecular dynamics, brownian dynamics, monte-carlo, etc.) or in particle-tracking experiments (colloids, granular materials) where the coordinates of all particles are known. 7 | 8 | Licence, citations, contact 9 | --------------------------- 10 | 11 | This code is under GPL 3.0 licence. See LICENCE file. 12 | 13 | Please cite Pyboo and it's author(s) in any scientific publication using this software. 14 | 15 | :: 16 | 17 | @misc{ 18 | pyboo, 19 | title={Pyboo: A Python package to compute bond orientational order parameters}, 20 | author={Mathieu Leocmach}, 21 | year={2017}, 22 | doi={10.5281/zenodo.1066568}, 23 | url={https://github.com/MathieuLeocmach/pyboo} 24 | } 25 | 26 | Contact 27 | Mathieu LEOCMACH, Institut Lumière Matière, UMR-CNRS 5306, Lyon, France 28 | mathieu.leocmach AT univ-lyon1.fr 29 | 30 | 31 | Installation 32 | ------------ 33 | 34 | Dependencies are numpy, scipy and numba. Tested with python 2.7 and python 3.5. 35 | 36 | You can install with pip: :: 37 | 38 | pip install pyboo 39 | 40 | 41 | Input 42 | ----- 43 | 44 | The present library takes as input a (N, 3) array of float coordinates named ``pos`` and a (M, 2) array of integers named ``bonds`` that defines the bond network. If ``bonds`` contains the couple (10, 55) it means that there is a bond between the particles which coordinates can be found at ``pos[10]`` and ``pos[55]``. The bonds are supposed unique and bidirectional, therefore if the bond (10, 55) is in ``bonds``, the bond (55, 10) exists *implicitely* and should not be part of ``bonds``. 45 | 46 | The library is agnostic on how the bonds were determined. Possible choices are (among others): 47 | - two particles closer than a maximum distance, 48 | - Delaunay triangulation. 49 | 50 | Other libraries have very efficient implementations of theses methods. See for example :class:`scipy.spatial.KDTree` for fast spatial query or :class:`scipy.spatial.Delaunay`. 51 | 52 | Alternatively Pyboo can take as input arrays of k nearest neighbours (that can also be obtained from :class:`scipy.spatial.KDTree`). For example in a dense assembly of hard spheres, one expects the important structures (FCC, HCP, icosahedron) to be made of a central particle and its 12 neighbours. The k=12 first neighbours are stored in ``ngbs``, a (N, 12) array of indicies. If for a reason or an other some particles have less than 12 neighbours, the remaining slots can be filled by negative values, e.g. -1. 53 | 54 | Spherical harmonics 55 | ------------------- 56 | 57 | The 3D orientation of each bond can be projected on a base of spherical harmonics :math:`Y_{\ell m}(\theta,\phi)`, where :math:`\ell \geq 0` indicates the order of symmetry, and :math:`m`, with :math:`-\ell \geq m \geq \ell`, indicates the orientation with respect to the referent set of orthonormal axes. Since our bonds are bidirectional :math:`\ell` is even. Averaging these coefficients over a set of bonds yields a measure of the symmetry of this set. 58 | 59 | For example the whole system is characterised by the coefficients 60 | 61 | .. math:: \bar{q}_{\ell m} = \frac{1}{M} \sum_{i,j} Y_{\ell m}(\theta_{ij},\phi_{ij}) 62 | 63 | where the average is taken over all the bonds. More locally, each particle :math:`i` is characterised by the coefficients 64 | 65 | .. math:: q_{\ell m}(i) = \frac{1}{N_i}\sum_{0}^{N_i} Y_{\ell m}(\theta_{ij},\phi_{ij}) 66 | 67 | where there are :math:`N_i` bonds starting from :math:`i`. We call the :math:`q_{\ell m}` coefficients the local tensorial bond orientational order parameter. 68 | 69 | The function :meth:`~boo.boo.bonds2qlm` computes the :math:`q_{\ell m}` coefficients for the :math:`\ell`-fold symetry. The extra parameter `periods` allows to do so in periodic boundary conditions. 70 | 71 | The function :meth:`~boo.boo.ngbs2qlm` does the same from a k neighbours array. For all particles :math:`N_i=k`, even for particles with less than k neighbours. 72 | 73 | Invarients 74 | ---------- 75 | 76 | The tensorial :math:`q_{\ell m}` coefficients are dependent of the orientation of the reference axis. That is why we have to compute quantities that are rotationally invarients: 77 | - the second order invarient indicates the strength of the :math:`\ell`-fold symetry. 78 | 79 | .. math:: q_\ell = \sqrt{\frac{4\pi}{2l+1} \sum_{m=-\ell}^{\ell} |q_{\ell m}|^2 } 80 | 81 | - the third order invarient allows to discriminate different types of :math:`\ell`-fold symetric structures. 82 | 83 | .. math:: w_\ell = \sum_{m_1+m_2+m_3=0} 84 | \left( \begin{array}{ccc} 85 | \ell & \ell & \ell \\ 86 | m_1 & m_2 & m_3 87 | \end{array} \right) 88 | q_{\ell m_1} q_{\ell m_2} q_{\ell m_3} 89 | 90 | where the term in brackets is the Wigner 3-j symbol. For example :math:`w_6` allows to disctiminate icosahedral structures, see Leocmach & Tanaka, Nature Com. (2012) `doi: 10.1038/ncomms1974 `_. 91 | 92 | Invarients can be computed respectively by :meth:`~boo.boo.ql` and :meth:`~boo.boo.wl`. 93 | 94 | Coarse-graining 95 | --------------- 96 | 97 | It is possible to coarse-grain the tensorial bond orientational order to get more information about the second shell of neighbours and thus discriminate better crystal structures, see Lechner & Delago J. Chem. Phys. (2008) `doi:10.1063/1.2977970 `_: 98 | 99 | .. math:: Q_{\ell m}(i) = \frac{1}{N_i+1}\left( q_{\ell m}(i) + \sum_{j=0}^{N_i} q_{\ell m}(j)\right) 100 | 101 | here the central particle is included in the sum. 102 | 103 | Coarse-graining can be done with :meth:`~boo.boo.coarsegrain_qlm` or :meth:`~boo.boo.coarsegrain_qlm_ngbs`. The parameter ``inside`` is a (N) array of booleans indicating particles where the original :math:`q_{\ell m}` coefficients were truthfully determined. Counter examples (where ``inside`` takes the value ``False``) are particles that were too close to one edge of the experimental window, so that some of their neighbours were not dectected, causing a incomplete bond set. Coarse-grained invariants :math:`Q_\ell` and :math:`W_\ell` can be computed in the same way by :meth:`~boo.boo.ql` and :meth:`~boo.boo.wl` respectively. 104 | 105 | Cross product 106 | ------------- 107 | 108 | The similarity between the symetry and the orientation of two neighbourhoods can be estimated by the normalized scalar product 109 | 110 | .. math:: s_\ell(i,j) = \frac{4\pi}{2\ell + 1} \frac{\sum_{m=-\ell}^{\ell} q_{\ell m}(i) q_{\ell m}^{*}(j)}{q_\ell(i) q_\ell(j)} 111 | 112 | This quantity is the result of :meth:`~boo.boo.product` divided by ``ql(qlm1) * ql(qlm2)``. The similarity between all neighbouring particles can be obtained from :meth:`~boo.boo.bond_normed_product`. 113 | 114 | Typical use: when :math:`s_6(i,j)` is larger than a threshold value (typically 0.7) the bond can be considered crystalline. A particle is considered crystalline when it has at least 7 crystalline bonds. See Auer & Frenkel, J.Chem.Phys. (2004) `doi: 10.1063/1.1638740 `_. This procedure is implemented in :meth:`~boo.boo.x_particles`. 115 | 116 | In a more continuous manner, the crystallinity parameter is defined as the average of the cross products over the neighbours, see Russo & Tanaka, Sci Rep. (2012) `doi:10.1038/srep00505 `_. 117 | 118 | .. math:: C_\ell(i) = \frac{1}{N_i} \sum_{j=0}{N_i} s_\ell (i,j) 119 | 120 | Crystallinity parameter is computed by :meth:`~boo.boo.crystallinity`. 121 | 122 | Spatial correlation 123 | ------------------- 124 | 125 | To know how spatially extended is the local symmetry and orientation, one can look at the average cross product at a certain distance. 126 | 127 | .. math:: g_\ell(r) = \frac{\sum_{i,j} s_\ell(i,j)\delta(r_{ij}-r)}{\sum_{i,j} \delta(r_{ij}-r)} 128 | 129 | where :math:`\delta` is a binning function equal to one between 0 and :math:`dr` and zero elsewhere. 130 | 131 | The function :meth:`~boo.boo.gG_l` returns separately the numerator and denominator of the above expression to ease further averaging. ``maxdist`` is the maximum range to consider and ``Nbins`` the number of bins between 0 and ``maxdist``. ``qlms`` is a list of bond orientational order coefficients that can have different values of :math:`\ell`, some coarse-grained or not. ``is_center`` is a (N) array of boolean marking the particles that are further than maxdist from any edge of the experimental window in order to avoid edge effects. 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /boo/boo.py: -------------------------------------------------------------------------------- 1 | """Computation of bond orientational order""" 2 | # 3 | # Copyright 2011 Mathieu Leocmach 4 | # 5 | # This file is part of pyboo. 6 | # 7 | # pyboo is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # pyboo is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with pyboo. If not, see . 19 | # 20 | from math import floor 21 | import numpy as np 22 | from scipy.special import sph_harm 23 | from scipy.spatial import cKDTree as KDTree 24 | from numba import jit, vectorize, guvectorize 25 | 26 | 27 | @vectorize#(['float64(complex128)', 'float32(complex64)']) 28 | def abs2(x): 29 | """squared norm of a complex number""" 30 | return x.real**2 + x.imag**2 31 | 32 | @vectorize(['float64(float64,float64,float64)']) 33 | def periodify(u, v, period=-1.0): 34 | """ 35 | Given two arrays of points in a d-dimensional space 36 | with periodic boundary conditions, 37 | find the shortest vector between each pair. 38 | 39 | Implemented using algorithm C4 of Deiters 2013 doi:10.1524/zpch.2013.0311 40 | 41 | Parameters 42 | ---------- 43 | u,v : array_like float 44 | period : float or an array of floats of length d. 45 | Negative periods indicate no periodicity in this dimension. 46 | 47 | Returns 48 | ---------- 49 | array_like float 50 | """ 51 | diff = v - u 52 | if period <= 0: 53 | return diff 54 | return diff - period * floor(diff /period + 0.5) 55 | 56 | 57 | def cart2sph(cartesian): 58 | r""" 59 | Convert Cartesian coordinates :math:`[[x,y,z],]` 60 | to spherical coordinates :math:`[[r,\phi,\theta],]`. 61 | :math:`\phi` is cologitudinal and :math:`\theta` azimutal 62 | """ 63 | spherical = np.zeros_like(cartesian) 64 | #distances 65 | c2 = cartesian**2 66 | r2 = c2.sum(-1) 67 | spherical[:, 0] = np.sqrt(r2) 68 | #work only on non-zero, non purely z vectors 69 | sel = (r2 > c2[:, 0]) | (r2+1.0 > 1.0) 70 | x, y, z = cartesian[sel].T 71 | r = spherical[sel, 0] 72 | #colatitudinal phi [0, pi[ 73 | spherical[sel, 1] = np.arccos(z/r) 74 | #azimutal (longitudinal) theta [0, 2pi[ 75 | theta = np.arctan2(y, x) 76 | theta[theta < 0] += 2*np.pi 77 | spherical[sel, 2] = theta 78 | return spherical 79 | 80 | def vect2Ylm(v, l): 81 | """Projects vectors v on the base of spherical harmonics of degree l.""" 82 | spherical = cart2sph(v) 83 | return sph_harm( 84 | np.arange(l+1)[:, None], l, 85 | spherical[:, 2][None, :], 86 | spherical[:, 1][None, :] 87 | ) 88 | 89 | def single_pos2qlm(pos, i, ngb_indices, l=6): 90 | """Returns the qlm for a single position""" 91 | #vectors to neighbours 92 | vectors = pos[ngb_indices]-pos[i] 93 | return vect2Ylm(vectors, l).mean(-1) 94 | 95 | def bonds2qlm(pos, bonds, l=6, periods=-1.0): 96 | """ 97 | Compute bond orientational order for each particle. 98 | 99 | Parameters 100 | ---------- 101 | pos : (N, 3) array of floats 102 | Spatial coordinates 103 | bonds : (M, 2) array of integers. 104 | Bonds are supposed unique and bidirectional. 105 | l : int 106 | A positive even integer indicating the order of symmetry. 107 | periods : float or (3) array of floats. 108 | Negative periods indicate no periodicity in this dimension. 109 | 110 | Returns 111 | ---------- 112 | qlm : (N, 2*l+1) array of complex 113 | Tensorial order parameter of order l for each particle 114 | """ 115 | qlm = np.zeros((len(pos), l+1), np.complex128) 116 | #spherical harmonic coefficients for each bond 117 | Ylm = vect2Ylm( 118 | periodify( 119 | pos[bonds[:, 0]], 120 | pos[bonds[:, 1]], 121 | periods 122 | ), 123 | l 124 | ).T 125 | #bin bond into each particle belonging to it 126 | np.add.at(qlm, bonds[:, 0], Ylm) 127 | np.add.at(qlm, bonds[:, 1], Ylm) 128 | #divide by the number of bonds each particle belongs to 129 | Nngb = np.zeros(len(pos), int) 130 | np.add.at(Nngb, bonds.ravel(), 1) 131 | return qlm / np.maximum(1, Nngb)[:, None] 132 | 133 | def ngbs2qlm(pos, ngbs, l=6, periods=-1): 134 | """ 135 | Compute bond orientational order supposing at most M neigbours per particles. 136 | 137 | Parameters 138 | ---------- 139 | pos : (N, 3) array of floats 140 | Spatial coordinates 141 | ngbs : (N, k) array of int 142 | Neighbour indices. 143 | Negative indices correspond to invalid neighbours and give zero contribution. 144 | l : int 145 | A positive even integer indicating the order of symmetry. 146 | periods : float or (3) floats. 147 | Negative periods indicate no periodicity in this dimension. 148 | 149 | Returns 150 | ---------- 151 | qlm : (N, 2*l+1) array of complex 152 | Tensorial order parameter of order l for each particle 153 | """ 154 | assert len(pos) == len(ngbs) 155 | #eliminate neighbours with negative indices 156 | good = ngbs >= 0 157 | #spherical harmonic coefficients for each bond 158 | Ylm = vect2Ylm( 159 | periodify( 160 | pos[np.repeat(np.arange(ngbs.shape[0]), ngbs.shape[-1])[good.ravel()]], 161 | pos[ngbs[good].ravel()], 162 | periods 163 | ), 164 | l 165 | ).T 166 | Ylm2 = np.zeros([ngbs.shape[0], ngbs.shape[1], l+1], np.complex128) 167 | Ylm2.reshape((ngbs.shape[0]*ngbs.shape[1], l+1))[good.ravel()] = Ylm 168 | return Ylm2.mean(1) 169 | 170 | def coarsegrain_qlm(qlm, bonds, inside): 171 | r""" 172 | Coarse grain the bond orientational order on the neighbourhood of a particle 173 | 174 | .. math:: Q_{\ell m}(i) = \frac{1}{N_i+1}\left(q_{\ell m}(i) + \sum_{j=0}^{N_i} q_{\ell m}(j)\right) 175 | 176 | See Lechner & Delago J. Chem. Phys. (2008) doi:10.1063/1.2977970 177 | Returns Qlm and the mask of the valid particles 178 | 179 | Parameters 180 | ---------- 181 | qlm : (N, 2*l+1) array of complex 182 | Tensorial order parameter of order l for each particle 183 | bonds : (M, 2) array of integers 184 | Bonds are supposed unique and bidirectional. 185 | inside : (N) array of booleans 186 | Particles that are outside are not added and contaminate their neighbours. 187 | 188 | Returns 189 | ---------- 190 | Qlm : (N, 2*l+1) array of complex 191 | Coarse-grained tensorial order parameter of order l for each particle 192 | inside2 : (N) array of booleans 193 | Particles that are inside and have no neighbour outside 194 | """ 195 | #Valid particles must be valid themselves have only valid neighbours 196 | inside2 = np.copy(inside) 197 | np.bitwise_and.at(inside2, bonds[:, 0], inside[bonds[:, 1]]) 198 | np.bitwise_and.at(inside2, bonds[:, 1], inside[bonds[:, 0]]) 199 | #number of neighbours 200 | Nngb = np.zeros(len(qlm), int) 201 | np.add.at(Nngb, bonds.ravel(), 1) 202 | #sum the boo coefficients of all the neighbours 203 | Qlm = np.zeros_like(qlm) 204 | np.add.at(Qlm, bonds[:, 0], qlm[bonds[:, 1]]) 205 | np.add.at(Qlm, bonds[:, 1], qlm[bonds[:, 0]]) 206 | Qlm[np.bitwise_not(inside2)] = 0 207 | return Qlm / np.maximum(1, Nngb)[:, None], inside2 208 | 209 | def coarsegrain_qlm_ngbs(qlm, ngbs, inside): 210 | r""" 211 | Coarse grain the bond orientational order on the neighbourhood of a particle 212 | 213 | .. math:: Q_{\ell m}(i) = \frac{1}{N_i+1}\left(q_{\ell m}(i) + \sum_{j=0}^{N_i} q_{\ell m}(j)\right) 214 | 215 | See Lechner & Delago J. Chem. Phys. (2008) doi:10.1063/1.2977970 216 | Returns Qlm and the mask of the valid particles 217 | 218 | Parameters 219 | ---------- 220 | qlm : (N, 2*l+1) array of complex 221 | Tensorial order parameter of order l for each particle 222 | ngbs : (N, k) array of int 223 | Neighbour indices. 224 | Negative indices correspond to invalid neighbours and give zero contribution. 225 | inside : (N) array of booleans 226 | Particles that are outside are not added and contaminate their neighbours. 227 | 228 | Returns 229 | ---------- 230 | Qlm : (N, 2*l+1) array of complex 231 | Coarse-grained tensorial order parameter of order l for each particle 232 | inside2 : (N) array of booleans 233 | Particles that are inside and have no neighbour outside 234 | """ 235 | assert len(qlm) == len(ngbs) 236 | #eliminate neighbours with negative indices 237 | good = ngbs >= 0 238 | #Valid particles must be valid themselves have only valid neighbours 239 | inside2 = np.copy(inside) 240 | inside2 = inside & np.all(np.where(good, inside[ngbs], True), axis=-1) 241 | #sum 242 | Qlm = np.zeros((ngbs.shape[0], ngbs.shape[1], qlm.shape[-1]), qlm.dtype) 243 | flatshape = (ngbs.shape[0]*ngbs.shape[1], qlm.shape[-1]) 244 | Qlm.reshape(flatshape)[good.ravel()] = qlm[ngbs].reshape(flatshape)[good.ravel()] 245 | return (Qlm.sum(1) + qlm) / (1 + ngbs.shape[1]), inside2 246 | 247 | 248 | @guvectorize( 249 | ['void(complex128[:], complex128[:], float64[:])'], 250 | '(n),(n)->()', 251 | #nopython=True 252 | ) 253 | def product(qlm1, qlm2, prod): 254 | r""" 255 | Product between two qlm 256 | 257 | .. math:: s_\ell (i,j) = \frac{4\pi}{2\ell + 1} \sum_{m=-\ell}{\ell} q_{\ell m}(i) q_{\ell m}(j)^* 258 | """ 259 | l = qlm1.shape[0]-1 260 | prod[0] = (qlm1[0] * qlm2[0].conjugate()).real 261 | for i in range(1, len(qlm1)): 262 | prod[0] += 2 * (qlm1[i] * qlm2[i].conjugate()).real 263 | prod[0] *= 4*np.pi/(2*l+1) 264 | 265 | 266 | @jit#(nopython=True) 267 | def ql(qlm): 268 | r""" 269 | Second order rotational invariant of the bond orientational order of l-fold symmetry 270 | 271 | .. math:: q_\ell = \sqrt{\frac{4\pi}{2l+1} \sum_{m=-\ell}^{\ell} |q_{\ell m}|^2 } 272 | 273 | Parameters 274 | ---------- 275 | qlm : (N, 2*l+1) array of complex 276 | Tensorial order parameter of order l for each particle 277 | 278 | Returns 279 | ---------- 280 | (N) array of float 281 | """ 282 | q = abs2(qlm[..., 0]) 283 | for m in range(1, qlm.shape[-1]): 284 | q += 2 * abs2(qlm[..., m]) 285 | l = qlm.shape[-1]-1 286 | return np.sqrt(4*np.pi / (2*l+1) * q) 287 | 288 | @jit#(['complex128[:](complex128[:,:], int64)'], nopython=True) 289 | def get_qlm(qlms, m): 290 | """qlm coefficients are redundant, negative m are obtained from positive m""" 291 | if m >= 0: 292 | return qlms[..., m] 293 | if (-m)%2 == 0: 294 | return np.conj(qlms[..., -m]) 295 | return -np.conj(qlms[..., -m]) 296 | 297 | 298 | @jit#(['float64(int64, int64[:])'], nopython=True) 299 | def get_w3j(l, ms): 300 | """Wigner 3j coefficients""" 301 | sm = np.sort(np.abs(ms)) 302 | return _W3J_[l//2, _W3J_M1_OFFSET_[sm[-1]] + sm[0]] 303 | 304 | @jit 305 | def wl(qlm): 306 | r""" 307 | Third order rotational invariant of the bond orientational order of l-fold symmetry 308 | 309 | .. math:: w_\ell = \sum_{m_1+m_2+m_3=0} 310 | \left( \begin{array}{ccc} 311 | \ell & \ell & \ell \\ 312 | m_1 & m_2 & m_3 313 | \end{array} \right) 314 | q_{\ell m_1} q_{\ell m_2} q_{\ell m_3} 315 | 316 | Parameters 317 | ---------- 318 | qlm : (N, 2*l+1) array of complex 319 | Tensorial order parameter of order l for each particle 320 | 321 | Returns 322 | ---------- 323 | (N) array of float 324 | """ 325 | l = qlm.shape[-1]-1 326 | w = np.zeros(qlm.shape[:-1]) 327 | for m1 in range(-l, l+1): 328 | for m2 in range(-l, l+1): 329 | m3 = -m1 - m2 330 | if -l <= m3 and m3 <= l: 331 | w += get_w3j(l, np.array([m1, m2, m3])) * ( 332 | get_qlm(qlm, m1) * get_qlm(qlm, m2) * get_qlm(qlm, m3) 333 | ).real 334 | return w 335 | 336 | def bond_normed_product(qlm, bonds): 337 | r""" 338 | Normalized cross product 339 | 340 | .. math:: \hat{s}_\ell (i,j) = \frac{s_\ell (i,j)}{q_\ell(i) q_\ell(j)} 341 | 342 | Parameters 343 | ---------- 344 | qlm : (N, 2*l+1) array of complex 345 | Tensorial order parameter of order l for each particle 346 | bonds : (M, 2) array of integers 347 | Bonds are supposed unique and bidirectional. 348 | 349 | Returns 350 | ---------- 351 | (M) array of float 352 | """ 353 | q = ql(qlm) 354 | return product(qlm[bonds[:, 0]], qlm[bonds[:, 1]])/( 355 | q[bonds[:, 0]] * q[bonds[:, 1]] 356 | ) 357 | 358 | def x_bonds(qlm, bonds, threshold=0.7): 359 | """ 360 | Which bonds are crystalline? 361 | If the normalized cross product of their qlm is larger than the threshold. 362 | 363 | Parameters 364 | ---------- 365 | qlm : (N, 2*l+1) array of complex 366 | Tensorial order parameter of order l for each particle 367 | bonds : (M, 2) array of integers 368 | Bonds are supposed unique and bidirectional. 369 | threshold : float 370 | Lower bound of the normed product for a bond to be considered crystalline. Default 0.7. 371 | 372 | Returns 373 | ---------- 374 | (P, 2) array of integers 375 | The bonds that are crystalline. P <= M 376 | """ 377 | return bonds[bond_normed_product(qlm, bonds) > threshold] 378 | 379 | def x_ngbs(qlm, ngbs, threshold=0.7): 380 | """ 381 | With which neighbours j does a particles i have a crystalline bond? 382 | If the normalized cross product of their qlm is larger than the threshold. 383 | 384 | Parameters 385 | ---------- 386 | qlm : (N, 2*l+1) array of complex 387 | Tensorial order parameter of order l for each particle 388 | ngbs : (N, k) array of int 389 | Neighbour indices. 390 | Negative indices correspond to invalid neighbours and give zero contribution. 391 | threshold : float 392 | Lower bound of the normed product for a bond to be considered crystalline. Default 0.7. 393 | 394 | Returns 395 | ---------- 396 | (N, k) array of booleans 397 | """ 398 | bonds = np.column_stack(( 399 | np.repeat(np.arange(ngbs.shape[0]), ngbs.shape[1]), 400 | ngbs.ravel() 401 | )) 402 | good = ngbs >= 0 403 | xn = (bond_normed_product(qlm, bonds) > threshold).reshape(ngbs.shape) 404 | return xn & good 405 | 406 | def x_particles(qlm, bonds, value_thr=0.7, nb_thr=7): 407 | """ 408 | Which particles are crystalline? If they have more than nb_thr crystalline bonds. 409 | 410 | Parameters 411 | ---------- 412 | qlm : (N, 2*l+1) array of complex 413 | Tensorial order parameter of order l for each particle 414 | bonds : (M, 2) array of integers. 415 | Bonds are supposed unique and bidirectional. 416 | value_thr : float 417 | Lower bound of the normed product for a bond to be considered crystalline. Default 0.7. 418 | nb_thr : int 419 | Minimum number of crystalline bonds for a particle to be considered crystalline. 420 | 421 | Returns 422 | ---------- 423 | (N) array of booleans 424 | """ 425 | xb = x_bonds(qlm, bonds, threshold=value_thr) 426 | nb = np.zeros(len(qlm), int) 427 | np.add.at(nb, xb.ravel(), 1) 428 | return nb >= nb_thr 429 | 430 | def crystallinity(qlm, bonds): 431 | r""" 432 | Crystallinity parameter, see Russo & Tanaka, Sci Rep. (2012) doi:10.1038/srep00505. 433 | 434 | .. math:: C_\ell(i) = \frac{1}{N_i} \sum_{j=0}{N_i} \hat{s}_\ell (i,j) 435 | 436 | Parameters 437 | ---------- 438 | qlm : (N, 2*l+1) array of complex 439 | Tensorial order parameter of order l for each particle 440 | bonds : (M, 2) array of integers. 441 | Bonds are supposed unique and bidirectional. 442 | 443 | Returns 444 | ---------- 445 | (N) array of floats 446 | """ 447 | #cross product for all bonds 448 | bv = bond_normed_product(qlm, bonds) 449 | #count number or neighbours 450 | nb = np.zeros(len(qlm), int) 451 | np.add.at(nb, bonds.ravel(), 1) 452 | #sum cross product over bonds for each particle 453 | c = np.zeros(len(qlm)) 454 | np.add.at(c, bonds[:, 0], bv) 455 | np.add.at(c, bonds[:, 1], bv) 456 | #mean 457 | return c/np.maximum(1, nb) 458 | 459 | def gG_l(pos, qlms, is_center, Nbins, maxdist): 460 | """ 461 | Spatial correlation of the qlms (non normalized). 462 | 463 | For each particle i tagged as is_center, 464 | for each particle j closer than maxdist, 465 | do the cross product between their qlm and count, 466 | then bin each quantity with respect to distance. 467 | The two first sums need to be normalised by the last one. 468 | 469 | Periodic boundary conditions are not supported. 470 | 471 | Parameters 472 | ---------- 473 | pos : (N, 3) array of floats 474 | Spatial coordinates 475 | qlms : list 476 | A list of M (N, 2l+1) arrays of boo coordinates for l-fold symmetry. 477 | l can be different for each item. 478 | is_center : (N) array of bool. 479 | For example all particles further away than maxdist from any edge of the box. 480 | Nbins : int 481 | The number of bins along r 482 | maxdist : float 483 | The maximum distance considered. 484 | 485 | Returns 486 | ---------- 487 | hqQ : (Nbins, M) array of floats 488 | The sum of cross products for each distance and each qlm 489 | g : (Nbins) array of ints 490 | The number of pairs for each distance 491 | """ 492 | for qlm in qlms: 493 | assert len(pos) == len(qlm) 494 | assert len(is_center) == len(pos) 495 | #conversion factor between indices and bins 496 | l2r = Nbins/maxdist 497 | #result containers 498 | #an additional bin for the case where the distance is exactly equal to maxdist 499 | hqQ = np.zeros((Nbins+1, len(qlms))) 500 | g = np.zeros(Nbins+1, int) 501 | #compute ql for all particles 502 | qQ = np.array([ql(qlm) for qlm in qlms]) 503 | nonzero = qQ.min(0) + 1.0 > 1.0 504 | #spatial indexing 505 | tree = KDTree(pos[nonzero], 12) 506 | centertree = KDTree(pos[is_center & nonzero], 12) 507 | #all pairs of points closer than maxdist with their distances in a record array 508 | query = centertree.sparse_distance_matrix(tree, maxdist, output_type='ndarray') 509 | #convert in original indices 510 | nonzeroindex = np.where(nonzero)[0] 511 | centerindex = np.where(is_center&nonzero)[0] 512 | query['i'] = centerindex[query['i']] 513 | query['j'] = nonzeroindex[query['j']] 514 | #keep only pairs where the points are distinct 515 | good = query['i'] != query['j'] 516 | query = query[good] 517 | #binning of distances 518 | rs = (query['v'] * l2r).astype(int) 519 | np.add.at(g, rs, 1) 520 | #binning of boo cross products 521 | pqQs = np.empty((len(rs), len(qlms))) 522 | for it, qlm in enumerate(qlms): 523 | pqQs[:, it] = product(qlm[query['i']], qlm[query['j']]) 524 | prodnorm = qQ[it, query['i']] * qQ[it, query['j']] 525 | pqQs[:, it] /= prodnorm 526 | np.add.at(hqQ, rs, pqQs) 527 | return hqQ[:-1], g[:-1] 528 | 529 | 530 | 531 | # Define constants for Wigner 3j symbols 532 | 533 | _W3J_ = np.zeros([6, 36]) 534 | _W3J_[0, 0] = 1 535 | _W3J_[1, :4] = np.sqrt([2/35., 1/70., 2/35., 3/35.]) * [-1, 1, 1, -1] 536 | _W3J_[2, :9] = np.sqrt([ 537 | 2/1001., 1/2002., 11/182., 5/1001., 538 | 7/286., 5/143., 14/143., 35/143., 5/143., 539 | ]) * [ 540 | 3, -3, -1/3.0, 2, 1, -1/3.0, 1/3.0, -1/3.0, 1 541 | ] 542 | 543 | _W3J_[3, :16] = np.sqrt([ 544 | 1/46189., 1/46189., 545 | 11/4199., 105/46189., 546 | 1/46189., 21/92378., 547 | 1/46189., 35/46189., 14/46189., 548 | 11/4199., 21/4199., 7/4199., 549 | 11/4199., 77/8398., 70/4199., 21/4199. 550 | ])*[ 551 | -20, 10, 1, -2, -43/2.0, 3, 4, 2.5, -6, 2.5, -1.5, 1, 1, -1, 1, -2 552 | ] 553 | 554 | _W3J_[4, :25] = np.sqrt([ 555 | 10/96577., 5/193154., 556 | 1/965770., 14/96577., 557 | 1/965770., 66/482885., 558 | 5/193154., 3/96577., 77/482885., 559 | 65/14858., 5/7429., 42/37145., 560 | 65/14858., 0.0, 3/7429., 66/37145., 561 | 13/74290., 78/7429., 26/37145., 33/37145., 562 | 26/37145., 13/37145., 273/37145., 429/37145., 11/7429., 563 | ]) * [ 564 | 7, -7, -37, 6, 73, -3, 565 | -5, -8, 6, -1, 3, -1, 566 | 1, 0, -3, 2, 7, -1, 3, -1, 567 | 1, -3, 1, -1, 3 568 | ] 569 | 570 | _W3J_[5, :36] = np.sqrt([ 571 | 7/33393355., 7/33393355., 572 | 7/33393355., 462/6678671., 573 | 7/33393355., 1001/6678671., 574 | 1/233753485., 77/6678671., 6006/6678671., 575 | 1/233753485., 55/46750697., 1155/13357342., 576 | 1/233753485., 2926/1757545., 33/46750697., 3003/6678671., 577 | 119/1964315., 22/2750041., 1914/474145., 429/5500082., 578 | 17/13750205., 561/2750041., 77/392863., 143/27500410., 2002/392863., 579 | 323/723695., 1309/20677., 374/144739., 143/144739., 1001/206770., 580 | 323/723695., 7106/723695., 561/723695., 2431/723695., 2002/103385., 1001/103385. 581 | ]) * [ 582 | -126, 63, 196/3.0, -7, -259/2.0, 7/3.0, 583 | 1097/3.0, 59/6.0, -2, 584 | 4021/6.0, -113/2.0, 3, 585 | -914, 1/3.0, 48, -3, 586 | -7/3.0, 65/3.0, -1, 3, 587 | 214/3.0, -3, -2/3.0, 71/3.0, -1, 588 | 3, -1/3.0, 5/3.0, -2, 1/3.0, 589 | 2/3.0, -1/3.0, 2, -4/3.0, 2/3.0, -1 590 | ] 591 | 592 | _W3J_M1_OFFSET_ = np.array([0, 1, 2, 4, 6, 9, 12, 16, 20, 25, 30], int) 593 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------