nucleus_example.py
Go to the documentation of this file.
1 # Example file for nucleus class
2 # Author: Moritz Reichert
3 # Date : 04.05.17
4 
5 # Import the nucleus class (Attention, the import has to be different for python 3)
6 # This in only working in python 2!
7 from class_files.nucleus_class import nucleus
8 
9 # Simple class to work with nuclei. The class is able to analyze a nucleus from a
10 # name of a nucleus and extract several properties from this name.
11 
12 
13 
14 ################
15 # INITIALIZING #
16 ################
17 
18 # Create instances of the nucleus class
19 o16 = nucleus('o16')
20 ne15= nucleus('ne15')
21 he4 = nucleus('he4')
22 
23 
24 ##############
25 # PROPERTIES #
26 ##############
27 
28 
29 # Get the properties of a nucleus
30 mass = o16.get_A()
31 atomic_number = o16.get_Z()
32 neutron_number = o16.get_N()
33 name = o16.get_name()
34 # Print it
35 print(name+' has a mass number of '+str(mass)+', with Z = '+str(atomic_number)+' and N = '+str(neutron_number)+'.')
36 
37 # The nucleus object can also store an abundance
38 o16.set_Y(1e-10)
39 # or alternatively set the mass fraction with o16.set_X(1e-10)
40 # You can access it with o16.get_Y()
41 
42 
43 
44 ###########
45 # SORTING #
46 ###########
47 
48 
49 # Put all nuclei in a list
50 nuclei_list = [ne15,he4,o16]
51 
52 # Sort it corresponding to proton number
53 sort_Z = sorted(nuclei_list)
54 sort_Z_names = map(lambda x: x.get_name(),sort_Z)
55 print('Sorted for Z: ',sort_Z_names)
56 
57 # Sort it for A
58 # First change the sort criteria for every nucleus in list
59 for n in nuclei_list:
60  n.set_sortcriteria('A')
61 
62 sort_A = sorted(nuclei_list)
63 sort_A_names = map(lambda x: x.get_name(),sort_A)
64 print('Sorted for A: ',sort_A_names)
bin.class_files.nucleus_class.nucleus
Definition: nucleus_class.py:9