Creates virtual compounds with properties based on xraylib. Compound wizard is a package from XISMuS software.
Project description
Installation
pip install compwizard
Compounds.py documentation
This module creates virtual compounds either from a database or from user input.
The virtual compound object will contain its chemical and physical attributes.
A compound can be initialized either by entering the name of a compound exisitng in the current database or by manually passing the parameters.
Compounds created via the weights fractions of elements will have .mass and .chem attributes empty.
Database can be checked with the Compounds.ListDatabase()
command.
To import the package in the project, use import Elements
The Compounds library is found within it. You can also use the following: from Elements import Compounds
compound.set_compound(*args,ctype=None,mode='by_atom',name='new_compound')
Parameters:
- *args: compound setup, string or 2 lists
The name of compound from database or two lists containing: first, the ratios or weights of elements, second, the elements. - ctype: string, optional
The initialization mode 'custom' or None, None is default and stands for a compound from the database. - mode: string, optional
The initialization type 'by_atom' or 'by_weight', 'by_atom' is default. This parameter should be defined if creating a 'custom' compound. - name: string, optional
Name of the new compound. Default is 'new_compound'. The name can be changed if desired by using the Compounds.give_name method.
Example:
from Elements import Compounds
new_compound = Compounds.compound()
new_compound.set_compound([2,1],['H','O'],ctype='custom')
nem_compound.set_compound([0.12,0.88],['H','O'],ctype='custom',mode='by_weight')
new_compound.set_compound('water')
All compounds in the example will have the same properties.
make_mixture_of(proportion, compounds)
Parameters:
- proportion: list
The ratio which the compounds will be mixed, either in weight fraction or in parts. - compounds: list
List of compound objects.
proportion and compounds must have the same dimension.
Example:
from Elements import Compounds
compound1 = Compounds.compound()
compound2 = Compounds.compound()
compound1.set_compound('linoil')
compound2.set_compound('TiWhite')
new_compound = Compounds.max_mixture_of( [25, 75], [compound1, compound2] )
The compound created by the mixture function will be a mixture with 25% compound1 and 75% compound2.
compound.set_attenuation(energy)
Parameters:
- energy: string or integer
The element the compound will be attenuating. E.g. if energy is set as 'Pb', it means the coeficients will be calculated for the attenuation of lead lines. If an integer is entered, the coefficients will be calculated for that one specific energy. It will still return a tuple, but with the second element equal to 0.
Example:
mycompound = Compounds.compound()
mycompound.set_compound('AuSheet')
mycompound.set_attenuation('Pb')
print(mycompound.lin_att,mycompound.tot_att)
(1912.6349060000002, 2833.4862456446012) (103.1, 152.73821000000004)
(by now the method returns a tuple, it will be changed in the future to return a dictionary with the line names as keys and the coefficients)
compound.mix(proportion,compounds)
Parameters:
- proportion: list
The ratio which the compounds will be mixed, either in weight fraction or in parts. The first value always refers to the compound starting the mixture, i.e. the object where the method is being applied to. - compounds: list
List containing the compound(s) objects to be mixed together.
Example:
water = Compounds.compound()
water.set_compound('water')
mycompound = Compounds.compound()
mycompound.set_compound('Linoil')
mixture = mycompound.mix([2,10],[water])
print(mixture.weight)
print(mixture.density)
{'H': 0.09166666666666667, 'O': 0.09166666666666667, 'C': 0.65}
1.4756558333333334
Attributes
water = Compounds.compound()
water.set_compound('water')
-
.name returns a string containing the name of the compound.
print(water.name)
'water'
-
.mass returns a float value with the atomic mass of the compound.
print(water.mass)
18.02
-
.chem returns a dictionary with the total atomic mass of each constituent chemical element.
print(water.chem)
{'H': 2.02, 'O': 16.0}
-
.density return a float value with the total density of the compound
print(water.density)
0.0009663706992230855
-
.weight returns a dictionary with the weight fraction of each constituent chemical element in a similar way of .chem
print(water.weight)
{'H': 0.1120976692563818, 'O': 0.8879023307436182}
-
.origin returns a string with the origin of the compound. Values are: 'by_weight', 'by_atom', 'by_mixing' or 'from_database'
print(water.origin)
from_database
-
.tot_att and .lin_att each will return a tuple with the attenuation coefficients of a given element. .tot_att will return the total attenuation while .lin_att will returns the linear attenuation (the same as .tot_att multiplied by the compound's density).
water.set_attenuation('Cu') print(water.lin_att) print(water.tot_att)
(0.009849807036256424, 0.007272790368341503)
(10.192576248612653, 7.525880466148724)If an
int
is passed as the set_attenuation argument, the tuple's second index will be 0.
Project details
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
File details
Details for the file compwizard-1.0.3.3.tar.gz
.
File metadata
- Download URL: compwizard-1.0.3.3.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dac9114b691d5a5bc22ab8485486401a45e72db76c12e590f1f4e8775bf10d4 |
|
MD5 | 04f79576867067f5f4b2d49a73432b8d |
|
BLAKE2b-256 | 38c2ccdfcb97b16986c9f160f9bae6e084e0c5a2fd2ec970be00cd816b15665c |
File details
Details for the file compwizard-1.0.3.3-py3-none-any.whl
.
File metadata
- Download URL: compwizard-1.0.3.3-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e30deba0129127efdd8da01e7426fe960fc9bdfc3e7447c910adfcc4aabf0a |
|
MD5 | daa87c4e9a086325286a3019dc13ce7e |
|
BLAKE2b-256 | 9873b700e32b653ec5c960e972a06e1b00efc257e2d0957c48f4db17065ca5eb |