Giter Club home page Giter Club logo

pyunitwizard's Introduction

PyUnitWizard

GitHub Actions Build Status codecov License: MIT Install with conda

There are several Python libraries to work with physical quantities in the market, such as pint, unyt or openmm.unit. Imagine that your project or workflow requires the interaction with more than one of these tools, or that you are not sure if you will work with a different quantities library in the future. Wouldn't having a unique API to work with different forms of physical quantities be a relief? PyUnitWizard just does that. It is the wizard you need in your code to change the form of your quantities with no effort.

Example

In [1]: import pyunitwizard as puw

In [2]: puw.configure.load_libraries(['pint', 'openmm.unit'])
   ...: puw.configure.set_default_form('pint')
   ...: puw.configure.set_standard_units(['nm', 'ps', 'kcal', 'mole'])
   ...: 

In [3]: q = puw.quantity(2.5, 'nanometers/picoseconds')

In [4]: puw.get_form(q)
Out[4]: 'pint'

In [5]: puw.get_value(q)
Out[5]: 2.5

In [6]: puw.get_unit(q)
Out[6]: <Unit('nanometer / picosecond')>

In [7]: puw.dimensionality(q)
Out[7]: {'[L]': 1, '[M]': 0, '[T]': -1, '[K]': 0, '[mol]': 0, '[A]': 0, '[Cd]': 0}

In [8]: q2 = puw.convert(q, to_unit='angstroms/femtoseconds', to_form='openmm.unit')

In [9]: print(q2)
0.025000000000000005 A/fs

In [10]: puw.get_form(q2)
Out[10]: 'openmm.unit'

In [11]: puw.compatibility(q, q2)
Out[11]: True

In [12]: q3 = puw.standardize(q2)

In [13]: print('q3 is now a {} quantity expressed in {}.'.format(puw.get_form(q3), puw.get_unit(q3)))
q3 is now a pint quantity expressed in nanometer / picosecond.

Units Python libraries

License

This project is under an MIT License. A copy of the license text is included in this repository.

Copyright

Copyright (c) 2021-2022 The Mexico Children's Hospital Federico Gómez, its Unit of Research on Computational Biology and Drug Design, and authors.

Acknowledgements

Project based on the Computational Molecular Science Python Cookiecutter version 1.5.

Contributors

A complete list of contributors can be found checking the insights section of this repository.

The main project authors and contributors are:

  • Daniel Ibarrola Sánchez
  • Liliana M. Moreno Vargas
  • Diego Prada Gracia

pyunitwizard's People

Contributors

daniel-ibarrola avatar dprada avatar

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.