Code Monkey home page Code Monkey logo

qmpy's Introduction

QmPy is a python package containing routines to numerically solve and visualize the schroedinger equation for different potentials. Its main purpose is to support an executable script called qmsolve which combines the functionalities above.

Disclaimer

This is a student project. It utilizes very unstable and simple numerical algorithms.

Requirements

This package requires Python 3.6 or higher and the packages numpy, scipy and matplotlib.

Installation

For easy installation with pip use:

pip install -i https://test.pypi.org/simple/ qmpy-schrodinger

Usage

Using the script

Information for legacy users

In terms of the restructuring in release 3.0.0, the configuration file format was changed to json. An additional script is included to convert legacy configuration files to the new syntax.

./parse_legacy_config old_config_filename.inp

Usage

The script requires a configuration file which contains all the necessary information about the quantum mechanical system. The data is provided in json format. By default the script will search for a file 'qmsolve_config.json'. An example of such a file is included below.

{
  "computation": {
    "mass": 4.0,
    "xrange": {
      "xmin": -20.0,
      "xmax":  20.0,
      "npoint": 1999
    },
    "evrange": [1, 10],
    "interpolation.type": "cspline",
    "potential": {
      "x.values": [-20.0, -10.0, 0.0, 10.0, 20.0],
      "y.values": [35.0, 0.0, 2.0, 0.0, 35.0]
    }
  },
  "visualisation": {
    "autoscale": true,
    "scale": null,
    "xlim": null,
    "ylim": null
  }
}

The field 'visualisation' is entirely optional and just for customisation purposes. The script can be run via the command line by using

./qmsolve

It supports computing energies, wavefunctions and expected values for the x-coordinate, which is invoked with the command ./qmsolve compute. The results may also be visualized by using ./qmsolve visualise. It also takes numerous optional arguments which will be listed when using the -h option with one of the commands.

Using the modules

Calculating the first four energies and wavefunctions of a particle in a box aswell as the expected values and uncertainties for the x-xoordinate for each state.

from qmpy.solvers import schroedinger, calculate_expval, calculate_uncertainty
from numpy import linspace, zeros

mass = 2.0
xcords = linspace(-2, 2, 1999)
pot = zeros((1999, ))

vals = {'mass': mass,
        'xcords': xcords,
        'potential': pot}

# returns the first four energies and wavefunctions
energies, wfuncs = schroedinger(vals, select_range=(0, 3))

# calculate the expected value for the x-coordinate for each state
expvals = calculate_expval(xcoords, wfuncs)

# calculate the uncertainty of the x-coordinate for each state
uncs = calculate_uncertainty(xcoords, wfuncs)

Plotting numerical data contained in a directory

from qmpy.graphics import qm_plot

# directory containing the files potential.dat, energies.dat,
# wavefuncs.dat, and expvalues.dat.
datadir = 'myqmdata/'

# plot the data and save the plot as 'my_plot.png'
qm_plot(datadir, sname='my_plot.png')

Documentation

The documentation can be found at kenokrieger.com/code_projects/qmpy.

Tests

Tests for the package are located in the tests/ directory. The tests can all be run via pytest through the command line (python3 -m pytest in the highest directory; you may need to update your PYTHONPATH accordingly).

Contributing

Contributions are always welcome. To contribute fork the repository from github and develop your feature including unit tests. For your contribution to be incorporated in the main build issue a pull request.

License

BSD 2-Clause License
See LICENSE.txt for further information.

qmpy's People

Contributors

kenokrieger avatar helmutwecke avatar

Stargazers

Bassirou Ndiaye avatar  avatar

Watchers

 avatar

Forkers

helmutwecke

qmpy's Issues

Test data for solvers

Reference wavefunctions for the infinite potential well are not normalized.
This affects the following files:

  • wfuncs.infwell.ref

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.