-
Notifications
You must be signed in to change notification settings - Fork 835
/
pymatgen.core.units.html
670 lines (522 loc) · 38 KB
/
pymatgen.core.units.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pymatgen.core.units module — pymatgen 2021.1.28 documentation</title>
<link rel="canonical" href="https://pymatgen.orgpymatgen.core.units.html"/>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="pymatgen.core.xcfunc module" href="pymatgen.core.xcfunc.html" />
<link rel="prev" title="pymatgen.core.trajectory module" href="pymatgen.core.trajectory.html" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33990148-1']);
_gaq.push(['_trackPageview']);
</script>
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: linear-gradient(0deg, rgba(23,63,162,1) 0%, rgba(0,70,192,1) 100%)" >
<a href="index.html" class="icon icon-home"> pymatgen
</a>
<div class="version">
2021.1.28
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="change_log.html">Change log</a></li>
<li class="toctree-l1"><a class="reference internal" href="usage.html">Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="team.html">Development Team</a></li>
<li class="toctree-l1"><a class="reference internal" href="references.html">References</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">API Docs</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="pymatgen.html">pymatgen package</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="pymatgen.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="pymatgen.alchemy.html">pymatgen.alchemy package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.analysis.html">pymatgen.analysis package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.apps.html">pymatgen.apps package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.cli.html">pymatgen.cli package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.command_line.html">pymatgen.command_line package</a></li>
<li class="toctree-l4 current"><a class="reference internal" href="pymatgen.core.html">pymatgen.core package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.electronic_structure.html">pymatgen.electronic_structure package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.entries.html">pymatgen.entries package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.ext.html">pymatgen.ext package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.io.html">pymatgen.io package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.optimization.html">pymatgen.optimization package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.phonon.html">pymatgen.phonon package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.plugins.html">pymatgen.plugins package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.symmetry.html">pymatgen.symmetry package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.transformations.html">pymatgen.transformations package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.util.html">pymatgen.util package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pymatgen.vis.html">pymatgen.vis package</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="pymatgen.html#submodules">Submodules</a></li>
<li class="toctree-l3"><a class="reference internal" href="pymatgen.html#module-pymatgen">Module contents</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">pymatgen</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li><a href="modules.html">pymatgen</a> »</li>
<li><a href="pymatgen.html">pymatgen package</a> »</li>
<li><a href="pymatgen.core.html">pymatgen.core package</a> »</li>
<li>pymatgen.core.units module</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/materialsproject/pymatgen/blob/master/docs_rst/pymatgen.core.units.rst" class="fa fa-github"> Edit on GitHub</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="module-pymatgen.core.units">
<span id="pymatgen-core-units-module"></span><h1>pymatgen.core.units module<a class="headerlink" href="#module-pymatgen.core.units" title="Permalink to this headline">¶</a></h1>
<p>This module implements a FloatWithUnit, which is a subclass of float. It
also defines supported units for some commonly used units for energy, length,
temperature, time and charge. FloatWithUnit also support conversion to one
another, and additions and subtractions perform automatic conversion if
units are detected. An ArrayWithUnit is also implemented, which is a subclass
of numpy’s ndarray with similar unit features.</p>
<dl class="py class">
<dt id="pymatgen.core.units.ArrayWithUnit">
<em class="property">class </em><code class="sig-name descname">ArrayWithUnit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">input_array</span></em>, <em class="sig-param"><span class="n">unit</span></em>, <em class="sig-param"><span class="n">unit_type</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L498-L709"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></p>
<p>Subclasses <cite>numpy.ndarray</cite> to attach a unit type. Typically, you should
use the pre-defined unit type subclasses such as EnergyArray,
LengthArray, etc. instead of using ArrayWithFloatWithUnit directly.</p>
<p>Supports conversion, addition and subtraction of the same unit type. E.g.,
1 m + 20 cm will be automatically converted to 1.2 m (units follow the
leftmost quantity).</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">EnergyArray</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="s2">"Ha"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">EnergyArray</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="s2">"eV"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="go">[ 1.03674933 2.07349865] Ha</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">"eV"</span><span class="p">)</span>
<span class="go">array([ 28.21138386, 56.42276772]) eV</span>
</pre></div>
</div>
<p>Override __new__.</p>
<dl class="py attribute">
<dt id="pymatgen.core.units.ArrayWithUnit.Error">
<code class="sig-name descname">Error</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L140-L143"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.Error" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#pymatgen.core.units.UnitError" title="pymatgen.core.units.UnitError"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnitError</span></code></a></p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.ArrayWithUnit.as_base_units">
<em class="property">property </em><code class="sig-name descname">as_base_units</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.as_base_units" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns this ArrayWithUnit in base SI units, including derived units.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>An ArrayWithUnit object in base SI units</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.ArrayWithUnit.conversions">
<code class="sig-name descname">conversions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L704-L709"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.conversions" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a string showing the available conversions.
Useful tool in interactive mode.</p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.ArrayWithUnit.supported_units">
<em class="property">property </em><code class="sig-name descname">supported_units</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.supported_units" title="Permalink to this definition">¶</a></dt>
<dd><p>Supported units for specific unit type.</p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.ArrayWithUnit.to">
<code class="sig-name descname">to</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">new_unit</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L663-L683"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.to" title="Permalink to this definition">¶</a></dt>
<dd><p>Conversion to a new_unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>new_unit</strong> – New unit type.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A ArrayWithFloatWithUnit object in the new units.</p>
</dd>
</dl>
<p>Example usage:
>>> e = EnergyArray([1, 1.1], “Ha”)
>>> e.to(“eV”)
array([ 27.21138386, 29.93252225]) eV</p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.ArrayWithUnit.unit">
<em class="property">property </em><code class="sig-name descname">unit</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.unit" title="Permalink to this definition">¶</a></dt>
<dd><p>The unit, e.g., “eV”.</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p>return</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.ArrayWithUnit.unit_type">
<em class="property">property </em><code class="sig-name descname">unit_type</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.ArrayWithUnit.unit_type" title="Permalink to this definition">¶</a></dt>
<dd><p>The type of unit. Energy, Charge, etc.</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p>return</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Charge">
<code class="sig-name descname">Charge</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='charge')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Charge" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with a charge unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., C, e (electron charge). Must be valid unit or UnitError
is raised.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Energy">
<code class="sig-name descname">Energy</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='energy')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Energy" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with an energy unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., eV, kJ, etc. Must be valid unit or UnitError is raised.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py class">
<dt id="pymatgen.core.units.FloatWithUnit">
<em class="property">class </em><code class="sig-name descname">FloatWithUnit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">val</span></em>, <em class="sig-param"><span class="n">unit</span></em>, <em class="sig-param"><span class="n">unit_type</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L286-L495"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></p>
<p>Subclasses float to attach a unit type. Typically, you should use the
pre-defined unit type subclasses such as Energy, Length, etc. instead of
using FloatWithUnit directly.</p>
<p>Supports conversion, addition and subtraction of the same unit type. E.g.,
1 m + 20 cm will be automatically converted to 1.2 m (units follow the
leftmost quantity). Note that FloatWithUnit does not override the eq
method for float, i.e., units are not checked when testing for equality.
The reason is to allow this class to be used transparently wherever floats
are expected.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">e</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="mf">1.1</span><span class="p">,</span> <span class="s2">"Ha"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="mf">1.1</span><span class="p">,</span> <span class="s2">"Ha"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s2">"eV"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="go">1.2102479761938871 Ha</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">"eV"</span><span class="p">)</span>
<span class="go">32.932522246000005 eV</span>
</pre></div>
</div>
<p>Initializes a float with unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – A unit. E.g., “C”.</p></li>
<li><p><strong>unit_type</strong> (<em>str</em>) – A type of unit. E.g., “charge”</p></li>
</ul>
</dd>
</dl>
<dl class="py attribute">
<dt id="pymatgen.core.units.FloatWithUnit.Error">
<code class="sig-name descname">Error</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L140-L143"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.Error" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#pymatgen.core.units.UnitError" title="pymatgen.core.units.UnitError"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnitError</span></code></a></p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.FloatWithUnit.as_base_units">
<em class="property">property </em><code class="sig-name descname">as_base_units</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.as_base_units" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns this FloatWithUnit in base SI units, including derived units.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>A FloatWithUnit object in base SI units</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.FloatWithUnit.from_string">
<em class="property">classmethod </em><code class="sig-name descname">from_string</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">s</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L311-L332"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.from_string" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize a FloatWithUnit from a string. Example Memory.from_string(“1. Mb”)</p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.FloatWithUnit.supported_units">
<em class="property">property </em><code class="sig-name descname">supported_units</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.supported_units" title="Permalink to this definition">¶</a></dt>
<dd><p>Supported units for specific unit type.</p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.FloatWithUnit.to">
<code class="sig-name descname">to</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">new_unit</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L457-L478"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.to" title="Permalink to this definition">¶</a></dt>
<dd><p>Conversion to a new_unit. Right now, only supports 1 to 1 mapping of
units of each type.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>new_unit</strong> – New unit type.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A FloatWithUnit object in the new units.</p>
</dd>
</dl>
<p>Example usage:
>>> e = Energy(1.1, “eV”)
>>> e = Energy(1.1, “Ha”)
>>> e.to(“eV”)
29.932522246 eV</p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.FloatWithUnit.unit">
<em class="property">property </em><code class="sig-name descname">unit</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.unit" title="Permalink to this definition">¶</a></dt>
<dd><p>The unit, e.g., “eV”.</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p>return</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.FloatWithUnit.unit_type">
<em class="property">property </em><code class="sig-name descname">unit_type</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.FloatWithUnit.unit_type" title="Permalink to this definition">¶</a></dt>
<dd><p>The type of unit. Energy, Charge, etc.</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p>return</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Length">
<code class="sig-name descname">Length</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='length')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Length" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with a length unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., m, ang, bohr, etc. Must be valid unit or UnitError is
raised.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Mass">
<code class="sig-name descname">Mass</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='mass')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Mass" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with a mass unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., amu, kg, etc. Must be valid unit or UnitError is
raised.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Memory">
<code class="sig-name descname">Memory</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='memory')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Memory" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with a memory unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., Kb, Mb, Gb, Tb. Must be valid unit or UnitError
is raised.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Temp">
<code class="sig-name descname">Temp</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='temperature')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Temp" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with a temperature unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., K. Only K (kelvin) is supported.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.Time">
<code class="sig-name descname">Time</code><em class="property"> = functools.partial(<class 'pymatgen.core.units.FloatWithUnit'>, unit_type='time')</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Time" title="Permalink to this definition">¶</a></dt>
<dd><p>A float with a time unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>val</strong> (<em>float</em>) – Value</p></li>
<li><p><strong>unit</strong> (<a class="reference internal" href="#pymatgen.core.units.Unit" title="pymatgen.core.units.Unit"><em>Unit</em></a>) – E.g., s, min, h. Must be valid unit or UnitError is
raised.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py class">
<dt id="pymatgen.core.units.Unit">
<em class="property">class </em><code class="sig-name descname">Unit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">unit_def</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L156-L283"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Unit" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Mapping</span></code></p>
<p>Represents a unit, e.g., “m” for meters, etc. Supports compound units.
Only integer powers are supported for units.</p>
<p>Constructs a unit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>unit_def</strong> – A definition for the unit. Either a mapping of unit to
powers, e.g., {“m”: 2, “s”: -1} represents “m^2 s^-1”,
or simply as a string “kg m^2 s^-1”. Note that the supported
format uses “^” as the power operator and all units must be
space-separated.</p>
</dd>
</dl>
<dl class="py attribute">
<dt id="pymatgen.core.units.Unit.Error">
<code class="sig-name descname">Error</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L140-L143"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Unit.Error" title="Permalink to this definition">¶</a></dt>
<dd><p>alias of <a class="reference internal" href="#pymatgen.core.units.UnitError" title="pymatgen.core.units.UnitError"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnitError</span></code></a></p>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.Unit.as_base_units">
<em class="property">property </em><code class="sig-name descname">as_base_units</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Unit.as_base_units" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts all units to base SI units, including derived units.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>(base_units_dict, scaling factor). base_units_dict will not
contain any constants, which are gathered in the scaling factor.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="pymatgen.core.units.Unit.get_conversion_factor">
<code class="sig-name descname">get_conversion_factor</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">new_unit</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L264-L283"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.Unit.get_conversion_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a conversion factor between this unit and a new unit.
Compound units are supported, but must have the same powers in each
unit type.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>new_unit</strong> – The new unit.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py exception">
<dt id="pymatgen.core.units.UnitError">
<em class="property">exception </em><code class="sig-name descname">UnitError</code><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L140-L143"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.UnitError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></p>
<p>Exception class for unit errors.</p>
</dd></dl>
<dl class="py data">
<dt id="pymatgen.core.units.kb">
<code class="sig-name descname">kb</code><em class="property"> = 8.617333262e-05</em><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.kb" title="Permalink to this definition">¶</a></dt>
<dd><p>Definitions of supported units. Values below are essentially scaling and
conversion factors. What matters is the relative values, not the absolute.
The SI units must have factor 1.</p>
</dd></dl>
<dl class="py function">
<dt id="pymatgen.core.units.obj_with_unit">
<code class="sig-name descname">obj_with_unit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">obj</span></em>, <em class="sig-param"><span class="n">unit</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L799-L814"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.obj_with_unit" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <cite>FloatWithUnit</cite> instance if obj is scalar, a dictionary of
objects with units if obj is a dict, else an instance of
<cite>ArrayWithFloatWithUnit</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>unit</strong> – Specific units (eV, Ha, m, ang, etc.).</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pymatgen.core.units.unitized">
<code class="sig-name descname">unitized</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">unit</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/materialsproject/pymatgen/blob/v2021.1.28/pymatgen/core/units.py#L817-L865"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pymatgen.core.units.unitized" title="Permalink to this definition">¶</a></dt>
<dd><p>Useful decorator to assign units to the output of a function. You can also
use it to standardize the output units of a function that already returns
a FloatWithUnit or ArrayWithUnit. For sequences, all values in the sequences
are assigned the same unit. It works with Python sequences only. The creation
of numpy arrays loses all unit information. For mapping types, the values
are assigned units.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>unit</strong> – Specific unit (eV, Ha, m, ang, etc.).</p>
</dd>
</dl>
<p>Example usage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@unitized</span><span class="p">(</span><span class="n">unit</span><span class="o">=</span><span class="s2">"kg"</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_mass</span><span class="p">():</span>
<span class="k">return</span> <span class="mf">123.45</span>
</pre></div>
</div>
</dd></dl>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2011, Pymatgen Development Team
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
</div>
</body>
</html>