<!-- DO NOT EDIT. -->
<!-- THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. -->
<!-- TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: -->
<!-- "auto_examples/readers_writers/plot_unit_conversion.py" -->
<!-- LINE NUMBERS ARE GIVEN BELOW. -->

#### NOTE
[Go to the end](#sphx-glr-download-auto-examples-readers-writers-plot-unit-conversion-py)
to download the full example code.

<a id="sphx-glr-auto-examples-readers-writers-plot-unit-conversion-py"></a>

# Unit Conversion

Convert [LAMMPS units](https://docs.lammps.org/units.html) to SI or other unit systems:

**Supported unit styles:**

- `real` - kcal/mol, Angstrom, fs
- `metal` - eV, Angstrom, ps
- `si` - kg, m, s
- `nano` - attogram, nanometer, nanosecond
- `lj` - Lennard-Jones reduced units (requires polymer specification)

<!-- GENERATED FROM PYTHON SOURCE LINES 18-40 -->
```none
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/pylimer_tools/io/unit_styles.py:177: UserWarning: LJ unit styles are derived. Reference used: https://doi.org/10.1021/acs.macromol.9b02428
  warnings.warn(
LJ 1 Pressure in Pascal: 101325.0
```

<br/>
```Python
from pylimer_tools.io.unit_styles import UnitStyleFactory

# Create unit style factory
unit_factory = UnitStyleFactory()

# Get unit conversion for specific LAMMPS unit style
real_units = unit_factory.get_unit_style("real")
metal_units = unit_factory.get_unit_style("metal")

# For LJ units, specify the polymer
lj_units = unit_factory.get_unit_style("lj", polymer="pdms")

# Convert pressure from LAMMPS units to SI
pressure_si = (1 * real_units.pressure).to("Pa").magnitude  # type: ignore

# Convert temperature (already in Kelvin for 'real' units)
temperature_si = (
    273.15 *
    real_units.temperature).to("K").magnitude  # type: ignore

print(f"LJ 1 Pressure in Pascal: {pressure_si}")
```

**Total running time of the script:** (0 minutes 0.201 seconds)

<a id="sphx-glr-download-auto-examples-readers-writers-plot-unit-conversion-py"></a>

[`Download Jupyter notebook: plot_unit_conversion.ipynb`](_downloads/87b8395119e9cf38ac4c73f6c2755e19/plot_unit_conversion.ipynb)

[`Download Python source code: plot_unit_conversion.py`](_downloads/19917ab26800d5ee8a8695afaa6982da/plot_unit_conversion.py)

[`Download zipped: plot_unit_conversion.zip`](_downloads/f3cb55597e63e8125ea9ef6c49a4916b/plot_unit_conversion.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
