Python package to specify material parameters for MaMMoS simulation suite.
Project description
[!CAUTION] Technically, one can create any entity corresponding to a class defined in the EMMO. However, we only test against the ontology classes defined in MaMMoS Ontology.
Installation
To install mammos-entity:
pip install mammos-entity
To install locally in editable mode using pip:
git clone https://github.com/MaMMoS-project/mammos-entity.git
cd mammos-entity
pip install -e .
[!TIP] If you want to install the package in editable mode how the god intended it to be :pray:, install pixi and run :raised_hands:
git clone https://github.com/MaMMoS-project/mammos-entity.git cd mammos-entity pixi install --frozen
[!CAUTION] For developers: after each increment in version of the package, do not forget to sync the
pixi.lockfile by runningpixi installsince all the workflows depend on pixi. At the launch of each workflow, the pixi setup action will check that the lock file is in sync, and if found otherwise, will fail.
Tests
To run tests:
git clone https://github.com/MaMMoS-project/mammos-entity.git
cd mammos-entity
pixi run tests
MaMMoS Entities
Definitions
-
a quantity is an object that carries a value and units.
-
an entity is a quantity, which in addition links the entity to its definition in the ontology.
This package provides entities.
Recommended import
>>> import mammos_entity as me # MaMMoS Entities. Or later Magnetic Entities
For entities that are important in MaMMoS, there are (or there will be) short cut definitions. For example for the saturation magnetisation we have:
>>> Ms = me.Ms(800e3) # defines Ms = 8e5 A/m (default units are SI, i.e. A/m here)
>>> Ms
SpontaneousMagnetization(value=800000.0, unit=A / m)
Entities behaves like Quantity
Each entities has all the attributes and methods that are available for Quantities (in AstroPy or MaMMosUnits). See unit examples for details. Important attributes:
>>> Ms.value
np.float64(800000.0)
>>> Ms.unit
Unit('A/m')
Access to Ontology
Each entity object knows about its role in the Ontology:
>>> Ms.label
'SpontaneousMagnetization'
>>> Ms.ontology
magnetic_material_mammos.SpontaneousMagnetization
>>> Ms_ontology = Ms.ontology # retrieves a ThingClass from owlready2
>>> Ms_ontology.get_annotations() # behaves like a normal Thing
{'prefLabel': [locstr('SpontaneousMagnetization', 'en')],
'elucidation': [locstr('The spontaneous magnetization, Ms, of a ferromagnet is the result\nof alignment of the magnetic moments of individual atoms. Ms exists\nwithin a domain of a ferromagnet.', 'en')],
'altLabel': [locstr('Ms', '')],
'wikipediaReference': [locstr('https://en.wikipedia.org/wiki/Spontaneous_magnetization', '')],
'IECEntry': [locstr('https://www.electropedia.org/iev/iev.nsf/display?openform&ievref=221-02-41', '')]}
Initialising entities conveniently
If no options are provided, SI units are chosen:
>>> m1 = me.Ms(8e5)
If units are provided as a string (and understood), these can be used:
>>> m2 = me.Ms(8e5, "A/m") # no change as A/m are the default SI units
>>> m3 = me.Ms(800, "kA/m") # use KilloAmp / m
>>> print(m1)
SpontaneousMagnetization(value=800000.0, unit=A / m)
>>> print(m2)
SpontaneousMagnetization(value=800000.0, unit=A / m)
>>> print(m3)
SpontaneousMagnetization(value=800.0, unit=kA / m)
It is not allowed to initialise an entity with wrong units.
>>> m4 = me.Ms(1.2, "T")
...
TypeError: The unit T does not match the units of SpontaneousMagnetization
Entity operations
The Quantity object (which is the AstroPy unit object) supports many operations that act on the numbers as normal and carries along the units silently. For example:
>>> m2**2
<Quantity 6.4e+11 A2 / m2>
However, since the units do not correspond to the right ontology object, the ontology property is dropped.
>>> m2**2.ontology
...
AttributeError: 'Quantity' object has no 'ontology' member
Direct conversion of units
>>> print(m2) # 8e5 A/m
SpontaneousMagnetization(value=800000.0, unit=A / m)
>>> print(m2.to("mA/m")) # prefactor change only, leads to 8e8 mA/m
SpontaneousMagnetization(value=800000000.0, unit=mA / m)
Indirect conversion
Where the conversion needs conversion factors with units (here called "indirect"), the ontology is dropped and astropy.Quantity is returned:
>>> import astropy.units as u
>>> print(m3)
SpontaneousMagnetization(value=800.0, unit=kA / m)
>>> m4 = m3.to("T", equivalencies=u.magnetic_flux_field())
>>> print(m4)
1.005309649696 T
Defining vector entities (Example Zeeman field)
It is possible to pass a collection as a value to the entity.
>>> H = me.H([1e4, 1e4, 1e4], "A/m")
>>> H
ExternalMagneticField(value=[10000. 10000. 10000.], unit=A / m)
>>> H.ontology
magnetic_material_mammos.ExternalMagneticField
>>> H.ontology.get_class_properties()
{emmo.elucidation, core.prefLabel, emmo.hasMeasurementUnit, core.altLabel}
>>> H.ontology.elucidation
[locstr('The external field H′, acting on a sample that is produced by\nelectric currents or the stray field of magnets outside the sample\nvolume, is often called the applied field.', 'en')]
Does mammos_entity not provide your preferred entity?
You can create any entity defined in the MaMMoS ontology on the fly
>>> list(me.mammos_ontology.classes())
[magnetic_material_mammos.EulerAngles,
magnetic_material_mammos.CoercivityHcExternal,
magnetic_material_mammos.DemagnetizingFactor,
...
magnetic_material_mammos.MagneticMomementPerUnitMass,
magnetic_material_mammos.EasyAxisDistributionSigma,
magnetic_material_mammos.CellVolume]
>>> rem = me.Entity("Remanence", value=1e5)
>>> rem
Remanence(value=100000.0, unit=A / m)
>>> rem.value
np.float64(100000.0)
>>> rem.unit
Unit('A/m')
>>> rem.ontology
magnetic_material_mammos.Remanence
Once again, if the units of the initialised entity do not match the ontology, the entity will not be created.
>>> me.Entity("Remanence", value=1.7e4, unit="m")
...
TypeError: The unit m does not match the units of Remanence
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mammos_entity-0.1.8.tar.gz.
File metadata
- Download URL: mammos_entity-0.1.8.tar.gz
- Upload date:
- Size: 74.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
498598cdf543bad44d79c7df526df65343bc2e93b5811ec079e5d186de10ac7d
|
|
| MD5 |
e558a3fe0a2ac501f5506ff9319cf9e5
|
|
| BLAKE2b-256 |
e2455f6b943181f840ad331c29b30380a387256c6d6eb0289858ad9edc1f0aa7
|
Provenance
The following attestation bundles were made for mammos_entity-0.1.8.tar.gz:
Publisher:
cd.yml on MaMMoS-project/mammos-entity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mammos_entity-0.1.8.tar.gz -
Subject digest:
498598cdf543bad44d79c7df526df65343bc2e93b5811ec079e5d186de10ac7d - Sigstore transparency entry: 211298633
- Sigstore integration time:
-
Permalink:
MaMMoS-project/mammos-entity@04898f141030a4cc3b2413a665d7bdfff8e6f49b -
Branch / Tag:
refs/tags/0.1.8 - Owner: https://github.com/MaMMoS-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@04898f141030a4cc3b2413a665d7bdfff8e6f49b -
Trigger Event:
push
-
Statement type:
File details
Details for the file mammos_entity-0.1.8-py3-none-any.whl.
File metadata
- Download URL: mammos_entity-0.1.8-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edda6d18294fff563dcd28efa59c58af4739f42d359f1081583dc64a0105497f
|
|
| MD5 |
99c2a27e950b8e64fa297cfb5ef4ee09
|
|
| BLAKE2b-256 |
02f2365d0b48f74047d8296fea256b325c4678cd564ceae1e1b1e0e0c9eb5e2b
|
Provenance
The following attestation bundles were made for mammos_entity-0.1.8-py3-none-any.whl:
Publisher:
cd.yml on MaMMoS-project/mammos-entity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mammos_entity-0.1.8-py3-none-any.whl -
Subject digest:
edda6d18294fff563dcd28efa59c58af4739f42d359f1081583dc64a0105497f - Sigstore transparency entry: 211298635
- Sigstore integration time:
-
Permalink:
MaMMoS-project/mammos-entity@04898f141030a4cc3b2413a665d7bdfff8e6f49b -
Branch / Tag:
refs/tags/0.1.8 - Owner: https://github.com/MaMMoS-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@04898f141030a4cc3b2413a665d7bdfff8e6f49b -
Trigger Event:
push
-
Statement type: